Commit ccfedab5 authored by lahiker42@gmail.com's avatar lahiker42@gmail.com

switch to using a fixed-size hash-table for detecting missing required fields,

it is only approximate now, but it should be good enough

git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@327 00440858-1255-0410-a3e6-75ea37f81c3a
parent b69033fd
......@@ -13,6 +13,9 @@
See Issue #63 for demo (w/ nice test case by dror.harari).
- add PROTOBUF_C_{MAJOR,MINOR} for compile-time checks and
protobuf_c_{major,minor} for checks about the running library. (Issue #53)
- 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)
0.15:
- make protobuf_c_message_init() into a function (Issue #49, daveb)
......
......@@ -63,11 +63,14 @@
#include <stdio.h> /* for occasional printf()s */
#include <stdlib.h> /* for abort(), malloc() etc */
#include <string.h> /* for strlen(), memcpy(), memmove() */
#if 0 /* we no longer use alloca. */
#if HAVE_ALLOCA_H
#include <alloca.h>
#elif HAVE_MALLOC_H
#include <malloc.h>
#endif
#endif
#ifndef PRINT_UNPACK_ERRORS
#define PRINT_UNPACK_ERRORS 1
......@@ -80,6 +83,14 @@ unsigned protobuf_c_minor = PROTOBUF_C_MINOR;
#define MAX_UINT64_ENCODED_SIZE 10
/* This should be roughly the biggest message you think you'll encounter.
However, the only point of the hashing is to detect uninitialized required members.
I doubt many messages have 128 REQUIRED fields, so hopefully this'll be fine.
TODO: A better solution is to separately in the descriptor index the required fields,
and use the allcoator if the required field count is too big. */
#define MAX_MEMBERS_FOR_HASH_SIZE 128
/* convenience macros */
#define TMPALLOC(allocator, size) ((allocator)->tmp_alloc ((allocator)->allocator_data, (size)))
#define FREE(allocator, ptr) \
......@@ -2153,7 +2164,7 @@ protobuf_c_message_unpack (const ProtobufCMessageDescriptor *desc,
unsigned f;
unsigned i_slab;
unsigned last_field_index = 0;
unsigned char required_fields_bitmap[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
unsigned char required_fields_bitmap[MAX_MEMBERS_FOR_HASH_SIZE/8] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
static const unsigned word_bits = sizeof(long) * 8;
ASSERT_IS_MESSAGE_DESCRIPTOR (desc);
......
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