Skip to content

Commit c49489c

Browse files
committed
remove some macros.
1 parent c91131f commit c49489c

File tree

5 files changed

+80
-124
lines changed

5 files changed

+80
-124
lines changed

msgpack/_unpacker.pyx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ cdef extern from "unpack.h":
3030
char *encoding
3131
char *unicode_errors
3232

33-
ctypedef struct template_context:
33+
ctypedef struct unpack_context:
3434
msgpack_user user
3535
PyObject* obj
3636
size_t count
3737
unsigned int ct
3838
PyObject* key
3939

40-
ctypedef int (*execute_fn)(template_context* ctx, const_char_ptr data,
40+
ctypedef int (*execute_fn)(unpack_context* ctx, const_char_ptr data,
4141
size_t len, size_t* off) except? -1
42-
execute_fn template_construct
43-
execute_fn template_skip
42+
execute_fn unpack_construct
43+
execute_fn unpack_skip
4444
execute_fn read_array_header
4545
execute_fn read_map_header
46-
void template_init(template_context* ctx)
47-
object template_data(template_context* ctx)
46+
void unpack_init(unpack_context* ctx)
47+
object unpack_data(unpack_context* ctx)
4848

49-
cdef inline init_ctx(template_context *ctx,
49+
cdef inline init_ctx(unpack_context *ctx,
5050
object object_hook, object object_pairs_hook, object list_hook,
5151
bint use_list, char* encoding, char* unicode_errors):
52-
template_init(ctx)
52+
unpack_init(ctx)
5353
ctx.user.use_list = use_list
5454
ctx.user.object_hook = ctx.user.list_hook = <PyObject*>NULL
5555

@@ -88,7 +88,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
8888
8989
See :class:`Unpacker` for options.
9090
"""
91-
cdef template_context ctx
91+
cdef unpack_context ctx
9292
cdef size_t off = 0
9393
cdef int ret
9494

@@ -110,9 +110,9 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
110110
cerr = PyBytes_AsString(unicode_errors)
111111

112112
init_ctx(&ctx, object_hook, object_pairs_hook, list_hook, use_list, cenc, cerr)
113-
ret = template_construct(&ctx, buf, buf_len, &off)
113+
ret = unpack_construct(&ctx, buf, buf_len, &off)
114114
if ret == 1:
115-
obj = template_data(&ctx)
115+
obj = unpack_data(&ctx)
116116
if off < buf_len:
117117
raise ExtraData(obj, PyBytes_FromStringAndSize(buf+off, buf_len-off))
118118
return obj
@@ -194,7 +194,7 @@ cdef class Unpacker(object):
194194
for o in unpacker:
195195
process(o)
196196
"""
197-
cdef template_context ctx
197+
cdef unpack_context ctx
198198
cdef char* buf
199199
cdef size_t buf_size, buf_head, buf_tail
200200
cdef object file_like
@@ -324,8 +324,8 @@ cdef class Unpacker(object):
324324
write_bytes(PyBytes_FromStringAndSize(self.buf + prev_head, self.buf_head - prev_head))
325325

326326
if ret == 1:
327-
obj = template_data(&self.ctx)
328-
template_init(&self.ctx)
327+
obj = unpack_data(&self.ctx)
328+
unpack_init(&self.ctx)
329329
return obj
330330
elif ret == 0:
331331
if self.file_like is not None:
@@ -357,7 +357,7 @@ cdef class Unpacker(object):
357357
358358
Raises `OutOfData` when there are no more bytes to unpack.
359359
"""
360-
return self._unpack(template_construct, write_bytes)
360+
return self._unpack(unpack_construct, write_bytes)
361361

362362
def skip(self, object write_bytes=None):
363363
"""
@@ -368,7 +368,7 @@ cdef class Unpacker(object):
368368
369369
Raises `OutOfData` when there are no more bytes to unpack.
370370
"""
371-
return self._unpack(template_skip, write_bytes)
371+
return self._unpack(unpack_skip, write_bytes)
372372

373373
def read_array_header(self, object write_bytes=None):
374374
"""assuming the next object is an array, return its size n, such that
@@ -390,7 +390,7 @@ cdef class Unpacker(object):
390390
return self
391391

392392
def __next__(self):
393-
return self._unpack(template_construct, None, 1)
393+
return self._unpack(unpack_construct, None, 1)
394394

395395
# for debug.
396396
#def _buf(self):

msgpack/pack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static inline int msgpack_pack_long_long(msgpack_packer* pk, long long d);
4545
static inline int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
4646
static inline int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
4747
static inline int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
48-
static inline int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d);
48+
//static inline int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d);
4949

5050
static inline int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d);
5151
static inline int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d);

msgpack/pack_template.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static inline int msgpack_pack_int64(msgpack_packer* x, int64_t d)
305305
}
306306

307307

308-
#ifdef msgpack_pack_inline_func_cint
308+
//#ifdef msgpack_pack_inline_func_cint
309309

310310
static inline int msgpack_pack_short(msgpack_packer* x, short d)
311311
{
@@ -555,8 +555,8 @@ if(sizeof(unsigned long long) == 2) {
555555
#endif
556556
}
557557

558-
#undef msgpack_pack_inline_func_cint
559-
#endif
558+
//#undef msgpack_pack_inline_func_cint
559+
//#endif
560560

561561

562562

msgpack/unpack.h

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,31 @@ typedef struct unpack_user {
2828
const char *unicode_errors;
2929
} unpack_user;
3030

31+
typedef PyObject* msgpack_unpack_object;
32+
struct unpack_context;
33+
typedef struct unpack_context unpack_context;
34+
typedef int (*execute_fn)(unpack_context *ctx, const char* data, size_t len, size_t* off);
3135

32-
#define msgpack_unpack_struct(name) \
33-
struct template ## name
34-
35-
#define msgpack_unpack_func(ret, name) \
36-
static inline ret template ## name
37-
38-
#define msgpack_unpack_callback(name) \
39-
template_callback ## name
40-
41-
#define msgpack_unpack_object PyObject*
42-
43-
#define msgpack_unpack_user unpack_user
44-
45-
typedef int (*execute_fn)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off);
46-
47-
struct template_context;
48-
typedef struct template_context template_context;
49-
50-
static inline msgpack_unpack_object template_callback_root(unpack_user* u)
36+
static inline msgpack_unpack_object unpack_callback_root(unpack_user* u)
5137
{
5238
return NULL;
5339
}
5440

55-
static inline int template_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o)
41+
static inline int unpack_callback_uint16(unpack_user* u, uint16_t d, msgpack_unpack_object* o)
5642
{
5743
PyObject *p = PyInt_FromLong((long)d);
5844
if (!p)
5945
return -1;
6046
*o = p;
6147
return 0;
6248
}
63-
static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o)
49+
static inline int unpack_callback_uint8(unpack_user* u, uint8_t d, msgpack_unpack_object* o)
6450
{
65-
return template_callback_uint16(u, d, o);
51+
return unpack_callback_uint16(u, d, o);
6652
}
6753

6854

69-
static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o)
55+
static inline int unpack_callback_uint32(unpack_user* u, uint32_t d, msgpack_unpack_object* o)
7056
{
7157
PyObject *p;
7258
if (d > LONG_MAX) {
@@ -80,7 +66,7 @@ static inline int template_callback_uint32(unpack_user* u, uint32_t d, msgpack_u
8066
return 0;
8167
}
8268

83-
static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o)
69+
static inline int unpack_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o)
8470
{
8571
PyObject *p = PyLong_FromUnsignedLongLong(d);
8672
if (!p)
@@ -89,7 +75,7 @@ static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_u
8975
return 0;
9076
}
9177

92-
static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o)
78+
static inline int unpack_callback_int32(unpack_user* u, int32_t d, msgpack_unpack_object* o)
9379
{
9480
PyObject *p = PyInt_FromLong(d);
9581
if (!p)
@@ -98,17 +84,17 @@ static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_unp
9884
return 0;
9985
}
10086

101-
static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o)
87+
static inline int unpack_callback_int16(unpack_user* u, int16_t d, msgpack_unpack_object* o)
10288
{
103-
return template_callback_int32(u, d, o);
89+
return unpack_callback_int32(u, d, o);
10490
}
10591

106-
static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o)
92+
static inline int unpack_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_object* o)
10793
{
108-
return template_callback_int32(u, d, o);
94+
return unpack_callback_int32(u, d, o);
10995
}
11096

111-
static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o)
97+
static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o)
11298
{
11399
PyObject *p = PyLong_FromLongLong(d);
114100
if (!p)
@@ -117,7 +103,7 @@ static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_unp
117103
return 0;
118104
}
119105

120-
static inline int template_callback_double(unpack_user* u, double d, msgpack_unpack_object* o)
106+
static inline int unpack_callback_double(unpack_user* u, double d, msgpack_unpack_object* o)
121107
{
122108
PyObject *p = PyFloat_FromDouble(d);
123109
if (!p)
@@ -126,21 +112,21 @@ static inline int template_callback_double(unpack_user* u, double d, msgpack_unp
126112
return 0;
127113
}
128114

129-
static inline int template_callback_float(unpack_user* u, float d, msgpack_unpack_object* o)
115+
static inline int unpack_callback_float(unpack_user* u, float d, msgpack_unpack_object* o)
130116
{
131-
return template_callback_double(u, d, o);
117+
return unpack_callback_double(u, d, o);
132118
}
133119

134-
static inline int template_callback_nil(unpack_user* u, msgpack_unpack_object* o)
120+
static inline int unpack_callback_nil(unpack_user* u, msgpack_unpack_object* o)
135121
{ Py_INCREF(Py_None); *o = Py_None; return 0; }
136122

137-
static inline int template_callback_true(unpack_user* u, msgpack_unpack_object* o)
123+
static inline int unpack_callback_true(unpack_user* u, msgpack_unpack_object* o)
138124
{ Py_INCREF(Py_True); *o = Py_True; return 0; }
139125

140-
static inline int template_callback_false(unpack_user* u, msgpack_unpack_object* o)
126+
static inline int unpack_callback_false(unpack_user* u, msgpack_unpack_object* o)
141127
{ Py_INCREF(Py_False); *o = Py_False; return 0; }
142128

143-
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
129+
static inline int unpack_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
144130
{
145131
PyObject *p = u->use_list ? PyList_New(n) : PyTuple_New(n);
146132

@@ -150,7 +136,7 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
150136
return 0;
151137
}
152138

153-
static inline int template_callback_array_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object o)
139+
static inline int unpack_callback_array_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object o)
154140
{
155141
if (u->use_list)
156142
PyList_SET_ITEM(*c, current, o);
@@ -159,7 +145,7 @@ static inline int template_callback_array_item(unpack_user* u, unsigned int curr
159145
return 0;
160146
}
161147

162-
static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_object* c)
148+
static inline int unpack_callback_array_end(unpack_user* u, msgpack_unpack_object* c)
163149
{
164150
if (u->list_hook) {
165151
PyObject *new_c = PyEval_CallFunction(u->list_hook, "(O)", *c);
@@ -171,7 +157,7 @@ static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_obj
171157
return 0;
172158
}
173159

174-
static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
160+
static inline int unpack_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
175161
{
176162
PyObject *p;
177163
if (u->has_pairs_hook) {
@@ -186,7 +172,7 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_
186172
return 0;
187173
}
188174

189-
static inline int template_callback_map_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v)
175+
static inline int unpack_callback_map_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object k, msgpack_unpack_object v)
190176
{
191177
if (u->has_pairs_hook) {
192178
msgpack_unpack_object item = PyTuple_Pack(2, k, v);
@@ -205,7 +191,7 @@ static inline int template_callback_map_item(unpack_user* u, unsigned int curren
205191
return -1;
206192
}
207193

208-
static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
194+
static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
209195
{
210196
if (u->object_hook) {
211197
PyObject *new_c = PyEval_CallFunction(u->object_hook, "(O)", *c);
@@ -218,7 +204,7 @@ static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_objec
218204
return 0;
219205
}
220206

221-
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)
207+
static inline int unpack_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)
222208
{
223209
PyObject *py;
224210
if(u->encoding) {

0 commit comments

Comments
 (0)