30 Commits

Author SHA1 Message Date
Robert Edmonds
7b90330bff Use GOOGLE_LOG(FATAL) instead of GOOGLE_LOG(DFATAL)
Looking at where these identifiers are ultimately defined [0], it looks
like "DFATAL" means either "ERROR" or "FATAL" depending on whether
NDEBUG is defined. However, looking at the actual code sites in protoc-c
where DFATAL is used, it's not clear why we couldn't just use FATAL
unconditionally.

This is aimed at supporting newer versions of protobuf where the DFATAL
identifier apparently no longer exists.

[0] https://github.com/protocolbuffers/protobuf/blob/v21.12/src/google/protobuf/stubs/logging.h#L61-L65
2023-07-02 19:35:43 -04:00
Ilya Lipnitskiy
7df109917a
protoc-c: add c_package option
This option allows to override the top-level 'package' setting, or even
remove the package prefix altogether (if set to "").

Fixes #322
2021-03-21 21:11:51 -07:00
Ilya Lipnitskiy
4f39ca6e0c
protoc-c: don't use FullName helpers for non-full names
FullName* methods are designed to split a full name based on '.' in the
name. name() does not have '.' separators, so call CamelToLower and
CamelToUpper in place of FullNameToLower and FullNameToUpper.
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
cebe3d03f9
protoc-c: add string as bytes option
Allows treating proto strings as ProtobufCBinaryData to work around
limitations such as NULL characters in strings, which are allowed in
protobuf, but not allowed in 'char *' types.

Fixes #203
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
6962695641
protoc-c: add option to customize base field name
Fixes #287
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
baa860ff97
protoc-c: add options for function generation
Add options controller helper function generation. Preserve existing
behavior of not generating pack/unpack functions for sub-messages if
option is not explicitly set.

Fixes #240
Fixes #442
2021-03-21 21:11:49 -07:00
Ilya Lipnitskiy
0e060260f0
protoc-c: add custom options support 2021-03-21 20:28:33 -07:00
Robert Edmonds
94532c7a63
Merge pull request #443 from acozzette/std-string
Updated the generator to fully qualify std::string
2020-10-16 20:03:05 -04:00
Adam Cozzette
3d2ed0d410 Updated the generator to fully qualify std::string
The protobuf common.h header currently has a "using std::string;"
statement that pulls std::string into the google::protobuf namespace:
ce66f6047d/src/google/protobuf/stubs/common.h (L195)

I plan to delete that line soon. To keep protobuf-c working, this commit
updates the generator to fully qualify std::string.
2020-10-16 16:45:21 -07:00
Robert Edmonds
d18a21d5ba
Merge pull request #430 from protobuf-c/ilya-underscore
protoc-c: Remove leading underscores from structs
2020-06-20 15:56:46 -04:00
Ilya Lipnitskiy
cd671dbc3d protobuf-c.c, protoc-c: Remove leading underscores
Fixes #188.

Implements suggested fix from the issue:
The struct tag namespace is different from the type namespace. Use the
same symbol names (i.e. without leading underscores) in every namespace.
2020-05-13 15:30:20 -07:00
Ilya Lipnitskiy
93afe2d52d c_message.cc: Resolve name conflict (Fixes #389) 2020-05-12 12:21:48 -07:00
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
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
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
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
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
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
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
da3dd5239a GenerateMessageDescriptor(): free field_indices, Coverity #1153644 2014-01-11 15:44:36 -05: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
653c04ea2c protoc-c/: fix include paths 2013-11-16 17:11:48 -05:00
Robert Edmonds
bbed775dae compiler/ -> protoc-c/ 2013-11-16 15:48:12 -05:00