mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-26 21:04:23 +08:00
Allowing <type>__free_unpacked(NULL, ...)
This makes __free_unpacked() consistent with free(), and simplifies callers by allowing them to indiscriminately free message objects without regard to whether they have been allocated or not.
This commit is contained in:
parent
f06a172a91
commit
c23065e4b1
@ -139,7 +139,7 @@ Foo__Bar__BazBah *
|
||||
~~~
|
||||
*
|
||||
* - `free_unpacked()`. Frees a message object obtained with the `unpack()`
|
||||
* method.
|
||||
* method. Freeing `NULL` is allowed (the same as with `free()`).
|
||||
*
|
||||
~~~{.c}
|
||||
void foo__bar__baz_bah__free_unpacked
|
||||
|
2
protoc-c/c_message.cc
Normal file → Executable file
2
protoc-c/c_message.cc
Normal file → Executable file
@ -376,6 +376,8 @@ GenerateHelperFunctionDefinitions(io::Printer* printer, bool is_submessage)
|
||||
" ($classname$ *message,\n"
|
||||
" ProtobufCAllocator *allocator)\n"
|
||||
"{\n"
|
||||
" if(!message)\n"
|
||||
" return;\n"
|
||||
" assert(message->base.descriptor == &$lcclassname$__descriptor);\n"
|
||||
" protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);\n"
|
||||
"}\n"
|
||||
|
8
t/generated-code2/test-generated-code2.c
Normal file → Executable file
8
t/generated-code2/test-generated-code2.c
Normal file → Executable file
@ -2181,6 +2181,12 @@ test_message_check(void)
|
||||
assert(1 == protobuf_c_message_check(&m.base));
|
||||
}
|
||||
|
||||
static void
|
||||
test_message_free_null (void)
|
||||
{
|
||||
foo__sub_mess__free_unpacked (NULL, NULL);
|
||||
}
|
||||
|
||||
/* === simple testing framework === */
|
||||
|
||||
typedef void (*TestFunc) (void);
|
||||
@ -2316,6 +2322,8 @@ static Test tests[] =
|
||||
{ "test field flags", test_field_flags },
|
||||
|
||||
{ "test message_check()", test_message_check },
|
||||
|
||||
{ "test freeing NULL", test_message_free_null },
|
||||
};
|
||||
#define n_tests (sizeof(tests)/sizeof(Test))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user