[vlc-devel] [PATCH 1/2] Use standard error codes

Rémi Denis-Courmont remi at remlab.net
Mon May 20 13:45:22 CEST 2019


Hi,

In which cases can those errors be confused? The whole point is to allow more precise errors (than VLC_EGENERIC), not less.

Le 20 mai 2019 09:43:37 GMT+03:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>On 2019-05-19 19:46, Rémi Denis-Courmont wrote:
>> While this is not complete nor free of ambiguities, this enables a
>lot
>> more expressive error values than the current tiny set. And even
>then,
>> mostly only VLC_EGENERIC and VLC_ENOMEM are ever used.
>> 
>> This also allows passing errors from the CRT or OS.
>> 
>> This assumes that 666 is not an error code that VLC will use though.
>> ---
>>   include/vlc_common.h    | 23 ++++++++++++++---------
>>   modules/lua/libs/misc.c | 23 ++---------------------
>>   2 files changed, 16 insertions(+), 30 deletions(-)
>> 
>> diff --git a/include/vlc_common.h b/include/vlc_common.h
>> index 0bbb98fd62..c6e6b7ae6a 100644
>> --- a/include/vlc_common.h
>> +++ b/include/vlc_common.h
>> @@ -42,6 +42,11 @@
>>  
>/*****************************************************************************
>>    * Required system headers
>>   
>*****************************************************************************/
>> +#ifndef __cplusplus
>> +# include <errno.h>
>> +#else
>> +# include <cerrno>
>> +#endif
>>   #include <stdlib.h>
>>   #include <stdarg.h>
>>   
>> @@ -468,23 +473,23 @@ typedef union
>>    * Error values (shouldn't be exposed)
>>   
>*****************************************************************************/
>>   /** No error */
>> -#define VLC_SUCCESS        (-0)
>> +#define VLC_SUCCESS        0
>>   /** Unspecified error */
>> -#define VLC_EGENERIC       (-1)
>> +#define VLC_EGENERIC       (-666)
>>   /** Not enough memory */
>> -#define VLC_ENOMEM         (-2)
>> +#define VLC_ENOMEM         (-ENOMEM)
>>   /** Timeout */
>> -#define VLC_ETIMEOUT       (-3)
>> +#define VLC_ETIMEOUT       (-ETIMEDOUT)
>>   /** Module not found */
>> -#define VLC_ENOMOD         (-4)
>> +#define VLC_ENOMOD         (-ENOTSUP)
>>   /** Object not found */
>> -#define VLC_ENOOBJ         (-5)
>> +#define VLC_ENOOBJ         (-EFAULT)
>
>We're losing some information about what kind of error this is.
>
>>   /** Variable not found */
>> -#define VLC_ENOVAR         (-6)
>> +#define VLC_ENOVAR         (-EFAULT)
>
>We're losing some information about what kind of error this is.
>
>>   /** Bad variable value */
>> -#define VLC_EBADVAR        (-7)
>> +#define VLC_EBADVAR        (-EINVAL)
>>   /** Item not found */
>> -#define VLC_ENOITEM        (-8)
>> +#define VLC_ENOITEM        (-ENOENT)
>>   
>>  
>/*****************************************************************************
>>    * Variable callbacks: called when the value is modified
>> diff --git a/modules/lua/libs/misc.c b/modules/lua/libs/misc.c
>> index 25f44c3047..c7d47c020b 100644
>> --- a/modules/lua/libs/misc.c
>> +++ b/modules/lua/libs/misc.c
>> @@ -85,27 +85,8 @@ vlc_object_t * vlclua_get_this( lua_State *L )
>>   int vlclua_push_ret( lua_State *L, int i_error )
>>   {
>>       lua_pushnumber( L, i_error );
>> -
>> -    int err;
>> -
>> -    switch( i_error )
>> -    {
>> -        case VLC_SUCCESS:   err = 0;         break;
>> -        case VLC_ENOMEM:    err = ENOMEM;    break;
>> -        case VLC_ETIMEOUT:  err = ETIMEDOUT; break;
>> -        case VLC_EBADVAR:   err = EINVAL;    break;
>> -        case VLC_ENOMOD:    err = ENOENT;    break;
>> -        case VLC_ENOOBJ:    err = ENOENT;    break;
>> -        case VLC_ENOVAR:    err = ENOENT;    break;
>> -        case VLC_EGENERIC:
>> -            lua_pushstring( L, "generic error" );
>> -            return 2;
>> -        default:
>> -            lua_pushstring( L, "unknown error" );
>> -            return 2;
>> -    }
>> -
>> -    lua_pushstring( L, vlc_strerror_c(err) );
>> +    lua_pushstring( L, (i_error == VLC_EGENERIC ? "generic error"
>> +                                                :
>vlc_strerror_c(-i_error)) );
>>       return 2;
>>   }
>>   
>> -- 
>> 2.20.1
>> 
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>> 
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20190520/8b5a6723/attachment.html>


More information about the vlc-devel mailing list