[v1,3/4] libcamera: controls: Arrays of arrays are not supported
diff mbox series

Message ID 20250401131939.749583-4-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: controls: Misc. changes
Related show

Commit Message

Barnabás Pőcze April 1, 2025, 1:19 p.m. UTC
Arrays of arrays, even arrays of strings, are not supported by
the current `ControlValue` mechanism, so disable them to trigger
comptime errors if attempts are made to use them.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/controls.h    | 2 +-
 src/apps/cam/capture_script.cpp | 4 ----
 2 files changed, 1 insertion(+), 5 deletions(-)

Comments

Laurent Pinchart April 1, 2025, 9:45 p.m. UTC | #1
On Tue, Apr 01, 2025 at 03:19:38PM +0200, Barnabás Pőcze wrote:
> Arrays of arrays, even arrays of strings, are not supported by
> the current `ControlValue` mechanism, so disable them to trigger
> comptime errors if attempts are made to use them.

What currently happens if we try to use them ?

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  include/libcamera/controls.h    | 2 +-
>  src/apps/cam/capture_script.cpp | 4 ----
>  2 files changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index d35347f4c..85c724ec1 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -120,7 +120,7 @@ struct control_type<Point> {
>  };
>  
>  template<typename T, std::size_t N>
> -struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
> +struct control_type<Span<T, N>, std::enable_if_t<control_type<std::remove_cv_t<T>>::size == 0>> : public control_type<std::remove_cv_t<T>> {
>  	static constexpr std::size_t size = N;
>  };
>  
> diff --git a/src/apps/cam/capture_script.cpp b/src/apps/cam/capture_script.cpp
> index fc1dfa75f..f3262af98 100644
> --- a/src/apps/cam/capture_script.cpp
> +++ b/src/apps/cam/capture_script.cpp
> @@ -600,10 +600,6 @@ ControlValue CaptureScript::parseArrayControl(const ControlId *id,
>  		value = Span<const float>(values.data(), values.size());
>  		break;
>  	}
> -	case ControlTypeString: {
> -		value = Span<const std::string>(repr.data(), repr.size());
> -		break;
> -	}
>  	default:
>  		std::cerr << "Unsupported control type" << std::endl;
>  		break;
Barnabás Pőcze April 2, 2025, 8:25 a.m. UTC | #2
Hi


2025. 04. 01. 23:45 keltezéssel, Laurent Pinchart írta:
> On Tue, Apr 01, 2025 at 03:19:38PM +0200, Barnabás Pőcze wrote:
>> Arrays of arrays, even arrays of strings, are not supported by
>> the current `ControlValue` mechanism, so disable them to trigger
>> comptime errors if attempts are made to use them.
> 
> What currently happens if we try to use them ?

There are two options I can see:

  * runtime assertion failure in `set()` because `elementSize == ControlValueSize[type]`
    is not true, e.g. `Span<const std::string>`
  * stores spans inside `ControlValue` (with arbitrarily dangling pointers),
    e.g. `Span<Span<Rectangle>>` (since `sizeof(Span<Rectangle>) == sizeof(Rectangle)`
    on x86-64)

So they don't really work in any reasonable capacity,
this is why I want to disable them for now.


Regards,
Barnabás Pőcze

> 
>> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>> ---
>>   include/libcamera/controls.h    | 2 +-
>>   src/apps/cam/capture_script.cpp | 4 ----
>>   2 files changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
>> index d35347f4c..85c724ec1 100644
>> --- a/include/libcamera/controls.h
>> +++ b/include/libcamera/controls.h
>> @@ -120,7 +120,7 @@ struct control_type<Point> {
>>   };
>>   
>>   template<typename T, std::size_t N>
>> -struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
>> +struct control_type<Span<T, N>, std::enable_if_t<control_type<std::remove_cv_t<T>>::size == 0>> : public control_type<std::remove_cv_t<T>> {
>>   	static constexpr std::size_t size = N;
>>   };
>>   
>> diff --git a/src/apps/cam/capture_script.cpp b/src/apps/cam/capture_script.cpp
>> index fc1dfa75f..f3262af98 100644
>> --- a/src/apps/cam/capture_script.cpp
>> +++ b/src/apps/cam/capture_script.cpp
>> @@ -600,10 +600,6 @@ ControlValue CaptureScript::parseArrayControl(const ControlId *id,
>>   		value = Span<const float>(values.data(), values.size());
>>   		break;
>>   	}
>> -	case ControlTypeString: {
>> -		value = Span<const std::string>(repr.data(), repr.size());
>> -		break;
>> -	}
>>   	default:
>>   		std::cerr << "Unsupported control type" << std::endl;
>>   		break;
>

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index d35347f4c..85c724ec1 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -120,7 +120,7 @@  struct control_type<Point> {
 };
 
 template<typename T, std::size_t N>
-struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
+struct control_type<Span<T, N>, std::enable_if_t<control_type<std::remove_cv_t<T>>::size == 0>> : public control_type<std::remove_cv_t<T>> {
 	static constexpr std::size_t size = N;
 };
 
diff --git a/src/apps/cam/capture_script.cpp b/src/apps/cam/capture_script.cpp
index fc1dfa75f..f3262af98 100644
--- a/src/apps/cam/capture_script.cpp
+++ b/src/apps/cam/capture_script.cpp
@@ -600,10 +600,6 @@  ControlValue CaptureScript::parseArrayControl(const ControlId *id,
 		value = Span<const float>(values.data(), values.size());
 		break;
 	}
-	case ControlTypeString: {
-		value = Span<const std::string>(repr.data(), repr.size());
-		break;
-	}
 	default:
 		std::cerr << "Unsupported control type" << std::endl;
 		break;