473 Commits

Author SHA1 Message Date
Robert Edmonds
09b801a968 protobuf-c: replace DO_ALLOC, FREE, system_alloc, system_free with inline memory allocation functions
this reworks memory allocation throughout the support library.

the old DO_ALLOC macro had several problems:

  1) only by reading the macro implementation is it possible to tell
  what actually occurs. consider:

        DO_ALLOC(x, ...);

  vs.:

        x = do_alloc(...);

  only in the latter is it clear that x is being assigned to.

  2) it looks like a typical macro/function call, except it alters the
  control flow, usually by return'ing or executing a goto in the
  enclosing function. this type of anti-pattern is explicitly called out
  in the linux kernel coding style.

  3) in one instance, setting the destination pointer to NULL is
  actually a *success* return. in parse_required_member(), when parsing
  a PROTOBUF_C_TYPE_BYTES wire field, it is possible that the field is
  present but of zero length, in which case memory shouldn't be
  allocated and nothing should actually be copied. this is not apparent
  from reading:

        DO_ALLOC(bd->data, allocator, len - pref_len, return 0);
        memcpy(bd->data, data + pref_len, len - pref_len);

  instead, make this behavior explicit:

        if (len - pref_len > 0) {
                bd->data = do_alloc(allocator, len - pref_len);
                if (bd->data == NULL)
                        return 0;
                memcpy(bd->data, data + pref_len, len - pref_len);
        }

  this is much more readable and makes it possible to write a
  replacement for DO_ALLOC which returns NULL on failures.

this changes the protobuf_c_default_allocator to contain only NULL
values; if a replacement function pointer is not present (non-NULL) in
this struct, the default malloc/free implementations are used. this
makes it impossible to call the default allocator functions directly and
represents an API/ABI break, which required a fix to the
PROTOBUF_C_BUFFER_SIMPLE_CLEAR macro.

despite turning one-line allocations in the simple case:

	DO_ALLOC(rv, allocator, desc->sizeof_message, return NULL);

into three-line statements like:

	rv = do_alloc(allocator, desc->sizeof_message);
	if (!rv)
		return (NULL);

this changeset actually *reduces* the total number of lines in the
support library.
2014-01-13 19:53:41 -05:00
Robert Edmonds
8216865a46 protobuf-c: remove alloc_failed_warning and protobuf_c_out_of_memory
in general, libraries shouldn't be responsible for terminating the
program if memory allocation fails. if we need to allocate memory and
can't, we should be returning a failure indicator, not providing a
strange interface to the user for receiving a callback in the event of
such an error.

also in general, libraries should never write to stdout or stderr.

this breaks the API/ABI and will require a note in the ChangeLog.
2014-01-13 15:35:44 -05:00
Robert Edmonds
8cd5f6764b protobuf-c: remove tmp_alloc and max_alloca fields of ProtobufCAllocator
i'm confused as to why these fields exist, since the typical
implementation of a "temporary alloc" would be something like alloca(),
and alloca() is usually just inlined code that adjusts the stack
pointer, which is not a function whose address could be taken.

this breaks the API/ABI and will require a note in the ChangeLog.

possibly we could revisit the idea of "temporary allocations" by using
C99 variable length arrays. this would have the advantage of being
standardized, unlike alloca().
2014-01-13 15:35:42 -05:00
Robert Edmonds
a533b594f7 spelling: "prefered" -> "preferred" 2014-01-13 14:57:54 -05:00
Robert Edmonds
871d678738 protobuf-c: remove UNALIGNED_ALLOC, DO_UNALIGNED_ALLOC macros 2014-01-13 14:19:28 -05:00
Robert Edmonds
b8c5e06de3 ChangeLog: coverity fixes 2014-01-11 15:52:16 -05:00
Robert Edmonds
da3dd5239a GenerateMessageDescriptor(): free field_indices, Coverity #1153644 2014-01-11 15:44:36 -05:00
Robert Edmonds
92b31528f8 GenerateEnumDescriptor(): free value_index, Coverity #1153645 2014-01-11 15:42:24 -05:00
Robert Edmonds
fb44851b4e GenerateEnumDescriptor(): free name_index, Coverity #1153646 2014-01-11 15:40:27 -05:00
Robert Edmonds
5a43922c6a GenerateServiceDescriptor(): free mi_array, Coverity #1153647 2014-01-11 15:38:29 -05:00
Robert Edmonds
aae02aa008 protobuf_c_message_unpack(): reflow some long lines for readability 2014-01-11 15:31:34 -05:00
Robert Edmonds
596352bb22 protobuf_c_message_unpack(): initialize tmp.length_prefix_len
this should silence Coverity #1153648, which complains because
tmp.length_prefix_len is uninitialized for certain wire types when
copied on line 2486:

    scanned_member_slabs[which_slab][in_slab_index++] = tmp;
2014-01-11 15:28:47 -05:00
Robert Edmonds
ac71dd5859 configure.ac: error out if protoc is not found 2014-01-11 15:04:30 -05:00
Robert Edmonds
c797b07eec protobuf-c/: gratuitous style changes
dave's original style drives me crazy. reformat the C code in
protobuf-c/ with "indent -kr -i8" and manually reflow for readability.

try to fit most lines in 80 columns, but due to the lengthy type and
function names in protobuf-c, enforcing an 80 column rule would result
in a lot of cramped statements, so try to fit lines in up to 100 columns
if it would improve readability. (e.g., one <=100 column line is
probably better than 3-4 <=80 column lines.)

ultimately i'd like to adopt most of the recommendations in the linux
coding style: https://www.kernel.org/doc/Documentation/CodingStyle.
this commit gets us most of the kernel indentation and comment coding
style recommendations. later commits will tackle style recommendations
that require more intrusive changes: breaking up large functions,
replacing macros that affect control flow (e.g., DO_ALLOC). this will
hopefully facilitate review and make the code base easier to maintain.

i ran the old and new versions of protobuf-c.c through something like:

  gcc -S -D__PRETTY_FUNCTION__=0 -D__FILE__=0 -D__LINE__=0 -Wall -O0 \
    -o protobuf-c.S -c protobuf-c.c

and reviewed the diffs of the assembly output to spot any functions that
changed, and went back to make sure that any differences were
functionally equivalent.
2014-01-11 13:41:11 -05:00
Robert Edmonds
934ff223db README.md: update due to the protobuf-c-rpc split out 2014-01-10 13:25:11 -05:00
Robert Edmonds
e3c49dfff2 TODO: remove protobuf-c-rpc 2014-01-10 13:25:11 -05:00
Robert Edmonds
ce1c8bbeb5 protobuf-c-rpc/: remove 2014-01-10 13:25:11 -05:00
Robert Edmonds
10e451eb6a .gitignore: remove protobuf-c-rpc 2014-01-10 13:25:11 -05:00
Robert Edmonds
5c4f8eafa7 .travis.yml: remove protobuf-c-rpc 2014-01-10 13:25:11 -05:00
Robert Edmonds
410a5b8e4e configure.ac: remove protobuf-c-rpc 2014-01-10 13:25:11 -05:00
Robert Edmonds
e8a55cf186 Makefile.am: remove protobuf-c-rpc 2014-01-10 13:25:11 -05:00
Ilya Lipnitskiy
0e9f999aa8 protobuf-c/protobuf-c.c: do not print unpack errors by default
(fixes #26)
2013-12-21 00:05:11 -08:00
Nick Galbreath
c1ff5d6bad protobuf-c/protobuf-c.c: prevent possible overflow on 64-bit systems
(fixes #106)
2013-12-20 23:45:19 -08:00
Ilya Lipnitskiy
b915eed32f protobuf-c/protobuf-c.c: fix compiler warnings (fixes #115)
protoc-c/c_enum.cc: fix compiler warnings
protoc-c/c_field.cc: fix compiler warnings
2013-12-17 00:08:42 -08:00
Robert Edmonds
9f39b7621e LICENSE: add a statement about the ownership of protoc-c output
Signed-off-by: Dave Benson <lahiker42@gmail.com>
2013-12-09 14:09:10 -05:00
Robert Edmonds
db4ab0ee85 ChangeLog: fix trailing whitespace 2013-12-09 14:08:57 -05:00
Ilya Lipnitskiy
ffb1c2462a protobuf-c/protobuf-c.c: add explicit casts in parsing functions for
better compatibility with 8- and 16-bit platforms (integrate fixes
from #47)
2013-12-03 22:40:40 -08:00
Ilya Lipnitskiy
5b3ac9ca97 protobuf-c.c: wrap DO_ALLOC macro in a do {} while(0) statement 2013-12-02 15:43:08 -08:00
Ilya Lipnitskiy
3ec5aa1256 protobuf-c-rpc/protobuf-c-rpc.c: remove the duplicate call to
protobuf_c_dispatch_close_fd() (fixes #82)
2013-11-27 16:13:24 -08:00
Ilya Lipnitskiy
b5b1d4e907 protobuf-c/protobuf-c.{c,h}: remove the unused protobuf_c_system_allocator 2013-11-27 15:53:56 -08:00
Ilya Lipnitskiy
b1056e922a protobuf-c-rpc/protobuf-c-rpc.c: perform a more thorough message
check for server closures (responses) to not crash the server in case of
a malformed message (related to #76)
2013-11-27 15:21:40 -08:00
Ilya Lipnitskiy
fb39c17616 protobuf-c/protobuf-c.c: add a few extra checks to
protobuf_c_message_check
2013-11-27 15:21:02 -08:00
Ilya Lipnitskiy
746ea972bc protobuf-c/protobuf-c.c: fix a logic error when a failed merge would
leave a dangling pointer to the parsed submessage
2013-11-22 17:37:09 -08:00
Ilya Lipnitskiy
7b665e9ce4 protobuf-c/protobuf-c.c: add return code check to merge_messages calls 2013-11-22 17:31:00 -08:00
Robert Edmonds
54464b90c4 ChangeLog: Issue #91 2013-11-22 19:48:44 -05:00
Ilya Lipnitskiy
b00f6d221c t/generated-code2/test-generated-code2.c: Rename test_optional_merge to
test_field_merge
2013-11-22 16:35:19 -08:00
Ilya Lipnitskiy
f4b9fd20a5 protobuf-c/protobuf-c.c: add functionality to merge multiple instances
of the same field on the wire (Fixes #91)
t/generated-code2/test-generated-code2.c: add a test case for merging
messages
t/test-full.proto: expand message definitions to test for merging nested
messages
2013-11-22 15:34:07 -08:00
Robert Edmonds
1f5e813fe7 protobuf-c/protobuf-c.c: the no_unpacking_needed case only executes on little endian 2013-11-21 17:13:11 -05:00
Robert Edmonds
49faa55bc2 IS_LITTLE_ENDIAN -> !defined(WORDS_BIGENDIAN)
this simplifies the AC_C_BIGENDIAN invocation.
2013-11-21 17:12:00 -05:00
Robert Edmonds
97c43baba3 there's no protobuf-c-config.h file with the new build system 2013-11-20 15:30:15 -05:00
Robert Edmonds
7c7cc361b5 ChangeLog: 0.16 updates 2013-11-20 15:04:46 -05:00
Robert Edmonds
3b3f78ce5d Makefile.am: bump libprotobuf-c SONAME 2013-11-20 15:04:24 -05:00
Robert Edmonds
79f2767e1c remove alloca() remnants 2013-11-20 14:41:54 -05:00
Ilya Lipnitskiy
5f122c44e0 protoc-c/main.cc: add a version string to protoc-c based on the
PACKAGE_STRING provided by autotools (fixes #52)
2013-11-19 00:11:05 -08:00
Ilya Lipnitskiy
59688a92b3 protobuf-c-rpc/protobuf-c-rpc.c: free the timer created by autoreconnect
in case the client has failed to connect and got destroyed (fixes #70)

protobuf-c-rpc/t/test-rpc.c: add a test case for #70
2013-11-18 22:22:46 -08:00
Ilya Lipnitskiy
5d74333219 protobuf-c-rpc/protobuf-c-rpc.c: handle server responses with NULL
messages on the client side (fixes #78)

protobuf-c-rpc/t/test-rpc.c: add a test case for #78
2013-11-18 22:14:36 -08:00
Ilya Lipnitskiy
4610a0d40e protobuf-c-rpc/protobuf-c-rpc.c: rename AF_LOCAL to AF_UNIX (Fixes #100) 2013-11-18 22:03:42 -08:00
Ilya Lipnitskiy
e9529ac463 .gitignore: Ignore temporary files that end with ~ 2013-11-18 21:08:53 -08:00
Ilya Lipnitskiy
0508aa0d6e protoc-c/c_file.cc: Add source .proto file name to the generated files 2013-11-18 21:05:44 -08:00
Robert Edmonds
2689e06257 README.md: add a section on contributing patches 2013-11-18 20:41:22 -05:00