[libcamera-devel,08/31] libcamera: controls: Don't convert 32-bit and 64-bit implicitly

Message ID 20200229164254.23604-9-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: Add support for array controls
Related show

Commit Message

Laurent Pinchart Feb. 29, 2020, 4:42 p.m. UTC
The ControlValue::get<T>() method verifies that the T type corresponds
to the ControlValue type. It however accepts int32_t as a return type
for 64-bit integer controls, and int64_t as a return type for 32-bit
integer controls. There's no reason to do so anymore, make the type
check stricter.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/controls.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Kieran Bingham March 2, 2020, 10:57 p.m. UTC | #1
Hi,

On 29/02/2020 16:42, Laurent Pinchart wrote:
> The ControlValue::get<T>() method verifies that the T type corresponds
> to the ControlValue type. It however accepts int32_t as a return type
> for 64-bit integer controls, and int64_t as a return type for 32-bit
> integer controls. There's no reason to do so anymore, make the type
> check stricter.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Oh I like this.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> ---
>  src/libcamera/controls.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 613e6d768c0f..f632d60adc8b 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -187,7 +187,7 @@ const bool &ControlValue::get<bool>() const
>  template<>
>  const int32_t &ControlValue::get<int32_t>() const
>  {
> -	ASSERT(type_ == ControlTypeInteger32 || type_ == ControlTypeInteger64);
> +	ASSERT(type_ == ControlTypeInteger32);
>  
>  	return integer32_;
>  }
> @@ -195,7 +195,7 @@ const int32_t &ControlValue::get<int32_t>() const
>  template<>
>  const int64_t &ControlValue::get<int64_t>() const
>  {
> -	ASSERT(type_ == ControlTypeInteger32 || type_ == ControlTypeInteger64);
> +	ASSERT(type_ == ControlTypeInteger64);
>  
>  	return integer64_;
>  }
>

Patch

diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 613e6d768c0f..f632d60adc8b 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -187,7 +187,7 @@  const bool &ControlValue::get<bool>() const
 template<>
 const int32_t &ControlValue::get<int32_t>() const
 {
-	ASSERT(type_ == ControlTypeInteger32 || type_ == ControlTypeInteger64);
+	ASSERT(type_ == ControlTypeInteger32);
 
 	return integer32_;
 }
@@ -195,7 +195,7 @@  const int32_t &ControlValue::get<int32_t>() const
 template<>
 const int64_t &ControlValue::get<int64_t>() const
 {
-	ASSERT(type_ == ControlTypeInteger32 || type_ == ControlTypeInteger64);
+	ASSERT(type_ == ControlTypeInteger64);
 
 	return integer64_;
 }