mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-26 21:04:23 +08:00
ensure enums are the size of ints
git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@329 00440858-1255-0410-a3e6-75ea37f81c3a
This commit is contained in:
parent
4800e0fba0
commit
d6857c2e9c
@ -16,6 +16,7 @@
|
||||
- use a small constant-size hash-table instead of alloca() for
|
||||
detecting required fields, and it also prevents us from using too
|
||||
much stack, etc. (Related to Issue #60)
|
||||
- add a macro to ensure enums are the size of ints. (Issue #69)
|
||||
|
||||
0.15:
|
||||
- make protobuf_c_message_init() into a function (Issue #49, daveb)
|
||||
|
3
TODO
3
TODO
@ -10,6 +10,9 @@
|
||||
be static??
|
||||
- dispatch-within-dispatch protection needed (ie assert that you can't
|
||||
recursively invoke the main-loop)
|
||||
- uh not sure i like the hash-based situation for required values.
|
||||
perhaps we need a message-descriptor flag to help out. (Could always use
|
||||
different hashes and sizes)
|
||||
|
||||
--------------------
|
||||
--- NEEDED TESTS ---
|
||||
|
@ -39,6 +39,15 @@
|
||||
*/
|
||||
|
||||
|
||||
/* A little enum helper macro: this will ensure that your
|
||||
enum's size is sizeof(int). In protobuf, it need not
|
||||
be larger than 32-bits.
|
||||
|
||||
This is written assuming it is appended to a list w/o a tail comma. */
|
||||
#ifndef _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE
|
||||
#define _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \
|
||||
, _##enum_name##_IS_INT_SIZE = INT_MAX
|
||||
#endif
|
||||
|
||||
/* === needs to be declared for the PROTOBUF_C_BUFFER_SIMPLE_INIT macro === */
|
||||
|
||||
|
@ -44,6 +44,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
|
||||
map<string, string> vars;
|
||||
vars["classname"] = FullNameToC(descriptor_->full_name());
|
||||
vars["shortname"] = descriptor_->name();
|
||||
vars["uc_name"] = FullNameToUpper(descriptor_->full_name());
|
||||
|
||||
printer->Print(vars, "typedef enum _$classname$ {\n");
|
||||
printer->Indent();
|
||||
@ -53,10 +54,10 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
|
||||
|
||||
|
||||
vars["opt_comma"] = ",";
|
||||
vars["prefix"] = FullNameToUpper(descriptor_->full_name()) + "__";
|
||||
for (int i = 0; i < descriptor_->value_count(); i++) {
|
||||
vars["name"] = descriptor_->value(i)->name();
|
||||
vars["number"] = SimpleItoa(descriptor_->value(i)->number());
|
||||
vars["prefix"] = FullNameToUpper(descriptor_->full_name()) + "__";
|
||||
if (i + 1 == descriptor_->value_count())
|
||||
vars["opt_comma"] = "";
|
||||
|
||||
@ -70,6 +71,7 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
|
||||
}
|
||||
}
|
||||
|
||||
printer->Print(vars, " _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE($uc_name$)\n");
|
||||
printer->Outdent();
|
||||
printer->Print(vars, "} $classname$;\n");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user