Skip to content

Commit fe30d22

Browse files
committed
Merge branch 'main' into bufsize-argument
2 parents fdf5c1c + a97b314 commit fe30d22

File tree

4 files changed

+15
-251
lines changed

4 files changed

+15
-251
lines changed

msgpack/_packer.pyx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ from .ext import ExtType, Timestamp
1616
cdef extern from "Python.h":
1717

1818
int PyMemoryView_Check(object obj)
19-
char* PyUnicode_AsUTF8AndSize(object obj, Py_ssize_t *l) except NULL
20-
2119

2220
cdef extern from "pack.h":
2321
struct msgpack_packer:
@@ -26,11 +24,9 @@ cdef extern from "pack.h":
2624
size_t buf_size
2725
bint use_bin_type
2826

29-
int msgpack_pack_int(msgpack_packer* pk, int d)
3027
int msgpack_pack_nil(msgpack_packer* pk)
3128
int msgpack_pack_true(msgpack_packer* pk)
3229
int msgpack_pack_false(msgpack_packer* pk)
33-
int msgpack_pack_long(msgpack_packer* pk, long d)
3430
int msgpack_pack_long_long(msgpack_packer* pk, long long d)
3531
int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d)
3632
int msgpack_pack_float(msgpack_packer* pk, float d)
@@ -44,8 +40,6 @@ cdef extern from "pack.h":
4440
int msgpack_pack_timestamp(msgpack_packer* x, long long seconds, unsigned long nanoseconds);
4541
int msgpack_pack_unicode(msgpack_packer* pk, object o, long long limit)
4642

47-
cdef extern from "buff_converter.h":
48-
object buff_to_buff(char *, Py_ssize_t)
4943

5044
cdef int DEFAULT_RECURSE_LIMIT=511
5145
cdef long long ITEM_LIMIT = (2**32)-1
@@ -191,9 +185,6 @@ cdef class Packer(object):
191185
continue
192186
else:
193187
raise OverflowError("Integer value out of range")
194-
elif PyInt_CheckExact(o) if strict_types else PyInt_Check(o):
195-
longval = o
196-
ret = msgpack_pack_long(&self.pk, longval)
197188
elif PyFloat_CheckExact(o) if strict_types else PyFloat_Check(o):
198189
if self.use_float:
199190
fval = o
@@ -376,4 +367,10 @@ cdef class Packer(object):
376367

377368
def getbuffer(self):
378369
"""Return view of internal buffer."""
379-
return buff_to_buff(self.pk.buf, self.pk.length)
370+
return memoryview(self)
371+
372+
def __getbuffer__(self, Py_buffer *buffer, int flags):
373+
PyBuffer_FillInfo(buffer, self, self.pk.buf, self.pk.length, 1, flags)
374+
375+
def __releasebuffer__(self, Py_buffer *buffer):
376+
pass

msgpack/buff_converter.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

msgpack/pack.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
#include "sysdep.h"
2222
#include <limits.h>
2323
#include <string.h>
24+
#include <stdbool.h>
2425

2526
#ifdef __cplusplus
2627
extern "C" {
27-
#else
28-
#define bool char
2928
#endif
3029

3130
typedef struct msgpack_packer {

msgpack/pack_template.h

Lines changed: 7 additions & 231 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@
3737
* Integer
3838
*/
3939

40-
#define msgpack_pack_real_uint8(x, d) \
41-
do { \
42-
if(d < (1<<7)) { \
43-
/* fixnum */ \
44-
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
45-
} else { \
46-
/* unsigned 8 */ \
47-
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
48-
msgpack_pack_append_buffer(x, buf, 2); \
49-
} \
50-
} while(0)
51-
5240
#define msgpack_pack_real_uint16(x, d) \
5341
do { \
5442
if(d < (1<<7)) { \
@@ -123,18 +111,6 @@ do { \
123111
} \
124112
} while(0)
125113

126-
#define msgpack_pack_real_int8(x, d) \
127-
do { \
128-
if(d < -(1<<5)) { \
129-
/* signed 8 */ \
130-
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
131-
msgpack_pack_append_buffer(x, buf, 2); \
132-
} else { \
133-
/* fixnum */ \
134-
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
135-
} \
136-
} while(0)
137-
138114
#define msgpack_pack_real_int16(x, d) \
139115
do { \
140116
if(d < -(1<<5)) { \
@@ -264,49 +240,6 @@ do { \
264240
} while(0)
265241

266242

267-
static inline int msgpack_pack_uint8(msgpack_packer* x, uint8_t d)
268-
{
269-
msgpack_pack_real_uint8(x, d);
270-
}
271-
272-
static inline int msgpack_pack_uint16(msgpack_packer* x, uint16_t d)
273-
{
274-
msgpack_pack_real_uint16(x, d);
275-
}
276-
277-
static inline int msgpack_pack_uint32(msgpack_packer* x, uint32_t d)
278-
{
279-
msgpack_pack_real_uint32(x, d);
280-
}
281-
282-
static inline int msgpack_pack_uint64(msgpack_packer* x, uint64_t d)
283-
{
284-
msgpack_pack_real_uint64(x, d);
285-
}
286-
287-
static inline int msgpack_pack_int8(msgpack_packer* x, int8_t d)
288-
{
289-
msgpack_pack_real_int8(x, d);
290-
}
291-
292-
static inline int msgpack_pack_int16(msgpack_packer* x, int16_t d)
293-
{
294-
msgpack_pack_real_int16(x, d);
295-
}
296-
297-
static inline int msgpack_pack_int32(msgpack_packer* x, int32_t d)
298-
{
299-
msgpack_pack_real_int32(x, d);
300-
}
301-
302-
static inline int msgpack_pack_int64(msgpack_packer* x, int64_t d)
303-
{
304-
msgpack_pack_real_int64(x, d);
305-
}
306-
307-
308-
//#ifdef msgpack_pack_inline_func_cint
309-
310243
static inline int msgpack_pack_short(msgpack_packer* x, short d)
311244
{
312245
#if defined(SIZEOF_SHORT)
@@ -372,192 +305,37 @@ if(sizeof(int) == 2) {
372305
static inline int msgpack_pack_long(msgpack_packer* x, long d)
373306
{
374307
#if defined(SIZEOF_LONG)
375-
#if SIZEOF_LONG == 2
376-
msgpack_pack_real_int16(x, d);
377-
#elif SIZEOF_LONG == 4
308+
#if SIZEOF_LONG == 4
378309
msgpack_pack_real_int32(x, d);
379310
#else
380311
msgpack_pack_real_int64(x, d);
381312
#endif
382313

383314
#elif defined(LONG_MAX)
384-
#if LONG_MAX == 0x7fffL
385-
msgpack_pack_real_int16(x, d);
386-
#elif LONG_MAX == 0x7fffffffL
315+
#if LONG_MAX == 0x7fffffffL
387316
msgpack_pack_real_int32(x, d);
388317
#else
389318
msgpack_pack_real_int64(x, d);
390319
#endif
391320

392321
#else
393-
if(sizeof(long) == 2) {
394-
msgpack_pack_real_int16(x, d);
395-
} else if(sizeof(long) == 4) {
396-
msgpack_pack_real_int32(x, d);
397-
} else {
398-
msgpack_pack_real_int64(x, d);
399-
}
322+
if (sizeof(long) == 4) {
323+
msgpack_pack_real_int32(x, d);
324+
} else {
325+
msgpack_pack_real_int64(x, d);
326+
}
400327
#endif
401328
}
402329

403330
static inline int msgpack_pack_long_long(msgpack_packer* x, long long d)
404331
{
405-
#if defined(SIZEOF_LONG_LONG)
406-
#if SIZEOF_LONG_LONG == 2
407-
msgpack_pack_real_int16(x, d);
408-
#elif SIZEOF_LONG_LONG == 4
409-
msgpack_pack_real_int32(x, d);
410-
#else
411-
msgpack_pack_real_int64(x, d);
412-
#endif
413-
414-
#elif defined(LLONG_MAX)
415-
#if LLONG_MAX == 0x7fffL
416-
msgpack_pack_real_int16(x, d);
417-
#elif LLONG_MAX == 0x7fffffffL
418-
msgpack_pack_real_int32(x, d);
419-
#else
420-
msgpack_pack_real_int64(x, d);
421-
#endif
422-
423-
#else
424-
if(sizeof(long long) == 2) {
425-
msgpack_pack_real_int16(x, d);
426-
} else if(sizeof(long long) == 4) {
427-
msgpack_pack_real_int32(x, d);
428-
} else {
429332
msgpack_pack_real_int64(x, d);
430333
}
431-
#endif
432-
}
433-
434-
static inline int msgpack_pack_unsigned_short(msgpack_packer* x, unsigned short d)
435-
{
436-
#if defined(SIZEOF_SHORT)
437-
#if SIZEOF_SHORT == 2
438-
msgpack_pack_real_uint16(x, d);
439-
#elif SIZEOF_SHORT == 4
440-
msgpack_pack_real_uint32(x, d);
441-
#else
442-
msgpack_pack_real_uint64(x, d);
443-
#endif
444-
445-
#elif defined(USHRT_MAX)
446-
#if USHRT_MAX == 0xffffU
447-
msgpack_pack_real_uint16(x, d);
448-
#elif USHRT_MAX == 0xffffffffU
449-
msgpack_pack_real_uint32(x, d);
450-
#else
451-
msgpack_pack_real_uint64(x, d);
452-
#endif
453-
454-
#else
455-
if(sizeof(unsigned short) == 2) {
456-
msgpack_pack_real_uint16(x, d);
457-
} else if(sizeof(unsigned short) == 4) {
458-
msgpack_pack_real_uint32(x, d);
459-
} else {
460-
msgpack_pack_real_uint64(x, d);
461-
}
462-
#endif
463-
}
464-
465-
static inline int msgpack_pack_unsigned_int(msgpack_packer* x, unsigned int d)
466-
{
467-
#if defined(SIZEOF_INT)
468-
#if SIZEOF_INT == 2
469-
msgpack_pack_real_uint16(x, d);
470-
#elif SIZEOF_INT == 4
471-
msgpack_pack_real_uint32(x, d);
472-
#else
473-
msgpack_pack_real_uint64(x, d);
474-
#endif
475-
476-
#elif defined(UINT_MAX)
477-
#if UINT_MAX == 0xffffU
478-
msgpack_pack_real_uint16(x, d);
479-
#elif UINT_MAX == 0xffffffffU
480-
msgpack_pack_real_uint32(x, d);
481-
#else
482-
msgpack_pack_real_uint64(x, d);
483-
#endif
484-
485-
#else
486-
if(sizeof(unsigned int) == 2) {
487-
msgpack_pack_real_uint16(x, d);
488-
} else if(sizeof(unsigned int) == 4) {
489-
msgpack_pack_real_uint32(x, d);
490-
} else {
491-
msgpack_pack_real_uint64(x, d);
492-
}
493-
#endif
494-
}
495-
496-
static inline int msgpack_pack_unsigned_long(msgpack_packer* x, unsigned long d)
497-
{
498-
#if defined(SIZEOF_LONG)
499-
#if SIZEOF_LONG == 2
500-
msgpack_pack_real_uint16(x, d);
501-
#elif SIZEOF_LONG == 4
502-
msgpack_pack_real_uint32(x, d);
503-
#else
504-
msgpack_pack_real_uint64(x, d);
505-
#endif
506-
507-
#elif defined(ULONG_MAX)
508-
#if ULONG_MAX == 0xffffUL
509-
msgpack_pack_real_uint16(x, d);
510-
#elif ULONG_MAX == 0xffffffffUL
511-
msgpack_pack_real_uint32(x, d);
512-
#else
513-
msgpack_pack_real_uint64(x, d);
514-
#endif
515-
516-
#else
517-
if(sizeof(unsigned long) == 2) {
518-
msgpack_pack_real_uint16(x, d);
519-
} else if(sizeof(unsigned long) == 4) {
520-
msgpack_pack_real_uint32(x, d);
521-
} else {
522-
msgpack_pack_real_uint64(x, d);
523-
}
524-
#endif
525-
}
526334

527335
static inline int msgpack_pack_unsigned_long_long(msgpack_packer* x, unsigned long long d)
528336
{
529-
#if defined(SIZEOF_LONG_LONG)
530-
#if SIZEOF_LONG_LONG == 2
531-
msgpack_pack_real_uint16(x, d);
532-
#elif SIZEOF_LONG_LONG == 4
533-
msgpack_pack_real_uint32(x, d);
534-
#else
535-
msgpack_pack_real_uint64(x, d);
536-
#endif
537-
538-
#elif defined(ULLONG_MAX)
539-
#if ULLONG_MAX == 0xffffUL
540-
msgpack_pack_real_uint16(x, d);
541-
#elif ULLONG_MAX == 0xffffffffUL
542-
msgpack_pack_real_uint32(x, d);
543-
#else
544-
msgpack_pack_real_uint64(x, d);
545-
#endif
546-
547-
#else
548-
if(sizeof(unsigned long long) == 2) {
549-
msgpack_pack_real_uint16(x, d);
550-
} else if(sizeof(unsigned long long) == 4) {
551-
msgpack_pack_real_uint32(x, d);
552-
} else {
553337
msgpack_pack_real_uint64(x, d);
554338
}
555-
#endif
556-
}
557-
558-
//#undef msgpack_pack_inline_func_cint
559-
//#endif
560-
561339

562340

563341
/*
@@ -810,11 +588,9 @@ static inline int msgpack_pack_timestamp(msgpack_packer* x, int64_t seconds, uin
810588
#undef TAKE8_32
811589
#undef TAKE8_64
812590

813-
#undef msgpack_pack_real_uint8
814591
#undef msgpack_pack_real_uint16
815592
#undef msgpack_pack_real_uint32
816593
#undef msgpack_pack_real_uint64
817-
#undef msgpack_pack_real_int8
818594
#undef msgpack_pack_real_int16
819595
#undef msgpack_pack_real_int32
820596
#undef msgpack_pack_real_int64

0 commit comments

Comments
 (0)