| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0602baf commit 3e9a2a7
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ jobs: | |||
| 10 | 10 | strategy: | |
| 11 | 11 | matrix: | |
| 12 | 12 | 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"] | ||
| 14 | 14 | ||
| 15 | 15 | runs-on: ${{ matrix.os }} | |
| 16 | 16 | name: Run test with Python ${{ matrix.py }} on ${{ matrix.os }} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ pyupgrade: | |||
| 22 | 22 | ||
| 23 | 23 | .PHONY: cython | |
| 24 | 24 | cython: | |
| 25 | - cython --cplus msgpack/_cmsgpack.pyx | ||
| 25 | + cython msgpack/_cmsgpack.pyx | ||
| 26 | 26 | ||
| 27 | 27 | .PHONY: test | |
| 28 | 28 | test: cython | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ cdef extern from "unpack.h": | |||
| 35 | 35 | PyObject* timestamp_t | |
| 36 | 36 | PyObject *giga; | |
| 37 | 37 | PyObject *utc; | |
| 38 | - char *unicode_errors | ||
| 38 | + const char *unicode_errors | ||
| 39 | 39 | Py_ssize_t max_str_len | |
| 40 | 40 | Py_ssize_t max_bin_len | |
| 41 | 41 | Py_ssize_t max_array_len | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,8 @@ | |||
| 24 | 24 | ||
| 25 | 25 | #ifdef __cplusplus | |
| 26 | 26 | extern "C" { | |
| 27 | + #else | ||
| 28 | + #define bool char | ||
| 27 | 29 | #endif | |
| 28 | 30 | ||
| 29 | 31 | typedef struct msgpack_packer { | |
| Original file line number | Diff line number | Diff 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 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,8 +75,7 @@ static inline void unpack_clear(unpack_context *ctx) | |||
| 75 | 75 | Py_CLEAR(ctx->stack[0].obj); | |
| 76 | 76 | } | |
| 77 | 77 | ||
| 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) | ||
| 80 | 79 | { | |
| 81 | 80 | assert(len >= *off); | |
| 82 | 81 | ||
@@ -386,6 +385,7 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize | |||
| 386 | 385 | #undef construct_cb | |
| 387 | 386 | } | |
| 388 | 387 | ||
| 388 | + #undef NEXT_CS | ||
| 389 | 389 | #undef SWITCH_RANGE_BEGIN | |
| 390 | 390 | #undef SWITCH_RANGE | |
| 391 | 391 | #undef SWITCH_RANGE_DEFAULT | |
@@ -397,68 +397,27 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize | |||
| 397 | 397 | #undef again_fixed_trail_if_zero | |
| 398 | 398 | #undef start_container | |
| 399 | 399 | ||
| 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); | ||
| 450 | 405 | } | |
| 451 | 406 | ||
| 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 | ||
| 463 | 422 | ||
| 464 | 423 | /* vim: set ts=4 sw=4 sts=4 expandtab */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ def cythonize(src): | |||
| 25 | 25 | if not have_cython: | |
| 26 | 26 | raise Exception("Cython is required for building from checkout") | |
| 27 | 27 | sys.stderr.write(f"cythonize: {src!r}\n") | |
| 28 | - cython_compiler.compile([src], cplus=True) | ||
| 28 | + cython_compiler.compile([src]) | ||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | 31 | def ensure_source(src): | |
@@ -51,17 +51,17 @@ def __init__(self, *args, **kwargs): | |||
| 51 | 51 | ||
| 52 | 52 | libraries = [] | |
| 53 | 53 | macros = [] | |
| 54 | + ext_modules = [] | ||
| 54 | 55 | ||
| 55 | 56 | if sys.platform == "win32": | |
| 56 | 57 | libraries.append("ws2_32") | |
| 57 | 58 | macros = [("__LITTLE_ENDIAN__", "1")] | |
| 58 | 59 | ||
| 59 | - ext_modules = [] | ||
| 60 | 60 | if not PYPY and not os.environ.get("MSGPACK_PUREPYTHON"): | |
| 61 | 61 | ext_modules.append( | |
| 62 | 62 | Extension( | |
| 63 | 63 | "msgpack._cmsgpack", | |
| 64 | - sources=["msgpack/_cmsgpack.cpp"], | ||
| 64 | + sources=["msgpack/_cmsgpack.c"], | ||
| 65 | 65 | libraries=libraries, | |
| 66 | 66 | include_dirs=["."], | |
| 67 | 67 | define_macros=macros, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments