Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e9a2a7

Browse filesBrowse files
authored
Stop using c++ (#600)
Python 3.13a6+ & C++ & Cython cause compile error on some compilers.
1 parent 0602baf commit 3e9a2a7
Copy full SHA for 3e9a2a7

File tree

Expand file treeCollapse file tree

7 files changed

+81
-69
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+81
-69
lines changed

‎.github/workflows/test.yml

Copy file name to clipboardExpand all lines: .github/workflows/test.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
13-
py: ["3.12", "3.11", "3.10", "3.9", "3.8"]
13+
py: ["3.13-dev", "3.12", "3.11", "3.10", "3.9", "3.8"]
1414

1515
runs-on: ${{ matrix.os }}
1616
name: Run test with Python ${{ matrix.py }} on ${{ matrix.os }}

‎Makefile

Copy file name to clipboardExpand all lines: Makefile
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pyupgrade:
2222

2323
.PHONY: cython
2424
cython:
25-
cython --cplus msgpack/_cmsgpack.pyx
25+
cython msgpack/_cmsgpack.pyx
2626

2727
.PHONY: test
2828
test: cython

‎msgpack/_unpacker.pyx

Copy file name to clipboardExpand all lines: msgpack/_unpacker.pyx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cdef extern from "unpack.h":
3535
PyObject* timestamp_t
3636
PyObject *giga;
3737
PyObject *utc;
38-
char *unicode_errors
38+
const char *unicode_errors
3939
Py_ssize_t max_str_len
4040
Py_ssize_t max_bin_len
4141
Py_ssize_t max_array_len

‎msgpack/pack.h

Copy file name to clipboardExpand all lines: msgpack/pack.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#ifdef __cplusplus
2626
extern "C" {
27+
#else
28+
#define bool char
2729
#endif
2830

2931
typedef struct msgpack_packer {

‎msgpack/unpack_container_header.h

Copy file name to clipboard
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
static inline int unpack_container_header(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
2+
{
3+
assert(len >= *off);
4+
uint32_t size;
5+
const unsigned char *const p = (unsigned char*)data + *off;
6+
7+
#define inc_offset(inc) \
8+
if (len - *off < inc) \
9+
return 0; \
10+
*off += inc;
11+
12+
switch (*p) {
13+
case var_offset:
14+
inc_offset(3);
15+
size = _msgpack_load16(uint16_t, p + 1);
16+
break;
17+
case var_offset + 1:
18+
inc_offset(5);
19+
size = _msgpack_load32(uint32_t, p + 1);
20+
break;
21+
#ifdef USE_CASE_RANGE
22+
case fixed_offset + 0x0 ... fixed_offset + 0xf:
23+
#else
24+
case fixed_offset + 0x0:
25+
case fixed_offset + 0x1:
26+
case fixed_offset + 0x2:
27+
case fixed_offset + 0x3:
28+
case fixed_offset + 0x4:
29+
case fixed_offset + 0x5:
30+
case fixed_offset + 0x6:
31+
case fixed_offset + 0x7:
32+
case fixed_offset + 0x8:
33+
case fixed_offset + 0x9:
34+
case fixed_offset + 0xa:
35+
case fixed_offset + 0xb:
36+
case fixed_offset + 0xc:
37+
case fixed_offset + 0xd:
38+
case fixed_offset + 0xe:
39+
case fixed_offset + 0xf:
40+
#endif
41+
++*off;
42+
size = ((unsigned int)*p) & 0x0f;
43+
break;
44+
default:
45+
PyErr_SetString(PyExc_ValueError, "Unexpected type header on stream");
46+
return -1;
47+
}
48+
unpack_callback_uint32(&ctx->user, size, &ctx->stack[0].obj);
49+
return 1;
50+
}
51+

‎msgpack/unpack_template.h

Copy file name to clipboardExpand all lines: msgpack/unpack_template.h
+22-63Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ static inline void unpack_clear(unpack_context *ctx)
7575
Py_CLEAR(ctx->stack[0].obj);
7676
}
7777

78-
template <bool construct>
79-
static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
78+
static inline int unpack_execute(bool construct, unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
8079
{
8180
assert(len >= *off);
8281

@@ -386,6 +385,7 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize
386385
#undef construct_cb
387386
}
388387

388+
#undef NEXT_CS
389389
#undef SWITCH_RANGE_BEGIN
390390
#undef SWITCH_RANGE
391391
#undef SWITCH_RANGE_DEFAULT
@@ -397,68 +397,27 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize
397397
#undef again_fixed_trail_if_zero
398398
#undef start_container
399399

400-
template <unsigned int fixed_offset, unsigned int var_offset>
401-
static inline int unpack_container_header(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)
402-
{
403-
assert(len >= *off);
404-
uint32_t size;
405-
const unsigned char *const p = (unsigned char*)data + *off;
406-
407-
#define inc_offset(inc) \
408-
if (len - *off < inc) \
409-
return 0; \
410-
*off += inc;
411-
412-
switch (*p) {
413-
case var_offset:
414-
inc_offset(3);
415-
size = _msgpack_load16(uint16_t, p + 1);
416-
break;
417-
case var_offset + 1:
418-
inc_offset(5);
419-
size = _msgpack_load32(uint32_t, p + 1);
420-
break;
421-
#ifdef USE_CASE_RANGE
422-
case fixed_offset + 0x0 ... fixed_offset + 0xf:
423-
#else
424-
case fixed_offset + 0x0:
425-
case fixed_offset + 0x1:
426-
case fixed_offset + 0x2:
427-
case fixed_offset + 0x3:
428-
case fixed_offset + 0x4:
429-
case fixed_offset + 0x5:
430-
case fixed_offset + 0x6:
431-
case fixed_offset + 0x7:
432-
case fixed_offset + 0x8:
433-
case fixed_offset + 0x9:
434-
case fixed_offset + 0xa:
435-
case fixed_offset + 0xb:
436-
case fixed_offset + 0xc:
437-
case fixed_offset + 0xd:
438-
case fixed_offset + 0xe:
439-
case fixed_offset + 0xf:
440-
#endif
441-
++*off;
442-
size = ((unsigned int)*p) & 0x0f;
443-
break;
444-
default:
445-
PyErr_SetString(PyExc_ValueError, "Unexpected type header on stream");
446-
return -1;
447-
}
448-
unpack_callback_uint32(&ctx->user, size, &ctx->stack[0].obj);
449-
return 1;
400+
static int unpack_construct(unpack_context *ctx, const char *data, Py_ssize_t len, Py_ssize_t *off) {
401+
return unpack_execute(1, ctx, data, len, off);
402+
}
403+
static int unpack_skip(unpack_context *ctx, const char *data, Py_ssize_t len, Py_ssize_t *off) {
404+
return unpack_execute(0, ctx, data, len, off);
450405
}
451406

452-
#undef SWITCH_RANGE_BEGIN
453-
#undef SWITCH_RANGE
454-
#undef SWITCH_RANGE_DEFAULT
455-
#undef SWITCH_RANGE_END
456-
457-
static const execute_fn unpack_construct = &unpack_execute<true>;
458-
static const execute_fn unpack_skip = &unpack_execute<false>;
459-
static const execute_fn read_array_header = &unpack_container_header<0x90, 0xdc>;
460-
static const execute_fn read_map_header = &unpack_container_header<0x80, 0xde>;
461-
462-
#undef NEXT_CS
407+
#define unpack_container_header read_array_header
408+
#define fixed_offset 0x90
409+
#define var_offset 0xdc
410+
#include "unpack_container_header.h"
411+
#undef unpack_container_header
412+
#undef fixed_offset
413+
#undef var_offset
414+
415+
#define unpack_container_header read_map_header
416+
#define fixed_offset 0x80
417+
#define var_offset 0xde
418+
#include "unpack_container_header.h"
419+
#undef unpack_container_header
420+
#undef fixed_offset
421+
#undef var_offset
463422

464423
/* vim: set ts=4 sw=4 sts=4 expandtab */

‎setup.py

Copy file name to clipboardExpand all lines: setup.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def cythonize(src):
2525
if not have_cython:
2626
raise Exception("Cython is required for building from checkout")
2727
sys.stderr.write(f"cythonize: {src!r}\n")
28-
cython_compiler.compile([src], cplus=True)
28+
cython_compiler.compile([src])
2929

3030

3131
def ensure_source(src):
@@ -51,17 +51,17 @@ def __init__(self, *args, **kwargs):
5151

5252
libraries = []
5353
macros = []
54+
ext_modules = []
5455

5556
if sys.platform == "win32":
5657
libraries.append("ws2_32")
5758
macros = [("__LITTLE_ENDIAN__", "1")]
5859

59-
ext_modules = []
6060
if not PYPY and not os.environ.get("MSGPACK_PUREPYTHON"):
6161
ext_modules.append(
6262
Extension(
6363
"msgpack._cmsgpack",
64-
sources=["msgpack/_cmsgpack.cpp"],
64+
sources=["msgpack/_cmsgpack.c"],
6565
libraries=libraries,
6666
include_dirs=["."],
6767
define_macros=macros,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.