first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
1133
kivy_venv/lib/python3.11/site-packages/Cython/Utility/AsyncGen.c
Normal file
1133
kivy_venv/lib/python3.11/site-packages/Cython/Utility/AsyncGen.c
Normal file
File diff suppressed because it is too large
Load diff
921
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Buffer.c
Normal file
921
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Buffer.c
Normal file
|
@ -0,0 +1,921 @@
|
|||
/////////////// BufferStructDeclare.proto ///////////////
|
||||
|
||||
/* structs for buffer access */
|
||||
|
||||
typedef struct {
|
||||
Py_ssize_t shape, strides, suboffsets;
|
||||
} __Pyx_Buf_DimInfo;
|
||||
|
||||
typedef struct {
|
||||
size_t refcount;
|
||||
Py_buffer pybuffer;
|
||||
} __Pyx_Buffer;
|
||||
|
||||
typedef struct {
|
||||
__Pyx_Buffer *rcbuffer;
|
||||
char *data;
|
||||
__Pyx_Buf_DimInfo diminfo[{{max_dims}}];
|
||||
} __Pyx_LocalBuf_ND;
|
||||
|
||||
/////////////// BufferIndexError.proto ///////////////
|
||||
static void __Pyx_RaiseBufferIndexError(int axis); /*proto*/
|
||||
|
||||
/////////////// BufferIndexError ///////////////
|
||||
static void __Pyx_RaiseBufferIndexError(int axis) {
|
||||
PyErr_Format(PyExc_IndexError,
|
||||
"Out of bounds on buffer access (axis %d)", axis);
|
||||
}
|
||||
|
||||
/////////////// BufferIndexErrorNogil.proto ///////////////
|
||||
//@requires: BufferIndexError
|
||||
|
||||
static void __Pyx_RaiseBufferIndexErrorNogil(int axis); /*proto*/
|
||||
|
||||
/////////////// BufferIndexErrorNogil ///////////////
|
||||
static void __Pyx_RaiseBufferIndexErrorNogil(int axis) {
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
#endif
|
||||
__Pyx_RaiseBufferIndexError(axis);
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_Release(gilstate);
|
||||
#endif
|
||||
}
|
||||
|
||||
/////////////// BufferFallbackError.proto ///////////////
|
||||
static void __Pyx_RaiseBufferFallbackError(void); /*proto*/
|
||||
|
||||
/////////////// BufferFallbackError ///////////////
|
||||
static void __Pyx_RaiseBufferFallbackError(void) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
|
||||
}
|
||||
|
||||
/////////////// BufferFormatStructs.proto ///////////////
|
||||
//@proto_block: utility_code_proto_before_types
|
||||
|
||||
#define IS_UNSIGNED(type) (((type) -1) > 0)
|
||||
|
||||
/* Run-time type information about structs used with buffers */
|
||||
struct __Pyx_StructField_;
|
||||
|
||||
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
|
||||
|
||||
typedef struct {
|
||||
const char* name; /* for error messages only */
|
||||
struct __Pyx_StructField_* fields;
|
||||
size_t size; /* sizeof(type) */
|
||||
size_t arraysize[8]; /* length of array in each dimension */
|
||||
int ndim;
|
||||
char typegroup; /* _R_eal, _C_omplex, Signed _I_nt, _U_nsigned int, _S_truct, _P_ointer, _O_bject, c_H_ar */
|
||||
char is_unsigned;
|
||||
int flags;
|
||||
} __Pyx_TypeInfo;
|
||||
|
||||
typedef struct __Pyx_StructField_ {
|
||||
__Pyx_TypeInfo* type;
|
||||
const char* name;
|
||||
size_t offset;
|
||||
} __Pyx_StructField;
|
||||
|
||||
typedef struct {
|
||||
__Pyx_StructField* field;
|
||||
size_t parent_offset;
|
||||
} __Pyx_BufFmt_StackElem;
|
||||
|
||||
typedef struct {
|
||||
__Pyx_StructField root;
|
||||
__Pyx_BufFmt_StackElem* head;
|
||||
size_t fmt_offset;
|
||||
size_t new_count, enc_count;
|
||||
size_t struct_alignment;
|
||||
int is_complex;
|
||||
char enc_type;
|
||||
char new_packmode;
|
||||
char enc_packmode;
|
||||
char is_valid_array;
|
||||
} __Pyx_BufFmt_Context;
|
||||
|
||||
|
||||
/////////////// GetAndReleaseBuffer.proto ///////////////
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
|
||||
static void __Pyx_ReleaseBuffer(Py_buffer *view);
|
||||
#else
|
||||
#define __Pyx_GetBuffer PyObject_GetBuffer
|
||||
#define __Pyx_ReleaseBuffer PyBuffer_Release
|
||||
#endif
|
||||
|
||||
/////////////// GetAndReleaseBuffer ///////////////
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
|
||||
if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
|
||||
|
||||
{{for type_ptr, getbuffer, releasebuffer in types}}
|
||||
{{if getbuffer}}
|
||||
if (__Pyx_TypeCheck(obj, {{type_ptr}})) return {{getbuffer}}(obj, view, flags);
|
||||
{{endif}}
|
||||
{{endfor}}
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
|
||||
PyObject *obj = view->obj;
|
||||
if (!obj) return;
|
||||
|
||||
if (PyObject_CheckBuffer(obj)) {
|
||||
PyBuffer_Release(view);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((0)) {}
|
||||
{{for type_ptr, getbuffer, releasebuffer in types}}
|
||||
{{if releasebuffer}}
|
||||
else if (__Pyx_TypeCheck(obj, {{type_ptr}})) {{releasebuffer}}(obj, view);
|
||||
{{endif}}
|
||||
{{endfor}}
|
||||
|
||||
view->obj = NULL;
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
||||
#endif /* PY_MAJOR_VERSION < 3 */
|
||||
|
||||
|
||||
/////////////// BufferGetAndValidate.proto ///////////////
|
||||
|
||||
#define __Pyx_GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack) \
|
||||
((obj == Py_None || obj == NULL) ? \
|
||||
(__Pyx_ZeroBuffer(buf), 0) : \
|
||||
__Pyx__GetBufferAndValidate(buf, obj, dtype, flags, nd, cast, stack))
|
||||
|
||||
static int __Pyx__GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
|
||||
__Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
|
||||
static void __Pyx_ZeroBuffer(Py_buffer* buf);
|
||||
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);/*proto*/
|
||||
|
||||
static Py_ssize_t __Pyx_minusones[] = { {{ ", ".join(["-1"] * max_dims) }} };
|
||||
static Py_ssize_t __Pyx_zeros[] = { {{ ", ".join(["0"] * max_dims) }} };
|
||||
|
||||
|
||||
/////////////// BufferGetAndValidate ///////////////
|
||||
//@requires: BufferFormatCheck
|
||||
|
||||
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
|
||||
if (unlikely(info->buf == NULL)) return;
|
||||
if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
|
||||
__Pyx_ReleaseBuffer(info);
|
||||
}
|
||||
|
||||
static void __Pyx_ZeroBuffer(Py_buffer* buf) {
|
||||
buf->buf = NULL;
|
||||
buf->obj = NULL;
|
||||
buf->strides = __Pyx_zeros;
|
||||
buf->shape = __Pyx_zeros;
|
||||
buf->suboffsets = __Pyx_minusones;
|
||||
}
|
||||
|
||||
static int __Pyx__GetBufferAndValidate(
|
||||
Py_buffer* buf, PyObject* obj, __Pyx_TypeInfo* dtype, int flags,
|
||||
int nd, int cast, __Pyx_BufFmt_StackElem* stack)
|
||||
{
|
||||
buf->buf = NULL;
|
||||
if (unlikely(__Pyx_GetBuffer(obj, buf, flags) == -1)) {
|
||||
__Pyx_ZeroBuffer(buf);
|
||||
return -1;
|
||||
}
|
||||
// From this point on, we have acquired the buffer and must release it on errors.
|
||||
if (unlikely(buf->ndim != nd)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer has wrong number of dimensions (expected %d, got %d)",
|
||||
nd, buf->ndim);
|
||||
goto fail;
|
||||
}
|
||||
if (!cast) {
|
||||
__Pyx_BufFmt_Context ctx;
|
||||
__Pyx_BufFmt_Init(&ctx, stack, dtype);
|
||||
if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
|
||||
}
|
||||
if (unlikely((size_t)buf->itemsize != dtype->size)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
|
||||
buf->itemsize, (buf->itemsize > 1) ? "s" : "",
|
||||
dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
|
||||
goto fail;
|
||||
}
|
||||
if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
|
||||
return 0;
|
||||
fail:;
|
||||
__Pyx_SafeReleaseBuffer(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/////////////// BufferFormatCheck.proto ///////////////
|
||||
|
||||
// Buffer format string checking
|
||||
//
|
||||
// Buffer type checking. Utility code for checking that acquired
|
||||
// buffers match our assumptions. We only need to check ndim and
|
||||
// the format string; the access mode/flags is checked by the
|
||||
// exporter. See:
|
||||
//
|
||||
// http://docs.python.org/3/library/struct.html
|
||||
// http://legacy.python.org/dev/peps/pep-3118/#additions-to-the-struct-string-syntax
|
||||
//
|
||||
// The alignment code is copied from _struct.c in Python.
|
||||
|
||||
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts);
|
||||
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
|
||||
__Pyx_BufFmt_StackElem* stack,
|
||||
__Pyx_TypeInfo* type); /*proto*/
|
||||
|
||||
/////////////// BufferFormatCheck ///////////////
|
||||
//@requires: ModuleSetupCode.c::IsLittleEndian
|
||||
//@requires: BufferFormatStructs
|
||||
|
||||
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
|
||||
__Pyx_BufFmt_StackElem* stack,
|
||||
__Pyx_TypeInfo* type) {
|
||||
stack[0].field = &ctx->root;
|
||||
stack[0].parent_offset = 0;
|
||||
ctx->root.type = type;
|
||||
ctx->root.name = "buffer dtype";
|
||||
ctx->root.offset = 0;
|
||||
ctx->head = stack;
|
||||
ctx->head->field = &ctx->root;
|
||||
ctx->fmt_offset = 0;
|
||||
ctx->head->parent_offset = 0;
|
||||
ctx->new_packmode = '@';
|
||||
ctx->enc_packmode = '@';
|
||||
ctx->new_count = 1;
|
||||
ctx->enc_count = 0;
|
||||
ctx->enc_type = 0;
|
||||
ctx->is_complex = 0;
|
||||
ctx->is_valid_array = 0;
|
||||
ctx->struct_alignment = 0;
|
||||
while (type->typegroup == 'S') {
|
||||
++ctx->head;
|
||||
ctx->head->field = type->fields;
|
||||
ctx->head->parent_offset = 0;
|
||||
type = type->fields->type;
|
||||
}
|
||||
}
|
||||
|
||||
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
|
||||
int count;
|
||||
const char* t = *ts;
|
||||
if (*t < '0' || *t > '9') {
|
||||
return -1;
|
||||
} else {
|
||||
count = *t++ - '0';
|
||||
while (*t >= '0' && *t <= '9') {
|
||||
count *= 10;
|
||||
count += *t++ - '0';
|
||||
}
|
||||
}
|
||||
*ts = t;
|
||||
return count;
|
||||
}
|
||||
|
||||
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
|
||||
int number = __Pyx_BufFmt_ParseNumber(ts);
|
||||
if (number == -1) /* First char was not a digit */
|
||||
PyErr_Format(PyExc_ValueError,\
|
||||
"Does not understand character buffer dtype format string ('%c')", **ts);
|
||||
return number;
|
||||
}
|
||||
|
||||
|
||||
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Unexpected format string character: '%c'", ch);
|
||||
}
|
||||
|
||||
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
|
||||
switch (ch) {
|
||||
case '?': return "'bool'";
|
||||
case 'c': return "'char'";
|
||||
case 'b': return "'signed char'";
|
||||
case 'B': return "'unsigned char'";
|
||||
case 'h': return "'short'";
|
||||
case 'H': return "'unsigned short'";
|
||||
case 'i': return "'int'";
|
||||
case 'I': return "'unsigned int'";
|
||||
case 'l': return "'long'";
|
||||
case 'L': return "'unsigned long'";
|
||||
case 'q': return "'long long'";
|
||||
case 'Q': return "'unsigned long long'";
|
||||
case 'f': return (is_complex ? "'complex float'" : "'float'");
|
||||
case 'd': return (is_complex ? "'complex double'" : "'double'");
|
||||
case 'g': return (is_complex ? "'complex long double'" : "'long double'");
|
||||
case 'T': return "a struct";
|
||||
case 'O': return "Python object";
|
||||
case 'P': return "a pointer";
|
||||
case 's': case 'p': return "a string";
|
||||
case 0: return "end";
|
||||
default: return "unparseable format string";
|
||||
}
|
||||
}
|
||||
|
||||
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
|
||||
switch (ch) {
|
||||
case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
|
||||
case 'h': case 'H': return 2;
|
||||
case 'i': case 'I': case 'l': case 'L': return 4;
|
||||
case 'q': case 'Q': return 8;
|
||||
case 'f': return (is_complex ? 8 : 4);
|
||||
case 'd': return (is_complex ? 16 : 8);
|
||||
case 'g': {
|
||||
PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
|
||||
return 0;
|
||||
}
|
||||
case 'O': case 'P': return sizeof(void*);
|
||||
default:
|
||||
__Pyx_BufFmt_RaiseUnexpectedChar(ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
|
||||
switch (ch) {
|
||||
case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
|
||||
case 'h': case 'H': return sizeof(short);
|
||||
case 'i': case 'I': return sizeof(int);
|
||||
case 'l': case 'L': return sizeof(long);
|
||||
#ifdef HAVE_LONG_LONG
|
||||
case 'q': case 'Q': return sizeof(PY_LONG_LONG);
|
||||
#endif
|
||||
case 'f': return sizeof(float) * (is_complex ? 2 : 1);
|
||||
case 'd': return sizeof(double) * (is_complex ? 2 : 1);
|
||||
case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
|
||||
case 'O': case 'P': return sizeof(void*);
|
||||
default: {
|
||||
__Pyx_BufFmt_RaiseUnexpectedChar(ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct { char c; short x; } __Pyx_st_short;
|
||||
typedef struct { char c; int x; } __Pyx_st_int;
|
||||
typedef struct { char c; long x; } __Pyx_st_long;
|
||||
typedef struct { char c; float x; } __Pyx_st_float;
|
||||
typedef struct { char c; double x; } __Pyx_st_double;
|
||||
typedef struct { char c; long double x; } __Pyx_st_longdouble;
|
||||
typedef struct { char c; void *x; } __Pyx_st_void_p;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
|
||||
#endif
|
||||
|
||||
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) {
|
||||
switch (ch) {
|
||||
case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
|
||||
case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
|
||||
case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
|
||||
case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
|
||||
#ifdef HAVE_LONG_LONG
|
||||
case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
|
||||
#endif
|
||||
case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
|
||||
case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
|
||||
case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
|
||||
case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
|
||||
default:
|
||||
__Pyx_BufFmt_RaiseUnexpectedChar(ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* These are for computing the padding at the end of the struct to align
|
||||
on the first member of the struct. This will probably the same as above,
|
||||
but we don't have any guarantees.
|
||||
*/
|
||||
typedef struct { short x; char c; } __Pyx_pad_short;
|
||||
typedef struct { int x; char c; } __Pyx_pad_int;
|
||||
typedef struct { long x; char c; } __Pyx_pad_long;
|
||||
typedef struct { float x; char c; } __Pyx_pad_float;
|
||||
typedef struct { double x; char c; } __Pyx_pad_double;
|
||||
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
|
||||
typedef struct { void *x; char c; } __Pyx_pad_void_p;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
|
||||
#endif
|
||||
|
||||
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) {
|
||||
switch (ch) {
|
||||
case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
|
||||
case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
|
||||
case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
|
||||
case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
|
||||
#ifdef HAVE_LONG_LONG
|
||||
case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
|
||||
#endif
|
||||
case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
|
||||
case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
|
||||
case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
|
||||
case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
|
||||
default:
|
||||
__Pyx_BufFmt_RaiseUnexpectedChar(ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
|
||||
switch (ch) {
|
||||
case 'c':
|
||||
return 'H';
|
||||
case 'b': case 'h': case 'i':
|
||||
case 'l': case 'q': case 's': case 'p':
|
||||
return 'I';
|
||||
case '?': case 'B': case 'H': case 'I': case 'L': case 'Q':
|
||||
return 'U';
|
||||
case 'f': case 'd': case 'g':
|
||||
return (is_complex ? 'C' : 'R');
|
||||
case 'O':
|
||||
return 'O';
|
||||
case 'P':
|
||||
return 'P';
|
||||
default: {
|
||||
__Pyx_BufFmt_RaiseUnexpectedChar(ch);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
|
||||
if (ctx->head == NULL || ctx->head->field == &ctx->root) {
|
||||
const char* expected;
|
||||
const char* quote;
|
||||
if (ctx->head == NULL) {
|
||||
expected = "end";
|
||||
quote = "";
|
||||
} else {
|
||||
expected = ctx->head->field->type->name;
|
||||
quote = "'";
|
||||
}
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer dtype mismatch, expected %s%s%s but got %s",
|
||||
quote, expected, quote,
|
||||
__Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
|
||||
} else {
|
||||
__Pyx_StructField* field = ctx->head->field;
|
||||
__Pyx_StructField* parent = (ctx->head - 1)->field;
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
|
||||
field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
|
||||
parent->type->name, field->name);
|
||||
}
|
||||
}
|
||||
|
||||
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
|
||||
char group;
|
||||
size_t size, offset, arraysize = 1;
|
||||
|
||||
/* printf("processing... %s\n", ctx->head->field->type->name); */
|
||||
|
||||
if (ctx->enc_type == 0) return 0;
|
||||
|
||||
/* Validate array size */
|
||||
if (ctx->head->field->type->arraysize[0]) {
|
||||
int i, ndim = 0;
|
||||
|
||||
/* handle strings ('s' and 'p') */
|
||||
if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
|
||||
ctx->is_valid_array = ctx->head->field->type->ndim == 1;
|
||||
ndim = 1;
|
||||
if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Expected a dimension of size %zu, got %zu",
|
||||
ctx->head->field->type->arraysize[0], ctx->enc_count);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx->is_valid_array) {
|
||||
PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
|
||||
ctx->head->field->type->ndim, ndim);
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < ctx->head->field->type->ndim; i++) {
|
||||
arraysize *= ctx->head->field->type->arraysize[i];
|
||||
}
|
||||
ctx->is_valid_array = 0;
|
||||
ctx->enc_count = 1;
|
||||
}
|
||||
|
||||
group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
|
||||
do {
|
||||
__Pyx_StructField* field = ctx->head->field;
|
||||
__Pyx_TypeInfo* type = field->type;
|
||||
|
||||
if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
|
||||
size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
|
||||
} else {
|
||||
size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
|
||||
}
|
||||
|
||||
if (ctx->enc_packmode == '@') {
|
||||
size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
|
||||
size_t align_mod_offset;
|
||||
if (align_at == 0) return -1;
|
||||
align_mod_offset = ctx->fmt_offset % align_at;
|
||||
if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
|
||||
|
||||
if (ctx->struct_alignment == 0)
|
||||
ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
|
||||
ctx->is_complex);
|
||||
}
|
||||
|
||||
if (type->size != size || type->typegroup != group) {
|
||||
if (type->typegroup == 'C' && type->fields != NULL) {
|
||||
/* special case -- treat as struct rather than complex number */
|
||||
size_t parent_offset = ctx->head->parent_offset + field->offset;
|
||||
++ctx->head;
|
||||
ctx->head->field = type->fields;
|
||||
ctx->head->parent_offset = parent_offset;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((type->typegroup == 'H' || group == 'H') && type->size == size) {
|
||||
/* special case -- chars don't care about sign */
|
||||
} else {
|
||||
__Pyx_BufFmt_RaiseExpected(ctx);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
offset = ctx->head->parent_offset + field->offset;
|
||||
if (ctx->fmt_offset != offset) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
|
||||
(Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->fmt_offset += size;
|
||||
if (arraysize)
|
||||
ctx->fmt_offset += (arraysize - 1) * size;
|
||||
|
||||
--ctx->enc_count; /* Consume from buffer string */
|
||||
|
||||
/* Done checking, move to next field, pushing or popping struct stack if needed */
|
||||
while (1) {
|
||||
if (field == &ctx->root) {
|
||||
ctx->head = NULL;
|
||||
if (ctx->enc_count != 0) {
|
||||
__Pyx_BufFmt_RaiseExpected(ctx);
|
||||
return -1;
|
||||
}
|
||||
break; /* breaks both loops as ctx->enc_count == 0 */
|
||||
}
|
||||
ctx->head->field = ++field;
|
||||
if (field->type == NULL) {
|
||||
--ctx->head;
|
||||
field = ctx->head->field;
|
||||
continue;
|
||||
} else if (field->type->typegroup == 'S') {
|
||||
size_t parent_offset = ctx->head->parent_offset + field->offset;
|
||||
if (field->type->fields->type == NULL) continue; /* empty struct */
|
||||
field = field->type->fields;
|
||||
++ctx->head;
|
||||
ctx->head->field = field;
|
||||
ctx->head->parent_offset = parent_offset;
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (ctx->enc_count);
|
||||
ctx->enc_type = 0;
|
||||
ctx->is_complex = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse an array in the format string (e.g. (1,2,3)) */
|
||||
static PyObject *
|
||||
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
|
||||
{
|
||||
const char *ts = *tsp;
|
||||
int i = 0, number, ndim;
|
||||
|
||||
++ts;
|
||||
if (ctx->new_count != 1) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Cannot handle repeated arrays in format string");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Process the previous element */
|
||||
if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
|
||||
|
||||
// store ndim now, as field advanced by __Pyx_BufFmt_ProcessTypeChunk call
|
||||
ndim = ctx->head->field->type->ndim;
|
||||
|
||||
/* Parse all numbers in the format string */
|
||||
while (*ts && *ts != ')') {
|
||||
// ignore space characters (not using isspace() due to C/C++ problem on MacOS-X)
|
||||
switch (*ts) {
|
||||
case ' ': case '\f': case '\r': case '\n': case '\t': case '\v': continue;
|
||||
default: break; /* not a 'break' in the loop */
|
||||
}
|
||||
|
||||
number = __Pyx_BufFmt_ExpectNumber(&ts);
|
||||
if (number == -1) return NULL;
|
||||
|
||||
if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
|
||||
return PyErr_Format(PyExc_ValueError,
|
||||
"Expected a dimension of size %zu, got %d",
|
||||
ctx->head->field->type->arraysize[i], number);
|
||||
|
||||
if (*ts != ',' && *ts != ')')
|
||||
return PyErr_Format(PyExc_ValueError,
|
||||
"Expected a comma in format string, got '%c'", *ts);
|
||||
|
||||
if (*ts == ',') ts++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i != ndim)
|
||||
return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
|
||||
ctx->head->field->type->ndim, i);
|
||||
|
||||
if (!*ts) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Unexpected end of format string, expected ')'");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->is_valid_array = 1;
|
||||
ctx->new_count = 1;
|
||||
*tsp = ++ts;
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
|
||||
int got_Z = 0;
|
||||
|
||||
while (1) {
|
||||
/* puts(ts); */
|
||||
switch(*ts) {
|
||||
case 0:
|
||||
if (ctx->enc_type != 0 && ctx->head == NULL) {
|
||||
__Pyx_BufFmt_RaiseExpected(ctx);
|
||||
return NULL;
|
||||
}
|
||||
if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
|
||||
if (ctx->head != NULL) {
|
||||
__Pyx_BufFmt_RaiseExpected(ctx);
|
||||
return NULL;
|
||||
}
|
||||
return ts;
|
||||
case ' ':
|
||||
case '\r':
|
||||
case '\n':
|
||||
++ts;
|
||||
break;
|
||||
case '<':
|
||||
if (!__Pyx_Is_Little_Endian()) {
|
||||
PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
|
||||
return NULL;
|
||||
}
|
||||
ctx->new_packmode = '=';
|
||||
++ts;
|
||||
break;
|
||||
case '>':
|
||||
case '!':
|
||||
if (__Pyx_Is_Little_Endian()) {
|
||||
PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
|
||||
return NULL;
|
||||
}
|
||||
ctx->new_packmode = '=';
|
||||
++ts;
|
||||
break;
|
||||
case '=':
|
||||
case '@':
|
||||
case '^':
|
||||
ctx->new_packmode = *ts++;
|
||||
break;
|
||||
case 'T': /* substruct */
|
||||
{
|
||||
const char* ts_after_sub;
|
||||
size_t i, struct_count = ctx->new_count;
|
||||
size_t struct_alignment = ctx->struct_alignment;
|
||||
ctx->new_count = 1;
|
||||
++ts;
|
||||
if (*ts != '{') {
|
||||
PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
|
||||
return NULL;
|
||||
}
|
||||
if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
|
||||
ctx->enc_type = 0; /* Erase processed last struct element */
|
||||
ctx->enc_count = 0;
|
||||
ctx->struct_alignment = 0;
|
||||
++ts;
|
||||
ts_after_sub = ts;
|
||||
for (i = 0; i != struct_count; ++i) {
|
||||
ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
|
||||
if (!ts_after_sub) return NULL;
|
||||
}
|
||||
ts = ts_after_sub;
|
||||
if (struct_alignment) ctx->struct_alignment = struct_alignment;
|
||||
}
|
||||
break;
|
||||
case '}': /* end of substruct; either repeat or move on */
|
||||
{
|
||||
size_t alignment = ctx->struct_alignment;
|
||||
++ts;
|
||||
if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
|
||||
ctx->enc_type = 0; /* Erase processed last struct element */
|
||||
if (alignment && ctx->fmt_offset % alignment) {
|
||||
/* Pad struct on size of the first member */
|
||||
ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
|
||||
}
|
||||
}
|
||||
return ts;
|
||||
case 'x':
|
||||
if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
|
||||
ctx->fmt_offset += ctx->new_count;
|
||||
ctx->new_count = 1;
|
||||
ctx->enc_count = 0;
|
||||
ctx->enc_type = 0;
|
||||
ctx->enc_packmode = ctx->new_packmode;
|
||||
++ts;
|
||||
break;
|
||||
case 'Z':
|
||||
got_Z = 1;
|
||||
++ts;
|
||||
if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
|
||||
__Pyx_BufFmt_RaiseUnexpectedChar('Z');
|
||||
return NULL;
|
||||
}
|
||||
CYTHON_FALLTHROUGH;
|
||||
case '?': case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
|
||||
case 'l': case 'L': case 'q': case 'Q':
|
||||
case 'f': case 'd': case 'g':
|
||||
case 'O': case 'p':
|
||||
if ((ctx->enc_type == *ts) && (got_Z == ctx->is_complex) &&
|
||||
(ctx->enc_packmode == ctx->new_packmode) && (!ctx->is_valid_array)) {
|
||||
/* Continue pooling same type */
|
||||
ctx->enc_count += ctx->new_count;
|
||||
ctx->new_count = 1;
|
||||
got_Z = 0;
|
||||
++ts;
|
||||
break;
|
||||
}
|
||||
CYTHON_FALLTHROUGH;
|
||||
case 's':
|
||||
/* 's' or new type (cannot be added to current pool) */
|
||||
if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
|
||||
ctx->enc_count = ctx->new_count;
|
||||
ctx->enc_packmode = ctx->new_packmode;
|
||||
ctx->enc_type = *ts;
|
||||
ctx->is_complex = got_Z;
|
||||
++ts;
|
||||
ctx->new_count = 1;
|
||||
got_Z = 0;
|
||||
break;
|
||||
case ':':
|
||||
++ts;
|
||||
while(*ts != ':') ++ts;
|
||||
++ts;
|
||||
break;
|
||||
case '(':
|
||||
if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
int number = __Pyx_BufFmt_ExpectNumber(&ts);
|
||||
if (number == -1) return NULL;
|
||||
ctx->new_count = (size_t)number;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////// TypeInfoCompare.proto ///////////////
|
||||
static int __pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b);
|
||||
|
||||
/////////////// TypeInfoCompare ///////////////
|
||||
//@requires: BufferFormatStructs
|
||||
|
||||
// See if two dtypes are equal
|
||||
static int
|
||||
__pyx_typeinfo_cmp(__Pyx_TypeInfo *a, __Pyx_TypeInfo *b)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!a || !b)
|
||||
return 0;
|
||||
|
||||
if (a == b)
|
||||
return 1;
|
||||
|
||||
if (a->size != b->size || a->typegroup != b->typegroup ||
|
||||
a->is_unsigned != b->is_unsigned || a->ndim != b->ndim) {
|
||||
if (a->typegroup == 'H' || b->typegroup == 'H') {
|
||||
/* Special case for chars */
|
||||
return a->size == b->size;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (a->ndim) {
|
||||
/* Verify multidimensional C arrays */
|
||||
for (i = 0; i < a->ndim; i++)
|
||||
if (a->arraysize[i] != b->arraysize[i])
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a->typegroup == 'S') {
|
||||
/* Check for packed struct */
|
||||
if (a->flags != b->flags)
|
||||
return 0;
|
||||
|
||||
/* compare all struct fields */
|
||||
if (a->fields || b->fields) {
|
||||
/* Check if both have fields */
|
||||
if (!(a->fields && b->fields))
|
||||
return 0;
|
||||
|
||||
/* compare */
|
||||
for (i = 0; a->fields[i].type && b->fields[i].type; i++) {
|
||||
__Pyx_StructField *field_a = a->fields + i;
|
||||
__Pyx_StructField *field_b = b->fields + i;
|
||||
|
||||
if (field_a->offset != field_b->offset ||
|
||||
!__pyx_typeinfo_cmp(field_a->type, field_b->type))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If all fields are processed, we have a match */
|
||||
return !a->fields[i].type && !b->fields[i].type;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/////////////// TypeInfoToFormat.proto ///////////////
|
||||
struct __pyx_typeinfo_string {
|
||||
char string[3];
|
||||
};
|
||||
static struct __pyx_typeinfo_string __Pyx_TypeInfoToFormat(__Pyx_TypeInfo *type);
|
||||
|
||||
/////////////// TypeInfoToFormat ///////////////
|
||||
//@requires: BufferFormatStructs
|
||||
|
||||
// See also MemoryView.pyx:BufferFormatFromTypeInfo
|
||||
|
||||
static struct __pyx_typeinfo_string __Pyx_TypeInfoToFormat(__Pyx_TypeInfo *type) {
|
||||
struct __pyx_typeinfo_string result = { {0} };
|
||||
char *buf = (char *) result.string;
|
||||
size_t size = type->size;
|
||||
|
||||
switch (type->typegroup) {
|
||||
case 'H':
|
||||
*buf = 'c';
|
||||
break;
|
||||
case 'I':
|
||||
case 'U':
|
||||
if (size == 1)
|
||||
*buf = (type->is_unsigned) ? 'B' : 'b';
|
||||
else if (size == 2)
|
||||
*buf = (type->is_unsigned) ? 'H' : 'h';
|
||||
else if (size == 4)
|
||||
*buf = (type->is_unsigned) ? 'I' : 'i';
|
||||
else if (size == 8)
|
||||
*buf = (type->is_unsigned) ? 'Q' : 'q';
|
||||
break;
|
||||
case 'P':
|
||||
*buf = 'P';
|
||||
break;
|
||||
case 'C':
|
||||
{
|
||||
__Pyx_TypeInfo complex_type = *type;
|
||||
complex_type.typegroup = 'R';
|
||||
complex_type.size /= 2;
|
||||
|
||||
*buf++ = 'Z';
|
||||
*buf = __Pyx_TypeInfoToFormat(&complex_type).string[0];
|
||||
break;
|
||||
}
|
||||
case 'R':
|
||||
if (size == 4)
|
||||
*buf = 'f';
|
||||
else if (size == 8)
|
||||
*buf = 'd';
|
||||
else
|
||||
*buf = 'g';
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
542
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Builtins.c
Normal file
542
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Builtins.c
Normal file
|
@ -0,0 +1,542 @@
|
|||
/*
|
||||
* Special implementations of built-in functions and methods.
|
||||
*
|
||||
* Optional optimisations for builtins are in Optimize.c.
|
||||
*
|
||||
* General object operations and protocols are in ObjectHandling.c.
|
||||
*/
|
||||
|
||||
//////////////////// Globals.proto ////////////////////
|
||||
|
||||
static PyObject* __Pyx_Globals(void); /*proto*/
|
||||
|
||||
//////////////////// Globals ////////////////////
|
||||
//@substitute: naming
|
||||
//@requires: ObjectHandling.c::GetAttr
|
||||
|
||||
// This is a stub implementation until we have something more complete.
|
||||
// Currently, we only handle the most common case of a read-only dict
|
||||
// of Python names. Supporting cdef names in the module and write
|
||||
// access requires a rewrite as a dedicated class.
|
||||
|
||||
static PyObject* __Pyx_Globals(void) {
|
||||
Py_ssize_t i;
|
||||
PyObject *names;
|
||||
PyObject *globals = $moddict_cname;
|
||||
Py_INCREF(globals);
|
||||
names = PyObject_Dir($module_cname);
|
||||
if (!names)
|
||||
goto bad;
|
||||
for (i = PyList_GET_SIZE(names)-1; i >= 0; i--) {
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
PyObject* name = PySequence_ITEM(names, i);
|
||||
if (!name)
|
||||
goto bad;
|
||||
#else
|
||||
PyObject* name = PyList_GET_ITEM(names, i);
|
||||
#endif
|
||||
if (!PyDict_Contains(globals, name)) {
|
||||
PyObject* value = __Pyx_GetAttr($module_cname, name);
|
||||
if (!value) {
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
Py_DECREF(name);
|
||||
#endif
|
||||
goto bad;
|
||||
}
|
||||
if (PyDict_SetItem(globals, name, value) < 0) {
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
Py_DECREF(name);
|
||||
#endif
|
||||
Py_DECREF(value);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
Py_DECREF(name);
|
||||
#endif
|
||||
}
|
||||
Py_DECREF(names);
|
||||
return globals;
|
||||
bad:
|
||||
Py_XDECREF(names);
|
||||
Py_XDECREF(globals);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//////////////////// PyExecGlobals.proto ////////////////////
|
||||
|
||||
static PyObject* __Pyx_PyExecGlobals(PyObject*);
|
||||
|
||||
//////////////////// PyExecGlobals ////////////////////
|
||||
//@requires: Globals
|
||||
//@requires: PyExec
|
||||
|
||||
static PyObject* __Pyx_PyExecGlobals(PyObject* code) {
|
||||
PyObject* result;
|
||||
PyObject* globals = __Pyx_Globals();
|
||||
if (unlikely(!globals))
|
||||
return NULL;
|
||||
result = __Pyx_PyExec2(code, globals);
|
||||
Py_DECREF(globals);
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////// PyExec.proto ////////////////////
|
||||
|
||||
static PyObject* __Pyx_PyExec3(PyObject*, PyObject*, PyObject*);
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyExec2(PyObject*, PyObject*);
|
||||
|
||||
//////////////////// PyExec ////////////////////
|
||||
//@substitute: naming
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyExec2(PyObject* o, PyObject* globals) {
|
||||
return __Pyx_PyExec3(o, globals, NULL);
|
||||
}
|
||||
|
||||
static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals) {
|
||||
PyObject* result;
|
||||
PyObject* s = 0;
|
||||
char *code = 0;
|
||||
|
||||
if (!globals || globals == Py_None) {
|
||||
globals = $moddict_cname;
|
||||
} else if (!PyDict_Check(globals)) {
|
||||
PyErr_Format(PyExc_TypeError, "exec() arg 2 must be a dict, not %.200s",
|
||||
Py_TYPE(globals)->tp_name);
|
||||
goto bad;
|
||||
}
|
||||
if (!locals || locals == Py_None) {
|
||||
locals = globals;
|
||||
}
|
||||
|
||||
if (__Pyx_PyDict_GetItemStr(globals, PYIDENT("__builtins__")) == NULL) {
|
||||
if (PyDict_SetItem(globals, PYIDENT("__builtins__"), PyEval_GetBuiltins()) < 0)
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (PyCode_Check(o)) {
|
||||
if (__Pyx_PyCode_HasFreeVars((PyCodeObject *)o)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"code object passed to exec() may not contain free variables");
|
||||
goto bad;
|
||||
}
|
||||
#if PY_VERSION_HEX < 0x030200B1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400)
|
||||
result = PyEval_EvalCode((PyCodeObject *)o, globals, locals);
|
||||
#else
|
||||
result = PyEval_EvalCode(o, globals, locals);
|
||||
#endif
|
||||
} else {
|
||||
PyCompilerFlags cf;
|
||||
cf.cf_flags = 0;
|
||||
#if PY_VERSION_HEX >= 0x030800A3
|
||||
cf.cf_feature_version = PY_MINOR_VERSION;
|
||||
#endif
|
||||
if (PyUnicode_Check(o)) {
|
||||
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
|
||||
s = PyUnicode_AsUTF8String(o);
|
||||
if (!s) goto bad;
|
||||
o = s;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
} else if (!PyBytes_Check(o)) {
|
||||
#else
|
||||
} else if (!PyString_Check(o)) {
|
||||
#endif
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"exec: arg 1 must be string, bytes or code object, got %.200s",
|
||||
Py_TYPE(o)->tp_name);
|
||||
goto bad;
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
code = PyBytes_AS_STRING(o);
|
||||
#else
|
||||
code = PyString_AS_STRING(o);
|
||||
#endif
|
||||
if (PyEval_MergeCompilerFlags(&cf)) {
|
||||
result = PyRun_StringFlags(code, Py_file_input, globals, locals, &cf);
|
||||
} else {
|
||||
result = PyRun_String(code, Py_file_input, globals, locals);
|
||||
}
|
||||
Py_XDECREF(s);
|
||||
}
|
||||
|
||||
return result;
|
||||
bad:
|
||||
Py_XDECREF(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////// GetAttr3.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/
|
||||
|
||||
//////////////////// GetAttr3 ////////////////////
|
||||
//@requires: ObjectHandling.c::GetAttr
|
||||
//@requires: Exceptions.c::PyThreadStateGet
|
||||
//@requires: Exceptions.c::PyErrFetchRestore
|
||||
//@requires: Exceptions.c::PyErrExceptionMatches
|
||||
|
||||
static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
|
||||
__Pyx_PyThreadState_declare
|
||||
__Pyx_PyThreadState_assign
|
||||
if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
|
||||
return NULL;
|
||||
__Pyx_PyErr_Clear();
|
||||
Py_INCREF(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
|
||||
PyObject *r = __Pyx_GetAttr(o, n);
|
||||
return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
|
||||
}
|
||||
|
||||
//////////////////// HasAttr.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); /*proto*/
|
||||
|
||||
//////////////////// HasAttr ////////////////////
|
||||
//@requires: ObjectHandling.c::GetAttr
|
||||
|
||||
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
|
||||
PyObject *r;
|
||||
if (unlikely(!__Pyx_PyBaseString_Check(n))) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"hasattr(): attribute name must be string");
|
||||
return -1;
|
||||
}
|
||||
r = __Pyx_GetAttr(o, n);
|
||||
if (unlikely(!r)) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
} else {
|
||||
Py_DECREF(r);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////// Intern.proto ////////////////////
|
||||
|
||||
static PyObject* __Pyx_Intern(PyObject* s); /* proto */
|
||||
|
||||
//////////////////// Intern ////////////////////
|
||||
|
||||
static PyObject* __Pyx_Intern(PyObject* s) {
|
||||
if (!(likely(PyString_CheckExact(s)))) {
|
||||
PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(s)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
Py_INCREF(s);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyUnicode_InternInPlace(&s);
|
||||
#else
|
||||
PyString_InternInPlace(&s);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
//////////////////// abs_longlong.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
|
||||
#if defined (__cplusplus) && __cplusplus >= 201103L
|
||||
return std::abs(x);
|
||||
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
return llabs(x);
|
||||
#elif defined (_MSC_VER)
|
||||
// abs() is defined for long, but 64-bits type on MSVC is long long.
|
||||
// Use MS-specific _abs64() instead, which returns the original (negative) value for abs(-MAX-1)
|
||||
return _abs64(x);
|
||||
#elif defined (__GNUC__)
|
||||
// gcc or clang on 64 bit windows.
|
||||
return __builtin_llabs(x);
|
||||
#else
|
||||
if (sizeof(PY_LONG_LONG) <= sizeof(Py_ssize_t))
|
||||
return __Pyx_sst_abs(x);
|
||||
return (x<0) ? -x : x;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//////////////////// py_abs.proto ////////////////////
|
||||
|
||||
#if CYTHON_USE_PYLONG_INTERNALS
|
||||
static PyObject *__Pyx_PyLong_AbsNeg(PyObject *num);/*proto*/
|
||||
|
||||
#define __Pyx_PyNumber_Absolute(x) \
|
||||
((likely(PyLong_CheckExact(x))) ? \
|
||||
(likely(Py_SIZE(x) >= 0) ? (Py_INCREF(x), (x)) : __Pyx_PyLong_AbsNeg(x)) : \
|
||||
PyNumber_Absolute(x))
|
||||
|
||||
#else
|
||||
#define __Pyx_PyNumber_Absolute(x) PyNumber_Absolute(x)
|
||||
#endif
|
||||
|
||||
//////////////////// py_abs ////////////////////
|
||||
|
||||
#if CYTHON_USE_PYLONG_INTERNALS
|
||||
static PyObject *__Pyx_PyLong_AbsNeg(PyObject *n) {
|
||||
if (likely(Py_SIZE(n) == -1)) {
|
||||
// digits are unsigned
|
||||
return PyLong_FromLong(((PyLongObject*)n)->ob_digit[0]);
|
||||
}
|
||||
#if CYTHON_COMPILING_IN_CPYTHON
|
||||
{
|
||||
PyObject *copy = _PyLong_Copy((PyLongObject*)n);
|
||||
if (likely(copy)) {
|
||||
// negate the size to swap the sign
|
||||
__Pyx_SET_SIZE(copy, -Py_SIZE(copy));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
#else
|
||||
return PyNumber_Negative(n);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////// pow2.proto ////////////////////
|
||||
|
||||
#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
|
||||
|
||||
|
||||
//////////////////// object_ord.proto ////////////////////
|
||||
//@requires: TypeConversion.c::UnicodeAsUCS4
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define __Pyx_PyObject_Ord(c) \
|
||||
(likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
|
||||
#else
|
||||
#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c)
|
||||
#endif
|
||||
static long __Pyx__PyObject_Ord(PyObject* c); /*proto*/
|
||||
|
||||
//////////////////// object_ord ////////////////////
|
||||
|
||||
static long __Pyx__PyObject_Ord(PyObject* c) {
|
||||
Py_ssize_t size;
|
||||
if (PyBytes_Check(c)) {
|
||||
size = PyBytes_GET_SIZE(c);
|
||||
if (likely(size == 1)) {
|
||||
return (unsigned char) PyBytes_AS_STRING(c)[0];
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
} else if (PyUnicode_Check(c)) {
|
||||
return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
|
||||
#endif
|
||||
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
|
||||
} else if (PyByteArray_Check(c)) {
|
||||
size = PyByteArray_GET_SIZE(c);
|
||||
if (likely(size == 1)) {
|
||||
return (unsigned char) PyByteArray_AS_STRING(c)[0];
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// FIXME: support character buffers - but CPython doesn't support them either
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"ord() expected string of length 1, but %.200s found", Py_TYPE(c)->tp_name);
|
||||
return (long)(Py_UCS4)-1;
|
||||
}
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"ord() expected a character, but string of length %zd found", size);
|
||||
return (long)(Py_UCS4)-1;
|
||||
}
|
||||
|
||||
|
||||
//////////////////// py_dict_keys.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_keys ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "keys", d);
|
||||
else
|
||||
return PyDict_Keys(d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_values.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_values ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "values", d);
|
||||
else
|
||||
return PyDict_Values(d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_items.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_items ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "items", d);
|
||||
else
|
||||
return PyDict_Items(d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_iterkeys.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_IterKeys(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_iterkeys ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_IterKeys(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "keys", d);
|
||||
else
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "iterkeys", d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_itervalues.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_IterValues(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_itervalues ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_IterValues(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "values", d);
|
||||
else
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "itervalues", d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_iteritems.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_IterItems(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_iteritems ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_IterItems(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "items", d);
|
||||
else
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "iteritems", d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_viewkeys.proto ////////////////////
|
||||
|
||||
#if PY_VERSION_HEX < 0x02070000
|
||||
#error This module uses dict views, which require Python 2.7 or later
|
||||
#endif
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewKeys(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_viewkeys ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewKeys(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "keys", d);
|
||||
else
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "viewkeys", d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_viewvalues.proto ////////////////////
|
||||
|
||||
#if PY_VERSION_HEX < 0x02070000
|
||||
#error This module uses dict views, which require Python 2.7 or later
|
||||
#endif
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewValues(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_viewvalues ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewValues(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "values", d);
|
||||
else
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "viewvalues", d);
|
||||
}
|
||||
|
||||
//////////////////// py_dict_viewitems.proto ////////////////////
|
||||
|
||||
#if PY_VERSION_HEX < 0x02070000
|
||||
#error This module uses dict views, which require Python 2.7 or later
|
||||
#endif
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewItems(PyObject* d); /*proto*/
|
||||
|
||||
//////////////////// py_dict_viewitems ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyDict_ViewItems(PyObject* d) {
|
||||
if (PY_MAJOR_VERSION >= 3)
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "items", d);
|
||||
else
|
||||
return CALL_UNBOUND_METHOD(PyDict_Type, "viewitems", d);
|
||||
}
|
||||
|
||||
|
||||
//////////////////// pyfrozenset_new.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it);
|
||||
|
||||
//////////////////// pyfrozenset_new ////////////////////
|
||||
//@substitute: naming
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
|
||||
if (it) {
|
||||
PyObject* result;
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
// PyPy currently lacks PyFrozenSet_CheckExact() and PyFrozenSet_New()
|
||||
PyObject* args;
|
||||
args = PyTuple_Pack(1, it);
|
||||
if (unlikely(!args))
|
||||
return NULL;
|
||||
result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL);
|
||||
Py_DECREF(args);
|
||||
return result;
|
||||
#else
|
||||
if (PyFrozenSet_CheckExact(it)) {
|
||||
Py_INCREF(it);
|
||||
return it;
|
||||
}
|
||||
result = PyFrozenSet_New(it);
|
||||
if (unlikely(!result))
|
||||
return NULL;
|
||||
if ((PY_VERSION_HEX >= 0x031000A1) || likely(PySet_GET_SIZE(result)))
|
||||
return result;
|
||||
// empty frozenset is a singleton (on Python <3.10)
|
||||
// seems wasteful, but CPython does the same
|
||||
Py_DECREF(result);
|
||||
#endif
|
||||
}
|
||||
#if CYTHON_USE_TYPE_SLOTS
|
||||
return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, $empty_tuple, NULL);
|
||||
#else
|
||||
return PyObject_Call((PyObject*)&PyFrozenSet_Type, $empty_tuple, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//////////////////// PySet_Update.proto ////////////////////
|
||||
|
||||
static CYTHON_INLINE int __Pyx_PySet_Update(PyObject* set, PyObject* it); /*proto*/
|
||||
|
||||
//////////////////// PySet_Update ////////////////////
|
||||
|
||||
static CYTHON_INLINE int __Pyx_PySet_Update(PyObject* set, PyObject* it) {
|
||||
PyObject *retval;
|
||||
#if CYTHON_USE_TYPE_SLOTS && !CYTHON_COMPILING_IN_PYPY
|
||||
if (PyAnySet_Check(it)) {
|
||||
if (PySet_GET_SIZE(it) == 0)
|
||||
return 0;
|
||||
// fast and safe case: CPython will update our result set and return it
|
||||
retval = PySet_Type.tp_as_number->nb_inplace_or(set, it);
|
||||
if (likely(retval == set)) {
|
||||
Py_DECREF(retval);
|
||||
return 0;
|
||||
}
|
||||
if (unlikely(!retval))
|
||||
return -1;
|
||||
// unusual result, fall through to set.update() call below
|
||||
Py_DECREF(retval);
|
||||
}
|
||||
#endif
|
||||
retval = CALL_UNBOUND_METHOD(PySet_Type, "update", set, it);
|
||||
if (unlikely(!retval)) return -1;
|
||||
Py_DECREF(retval);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
#################### FromPyStructUtility ####################
|
||||
|
||||
cdef extern from *:
|
||||
ctypedef struct PyTypeObject:
|
||||
char* tp_name
|
||||
PyTypeObject *Py_TYPE(obj)
|
||||
bint PyMapping_Check(obj)
|
||||
object PyErr_Format(exc, const char *format, ...)
|
||||
|
||||
@cname("{{funcname}}")
|
||||
cdef {{struct_type}} {{funcname}}(obj) except *:
|
||||
cdef {{struct_type}} result
|
||||
if not PyMapping_Check(obj):
|
||||
PyErr_Format(TypeError, b"Expected %.16s, got %.200s", b"a mapping", Py_TYPE(obj).tp_name)
|
||||
|
||||
{{for member in var_entries:}}
|
||||
try:
|
||||
value = obj['{{member.name}}']
|
||||
except KeyError:
|
||||
raise ValueError("No value specified for struct attribute '{{member.name}}'")
|
||||
result.{{member.cname}} = value
|
||||
{{endfor}}
|
||||
return result
|
||||
|
||||
|
||||
#################### FromPyUnionUtility ####################
|
||||
|
||||
cdef extern from *:
|
||||
ctypedef struct PyTypeObject:
|
||||
char* tp_name
|
||||
PyTypeObject *Py_TYPE(obj)
|
||||
bint PyMapping_Check(obj)
|
||||
object PyErr_Format(exc, const char *format, ...)
|
||||
|
||||
@cname("{{funcname}}")
|
||||
cdef {{struct_type}} {{funcname}}(obj) except *:
|
||||
cdef {{struct_type}} result
|
||||
cdef Py_ssize_t length
|
||||
if not PyMapping_Check(obj):
|
||||
PyErr_Format(TypeError, b"Expected %.16s, got %.200s", b"a mapping", Py_TYPE(obj).tp_name)
|
||||
|
||||
last_found = None
|
||||
length = len(obj)
|
||||
if length:
|
||||
{{for member in var_entries:}}
|
||||
if '{{member.name}}' in obj:
|
||||
if last_found is not None:
|
||||
raise ValueError("More than one union attribute passed: '%s' and '%s'" % (last_found, '{{member.name}}'))
|
||||
last_found = '{{member.name}}'
|
||||
result.{{member.cname}} = obj['{{member.name}}']
|
||||
length -= 1
|
||||
if not length:
|
||||
return result
|
||||
{{endfor}}
|
||||
if last_found is None:
|
||||
raise ValueError("No value specified for any of the union attributes (%s)" %
|
||||
'{{", ".join(member.name for member in var_entries)}}')
|
||||
return result
|
||||
|
||||
|
||||
#################### cfunc.to_py ####################
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}({{return_type.ctype}} (*f)({{ ', '.join(arg.type_cname for arg in args) }}) {{except_clause}}):
|
||||
def wrap({{ ', '.join('{arg.ctype} {arg.name}'.format(arg=arg) for arg in args) }}):
|
||||
"""wrap({{', '.join(('{arg.name}: {arg.type_displayname}'.format(arg=arg) if arg.type_displayname else arg.name) for arg in args)}}){{if return_type.type_displayname}} -> {{return_type.type_displayname}}{{endif}}"""
|
||||
{{'' if return_type.type.is_void else 'return '}}f({{ ', '.join(arg.name for arg in args) }})
|
||||
return wrap
|
||||
|
||||
|
||||
#################### carray.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
object PyErr_Format(exc, const char *format, ...)
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef int {{cname}}(object o, {{base_type}} *v, Py_ssize_t length) except -1:
|
||||
cdef Py_ssize_t i = length
|
||||
try:
|
||||
i = len(o)
|
||||
except (TypeError, OverflowError):
|
||||
pass
|
||||
if i == length:
|
||||
for i, item in enumerate(o):
|
||||
if i >= length:
|
||||
break
|
||||
v[i] = item
|
||||
else:
|
||||
i += 1 # convert index to length
|
||||
if i == length:
|
||||
return 0
|
||||
|
||||
PyErr_Format(
|
||||
IndexError,
|
||||
("too many values found during array assignment, expected %zd"
|
||||
if i >= length else
|
||||
"not enough values found during array assignment, expected %zd, got %zd"),
|
||||
length, i)
|
||||
|
||||
|
||||
#################### carray.to_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
void Py_INCREF(object o)
|
||||
tuple PyTuple_New(Py_ssize_t size)
|
||||
list PyList_New(Py_ssize_t size)
|
||||
void PyTuple_SET_ITEM(object p, Py_ssize_t pos, object o)
|
||||
void PyList_SET_ITEM(object p, Py_ssize_t pos, object o)
|
||||
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef inline list {{cname}}({{base_type}} *v, Py_ssize_t length):
|
||||
cdef size_t i
|
||||
cdef object value
|
||||
l = PyList_New(length)
|
||||
for i in range(<size_t>length):
|
||||
value = v[i]
|
||||
Py_INCREF(value)
|
||||
PyList_SET_ITEM(l, i, value)
|
||||
return l
|
||||
|
||||
|
||||
@cname("{{to_tuple_cname}}")
|
||||
cdef inline tuple {{to_tuple_cname}}({{base_type}} *v, Py_ssize_t length):
|
||||
cdef size_t i
|
||||
cdef object value
|
||||
t = PyTuple_New(length)
|
||||
for i in range(<size_t>length):
|
||||
value = v[i]
|
||||
Py_INCREF(value)
|
||||
PyTuple_SET_ITEM(t, i, value)
|
||||
return t
|
|
@ -0,0 +1,95 @@
|
|||
|
||||
/////////////// CDivisionWarning.proto ///////////////
|
||||
|
||||
static int __Pyx_cdivision_warning(const char *, int); /* proto */
|
||||
|
||||
/////////////// CDivisionWarning ///////////////
|
||||
|
||||
static int __Pyx_cdivision_warning(const char *filename, int lineno) {
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
// avoid compiler warnings
|
||||
filename++; lineno++;
|
||||
return PyErr_Warn(PyExc_RuntimeWarning,
|
||||
"division with oppositely signed operands, C and Python semantics differ");
|
||||
#else
|
||||
return PyErr_WarnExplicit(PyExc_RuntimeWarning,
|
||||
"division with oppositely signed operands, C and Python semantics differ",
|
||||
filename,
|
||||
lineno,
|
||||
__Pyx_MODULE_NAME,
|
||||
NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/////////////// DivInt.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s __Pyx_div_%(type_name)s(%(type)s, %(type)s); /* proto */
|
||||
|
||||
/////////////// DivInt ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s __Pyx_div_%(type_name)s(%(type)s a, %(type)s b) {
|
||||
%(type)s q = a / b;
|
||||
%(type)s r = a - q*b;
|
||||
q -= ((r != 0) & ((r ^ b) < 0));
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
/////////////// ModInt.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s, %(type)s); /* proto */
|
||||
|
||||
/////////////// ModInt ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s a, %(type)s b) {
|
||||
%(type)s r = a %% b;
|
||||
r += ((r != 0) & ((r ^ b) < 0)) * b;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/////////////// ModFloat.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s, %(type)s); /* proto */
|
||||
|
||||
/////////////// ModFloat ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s __Pyx_mod_%(type_name)s(%(type)s a, %(type)s b) {
|
||||
%(type)s r = fmod%(math_h_modifier)s(a, b);
|
||||
r += ((r != 0) & ((r < 0) ^ (b < 0))) * b;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/////////////// IntPow.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s %(func_name)s(%(type)s, %(type)s); /* proto */
|
||||
|
||||
/////////////// IntPow ///////////////
|
||||
|
||||
static CYTHON_INLINE %(type)s %(func_name)s(%(type)s b, %(type)s e) {
|
||||
%(type)s t = b;
|
||||
switch (e) {
|
||||
case 3:
|
||||
t *= b;
|
||||
CYTHON_FALLTHROUGH;
|
||||
case 2:
|
||||
t *= b;
|
||||
CYTHON_FALLTHROUGH;
|
||||
case 1:
|
||||
return t;
|
||||
case 0:
|
||||
return 1;
|
||||
}
|
||||
#if %(signed)s
|
||||
if (unlikely(e<0)) return 0;
|
||||
#endif
|
||||
t = 1;
|
||||
while (likely(e)) {
|
||||
t *= (b * (e&1)) | ((~e)&1); /* 1 or b */
|
||||
b *= b;
|
||||
e >>= 1;
|
||||
}
|
||||
return t;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
//////////////// Capsule.proto ////////////////
|
||||
|
||||
/* Todo: wrap the rest of the functionality in similar functions */
|
||||
static CYTHON_INLINE PyObject *__pyx_capsule_create(void *p, const char *sig);
|
||||
|
||||
//////////////// Capsule ////////////////
|
||||
|
||||
static CYTHON_INLINE PyObject *
|
||||
__pyx_capsule_create(void *p, CYTHON_UNUSED const char *sig)
|
||||
{
|
||||
PyObject *cobj;
|
||||
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
cobj = PyCapsule_New(p, sig, NULL);
|
||||
#else
|
||||
cobj = PyCObject_FromVoidPtr(p, NULL);
|
||||
#endif
|
||||
|
||||
return cobj;
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/////////////// FetchCommonType.proto ///////////////
|
||||
|
||||
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
|
||||
|
||||
/////////////// FetchCommonType ///////////////
|
||||
|
||||
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
|
||||
PyObject* fake_module;
|
||||
PyTypeObject* cached_type = NULL;
|
||||
|
||||
fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
|
||||
if (!fake_module) return NULL;
|
||||
Py_INCREF(fake_module);
|
||||
|
||||
cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
|
||||
if (cached_type) {
|
||||
if (!PyType_Check((PyObject*)cached_type)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Shared Cython type %.200s is not a type object",
|
||||
type->tp_name);
|
||||
goto bad;
|
||||
}
|
||||
if (cached_type->tp_basicsize != type->tp_basicsize) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Shared Cython type %.200s has the wrong size, try recompiling",
|
||||
type->tp_name);
|
||||
goto bad;
|
||||
}
|
||||
} else {
|
||||
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
|
||||
PyErr_Clear();
|
||||
if (PyType_Ready(type) < 0) goto bad;
|
||||
if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
|
||||
goto bad;
|
||||
Py_INCREF(type);
|
||||
cached_type = type;
|
||||
}
|
||||
|
||||
done:
|
||||
Py_DECREF(fake_module);
|
||||
// NOTE: always returns owned reference, or NULL on error
|
||||
return cached_type;
|
||||
|
||||
bad:
|
||||
Py_XDECREF(cached_type);
|
||||
cached_type = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
/////////////// FetchCommonPointer.proto ///////////////
|
||||
|
||||
static void* __Pyx_FetchCommonPointer(void* pointer, const char* name);
|
||||
|
||||
/////////////// FetchCommonPointer ///////////////
|
||||
|
||||
|
||||
static void* __Pyx_FetchCommonPointer(void* pointer, const char* name) {
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
PyObject* fake_module = NULL;
|
||||
PyObject* capsule = NULL;
|
||||
void* value = NULL;
|
||||
|
||||
fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
|
||||
if (!fake_module) return NULL;
|
||||
Py_INCREF(fake_module);
|
||||
|
||||
capsule = PyObject_GetAttrString(fake_module, name);
|
||||
if (!capsule) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
|
||||
PyErr_Clear();
|
||||
capsule = PyCapsule_New(pointer, name, NULL);
|
||||
if (!capsule) goto bad;
|
||||
if (PyObject_SetAttrString(fake_module, name, capsule) < 0)
|
||||
goto bad;
|
||||
}
|
||||
value = PyCapsule_GetPointer(capsule, name);
|
||||
|
||||
bad:
|
||||
Py_XDECREF(capsule);
|
||||
Py_DECREF(fake_module);
|
||||
return value;
|
||||
#else
|
||||
return pointer;
|
||||
#endif
|
||||
}
|
291
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Complex.c
Normal file
291
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Complex.c
Normal file
|
@ -0,0 +1,291 @@
|
|||
/////////////// Header.proto ///////////////
|
||||
//@proto_block: h_code
|
||||
|
||||
#if !defined(CYTHON_CCOMPLEX)
|
||||
#if defined(__cplusplus)
|
||||
#define CYTHON_CCOMPLEX 1
|
||||
#elif defined(_Complex_I)
|
||||
#define CYTHON_CCOMPLEX 1
|
||||
#else
|
||||
#define CYTHON_CCOMPLEX 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CYTHON_CCOMPLEX
|
||||
#ifdef __cplusplus
|
||||
#include <complex>
|
||||
#else
|
||||
#include <complex.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
|
||||
#undef _Complex_I
|
||||
#define _Complex_I 1.0fj
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// RealImag.proto ///////////////
|
||||
|
||||
#if CYTHON_CCOMPLEX
|
||||
#ifdef __cplusplus
|
||||
#define __Pyx_CREAL(z) ((z).real())
|
||||
#define __Pyx_CIMAG(z) ((z).imag())
|
||||
#else
|
||||
#define __Pyx_CREAL(z) (__real__(z))
|
||||
#define __Pyx_CIMAG(z) (__imag__(z))
|
||||
#endif
|
||||
#else
|
||||
#define __Pyx_CREAL(z) ((z).real)
|
||||
#define __Pyx_CIMAG(z) ((z).imag)
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) && CYTHON_CCOMPLEX \
|
||||
&& (defined(_WIN32) || defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 5 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4 )) || __cplusplus >= 201103)
|
||||
#define __Pyx_SET_CREAL(z,x) ((z).real(x))
|
||||
#define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
|
||||
#else
|
||||
#define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
|
||||
#define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// Declarations.proto ///////////////
|
||||
//@proto_block: complex_type_declarations
|
||||
|
||||
#if CYTHON_CCOMPLEX
|
||||
#ifdef __cplusplus
|
||||
typedef ::std::complex< {{real_type}} > {{type_name}};
|
||||
#else
|
||||
typedef {{real_type}} _Complex {{type_name}};
|
||||
#endif
|
||||
#else
|
||||
typedef struct { {{real_type}} real, imag; } {{type_name}};
|
||||
#endif
|
||||
|
||||
static CYTHON_INLINE {{type}} {{type_name}}_from_parts({{real_type}}, {{real_type}});
|
||||
|
||||
/////////////// Declarations ///////////////
|
||||
|
||||
#if CYTHON_CCOMPLEX
|
||||
#ifdef __cplusplus
|
||||
static CYTHON_INLINE {{type}} {{type_name}}_from_parts({{real_type}} x, {{real_type}} y) {
|
||||
return ::std::complex< {{real_type}} >(x, y);
|
||||
}
|
||||
#else
|
||||
static CYTHON_INLINE {{type}} {{type_name}}_from_parts({{real_type}} x, {{real_type}} y) {
|
||||
return x + y*({{type}})_Complex_I;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
static CYTHON_INLINE {{type}} {{type_name}}_from_parts({{real_type}} x, {{real_type}} y) {
|
||||
{{type}} z;
|
||||
z.real = x;
|
||||
z.imag = y;
|
||||
return z;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// ToPy.proto ///////////////
|
||||
|
||||
#define __pyx_PyComplex_FromComplex(z) \
|
||||
PyComplex_FromDoubles((double)__Pyx_CREAL(z), \
|
||||
(double)__Pyx_CIMAG(z))
|
||||
|
||||
|
||||
/////////////// FromPy.proto ///////////////
|
||||
|
||||
static {{type}} __Pyx_PyComplex_As_{{type_name}}(PyObject*);
|
||||
|
||||
/////////////// FromPy ///////////////
|
||||
|
||||
static {{type}} __Pyx_PyComplex_As_{{type_name}}(PyObject* o) {
|
||||
Py_complex cval;
|
||||
#if !CYTHON_COMPILING_IN_PYPY
|
||||
if (PyComplex_CheckExact(o))
|
||||
cval = ((PyComplexObject *)o)->cval;
|
||||
else
|
||||
#endif
|
||||
cval = PyComplex_AsCComplex(o);
|
||||
return {{type_name}}_from_parts(
|
||||
({{real_type}})cval.real,
|
||||
({{real_type}})cval.imag);
|
||||
}
|
||||
|
||||
|
||||
/////////////// Arithmetic.proto ///////////////
|
||||
|
||||
#if CYTHON_CCOMPLEX
|
||||
#define __Pyx_c_eq{{func_suffix}}(a, b) ((a)==(b))
|
||||
#define __Pyx_c_sum{{func_suffix}}(a, b) ((a)+(b))
|
||||
#define __Pyx_c_diff{{func_suffix}}(a, b) ((a)-(b))
|
||||
#define __Pyx_c_prod{{func_suffix}}(a, b) ((a)*(b))
|
||||
#define __Pyx_c_quot{{func_suffix}}(a, b) ((a)/(b))
|
||||
#define __Pyx_c_neg{{func_suffix}}(a) (-(a))
|
||||
#ifdef __cplusplus
|
||||
#define __Pyx_c_is_zero{{func_suffix}}(z) ((z)==({{real_type}})0)
|
||||
#define __Pyx_c_conj{{func_suffix}}(z) (::std::conj(z))
|
||||
#if {{is_float}}
|
||||
#define __Pyx_c_abs{{func_suffix}}(z) (::std::abs(z))
|
||||
#define __Pyx_c_pow{{func_suffix}}(a, b) (::std::pow(a, b))
|
||||
#endif
|
||||
#else
|
||||
#define __Pyx_c_is_zero{{func_suffix}}(z) ((z)==0)
|
||||
#define __Pyx_c_conj{{func_suffix}}(z) (conj{{m}}(z))
|
||||
#if {{is_float}}
|
||||
#define __Pyx_c_abs{{func_suffix}}(z) (cabs{{m}}(z))
|
||||
#define __Pyx_c_pow{{func_suffix}}(a, b) (cpow{{m}}(a, b))
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
static CYTHON_INLINE int __Pyx_c_eq{{func_suffix}}({{type}}, {{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_sum{{func_suffix}}({{type}}, {{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_diff{{func_suffix}}({{type}}, {{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_prod{{func_suffix}}({{type}}, {{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_quot{{func_suffix}}({{type}}, {{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_neg{{func_suffix}}({{type}});
|
||||
static CYTHON_INLINE int __Pyx_c_is_zero{{func_suffix}}({{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_conj{{func_suffix}}({{type}});
|
||||
#if {{is_float}}
|
||||
static CYTHON_INLINE {{real_type}} __Pyx_c_abs{{func_suffix}}({{type}});
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_pow{{func_suffix}}({{type}}, {{type}});
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/////////////// Arithmetic ///////////////
|
||||
|
||||
#if CYTHON_CCOMPLEX
|
||||
#else
|
||||
static CYTHON_INLINE int __Pyx_c_eq{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
return (a.real == b.real) && (a.imag == b.imag);
|
||||
}
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_sum{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
{{type}} z;
|
||||
z.real = a.real + b.real;
|
||||
z.imag = a.imag + b.imag;
|
||||
return z;
|
||||
}
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_diff{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
{{type}} z;
|
||||
z.real = a.real - b.real;
|
||||
z.imag = a.imag - b.imag;
|
||||
return z;
|
||||
}
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_prod{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
{{type}} z;
|
||||
z.real = a.real * b.real - a.imag * b.imag;
|
||||
z.imag = a.real * b.imag + a.imag * b.real;
|
||||
return z;
|
||||
}
|
||||
|
||||
#if {{is_float}}
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_quot{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
if (b.imag == 0) {
|
||||
return {{type_name}}_from_parts(a.real / b.real, a.imag / b.real);
|
||||
} else if (fabs{{m}}(b.real) >= fabs{{m}}(b.imag)) {
|
||||
if (b.real == 0 && b.imag == 0) {
|
||||
return {{type_name}}_from_parts(a.real / b.real, a.imag / b.imag);
|
||||
} else {
|
||||
{{real_type}} r = b.imag / b.real;
|
||||
{{real_type}} s = ({{real_type}})(1.0) / (b.real + b.imag * r);
|
||||
return {{type_name}}_from_parts(
|
||||
(a.real + a.imag * r) * s, (a.imag - a.real * r) * s);
|
||||
}
|
||||
} else {
|
||||
{{real_type}} r = b.real / b.imag;
|
||||
{{real_type}} s = ({{real_type}})(1.0) / (b.imag + b.real * r);
|
||||
return {{type_name}}_from_parts(
|
||||
(a.real * r + a.imag) * s, (a.imag * r - a.real) * s);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_quot{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
if (b.imag == 0) {
|
||||
return {{type_name}}_from_parts(a.real / b.real, a.imag / b.real);
|
||||
} else {
|
||||
{{real_type}} denom = b.real * b.real + b.imag * b.imag;
|
||||
return {{type_name}}_from_parts(
|
||||
(a.real * b.real + a.imag * b.imag) / denom,
|
||||
(a.imag * b.real - a.real * b.imag) / denom);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_neg{{func_suffix}}({{type}} a) {
|
||||
{{type}} z;
|
||||
z.real = -a.real;
|
||||
z.imag = -a.imag;
|
||||
return z;
|
||||
}
|
||||
static CYTHON_INLINE int __Pyx_c_is_zero{{func_suffix}}({{type}} a) {
|
||||
return (a.real == 0) && (a.imag == 0);
|
||||
}
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_conj{{func_suffix}}({{type}} a) {
|
||||
{{type}} z;
|
||||
z.real = a.real;
|
||||
z.imag = -a.imag;
|
||||
return z;
|
||||
}
|
||||
#if {{is_float}}
|
||||
static CYTHON_INLINE {{real_type}} __Pyx_c_abs{{func_suffix}}({{type}} z) {
|
||||
#if !defined(HAVE_HYPOT) || defined(_MSC_VER)
|
||||
return sqrt{{m}}(z.real*z.real + z.imag*z.imag);
|
||||
#else
|
||||
return hypot{{m}}(z.real, z.imag);
|
||||
#endif
|
||||
}
|
||||
static CYTHON_INLINE {{type}} __Pyx_c_pow{{func_suffix}}({{type}} a, {{type}} b) {
|
||||
{{type}} z;
|
||||
{{real_type}} r, lnr, theta, z_r, z_theta;
|
||||
if (b.imag == 0 && b.real == (int)b.real) {
|
||||
if (b.real < 0) {
|
||||
{{real_type}} denom = a.real * a.real + a.imag * a.imag;
|
||||
a.real = a.real / denom;
|
||||
a.imag = -a.imag / denom;
|
||||
b.real = -b.real;
|
||||
}
|
||||
switch ((int)b.real) {
|
||||
case 0:
|
||||
z.real = 1;
|
||||
z.imag = 0;
|
||||
return z;
|
||||
case 1:
|
||||
return a;
|
||||
case 2:
|
||||
return __Pyx_c_prod{{func_suffix}}(a, a);
|
||||
case 3:
|
||||
z = __Pyx_c_prod{{func_suffix}}(a, a);
|
||||
return __Pyx_c_prod{{func_suffix}}(z, a);
|
||||
case 4:
|
||||
z = __Pyx_c_prod{{func_suffix}}(a, a);
|
||||
return __Pyx_c_prod{{func_suffix}}(z, z);
|
||||
}
|
||||
}
|
||||
if (a.imag == 0) {
|
||||
if (a.real == 0) {
|
||||
return a;
|
||||
} else if ((b.imag == 0) && (a.real >= 0)) {
|
||||
z.real = pow{{m}}(a.real, b.real);
|
||||
z.imag = 0;
|
||||
return z;
|
||||
} else if (a.real > 0) {
|
||||
r = a.real;
|
||||
theta = 0;
|
||||
} else {
|
||||
r = -a.real;
|
||||
theta = atan2{{m}}(0.0, -1.0);
|
||||
}
|
||||
} else {
|
||||
r = __Pyx_c_abs{{func_suffix}}(a);
|
||||
theta = atan2{{m}}(a.imag, a.real);
|
||||
}
|
||||
lnr = log{{m}}(r);
|
||||
z_r = exp{{m}}(lnr * b.real - theta * b.imag);
|
||||
z_theta = theta * b.real + lnr * b.imag;
|
||||
z.real = z_r * cos{{m}}(z_theta);
|
||||
z.imag = z_r * sin{{m}}(z_theta);
|
||||
return z;
|
||||
}
|
||||
#endif
|
||||
#endif
|
2391
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Coroutine.c
Normal file
2391
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Coroutine.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,66 @@
|
|||
#################### EnumBase ####################
|
||||
|
||||
cimport cython
|
||||
|
||||
cdef extern from *:
|
||||
int PY_VERSION_HEX
|
||||
|
||||
cdef object __Pyx_OrderedDict
|
||||
if PY_VERSION_HEX >= 0x02070000:
|
||||
from collections import OrderedDict as __Pyx_OrderedDict
|
||||
else:
|
||||
__Pyx_OrderedDict = dict
|
||||
|
||||
@cython.internal
|
||||
cdef class __Pyx_EnumMeta(type):
|
||||
def __init__(cls, name, parents, dct):
|
||||
type.__init__(cls, name, parents, dct)
|
||||
cls.__members__ = __Pyx_OrderedDict()
|
||||
def __iter__(cls):
|
||||
return iter(cls.__members__.values())
|
||||
def __getitem__(cls, name):
|
||||
return cls.__members__[name]
|
||||
|
||||
# @cython.internal
|
||||
cdef object __Pyx_EnumBase
|
||||
class __Pyx_EnumBase(int):
|
||||
__metaclass__ = __Pyx_EnumMeta
|
||||
def __new__(cls, value, name=None):
|
||||
for v in cls:
|
||||
if v == value:
|
||||
return v
|
||||
if name is None:
|
||||
raise ValueError("Unknown enum value: '%s'" % value)
|
||||
res = int.__new__(cls, value)
|
||||
res.name = name
|
||||
setattr(cls, name, res)
|
||||
cls.__members__[name] = res
|
||||
return res
|
||||
def __repr__(self):
|
||||
return "<%s.%s: %d>" % (self.__class__.__name__, self.name, self)
|
||||
def __str__(self):
|
||||
return "%s.%s" % (self.__class__.__name__, self.name)
|
||||
|
||||
if PY_VERSION_HEX >= 0x03040000:
|
||||
from enum import IntEnum as __Pyx_EnumBase
|
||||
|
||||
#################### EnumType ####################
|
||||
#@requires: EnumBase
|
||||
|
||||
cdef dict __Pyx_globals = globals()
|
||||
if PY_VERSION_HEX >= 0x03040000:
|
||||
# create new IntEnum()
|
||||
{{name}} = __Pyx_EnumBase('{{name}}', __Pyx_OrderedDict([
|
||||
{{for item in items}}
|
||||
('{{item}}', {{item}}),
|
||||
{{endfor}}
|
||||
]))
|
||||
{{for item in items}}
|
||||
__Pyx_globals['{{item}}'] = {{name}}.{{item}}
|
||||
{{endfor}}
|
||||
else:
|
||||
class {{name}}(__Pyx_EnumBase):
|
||||
pass
|
||||
{{for item in items}}
|
||||
__Pyx_globals['{{item}}'] = {{name}}({{item}}, '{{item}}')
|
||||
{{endfor}}
|
|
@ -0,0 +1,237 @@
|
|||
# TODO: Figure out how many of the pass-by-value copies the compiler can eliminate.
|
||||
|
||||
|
||||
#################### string.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass string "{{type}}":
|
||||
string()
|
||||
string(char* c_str, size_t size)
|
||||
cdef const char* __Pyx_PyObject_AsStringAndSize(object, Py_ssize_t*) except NULL
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef string {{cname}}(object o) except *:
|
||||
cdef Py_ssize_t length = 0
|
||||
cdef const char* data = __Pyx_PyObject_AsStringAndSize(o, &length)
|
||||
return string(data, length)
|
||||
|
||||
|
||||
#################### string.to_py ####################
|
||||
|
||||
#cimport cython
|
||||
#from libcpp.string cimport string
|
||||
cdef extern from *:
|
||||
cdef cppclass string "{{type}}":
|
||||
char* data()
|
||||
size_t size()
|
||||
|
||||
{{for py_type in ['PyObject', 'PyUnicode', 'PyStr', 'PyBytes', 'PyByteArray']}}
|
||||
cdef extern from *:
|
||||
cdef object __Pyx_{{py_type}}_FromStringAndSize(const char*, size_t)
|
||||
|
||||
@cname("{{cname.replace("PyObject", py_type, 1)}}")
|
||||
cdef inline object {{cname.replace("PyObject", py_type, 1)}}(const string& s):
|
||||
return __Pyx_{{py_type}}_FromStringAndSize(s.data(), s.size())
|
||||
{{endfor}}
|
||||
|
||||
|
||||
#################### vector.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass vector "std::vector" [T]:
|
||||
void push_back(T&)
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef vector[X] {{cname}}(object o) except *:
|
||||
cdef vector[X] v
|
||||
for item in o:
|
||||
v.push_back(<X>item)
|
||||
return v
|
||||
|
||||
|
||||
#################### vector.to_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass vector "const std::vector" [T]:
|
||||
size_t size()
|
||||
T& operator[](size_t)
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}(vector[X]& v):
|
||||
return [v[i] for i in range(v.size())]
|
||||
|
||||
|
||||
#################### list.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass cpp_list "std::list" [T]:
|
||||
void push_back(T&)
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef cpp_list[X] {{cname}}(object o) except *:
|
||||
cdef cpp_list[X] l
|
||||
for item in o:
|
||||
l.push_back(<X>item)
|
||||
return l
|
||||
|
||||
|
||||
#################### list.to_py ####################
|
||||
|
||||
cimport cython
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass cpp_list "std::list" [T]:
|
||||
cppclass const_iterator:
|
||||
T& operator*()
|
||||
const_iterator operator++()
|
||||
bint operator!=(const_iterator)
|
||||
const_iterator begin()
|
||||
const_iterator end()
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}(const cpp_list[X]& v):
|
||||
o = []
|
||||
cdef cpp_list[X].const_iterator iter = v.begin()
|
||||
while iter != v.end():
|
||||
o.append(cython.operator.dereference(iter))
|
||||
cython.operator.preincrement(iter)
|
||||
return o
|
||||
|
||||
|
||||
#################### set.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass set "std::{{maybe_unordered}}set" [T]:
|
||||
void insert(T&)
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef set[X] {{cname}}(object o) except *:
|
||||
cdef set[X] s
|
||||
for item in o:
|
||||
s.insert(<X>item)
|
||||
return s
|
||||
|
||||
|
||||
#################### set.to_py ####################
|
||||
|
||||
cimport cython
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass cpp_set "std::{{maybe_unordered}}set" [T]:
|
||||
cppclass const_iterator:
|
||||
T& operator*()
|
||||
const_iterator operator++()
|
||||
bint operator!=(const_iterator)
|
||||
const_iterator begin()
|
||||
const_iterator end()
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}(const cpp_set[X]& s):
|
||||
o = set()
|
||||
cdef cpp_set[X].const_iterator iter = s.begin()
|
||||
while iter != s.end():
|
||||
o.add(cython.operator.dereference(iter))
|
||||
cython.operator.preincrement(iter)
|
||||
return o
|
||||
|
||||
#################### pair.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass pair "std::pair" [T, U]:
|
||||
pair()
|
||||
pair(T&, U&)
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef pair[X,Y] {{cname}}(object o) except *:
|
||||
x, y = o
|
||||
return pair[X,Y](<X>x, <Y>y)
|
||||
|
||||
|
||||
#################### pair.to_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass pair "std::pair" [T, U]:
|
||||
T first
|
||||
U second
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}(const pair[X,Y]& p):
|
||||
return p.first, p.second
|
||||
|
||||
|
||||
#################### map.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass pair "std::pair" [T, U]:
|
||||
pair(T&, U&)
|
||||
cdef cppclass map "std::{{maybe_unordered}}map" [T, U]:
|
||||
void insert(pair[T, U]&)
|
||||
cdef cppclass vector "std::vector" [T]:
|
||||
pass
|
||||
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef map[X,Y] {{cname}}(object o) except *:
|
||||
cdef dict d = o
|
||||
cdef map[X,Y] m
|
||||
for key, value in d.iteritems():
|
||||
m.insert(pair[X,Y](<X>key, <Y>value))
|
||||
return m
|
||||
|
||||
|
||||
#################### map.to_py ####################
|
||||
# TODO: Work out const so that this can take a const
|
||||
# reference rather than pass by value.
|
||||
|
||||
cimport cython
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass map "std::{{maybe_unordered}}map" [T, U]:
|
||||
cppclass value_type:
|
||||
T first
|
||||
U second
|
||||
cppclass const_iterator:
|
||||
value_type& operator*()
|
||||
const_iterator operator++()
|
||||
bint operator!=(const_iterator)
|
||||
const_iterator begin()
|
||||
const_iterator end()
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}(const map[X,Y]& s):
|
||||
o = {}
|
||||
cdef const map[X,Y].value_type *key_value
|
||||
cdef map[X,Y].const_iterator iter = s.begin()
|
||||
while iter != s.end():
|
||||
key_value = &cython.operator.dereference(iter)
|
||||
o[key_value.first] = key_value.second
|
||||
cython.operator.preincrement(iter)
|
||||
return o
|
||||
|
||||
|
||||
#################### complex.from_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass std_complex "std::complex" [T]:
|
||||
std_complex()
|
||||
std_complex(T, T) except +
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef std_complex[X] {{cname}}(object o) except *:
|
||||
cdef double complex z = o
|
||||
return std_complex[X](<X>z.real, <X>z.imag)
|
||||
|
||||
|
||||
#################### complex.to_py ####################
|
||||
|
||||
cdef extern from *:
|
||||
cdef cppclass std_complex "std::complex" [T]:
|
||||
X real()
|
||||
X imag()
|
||||
|
||||
@cname("{{cname}}")
|
||||
cdef object {{cname}}(const std_complex[X]& z):
|
||||
cdef double complex tmp
|
||||
tmp.real = <double>z.real()
|
||||
tmp.imag = <double>z.imag()
|
||||
return tmp
|
|
@ -0,0 +1,58 @@
|
|||
/////////////// CppExceptionConversion.proto ///////////////
|
||||
|
||||
#ifndef __Pyx_CppExn2PyErr
|
||||
#include <new>
|
||||
#include <typeinfo>
|
||||
#include <stdexcept>
|
||||
#include <ios>
|
||||
|
||||
static void __Pyx_CppExn2PyErr() {
|
||||
// Catch a handful of different errors here and turn them into the
|
||||
// equivalent Python errors.
|
||||
try {
|
||||
if (PyErr_Occurred())
|
||||
; // let the latest Python exn pass through and ignore the current one
|
||||
else
|
||||
throw;
|
||||
} catch (const std::bad_alloc& exn) {
|
||||
PyErr_SetString(PyExc_MemoryError, exn.what());
|
||||
} catch (const std::bad_cast& exn) {
|
||||
PyErr_SetString(PyExc_TypeError, exn.what());
|
||||
} catch (const std::bad_typeid& exn) {
|
||||
PyErr_SetString(PyExc_TypeError, exn.what());
|
||||
} catch (const std::domain_error& exn) {
|
||||
PyErr_SetString(PyExc_ValueError, exn.what());
|
||||
} catch (const std::invalid_argument& exn) {
|
||||
PyErr_SetString(PyExc_ValueError, exn.what());
|
||||
} catch (const std::ios_base::failure& exn) {
|
||||
// Unfortunately, in standard C++ we have no way of distinguishing EOF
|
||||
// from other errors here; be careful with the exception mask
|
||||
PyErr_SetString(PyExc_IOError, exn.what());
|
||||
} catch (const std::out_of_range& exn) {
|
||||
// Change out_of_range to IndexError
|
||||
PyErr_SetString(PyExc_IndexError, exn.what());
|
||||
} catch (const std::overflow_error& exn) {
|
||||
PyErr_SetString(PyExc_OverflowError, exn.what());
|
||||
} catch (const std::range_error& exn) {
|
||||
PyErr_SetString(PyExc_ArithmeticError, exn.what());
|
||||
} catch (const std::underflow_error& exn) {
|
||||
PyErr_SetString(PyExc_ArithmeticError, exn.what());
|
||||
} catch (const std::exception& exn) {
|
||||
PyErr_SetString(PyExc_RuntimeError, exn.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// PythranConversion.proto ///////////////
|
||||
|
||||
template <class T>
|
||||
auto __Pyx_pythran_to_python(T &&value) -> decltype(to_python(
|
||||
typename pythonic::returnable<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::type{std::forward<T>(value)}))
|
||||
{
|
||||
using returnable_type = typename pythonic::returnable<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::type;
|
||||
return to_python(returnable_type{std::forward<T>(value)});
|
||||
}
|
File diff suppressed because it is too large
Load diff
219
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Embed.c
Normal file
219
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Embed.c
Normal file
|
@ -0,0 +1,219 @@
|
|||
//////////////////// MainFunction ////////////////////
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <floatingpoint.h>
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
int %(main_method)s(int argc, char** argv) {
|
||||
#elif defined(WIN32) || defined(MS_WINDOWS)
|
||||
int %(wmain_method)s(int argc, wchar_t **argv) {
|
||||
#else
|
||||
static int __Pyx_main(int argc, wchar_t **argv) {
|
||||
#endif
|
||||
/* 754 requires that FP exceptions run in "no stop" mode by default,
|
||||
* and until C vendors implement C99's ways to control FP exceptions,
|
||||
* Python requires non-stop mode. Alas, some platforms enable FP
|
||||
* exceptions by default. Here we disable them.
|
||||
*/
|
||||
#ifdef __FreeBSD__
|
||||
fp_except_t m;
|
||||
|
||||
m = fpgetmask();
|
||||
fpsetmask(m & ~FP_X_OFL);
|
||||
#endif
|
||||
if (argc && argv)
|
||||
Py_SetProgramName(argv[0]);
|
||||
Py_Initialize();
|
||||
if (argc && argv)
|
||||
PySys_SetArgv(argc, argv);
|
||||
{ /* init module '%(module_name)s' as '__main__' */
|
||||
PyObject* m = NULL;
|
||||
%(module_is_main)s = 1;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
init%(module_name)s();
|
||||
#elif CYTHON_PEP489_MULTI_PHASE_INIT
|
||||
m = PyInit_%(module_name)s();
|
||||
if (!PyModule_Check(m)) {
|
||||
PyModuleDef *mdef = (PyModuleDef *) m;
|
||||
PyObject *modname = PyUnicode_FromString("__main__");
|
||||
m = NULL;
|
||||
if (modname) {
|
||||
// FIXME: not currently calling PyModule_FromDefAndSpec() here because we do not have a module spec!
|
||||
// FIXME: not currently setting __file__, __path__, __spec__, ...
|
||||
m = PyModule_NewObject(modname);
|
||||
Py_DECREF(modname);
|
||||
if (m) PyModule_ExecDef(m, mdef);
|
||||
}
|
||||
}
|
||||
#else
|
||||
m = PyInit_%(module_name)s();
|
||||
#endif
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print(); /* This exits with the right code if SystemExit. */
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (Py_FlushLine()) PyErr_Clear();
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
Py_XDECREF(m);
|
||||
}
|
||||
#if PY_VERSION_HEX < 0x03060000
|
||||
Py_Finalize();
|
||||
#else
|
||||
if (Py_FinalizeEx() < 0)
|
||||
return 2;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3 && !defined(WIN32) && !defined(MS_WINDOWS)
|
||||
#include <locale.h>
|
||||
|
||||
static wchar_t*
|
||||
__Pyx_char2wchar(char* arg)
|
||||
{
|
||||
wchar_t *res;
|
||||
#ifdef HAVE_BROKEN_MBSTOWCS
|
||||
/* Some platforms have a broken implementation of
|
||||
* mbstowcs which does not count the characters that
|
||||
* would result from conversion. Use an upper bound.
|
||||
*/
|
||||
size_t argsize = strlen(arg);
|
||||
#else
|
||||
size_t argsize = mbstowcs(NULL, arg, 0);
|
||||
#endif
|
||||
size_t count;
|
||||
unsigned char *in;
|
||||
wchar_t *out;
|
||||
#ifdef HAVE_MBRTOWC
|
||||
mbstate_t mbs;
|
||||
#endif
|
||||
if (argsize != (size_t)-1) {
|
||||
res = (wchar_t *)malloc((argsize+1)*sizeof(wchar_t));
|
||||
if (!res)
|
||||
goto oom;
|
||||
count = mbstowcs(res, arg, argsize+1);
|
||||
if (count != (size_t)-1) {
|
||||
wchar_t *tmp;
|
||||
/* Only use the result if it contains no
|
||||
surrogate characters. */
|
||||
for (tmp = res; *tmp != 0 &&
|
||||
(*tmp < 0xd800 || *tmp > 0xdfff); tmp++)
|
||||
;
|
||||
if (*tmp == 0)
|
||||
return res;
|
||||
}
|
||||
free(res);
|
||||
}
|
||||
/* Conversion failed. Fall back to escaping with surrogateescape. */
|
||||
#ifdef HAVE_MBRTOWC
|
||||
/* Try conversion with mbrtwoc (C99), and escape non-decodable bytes. */
|
||||
|
||||
/* Overallocate; as multi-byte characters are in the argument, the
|
||||
actual output could use less memory. */
|
||||
argsize = strlen(arg) + 1;
|
||||
res = (wchar_t *)malloc(argsize*sizeof(wchar_t));
|
||||
if (!res) goto oom;
|
||||
in = (unsigned char*)arg;
|
||||
out = res;
|
||||
memset(&mbs, 0, sizeof mbs);
|
||||
while (argsize) {
|
||||
size_t converted = mbrtowc(out, (char*)in, argsize, &mbs);
|
||||
if (converted == 0)
|
||||
/* Reached end of string; null char stored. */
|
||||
break;
|
||||
if (converted == (size_t)-2) {
|
||||
/* Incomplete character. This should never happen,
|
||||
since we provide everything that we have -
|
||||
unless there is a bug in the C library, or I
|
||||
misunderstood how mbrtowc works. */
|
||||
fprintf(stderr, "unexpected mbrtowc result -2\\n");
|
||||
free(res);
|
||||
return NULL;
|
||||
}
|
||||
if (converted == (size_t)-1) {
|
||||
/* Conversion error. Escape as UTF-8b, and start over
|
||||
in the initial shift state. */
|
||||
*out++ = 0xdc00 + *in++;
|
||||
argsize--;
|
||||
memset(&mbs, 0, sizeof mbs);
|
||||
continue;
|
||||
}
|
||||
if (*out >= 0xd800 && *out <= 0xdfff) {
|
||||
/* Surrogate character. Escape the original
|
||||
byte sequence with surrogateescape. */
|
||||
argsize -= converted;
|
||||
while (converted--)
|
||||
*out++ = 0xdc00 + *in++;
|
||||
continue;
|
||||
}
|
||||
/* successfully converted some bytes */
|
||||
in += converted;
|
||||
argsize -= converted;
|
||||
out++;
|
||||
}
|
||||
#else
|
||||
/* Cannot use C locale for escaping; manually escape as if charset
|
||||
is ASCII (i.e. escape all bytes > 128. This will still roundtrip
|
||||
correctly in the locale's charset, which must be an ASCII superset. */
|
||||
res = (wchar_t *)malloc((strlen(arg)+1)*sizeof(wchar_t));
|
||||
if (!res) goto oom;
|
||||
in = (unsigned char*)arg;
|
||||
out = res;
|
||||
while(*in)
|
||||
if(*in < 128)
|
||||
*out++ = *in++;
|
||||
else
|
||||
*out++ = 0xdc00 + *in++;
|
||||
*out = 0;
|
||||
#endif
|
||||
return res;
|
||||
oom:
|
||||
fprintf(stderr, "out of memory\\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
%(main_method)s(int argc, char **argv)
|
||||
{
|
||||
if (!argc) {
|
||||
return __Pyx_main(0, NULL);
|
||||
}
|
||||
else {
|
||||
int i, res;
|
||||
wchar_t **argv_copy = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
|
||||
/* We need a second copy, as Python might modify the first one. */
|
||||
wchar_t **argv_copy2 = (wchar_t **)malloc(sizeof(wchar_t*)*argc);
|
||||
char *oldloc = strdup(setlocale(LC_ALL, NULL));
|
||||
if (!argv_copy || !argv_copy2 || !oldloc) {
|
||||
fprintf(stderr, "out of memory\\n");
|
||||
free(argv_copy);
|
||||
free(argv_copy2);
|
||||
free(oldloc);
|
||||
return 1;
|
||||
}
|
||||
res = 0;
|
||||
setlocale(LC_ALL, "");
|
||||
for (i = 0; i < argc; i++) {
|
||||
argv_copy2[i] = argv_copy[i] = __Pyx_char2wchar(argv[i]);
|
||||
if (!argv_copy[i]) res = 1; /* failure, but continue to simplify cleanup */
|
||||
}
|
||||
setlocale(LC_ALL, oldloc);
|
||||
free(oldloc);
|
||||
if (res == 0)
|
||||
res = __Pyx_main(argc, argv_copy);
|
||||
for (i = 0; i < argc; i++) {
|
||||
#if PY_VERSION_HEX < 0x03050000
|
||||
free(argv_copy2[i]);
|
||||
#else
|
||||
PyMem_RawFree(argv_copy2[i]);
|
||||
#endif
|
||||
}
|
||||
free(argv_copy);
|
||||
free(argv_copy2);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,814 @@
|
|||
// Exception raising code
|
||||
//
|
||||
// Exceptions are raised by __Pyx_Raise() and stored as plain
|
||||
// type/value/tb in PyThreadState->curexc_*. When being caught by an
|
||||
// 'except' statement, curexc_* is moved over to exc_* by
|
||||
// __Pyx_GetException()
|
||||
|
||||
|
||||
/////////////// PyThreadStateGet.proto ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#define __Pyx_PyThreadState_declare PyThreadState *$local_tstate_cname;
|
||||
#define __Pyx_PyThreadState_assign $local_tstate_cname = __Pyx_PyThreadState_Current;
|
||||
#define __Pyx_PyErr_Occurred() $local_tstate_cname->curexc_type
|
||||
#else
|
||||
#define __Pyx_PyThreadState_declare
|
||||
#define __Pyx_PyThreadState_assign
|
||||
#define __Pyx_PyErr_Occurred() PyErr_Occurred()
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// PyErrExceptionMatches.proto ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState($local_tstate_cname, err)
|
||||
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
|
||||
#else
|
||||
#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err)
|
||||
#endif
|
||||
|
||||
/////////////// PyErrExceptionMatches ///////////////
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
|
||||
Py_ssize_t i, n;
|
||||
n = PyTuple_GET_SIZE(tuple);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
// the tighter subtype checking in Py3 allows faster out-of-order comparison
|
||||
for (i=0; i<n; i++) {
|
||||
if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
|
||||
}
|
||||
#endif
|
||||
for (i=0; i<n; i++) {
|
||||
if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
|
||||
PyObject *exc_type = tstate->curexc_type;
|
||||
if (exc_type == err) return 1;
|
||||
if (unlikely(!exc_type)) return 0;
|
||||
if (unlikely(PyTuple_Check(err)))
|
||||
return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
|
||||
return __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// PyErrFetchRestore.proto ///////////////
|
||||
//@substitute: naming
|
||||
//@requires: PyThreadStateGet
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
|
||||
#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
|
||||
#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
|
||||
#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState($local_tstate_cname, type, value, tb)
|
||||
#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState($local_tstate_cname, type, value, tb)
|
||||
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); /*proto*/
|
||||
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
|
||||
|
||||
#if CYTHON_COMPILING_IN_CPYTHON
|
||||
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
|
||||
#else
|
||||
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define __Pyx_PyErr_Clear() PyErr_Clear()
|
||||
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
|
||||
#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
|
||||
#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
|
||||
#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
|
||||
#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
|
||||
#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
|
||||
#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
|
||||
#endif
|
||||
|
||||
/////////////// PyErrFetchRestore ///////////////
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
|
||||
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
||||
tmp_type = tstate->curexc_type;
|
||||
tmp_value = tstate->curexc_value;
|
||||
tmp_tb = tstate->curexc_traceback;
|
||||
tstate->curexc_type = type;
|
||||
tstate->curexc_value = value;
|
||||
tstate->curexc_traceback = tb;
|
||||
Py_XDECREF(tmp_type);
|
||||
Py_XDECREF(tmp_value);
|
||||
Py_XDECREF(tmp_tb);
|
||||
}
|
||||
|
||||
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
|
||||
*type = tstate->curexc_type;
|
||||
*value = tstate->curexc_value;
|
||||
*tb = tstate->curexc_traceback;
|
||||
tstate->curexc_type = 0;
|
||||
tstate->curexc_value = 0;
|
||||
tstate->curexc_traceback = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// RaiseException.proto ///////////////
|
||||
|
||||
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); /*proto*/
|
||||
|
||||
/////////////// RaiseException ///////////////
|
||||
//@requires: PyErrFetchRestore
|
||||
//@requires: PyThreadStateGet
|
||||
|
||||
// The following function is based on do_raise() from ceval.c. There
|
||||
// are separate versions for Python2 and Python3 as exception handling
|
||||
// has changed quite a lot between the two versions.
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
|
||||
CYTHON_UNUSED PyObject *cause) {
|
||||
__Pyx_PyThreadState_declare
|
||||
/* 'cause' is only used in Py3 */
|
||||
Py_XINCREF(type);
|
||||
if (!value || value == Py_None)
|
||||
value = NULL;
|
||||
else
|
||||
Py_INCREF(value);
|
||||
|
||||
if (!tb || tb == Py_None)
|
||||
tb = NULL;
|
||||
else {
|
||||
Py_INCREF(tb);
|
||||
if (!PyTraceBack_Check(tb)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"raise: arg 3 must be a traceback or None");
|
||||
goto raise_error;
|
||||
}
|
||||
}
|
||||
|
||||
if (PyType_Check(type)) {
|
||||
/* instantiate the type now (we don't know when and how it will be caught) */
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
/* PyPy can't handle value == NULL */
|
||||
if (!value) {
|
||||
Py_INCREF(Py_None);
|
||||
value = Py_None;
|
||||
}
|
||||
#endif
|
||||
PyErr_NormalizeException(&type, &value, &tb);
|
||||
|
||||
} else {
|
||||
/* Raising an instance. The value should be a dummy. */
|
||||
if (value) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"instance exception may not have a separate value");
|
||||
goto raise_error;
|
||||
}
|
||||
/* Normalize to raise <class>, <instance> */
|
||||
value = type;
|
||||
type = (PyObject*) Py_TYPE(type);
|
||||
Py_INCREF(type);
|
||||
if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"raise: exception class must be a subclass of BaseException");
|
||||
goto raise_error;
|
||||
}
|
||||
}
|
||||
|
||||
__Pyx_PyThreadState_assign
|
||||
__Pyx_ErrRestore(type, value, tb);
|
||||
return;
|
||||
raise_error:
|
||||
Py_XDECREF(value);
|
||||
Py_XDECREF(type);
|
||||
Py_XDECREF(tb);
|
||||
return;
|
||||
}
|
||||
|
||||
#else /* Python 3+ */
|
||||
|
||||
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
|
||||
PyObject* owned_instance = NULL;
|
||||
if (tb == Py_None) {
|
||||
tb = 0;
|
||||
} else if (tb && !PyTraceBack_Check(tb)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"raise: arg 3 must be a traceback or None");
|
||||
goto bad;
|
||||
}
|
||||
if (value == Py_None)
|
||||
value = 0;
|
||||
|
||||
if (PyExceptionInstance_Check(type)) {
|
||||
if (value) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"instance exception may not have a separate value");
|
||||
goto bad;
|
||||
}
|
||||
value = type;
|
||||
type = (PyObject*) Py_TYPE(value);
|
||||
} else if (PyExceptionClass_Check(type)) {
|
||||
// make sure value is an exception instance of type
|
||||
PyObject *instance_class = NULL;
|
||||
if (value && PyExceptionInstance_Check(value)) {
|
||||
instance_class = (PyObject*) Py_TYPE(value);
|
||||
if (instance_class != type) {
|
||||
int is_subclass = PyObject_IsSubclass(instance_class, type);
|
||||
if (!is_subclass) {
|
||||
instance_class = NULL;
|
||||
} else if (unlikely(is_subclass == -1)) {
|
||||
// error on subclass test
|
||||
goto bad;
|
||||
} else {
|
||||
// believe the instance
|
||||
type = instance_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!instance_class) {
|
||||
// instantiate the type now (we don't know when and how it will be caught)
|
||||
// assuming that 'value' is an argument to the type's constructor
|
||||
// not using PyErr_NormalizeException() to avoid ref-counting problems
|
||||
PyObject *args;
|
||||
if (!value)
|
||||
args = PyTuple_New(0);
|
||||
else if (PyTuple_Check(value)) {
|
||||
Py_INCREF(value);
|
||||
args = value;
|
||||
} else
|
||||
args = PyTuple_Pack(1, value);
|
||||
if (!args)
|
||||
goto bad;
|
||||
owned_instance = PyObject_Call(type, args, NULL);
|
||||
Py_DECREF(args);
|
||||
if (!owned_instance)
|
||||
goto bad;
|
||||
value = owned_instance;
|
||||
if (!PyExceptionInstance_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"calling %R should have returned an instance of "
|
||||
"BaseException, not %R",
|
||||
type, Py_TYPE(value));
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"raise: exception class must be a subclass of BaseException");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (cause) {
|
||||
PyObject *fixed_cause;
|
||||
if (cause == Py_None) {
|
||||
// raise ... from None
|
||||
fixed_cause = NULL;
|
||||
} else if (PyExceptionClass_Check(cause)) {
|
||||
fixed_cause = PyObject_CallObject(cause, NULL);
|
||||
if (fixed_cause == NULL)
|
||||
goto bad;
|
||||
} else if (PyExceptionInstance_Check(cause)) {
|
||||
fixed_cause = cause;
|
||||
Py_INCREF(fixed_cause);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"exception causes must derive from "
|
||||
"BaseException");
|
||||
goto bad;
|
||||
}
|
||||
PyException_SetCause(value, fixed_cause);
|
||||
}
|
||||
|
||||
PyErr_SetObject(type, value);
|
||||
|
||||
if (tb) {
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
||||
PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
|
||||
Py_INCREF(tb);
|
||||
PyErr_Restore(tmp_type, tmp_value, tb);
|
||||
Py_XDECREF(tmp_tb);
|
||||
#else
|
||||
PyThreadState *tstate = __Pyx_PyThreadState_Current;
|
||||
PyObject* tmp_tb = tstate->curexc_traceback;
|
||||
if (tb != tmp_tb) {
|
||||
Py_INCREF(tb);
|
||||
tstate->curexc_traceback = tb;
|
||||
Py_XDECREF(tmp_tb);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bad:
|
||||
Py_XDECREF(owned_instance);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// GetTopmostException.proto ///////////////
|
||||
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
|
||||
#endif
|
||||
|
||||
/////////////// GetTopmostException ///////////////
|
||||
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
// Copied from errors.c in CPython.
|
||||
static _PyErr_StackItem *
|
||||
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
|
||||
{
|
||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||
while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
|
||||
exc_info->previous_item != NULL)
|
||||
{
|
||||
exc_info = exc_info->previous_item;
|
||||
}
|
||||
return exc_info;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// GetException.proto ///////////////
|
||||
//@substitute: naming
|
||||
//@requires: PyThreadStateGet
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#define __Pyx_GetException(type, value, tb) __Pyx__GetException($local_tstate_cname, type, value, tb)
|
||||
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
|
||||
#else
|
||||
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
|
||||
#endif
|
||||
|
||||
/////////////// GetException ///////////////
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
|
||||
#else
|
||||
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
|
||||
#endif
|
||||
{
|
||||
PyObject *local_type, *local_value, *local_tb;
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
||||
local_type = tstate->curexc_type;
|
||||
local_value = tstate->curexc_value;
|
||||
local_tb = tstate->curexc_traceback;
|
||||
tstate->curexc_type = 0;
|
||||
tstate->curexc_value = 0;
|
||||
tstate->curexc_traceback = 0;
|
||||
#else
|
||||
PyErr_Fetch(&local_type, &local_value, &local_tb);
|
||||
#endif
|
||||
PyErr_NormalizeException(&local_type, &local_value, &local_tb);
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
if (unlikely(tstate->curexc_type))
|
||||
#else
|
||||
if (unlikely(PyErr_Occurred()))
|
||||
#endif
|
||||
goto bad;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (local_tb) {
|
||||
if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
|
||||
goto bad;
|
||||
}
|
||||
#endif
|
||||
// traceback may be NULL for freshly raised exceptions
|
||||
Py_XINCREF(local_tb);
|
||||
// exception state may be temporarily empty in parallel loops (race condition)
|
||||
Py_XINCREF(local_type);
|
||||
Py_XINCREF(local_value);
|
||||
*type = local_type;
|
||||
*value = local_value;
|
||||
*tb = local_tb;
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
{
|
||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||
tmp_type = exc_info->exc_type;
|
||||
tmp_value = exc_info->exc_value;
|
||||
tmp_tb = exc_info->exc_traceback;
|
||||
exc_info->exc_type = local_type;
|
||||
exc_info->exc_value = local_value;
|
||||
exc_info->exc_traceback = local_tb;
|
||||
}
|
||||
#else
|
||||
tmp_type = tstate->exc_type;
|
||||
tmp_value = tstate->exc_value;
|
||||
tmp_tb = tstate->exc_traceback;
|
||||
tstate->exc_type = local_type;
|
||||
tstate->exc_value = local_value;
|
||||
tstate->exc_traceback = local_tb;
|
||||
#endif
|
||||
// Make sure tstate is in a consistent state when we XDECREF
|
||||
// these objects (DECREF may run arbitrary code).
|
||||
Py_XDECREF(tmp_type);
|
||||
Py_XDECREF(tmp_value);
|
||||
Py_XDECREF(tmp_tb);
|
||||
#else
|
||||
PyErr_SetExcInfo(local_type, local_value, local_tb);
|
||||
#endif
|
||||
return 0;
|
||||
bad:
|
||||
*type = 0;
|
||||
*value = 0;
|
||||
*tb = 0;
|
||||
Py_XDECREF(local_type);
|
||||
Py_XDECREF(local_value);
|
||||
Py_XDECREF(local_tb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/////////////// ReRaiseException.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE void __Pyx_ReraiseException(void); /*proto*/
|
||||
|
||||
/////////////// ReRaiseException ///////////////
|
||||
//@requires: GetTopmostException
|
||||
|
||||
static CYTHON_INLINE void __Pyx_ReraiseException(void) {
|
||||
PyObject *type = NULL, *value = NULL, *tb = NULL;
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
PyThreadState *tstate = PyThreadState_GET();
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
_PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
|
||||
type = exc_info->exc_type;
|
||||
value = exc_info->exc_value;
|
||||
tb = exc_info->exc_traceback;
|
||||
#else
|
||||
type = tstate->exc_type;
|
||||
value = tstate->exc_value;
|
||||
tb = tstate->exc_traceback;
|
||||
#endif
|
||||
#else
|
||||
PyErr_GetExcInfo(&type, &value, &tb);
|
||||
#endif
|
||||
if (!type || type == Py_None) {
|
||||
#if !CYTHON_FAST_THREAD_STATE
|
||||
Py_XDECREF(type);
|
||||
Py_XDECREF(value);
|
||||
Py_XDECREF(tb);
|
||||
#endif
|
||||
// message copied from Py3
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"No active exception to reraise");
|
||||
} else {
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
Py_INCREF(type);
|
||||
Py_XINCREF(value);
|
||||
Py_XINCREF(tb);
|
||||
|
||||
#endif
|
||||
PyErr_Restore(type, value, tb);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////// SaveResetException.proto ///////////////
|
||||
//@substitute: naming
|
||||
//@requires: PyThreadStateGet
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave($local_tstate_cname, type, value, tb)
|
||||
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
|
||||
#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset($local_tstate_cname, type, value, tb)
|
||||
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); /*proto*/
|
||||
|
||||
#else
|
||||
|
||||
#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb)
|
||||
#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb)
|
||||
#endif
|
||||
|
||||
/////////////// SaveResetException ///////////////
|
||||
//@requires: GetTopmostException
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
_PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
|
||||
*type = exc_info->exc_type;
|
||||
*value = exc_info->exc_value;
|
||||
*tb = exc_info->exc_traceback;
|
||||
#else
|
||||
*type = tstate->exc_type;
|
||||
*value = tstate->exc_value;
|
||||
*tb = tstate->exc_traceback;
|
||||
#endif
|
||||
Py_XINCREF(*type);
|
||||
Py_XINCREF(*value);
|
||||
Py_XINCREF(*tb);
|
||||
}
|
||||
|
||||
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
|
||||
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
||||
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||
tmp_type = exc_info->exc_type;
|
||||
tmp_value = exc_info->exc_value;
|
||||
tmp_tb = exc_info->exc_traceback;
|
||||
exc_info->exc_type = type;
|
||||
exc_info->exc_value = value;
|
||||
exc_info->exc_traceback = tb;
|
||||
#else
|
||||
tmp_type = tstate->exc_type;
|
||||
tmp_value = tstate->exc_value;
|
||||
tmp_tb = tstate->exc_traceback;
|
||||
tstate->exc_type = type;
|
||||
tstate->exc_value = value;
|
||||
tstate->exc_traceback = tb;
|
||||
#endif
|
||||
Py_XDECREF(tmp_type);
|
||||
Py_XDECREF(tmp_value);
|
||||
Py_XDECREF(tmp_tb);
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// SwapException.proto ///////////////
|
||||
//@substitute: naming
|
||||
//@requires: PyThreadStateGet
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap($local_tstate_cname, type, value, tb)
|
||||
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
|
||||
#else
|
||||
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); /*proto*/
|
||||
#endif
|
||||
|
||||
/////////////// SwapException ///////////////
|
||||
|
||||
#if CYTHON_FAST_THREAD_STATE
|
||||
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
|
||||
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
||||
|
||||
#if CYTHON_USE_EXC_INFO_STACK
|
||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||
tmp_type = exc_info->exc_type;
|
||||
tmp_value = exc_info->exc_value;
|
||||
tmp_tb = exc_info->exc_traceback;
|
||||
|
||||
exc_info->exc_type = *type;
|
||||
exc_info->exc_value = *value;
|
||||
exc_info->exc_traceback = *tb;
|
||||
#else
|
||||
tmp_type = tstate->exc_type;
|
||||
tmp_value = tstate->exc_value;
|
||||
tmp_tb = tstate->exc_traceback;
|
||||
|
||||
tstate->exc_type = *type;
|
||||
tstate->exc_value = *value;
|
||||
tstate->exc_traceback = *tb;
|
||||
#endif
|
||||
|
||||
*type = tmp_type;
|
||||
*value = tmp_value;
|
||||
*tb = tmp_tb;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
|
||||
PyObject *tmp_type, *tmp_value, *tmp_tb;
|
||||
PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
|
||||
PyErr_SetExcInfo(*type, *value, *tb);
|
||||
*type = tmp_type;
|
||||
*value = tmp_value;
|
||||
*tb = tmp_tb;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// WriteUnraisableException.proto ///////////////
|
||||
|
||||
static void __Pyx_WriteUnraisable(const char *name, int clineno,
|
||||
int lineno, const char *filename,
|
||||
int full_traceback, int nogil); /*proto*/
|
||||
|
||||
/////////////// WriteUnraisableException ///////////////
|
||||
//@requires: PyErrFetchRestore
|
||||
//@requires: PyThreadStateGet
|
||||
|
||||
static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
|
||||
CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
|
||||
int full_traceback, CYTHON_UNUSED int nogil) {
|
||||
PyObject *old_exc, *old_val, *old_tb;
|
||||
PyObject *ctx;
|
||||
__Pyx_PyThreadState_declare
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE state;
|
||||
if (nogil)
|
||||
state = PyGILState_Ensure();
|
||||
/* initalize to suppress warning */
|
||||
else state = (PyGILState_STATE)0;
|
||||
#endif
|
||||
__Pyx_PyThreadState_assign
|
||||
__Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
|
||||
if (full_traceback) {
|
||||
Py_XINCREF(old_exc);
|
||||
Py_XINCREF(old_val);
|
||||
Py_XINCREF(old_tb);
|
||||
__Pyx_ErrRestore(old_exc, old_val, old_tb);
|
||||
PyErr_PrintEx(1);
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
ctx = PyString_FromString(name);
|
||||
#else
|
||||
ctx = PyUnicode_FromString(name);
|
||||
#endif
|
||||
__Pyx_ErrRestore(old_exc, old_val, old_tb);
|
||||
if (!ctx) {
|
||||
PyErr_WriteUnraisable(Py_None);
|
||||
} else {
|
||||
PyErr_WriteUnraisable(ctx);
|
||||
Py_DECREF(ctx);
|
||||
}
|
||||
#ifdef WITH_THREAD
|
||||
if (nogil)
|
||||
PyGILState_Release(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
/////////////// CLineInTraceback.proto ///////////////
|
||||
|
||||
#ifdef CYTHON_CLINE_IN_TRACEBACK /* 0 or 1 to disable/enable C line display in tracebacks at C compile time */
|
||||
#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
|
||||
#else
|
||||
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);/*proto*/
|
||||
#endif
|
||||
|
||||
/////////////// CLineInTraceback ///////////////
|
||||
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
||||
//@requires: ObjectHandling.c::PyDictVersioning
|
||||
//@requires: PyErrFetchRestore
|
||||
//@substitute: naming
|
||||
|
||||
#ifndef CYTHON_CLINE_IN_TRACEBACK
|
||||
static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
|
||||
PyObject *use_cline;
|
||||
PyObject *ptype, *pvalue, *ptraceback;
|
||||
#if CYTHON_COMPILING_IN_CPYTHON
|
||||
PyObject **cython_runtime_dict;
|
||||
#endif
|
||||
|
||||
if (unlikely(!${cython_runtime_cname})) {
|
||||
// Very early error where the runtime module is not set up yet.
|
||||
return c_line;
|
||||
}
|
||||
|
||||
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
|
||||
|
||||
#if CYTHON_COMPILING_IN_CPYTHON
|
||||
cython_runtime_dict = _PyObject_GetDictPtr(${cython_runtime_cname});
|
||||
if (likely(cython_runtime_dict)) {
|
||||
__PYX_PY_DICT_LOOKUP_IF_MODIFIED(
|
||||
use_cline, *cython_runtime_dict,
|
||||
__Pyx_PyDict_GetItemStr(*cython_runtime_dict, PYIDENT("cline_in_traceback")))
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(${cython_runtime_cname}, PYIDENT("cline_in_traceback"));
|
||||
if (use_cline_obj) {
|
||||
use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
|
||||
Py_DECREF(use_cline_obj);
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
use_cline = NULL;
|
||||
}
|
||||
}
|
||||
if (!use_cline) {
|
||||
c_line = 0;
|
||||
// No need to handle errors here when we reset the exception state just afterwards.
|
||||
(void) PyObject_SetAttr(${cython_runtime_cname}, PYIDENT("cline_in_traceback"), Py_False);
|
||||
}
|
||||
else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
|
||||
c_line = 0;
|
||||
}
|
||||
__Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
|
||||
return c_line;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// AddTraceback.proto ///////////////
|
||||
|
||||
static void __Pyx_AddTraceback(const char *funcname, int c_line,
|
||||
int py_line, const char *filename); /*proto*/
|
||||
|
||||
/////////////// AddTraceback ///////////////
|
||||
//@requires: ModuleSetupCode.c::CodeObjectCache
|
||||
//@requires: CLineInTraceback
|
||||
//@substitute: naming
|
||||
|
||||
#include "compile.h"
|
||||
#include "frameobject.h"
|
||||
#include "traceback.h"
|
||||
#if PY_VERSION_HEX >= 0x030b00a6
|
||||
#ifndef Py_BUILD_CORE
|
||||
#define Py_BUILD_CORE 1
|
||||
#endif
|
||||
#include "internal/pycore_frame.h"
|
||||
#endif
|
||||
|
||||
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
|
||||
const char *funcname, int c_line,
|
||||
int py_line, const char *filename) {
|
||||
PyCodeObject *py_code = NULL;
|
||||
PyObject *py_funcname = NULL;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject *py_srcfile = NULL;
|
||||
|
||||
py_srcfile = PyString_FromString(filename);
|
||||
if (!py_srcfile) goto bad;
|
||||
#endif
|
||||
|
||||
if (c_line) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, $cfilenm_cname, c_line);
|
||||
if (!py_funcname) goto bad;
|
||||
#else
|
||||
py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, $cfilenm_cname, c_line);
|
||||
if (!py_funcname) goto bad;
|
||||
funcname = PyUnicode_AsUTF8(py_funcname);
|
||||
if (!funcname) goto bad;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
py_funcname = PyString_FromString(funcname);
|
||||
if (!py_funcname) goto bad;
|
||||
#endif
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
py_code = __Pyx_PyCode_New(
|
||||
0, /*int argcount,*/
|
||||
0, /*int kwonlyargcount,*/
|
||||
0, /*int nlocals,*/
|
||||
0, /*int stacksize,*/
|
||||
0, /*int flags,*/
|
||||
$empty_bytes, /*PyObject *code,*/
|
||||
$empty_tuple, /*PyObject *consts,*/
|
||||
$empty_tuple, /*PyObject *names,*/
|
||||
$empty_tuple, /*PyObject *varnames,*/
|
||||
$empty_tuple, /*PyObject *freevars,*/
|
||||
$empty_tuple, /*PyObject *cellvars,*/
|
||||
py_srcfile, /*PyObject *filename,*/
|
||||
py_funcname, /*PyObject *name,*/
|
||||
py_line, /*int firstlineno,*/
|
||||
$empty_bytes /*PyObject *lnotab*/
|
||||
);
|
||||
Py_DECREF(py_srcfile);
|
||||
#else
|
||||
py_code = PyCode_NewEmpty(filename, funcname, py_line);
|
||||
#endif
|
||||
Py_XDECREF(py_funcname); // XDECREF since it's only set on Py3 if cline
|
||||
return py_code;
|
||||
bad:
|
||||
Py_XDECREF(py_funcname);
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
Py_XDECREF(py_srcfile);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void __Pyx_AddTraceback(const char *funcname, int c_line,
|
||||
int py_line, const char *filename) {
|
||||
PyCodeObject *py_code = 0;
|
||||
PyFrameObject *py_frame = 0;
|
||||
PyThreadState *tstate = __Pyx_PyThreadState_Current;
|
||||
PyObject *ptype, *pvalue, *ptraceback;
|
||||
|
||||
if (c_line) {
|
||||
c_line = __Pyx_CLineForTraceback(tstate, c_line);
|
||||
}
|
||||
|
||||
// Negate to avoid collisions between py and c lines.
|
||||
py_code = $global_code_object_cache_find(c_line ? -c_line : py_line);
|
||||
if (!py_code) {
|
||||
__Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
|
||||
py_code = __Pyx_CreateCodeObjectForTraceback(
|
||||
funcname, c_line, py_line, filename);
|
||||
if (!py_code) {
|
||||
/* If the code object creation fails, then we should clear the
|
||||
fetched exception references and propagate the new exception */
|
||||
Py_XDECREF(ptype);
|
||||
Py_XDECREF(pvalue);
|
||||
Py_XDECREF(ptraceback);
|
||||
goto bad;
|
||||
}
|
||||
__Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
|
||||
$global_code_object_cache_insert(c_line ? -c_line : py_line, py_code);
|
||||
}
|
||||
py_frame = PyFrame_New(
|
||||
tstate, /*PyThreadState *tstate,*/
|
||||
py_code, /*PyCodeObject *code,*/
|
||||
$moddict_cname, /*PyObject *globals,*/
|
||||
0 /*PyObject *locals*/
|
||||
);
|
||||
if (!py_frame) goto bad;
|
||||
__Pyx_PyFrame_SetLineNumber(py_frame, py_line);
|
||||
PyTraceBack_Here(py_frame);
|
||||
bad:
|
||||
Py_XDECREF(py_code);
|
||||
Py_XDECREF(py_frame);
|
||||
}
|
|
@ -0,0 +1,301 @@
|
|||
/////////////// PyType_Ready.proto ///////////////
|
||||
|
||||
static int __Pyx_PyType_Ready(PyTypeObject *t);
|
||||
|
||||
/////////////// PyType_Ready ///////////////
|
||||
|
||||
// Wrapper around PyType_Ready() with some runtime checks and fixes
|
||||
// to deal with multiple inheritance.
|
||||
static int __Pyx_PyType_Ready(PyTypeObject *t) {
|
||||
// Loop over all bases (except the first) and check that those
|
||||
// really are heap types. Otherwise, it would not be safe to
|
||||
// subclass them.
|
||||
//
|
||||
// We also check tp_dictoffset: it is unsafe to inherit
|
||||
// tp_dictoffset from a base class because the object structures
|
||||
// would not be compatible. So, if our extension type doesn't set
|
||||
// tp_dictoffset (i.e. there is no __dict__ attribute in the object
|
||||
// structure), we need to check that none of the base classes sets
|
||||
// it either.
|
||||
int r;
|
||||
PyObject *bases = t->tp_bases;
|
||||
if (bases)
|
||||
{
|
||||
Py_ssize_t i, n = PyTuple_GET_SIZE(bases);
|
||||
for (i = 1; i < n; i++) /* Skip first base */
|
||||
{
|
||||
PyObject *b0 = PyTuple_GET_ITEM(bases, i);
|
||||
PyTypeObject *b;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
/* Disallow old-style classes */
|
||||
if (PyClass_Check(b0))
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class",
|
||||
PyString_AS_STRING(((PyClassObject*)b0)->cl_name));
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
b = (PyTypeObject*)b0;
|
||||
if (!PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "base class '%.200s' is not a heap type",
|
||||
b->tp_name);
|
||||
return -1;
|
||||
}
|
||||
if (t->tp_dictoffset == 0 && b->tp_dictoffset)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"extension type '%.200s' has no __dict__ slot, but base type '%.200s' has: "
|
||||
"either add 'cdef dict __dict__' to the extension type "
|
||||
"or add '__slots__ = [...]' to the base type",
|
||||
t->tp_name, b->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION)
|
||||
{
|
||||
// Make sure GC does not pick up our non-heap type as heap type with this hack!
|
||||
// For details, see https://github.com/cython/cython/issues/3603
|
||||
PyObject *ret, *py_status;
|
||||
int gc_was_enabled;
|
||||
PyObject *gc = PyImport_Import(PYUNICODE("gc"));
|
||||
if (unlikely(!gc)) return -1;
|
||||
py_status = PyObject_CallMethodObjArgs(gc, PYUNICODE("isenabled"), NULL);
|
||||
if (unlikely(!py_status)) {
|
||||
Py_DECREF(gc);
|
||||
return -1;
|
||||
}
|
||||
gc_was_enabled = __Pyx_PyObject_IsTrue(py_status);
|
||||
Py_DECREF(py_status);
|
||||
if (gc_was_enabled > 0) {
|
||||
ret = PyObject_CallMethodObjArgs(gc, PYUNICODE("disable"), NULL);
|
||||
if (unlikely(!ret)) {
|
||||
Py_DECREF(gc);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(ret);
|
||||
} else if (unlikely(gc_was_enabled == -1)) {
|
||||
Py_DECREF(gc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// As of https://bugs.python.org/issue22079
|
||||
// PyType_Ready enforces that all bases of a non-heap type are
|
||||
// non-heap. We know that this is the case for the solid base but
|
||||
// other bases are heap allocated and are kept alive through the
|
||||
// tp_bases reference.
|
||||
// Other than this check, the Py_TPFLAGS_HEAPTYPE flag is unused
|
||||
// in PyType_Ready().
|
||||
t->tp_flags |= Py_TPFLAGS_HEAPTYPE;
|
||||
#endif
|
||||
|
||||
r = PyType_Ready(t);
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION)
|
||||
t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
|
||||
|
||||
if (gc_was_enabled) {
|
||||
PyObject *t, *v, *tb;
|
||||
PyErr_Fetch(&t, &v, &tb);
|
||||
ret = PyObject_CallMethodObjArgs(gc, PYUNICODE("enable"), NULL);
|
||||
if (likely(ret || r == -1)) {
|
||||
Py_XDECREF(ret);
|
||||
// do not overwrite exceptions raised by PyType_Ready() above
|
||||
PyErr_Restore(t, v, tb);
|
||||
} else {
|
||||
// PyType_Ready() succeeded, but gc.enable() failed.
|
||||
Py_XDECREF(t);
|
||||
Py_XDECREF(v);
|
||||
Py_XDECREF(tb);
|
||||
r = -1;
|
||||
}
|
||||
}
|
||||
Py_DECREF(gc);
|
||||
}
|
||||
#endif
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/////////////// CallNextTpDealloc.proto ///////////////
|
||||
|
||||
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);
|
||||
|
||||
/////////////// CallNextTpDealloc ///////////////
|
||||
|
||||
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc) {
|
||||
PyTypeObject* type = Py_TYPE(obj);
|
||||
/* try to find the first parent type that has a different tp_dealloc() function */
|
||||
while (type && type->tp_dealloc != current_tp_dealloc)
|
||||
type = type->tp_base;
|
||||
while (type && type->tp_dealloc == current_tp_dealloc)
|
||||
type = type->tp_base;
|
||||
if (type)
|
||||
type->tp_dealloc(obj);
|
||||
}
|
||||
|
||||
/////////////// CallNextTpTraverse.proto ///////////////
|
||||
|
||||
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse);
|
||||
|
||||
/////////////// CallNextTpTraverse ///////////////
|
||||
|
||||
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) {
|
||||
PyTypeObject* type = Py_TYPE(obj);
|
||||
/* try to find the first parent type that has a different tp_traverse() function */
|
||||
while (type && type->tp_traverse != current_tp_traverse)
|
||||
type = type->tp_base;
|
||||
while (type && type->tp_traverse == current_tp_traverse)
|
||||
type = type->tp_base;
|
||||
if (type && type->tp_traverse)
|
||||
return type->tp_traverse(obj, v, a);
|
||||
// FIXME: really ignore?
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////// CallNextTpClear.proto ///////////////
|
||||
|
||||
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc);
|
||||
|
||||
/////////////// CallNextTpClear ///////////////
|
||||
|
||||
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
|
||||
PyTypeObject* type = Py_TYPE(obj);
|
||||
/* try to find the first parent type that has a different tp_clear() function */
|
||||
while (type && type->tp_clear != current_tp_clear)
|
||||
type = type->tp_base;
|
||||
while (type && type->tp_clear == current_tp_clear)
|
||||
type = type->tp_base;
|
||||
if (type && type->tp_clear)
|
||||
type->tp_clear(obj);
|
||||
}
|
||||
|
||||
/////////////// SetupReduce.proto ///////////////
|
||||
|
||||
static int __Pyx_setup_reduce(PyObject* type_obj);
|
||||
|
||||
/////////////// SetupReduce ///////////////
|
||||
//@requires: ObjectHandling.c::PyObjectGetAttrStrNoError
|
||||
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
||||
//@substitute: naming
|
||||
|
||||
static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
|
||||
int ret;
|
||||
PyObject *name_attr;
|
||||
|
||||
name_attr = __Pyx_PyObject_GetAttrStr(meth, PYIDENT("__name__"));
|
||||
if (likely(name_attr)) {
|
||||
ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (unlikely(ret < 0)) {
|
||||
PyErr_Clear();
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
Py_XDECREF(name_attr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __Pyx_setup_reduce(PyObject* type_obj) {
|
||||
int ret = 0;
|
||||
PyObject *object_reduce = NULL;
|
||||
PyObject *object_getstate = NULL;
|
||||
PyObject *object_reduce_ex = NULL;
|
||||
PyObject *reduce = NULL;
|
||||
PyObject *reduce_ex = NULL;
|
||||
PyObject *reduce_cython = NULL;
|
||||
PyObject *setstate = NULL;
|
||||
PyObject *setstate_cython = NULL;
|
||||
PyObject *getstate = NULL;
|
||||
|
||||
#if CYTHON_USE_PYTYPE_LOOKUP
|
||||
getstate = _PyType_Lookup((PyTypeObject*)type_obj, PYIDENT("__getstate__"));
|
||||
#else
|
||||
getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__getstate__"));
|
||||
if (!getstate && PyErr_Occurred()) {
|
||||
goto __PYX_BAD;
|
||||
}
|
||||
#endif
|
||||
if (getstate) {
|
||||
// Python 3.11 introduces object.__getstate__. Because it's version-specific failure to find it should not be an error
|
||||
#if CYTHON_USE_PYTYPE_LOOKUP
|
||||
object_getstate = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__getstate__"));
|
||||
#else
|
||||
object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, PYIDENT("__getstate__"));
|
||||
if (!object_getstate && PyErr_Occurred()) {
|
||||
goto __PYX_BAD;
|
||||
}
|
||||
#endif
|
||||
if (object_getstate != getstate) {
|
||||
goto __PYX_GOOD;
|
||||
}
|
||||
}
|
||||
|
||||
#if CYTHON_USE_PYTYPE_LOOKUP
|
||||
object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__reduce_ex__")); if (!object_reduce_ex) goto __PYX_BAD;
|
||||
#else
|
||||
object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce_ex__")); if (!object_reduce_ex) goto __PYX_BAD;
|
||||
#endif
|
||||
|
||||
reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce_ex__")); if (unlikely(!reduce_ex)) goto __PYX_BAD;
|
||||
if (reduce_ex == object_reduce_ex) {
|
||||
|
||||
#if CYTHON_USE_PYTYPE_LOOKUP
|
||||
object_reduce = _PyType_Lookup(&PyBaseObject_Type, PYIDENT("__reduce__")); if (!object_reduce) goto __PYX_BAD;
|
||||
#else
|
||||
object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, PYIDENT("__reduce__")); if (!object_reduce) goto __PYX_BAD;
|
||||
#endif
|
||||
reduce = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce__")); if (unlikely(!reduce)) goto __PYX_BAD;
|
||||
|
||||
if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"))) {
|
||||
reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__reduce_cython__"));
|
||||
if (likely(reduce_cython)) {
|
||||
ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__reduce__"), reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
|
||||
ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__reduce_cython__")); if (unlikely(ret < 0)) goto __PYX_BAD;
|
||||
} else if (reduce == object_reduce || PyErr_Occurred()) {
|
||||
// Ignore if we're done, i.e. if 'reduce' already has the right name and the original is gone.
|
||||
// Otherwise: error.
|
||||
goto __PYX_BAD;
|
||||
}
|
||||
|
||||
setstate = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__setstate__"));
|
||||
if (!setstate) PyErr_Clear();
|
||||
if (!setstate || __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"))) {
|
||||
setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate_cython__"));
|
||||
if (likely(setstate_cython)) {
|
||||
ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__setstate__"), setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
|
||||
ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__setstate_cython__")); if (unlikely(ret < 0)) goto __PYX_BAD;
|
||||
} else if (!setstate || PyErr_Occurred()) {
|
||||
// Ignore if we're done, i.e. if 'setstate' already has the right name and the original is gone.
|
||||
// Otherwise: error.
|
||||
goto __PYX_BAD;
|
||||
}
|
||||
}
|
||||
PyType_Modified((PyTypeObject*)type_obj);
|
||||
}
|
||||
}
|
||||
goto __PYX_GOOD;
|
||||
|
||||
__PYX_BAD:
|
||||
if (!PyErr_Occurred())
|
||||
PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
|
||||
ret = -1;
|
||||
__PYX_GOOD:
|
||||
#if !CYTHON_USE_PYTYPE_LOOKUP
|
||||
Py_XDECREF(object_reduce);
|
||||
Py_XDECREF(object_reduce_ex);
|
||||
Py_XDECREF(object_getstate);
|
||||
Py_XDECREF(getstate);
|
||||
#endif
|
||||
Py_XDECREF(reduce);
|
||||
Py_XDECREF(reduce_ex);
|
||||
Py_XDECREF(reduce_cython);
|
||||
Py_XDECREF(setstate);
|
||||
Py_XDECREF(setstate_cython);
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,352 @@
|
|||
//////////////////// ArgTypeTest.proto ////////////////////
|
||||
|
||||
|
||||
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact) \
|
||||
((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 : \
|
||||
__Pyx__ArgTypeTest(obj, type, name, exact))
|
||||
|
||||
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); /*proto*/
|
||||
|
||||
//////////////////// ArgTypeTest ////////////////////
|
||||
|
||||
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
|
||||
{
|
||||
if (unlikely(!type)) {
|
||||
PyErr_SetString(PyExc_SystemError, "Missing type object");
|
||||
return 0;
|
||||
}
|
||||
else if (exact) {
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if (likely(__Pyx_TypeCheck(obj, type))) return 1;
|
||||
}
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
|
||||
name, type->tp_name, Py_TYPE(obj)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////// RaiseArgTupleInvalid.proto ////////////////////
|
||||
|
||||
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
|
||||
Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); /*proto*/
|
||||
|
||||
//////////////////// RaiseArgTupleInvalid ////////////////////
|
||||
|
||||
// __Pyx_RaiseArgtupleInvalid raises the correct exception when too
|
||||
// many or too few positional arguments were found. This handles
|
||||
// Py_ssize_t formatting correctly.
|
||||
|
||||
static void __Pyx_RaiseArgtupleInvalid(
|
||||
const char* func_name,
|
||||
int exact,
|
||||
Py_ssize_t num_min,
|
||||
Py_ssize_t num_max,
|
||||
Py_ssize_t num_found)
|
||||
{
|
||||
Py_ssize_t num_expected;
|
||||
const char *more_or_less;
|
||||
|
||||
if (num_found < num_min) {
|
||||
num_expected = num_min;
|
||||
more_or_less = "at least";
|
||||
} else {
|
||||
num_expected = num_max;
|
||||
more_or_less = "at most";
|
||||
}
|
||||
if (exact) {
|
||||
more_or_less = "exactly";
|
||||
}
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
|
||||
func_name, more_or_less, num_expected,
|
||||
(num_expected == 1) ? "" : "s", num_found);
|
||||
}
|
||||
|
||||
|
||||
//////////////////// RaiseKeywordRequired.proto ////////////////////
|
||||
|
||||
static void __Pyx_RaiseKeywordRequired(const char* func_name, PyObject* kw_name); /*proto*/
|
||||
|
||||
//////////////////// RaiseKeywordRequired ////////////////////
|
||||
|
||||
static void __Pyx_RaiseKeywordRequired(const char* func_name, PyObject* kw_name) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
"%s() needs keyword-only argument %U", func_name, kw_name);
|
||||
#else
|
||||
"%s() needs keyword-only argument %s", func_name,
|
||||
PyString_AS_STRING(kw_name));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//////////////////// RaiseDoubleKeywords.proto ////////////////////
|
||||
|
||||
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/
|
||||
|
||||
//////////////////// RaiseDoubleKeywords ////////////////////
|
||||
|
||||
static void __Pyx_RaiseDoubleKeywordsError(
|
||||
const char* func_name,
|
||||
PyObject* kw_name)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
"%s() got multiple values for keyword argument '%U'", func_name, kw_name);
|
||||
#else
|
||||
"%s() got multiple values for keyword argument '%s'", func_name,
|
||||
PyString_AsString(kw_name));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//////////////////// RaiseMappingExpected.proto ////////////////////
|
||||
|
||||
static void __Pyx_RaiseMappingExpectedError(PyObject* arg); /*proto*/
|
||||
|
||||
//////////////////// RaiseMappingExpected ////////////////////
|
||||
|
||||
static void __Pyx_RaiseMappingExpectedError(PyObject* arg) {
|
||||
PyErr_Format(PyExc_TypeError, "'%.200s' object is not a mapping", Py_TYPE(arg)->tp_name);
|
||||
}
|
||||
|
||||
|
||||
//////////////////// KeywordStringCheck.proto ////////////////////
|
||||
|
||||
static int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed); /*proto*/
|
||||
|
||||
//////////////////// KeywordStringCheck ////////////////////
|
||||
|
||||
// __Pyx_CheckKeywordStrings raises an error if non-string keywords
|
||||
// were passed to a function, or if any keywords were passed to a
|
||||
// function that does not accept them.
|
||||
|
||||
static int __Pyx_CheckKeywordStrings(
|
||||
PyObject *kwdict,
|
||||
const char* function_name,
|
||||
int kw_allowed)
|
||||
{
|
||||
PyObject* key = 0;
|
||||
Py_ssize_t pos = 0;
|
||||
#if CYTHON_COMPILING_IN_PYPY
|
||||
/* PyPy appears to check keywords at call time, not at unpacking time => not much to do here */
|
||||
if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
|
||||
goto invalid_keyword;
|
||||
return 1;
|
||||
#else
|
||||
while (PyDict_Next(kwdict, &pos, &key, 0)) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (unlikely(!PyString_Check(key)))
|
||||
#endif
|
||||
if (unlikely(!PyUnicode_Check(key)))
|
||||
goto invalid_keyword_type;
|
||||
}
|
||||
if ((!kw_allowed) && unlikely(key))
|
||||
goto invalid_keyword;
|
||||
return 1;
|
||||
invalid_keyword_type:
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() keywords must be strings", function_name);
|
||||
return 0;
|
||||
#endif
|
||||
invalid_keyword:
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
"%.200s() got an unexpected keyword argument '%.200s'",
|
||||
function_name, PyString_AsString(key));
|
||||
#else
|
||||
"%s() got an unexpected keyword argument '%U'",
|
||||
function_name, key);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//////////////////// ParseKeywords.proto ////////////////////
|
||||
|
||||
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \
|
||||
PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \
|
||||
const char* function_name); /*proto*/
|
||||
|
||||
//////////////////// ParseKeywords ////////////////////
|
||||
//@requires: RaiseDoubleKeywords
|
||||
|
||||
// __Pyx_ParseOptionalKeywords copies the optional/unknown keyword
|
||||
// arguments from the kwds dict into kwds2. If kwds2 is NULL, unknown
|
||||
// keywords will raise an invalid keyword error.
|
||||
//
|
||||
// Three kinds of errors are checked: 1) non-string keywords, 2)
|
||||
// unexpected keywords and 3) overlap with positional arguments.
|
||||
//
|
||||
// If num_posargs is greater 0, it denotes the number of positional
|
||||
// arguments that were passed and that must therefore not appear
|
||||
// amongst the keywords as well.
|
||||
//
|
||||
// This method does not check for required keyword arguments.
|
||||
|
||||
static int __Pyx_ParseOptionalKeywords(
|
||||
PyObject *kwds,
|
||||
PyObject **argnames[],
|
||||
PyObject *kwds2,
|
||||
PyObject *values[],
|
||||
Py_ssize_t num_pos_args,
|
||||
const char* function_name)
|
||||
{
|
||||
PyObject *key = 0, *value = 0;
|
||||
Py_ssize_t pos = 0;
|
||||
PyObject*** name;
|
||||
PyObject*** first_kw_arg = argnames + num_pos_args;
|
||||
|
||||
while (PyDict_Next(kwds, &pos, &key, &value)) {
|
||||
name = first_kw_arg;
|
||||
while (*name && (**name != key)) name++;
|
||||
if (*name) {
|
||||
values[name-argnames] = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
name = first_kw_arg;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (likely(PyString_Check(key))) {
|
||||
while (*name) {
|
||||
if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
|
||||
&& _PyString_Eq(**name, key)) {
|
||||
values[name-argnames] = value;
|
||||
break;
|
||||
}
|
||||
name++;
|
||||
}
|
||||
if (*name) continue;
|
||||
else {
|
||||
// not found after positional args, check for duplicate
|
||||
PyObject*** argname = argnames;
|
||||
while (argname != first_kw_arg) {
|
||||
if ((**argname == key) || (
|
||||
(CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
|
||||
&& _PyString_Eq(**argname, key))) {
|
||||
goto arg_passed_twice;
|
||||
}
|
||||
argname++;
|
||||
}
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (likely(PyUnicode_Check(key))) {
|
||||
while (*name) {
|
||||
int cmp = (**name == key) ? 0 :
|
||||
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
|
||||
(__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
|
||||
#endif
|
||||
// In Py2, we may need to convert the argument name from str to unicode for comparison.
|
||||
PyUnicode_Compare(**name, key);
|
||||
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
|
||||
if (cmp == 0) {
|
||||
values[name-argnames] = value;
|
||||
break;
|
||||
}
|
||||
name++;
|
||||
}
|
||||
if (*name) continue;
|
||||
else {
|
||||
// not found after positional args, check for duplicate
|
||||
PyObject*** argname = argnames;
|
||||
while (argname != first_kw_arg) {
|
||||
int cmp = (**argname == key) ? 0 :
|
||||
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
|
||||
(__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
|
||||
#endif
|
||||
// need to convert argument name from bytes to unicode for comparison
|
||||
PyUnicode_Compare(**argname, key);
|
||||
if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
|
||||
if (cmp == 0) goto arg_passed_twice;
|
||||
argname++;
|
||||
}
|
||||
}
|
||||
} else
|
||||
goto invalid_keyword_type;
|
||||
|
||||
if (kwds2) {
|
||||
if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
|
||||
} else {
|
||||
goto invalid_keyword;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
arg_passed_twice:
|
||||
__Pyx_RaiseDoubleKeywordsError(function_name, key);
|
||||
goto bad;
|
||||
invalid_keyword_type:
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() keywords must be strings", function_name);
|
||||
goto bad;
|
||||
invalid_keyword:
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
"%.200s() got an unexpected keyword argument '%.200s'",
|
||||
function_name, PyString_AsString(key));
|
||||
#else
|
||||
"%s() got an unexpected keyword argument '%U'",
|
||||
function_name, key);
|
||||
#endif
|
||||
bad:
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//////////////////// MergeKeywords.proto ////////////////////
|
||||
|
||||
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping); /*proto*/
|
||||
|
||||
//////////////////// MergeKeywords ////////////////////
|
||||
//@requires: RaiseDoubleKeywords
|
||||
//@requires: Optimize.c::dict_iter
|
||||
|
||||
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
|
||||
PyObject *iter, *key = NULL, *value = NULL;
|
||||
int source_is_dict, result;
|
||||
Py_ssize_t orig_length, ppos = 0;
|
||||
|
||||
iter = __Pyx_dict_iterator(source_mapping, 0, PYIDENT("items"), &orig_length, &source_is_dict);
|
||||
if (unlikely(!iter)) {
|
||||
// slow fallback: try converting to dict, then iterate
|
||||
PyObject *args;
|
||||
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
|
||||
PyErr_Clear();
|
||||
args = PyTuple_Pack(1, source_mapping);
|
||||
if (likely(args)) {
|
||||
PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL);
|
||||
Py_DECREF(args);
|
||||
if (likely(fallback)) {
|
||||
iter = __Pyx_dict_iterator(fallback, 1, PYIDENT("items"), &orig_length, &source_is_dict);
|
||||
Py_DECREF(fallback);
|
||||
}
|
||||
}
|
||||
if (unlikely(!iter)) goto bad;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict);
|
||||
if (unlikely(result < 0)) goto bad;
|
||||
if (!result) break;
|
||||
|
||||
if (unlikely(PyDict_Contains(kwdict, key))) {
|
||||
__Pyx_RaiseDoubleKeywordsError("function", key);
|
||||
result = -1;
|
||||
} else {
|
||||
result = PyDict_SetItem(kwdict, key, value);
|
||||
}
|
||||
Py_DECREF(key);
|
||||
Py_DECREF(value);
|
||||
if (unlikely(result < 0)) goto bad;
|
||||
}
|
||||
Py_XDECREF(iter);
|
||||
return 0;
|
||||
|
||||
bad:
|
||||
Py_XDECREF(iter);
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,727 @@
|
|||
/////////////// PyIdentifierFromString.proto ///////////////
|
||||
|
||||
#if !defined(__Pyx_PyIdentifier_FromString)
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
#define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
|
||||
#else
|
||||
#define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// Import.proto ///////////////
|
||||
|
||||
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /*proto*/
|
||||
|
||||
/////////////// Import ///////////////
|
||||
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
||||
//@substitute: naming
|
||||
|
||||
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
|
||||
PyObject *empty_list = 0;
|
||||
PyObject *module = 0;
|
||||
PyObject *global_dict = 0;
|
||||
PyObject *empty_dict = 0;
|
||||
PyObject *list;
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject *py_import;
|
||||
py_import = __Pyx_PyObject_GetAttrStr($builtins_cname, PYIDENT("__import__"));
|
||||
if (!py_import)
|
||||
goto bad;
|
||||
#endif
|
||||
if (from_list)
|
||||
list = from_list;
|
||||
else {
|
||||
empty_list = PyList_New(0);
|
||||
if (!empty_list)
|
||||
goto bad;
|
||||
list = empty_list;
|
||||
}
|
||||
global_dict = PyModule_GetDict($module_cname);
|
||||
if (!global_dict)
|
||||
goto bad;
|
||||
empty_dict = PyDict_New();
|
||||
if (!empty_dict)
|
||||
goto bad;
|
||||
{
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (level == -1) {
|
||||
// Avoid C compiler warning if strchr() evaluates to false at compile time.
|
||||
if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
|
||||
/* try package relative import first */
|
||||
module = PyImport_ImportModuleLevelObject(
|
||||
name, global_dict, empty_dict, list, 1);
|
||||
if (!module) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_ImportError))
|
||||
goto bad;
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
level = 0; /* try absolute import on failure */
|
||||
}
|
||||
#endif
|
||||
if (!module) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
PyObject *py_level = PyInt_FromLong(level);
|
||||
if (!py_level)
|
||||
goto bad;
|
||||
module = PyObject_CallFunctionObjArgs(py_import,
|
||||
name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
|
||||
Py_DECREF(py_level);
|
||||
#else
|
||||
module = PyImport_ImportModuleLevelObject(
|
||||
name, global_dict, empty_dict, list, level);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
bad:
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
Py_XDECREF(py_import);
|
||||
#endif
|
||||
Py_XDECREF(empty_list);
|
||||
Py_XDECREF(empty_dict);
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
/////////////// ImportFrom.proto ///////////////
|
||||
|
||||
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /*proto*/
|
||||
|
||||
/////////////// ImportFrom ///////////////
|
||||
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
||||
|
||||
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
|
||||
PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
|
||||
if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Format(PyExc_ImportError,
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
"cannot import name %.230s", PyString_AS_STRING(name));
|
||||
#else
|
||||
"cannot import name %S", name);
|
||||
#endif
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/////////////// ImportStar ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
/* import_all_from is an unexposed function from ceval.c */
|
||||
|
||||
static int
|
||||
__Pyx_import_all_from(PyObject *locals, PyObject *v)
|
||||
{
|
||||
PyObject *all = PyObject_GetAttrString(v, "__all__");
|
||||
PyObject *dict, *name, *value;
|
||||
int skip_leading_underscores = 0;
|
||||
int pos, err;
|
||||
|
||||
if (all == NULL) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||
return -1; /* Unexpected error */
|
||||
PyErr_Clear();
|
||||
dict = PyObject_GetAttrString(v, "__dict__");
|
||||
if (dict == NULL) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||
return -1;
|
||||
PyErr_SetString(PyExc_ImportError,
|
||||
"from-import-* object has no __dict__ and no __all__");
|
||||
return -1;
|
||||
}
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
all = PyObject_CallMethod(dict, (char *)"keys", NULL);
|
||||
#else
|
||||
all = PyMapping_Keys(dict);
|
||||
#endif
|
||||
Py_DECREF(dict);
|
||||
if (all == NULL)
|
||||
return -1;
|
||||
skip_leading_underscores = 1;
|
||||
}
|
||||
|
||||
for (pos = 0, err = 0; ; pos++) {
|
||||
name = PySequence_GetItem(all, pos);
|
||||
if (name == NULL) {
|
||||
if (!PyErr_ExceptionMatches(PyExc_IndexError))
|
||||
err = -1;
|
||||
else
|
||||
PyErr_Clear();
|
||||
break;
|
||||
}
|
||||
if (skip_leading_underscores &&
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
likely(PyString_Check(name)) &&
|
||||
PyString_AS_STRING(name)[0] == '_')
|
||||
#else
|
||||
likely(PyUnicode_Check(name)) &&
|
||||
likely(__Pyx_PyUnicode_GET_LENGTH(name)) &&
|
||||
__Pyx_PyUnicode_READ_CHAR(name, 0) == '_')
|
||||
#endif
|
||||
{
|
||||
Py_DECREF(name);
|
||||
continue;
|
||||
}
|
||||
value = PyObject_GetAttr(v, name);
|
||||
if (value == NULL)
|
||||
err = -1;
|
||||
else if (PyDict_CheckExact(locals))
|
||||
err = PyDict_SetItem(locals, name, value);
|
||||
else
|
||||
err = PyObject_SetItem(locals, name, value);
|
||||
Py_DECREF(name);
|
||||
Py_XDECREF(value);
|
||||
if (err != 0)
|
||||
break;
|
||||
}
|
||||
Py_DECREF(all);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static int ${import_star}(PyObject* m) {
|
||||
|
||||
int i;
|
||||
int ret = -1;
|
||||
char* s;
|
||||
PyObject *locals = 0;
|
||||
PyObject *list = 0;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyObject *utf8_name = 0;
|
||||
#endif
|
||||
PyObject *name;
|
||||
PyObject *item;
|
||||
|
||||
locals = PyDict_New(); if (!locals) goto bad;
|
||||
if (__Pyx_import_all_from(locals, m) < 0) goto bad;
|
||||
list = PyDict_Items(locals); if (!list) goto bad;
|
||||
|
||||
for(i=0; i<PyList_GET_SIZE(list); i++) {
|
||||
name = PyTuple_GET_ITEM(PyList_GET_ITEM(list, i), 0);
|
||||
item = PyTuple_GET_ITEM(PyList_GET_ITEM(list, i), 1);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
utf8_name = PyUnicode_AsUTF8String(name);
|
||||
if (!utf8_name) goto bad;
|
||||
s = PyBytes_AS_STRING(utf8_name);
|
||||
if (${import_star_set}(item, name, s) < 0) goto bad;
|
||||
Py_DECREF(utf8_name); utf8_name = 0;
|
||||
#else
|
||||
s = PyString_AsString(name);
|
||||
if (!s) goto bad;
|
||||
if (${import_star_set}(item, name, s) < 0) goto bad;
|
||||
#endif
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
bad:
|
||||
Py_XDECREF(locals);
|
||||
Py_XDECREF(list);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
Py_XDECREF(utf8_name);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/////////////// SetPackagePathFromImportLib.proto ///////////////
|
||||
|
||||
// PY_VERSION_HEX >= 0x03030000
|
||||
#if PY_MAJOR_VERSION >= 3 && !CYTHON_PEP489_MULTI_PHASE_INIT
|
||||
static int __Pyx_SetPackagePathFromImportLib(PyObject *module_name);
|
||||
#else
|
||||
#define __Pyx_SetPackagePathFromImportLib(a) 0
|
||||
#endif
|
||||
|
||||
/////////////// SetPackagePathFromImportLib ///////////////
|
||||
//@requires: ObjectHandling.c::PyObjectGetAttrStr
|
||||
//@substitute: naming
|
||||
|
||||
// PY_VERSION_HEX >= 0x03030000
|
||||
#if PY_MAJOR_VERSION >= 3 && !CYTHON_PEP489_MULTI_PHASE_INIT
|
||||
static int __Pyx_SetPackagePathFromImportLib(PyObject *module_name) {
|
||||
PyObject *importlib, *osmod, *ossep, *parts, *package_path;
|
||||
PyObject *file_path = NULL;
|
||||
int result;
|
||||
PyObject *spec;
|
||||
// package_path = [importlib.util.find_spec(module_name).origin.rsplit(os.sep, 1)[0]]
|
||||
importlib = PyImport_ImportModule("importlib.util");
|
||||
if (unlikely(!importlib))
|
||||
goto bad;
|
||||
spec = PyObject_CallMethod(importlib, "find_spec", "(O)", module_name);
|
||||
Py_DECREF(importlib);
|
||||
if (unlikely(!spec))
|
||||
goto bad;
|
||||
file_path = PyObject_GetAttrString(spec, "origin");
|
||||
Py_DECREF(spec);
|
||||
if (unlikely(!file_path))
|
||||
goto bad;
|
||||
|
||||
if (unlikely(PyObject_SetAttrString($module_cname, "__file__", file_path) < 0))
|
||||
goto bad;
|
||||
|
||||
osmod = PyImport_ImportModule("os");
|
||||
if (unlikely(!osmod))
|
||||
goto bad;
|
||||
ossep = PyObject_GetAttrString(osmod, "sep");
|
||||
Py_DECREF(osmod);
|
||||
if (unlikely(!ossep))
|
||||
goto bad;
|
||||
parts = PyObject_CallMethod(file_path, "rsplit", "(Oi)", ossep, 1);
|
||||
Py_DECREF(file_path); file_path = NULL;
|
||||
Py_DECREF(ossep);
|
||||
if (unlikely(!parts))
|
||||
goto bad;
|
||||
package_path = Py_BuildValue("[O]", PyList_GET_ITEM(parts, 0));
|
||||
Py_DECREF(parts);
|
||||
if (unlikely(!package_path))
|
||||
goto bad;
|
||||
goto set_path;
|
||||
|
||||
bad:
|
||||
PyErr_WriteUnraisable(module_name);
|
||||
Py_XDECREF(file_path);
|
||||
|
||||
// set an empty path list on failure
|
||||
PyErr_Clear();
|
||||
package_path = PyList_New(0);
|
||||
if (unlikely(!package_path))
|
||||
return -1;
|
||||
|
||||
set_path:
|
||||
result = PyObject_SetAttrString($module_cname, "__path__", package_path);
|
||||
Py_DECREF(package_path);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// TypeImport.proto ///////////////
|
||||
|
||||
#ifndef __PYX_HAVE_RT_ImportType_proto
|
||||
#define __PYX_HAVE_RT_ImportType_proto
|
||||
|
||||
enum __Pyx_ImportType_CheckSize {
|
||||
__Pyx_ImportType_CheckSize_Error = 0,
|
||||
__Pyx_ImportType_CheckSize_Warn = 1,
|
||||
__Pyx_ImportType_CheckSize_Ignore = 2
|
||||
};
|
||||
|
||||
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); /*proto*/
|
||||
|
||||
#endif
|
||||
|
||||
/////////////// TypeImport ///////////////
|
||||
|
||||
#ifndef __PYX_HAVE_RT_ImportType
|
||||
#define __PYX_HAVE_RT_ImportType
|
||||
static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
|
||||
size_t size, enum __Pyx_ImportType_CheckSize check_size)
|
||||
{
|
||||
PyObject *result = 0;
|
||||
char warning[200];
|
||||
Py_ssize_t basicsize;
|
||||
#ifdef Py_LIMITED_API
|
||||
PyObject *py_basicsize;
|
||||
#endif
|
||||
|
||||
result = PyObject_GetAttrString(module, class_name);
|
||||
if (!result)
|
||||
goto bad;
|
||||
if (!PyType_Check(result)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s.%.200s is not a type object",
|
||||
module_name, class_name);
|
||||
goto bad;
|
||||
}
|
||||
#ifndef Py_LIMITED_API
|
||||
basicsize = ((PyTypeObject *)result)->tp_basicsize;
|
||||
#else
|
||||
py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
|
||||
if (!py_basicsize)
|
||||
goto bad;
|
||||
basicsize = PyLong_AsSsize_t(py_basicsize);
|
||||
Py_DECREF(py_basicsize);
|
||||
py_basicsize = 0;
|
||||
if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
|
||||
goto bad;
|
||||
#endif
|
||||
if ((size_t)basicsize < size) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s.%.200s size changed, may indicate binary incompatibility. "
|
||||
"Expected %zd from C header, got %zd from PyObject",
|
||||
module_name, class_name, size, basicsize);
|
||||
goto bad;
|
||||
}
|
||||
if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s.%.200s size changed, may indicate binary incompatibility. "
|
||||
"Expected %zd from C header, got %zd from PyObject",
|
||||
module_name, class_name, size, basicsize);
|
||||
goto bad;
|
||||
}
|
||||
else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
|
||||
PyOS_snprintf(warning, sizeof(warning),
|
||||
"%s.%s size changed, may indicate binary incompatibility. "
|
||||
"Expected %zd from C header, got %zd from PyObject",
|
||||
module_name, class_name, size, basicsize);
|
||||
if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
|
||||
}
|
||||
/* check_size == __Pyx_ImportType_CheckSize_Ignore does not warn nor error */
|
||||
return (PyTypeObject *)result;
|
||||
bad:
|
||||
Py_XDECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// FunctionImport.proto ///////////////
|
||||
|
||||
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig); /*proto*/
|
||||
|
||||
/////////////// FunctionImport ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
#ifndef __PYX_HAVE_RT_ImportFunction
|
||||
#define __PYX_HAVE_RT_ImportFunction
|
||||
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
|
||||
PyObject *d = 0;
|
||||
PyObject *cobj = 0;
|
||||
union {
|
||||
void (*fp)(void);
|
||||
void *p;
|
||||
} tmp;
|
||||
|
||||
d = PyObject_GetAttrString(module, (char *)"$api_name");
|
||||
if (!d)
|
||||
goto bad;
|
||||
cobj = PyDict_GetItemString(d, funcname);
|
||||
if (!cobj) {
|
||||
PyErr_Format(PyExc_ImportError,
|
||||
"%.200s does not export expected C function %.200s",
|
||||
PyModule_GetName(module), funcname);
|
||||
goto bad;
|
||||
}
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
if (!PyCapsule_IsValid(cobj, sig)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
|
||||
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
|
||||
goto bad;
|
||||
}
|
||||
tmp.p = PyCapsule_GetPointer(cobj, sig);
|
||||
#else
|
||||
{const char *desc, *s1, *s2;
|
||||
desc = (const char *)PyCObject_GetDesc(cobj);
|
||||
if (!desc)
|
||||
goto bad;
|
||||
s1 = desc; s2 = sig;
|
||||
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
|
||||
if (*s1 != *s2) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
|
||||
PyModule_GetName(module), funcname, sig, desc);
|
||||
goto bad;
|
||||
}
|
||||
tmp.p = PyCObject_AsVoidPtr(cobj);}
|
||||
#endif
|
||||
*f = tmp.fp;
|
||||
if (!(*f))
|
||||
goto bad;
|
||||
Py_DECREF(d);
|
||||
return 0;
|
||||
bad:
|
||||
Py_XDECREF(d);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// FunctionExport.proto ///////////////
|
||||
|
||||
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig); /*proto*/
|
||||
|
||||
/////////////// FunctionExport ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
|
||||
PyObject *d = 0;
|
||||
PyObject *cobj = 0;
|
||||
union {
|
||||
void (*fp)(void);
|
||||
void *p;
|
||||
} tmp;
|
||||
|
||||
d = PyObject_GetAttrString($module_cname, (char *)"$api_name");
|
||||
if (!d) {
|
||||
PyErr_Clear();
|
||||
d = PyDict_New();
|
||||
if (!d)
|
||||
goto bad;
|
||||
Py_INCREF(d);
|
||||
if (PyModule_AddObject($module_cname, (char *)"$api_name", d) < 0)
|
||||
goto bad;
|
||||
}
|
||||
tmp.fp = f;
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
cobj = PyCapsule_New(tmp.p, sig, 0);
|
||||
#else
|
||||
cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
|
||||
#endif
|
||||
if (!cobj)
|
||||
goto bad;
|
||||
if (PyDict_SetItemString(d, name, cobj) < 0)
|
||||
goto bad;
|
||||
Py_DECREF(cobj);
|
||||
Py_DECREF(d);
|
||||
return 0;
|
||||
bad:
|
||||
Py_XDECREF(cobj);
|
||||
Py_XDECREF(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/////////////// VoidPtrImport.proto ///////////////
|
||||
|
||||
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig); /*proto*/
|
||||
|
||||
/////////////// VoidPtrImport ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
#ifndef __PYX_HAVE_RT_ImportVoidPtr
|
||||
#define __PYX_HAVE_RT_ImportVoidPtr
|
||||
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig) {
|
||||
PyObject *d = 0;
|
||||
PyObject *cobj = 0;
|
||||
|
||||
d = PyObject_GetAttrString(module, (char *)"$api_name");
|
||||
if (!d)
|
||||
goto bad;
|
||||
cobj = PyDict_GetItemString(d, name);
|
||||
if (!cobj) {
|
||||
PyErr_Format(PyExc_ImportError,
|
||||
"%.200s does not export expected C variable %.200s",
|
||||
PyModule_GetName(module), name);
|
||||
goto bad;
|
||||
}
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
if (!PyCapsule_IsValid(cobj, sig)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
|
||||
PyModule_GetName(module), name, sig, PyCapsule_GetName(cobj));
|
||||
goto bad;
|
||||
}
|
||||
*p = PyCapsule_GetPointer(cobj, sig);
|
||||
#else
|
||||
{const char *desc, *s1, *s2;
|
||||
desc = (const char *)PyCObject_GetDesc(cobj);
|
||||
if (!desc)
|
||||
goto bad;
|
||||
s1 = desc; s2 = sig;
|
||||
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
|
||||
if (*s1 != *s2) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
|
||||
PyModule_GetName(module), name, sig, desc);
|
||||
goto bad;
|
||||
}
|
||||
*p = PyCObject_AsVoidPtr(cobj);}
|
||||
#endif
|
||||
if (!(*p))
|
||||
goto bad;
|
||||
Py_DECREF(d);
|
||||
return 0;
|
||||
bad:
|
||||
Py_XDECREF(d);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/////////////// VoidPtrExport.proto ///////////////
|
||||
|
||||
static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig); /*proto*/
|
||||
|
||||
/////////////// VoidPtrExport ///////////////
|
||||
//@substitute: naming
|
||||
//@requires: ObjectHandling.c::PyObjectSetAttrStr
|
||||
|
||||
static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) {
|
||||
PyObject *d;
|
||||
PyObject *cobj = 0;
|
||||
|
||||
d = PyDict_GetItem($moddict_cname, PYIDENT("$api_name"));
|
||||
Py_XINCREF(d);
|
||||
if (!d) {
|
||||
d = PyDict_New();
|
||||
if (!d)
|
||||
goto bad;
|
||||
if (__Pyx_PyObject_SetAttrStr($module_cname, PYIDENT("$api_name"), d) < 0)
|
||||
goto bad;
|
||||
}
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
cobj = PyCapsule_New(p, sig, 0);
|
||||
#else
|
||||
cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
|
||||
#endif
|
||||
if (!cobj)
|
||||
goto bad;
|
||||
if (PyDict_SetItem(d, name, cobj) < 0)
|
||||
goto bad;
|
||||
Py_DECREF(cobj);
|
||||
Py_DECREF(d);
|
||||
return 0;
|
||||
bad:
|
||||
Py_XDECREF(cobj);
|
||||
Py_XDECREF(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/////////////// SetVTable.proto ///////////////
|
||||
|
||||
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
|
||||
|
||||
/////////////// SetVTable ///////////////
|
||||
|
||||
static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
PyObject *ob = PyCapsule_New(vtable, 0, 0);
|
||||
#else
|
||||
PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
|
||||
#endif
|
||||
if (!ob)
|
||||
goto bad;
|
||||
if (PyDict_SetItem(dict, PYIDENT("__pyx_vtable__"), ob) < 0)
|
||||
goto bad;
|
||||
Py_DECREF(ob);
|
||||
return 0;
|
||||
bad:
|
||||
Py_XDECREF(ob);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/////////////// GetVTable.proto ///////////////
|
||||
|
||||
static void* __Pyx_GetVtable(PyObject *dict); /*proto*/
|
||||
|
||||
/////////////// GetVTable ///////////////
|
||||
|
||||
static void* __Pyx_GetVtable(PyObject *dict) {
|
||||
void* ptr;
|
||||
PyObject *ob = PyObject_GetItem(dict, PYIDENT("__pyx_vtable__"));
|
||||
if (!ob)
|
||||
goto bad;
|
||||
#if PY_VERSION_HEX >= 0x02070000
|
||||
ptr = PyCapsule_GetPointer(ob, 0);
|
||||
#else
|
||||
ptr = PyCObject_AsVoidPtr(ob);
|
||||
#endif
|
||||
if (!ptr && !PyErr_Occurred())
|
||||
PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
|
||||
Py_DECREF(ob);
|
||||
return ptr;
|
||||
bad:
|
||||
Py_XDECREF(ob);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/////////////// MergeVTables.proto ///////////////
|
||||
//@requires: GetVTable
|
||||
|
||||
static int __Pyx_MergeVtables(PyTypeObject *type); /*proto*/
|
||||
|
||||
/////////////// MergeVTables ///////////////
|
||||
|
||||
static int __Pyx_MergeVtables(PyTypeObject *type) {
|
||||
int i;
|
||||
void** base_vtables;
|
||||
void* unknown = (void*)-1;
|
||||
PyObject* bases = type->tp_bases;
|
||||
int base_depth = 0;
|
||||
{
|
||||
PyTypeObject* base = type->tp_base;
|
||||
while (base) {
|
||||
base_depth += 1;
|
||||
base = base->tp_base;
|
||||
}
|
||||
}
|
||||
base_vtables = (void**) malloc(sizeof(void*) * (size_t)(base_depth + 1));
|
||||
base_vtables[0] = unknown;
|
||||
// Could do MRO resolution of individual methods in the future, assuming
|
||||
// compatible vtables, but for now simply require a common vtable base.
|
||||
// Note that if the vtables of various bases are extended separately,
|
||||
// resolution isn't possible and we must reject it just as when the
|
||||
// instance struct is so extended. (It would be good to also do this
|
||||
// check when a multiple-base class is created in pure Python as well.)
|
||||
for (i = 1; i < PyTuple_GET_SIZE(bases); i++) {
|
||||
void* base_vtable = __Pyx_GetVtable(((PyTypeObject*)PyTuple_GET_ITEM(bases, i))->tp_dict);
|
||||
if (base_vtable != NULL) {
|
||||
int j;
|
||||
PyTypeObject* base = type->tp_base;
|
||||
for (j = 0; j < base_depth; j++) {
|
||||
if (base_vtables[j] == unknown) {
|
||||
base_vtables[j] = __Pyx_GetVtable(base->tp_dict);
|
||||
base_vtables[j + 1] = unknown;
|
||||
}
|
||||
if (base_vtables[j] == base_vtable) {
|
||||
break;
|
||||
} else if (base_vtables[j] == NULL) {
|
||||
// No more potential matching bases (with vtables).
|
||||
goto bad;
|
||||
}
|
||||
base = base->tp_base;
|
||||
}
|
||||
}
|
||||
}
|
||||
PyErr_Clear();
|
||||
free(base_vtables);
|
||||
return 0;
|
||||
bad:
|
||||
PyErr_Format(
|
||||
PyExc_TypeError,
|
||||
"multiple bases have vtable conflict: '%s' and '%s'",
|
||||
type->tp_base->tp_name, ((PyTypeObject*)PyTuple_GET_ITEM(bases, i))->tp_name);
|
||||
free(base_vtables);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/////////////// ImportNumPyArray.proto ///////////////
|
||||
|
||||
static PyObject *__pyx_numpy_ndarray = NULL;
|
||||
|
||||
static PyObject* __Pyx_ImportNumPyArrayTypeIfAvailable(void); /*proto*/
|
||||
|
||||
/////////////// ImportNumPyArray.cleanup ///////////////
|
||||
Py_CLEAR(__pyx_numpy_ndarray);
|
||||
|
||||
/////////////// ImportNumPyArray ///////////////
|
||||
//@requires: ImportExport.c::Import
|
||||
|
||||
static PyObject* __Pyx__ImportNumPyArray(void) {
|
||||
PyObject *numpy_module, *ndarray_object = NULL;
|
||||
numpy_module = __Pyx_Import(PYIDENT("numpy"), NULL, 0);
|
||||
if (likely(numpy_module)) {
|
||||
ndarray_object = PyObject_GetAttrString(numpy_module, "ndarray");
|
||||
Py_DECREF(numpy_module);
|
||||
}
|
||||
if (unlikely(!ndarray_object)) {
|
||||
// ImportError, AttributeError, ...
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (unlikely(!ndarray_object || !PyObject_TypeCheck(ndarray_object, &PyType_Type))) {
|
||||
Py_XDECREF(ndarray_object);
|
||||
Py_INCREF(Py_None);
|
||||
ndarray_object = Py_None;
|
||||
}
|
||||
return ndarray_object;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE PyObject* __Pyx_ImportNumPyArrayTypeIfAvailable(void) {
|
||||
if (unlikely(!__pyx_numpy_ndarray)) {
|
||||
__pyx_numpy_ndarray = __Pyx__ImportNumPyArray();
|
||||
}
|
||||
Py_INCREF(__pyx_numpy_ndarray);
|
||||
return __pyx_numpy_ndarray;
|
||||
}
|
1496
kivy_venv/lib/python3.11/site-packages/Cython/Utility/MemoryView.pyx
Normal file
1496
kivy_venv/lib/python3.11/site-packages/Cython/Utility/MemoryView.pyx
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,941 @@
|
|||
////////// MemviewSliceStruct.proto //////////
|
||||
//@proto_block: utility_code_proto_before_types
|
||||
|
||||
/* memoryview slice struct */
|
||||
struct {{memview_struct_name}};
|
||||
|
||||
typedef struct {
|
||||
struct {{memview_struct_name}} *memview;
|
||||
char *data;
|
||||
Py_ssize_t shape[{{max_dims}}];
|
||||
Py_ssize_t strides[{{max_dims}}];
|
||||
Py_ssize_t suboffsets[{{max_dims}}];
|
||||
} {{memviewslice_name}};
|
||||
|
||||
// used for "len(memviewslice)"
|
||||
#define __Pyx_MemoryView_Len(m) (m.shape[0])
|
||||
|
||||
|
||||
/////////// Atomics.proto /////////////
|
||||
//@proto_block: utility_code_proto_before_types
|
||||
|
||||
#include <pythread.h>
|
||||
|
||||
#ifndef CYTHON_ATOMICS
|
||||
#define CYTHON_ATOMICS 1
|
||||
#endif
|
||||
// using CYTHON_ATOMICS as a cdef extern bint in the Cython memoryview code
|
||||
// interacts badly with "import *". Therefore, define a helper function-like macro
|
||||
#define __PYX_CYTHON_ATOMICS_ENABLED() CYTHON_ATOMICS
|
||||
|
||||
#define __pyx_atomic_int_type int
|
||||
|
||||
#if CYTHON_ATOMICS && (__GNUC__ >= 5 || (__GNUC__ == 4 && \
|
||||
(__GNUC_MINOR__ > 1 || \
|
||||
(__GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ >= 2))))
|
||||
/* gcc >= 4.1.2 */
|
||||
#define __pyx_atomic_incr_aligned(value) __sync_fetch_and_add(value, 1)
|
||||
#define __pyx_atomic_decr_aligned(value) __sync_fetch_and_sub(value, 1)
|
||||
|
||||
#ifdef __PYX_DEBUG_ATOMICS
|
||||
#warning "Using GNU atomics"
|
||||
#endif
|
||||
#elif CYTHON_ATOMICS && defined(_MSC_VER) && CYTHON_COMPILING_IN_NOGIL
|
||||
/* msvc */
|
||||
#include <intrin.h>
|
||||
#undef __pyx_atomic_int_type
|
||||
#define __pyx_atomic_int_type long
|
||||
#pragma intrinsic (_InterlockedExchangeAdd)
|
||||
#define __pyx_atomic_incr_aligned(value) _InterlockedExchangeAdd(value, 1)
|
||||
#define __pyx_atomic_decr_aligned(value) _InterlockedExchangeAdd(value, -1)
|
||||
|
||||
#ifdef __PYX_DEBUG_ATOMICS
|
||||
#pragma message ("Using MSVC atomics")
|
||||
#endif
|
||||
#else
|
||||
#undef CYTHON_ATOMICS
|
||||
#define CYTHON_ATOMICS 0
|
||||
|
||||
#ifdef __PYX_DEBUG_ATOMICS
|
||||
#warning "Not using atomics"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef volatile __pyx_atomic_int_type __pyx_atomic_int;
|
||||
|
||||
#if CYTHON_ATOMICS
|
||||
#define __pyx_add_acquisition_count(memview) \
|
||||
__pyx_atomic_incr_aligned(__pyx_get_slice_count_pointer(memview))
|
||||
#define __pyx_sub_acquisition_count(memview) \
|
||||
__pyx_atomic_decr_aligned(__pyx_get_slice_count_pointer(memview))
|
||||
#else
|
||||
#define __pyx_add_acquisition_count(memview) \
|
||||
__pyx_add_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
|
||||
#define __pyx_sub_acquisition_count(memview) \
|
||||
__pyx_sub_acquisition_count_locked(__pyx_get_slice_count_pointer(memview), memview->lock)
|
||||
#endif
|
||||
|
||||
|
||||
/////////////// ObjectToMemviewSlice.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *, int writable_flag);
|
||||
|
||||
|
||||
////////// MemviewSliceInit.proto //////////
|
||||
|
||||
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
|
||||
|
||||
#define __Pyx_MEMVIEW_DIRECT 1
|
||||
#define __Pyx_MEMVIEW_PTR 2
|
||||
#define __Pyx_MEMVIEW_FULL 4
|
||||
#define __Pyx_MEMVIEW_CONTIG 8
|
||||
#define __Pyx_MEMVIEW_STRIDED 16
|
||||
#define __Pyx_MEMVIEW_FOLLOW 32
|
||||
|
||||
#define __Pyx_IS_C_CONTIG 1
|
||||
#define __Pyx_IS_F_CONTIG 2
|
||||
|
||||
static int __Pyx_init_memviewslice(
|
||||
struct __pyx_memoryview_obj *memview,
|
||||
int ndim,
|
||||
__Pyx_memviewslice *memviewslice,
|
||||
int memview_is_new_reference);
|
||||
|
||||
static CYTHON_INLINE int __pyx_add_acquisition_count_locked(
|
||||
__pyx_atomic_int *acquisition_count, PyThread_type_lock lock);
|
||||
static CYTHON_INLINE int __pyx_sub_acquisition_count_locked(
|
||||
__pyx_atomic_int *acquisition_count, PyThread_type_lock lock);
|
||||
|
||||
#define __pyx_get_slice_count_pointer(memview) (memview->acquisition_count_aligned_p)
|
||||
#define __pyx_get_slice_count(memview) (*__pyx_get_slice_count_pointer(memview))
|
||||
#define __PYX_INC_MEMVIEW(slice, have_gil) __Pyx_INC_MEMVIEW(slice, have_gil, __LINE__)
|
||||
#define __PYX_XDEC_MEMVIEW(slice, have_gil) __Pyx_XDEC_MEMVIEW(slice, have_gil, __LINE__)
|
||||
static CYTHON_INLINE void __Pyx_INC_MEMVIEW({{memviewslice_name}} *, int, int);
|
||||
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *, int, int);
|
||||
|
||||
|
||||
/////////////// MemviewSliceIndex.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE char *__pyx_memviewslice_index_full(
|
||||
const char *bufp, Py_ssize_t idx, Py_ssize_t stride, Py_ssize_t suboffset);
|
||||
|
||||
|
||||
/////////////// ObjectToMemviewSlice ///////////////
|
||||
//@requires: MemviewSliceValidateAndInit
|
||||
|
||||
static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *obj, int writable_flag) {
|
||||
{{memviewslice_name}} result = {{memslice_init}};
|
||||
__Pyx_BufFmt_StackElem stack[{{struct_nesting_depth}}];
|
||||
int axes_specs[] = { {{axes_specs}} };
|
||||
int retcode;
|
||||
|
||||
if (obj == Py_None) {
|
||||
/* We don't bother to refcount None */
|
||||
result.memview = (struct __pyx_memoryview_obj *) Py_None;
|
||||
return result;
|
||||
}
|
||||
|
||||
retcode = __Pyx_ValidateAndInit_memviewslice(axes_specs, {{c_or_f_flag}},
|
||||
{{buf_flag}} | writable_flag, {{ndim}},
|
||||
&{{dtype_typeinfo}}, stack,
|
||||
&result, obj);
|
||||
|
||||
if (unlikely(retcode == -1))
|
||||
goto __pyx_fail;
|
||||
|
||||
return result;
|
||||
__pyx_fail:
|
||||
result.memview = NULL;
|
||||
result.data = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/////////////// MemviewSliceValidateAndInit.proto ///////////////
|
||||
|
||||
static int __Pyx_ValidateAndInit_memviewslice(
|
||||
int *axes_specs,
|
||||
int c_or_f_flag,
|
||||
int buf_flags,
|
||||
int ndim,
|
||||
__Pyx_TypeInfo *dtype,
|
||||
__Pyx_BufFmt_StackElem stack[],
|
||||
__Pyx_memviewslice *memviewslice,
|
||||
PyObject *original_obj);
|
||||
|
||||
/////////////// MemviewSliceValidateAndInit ///////////////
|
||||
//@requires: Buffer.c::TypeInfoCompare
|
||||
//@requires: Buffer.c::BufferFormatStructs
|
||||
//@requires: Buffer.c::BufferFormatCheck
|
||||
|
||||
static int
|
||||
__pyx_check_strides(Py_buffer *buf, int dim, int ndim, int spec)
|
||||
{
|
||||
if (buf->shape[dim] <= 1)
|
||||
return 1;
|
||||
|
||||
if (buf->strides) {
|
||||
if (spec & __Pyx_MEMVIEW_CONTIG) {
|
||||
if (spec & (__Pyx_MEMVIEW_PTR|__Pyx_MEMVIEW_FULL)) {
|
||||
if (unlikely(buf->strides[dim] != sizeof(void *))) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer is not indirectly contiguous "
|
||||
"in dimension %d.", dim);
|
||||
goto fail;
|
||||
}
|
||||
} else if (unlikely(buf->strides[dim] != buf->itemsize)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Buffer and memoryview are not contiguous "
|
||||
"in the same dimension.");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (spec & __Pyx_MEMVIEW_FOLLOW) {
|
||||
Py_ssize_t stride = buf->strides[dim];
|
||||
if (stride < 0)
|
||||
stride = -stride;
|
||||
if (unlikely(stride < buf->itemsize)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Buffer and memoryview are not contiguous "
|
||||
"in the same dimension.");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (unlikely(spec & __Pyx_MEMVIEW_CONTIG && dim != ndim - 1)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"C-contiguous buffer is not contiguous in "
|
||||
"dimension %d", dim);
|
||||
goto fail;
|
||||
} else if (unlikely(spec & (__Pyx_MEMVIEW_PTR))) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"C-contiguous buffer is not indirect in "
|
||||
"dimension %d", dim);
|
||||
goto fail;
|
||||
} else if (unlikely(buf->suboffsets)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Buffer exposes suboffsets but no strides");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
__pyx_check_suboffsets(Py_buffer *buf, int dim, CYTHON_UNUSED int ndim, int spec)
|
||||
{
|
||||
// Todo: without PyBUF_INDIRECT we may not have suboffset information, i.e., the
|
||||
// ptr may not be set to NULL but may be uninitialized?
|
||||
if (spec & __Pyx_MEMVIEW_DIRECT) {
|
||||
if (unlikely(buf->suboffsets && buf->suboffsets[dim] >= 0)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer not compatible with direct access "
|
||||
"in dimension %d.", dim);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (spec & __Pyx_MEMVIEW_PTR) {
|
||||
if (unlikely(!buf->suboffsets || (buf->suboffsets[dim] < 0))) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer is not indirectly accessible "
|
||||
"in dimension %d.", dim);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
__pyx_verify_contig(Py_buffer *buf, int ndim, int c_or_f_flag)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (c_or_f_flag & __Pyx_IS_F_CONTIG) {
|
||||
Py_ssize_t stride = 1;
|
||||
for (i = 0; i < ndim; i++) {
|
||||
if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Buffer not fortran contiguous.");
|
||||
goto fail;
|
||||
}
|
||||
stride = stride * buf->shape[i];
|
||||
}
|
||||
} else if (c_or_f_flag & __Pyx_IS_C_CONTIG) {
|
||||
Py_ssize_t stride = 1;
|
||||
for (i = ndim - 1; i >- 1; i--) {
|
||||
if (unlikely(stride * buf->itemsize != buf->strides[i] && buf->shape[i] > 1)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Buffer not C contiguous.");
|
||||
goto fail;
|
||||
}
|
||||
stride = stride * buf->shape[i];
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
fail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __Pyx_ValidateAndInit_memviewslice(
|
||||
int *axes_specs,
|
||||
int c_or_f_flag,
|
||||
int buf_flags,
|
||||
int ndim,
|
||||
__Pyx_TypeInfo *dtype,
|
||||
__Pyx_BufFmt_StackElem stack[],
|
||||
__Pyx_memviewslice *memviewslice,
|
||||
PyObject *original_obj)
|
||||
{
|
||||
struct __pyx_memoryview_obj *memview, *new_memview;
|
||||
__Pyx_RefNannyDeclarations
|
||||
Py_buffer *buf;
|
||||
int i, spec = 0, retval = -1;
|
||||
__Pyx_BufFmt_Context ctx;
|
||||
int from_memoryview = __pyx_memoryview_check(original_obj);
|
||||
|
||||
__Pyx_RefNannySetupContext("ValidateAndInit_memviewslice", 0);
|
||||
|
||||
if (from_memoryview && __pyx_typeinfo_cmp(dtype, ((struct __pyx_memoryview_obj *)
|
||||
original_obj)->typeinfo)) {
|
||||
/* We have a matching dtype, skip format parsing */
|
||||
memview = (struct __pyx_memoryview_obj *) original_obj;
|
||||
new_memview = NULL;
|
||||
} else {
|
||||
memview = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
|
||||
original_obj, buf_flags, 0, dtype);
|
||||
new_memview = memview;
|
||||
if (unlikely(!memview))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
buf = &memview->view;
|
||||
if (unlikely(buf->ndim != ndim)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Buffer has wrong number of dimensions (expected %d, got %d)",
|
||||
ndim, buf->ndim);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (new_memview) {
|
||||
__Pyx_BufFmt_Init(&ctx, stack, dtype);
|
||||
if (unlikely(!__Pyx_BufFmt_CheckString(&ctx, buf->format))) goto fail;
|
||||
}
|
||||
|
||||
if (unlikely((unsigned) buf->itemsize != dtype->size)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) "
|
||||
"does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)",
|
||||
buf->itemsize,
|
||||
(buf->itemsize > 1) ? "s" : "",
|
||||
dtype->name,
|
||||
dtype->size,
|
||||
(dtype->size > 1) ? "s" : "");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Check axes */
|
||||
if (buf->len > 0) {
|
||||
// 0-sized arrays do not undergo these checks since their strides are
|
||||
// irrelevant and they are always both C- and F-contiguous.
|
||||
for (i = 0; i < ndim; i++) {
|
||||
spec = axes_specs[i];
|
||||
if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
|
||||
goto fail;
|
||||
if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Check contiguity */
|
||||
if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Initialize */
|
||||
if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
|
||||
new_memview != NULL) == -1)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
goto no_fail;
|
||||
|
||||
fail:
|
||||
Py_XDECREF(new_memview);
|
||||
retval = -1;
|
||||
|
||||
no_fail:
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
////////// MemviewSliceInit //////////
|
||||
|
||||
static int
|
||||
__Pyx_init_memviewslice(struct __pyx_memoryview_obj *memview,
|
||||
int ndim,
|
||||
{{memviewslice_name}} *memviewslice,
|
||||
int memview_is_new_reference)
|
||||
{
|
||||
__Pyx_RefNannyDeclarations
|
||||
int i, retval=-1;
|
||||
Py_buffer *buf = &memview->view;
|
||||
__Pyx_RefNannySetupContext("init_memviewslice", 0);
|
||||
|
||||
if (unlikely(memviewslice->memview || memviewslice->data)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"memviewslice is already initialized!");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (buf->strides) {
|
||||
for (i = 0; i < ndim; i++) {
|
||||
memviewslice->strides[i] = buf->strides[i];
|
||||
}
|
||||
} else {
|
||||
Py_ssize_t stride = buf->itemsize;
|
||||
for (i = ndim - 1; i >= 0; i--) {
|
||||
memviewslice->strides[i] = stride;
|
||||
stride *= buf->shape[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ndim; i++) {
|
||||
memviewslice->shape[i] = buf->shape[i];
|
||||
if (buf->suboffsets) {
|
||||
memviewslice->suboffsets[i] = buf->suboffsets[i];
|
||||
} else {
|
||||
memviewslice->suboffsets[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
memviewslice->memview = memview;
|
||||
memviewslice->data = (char *)buf->buf;
|
||||
if (__pyx_add_acquisition_count(memview) == 0 && !memview_is_new_reference) {
|
||||
Py_INCREF(memview);
|
||||
}
|
||||
retval = 0;
|
||||
goto no_fail;
|
||||
|
||||
fail:
|
||||
/* Don't decref, the memoryview may be borrowed. Let the caller do the cleanup */
|
||||
/* __Pyx_XDECREF(memviewslice->memview); */
|
||||
memviewslice->memview = 0;
|
||||
memviewslice->data = 0;
|
||||
retval = -1;
|
||||
no_fail:
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return retval;
|
||||
}
|
||||
|
||||
#ifndef Py_NO_RETURN
|
||||
// available since Py3.3
|
||||
#define Py_NO_RETURN
|
||||
#endif
|
||||
|
||||
static void __pyx_fatalerror(const char *fmt, ...) Py_NO_RETURN {
|
||||
va_list vargs;
|
||||
char msg[200];
|
||||
|
||||
#if PY_VERSION_HEX >= 0x030A0000 || defined(HAVE_STDARG_PROTOTYPES)
|
||||
va_start(vargs, fmt);
|
||||
#else
|
||||
va_start(vargs);
|
||||
#endif
|
||||
vsnprintf(msg, 200, fmt, vargs);
|
||||
va_end(vargs);
|
||||
|
||||
Py_FatalError(msg);
|
||||
}
|
||||
|
||||
static CYTHON_INLINE int
|
||||
__pyx_add_acquisition_count_locked(__pyx_atomic_int *acquisition_count,
|
||||
PyThread_type_lock lock)
|
||||
{
|
||||
int result;
|
||||
PyThread_acquire_lock(lock, 1);
|
||||
result = (*acquisition_count)++;
|
||||
PyThread_release_lock(lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE int
|
||||
__pyx_sub_acquisition_count_locked(__pyx_atomic_int *acquisition_count,
|
||||
PyThread_type_lock lock)
|
||||
{
|
||||
int result;
|
||||
PyThread_acquire_lock(lock, 1);
|
||||
result = (*acquisition_count)--;
|
||||
PyThread_release_lock(lock);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static CYTHON_INLINE void
|
||||
__Pyx_INC_MEMVIEW({{memviewslice_name}} *memslice, int have_gil, int lineno)
|
||||
{
|
||||
int first_time;
|
||||
struct {{memview_struct_name}} *memview = memslice->memview;
|
||||
if (unlikely(!memview || (PyObject *) memview == Py_None))
|
||||
return; /* allow uninitialized memoryview assignment */
|
||||
|
||||
if (unlikely(__pyx_get_slice_count(memview) < 0))
|
||||
__pyx_fatalerror("Acquisition count is %d (line %d)",
|
||||
__pyx_get_slice_count(memview), lineno);
|
||||
|
||||
first_time = __pyx_add_acquisition_count(memview) == 0;
|
||||
|
||||
if (unlikely(first_time)) {
|
||||
if (have_gil) {
|
||||
Py_INCREF((PyObject *) memview);
|
||||
} else {
|
||||
PyGILState_STATE _gilstate = PyGILState_Ensure();
|
||||
Py_INCREF((PyObject *) memview);
|
||||
PyGILState_Release(_gilstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW({{memviewslice_name}} *memslice,
|
||||
int have_gil, int lineno) {
|
||||
int last_time;
|
||||
struct {{memview_struct_name}} *memview = memslice->memview;
|
||||
|
||||
if (unlikely(!memview || (PyObject *) memview == Py_None)) {
|
||||
// we do not ref-count None
|
||||
memslice->memview = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (unlikely(__pyx_get_slice_count(memview) <= 0))
|
||||
__pyx_fatalerror("Acquisition count is %d (line %d)",
|
||||
__pyx_get_slice_count(memview), lineno);
|
||||
|
||||
last_time = __pyx_sub_acquisition_count(memview) == 1;
|
||||
memslice->data = NULL;
|
||||
|
||||
if (unlikely(last_time)) {
|
||||
if (have_gil) {
|
||||
Py_CLEAR(memslice->memview);
|
||||
} else {
|
||||
PyGILState_STATE _gilstate = PyGILState_Ensure();
|
||||
Py_CLEAR(memslice->memview);
|
||||
PyGILState_Release(_gilstate);
|
||||
}
|
||||
} else {
|
||||
memslice->memview = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////// MemviewSliceCopyTemplate.proto //////////
|
||||
|
||||
static {{memviewslice_name}}
|
||||
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
|
||||
const char *mode, int ndim,
|
||||
size_t sizeof_dtype, int contig_flag,
|
||||
int dtype_is_object);
|
||||
|
||||
|
||||
////////// MemviewSliceCopyTemplate //////////
|
||||
|
||||
static {{memviewslice_name}}
|
||||
__pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
|
||||
const char *mode, int ndim,
|
||||
size_t sizeof_dtype, int contig_flag,
|
||||
int dtype_is_object)
|
||||
{
|
||||
__Pyx_RefNannyDeclarations
|
||||
int i;
|
||||
__Pyx_memviewslice new_mvs = {{memslice_init}};
|
||||
struct __pyx_memoryview_obj *from_memview = from_mvs->memview;
|
||||
Py_buffer *buf = &from_memview->view;
|
||||
PyObject *shape_tuple = NULL;
|
||||
PyObject *temp_int = NULL;
|
||||
struct __pyx_array_obj *array_obj = NULL;
|
||||
struct __pyx_memoryview_obj *memview_obj = NULL;
|
||||
|
||||
__Pyx_RefNannySetupContext("__pyx_memoryview_copy_new_contig", 0);
|
||||
|
||||
for (i = 0; i < ndim; i++) {
|
||||
if (unlikely(from_mvs->suboffsets[i] >= 0)) {
|
||||
PyErr_Format(PyExc_ValueError, "Cannot copy memoryview slice with "
|
||||
"indirect dimensions (axis %d)", i);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
shape_tuple = PyTuple_New(ndim);
|
||||
if (unlikely(!shape_tuple)) {
|
||||
goto fail;
|
||||
}
|
||||
__Pyx_GOTREF(shape_tuple);
|
||||
|
||||
|
||||
for(i = 0; i < ndim; i++) {
|
||||
temp_int = PyInt_FromSsize_t(from_mvs->shape[i]);
|
||||
if(unlikely(!temp_int)) {
|
||||
goto fail;
|
||||
} else {
|
||||
PyTuple_SET_ITEM(shape_tuple, i, temp_int);
|
||||
temp_int = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
array_obj = __pyx_array_new(shape_tuple, sizeof_dtype, buf->format, (char *) mode, NULL);
|
||||
if (unlikely(!array_obj)) {
|
||||
goto fail;
|
||||
}
|
||||
__Pyx_GOTREF(array_obj);
|
||||
|
||||
memview_obj = (struct __pyx_memoryview_obj *) __pyx_memoryview_new(
|
||||
(PyObject *) array_obj, contig_flag,
|
||||
dtype_is_object,
|
||||
from_mvs->memview->typeinfo);
|
||||
if (unlikely(!memview_obj))
|
||||
goto fail;
|
||||
|
||||
/* initialize new_mvs */
|
||||
if (unlikely(__Pyx_init_memviewslice(memview_obj, ndim, &new_mvs, 1) < 0))
|
||||
goto fail;
|
||||
|
||||
if (unlikely(__pyx_memoryview_copy_contents(*from_mvs, new_mvs, ndim, ndim,
|
||||
dtype_is_object) < 0))
|
||||
goto fail;
|
||||
|
||||
goto no_fail;
|
||||
|
||||
fail:
|
||||
__Pyx_XDECREF(new_mvs.memview);
|
||||
new_mvs.memview = NULL;
|
||||
new_mvs.data = NULL;
|
||||
no_fail:
|
||||
__Pyx_XDECREF(shape_tuple);
|
||||
__Pyx_XDECREF(temp_int);
|
||||
__Pyx_XDECREF(array_obj);
|
||||
__Pyx_RefNannyFinishContext();
|
||||
return new_mvs;
|
||||
}
|
||||
|
||||
|
||||
////////// CopyContentsUtility.proto /////////
|
||||
|
||||
#define {{func_cname}}(slice) \
|
||||
__pyx_memoryview_copy_new_contig(&slice, "{{mode}}", {{ndim}}, \
|
||||
sizeof({{dtype_decl}}), {{contig_flag}}, \
|
||||
{{dtype_is_object}})
|
||||
|
||||
|
||||
////////// OverlappingSlices.proto //////////
|
||||
|
||||
static int __pyx_slices_overlap({{memviewslice_name}} *slice1,
|
||||
{{memviewslice_name}} *slice2,
|
||||
int ndim, size_t itemsize);
|
||||
|
||||
|
||||
////////// OverlappingSlices //////////
|
||||
|
||||
/* Based on numpy's core/src/multiarray/array_assign.c */
|
||||
|
||||
/* Gets a half-open range [start, end) which contains the array data */
|
||||
static void
|
||||
__pyx_get_array_memory_extents({{memviewslice_name}} *slice,
|
||||
void **out_start, void **out_end,
|
||||
int ndim, size_t itemsize)
|
||||
{
|
||||
char *start, *end;
|
||||
int i;
|
||||
|
||||
start = end = slice->data;
|
||||
|
||||
for (i = 0; i < ndim; i++) {
|
||||
Py_ssize_t stride = slice->strides[i];
|
||||
Py_ssize_t extent = slice->shape[i];
|
||||
|
||||
if (extent == 0) {
|
||||
*out_start = *out_end = start;
|
||||
return;
|
||||
} else {
|
||||
if (stride > 0)
|
||||
end += stride * (extent - 1);
|
||||
else
|
||||
start += stride * (extent - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return a half-open range */
|
||||
*out_start = start;
|
||||
*out_end = end + itemsize;
|
||||
}
|
||||
|
||||
/* Returns 1 if the arrays have overlapping data, 0 otherwise */
|
||||
static int
|
||||
__pyx_slices_overlap({{memviewslice_name}} *slice1,
|
||||
{{memviewslice_name}} *slice2,
|
||||
int ndim, size_t itemsize)
|
||||
{
|
||||
void *start1, *end1, *start2, *end2;
|
||||
|
||||
__pyx_get_array_memory_extents(slice1, &start1, &end1, ndim, itemsize);
|
||||
__pyx_get_array_memory_extents(slice2, &start2, &end2, ndim, itemsize);
|
||||
|
||||
return (start1 < end2) && (start2 < end1);
|
||||
}
|
||||
|
||||
|
||||
////////// MemviewSliceCheckContig.proto //////////
|
||||
|
||||
#define __pyx_memviewslice_is_contig_{{contig_type}}{{ndim}}(slice) \
|
||||
__pyx_memviewslice_is_contig(slice, '{{contig_type}}', {{ndim}})
|
||||
|
||||
|
||||
////////// MemviewSliceIsContig.proto //////////
|
||||
|
||||
static int __pyx_memviewslice_is_contig(const {{memviewslice_name}} mvs, char order, int ndim);/*proto*/
|
||||
|
||||
|
||||
////////// MemviewSliceIsContig //////////
|
||||
|
||||
static int
|
||||
__pyx_memviewslice_is_contig(const {{memviewslice_name}} mvs, char order, int ndim)
|
||||
{
|
||||
int i, index, step, start;
|
||||
Py_ssize_t itemsize = mvs.memview->view.itemsize;
|
||||
|
||||
if (order == 'F') {
|
||||
step = 1;
|
||||
start = 0;
|
||||
} else {
|
||||
step = -1;
|
||||
start = ndim - 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < ndim; i++) {
|
||||
index = start + step * i;
|
||||
if (mvs.suboffsets[index] >= 0 || mvs.strides[index] != itemsize)
|
||||
return 0;
|
||||
|
||||
itemsize *= mvs.shape[index];
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/////////////// MemviewSliceIndex ///////////////
|
||||
|
||||
static CYTHON_INLINE char *
|
||||
__pyx_memviewslice_index_full(const char *bufp, Py_ssize_t idx,
|
||||
Py_ssize_t stride, Py_ssize_t suboffset)
|
||||
{
|
||||
bufp = bufp + idx * stride;
|
||||
if (suboffset >= 0) {
|
||||
bufp = *((char **) bufp) + suboffset;
|
||||
}
|
||||
return (char *) bufp;
|
||||
}
|
||||
|
||||
|
||||
/////////////// MemviewDtypeToObject.proto ///////////////
|
||||
|
||||
{{if to_py_function}}
|
||||
static CYTHON_INLINE PyObject *{{get_function}}(const char *itemp); /* proto */
|
||||
{{endif}}
|
||||
|
||||
{{if from_py_function}}
|
||||
static CYTHON_INLINE int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
|
||||
{{endif}}
|
||||
|
||||
/////////////// MemviewDtypeToObject ///////////////
|
||||
|
||||
{{#__pyx_memview_<dtype_name>_to_object}}
|
||||
|
||||
/* Convert a dtype to or from a Python object */
|
||||
|
||||
{{if to_py_function}}
|
||||
static CYTHON_INLINE PyObject *{{get_function}}(const char *itemp) {
|
||||
return (PyObject *) {{to_py_function}}(*({{dtype}} *) itemp);
|
||||
}
|
||||
{{endif}}
|
||||
|
||||
{{if from_py_function}}
|
||||
static CYTHON_INLINE int {{set_function}}(const char *itemp, PyObject *obj) {
|
||||
{{dtype}} value = {{from_py_function}}(obj);
|
||||
if ({{error_condition}})
|
||||
return 0;
|
||||
*({{dtype}} *) itemp = value;
|
||||
return 1;
|
||||
}
|
||||
{{endif}}
|
||||
|
||||
|
||||
/////////////// MemviewObjectToObject.proto ///////////////
|
||||
|
||||
/* Function callbacks (for memoryview object) for dtype object */
|
||||
static PyObject *{{get_function}}(const char *itemp); /* proto */
|
||||
static int {{set_function}}(const char *itemp, PyObject *obj); /* proto */
|
||||
|
||||
|
||||
/////////////// MemviewObjectToObject ///////////////
|
||||
|
||||
static PyObject *{{get_function}}(const char *itemp) {
|
||||
PyObject *result = *(PyObject **) itemp;
|
||||
Py_INCREF(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int {{set_function}}(const char *itemp, PyObject *obj) {
|
||||
Py_INCREF(obj);
|
||||
Py_DECREF(*(PyObject **) itemp);
|
||||
*(PyObject **) itemp = obj;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/////////// ToughSlice //////////
|
||||
|
||||
/* Dimension is indexed with 'start:stop:step' */
|
||||
|
||||
if (unlikely(__pyx_memoryview_slice_memviewslice(
|
||||
&{{dst}},
|
||||
{{src}}.shape[{{dim}}], {{src}}.strides[{{dim}}], {{src}}.suboffsets[{{dim}}],
|
||||
{{dim}},
|
||||
{{new_ndim}},
|
||||
&{{get_suboffset_dim()}},
|
||||
{{start}},
|
||||
{{stop}},
|
||||
{{step}},
|
||||
{{int(have_start)}},
|
||||
{{int(have_stop)}},
|
||||
{{int(have_step)}},
|
||||
1) < 0))
|
||||
{
|
||||
{{error_goto}}
|
||||
}
|
||||
|
||||
|
||||
////////// SimpleSlice //////////
|
||||
|
||||
/* Dimension is indexed with ':' only */
|
||||
|
||||
{{dst}}.shape[{{new_ndim}}] = {{src}}.shape[{{dim}}];
|
||||
{{dst}}.strides[{{new_ndim}}] = {{src}}.strides[{{dim}}];
|
||||
|
||||
{{if access == 'direct'}}
|
||||
{{dst}}.suboffsets[{{new_ndim}}] = -1;
|
||||
{{else}}
|
||||
{{dst}}.suboffsets[{{new_ndim}}] = {{src}}.suboffsets[{{dim}}];
|
||||
if ({{src}}.suboffsets[{{dim}}] >= 0)
|
||||
{{get_suboffset_dim()}} = {{new_ndim}};
|
||||
{{endif}}
|
||||
|
||||
|
||||
////////// SliceIndex //////////
|
||||
|
||||
// Dimension is indexed with an integer, we could use the ToughSlice
|
||||
// approach, but this is faster
|
||||
|
||||
{
|
||||
Py_ssize_t __pyx_tmp_idx = {{idx}};
|
||||
|
||||
{{if wraparound or boundscheck}}
|
||||
Py_ssize_t __pyx_tmp_shape = {{src}}.shape[{{dim}}];
|
||||
{{endif}}
|
||||
|
||||
Py_ssize_t __pyx_tmp_stride = {{src}}.strides[{{dim}}];
|
||||
{{if wraparound}}
|
||||
if (__pyx_tmp_idx < 0)
|
||||
__pyx_tmp_idx += __pyx_tmp_shape;
|
||||
{{endif}}
|
||||
|
||||
{{if boundscheck}}
|
||||
if (unlikely(!__Pyx_is_valid_index(__pyx_tmp_idx, __pyx_tmp_shape))) {
|
||||
{{if not have_gil}}
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
|
||||
#endif
|
||||
{{endif}}
|
||||
|
||||
PyErr_SetString(PyExc_IndexError,
|
||||
"Index out of bounds (axis {{dim}})");
|
||||
|
||||
{{if not have_gil}}
|
||||
#ifdef WITH_THREAD
|
||||
PyGILState_Release(__pyx_gilstate_save);
|
||||
#endif
|
||||
{{endif}}
|
||||
|
||||
{{error_goto}}
|
||||
}
|
||||
{{endif}}
|
||||
|
||||
{{if all_dimensions_direct}}
|
||||
{{dst}}.data += __pyx_tmp_idx * __pyx_tmp_stride;
|
||||
{{else}}
|
||||
if ({{get_suboffset_dim()}} < 0) {
|
||||
{{dst}}.data += __pyx_tmp_idx * __pyx_tmp_stride;
|
||||
|
||||
/* This dimension is the first dimension, or is preceded by */
|
||||
/* direct or indirect dimensions that are indexed away. */
|
||||
/* Hence suboffset_dim must be less than zero, and we can have */
|
||||
/* our data pointer refer to another block by dereferencing. */
|
||||
/* slice.data -> B -> C becomes slice.data -> C */
|
||||
|
||||
{{if indirect}}
|
||||
{
|
||||
Py_ssize_t __pyx_tmp_suboffset = {{src}}.suboffsets[{{dim}}];
|
||||
|
||||
{{if generic}}
|
||||
if (__pyx_tmp_suboffset >= 0)
|
||||
{{endif}}
|
||||
|
||||
{{dst}}.data = *((char **) {{dst}}.data) + __pyx_tmp_suboffset;
|
||||
}
|
||||
{{endif}}
|
||||
|
||||
} else {
|
||||
{{dst}}.suboffsets[{{get_suboffset_dim()}}] += __pyx_tmp_idx * __pyx_tmp_stride;
|
||||
|
||||
/* Note: dimension can not be indirect, the compiler will have */
|
||||
/* issued an error */
|
||||
}
|
||||
|
||||
{{endif}}
|
||||
}
|
||||
|
||||
|
||||
////////// FillStrided1DScalar.proto //////////
|
||||
|
||||
static void
|
||||
__pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
|
||||
size_t itemsize, void *itemp);
|
||||
|
||||
////////// FillStrided1DScalar //////////
|
||||
|
||||
/* Fill a slice with a scalar value. The dimension is direct and strided or contiguous */
|
||||
/* This can be used as a callback for the memoryview object to efficienty assign a scalar */
|
||||
/* Currently unused */
|
||||
static void
|
||||
__pyx_fill_slice_{{dtype_name}}({{type_decl}} *p, Py_ssize_t extent, Py_ssize_t stride,
|
||||
size_t itemsize, void *itemp)
|
||||
{
|
||||
Py_ssize_t i;
|
||||
{{type_decl}} item = *(({{type_decl}} *) itemp);
|
||||
{{type_decl}} *endp;
|
||||
|
||||
stride /= sizeof({{type_decl}});
|
||||
endp = p + stride * extent;
|
||||
|
||||
while (p < endp) {
|
||||
*p = item;
|
||||
p += stride;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
1195
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Optimize.c
Normal file
1195
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Optimize.c
Normal file
File diff suppressed because it is too large
Load diff
311
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Overflow.c
Normal file
311
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Overflow.c
Normal file
|
@ -0,0 +1,311 @@
|
|||
/*
|
||||
These functions provide integer arithmetic with integer checking. They do not
|
||||
actually raise an exception when an overflow is detected, but rather set a bit
|
||||
in the overflow parameter. (This parameter may be re-used across several
|
||||
arithmetic operations, so should be or-ed rather than assigned to.)
|
||||
|
||||
The implementation is divided into two parts, the signed and unsigned basecases,
|
||||
which is where the magic happens, and a generic template matching a specific
|
||||
type to an implementation based on its (c-compile-time) size and signedness.
|
||||
|
||||
When possible, branching is avoided, and preference is given to speed over
|
||||
accuracy (a low rate of falsely "detected" overflows are acceptable,
|
||||
undetected overflows are not).
|
||||
|
||||
|
||||
TODO: Hook up checking.
|
||||
TODO: Conditionally support 128-bit with intmax_t?
|
||||
*/
|
||||
|
||||
/////////////// Common.proto ///////////////
|
||||
|
||||
static int __Pyx_check_twos_complement(void) {
|
||||
if ((-1 != ~0)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Two's complement required for overflow checks.");
|
||||
return 1;
|
||||
} else if ((sizeof(short) == sizeof(int))) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "sizeof(short) < sizeof(int) required for overflow checks.");
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define __PYX_IS_UNSIGNED(type) ((((type) -1) > 0))
|
||||
#define __PYX_SIGN_BIT(type) ((((unsigned type) 1) << (sizeof(type) * 8 - 1)))
|
||||
#define __PYX_HALF_MAX(type) ((((type) 1) << (sizeof(type) * 8 - 2)))
|
||||
#define __PYX_MIN(type) ((__PYX_IS_UNSIGNED(type) ? (type) 0 : 0 - __PYX_HALF_MAX(type) - __PYX_HALF_MAX(type)))
|
||||
#define __PYX_MAX(type) ((~__PYX_MIN(type)))
|
||||
|
||||
#define __Pyx_add_no_overflow(a, b, overflow) ((a) + (b))
|
||||
#define __Pyx_add_const_no_overflow(a, b, overflow) ((a) + (b))
|
||||
#define __Pyx_sub_no_overflow(a, b, overflow) ((a) - (b))
|
||||
#define __Pyx_sub_const_no_overflow(a, b, overflow) ((a) - (b))
|
||||
#define __Pyx_mul_no_overflow(a, b, overflow) ((a) * (b))
|
||||
#define __Pyx_mul_const_no_overflow(a, b, overflow) ((a) * (b))
|
||||
#define __Pyx_div_no_overflow(a, b, overflow) ((a) / (b))
|
||||
#define __Pyx_div_const_no_overflow(a, b, overflow) ((a) / (b))
|
||||
|
||||
/////////////// Common.init ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
// FIXME: Propagate the error here instead of just printing it.
|
||||
if (unlikely(__Pyx_check_twos_complement())) {
|
||||
PyErr_WriteUnraisable($module_cname);
|
||||
}
|
||||
|
||||
/////////////// BaseCaseUnsigned.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_add_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_sub_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_div_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow);
|
||||
|
||||
// Use these when b is known at compile time.
|
||||
#define __Pyx_add_const_{{NAME}}_checking_overflow __Pyx_add_{{NAME}}_checking_overflow
|
||||
#define __Pyx_sub_const_{{NAME}}_checking_overflow __Pyx_sub_{{NAME}}_checking_overflow
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} constant, int *overflow);
|
||||
#define __Pyx_div_const_{{NAME}}_checking_overflow __Pyx_div_{{NAME}}_checking_overflow
|
||||
|
||||
/////////////// BaseCaseUnsigned ///////////////
|
||||
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_add_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) {
|
||||
{{UINT}} r = a + b;
|
||||
*overflow |= r < a;
|
||||
return r;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_sub_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) {
|
||||
{{UINT}} r = a - b;
|
||||
*overflow |= r > a;
|
||||
return r;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_mul_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) {
|
||||
if ((sizeof({{UINT}}) < sizeof(unsigned long))) {
|
||||
unsigned long big_r = ((unsigned long) a) * ((unsigned long) b);
|
||||
{{UINT}} r = ({{UINT}}) big_r;
|
||||
*overflow |= big_r != r;
|
||||
return r;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
} else if ((sizeof({{UINT}}) < sizeof(unsigned PY_LONG_LONG))) {
|
||||
unsigned PY_LONG_LONG big_r = ((unsigned PY_LONG_LONG) a) * ((unsigned PY_LONG_LONG) b);
|
||||
{{UINT}} r = ({{UINT}}) big_r;
|
||||
*overflow |= big_r != r;
|
||||
return r;
|
||||
#endif
|
||||
} else {
|
||||
{{UINT}} prod = a * b;
|
||||
double dprod = ((double) a) * ((double) b);
|
||||
// Overflow results in an error of at least 2^sizeof(UINT),
|
||||
// whereas rounding represents an error on the order of 2^(sizeof(UINT)-53).
|
||||
*overflow |= fabs(dprod - prod) > (__PYX_MAX({{UINT}}) / 2);
|
||||
return prod;
|
||||
}
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) {
|
||||
if (b > 1) {
|
||||
*overflow |= a > __PYX_MAX({{UINT}}) / b;
|
||||
}
|
||||
return a * b;
|
||||
}
|
||||
|
||||
|
||||
static CYTHON_INLINE {{UINT}} __Pyx_div_{{NAME}}_checking_overflow({{UINT}} a, {{UINT}} b, int *overflow) {
|
||||
if (b == 0) {
|
||||
*overflow |= 1;
|
||||
return 0;
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
|
||||
|
||||
/////////////// BaseCaseSigned.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{INT}} __Pyx_sub_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{INT}} __Pyx_div_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow);
|
||||
|
||||
|
||||
// Use when b is known at compile time.
|
||||
static CYTHON_INLINE {{INT}} __Pyx_add_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{INT}} __Pyx_sub_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow);
|
||||
static CYTHON_INLINE {{INT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} constant, int *overflow);
|
||||
#define __Pyx_div_const_{{NAME}}_checking_overflow __Pyx_div_{{NAME}}_checking_overflow
|
||||
|
||||
/////////////// BaseCaseSigned ///////////////
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_add_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
if ((sizeof({{INT}}) < sizeof(long))) {
|
||||
long big_r = ((long) a) + ((long) b);
|
||||
{{INT}} r = ({{INT}}) big_r;
|
||||
*overflow |= big_r != r;
|
||||
return r;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
} else if ((sizeof({{INT}}) < sizeof(PY_LONG_LONG))) {
|
||||
PY_LONG_LONG big_r = ((PY_LONG_LONG) a) + ((PY_LONG_LONG) b);
|
||||
{{INT}} r = ({{INT}}) big_r;
|
||||
*overflow |= big_r != r;
|
||||
return r;
|
||||
#endif
|
||||
} else {
|
||||
// Signed overflow undefined, but unsigned overflow is well defined.
|
||||
{{INT}} r = ({{INT}}) ((unsigned {{INT}}) a + (unsigned {{INT}}) b);
|
||||
// Overflow happened if the operands have the same sign, but the result
|
||||
// has opposite sign.
|
||||
// sign(a) == sign(b) != sign(r)
|
||||
{{INT}} sign_a = __PYX_SIGN_BIT({{INT}}) & a;
|
||||
{{INT}} sign_b = __PYX_SIGN_BIT({{INT}}) & b;
|
||||
{{INT}} sign_r = __PYX_SIGN_BIT({{INT}}) & r;
|
||||
*overflow |= (sign_a == sign_b) & (sign_a != sign_r);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_add_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
if (b > 0) {
|
||||
*overflow |= a > __PYX_MAX({{INT}}) - b;
|
||||
} else if (b < 0) {
|
||||
*overflow |= a < __PYX_MIN({{INT}}) - b;
|
||||
}
|
||||
return a + b;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_sub_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
*overflow |= b == __PYX_MIN({{INT}});
|
||||
return __Pyx_add_{{NAME}}_checking_overflow(a, -b, overflow);
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_sub_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
*overflow |= b == __PYX_MIN({{INT}});
|
||||
return __Pyx_add_const_{{NAME}}_checking_overflow(a, -b, overflow);
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_mul_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
if ((sizeof({{INT}}) < sizeof(long))) {
|
||||
long big_r = ((long) a) * ((long) b);
|
||||
{{INT}} r = ({{INT}}) big_r;
|
||||
*overflow |= big_r != r;
|
||||
return ({{INT}}) r;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
} else if ((sizeof({{INT}}) < sizeof(PY_LONG_LONG))) {
|
||||
PY_LONG_LONG big_r = ((PY_LONG_LONG) a) * ((PY_LONG_LONG) b);
|
||||
{{INT}} r = ({{INT}}) big_r;
|
||||
*overflow |= big_r != r;
|
||||
return ({{INT}}) r;
|
||||
#endif
|
||||
} else {
|
||||
{{INT}} prod = a * b;
|
||||
double dprod = ((double) a) * ((double) b);
|
||||
// Overflow results in an error of at least 2^sizeof(INT),
|
||||
// whereas rounding represents an error on the order of 2^(sizeof(INT)-53).
|
||||
*overflow |= fabs(dprod - prod) > (__PYX_MAX({{INT}}) / 2);
|
||||
return prod;
|
||||
}
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_mul_const_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
if (b > 1) {
|
||||
*overflow |= a > __PYX_MAX({{INT}}) / b;
|
||||
*overflow |= a < __PYX_MIN({{INT}}) / b;
|
||||
} else if (b == -1) {
|
||||
*overflow |= a == __PYX_MIN({{INT}});
|
||||
} else if (b < -1) {
|
||||
*overflow |= a > __PYX_MIN({{INT}}) / b;
|
||||
*overflow |= a < __PYX_MAX({{INT}}) / b;
|
||||
}
|
||||
return a * b;
|
||||
}
|
||||
|
||||
static CYTHON_INLINE {{INT}} __Pyx_div_{{NAME}}_checking_overflow({{INT}} a, {{INT}} b, int *overflow) {
|
||||
if (b == 0) {
|
||||
*overflow |= 1;
|
||||
return 0;
|
||||
}
|
||||
*overflow |= (a == __PYX_MIN({{INT}})) & (b == -1);
|
||||
return a / b;
|
||||
}
|
||||
|
||||
|
||||
/////////////// SizeCheck.init ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
// FIXME: Propagate the error here instead of just printing it.
|
||||
if (unlikely(__Pyx_check_sane_{{NAME}}())) {
|
||||
PyErr_WriteUnraisable($module_cname);
|
||||
}
|
||||
|
||||
/////////////// SizeCheck.proto ///////////////
|
||||
|
||||
static int __Pyx_check_sane_{{NAME}}(void) {
|
||||
if (((sizeof({{TYPE}}) <= sizeof(int)) ||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
(sizeof({{TYPE}}) == sizeof(PY_LONG_LONG)) ||
|
||||
#endif
|
||||
(sizeof({{TYPE}}) == sizeof(long)))) {
|
||||
return 0;
|
||||
} else {
|
||||
PyErr_Format(PyExc_RuntimeError, \
|
||||
"Bad size for int type %.{{max(60, len(TYPE))}}s: %d", "{{TYPE}}", (int) sizeof({{TYPE}}));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////// Binop.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}} a, {{TYPE}} b, int *overflow);
|
||||
|
||||
/////////////// Binop ///////////////
|
||||
|
||||
static CYTHON_INLINE {{TYPE}} __Pyx_{{BINOP}}_{{NAME}}_checking_overflow({{TYPE}} a, {{TYPE}} b, int *overflow) {
|
||||
if ((sizeof({{TYPE}}) < sizeof(int))) {
|
||||
return __Pyx_{{BINOP}}_no_overflow(a, b, overflow);
|
||||
} else if (__PYX_IS_UNSIGNED({{TYPE}})) {
|
||||
if ((sizeof({{TYPE}}) == sizeof(unsigned int))) {
|
||||
return ({{TYPE}}) __Pyx_{{BINOP}}_unsigned_int_checking_overflow(a, b, overflow);
|
||||
} else if ((sizeof({{TYPE}}) == sizeof(unsigned long))) {
|
||||
return ({{TYPE}}) __Pyx_{{BINOP}}_unsigned_long_checking_overflow(a, b, overflow);
|
||||
#ifdef HAVE_LONG_LONG
|
||||
} else if ((sizeof({{TYPE}}) == sizeof(unsigned PY_LONG_LONG))) {
|
||||
return ({{TYPE}}) __Pyx_{{BINOP}}_unsigned_long_long_checking_overflow(a, b, overflow);
|
||||
#endif
|
||||
} else {
|
||||
abort(); return 0; /* handled elsewhere */
|
||||
}
|
||||
} else {
|
||||
if ((sizeof({{TYPE}}) == sizeof(int))) {
|
||||
return ({{TYPE}}) __Pyx_{{BINOP}}_int_checking_overflow(a, b, overflow);
|
||||
} else if ((sizeof({{TYPE}}) == sizeof(long))) {
|
||||
return ({{TYPE}}) __Pyx_{{BINOP}}_long_checking_overflow(a, b, overflow);
|
||||
#ifdef HAVE_LONG_LONG
|
||||
} else if ((sizeof({{TYPE}}) == sizeof(PY_LONG_LONG))) {
|
||||
return ({{TYPE}}) __Pyx_{{BINOP}}_long_long_checking_overflow(a, b, overflow);
|
||||
#endif
|
||||
} else {
|
||||
abort(); return 0; /* handled elsewhere */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////// LeftShift.proto ///////////////
|
||||
|
||||
static CYTHON_INLINE {{TYPE}} __Pyx_lshift_{{NAME}}_checking_overflow({{TYPE}} a, {{TYPE}} b, int *overflow) {
|
||||
*overflow |=
|
||||
#if {{SIGNED}}
|
||||
(b < 0) |
|
||||
#endif
|
||||
(b > ({{TYPE}}) (8 * sizeof({{TYPE}}))) | (a > (__PYX_MAX({{TYPE}}) >> b));
|
||||
return a << b;
|
||||
}
|
||||
#define __Pyx_lshift_const_{{NAME}}_checking_overflow __Pyx_lshift_{{NAME}}_checking_overflow
|
||||
|
||||
|
||||
/////////////// UnaryNegOverflows.proto ///////////////
|
||||
|
||||
//FIXME: shouldn't the macro name be prefixed by "__Pyx_" ? Too late now, I guess...
|
||||
// from intobject.c
|
||||
#define UNARY_NEG_WOULD_OVERFLOW(x) \
|
||||
(((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))
|
176
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Printing.c
Normal file
176
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Printing.c
Normal file
|
@ -0,0 +1,176 @@
|
|||
////////////////////// Print.proto //////////////////////
|
||||
//@substitute: naming
|
||||
|
||||
static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
|
||||
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
|
||||
static PyObject* $print_function = 0;
|
||||
static PyObject* $print_function_kwargs = 0;
|
||||
#endif
|
||||
|
||||
////////////////////// Print.cleanup //////////////////////
|
||||
//@substitute: naming
|
||||
|
||||
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
|
||||
Py_CLEAR($print_function);
|
||||
Py_CLEAR($print_function_kwargs);
|
||||
#endif
|
||||
|
||||
////////////////////// Print //////////////////////
|
||||
//@substitute: naming
|
||||
|
||||
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
|
||||
static PyObject *__Pyx_GetStdout(void) {
|
||||
PyObject *f = PySys_GetObject((char *)"stdout");
|
||||
if (!f) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
|
||||
int i;
|
||||
|
||||
if (!f) {
|
||||
if (!(f = __Pyx_GetStdout()))
|
||||
return -1;
|
||||
}
|
||||
Py_INCREF(f);
|
||||
for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
|
||||
PyObject* v;
|
||||
if (PyFile_SoftSpace(f, 1)) {
|
||||
if (PyFile_WriteString(" ", f) < 0)
|
||||
goto error;
|
||||
}
|
||||
v = PyTuple_GET_ITEM(arg_tuple, i);
|
||||
if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
|
||||
goto error;
|
||||
if (PyString_Check(v)) {
|
||||
char *s = PyString_AsString(v);
|
||||
Py_ssize_t len = PyString_Size(v);
|
||||
if (len > 0) {
|
||||
// append soft-space if necessary (not using isspace() due to C/C++ problem on MacOS-X)
|
||||
switch (s[len-1]) {
|
||||
case ' ': break;
|
||||
case '\f': case '\r': case '\n': case '\t': case '\v':
|
||||
PyFile_SoftSpace(f, 0);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newline) {
|
||||
if (PyFile_WriteString("\n", f) < 0)
|
||||
goto error;
|
||||
PyFile_SoftSpace(f, 0);
|
||||
}
|
||||
Py_DECREF(f);
|
||||
return 0;
|
||||
error:
|
||||
Py_DECREF(f);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else /* Python 3 has a print function */
|
||||
|
||||
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
|
||||
PyObject* kwargs = 0;
|
||||
PyObject* result = 0;
|
||||
PyObject* end_string;
|
||||
if (unlikely(!$print_function)) {
|
||||
$print_function = PyObject_GetAttr($builtins_cname, PYIDENT("print"));
|
||||
if (!$print_function)
|
||||
return -1;
|
||||
}
|
||||
if (stream) {
|
||||
kwargs = PyDict_New();
|
||||
if (unlikely(!kwargs))
|
||||
return -1;
|
||||
if (unlikely(PyDict_SetItem(kwargs, PYIDENT("file"), stream) < 0))
|
||||
goto bad;
|
||||
if (!newline) {
|
||||
end_string = PyUnicode_FromStringAndSize(" ", 1);
|
||||
if (unlikely(!end_string))
|
||||
goto bad;
|
||||
if (PyDict_SetItem(kwargs, PYIDENT("end"), end_string) < 0) {
|
||||
Py_DECREF(end_string);
|
||||
goto bad;
|
||||
}
|
||||
Py_DECREF(end_string);
|
||||
}
|
||||
} else if (!newline) {
|
||||
if (unlikely(!$print_function_kwargs)) {
|
||||
$print_function_kwargs = PyDict_New();
|
||||
if (unlikely(!$print_function_kwargs))
|
||||
return -1;
|
||||
end_string = PyUnicode_FromStringAndSize(" ", 1);
|
||||
if (unlikely(!end_string))
|
||||
return -1;
|
||||
if (PyDict_SetItem($print_function_kwargs, PYIDENT("end"), end_string) < 0) {
|
||||
Py_DECREF(end_string);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(end_string);
|
||||
}
|
||||
kwargs = $print_function_kwargs;
|
||||
}
|
||||
result = PyObject_Call($print_function, arg_tuple, kwargs);
|
||||
if (unlikely(kwargs) && (kwargs != $print_function_kwargs))
|
||||
Py_DECREF(kwargs);
|
||||
if (!result)
|
||||
return -1;
|
||||
Py_DECREF(result);
|
||||
return 0;
|
||||
bad:
|
||||
if (kwargs != $print_function_kwargs)
|
||||
Py_XDECREF(kwargs);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////// PrintOne.proto //////////////////////
|
||||
//@requires: Print
|
||||
|
||||
static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/
|
||||
|
||||
////////////////////// PrintOne //////////////////////
|
||||
|
||||
#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
|
||||
|
||||
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
|
||||
if (!f) {
|
||||
if (!(f = __Pyx_GetStdout()))
|
||||
return -1;
|
||||
}
|
||||
Py_INCREF(f);
|
||||
if (PyFile_SoftSpace(f, 0)) {
|
||||
if (PyFile_WriteString(" ", f) < 0)
|
||||
goto error;
|
||||
}
|
||||
if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
|
||||
goto error;
|
||||
if (PyFile_WriteString("\n", f) < 0)
|
||||
goto error;
|
||||
Py_DECREF(f);
|
||||
return 0;
|
||||
error:
|
||||
Py_DECREF(f);
|
||||
return -1;
|
||||
/* the line below is just to avoid C compiler
|
||||
* warnings about unused functions */
|
||||
return __Pyx_Print(f, NULL, 0);
|
||||
}
|
||||
|
||||
#else /* Python 3 has a print function */
|
||||
|
||||
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
|
||||
int res;
|
||||
PyObject* arg_tuple = PyTuple_Pack(1, o);
|
||||
if (unlikely(!arg_tuple))
|
||||
return -1;
|
||||
res = __Pyx_Print(stream, arg_tuple, 1);
|
||||
Py_DECREF(arg_tuple);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
377
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Profile.c
Normal file
377
kivy_venv/lib/python3.11/site-packages/Cython/Utility/Profile.c
Normal file
|
@ -0,0 +1,377 @@
|
|||
/////////////// Profile.proto ///////////////
|
||||
//@requires: Exceptions.c::PyErrFetchRestore
|
||||
//@substitute: naming
|
||||
|
||||
// Note that cPython ignores PyTrace_EXCEPTION,
|
||||
// but maybe some other profilers don't.
|
||||
|
||||
#ifndef CYTHON_PROFILE
|
||||
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
|
||||
#define CYTHON_PROFILE 0
|
||||
#else
|
||||
#define CYTHON_PROFILE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CYTHON_TRACE_NOGIL
|
||||
#define CYTHON_TRACE_NOGIL 0
|
||||
#else
|
||||
#if CYTHON_TRACE_NOGIL && !defined(CYTHON_TRACE)
|
||||
#define CYTHON_TRACE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CYTHON_TRACE
|
||||
#define CYTHON_TRACE 0
|
||||
#endif
|
||||
|
||||
#if CYTHON_TRACE
|
||||
#undef CYTHON_PROFILE_REUSE_FRAME
|
||||
#endif
|
||||
|
||||
#ifndef CYTHON_PROFILE_REUSE_FRAME
|
||||
#define CYTHON_PROFILE_REUSE_FRAME 0
|
||||
#endif
|
||||
|
||||
#if CYTHON_PROFILE || CYTHON_TRACE
|
||||
|
||||
#include "compile.h"
|
||||
#include "frameobject.h"
|
||||
#include "traceback.h"
|
||||
#if PY_VERSION_HEX >= 0x030b00a6
|
||||
#ifndef Py_BUILD_CORE
|
||||
#define Py_BUILD_CORE 1
|
||||
#endif
|
||||
#include "internal/pycore_frame.h"
|
||||
#endif
|
||||
|
||||
#if CYTHON_PROFILE_REUSE_FRAME
|
||||
#define CYTHON_FRAME_MODIFIER static
|
||||
#define CYTHON_FRAME_DEL(frame)
|
||||
#else
|
||||
#define CYTHON_FRAME_MODIFIER
|
||||
#define CYTHON_FRAME_DEL(frame) Py_CLEAR(frame)
|
||||
#endif
|
||||
|
||||
#define __Pyx_TraceDeclarations \
|
||||
static PyCodeObject *$frame_code_cname = NULL; \
|
||||
CYTHON_FRAME_MODIFIER PyFrameObject *$frame_cname = NULL; \
|
||||
int __Pyx_use_tracing = 0;
|
||||
|
||||
#define __Pyx_TraceFrameInit(codeobj) \
|
||||
if (codeobj) $frame_code_cname = (PyCodeObject*) codeobj;
|
||||
|
||||
#if PY_VERSION_HEX >= 0x030b00a2
|
||||
#define __Pyx_IsTracing(tstate, check_tracing, check_funcs) \
|
||||
(unlikely((tstate)->cframe->use_tracing) && \
|
||||
(!(check_tracing) || !(tstate)->tracing) && \
|
||||
(!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
|
||||
|
||||
#define __Pyx_EnterTracing(tstate) PyThreadState_EnterTracing(tstate)
|
||||
|
||||
#define __Pyx_LeaveTracing(tstate) PyThreadState_LeaveTracing(tstate)
|
||||
|
||||
#elif PY_VERSION_HEX >= 0x030a00b1
|
||||
#define __Pyx_IsTracing(tstate, check_tracing, check_funcs) \
|
||||
(unlikely((tstate)->cframe->use_tracing) && \
|
||||
(!(check_tracing) || !(tstate)->tracing) && \
|
||||
(!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
|
||||
|
||||
#define __Pyx_EnterTracing(tstate) \
|
||||
do { tstate->tracing++; tstate->cframe->use_tracing = 0; } while (0)
|
||||
|
||||
#define __Pyx_LeaveTracing(tstate) \
|
||||
do { \
|
||||
tstate->tracing--; \
|
||||
tstate->cframe->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL) \
|
||||
|| tstate->c_profilefunc != NULL); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
#define __Pyx_IsTracing(tstate, check_tracing, check_funcs) \
|
||||
(unlikely((tstate)->use_tracing) && \
|
||||
(!(check_tracing) || !(tstate)->tracing) && \
|
||||
(!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
|
||||
|
||||
#define __Pyx_EnterTracing(tstate) \
|
||||
do { tstate->tracing++; tstate->use_tracing = 0; } while (0)
|
||||
|
||||
#define __Pyx_LeaveTracing(tstate) \
|
||||
do { \
|
||||
tstate->tracing--; \
|
||||
tstate->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL) \
|
||||
|| tstate->c_profilefunc != NULL); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
#define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \
|
||||
if (nogil) { \
|
||||
if (CYTHON_TRACE_NOGIL) { \
|
||||
PyThreadState *tstate; \
|
||||
PyGILState_STATE state = PyGILState_Ensure(); \
|
||||
tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 1, 1)) { \
|
||||
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
|
||||
} \
|
||||
PyGILState_Release(state); \
|
||||
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
|
||||
} \
|
||||
} else { \
|
||||
PyThreadState* tstate = PyThreadState_GET(); \
|
||||
if (__Pyx_IsTracing(tstate, 1, 1)) { \
|
||||
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
|
||||
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) \
|
||||
{ PyThreadState* tstate = PyThreadState_GET(); \
|
||||
if (__Pyx_IsTracing(tstate, 1, 1)) { \
|
||||
__Pyx_use_tracing = __Pyx_TraceSetupAndCall(&$frame_code_cname, &$frame_cname, tstate, funcname, srcfile, firstlineno); \
|
||||
if (unlikely(__Pyx_use_tracing < 0)) goto_error; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define __Pyx_TraceException() \
|
||||
if (likely(!__Pyx_use_tracing)); else { \
|
||||
PyThreadState* tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 1)) { \
|
||||
__Pyx_EnterTracing(tstate); \
|
||||
PyObject *exc_info = __Pyx_GetExceptionTuple(tstate); \
|
||||
if (exc_info) { \
|
||||
if (CYTHON_TRACE && tstate->c_tracefunc) \
|
||||
tstate->c_tracefunc( \
|
||||
tstate->c_traceobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
|
||||
tstate->c_profilefunc( \
|
||||
tstate->c_profileobj, $frame_cname, PyTrace_EXCEPTION, exc_info); \
|
||||
Py_DECREF(exc_info); \
|
||||
} \
|
||||
__Pyx_LeaveTracing(tstate); \
|
||||
} \
|
||||
}
|
||||
|
||||
static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
|
||||
PyObject *type, *value, *traceback;
|
||||
__Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
|
||||
__Pyx_EnterTracing(tstate);
|
||||
if (CYTHON_TRACE && tstate->c_tracefunc)
|
||||
tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result);
|
||||
if (tstate->c_profilefunc)
|
||||
tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result);
|
||||
CYTHON_FRAME_DEL(frame);
|
||||
__Pyx_LeaveTracing(tstate);
|
||||
__Pyx_ErrRestoreInState(tstate, type, value, traceback);
|
||||
}
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
#define __Pyx_TraceReturn(result, nogil) \
|
||||
if (likely(!__Pyx_use_tracing)); else { \
|
||||
if (nogil) { \
|
||||
if (CYTHON_TRACE_NOGIL) { \
|
||||
PyThreadState *tstate; \
|
||||
PyGILState_STATE state = PyGILState_Ensure(); \
|
||||
tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 0)) { \
|
||||
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
|
||||
} \
|
||||
PyGILState_Release(state); \
|
||||
} \
|
||||
} else { \
|
||||
PyThreadState* tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 0)) { \
|
||||
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define __Pyx_TraceReturn(result, nogil) \
|
||||
if (likely(!__Pyx_use_tracing)); else { \
|
||||
PyThreadState* tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 0)) { \
|
||||
__Pyx_call_return_trace_func(tstate, $frame_cname, (PyObject*)result); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno); /*proto*/
|
||||
static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno); /*proto*/
|
||||
|
||||
#else
|
||||
|
||||
#define __Pyx_TraceDeclarations
|
||||
#define __Pyx_TraceFrameInit(codeobj)
|
||||
// mark error label as used to avoid compiler warnings
|
||||
#define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) if ((1)); else goto_error;
|
||||
#define __Pyx_TraceException()
|
||||
#define __Pyx_TraceReturn(result, nogil)
|
||||
|
||||
#endif /* CYTHON_PROFILE */
|
||||
|
||||
#if CYTHON_TRACE
|
||||
// see call_trace_protected() in CPython's ceval.c
|
||||
static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) {
|
||||
int ret;
|
||||
PyObject *type, *value, *traceback;
|
||||
__Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
|
||||
__Pyx_PyFrame_SetLineNumber(frame, lineno);
|
||||
__Pyx_EnterTracing(tstate);
|
||||
|
||||
ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
|
||||
|
||||
__Pyx_LeaveTracing(tstate);
|
||||
if (likely(!ret)) {
|
||||
__Pyx_ErrRestoreInState(tstate, type, value, traceback);
|
||||
} else {
|
||||
Py_XDECREF(type);
|
||||
Py_XDECREF(value);
|
||||
Py_XDECREF(traceback);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
#define __Pyx_TraceLine(lineno, nogil, goto_error) \
|
||||
if (likely(!__Pyx_use_tracing)); else { \
|
||||
if (nogil) { \
|
||||
if (CYTHON_TRACE_NOGIL) { \
|
||||
int ret = 0; \
|
||||
PyThreadState *tstate; \
|
||||
PyGILState_STATE state = PyGILState_Ensure(); \
|
||||
tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \
|
||||
ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
|
||||
} \
|
||||
PyGILState_Release(state); \
|
||||
if (unlikely(ret)) goto_error; \
|
||||
} \
|
||||
} else { \
|
||||
PyThreadState* tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \
|
||||
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
|
||||
if (unlikely(ret)) goto_error; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define __Pyx_TraceLine(lineno, nogil, goto_error) \
|
||||
if (likely(!__Pyx_use_tracing)); else { \
|
||||
PyThreadState* tstate = __Pyx_PyThreadState_Current; \
|
||||
if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && $frame_cname->f_trace) { \
|
||||
int ret = __Pyx_call_line_trace_func(tstate, $frame_cname, lineno); \
|
||||
if (unlikely(ret)) goto_error; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
// mark error label as used to avoid compiler warnings
|
||||
#define __Pyx_TraceLine(lineno, nogil, goto_error) if ((1)); else goto_error;
|
||||
#endif
|
||||
|
||||
/////////////// Profile ///////////////
|
||||
//@substitute: naming
|
||||
|
||||
#if CYTHON_PROFILE
|
||||
|
||||
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
|
||||
PyFrameObject** frame,
|
||||
PyThreadState* tstate,
|
||||
const char *funcname,
|
||||
const char *srcfile,
|
||||
int firstlineno) {
|
||||
PyObject *type, *value, *traceback;
|
||||
int retval;
|
||||
if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
|
||||
if (*code == NULL) {
|
||||
*code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
|
||||
if (*code == NULL) return 0;
|
||||
}
|
||||
*frame = PyFrame_New(
|
||||
tstate, /*PyThreadState *tstate*/
|
||||
*code, /*PyCodeObject *code*/
|
||||
$moddict_cname, /*PyObject *globals*/
|
||||
0 /*PyObject *locals*/
|
||||
);
|
||||
if (*frame == NULL) return 0;
|
||||
if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
|
||||
// this enables "f_lineno" lookup, at least in CPython ...
|
||||
Py_INCREF(Py_None);
|
||||
(*frame)->f_trace = Py_None;
|
||||
}
|
||||
#if PY_VERSION_HEX < 0x030400B1
|
||||
} else {
|
||||
(*frame)->f_tstate = tstate;
|
||||
#endif
|
||||
}
|
||||
__Pyx_PyFrame_SetLineNumber(*frame, firstlineno);
|
||||
|
||||
retval = 1;
|
||||
__Pyx_EnterTracing(tstate);
|
||||
__Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
|
||||
|
||||
#if CYTHON_TRACE
|
||||
if (tstate->c_tracefunc)
|
||||
retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
|
||||
if (retval && tstate->c_profilefunc)
|
||||
#endif
|
||||
retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
|
||||
|
||||
__Pyx_LeaveTracing(tstate);
|
||||
if (retval) {
|
||||
__Pyx_ErrRestoreInState(tstate, type, value, traceback);
|
||||
return __Pyx_IsTracing(tstate, 0, 0) && retval;
|
||||
} else {
|
||||
Py_XDECREF(type);
|
||||
Py_XDECREF(value);
|
||||
Py_XDECREF(traceback);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
|
||||
PyCodeObject *py_code = 0;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
py_code = PyCode_NewEmpty(srcfile, funcname, firstlineno);
|
||||
// make CPython use a fresh dict for "f_locals" at need (see GH #1836)
|
||||
if (likely(py_code)) {
|
||||
py_code->co_flags |= CO_OPTIMIZED | CO_NEWLOCALS;
|
||||
}
|
||||
#else
|
||||
PyObject *py_srcfile = 0;
|
||||
PyObject *py_funcname = 0;
|
||||
|
||||
py_funcname = PyString_FromString(funcname);
|
||||
if (unlikely(!py_funcname)) goto bad;
|
||||
py_srcfile = PyString_FromString(srcfile);
|
||||
if (unlikely(!py_srcfile)) goto bad;
|
||||
|
||||
py_code = PyCode_New(
|
||||
0, /*int argcount,*/
|
||||
0, /*int nlocals,*/
|
||||
0, /*int stacksize,*/
|
||||
// make CPython use a fresh dict for "f_locals" at need (see GH #1836)
|
||||
CO_OPTIMIZED | CO_NEWLOCALS, /*int flags,*/
|
||||
$empty_bytes, /*PyObject *code,*/
|
||||
$empty_tuple, /*PyObject *consts,*/
|
||||
$empty_tuple, /*PyObject *names,*/
|
||||
$empty_tuple, /*PyObject *varnames,*/
|
||||
$empty_tuple, /*PyObject *freevars,*/
|
||||
$empty_tuple, /*PyObject *cellvars,*/
|
||||
py_srcfile, /*PyObject *filename,*/
|
||||
py_funcname, /*PyObject *name,*/
|
||||
firstlineno, /*int firstlineno,*/
|
||||
$empty_bytes /*PyObject *lnotab*/
|
||||
);
|
||||
|
||||
bad:
|
||||
Py_XDECREF(py_srcfile);
|
||||
Py_XDECREF(py_funcname);
|
||||
#endif
|
||||
|
||||
return py_code;
|
||||
}
|
||||
|
||||
#endif /* CYTHON_PROFILE */
|
1195
kivy_venv/lib/python3.11/site-packages/Cython/Utility/StringTools.c
Normal file
1195
kivy_venv/lib/python3.11/site-packages/Cython/Utility/StringTools.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,8 @@
|
|||
########## TestCyUtilityLoader ##########
|
||||
#@requires: OtherUtility
|
||||
|
||||
test {{cy_loader}} impl
|
||||
|
||||
|
||||
########## OtherUtility ##########
|
||||
req {{cy_loader}} impl
|
|
@ -0,0 +1,64 @@
|
|||
########## TestClass ##########
|
||||
# These utilities are for testing purposes
|
||||
|
||||
cdef extern from *:
|
||||
cdef object __pyx_test_dep(object)
|
||||
|
||||
@cname('__pyx_TestClass')
|
||||
cdef class TestClass(object):
|
||||
cdef public int value
|
||||
|
||||
def __init__(self, int value):
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return 'TestClass(%d)' % self.value
|
||||
|
||||
cdef cdef_method(self, int value):
|
||||
print 'Hello from cdef_method', value
|
||||
|
||||
cpdef cpdef_method(self, int value):
|
||||
print 'Hello from cpdef_method', value
|
||||
|
||||
def def_method(self, int value):
|
||||
print 'Hello from def_method', value
|
||||
|
||||
@cname('cdef_cname')
|
||||
cdef cdef_cname_method(self, int value):
|
||||
print "Hello from cdef_cname_method", value
|
||||
|
||||
@cname('cpdef_cname')
|
||||
cpdef cpdef_cname_method(self, int value):
|
||||
print "Hello from cpdef_cname_method", value
|
||||
|
||||
@cname('def_cname')
|
||||
def def_cname_method(self, int value):
|
||||
print "Hello from def_cname_method", value
|
||||
|
||||
@cname('__pyx_test_call_other_cy_util')
|
||||
cdef test_call(obj):
|
||||
print 'test_call'
|
||||
__pyx_test_dep(obj)
|
||||
|
||||
@cname('__pyx_TestClass_New')
|
||||
cdef _testclass_new(int value):
|
||||
return TestClass(value)
|
||||
|
||||
########### TestDep ##########
|
||||
|
||||
@cname('__pyx_test_dep')
|
||||
cdef test_dep(obj):
|
||||
print 'test_dep', obj
|
||||
|
||||
########## TestScope ##########
|
||||
|
||||
@cname('__pyx_testscope')
|
||||
cdef object _testscope(int value):
|
||||
return "hello from cython scope, value=%d" % value
|
||||
|
||||
########## View.TestScope ##########
|
||||
|
||||
@cname('__pyx_view_testscope')
|
||||
cdef object _testscope(int value):
|
||||
return "hello from cython.view scope, value=%d" % value
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
////////// TestUtilityLoader.proto //////////
|
||||
test {{loader}} prototype
|
||||
|
||||
////////// TestUtilityLoader //////////
|
||||
//@requires: OtherUtility
|
||||
test {{loader}} impl
|
||||
|
||||
////////// OtherUtility.proto //////////
|
||||
req {{loader}} proto
|
||||
|
||||
////////// OtherUtility //////////
|
||||
req {{loader}} impl
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,29 @@
|
|||
|
||||
def pylong_join(count, digits_ptr='digits', join_type='unsigned long'):
|
||||
"""
|
||||
Generate an unrolled shift-then-or loop over the first 'count' digits.
|
||||
Assumes that they fit into 'join_type'.
|
||||
|
||||
(((d[2] << n) | d[1]) << n) | d[0]
|
||||
"""
|
||||
return ('(' * (count * 2) + ' | '.join(
|
||||
"(%s)%s[%d])%s)" % (join_type, digits_ptr, _i, " << PyLong_SHIFT" if _i else '')
|
||||
for _i in range(count-1, -1, -1)))
|
||||
|
||||
|
||||
# although it could potentially make use of data independence,
|
||||
# this implementation is a bit slower than the simpler one above
|
||||
def _pylong_join(count, digits_ptr='digits', join_type='unsigned long'):
|
||||
"""
|
||||
Generate an or-ed series of shifts for the first 'count' digits.
|
||||
Assumes that they fit into 'join_type'.
|
||||
|
||||
(d[2] << 2*n) | (d[1] << 1*n) | d[0]
|
||||
"""
|
||||
def shift(n):
|
||||
# avoid compiler warnings for overly large shifts that will be discarded anyway
|
||||
return " << (%d * PyLong_SHIFT < 8 * sizeof(%s) ? %d * PyLong_SHIFT : 0)" % (n, join_type, n) if n else ''
|
||||
|
||||
return '(%s)' % ' | '.join(
|
||||
"(((%s)%s[%d])%s)" % (join_type, digits_ptr, i, shift(i))
|
||||
for i in range(count-1, -1, -1))
|
Binary file not shown.
|
@ -0,0 +1,149 @@
|
|||
/////////////// ArrayAPI.proto ///////////////
|
||||
|
||||
// arrayarray.h
|
||||
//
|
||||
// Artificial C-API for Python's <array.array> type,
|
||||
// used by array.pxd
|
||||
//
|
||||
// last changes: 2009-05-15 rk
|
||||
// 2012-05-02 andreasvc
|
||||
// (see revision control)
|
||||
//
|
||||
|
||||
#ifndef _ARRAYARRAY_H
|
||||
#define _ARRAYARRAY_H
|
||||
|
||||
// These two forward declarations are explicitly handled in the type
|
||||
// declaration code, as including them here is too late for cython-defined
|
||||
// types to use them.
|
||||
// struct arrayobject;
|
||||
// typedef struct arrayobject arrayobject;
|
||||
|
||||
// All possible arraydescr values are defined in the vector "descriptors"
|
||||
// below. That's defined later because the appropriate get and set
|
||||
// functions aren't visible yet.
|
||||
typedef struct arraydescr {
|
||||
int typecode;
|
||||
int itemsize;
|
||||
PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
|
||||
int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
char *formats;
|
||||
#endif
|
||||
} arraydescr;
|
||||
|
||||
|
||||
struct arrayobject {
|
||||
PyObject_HEAD
|
||||
Py_ssize_t ob_size;
|
||||
union {
|
||||
char *ob_item;
|
||||
float *as_floats;
|
||||
double *as_doubles;
|
||||
int *as_ints;
|
||||
unsigned int *as_uints;
|
||||
unsigned char *as_uchars;
|
||||
signed char *as_schars;
|
||||
char *as_chars;
|
||||
unsigned long *as_ulongs;
|
||||
long *as_longs;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
unsigned long long *as_ulonglongs;
|
||||
long long *as_longlongs;
|
||||
#endif
|
||||
short *as_shorts;
|
||||
unsigned short *as_ushorts;
|
||||
Py_UNICODE *as_pyunicodes;
|
||||
void *as_voidptr;
|
||||
} data;
|
||||
Py_ssize_t allocated;
|
||||
struct arraydescr *ob_descr;
|
||||
PyObject *weakreflist; /* List of weak references */
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
int ob_exports; /* Number of exported buffers */
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef NO_NEWARRAY_INLINE
|
||||
// fast creation of a new array
|
||||
static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t size,
|
||||
struct arraydescr *descr) {
|
||||
arrayobject *op;
|
||||
size_t nbytes;
|
||||
|
||||
if (size < 0) {
|
||||
PyErr_BadInternalCall();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nbytes = size * descr->itemsize;
|
||||
// Check for overflow
|
||||
if (nbytes / descr->itemsize != (size_t)size) {
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
op = (arrayobject *) type->tp_alloc(type, 0);
|
||||
if (op == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
op->ob_descr = descr;
|
||||
op->allocated = size;
|
||||
op->weakreflist = NULL;
|
||||
__Pyx_SET_SIZE(op, size);
|
||||
if (size <= 0) {
|
||||
op->data.ob_item = NULL;
|
||||
}
|
||||
else {
|
||||
op->data.ob_item = PyMem_NEW(char, nbytes);
|
||||
if (op->data.ob_item == NULL) {
|
||||
Py_DECREF(op);
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
}
|
||||
return (PyObject *) op;
|
||||
}
|
||||
#else
|
||||
PyObject* newarrayobject(PyTypeObject *type, Py_ssize_t size,
|
||||
struct arraydescr *descr);
|
||||
#endif /* ifndef NO_NEWARRAY_INLINE */
|
||||
|
||||
// fast resize (reallocation to the point)
|
||||
// not designed for filing small increments (but for fast opaque array apps)
|
||||
static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
|
||||
void *items = (void*) self->data.ob_item;
|
||||
PyMem_Resize(items, char, (size_t)(n * self->ob_descr->itemsize));
|
||||
if (items == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
}
|
||||
self->data.ob_item = (char*) items;
|
||||
__Pyx_SET_SIZE(self, n);
|
||||
self->allocated = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// suitable for small increments; over allocation 50% ;
|
||||
static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
|
||||
void *items = (void*) self->data.ob_item;
|
||||
Py_ssize_t newsize;
|
||||
if (n < self->allocated && n*4 > self->allocated) {
|
||||
__Pyx_SET_SIZE(self, n);
|
||||
return 0;
|
||||
}
|
||||
newsize = n + (n / 2) + 1;
|
||||
if (newsize <= n) { /* overflow */
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
}
|
||||
PyMem_Resize(items, char, (size_t)(newsize * self->ob_descr->itemsize));
|
||||
if (items == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
}
|
||||
self->data.ob_item = (char*) items;
|
||||
__Pyx_SET_SIZE(self, n);
|
||||
self->allocated = newsize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* _ARRAYARRAY_H */
|
Loading…
Add table
Add a link
Reference in a new issue