Skip to content

Commit e9ab4d8

Browse files
committed
Fix warnings
fixes #146
1 parent ab359e3 commit e9ab4d8

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

msgpack/_unpacker.pyx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ cdef extern from "unpack.h":
3737
ctypedef struct unpack_context:
3838
msgpack_user user
3939
PyObject* obj
40-
size_t count
40+
Py_ssize_t count
4141

4242
ctypedef int (*execute_fn)(unpack_context* ctx, const char* data,
43-
size_t len, size_t* off) except? -1
43+
Py_ssize_t len, Py_ssize_t* off) except? -1
4444
execute_fn unpack_construct
4545
execute_fn unpack_skip
4646
execute_fn read_array_header
@@ -112,7 +112,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
112112
See :class:`Unpacker` for options.
113113
"""
114114
cdef unpack_context ctx
115-
cdef size_t off = 0
115+
cdef Py_ssize_t off = 0
116116
cdef int ret
117117

118118
cdef char* buf
@@ -142,7 +142,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
142142
raise ExtraData(obj, PyBytes_FromStringAndSize(buf+off, buf_len-off))
143143
return obj
144144
else:
145-
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
145+
raise UnpackValueError("Unpack failed: error = %s" % (ret,))
146146

147147

148148
def unpack(object stream, object object_hook=None, object list_hook=None,
@@ -233,14 +233,14 @@ cdef class Unpacker(object):
233233
"""
234234
cdef unpack_context ctx
235235
cdef char* buf
236-
cdef size_t buf_size, buf_head, buf_tail
236+
cdef Py_ssize_t buf_size, buf_head, buf_tail
237237
cdef object file_like
238238
cdef object file_like_read
239239
cdef Py_ssize_t read_size
240240
# To maintain refcnt.
241241
cdef object object_hook, object_pairs_hook, list_hook, ext_hook
242242
cdef object encoding, unicode_errors
243-
cdef size_t max_buffer_size
243+
cdef Py_ssize_t max_buffer_size
244244

245245
def __cinit__(self):
246246
self.buf = NULL
@@ -325,10 +325,10 @@ cdef class Unpacker(object):
325325
cdef:
326326
char* buf = self.buf
327327
char* new_buf
328-
size_t head = self.buf_head
329-
size_t tail = self.buf_tail
330-
size_t buf_size = self.buf_size
331-
size_t new_size
328+
Py_ssize_t head = self.buf_head
329+
Py_ssize_t tail = self.buf_tail
330+
Py_ssize_t buf_size = self.buf_size
331+
Py_ssize_t new_size
332332

333333
if tail + _buf_len > buf_size:
334334
if ((tail - head) + _buf_len) <= buf_size:
@@ -374,7 +374,7 @@ cdef class Unpacker(object):
374374
cdef object _unpack(self, execute_fn execute, object write_bytes, bint iter=0):
375375
cdef int ret
376376
cdef object obj
377-
cdef size_t prev_head
377+
cdef Py_ssize_t prev_head
378378

379379
if self.buf_head >= self.buf_tail and self.file_like is not None:
380380
self.read_from_file()
@@ -408,7 +408,7 @@ cdef class Unpacker(object):
408408

409409
def read_bytes(self, Py_ssize_t nbytes):
410410
"""Read a specified number of raw bytes from the stream"""
411-
cdef size_t nread
411+
cdef Py_ssize_t nread
412412
nread = min(self.buf_tail - self.buf_head, nbytes)
413413
ret = PyBytes_FromStringAndSize(self.buf + self.buf_head, nread)
414414
self.buf_head += nread

msgpack/unpack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ typedef struct unpack_user {
3333
typedef PyObject* msgpack_unpack_object;
3434
struct unpack_context;
3535
typedef struct unpack_context unpack_context;
36-
typedef int (*execute_fn)(unpack_context *ctx, const char* data, size_t len, size_t* off);
36+
typedef int (*execute_fn)(unpack_context *ctx, const char* data, Py_ssize_t len, Py_ssize_t* off);
3737

3838
static inline msgpack_unpack_object unpack_callback_root(unpack_user* u)
3939
{

msgpack/unpack_template.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
typedef struct unpack_stack {
2626
PyObject* obj;
27-
size_t size;
28-
size_t count;
27+
Py_ssize_t size;
28+
Py_ssize_t count;
2929
unsigned int ct;
3030
PyObject* map_key;
3131
} unpack_stack;
@@ -72,7 +72,7 @@ static inline PyObject* unpack_data(unpack_context* ctx)
7272

7373

7474
template <bool construct>
75-
static inline int unpack_execute(unpack_context* ctx, const char* data, size_t len, size_t* off)
75+
static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
7676
{
7777
assert(len >= *off);
7878

@@ -89,7 +89,7 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, size_t l
8989
*/
9090
unpack_user* user = &ctx->user;
9191

92-
PyObject* obj;
92+
PyObject* obj = NULL;
9393
unpack_stack* c = NULL;
9494

9595
int ret;
@@ -409,7 +409,7 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, size_t l
409409
#undef start_container
410410

411411
template <unsigned int fixed_offset, unsigned int var_offset>
412-
static inline int unpack_container_header(unpack_context* ctx, const char* data, size_t len, size_t* off)
412+
static inline int unpack_container_header(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
413413
{
414414
assert(len >= *off);
415415
uint32_t size;

0 commit comments

Comments
 (0)