libcamera: base: utils: Implement hex() for 8-bit and 16-bit values
diff mbox series

Message ID 20240703192924.10643-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 45bd1f20f6a9c9b97972944358c75beb9dfafb9c
Headers show
Series
  • libcamera: base: utils: Implement hex() for 8-bit and 16-bit values
Related show

Commit Message

Laurent Pinchart July 3, 2024, 7:29 p.m. UTC
The utils::hex() function is implemented for 32-bit and 64-bit integers,
but not for 8-bit and 16-bit. This causes a link error (possibly at
runtime for IPA modules due to lazy linking) when trying to print 8-bit
or 16-bit integers. Implement additional specializations to fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/base/utils.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)


base-commit: 196abb8d1d6e0fe9d190315e72a85eb12d16a554

Comments

Umang Jain July 4, 2024, 3:56 a.m. UTC | #1
Hi Laurent,

Thank you for the patch.

On 04/07/24 12:59 am, Laurent Pinchart wrote:
> The utils::hex() function is implemented for 32-bit and 64-bit integers,
> but not for 8-bit and 16-bit. This causes a link error (possibly at
> runtime for IPA modules due to lazy linking) when trying to print 8-bit
> or 16-bit integers. Implement additional specializations to fix it.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

test/utils.cpp can be expanded to cover these as well as part of the patch ?

With that,

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   include/libcamera/base/utils.h | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
>
> diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
> index 4ae02dc97478..734ff81e2860 100644
> --- a/include/libcamera/base/utils.h
> +++ b/include/libcamera/base/utils.h
> @@ -90,6 +90,30 @@ template<typename T,
>   _hex hex(T value, unsigned int width = 0);
>   
>   #ifndef __DOXYGEN__
> +template<>
> +inline _hex hex<int8_t>(int8_t value, unsigned int width)
> +{
> +	return { static_cast<uint64_t>(value), width ? width : 2 };
> +}
> +
> +template<>
> +inline _hex hex<uint8_t>(uint8_t value, unsigned int width)
> +{
> +	return { static_cast<uint64_t>(value), width ? width : 2 };
> +}
> +
> +template<>
> +inline _hex hex<int16_t>(int16_t value, unsigned int width)
> +{
> +	return { static_cast<uint64_t>(value), width ? width : 4 };
> +}
> +
> +template<>
> +inline _hex hex<uint16_t>(uint16_t value, unsigned int width)
> +{
> +	return { static_cast<uint64_t>(value), width ? width : 4 };
> +}
> +
>   template<>
>   inline _hex hex<int32_t>(int32_t value, unsigned int width)
>   {
>
> base-commit: 196abb8d1d6e0fe9d190315e72a85eb12d16a554

Patch
diff mbox series

diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
index 4ae02dc97478..734ff81e2860 100644
--- a/include/libcamera/base/utils.h
+++ b/include/libcamera/base/utils.h
@@ -90,6 +90,30 @@  template<typename T,
 _hex hex(T value, unsigned int width = 0);
 
 #ifndef __DOXYGEN__
+template<>
+inline _hex hex<int8_t>(int8_t value, unsigned int width)
+{
+	return { static_cast<uint64_t>(value), width ? width : 2 };
+}
+
+template<>
+inline _hex hex<uint8_t>(uint8_t value, unsigned int width)
+{
+	return { static_cast<uint64_t>(value), width ? width : 2 };
+}
+
+template<>
+inline _hex hex<int16_t>(int16_t value, unsigned int width)
+{
+	return { static_cast<uint64_t>(value), width ? width : 4 };
+}
+
+template<>
+inline _hex hex<uint16_t>(uint16_t value, unsigned int width)
+{
+	return { static_cast<uint64_t>(value), width ? width : 4 };
+}
+
 template<>
 inline _hex hex<int32_t>(int32_t value, unsigned int width)
 {