[libcamera-devel] libcamera: control_serializer: Use explicit ControlTypeNone case

Message ID 20200301160254.4548-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel] libcamera: control_serializer: Use explicit ControlTypeNone case
Related show

Commit Message

Laurent Pinchart March 1, 2020, 4:02 p.m. UTC
Replace the default case with an explicit ControlTypeNone case in
ControlSerializer::load() to catch ommissions when adding new control
types.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/control_serializer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kieran Bingham March 2, 2020, 3:35 p.m. UTC | #1
Hi Laurent,

On 01/03/2020 16:02, Laurent Pinchart wrote:
> Replace the default case with an explicit ControlTypeNone case in
> ControlSerializer::load() to catch ommissions when adding new control
> types.
> 
s/ommissions/omissions/

This sounds good. Does it cause any issue with no default case found?

In fact looking again, Of course this now means that the compiler will
warn us here if an option is not handled by the case statement.

Excellent.

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

> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/libcamera/control_serializer.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> index 5537c5466025..e78fca88cfea 100644
> --- a/src/libcamera/control_serializer.cpp
> +++ b/src/libcamera/control_serializer.cpp
> @@ -361,7 +361,7 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
>  		return ControlValue(value);
>  	}
>  
> -	default:
> +	case ControlTypeNone:
>  		return ControlValue();
>  	}
>  }
>
Laurent Pinchart March 2, 2020, 4:41 p.m. UTC | #2
Hi Kieran,

On Mon, Mar 02, 2020 at 03:35:23PM +0000, Kieran Bingham wrote:
> On 01/03/2020 16:02, Laurent Pinchart wrote:
> > Replace the default case with an explicit ControlTypeNone case in
> > ControlSerializer::load() to catch ommissions when adding new control
> > types.
>
> s/ommissions/omissions/
> 
> This sounds good. Does it cause any issue with no default case found?
> 
> In fact looking again, Of course this now means that the compiler will
> warn us here if an option is not handled by the case statement.

But some gcc version still reports that the function has an exit path
with a return statement :-( I'll have to add both.

> Excellent.
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  src/libcamera/control_serializer.cpp | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> > index 5537c5466025..e78fca88cfea 100644
> > --- a/src/libcamera/control_serializer.cpp
> > +++ b/src/libcamera/control_serializer.cpp
> > @@ -361,7 +361,7 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
> >  		return ControlValue(value);
> >  	}
> >  
> > -	default:
> > +	case ControlTypeNone:
> >  		return ControlValue();
> >  	}
> >  }
Kieran Bingham March 2, 2020, 10:36 p.m. UTC | #3
Hi Laurent,

On 02/03/2020 16:41, Laurent Pinchart wrote:
> Hi Kieran,
> 
> On Mon, Mar 02, 2020 at 03:35:23PM +0000, Kieran Bingham wrote:
>> On 01/03/2020 16:02, Laurent Pinchart wrote:
>>> Replace the default case with an explicit ControlTypeNone case in
>>> ControlSerializer::load() to catch ommissions when adding new control
>>> types.
>>
>> s/ommissions/omissions/
>>
>> This sounds good. Does it cause any issue with no default case found?
>>
>> In fact looking again, Of course this now means that the compiler will
>> warn us here if an option is not handled by the case statement.
> 
> But some gcc version still reports that the function has an exit path
> with a return statement :-( I'll have to add both.

Does adding both remove the benefit of having the compiler warn us when
we add new enum types without adding them to the case statement?

If not then that's fine.

> 
>> Excellent.
>>
>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>
>>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> ---
>>>  src/libcamera/control_serializer.cpp | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
>>> index 5537c5466025..e78fca88cfea 100644
>>> --- a/src/libcamera/control_serializer.cpp
>>> +++ b/src/libcamera/control_serializer.cpp
>>> @@ -361,7 +361,7 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
>>>  		return ControlValue(value);
>>>  	}
>>>  
>>> -	default:
>>> +	case ControlTypeNone:
>>>  		return ControlValue();
>>>  	}
>>>  }
>
Laurent Pinchart March 3, 2020, 8:42 a.m. UTC | #4
Hi Kieran,

On Mon, Mar 02, 2020 at 10:36:36PM +0000, Kieran Bingham wrote:
> On 02/03/2020 16:41, Laurent Pinchart wrote:
> > On Mon, Mar 02, 2020 at 03:35:23PM +0000, Kieran Bingham wrote:
> >> On 01/03/2020 16:02, Laurent Pinchart wrote:
> >>> Replace the default case with an explicit ControlTypeNone case in
> >>> ControlSerializer::load() to catch ommissions when adding new control
> >>> types.
> >>
> >> s/ommissions/omissions/
> >>
> >> This sounds good. Does it cause any issue with no default case found?
> >>
> >> In fact looking again, Of course this now means that the compiler will
> >> warn us here if an option is not handled by the case statement.
> > 
> > But some gcc version still reports that the function has an exit path
> > with a return statement :-( I'll have to add both.
> 
> Does adding both remove the benefit of having the compiler warn us when
> we add new enum types without adding them to the case statement?
> 
> If not then that's fine.

The benefit stays :-) I've just tested it.

> >> Excellent.
> >>
> >> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >>
> >>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>> ---
> >>>  src/libcamera/control_serializer.cpp | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
> >>> index 5537c5466025..e78fca88cfea 100644
> >>> --- a/src/libcamera/control_serializer.cpp
> >>> +++ b/src/libcamera/control_serializer.cpp
> >>> @@ -361,7 +361,7 @@ ControlValue ControlSerializer::load<ControlValue>(ControlType type,
> >>>  		return ControlValue(value);
> >>>  	}
> >>>  
> >>> -	default:
> >>> +	case ControlTypeNone:
> >>>  		return ControlValue();
> >>>  	}
> >>>  }

Patch

diff --git a/src/libcamera/control_serializer.cpp b/src/libcamera/control_serializer.cpp
index 5537c5466025..e78fca88cfea 100644
--- a/src/libcamera/control_serializer.cpp
+++ b/src/libcamera/control_serializer.cpp
@@ -361,7 +361,7 @@  ControlValue ControlSerializer::load<ControlValue>(ControlType type,
 		return ControlValue(value);
 	}
 
-	default:
+	case ControlTypeNone:
 		return ControlValue();
 	}
 }