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
This commit is contained in:
Petteri Aimonen
2013-04-02 19:55:21 +03:00
parent 6f3740f74e
commit 214b0eae8a
11 changed files with 58 additions and 30 deletions

View File

@@ -414,6 +414,12 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type
{
pb_callback_t *pCallback = (pb_callback_t*)iter->pData;
#ifdef PB_OLD_CALLBACK_STYLE
void *arg = pCallback->arg;
#else
void **arg = &(pCallback->arg);
#endif
if (pCallback->funcs.decode == NULL)
return pb_skip_field(stream, wire_type);
@@ -426,7 +432,7 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type
while (substream.bytes_left)
{
if (!pCallback->funcs.decode(&substream, iter->pos, pCallback->arg))
if (!pCallback->funcs.decode(&substream, iter->pos, arg))
PB_RETURN_ERROR(stream, "callback failed");
}
@@ -447,7 +453,7 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type
return false;
substream = pb_istream_from_buffer(buffer, size);
return pCallback->funcs.decode(&substream, iter->pos, pCallback->arg);
return pCallback->funcs.decode(&substream, iter->pos, arg);
}
}