[Libwebsockets] [PATCH] fix callback typedefs and declarations

Denis Osvald denis.osvald at sartura.hr
Wed Jan 6 17:45:38 CET 2016


Hi,

On 01/06/2016 04:47 AM, Andy Green wrote:
> 
> 
> On 01/05/2016 05:59 PM, Denis Osvald wrote:
>> Hi all,
>>
>> I have noticed in the libwebsockets.h two peculiarities:
>>
>> 1. a symbol called `callback` is exported (of type callback_function),
>> but not present anywhere in the library
>>
>> 2. the `callback_function` typedef does not have a lws_ prefix
>>
>> I believe no callback symbol/function needs to be declared in the
>> library,
>> only the callback typedef. So, (1) should be solved by removing the
>> declaration of callback; (2) is simply solved by renaming the typedef.
> 
> This stuff is there to satisfy the inline documentation generation script.
> 
> Rather than remove it, it might make sense to choose a better fake name,
> like __lws_user_callback... it doesn't matter exactly what it is but the
> documentation stuff needed to match to a declaration as I recall.  If
> you want to adapt the patch to do that, I'll be happy to take it.
> 

When making the patch, I did succeed to make the kernel-doc script
generate proper HTML for the typedefs, while also removing the actual
function declaration.

Please try if the whole HTML generates as it should with the patch (I
think it does but don't know the exact command for scripts/kernel-doc to
use so couldn't be sure).

Maybe when I have the exact command to generate html, it would be
appropriate to include a clean diff for the html in the patch v2 then,
or you can just update the doc in a separate commit.

> Also, by the time it got to my email client your patches are mangled and
> won't apply (seems to have lost one of the top context lines in each
> stanza somehow).
> 
> Could you please either attach them as explicit files or push to github.

I put the original patch v1 as an attachment to this message.

Regards,
Denis

> 
> Thanks,
> 
> -Andy
> 
>> Same two issues with extension_callback as well.
>>
>> The patch below renames the callback typedef and moves doc/comment
>> from the unneeded function declaration to the typedef declaration. For
>> kerneldoc to work correctly with function typedef I had to remove parens
>> around typedef name, but I expect no prolems.
>>
>> Below is the patch I have made for renames.
>> Please consider accepting the patch.
>>
>> Regards, Denis
>>
>>  From 2a8caca16c3ece82351d29e0f1e338fcc3dc4e89 Mon Sep 17 00:00:00 2001
>> From: Denis Osvald <denis.osvald at sartura.hr>
>> Date: Mon, 21 Dec 2015 18:06:38 +0100
>> Subject: [PATCH] fix callback typedefs and declarations
>>
>> Remove declarations of callback and extension_callback as these are
>> functions declared in header but not defined anywhere.
>>
>> Also rename typedefs callback_function and extension_callback_function
>> to lws_callback_function and lws_extension_callback_function so all
>> symbolx exported by header have lws prefix;
>>
>> Signed-off-by: Denis Osvald <denis.osvald at sartura.hr>
>> ---
>>   lib/libwebsockets.c         |  2 +-
>>   lib/libwebsockets.h         | 23 +++++++----------------
>>   lib/private-libwebsockets.h |  2 +-
>>   3 files changed, 9 insertions(+), 18 deletions(-)
>>
>> diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
>> index 4035121..c07f9e7 100644
>> --- a/lib/libwebsockets.c
>> +++ b/lib/libwebsockets.c
>> @@ -641,7 +641,7 @@ lws_canonical_hostname(struct lws_context *context)
>>       return (const char *)context->canonical_hostname;
>>   }
>>   -int user_callback_handle_rxflow(callback_function callback_function,
>> +int user_callback_handle_rxflow(lws_callback_function callback_function,
>>                   struct lws *wsi,
>>                   enum lws_callback_reasons reason, void *user,
>>                   void *in, size_t len)
>> diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
>> index 3536125..e875d02 100644
>> --- a/lib/libwebsockets.h
>> +++ b/lib/libwebsockets.h
>> @@ -760,7 +760,7 @@ struct lws_context;
>>   struct lws_extension;
>>    /**
>> - * callback_function() - User server actions
>> + * typedef lws_callback_function() - User server actions
>>    * @wsi:    Opaque websocket instance pointer
>>    * @reason:    The reason for the call
>>    * @user:    Pointer to per-session user data allocated by library
>> @@ -1044,17 +1044,13 @@ struct lws_extension;
>>    *        wsi lifecycle changes if it acquires the same lock for the
>>    *        duration of wsi dereference from the other thread context.
>>    */
>> -LWS_VISIBLE LWS_EXTERN int
>> -callback(const struct lws *wsi, enum lws_callback_reasons reason,
>> void *user,
>> -     void *in, size_t len);
>> -
>>   typedef int
>> -(callback_function)(struct lws *wsi, enum lws_callback_reasons reason,
>> +lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
>>               void *user, void *in, size_t len);
>>    #ifndef LWS_NO_EXTENSIONS
>>   /**
>> - * extension_callback_function() - Hooks to allow extensions to operate
>> + * typedef lws_extension_callback_function() - Hooks to allow
>> extensions to operate
>>    * @context:    Websockets context
>>    * @ext:    This extension
>>    * @wsi:    Opaque websocket instance pointer
>> @@ -1111,13 +1107,8 @@ typedef int
>>    *        buffer safely, it should copy the data into its own buffer
>> and
>>    *        set the lws_tokens token pointer to it.
>>    */
>> -LWS_VISIBLE LWS_EXTERN int
>> -extension_callback(struct lws_context *context, const struct
>> lws_extension *ext,
>> -           struct lws *wsi, enum lws_extension_callback_reasons reason,
>> -           void *user, void *in, size_t len);
>> -
>>   typedef int
>> -(extension_callback_function)(struct lws_context *context,
>> +lws_extension_callback_function(struct lws_context *context,
>>                     const struct lws_extension *ext, struct lws *wsi,
>>                     enum lws_extension_callback_reasons reason,
>>                     void *user, void *in, size_t len);
>> @@ -1165,7 +1156,7 @@ typedef int
>>    struct lws_protocols {
>>       const char *name;
>> -    callback_function *callback;
>> +    lws_callback_function *callback;
>>       size_t per_session_data_size;
>>       size_t rx_buffer_size;
>>       unsigned int id;
>> @@ -1191,7 +1182,7 @@ struct lws_protocols {
>>    struct lws_extension {
>>       const char *name;
>> -    extension_callback_function *callback;
>> +    lws_extension_callback_function *callback;
>>       size_t per_session_data_size;
>>       void *per_context_private_data;
>>   @@ -1201,7 +1192,7 @@ struct lws_extension {
>>   #endif
>>    /**
>> - * struct lws_context_creation_info: parameters to create context with
>> + * struct lws_context_creation_info - parameters to create context with
>>    *
>>    * @port:    Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to
>>    *        suppress listening on any port, that's what you want if
>> you are
>> diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h
>> index 62a3646..ec06ab8 100644
>> --- a/lib/private-libwebsockets.h
>> +++ b/lib/private-libwebsockets.h
>> @@ -1037,7 +1037,7 @@ LWS_EXTERN void
>>   lws_union_transition(struct lws *wsi, enum connection_mode mode);
>>    LWS_EXTERN int
>> -user_callback_handle_rxflow(callback_function, struct lws *wsi,
>> +user_callback_handle_rxflow(lws_callback_function, struct lws *wsi,
>>                   enum lws_callback_reasons reason, void *user,
>>                   void *in, size_t len);
>>   #ifdef LWS_USE_HTTP2
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-fix-callback-typedefs-and-declarations.patch
Type: text/x-patch
Size: 4564 bytes
Desc: not available
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20160106/410826fe/attachment.bin>


More information about the Libwebsockets mailing list