52 Commits

Author SHA1 Message Date
Robert Edmonds
83c59e705f Convert uses of protobuf's scoped_ptr.h to C++11 std::unique_ptr
Upstream protobuf removed scoped_ptr.h, which provided the scoped_ptr
that we depended on, in commit 67952fab2c766ac5eacc15bb78e5af4039a3d398
(67952fab2c).

This commit converts uses of scoped_ptr type to idiomatic C++11
std::unique_ptr, similar to the changes in the protobuf commit.

This has been tested on protobuf 3.0.0 (the version currently in Debian)
as well as the latest protobuf 3.6.1 release.
2018-08-13 21:26:00 -04:00
Robert Edmonds
26a836423c
Merge pull request #309 from iveqy/add_std
Add std:: to some types
2018-08-13 20:57:46 -04:00
Fredrik Gustafsson
034e603d2a Add std:: to some types
This is required for compilation to succeed on debian jessie with g++
6.3.0.
2018-03-11 08:57:46 +01:00
Robert Edmonds
4302266b45 Restore protobuf-2.x compatibility
The change in commit 712154b912de824741381c0bb26c2fbed54515a3 ("Bump
minimum required header version for proto3 syntax") uses functionality
only exposed by protobuf-3.x, breaking the build when compiling against
protobuf-2.x.

Since we still want to support building against protobuf-2.x, this
commit makes the proto3 syntax check in the file generator dependent on
building against protobuf-3.x.
2017-08-07 12:31:55 -04:00
Robert Edmonds
712154b912 Bump minimum required header version for proto3 syntax
The changes in #274 (proto3: make strings default to "" instead of NULL)
add a new symbol to the library and add an 'extern' declaration to the
protobuf-c header file.

Since the compiler may generate files that depend on that new
'protobuf_c_empty_string' declaration in protobuf-c.h, we need to bump
the min_header_version value that is written into generated header
files. But since the 'protobuf_c_empty_string' symbol can only be
referenced when generating proto3 syntax files, we only need to use the
stricter min_header_version value when processing a proto3 file.
2017-07-29 20:16:22 -04:00
Robert Edmonds
582cad8bff Fix namespace errors when compiled with latest protobuf
The protobuf project removed "using namespace std" namespace pollution
from their stubs/common.h header file. This caused build failures for us
since we relied on their namespace pollution.

This commit updates protobuf-c to convert:

 'map' → 'std::map'
 'set' → 'std::set'
 'back_insert_iterator' → 'std::back_insert_iterator'
2017-07-29 18:52:28 -04:00
Paolo Borelli
2a46af4278 proto3: make strings default to "" instead of NULL
The spec talks about "empty string" and other languages like C#
return a zero length string and not null.
This is useful because when moving from proto2's "required string"
to a proto3's plain string we will be guaranteed that we
never get a null pointer.
The tradeoff is adding a special case to the library but avoiding
a lot of null checks in the calling code.
The current code is already special casing "" in pack_string.
2017-06-12 09:32:39 +02:00
Robert Edmonds
c48d932003 Merge pull request #228 from pbor/wip/proto3
proto3 support
2017-02-25 14:20:04 -08:00
Robert Edmonds
638c54d4db GenerateStructDefinition(): Reset vars["opt_comma"] when processing multiple oneofs
This commit fixes #251, which causes incorrect code to be generated when
there are multiple oneofs in the same message.

In #221, we added code to force int-sizing for oneof enums, but we only
set vars["opt_comma"] initially, before entering the loop over the
message's oneofs. This caused commas to be omitted when generating the
enums for subsequent oneofs after the first oneof.

This commit resets vars["opt_comma"] every time through the loop that
generates the enum declarations for the message's oneofs.
2017-02-25 15:52:39 -05:00
Robert Edmonds
956ea86712 GenerateStructDefinition(): Append oneof name when forcing enums to be int size
This commit fixes a problem identified in #251. When generating the
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE directive at the end of the enum
values generated for a oneof, we inadvertently only included the
protobuf class name in the call to the directive. This breaks if there
is more than one oneof per protobuf class, which causes duplicate enum
names to be generated.

This issue is fixed by also appending the oneof's name to the protobuf
class name when generating the PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE
directive, which should cause unique enum names to be generated.

This changes the enum name that is generated, but these names are
implementation details since they are sentinel values that only exist to
force the compiler to size the enum type correctly.

(The test case for #220 is updated since that test relies on the
oneof implementation details in the code generator.)
2017-02-25 15:52:39 -05:00
Richard Kettlewell
c23065e4b1 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.
2017-02-25 19:59:17 +00:00
Paolo Borelli
8194f4d91a proto3 support
This is a first cut at adding proto3 support.

As far as I understand protobuf-c already has pretty much everything
needed once it is built using a new version of protobuf itself.
The only missing thing is that in proto3 all fields are optional and
having to manually set has_foo is inconvenient.

This patch special cases the proto3 syntax files so that structs for the
bytes, enum and primitive fields do not emit the has_ field.

It also adds PROTOBUF_C_LABEL_NONE to the label enum that is used for
proto3 fields. When a fields has this label, the quantifier is not
consulted and instead the field is packed/unpacked depending on
whether it has a value different from NULL/0.
2016-10-30 10:06:52 +01:00
Thomas Köckerbauer
f73cc06d1e make init_value const 2016-09-07 15:18:41 +02:00
Ilya Lipnitskiy
bb6553c397 protoc-c/c_message.cc: Force int size on oneof enums
Fixes #220. Patch by Dave Benson from the mailing list thread.
2016-06-17 00:27:34 -07:00
Robert Edmonds
171ccd222b Merge remote-tracking branch 'pbor/wip/plugin' into next 2016-04-25 21:40:37 -04:00
Ilya Lipnitskiy
258eb7d4dc protoc-c/c_enum_field.cc: Fix default enum values
From https://developers.google.com/protocol-buffers/docs/proto#optional:
If the default value is not specified for an optional element, a
type-specific default value is used instead: for strings, the default
value is the empty string. For bools, the default value is false. For
numeric types, the default value is zero. For enums, the default value
is the first value listed in the enum's type definition. This means care
must be taken when adding a value to the beginning of an enum value
list.

Prior to this change, protoc-c set the default enum value to 0, whether
or not 0 was the first value listed in the enum's type definition (or if
it even was listed at all).
2016-04-22 11:12:15 -07:00
Paolo Borelli
af2120aa55 Turn the compiler into a protoc plugin
Using the old "protoc-c" command directly is still supported
through a symlink.
2016-02-17 10:58:43 +01:00
Paolo Borelli
af613f932a Fix union initialization
Using {} as an initializer fails on MSVC

Signed-off-by: Paolo Borelli <pborelli@gnome.org>
2016-02-02 14:45:29 -05:00
Ilya Lipnitskiy
0e2d3c09e2 Rename LITE_RUNTIME to CODE_SIZE 2015-10-30 15:54:00 -07:00
Ilya Lipnitskiy
603e431864 protoc-c: Support the optimize_for = LITE_RUNTIME file option
Adds support for the LITE_RUNTIME optimization option to the protobuf-c
compiler. Enabling this option would generate lighter weight message,
enum, and service descriptors that contain NO strings. As a result,
calls to lookup descriptors via the *_get_{field,value,method}_by_name
API will return NULL.

Default compiler behavior (when optimize_for is not specified or is not
set to LITE_RUNTIME) is unchanged.
2015-03-15 20:01:03 -07:00
Andrey Myznikov
812ecf9326 Fix incorrect 'Short version of service name' generation for ProtobufCServiceDescriptor 2015-03-14 16:00:28 -04:00
Robert Edmonds
cbe7b84a14 Merge remote-tracking branch 'github/protoc_c_comments' into next 2015-03-13 12:42:51 -04:00
Ilya Lipnitskiy
b64f6c1f68 protoc-c/c_enum.cc: Make enum_values_{by_name,by_number} structs static 2015-02-14 19:21:29 -08:00
Ilya Lipnitskiy
8f42a69f86 protoc-c/c_helpers.cc: Enhance comment string parsing
Certain protobuf comments could generate invalid C comments
and inadvertently close the comment block. This commit removes '/'
signs in such comments.

One example of a .proto file containing such comments is a commonly
included descriptor.proto from the protobuf library.
2015-01-30 20:11:34 -08:00
Ilya Lipnitskiy
35ec2e2f9c protoc-c: Print comments for generated enum, message, and field definitions 2014-12-16 18:12:54 -08:00
Ilya Lipnitskiy
9db84a3b90 protoc-c: Implement oneofs 2014-11-19 23:07:23 -08:00
Robert Edmonds
8655ca076d PROTOBUF_C_{NO_,}DEPRECATED -> PROTOBUF_C__{NO_,}DEPRECATED
these identifiers aren't intended for use by client code. add a double
underscore to indicate this.
2014-06-06 14:55:11 -04:00
Robert Edmonds
af5120e678 PROTOBUF_C_{BEGIN,END}_DECLS -> PROTOBUF_C__{BEGIN,END}_DECLS
these identifiers aren't intended for use by client code. add a double
underscore to indicate this.
2014-06-06 14:50:14 -04:00
Andrei Nigmatulin
94e7cde263 cosmetics 2014-06-06 14:48:59 -04:00
Robert Edmonds
c96fee16c2 PROTOBUF_C_OFFSETOF -> offsetof
offsetof() conforms to the C89 standard, just call it directly.
2014-06-04 17:28:51 -04:00
Robert Edmonds
97b6aa368b use double underscores in the MAGIC identifiers
these magic constants aren't intended for use by client code. add a
double underscore to indicate this.
2014-06-04 17:17:15 -04:00
Robert Edmonds
d0cadf1a4a PROTOBUF_C_ASSERT -> assert
assert() conforms to the C89 standard, just call it directly.
2014-06-04 17:14:44 -04:00
Robert Edmonds
ecc4febaba _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE -> PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE
identifiers that begin with an underscore are reserved. instead, use a
double underscore in the *middle* of the identifier to indicate that
it's an "internal" identifier.
2014-06-03 17:43:21 -04:00
Robert Edmonds
9fa749d679 loosen the coupling between protoc-c and the protobuf-c headers
exact version coupling between the compiler and the public headers is
too strict because some existing projects (such as collectd,
riemann-c-client, and nmsg) directly embed .pb-c.h files generated by
protoc-c into their exported headers. this would cause unnecessary build
failures in downstream clients of these libraries if a newer version of
the protobuf-c headers is installed.

however, it's still desireable to be able to explicitly declare when
compatibility is broken between the headers and the compiler, so
introduce new variables that allow independently setting the minimum
header version required by the compiler and the minimum compiler version
required by the header.

this follows the protobuf C++ implementation a little bit more closely,
though we don't have an analogous facility for verifying that the header
and *library* are compatible. (this seems like overkill for a C project;
in practice the headers and the library will be from the same version,
especially in downstream distributors like debian where the -dev package
has an exact versioned dependency on the shared library package.)
2014-06-03 13:54:50 -04:00
Robert Edmonds
c7c7850b51 tightly couple protoc-c output with the protobuf-c headers
this adds a version guard like the protobuf C++ implementation. it
ensures that protoc-c and <protobuf-c.h> are from the exact same version
of protobuf-c.
2014-04-03 18:19:00 -04:00
Andrei Nigmatulin
e962705437 added deprecated flag into ProtobufCFieldDescriptor->flags
[edmonds@fsi.io: resolve merge conflicts, add documentation]
2014-04-03 11:41:13 -04:00
Robert Edmonds
8a71fdab60 minor adjustments to the field flags patch
rename PROTOBUF_C_FIELD_FLAGS_PACKED to PROTOBUF_C_FIELD_FLAG_PACKED.

rename ProtobufCFieldFlagType to ProtobufCFieldFlag.

wrap some particular long lines.

update documentation.

for clarity, use a "uint32_t" instead of "unsigned" for the 'flags'
field in _ProtobufCFieldDescriptor.
2014-04-03 10:17:14 -04:00
Andrei Nigmatulin
9c6f2fe4d3 turned ProtobufCFieldDescriptor->packed into ->flags 2014-04-03 09:56:03 -04:00
Andrei Nigmatulin
613b367596 fixed gcc warnings 'integer constant is so large that it is unsigned' for large 64 bit constants (default values) 2014-03-29 14:02:37 -04:00
Robert Edmonds
d2658e25fe protoc-c: preserve case in C enum value names (Issue #129)
there is some confusion with regard to the use of lower case letters in
enum values. take the following message definition:

    message LowerCase {
      enum CaseEnum {
        UPPER = 1;
        lower = 2;
      }
      optional CaseEnum value = 1 [default = lower];
    }

this generates the following C enum:

    typedef enum _LowerCase__CaseEnum {
      LOWER_CASE__CASE_ENUM__UPPER = 1,
      LOWER_CASE__CASE_ENUM__lower = 2
        _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE(LOWER_CASE__CASE_ENUM)
    } LowerCase__CaseEnum;

note that the case of the enum value 'lower' was preserved in the C
symbol name as 'LOWER_CASE__CASE_ENUM__lower', but that the _INIT macro
references the same enum value with the (non-existent) C symbol name
'LOWER_CASE__CASE_ENUM__LOWER':

    #define LOWER_CASE__INIT \
     { PROTOBUF_C_MESSAGE_INIT (&lower_case__descriptor) \
        , 0,LOWER_CASE__CASE_ENUM__LOWER }

additionally, the ProtobufCEnumValue array generated also refers to the
same enum value with the (non-existent) upper cased version:

    const ProtobufCEnumValue lower_case__case_enum__enum_values_by_number[2] =
    {
      { "UPPER", "LOWER_CASE__CASE_ENUM__UPPER", 1 },
      { "lower", "LOWER_CASE__CASE_ENUM__LOWER", 2 },
    };

we should preserve the existing behavior of copying the case from the
enum values in the message definition and fix up the places where the
(non-existent) upper case version is used, rather than changing the enum
definition itself to match the case used in the _INIT macro and
enum_values_by_number array, because it's possible that there might be
existing working code that uses enum values with lower case letters that
would be affected by such a change.

incidentally, google's C++ protobuf implementation preserves case in
enum values. protoc --cpp_out generates the following enum declaration
for the message descriptor above:

    enum LowerCase_CaseEnum {
      LowerCase_CaseEnum_UPPER = 1,
      LowerCase_CaseEnum_lower = 2
    };
2014-03-24 18:07:04 -04: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
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
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
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
23c9b03ea7 update copyright and license statements throughout
per https://code.google.com/p/protobuf/source/detail?r=50, the license
on google-originated protobuf code was switched from Apache-2.0 to
BSD-3-Clause (so-called "New BSD" license). update any of the google
license statements to use this new license.

per email with dave, drop the third clause on his BSD-3-Clause license,
so this now becomes BSD-2-Clause.

make sure to use consistent indentation and wrapping throughout.
2013-11-18 20:25:34 -05:00
Robert Edmonds
6f7862963e protoc-c/c_file.cc: fix include path in generated output 2013-11-16 17:12:01 -05:00
Robert Edmonds
653c04ea2c protoc-c/: fix include paths 2013-11-16 17:11:48 -05:00