From 249d3e9c908ea4a3fd2012a753ca7f0cea0b4ee5 Mon Sep 17 00:00:00 2001 From: frsyuki Date: Sun, 15 Feb 2009 09:09:56 +0000 Subject: [PATCH] lang/c/msgpack: removed string type git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@54 5a5092ae-2292-43ba-b2d5-dcab9c1a2731 --- c/bench.c | 6 ++---- c/bench_inline.c | 4 +--- c/unpack.h | 3 +-- c/unpack_inline.c | 7 ++----- msgpack/unpack/callback.h | 2 +- msgpack/unpack/inline_context.h | 2 +- msgpack/unpack/inline_impl.h | 36 +++++++++++++++++---------------- ruby/test_format.rb | 6 ------ ruby/unpack_inline.c | 7 ++----- 9 files changed, 29 insertions(+), 44 deletions(-) diff --git a/c/bench.c b/c/bench.c index f27350a0..91f0c21f 100644 --- a/c/bench.c +++ b/c/bench.c @@ -55,8 +55,7 @@ static void* unpack_array_start(void* data, unsigned int n) { return NULL; } static void unpack_array_item(void* data, void* c, void* o) { } static void* unpack_map_start(void* data, unsigned int n) { return NULL; } static void unpack_map_item(void* data, void* c, void* k, void* v) { } -static void* unpack_string(void* data, const void* b, size_t l) { return NULL; } -static void* unpack_raw(void* data, const void* b, size_t l) { /*printf("unpack raw %p %lu\n",b,l);*/ return NULL; } +static void* unpack_raw(void* data, const void* b, const void* p, size_t l) { /*printf("unpack raw %p %lu\n",p,l);*/ return NULL; } typedef struct { size_t allocated; @@ -119,7 +118,7 @@ void bench_json(void) NULL, NULL, reformat_number, - reformat_string, + reformat_string, reformat_start_map, reformat_map_key, reformat_end_map, @@ -236,7 +235,6 @@ void bench_msgpack(void) unpack_array_item, unpack_map_start, unpack_map_item, - unpack_string, unpack_raw, }; msgpack_unpack_t* mupk = msgpack_unpack_new(NULL, &cb); diff --git a/c/bench_inline.c b/c/bench_inline.c index 29015081..5390319a 100644 --- a/c/bench_inline.c +++ b/c/bench_inline.c @@ -65,8 +65,7 @@ static inline void* msgpack_unpack_array_start(msgpack_unpack_context* x, unsign static inline void msgpack_unpack_array_item(msgpack_unpack_context* x, void* c, void* o) { } static inline void* msgpack_unpack_map_start(msgpack_unpack_context* x, unsigned int n) { return NULL; } static inline void msgpack_unpack_map_item(msgpack_unpack_context* x, void* c, void* k, void* v) { } -static inline void* msgpack_unpack_string(msgpack_unpack_context* x, const void* b, size_t l) { return NULL; } -static inline void* msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, size_t l) { return NULL; } +static inline void* msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, const void* p, size_t l) { return NULL; } #include "msgpack/unpack/inline_impl.h" @@ -131,7 +130,6 @@ void bench_json(void) NULL, NULL, reformat_number, - reformat_string, reformat_start_map, reformat_map_key, reformat_end_map, diff --git a/c/unpack.h b/c/unpack.h index 3230a0d8..094328ec 100644 --- a/c/unpack.h +++ b/c/unpack.h @@ -39,8 +39,7 @@ typedef struct { void (*unpack_array_item)(void* data, void* c, void* o); void* (*unpack_map_start)(void* data, unsigned int n); void (*unpack_map_item)(void* data, void* c, void* k, void* v); - void* (*unpack_string)(void* data, const void* b, size_t l); - void* (*unpack_raw)(void* data, const void* b, size_t l); + void* (*unpack_raw)(void* data, const void* b, const void* p, size_t l); } msgpack_unpack_callback; typedef struct { diff --git a/c/unpack_inline.c b/c/unpack_inline.c index 35254685..d758d3e2 100644 --- a/c/unpack_inline.c +++ b/c/unpack_inline.c @@ -71,11 +71,8 @@ static inline void* msgpack_unpack_map_start(msgpack_unpack_t* x, unsigned int n static inline void msgpack_unpack_map_item(msgpack_unpack_t* x, void* c, void* k, void* v) { x->callback.unpack_map_item(x->data, c, k, v); } -static inline void* msgpack_unpack_string(msgpack_unpack_t* x, const void* b, size_t l) -{ return x->callback.unpack_string(x->data, b, l); } - -static inline void* msgpack_unpack_raw(msgpack_unpack_t* x, const void* b, size_t l) -{ return x->callback.unpack_raw(x->data, b, l); } +static inline void* msgpack_unpack_raw(msgpack_unpack_t* x, const void* b, const void* p, size_t l) +{ return x->callback.unpack_raw(x->data, b, p, l); } #include "msgpack/unpack/inline_impl.h" diff --git a/msgpack/unpack/callback.h b/msgpack/unpack/callback.h index b058a15b..51508cca 100644 --- a/msgpack/unpack/callback.h +++ b/msgpack/unpack/callback.h @@ -20,5 +20,5 @@ msgpack_object msgpack_unpack_array_start(msgpack_unpack_context* x, unsigned in msgpack_object msgpack_unpack_map_start(msgpack_unpack_context* x, unsigned int n); void msgpack_unpack_map_item(msgpack_unpack_context* x, msgpack_object c, msgpack_object k, msgpack_object v); msgpack_object msgpack_unpack_string(msgpack_unpack_context* x, const void* b, size_t l); -msgpack_object msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, size_t l); +msgpack_object msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, const void* p, size_t l); diff --git a/msgpack/unpack/inline_context.h b/msgpack/unpack/inline_context.h index d6558a39..22698d5e 100644 --- a/msgpack/unpack/inline_context.h +++ b/msgpack/unpack/inline_context.h @@ -34,7 +34,7 @@ typedef struct { size_t count; unsigned int ct; union { - const unsigned char* terminal_trail_start; + /*const unsigned char* terminal_trail_start;*/ msgpack_object map_key; } tmp; } msgpack_unpacker_stack; diff --git a/msgpack/unpack/inline_impl.h b/msgpack/unpack/inline_impl.h index f610dd74..fdbe7f67 100644 --- a/msgpack/unpack/inline_impl.h +++ b/msgpack/unpack/inline_impl.h @@ -103,7 +103,7 @@ static inline uint64_t betoh64(uint64_t x) { typedef enum { CS_HEADER = 0x00, // nil - CS_STRING = 0x01, + //CS_STRING = 0x01, //CS_ = 0x02, // false //CS_ = 0x03, // true @@ -186,15 +186,17 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len obj = func(user, arg); \ /*printf("obj %d\n",obj);*/ \ goto _push -#define push_variable_value(func, arg, arglen) \ - obj = func(user, arg, arglen); \ +#define push_variable_value(func, base, pos, len) \ + obj = func(user, (const void*)base, (const void*)pos, len); \ /*printf("obj %d\n",obj);*/ \ goto _push +/* #define again_terminal_trail(_cs, from) \ cs = _cs; \ stack[top].tmp.terminal_trail_start = from; \ goto _terminal_trail_again +*/ #define again_fixed_trail(_cs, trail_len) \ trail = trail_len; \ cs = _cs; \ @@ -237,8 +239,8 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len switch(*p) { case 0xc0: // nil push_simple_value(msgpack_unpack_nil); - case 0xc1: // string - again_terminal_trail(NEXT_CS(p), p+1); + //case 0xc1: // string + // again_terminal_trail(NEXT_CS(p), p+1); case 0xc2: // false push_simple_value(msgpack_unpack_false); case 0xc3: // true @@ -289,16 +291,16 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len // end CS_HEADER - _terminal_trail_again: - ++p; + //_terminal_trail_again: + // ++p; - case CS_STRING: - if(*p == 0) { - const unsigned char* start = stack[top].tmp.terminal_trail_start; - obj = msgpack_unpack_string(user, start, p-start); - goto _push; - } - goto _terminal_trail_again; + //case CS_STRING: + // if(*p == 0) { + // const unsigned char* start = stack[top].tmp.terminal_trail_start; + // obj = msgpack_unpack_string(user, start, p-start); + // goto _push; + // } + // goto _terminal_trail_again; _fixed_trail_again: @@ -343,7 +345,7 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len //case ACS_BIG_INT_VALUE: //_big_int_zero: // // FIXME - // push_variable_value(msgpack_unpack_big_int, n, trail); + // push_variable_value(msgpack_unpack_big_int, data, n, trail); //case CS_BIG_FLOAT_16: // again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t)PTR_CAST_16(n), _big_float_zero); @@ -352,7 +354,7 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len //case ACS_BIG_FLOAT_VALUE: //_big_float_zero: // // FIXME - // push_variable_value(msgpack_unpack_big_float, n, trail); + // push_variable_value(msgpack_unpack_big_float, data, n, trail); case CS_RAW_16: again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t)PTR_CAST_16(n), _raw_zero); @@ -360,7 +362,7 @@ int msgpack_unpacker_execute(msgpack_unpacker* ctx, const char* data, size_t len again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t)PTR_CAST_32(n), _raw_zero); case ACS_RAW_VALUE: _raw_zero: - push_variable_value(msgpack_unpack_raw, n, trail); + push_variable_value(msgpack_unpack_raw, data, n, trail); case CS_ARRAY_16: start_container(msgpack_unpack_array_start, (uint16_t)PTR_CAST_16(n), CT_ARRAY_ITEM); diff --git a/ruby/test_format.rb b/ruby/test_format.rb index 7c2e8fcd..99a27d1b 100644 --- a/ruby/test_format.rb +++ b/ruby/test_format.rb @@ -119,10 +119,4 @@ check([ 0xdf, 0x00, 0x00, 0x00, 0x02, 0xc0, 0xc2, 0xc3, 0xc2, ], [{}, {nil=>false}, {true=>false, nil=>false}, {}, {nil=>false}, {true=>false, nil=>false}]) -# string -check([ - 0x92, - 0xc1, 0x00, - 0xc1, ?a, ?b, ?c, 0x00, -], ["", "abc"]) diff --git a/ruby/unpack_inline.c b/ruby/unpack_inline.c index f6715d9d..b30754b4 100644 --- a/ruby/unpack_inline.c +++ b/ruby/unpack_inline.c @@ -71,11 +71,8 @@ static inline VALUE msgpack_unpack_map_start(msgpack_unpack_context* x, unsigned static inline void msgpack_unpack_map_item(msgpack_unpack_context* x, VALUE c, VALUE k, VALUE v) { rb_hash_aset(c, k, v); } -static inline VALUE msgpack_unpack_string(msgpack_unpack_context* x, const void* b, size_t l) -{ return rb_str_new(b, l); } - -static inline VALUE msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, size_t l) -{ return rb_str_new(b, l); } +static inline VALUE msgpack_unpack_raw(msgpack_unpack_context* x, const void* b, const void* p, size_t l) +{ return rb_str_new(p, l); } #include "msgpack/unpack/inline_impl.h"