From 214b0eae8aa011fa8b3e8a3dcc784f8d423aeffb Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Tue, 2 Apr 2013 19:55:21 +0300 Subject: Change the callback function to use void**. NOTE: This change breaks backwards-compatibility by default. If you have old callback functions, you can define PB_OLD_CALLBACK_STYLE to retain the old behaviour. If you want to convert your old callbacks to new signature, you need to do the following: 1) Change decode callback argument to void **arg and encode callback argument to void * const *arg. 2) Change any reference to arg into *arg. The rationale for making the new behaviour the default is that it simplifies the common case of "allocate some memory in decode callback". Update issue 69 Status: FixedInGit --- pb_encode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'pb_encode.c') diff --git a/pb_encode.c b/pb_encode.c index 7acee360..48a3c950 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -198,9 +198,16 @@ bool checkreturn encode_static_field(pb_ostream_t *stream, const pb_field_t *fie bool checkreturn encode_callback_field(pb_ostream_t *stream, const pb_field_t *field, const void *pData) { const pb_callback_t *callback = (const pb_callback_t*)pData; + +#ifdef PB_OLD_CALLBACK_STYLE + const void *arg = callback->arg; +#else + void * const *arg = &(callback->arg); +#endif + if (callback->funcs.encode != NULL) { - if (!callback->funcs.encode(stream, field, callback->arg)) + if (!callback->funcs.encode(stream, field, arg)) PB_RETURN_ERROR(stream, "callback error"); } return true; -- cgit 1.2.3-korg