Commit c797b07e authored by Robert Edmonds's avatar Robert Edmonds

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.
parent 934ff223
...@@ -28,11 +28,16 @@ ...@@ -28,11 +28,16 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* 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. */ #define PROTOBUF_C_SERVICE_DESCRIPTOR_MAGIC 0x14159bc3
#define PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9
#define PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC 0x114315af
/*
* 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 #ifndef _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE
#define _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \ #define _PROTOBUF_C_FORCE_ENUM_TO_BE_INT_SIZE(enum_name) \
, _##enum_name##_IS_INT_SIZE = INT_MAX , _##enum_name##_IS_INT_SIZE = INT_MAX
...@@ -40,55 +45,60 @@ ...@@ -40,55 +45,60 @@
/* === needs to be declared for the PROTOBUF_C_BUFFER_SIMPLE_INIT macro === */ /* === needs to be declared for the PROTOBUF_C_BUFFER_SIMPLE_INIT macro === */
void protobuf_c_buffer_simple_append (ProtobufCBuffer *buffer, void
protobuf_c_buffer_simple_append(
ProtobufCBuffer *buffer,
size_t len, size_t len,
const unsigned char *data); const unsigned char *data);
/* === stuff which needs to be declared for use in the generated code === */ /* === stuff which needs to be declared for use in the generated code === */
struct _ProtobufCEnumValueIndex struct _ProtobufCEnumValueIndex {
{
const char *name; const char *name;
unsigned index; /* into values[] array */ unsigned index; /* into values[] array */
}; };
/* IntRange: helper structure for optimizing /*
int => index lookups * IntRange: helper structure for optimizing int => index lookups in the case
in the case where the keys are mostly consecutive values, * where the keys are mostly consecutive values, as they presumably are for
as they presumably are for enums and fields. * enums and fields.
*
The data structures assumes that the values in the original * The data structures assumes that the values in the original array are
array are sorted */ * sorted.
struct _ProtobufCIntRange */
{ struct _ProtobufCIntRange {
int start_value; int start_value;
unsigned orig_index; unsigned orig_index;
/* NOTE: the number of values in the range can /*
be inferred by looking at the next element's orig_index. * NOTE: the number of values in the range can be inferred by looking
a dummy element is added to make this simple */ * at the next element's orig_index. A dummy element is added to make
* this simple.
*/
}; };
/* === declared for exposition on ProtobufCIntRange === */ /* === declared for exposition on ProtobufCIntRange === */
/* note: ranges must have an extra sentinel IntRange at the end whose
orig_index is set to the number of actual values in the original array */
/* returns -1 if no orig_index found */
int protobuf_c_int_ranges_lookup (unsigned n_ranges,
ProtobufCIntRange *ranges);
#define PROTOBUF_C_SERVICE_DESCRIPTOR_MAGIC 0x14159bc3 /*
#define PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC 0x28aaeef9 * Note: ranges must have an extra sentinel IntRange at the end whose
#define PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC 0x114315af * orig_index is set to the number of actual values in the original array.
* Returns -1 if no orig_index found.
*/
int
protobuf_c_int_ranges_lookup(unsigned n_ranges, ProtobufCIntRange *ranges);
/* === behind the scenes on the generated service's __init functions */ /* === behind the scenes on the generated service's __init functions */
typedef void (*ProtobufCServiceDestroy) (ProtobufCService *service);
typedef void (*ProtobufCServiceDestroy)(ProtobufCService *);
void void
protobuf_c_service_generated_init (ProtobufCService *service, protobuf_c_service_generated_init(
ProtobufCService *service,
const ProtobufCServiceDescriptor *descriptor, const ProtobufCServiceDescriptor *descriptor,
ProtobufCServiceDestroy destroy); ProtobufCServiceDestroy destroy);
void void
protobuf_c_service_invoke_internal(ProtobufCService *service, protobuf_c_service_invoke_internal(
ProtobufCService *service,
unsigned method_index, unsigned method_index,
const ProtobufCMessage *input, const ProtobufCMessage *input,
ProtobufCClosure closure, ProtobufCClosure closure,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment