Skip to content

Commit e8f6d2a

Browse files
committed
Merge pull request #54 from msgpack/remove-macros
Remove macros for readability.
2 parents 944b41e + c49489c commit e8f6d2a

File tree

5 files changed

+105
-227
lines changed

5 files changed

+105
-227
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 & 9 deletions
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);
@@ -90,14 +90,6 @@ static inline int msgpack_pack_write(msgpack_packer* pk, const char *data, size_
9090
return 0;
9191
}
9292

93-
#define msgpack_pack_inline_func(name) \
94-
static inline int msgpack_pack ## name
95-
96-
#define msgpack_pack_inline_func_cint(name) \
97-
static inline int msgpack_pack ## name
98-
99-
#define msgpack_pack_user msgpack_packer*
100-
10193
#define msgpack_pack_append_buffer(user, buf, len) \
10294
return msgpack_pack_write(user, (const char*)buf, len)
10395

0 commit comments

Comments
 (0)