Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit3e9a2a7

Browse files
authored
Stop using c++ (#600)
Python 3.13a6+ & C++ & Cython cause compile error on some compilers.
1 parent0602baf commit3e9a2a7

File tree

7 files changed

+81
-69
lines changed

7 files changed

+81
-69
lines changed

‎.github/workflows/test.yml

Lines 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

Lines 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--cplusmsgpack/_cmsgpack.pyx
25+
cython msgpack/_cmsgpack.pyx
2626

2727
.PHONY: test
2828
test: cython

‎msgpack/_unpacker.pyx

Lines 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+
constchar*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

Lines 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+
#definebool char
2729
#endif
2830

2931
typedefstructmsgpack_packer {

‎msgpack/unpack_container_header.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
staticinlineintunpack_container_header(unpack_context*ctx,constchar*data,Py_ssize_tlen,Py_ssize_t*off)
2+
{
3+
assert(len >=*off);
4+
uint32_tsize;
5+
constunsignedchar*constp= (unsignedchar*)data+*off;
6+
7+
#defineinc_offset(inc) \
8+
if (len - *off < inc) \
9+
return 0; \
10+
*off += inc;
11+
12+
switch (*p) {
13+
casevar_offset:
14+
inc_offset(3);
15+
size=_msgpack_load16(uint16_t,p+1);
16+
break;
17+
casevar_offset+1:
18+
inc_offset(5);
19+
size=_msgpack_load32(uint32_t,p+1);
20+
break;
21+
#ifdefUSE_CASE_RANGE
22+
casefixed_offset+0x0 ...fixed_offset+0xf:
23+
#else
24+
casefixed_offset+0x0:
25+
casefixed_offset+0x1:
26+
casefixed_offset+0x2:
27+
casefixed_offset+0x3:
28+
casefixed_offset+0x4:
29+
casefixed_offset+0x5:
30+
casefixed_offset+0x6:
31+
casefixed_offset+0x7:
32+
casefixed_offset+0x8:
33+
casefixed_offset+0x9:
34+
casefixed_offset+0xa:
35+
casefixed_offset+0xb:
36+
casefixed_offset+0xc:
37+
casefixed_offset+0xd:
38+
casefixed_offset+0xe:
39+
casefixed_offset+0xf:
40+
#endif
41+
++*off;
42+
size= ((unsignedint)*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+
return1;
50+
}
51+

‎msgpack/unpack_template.h

Lines 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-
staticinlineintunpack_execute(unpack_context* ctx,constchar* data, Py_ssize_t len, Py_ssize_t* off)
78+
staticinlineintunpack_execute(boolconstruct,unpack_context*ctx,constchar*data,Py_ssize_tlen,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<unsignedint fixed_offset,unsignedint var_offset>
401-
staticinlineintunpack_container_header(unpack_context* ctx,constchar* data, Py_ssize_t len, Py_ssize_t* off)
402-
{
403-
assert(len >= *off);
404-
uint32_t size;
405-
constunsignedchar *const p = (unsignedchar*)data + *off;
406-
407-
#defineinc_offset(inc) \
408-
if (len - *off < inc) \
409-
return0; \
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 = ((unsignedint)*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-
return1;
400+
staticintunpack_construct(unpack_context*ctx,constchar*data,Py_ssize_tlen,Py_ssize_t*off) {
401+
returnunpack_execute(1,ctx,data,len,off);
402+
}
403+
staticintunpack_skip(unpack_context*ctx,constchar*data,Py_ssize_tlen,Py_ssize_t*off) {
404+
returnunpack_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-
staticconst execute_fn unpack_construct = &unpack_execute<true>;
458-
staticconst execute_fn unpack_skip = &unpack_execute<false>;
459-
staticconst execute_fn read_array_header = &unpack_container_header<0x90,0xdc>;
460-
staticconst execute_fn read_map_header = &unpack_container_header<0x80,0xde>;
461-
462-
#undef NEXT_CS
407+
#defineunpack_container_header read_array_header
408+
#definefixed_offset 0x90
409+
#definevar_offset 0xdc
410+
#include"unpack_container_header.h"
411+
#undef unpack_container_header
412+
#undef fixed_offset
413+
#undef var_offset
414+
415+
#defineunpack_container_header read_map_header
416+
#definefixed_offset 0x80
417+
#definevar_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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def cythonize(src):
2525
ifnothave_cython:
2626
raiseException("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
defensure_source(src):
@@ -51,17 +51,17 @@ def __init__(self, *args, **kwargs):
5151

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

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

59-
ext_modules= []
6060
ifnotPYPYandnotos.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)

[8]ページ先頭

©2009-2025 Movatter.jp