diff --git a/.gitignore b/.gitignore index bf6b116..5a2f9cf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /rtmidi_python.pyd /MANIFEST + +/.tox diff --git a/rtmidi_python.cpp b/rtmidi_python.cpp index 5792036..108eead 100644 --- a/rtmidi_python.cpp +++ b/rtmidi_python.cpp @@ -1,26 +1,14 @@ -/* Generated by Cython 0.20 on Wed Jan 22 22:57:24 2014 */ +/* Generated by Cython 0.23.4 */ #define PY_SSIZE_T_CLEAN -#ifndef CYTHON_USE_PYLONG_INTERNALS -#ifdef PYLONG_BITS_IN_DIGIT -#define CYTHON_USE_PYLONG_INTERNALS 0 -#else -#include "pyconfig.h" -#ifdef PYLONG_BITS_IN_DIGIT -#define CYTHON_USE_PYLONG_INTERNALS 1 -#else -#define CYTHON_USE_PYLONG_INTERNALS 0 -#endif -#endif -#endif #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02040000 - #error Cython requires Python 2.4+. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) + #error Cython requires Python 2.6+ or Python 3.2+. #else -#define CYTHON_ABI "0_20" -#include /* For offsetof */ +#define CYTHON_ABI "0_23_4" +#include #ifndef offsetof #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif @@ -54,98 +42,40 @@ #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_CPYTHON 1 #endif -#if CYTHON_COMPILING_IN_PYPY -#define Py_OptimizeFlag 0 -#endif -#if PY_VERSION_HEX < 0x02050000 - typedef int Py_ssize_t; - #define PY_SSIZE_T_MAX INT_MAX - #define PY_SSIZE_T_MIN INT_MIN - #define PY_FORMAT_SIZE_T "" - #define CYTHON_FORMAT_SSIZE_T "" - #define PyInt_FromSsize_t(z) PyInt_FromLong(z) - #define PyInt_AsSsize_t(o) __Pyx_PyInt_As_int(o) - #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \ - (PyErr_Format(PyExc_TypeError, \ - "expected index value, got %.200s", Py_TYPE(o)->tp_name), \ - (PyObject*)0)) - #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \ - !PyComplex_Check(o)) - #define PyIndex_Check __Pyx_PyIndex_Check - #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message) - #define __PYX_BUILD_PY_SSIZE_T "i" -#else - #define __PYX_BUILD_PY_SSIZE_T "n" - #define CYTHON_FORMAT_SSIZE_T "z" - #define __Pyx_PyIndex_Check PyIndex_Check +#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000 +#define CYTHON_USE_PYLONG_INTERNALS 1 #endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) - #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) - #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) - #define PyVarObject_HEAD_INIT(type, size) \ - PyObject_HEAD_INIT(type) size, - #define PyType_Modified(t) - typedef struct { - void *buf; - PyObject *obj; - Py_ssize_t len; - Py_ssize_t itemsize; - int readonly; - int ndim; - char *format; - Py_ssize_t *shape; - Py_ssize_t *strides; - Py_ssize_t *suboffsets; - void *internal; - } Py_buffer; - #define PyBUF_SIMPLE 0 - #define PyBUF_WRITABLE 0x0001 - #define PyBUF_FORMAT 0x0004 - #define PyBUF_ND 0x0008 - #define PyBUF_STRIDES (0x0010 | PyBUF_ND) - #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES) - #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES) - #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES) - #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES) - #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE) - #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE) - typedef int (*getbufferproc)(PyObject *, Py_buffer *, int); - typedef void (*releasebufferproc)(PyObject *, Py_buffer *); +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) +#define Py_OptimizeFlag 0 #endif +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" #if PY_MAJOR_VERSION < 3 #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ - PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" - #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \ + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) #define __Pyx_DefaultClassType PyType_Type #endif -#if PY_VERSION_HEX < 0x02060000 - #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict") -#endif -#if PY_MAJOR_VERSION >= 3 +#ifndef Py_TPFLAGS_CHECKTYPES #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX #define Py_TPFLAGS_HAVE_INDEX 0 #endif -#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3) +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER #define Py_TPFLAGS_HAVE_NEWBUFFER 0 #endif -#if PY_VERSION_HEX < 0x02060000 - #define Py_TPFLAGS_HAVE_VERSION_TAG 0 -#endif -#if PY_VERSION_HEX < 0x02060000 && !defined(Py_TPFLAGS_IS_ABSTRACT) - #define Py_TPFLAGS_IS_ABSTRACT 0 -#endif -#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE) +#ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 - #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \ + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) @@ -161,10 +91,19 @@ #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) #endif -#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) -#define __Pyx_PyUnicode_Concat(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \ - PyNumber_Add(a, b) : PyUnicode_Concat(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else @@ -177,36 +116,13 @@ #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact #endif -#if PY_VERSION_HEX < 0x02060000 - #define PyBytesObject PyStringObject - #define PyBytes_Type PyString_Type - #define PyBytes_Check PyString_Check - #define PyBytes_CheckExact PyString_CheckExact - #define PyBytes_FromString PyString_FromString - #define PyBytes_FromStringAndSize PyString_FromStringAndSize - #define PyBytes_FromFormat PyString_FromFormat - #define PyBytes_DecodeEscape PyString_DecodeEscape - #define PyBytes_AsString PyString_AsString - #define PyBytes_AsStringAndSize PyString_AsStringAndSize - #define PyBytes_Size PyString_Size - #define PyBytes_AS_STRING PyString_AS_STRING - #define PyBytes_GET_SIZE PyString_GET_SIZE - #define PyBytes_Repr PyString_Repr - #define PyBytes_Concat PyString_Concat - #define PyBytes_ConcatAndDel PyString_ConcatAndDel -#endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) #else - #define __Pyx_PyBaseString_Check(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj) || \ - PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) #endif -#if PY_VERSION_HEX < 0x02060000 - #define PySet_Check(obj) PyObject_TypeCheck(obj, &PySet_Type) - #define PyFrozenSet_Check(obj) PyObject_TypeCheck(obj, &PyFrozenSet_Type) -#endif #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif @@ -231,7 +147,12 @@ #if PY_MAJOR_VERSION >= 3 #define PyBoolObject PyLongObject #endif -#if PY_VERSION_HEX < 0x03020000 +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong #define __Pyx_PyInt_AsHash_t PyInt_AsLong @@ -239,53 +160,23 @@ #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif -#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300) - #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value) - #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b) -#else - #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0))) - #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1))) - #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \ - (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \ - (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \ - (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1))) -#endif #if PY_MAJOR_VERSION >= 3 - #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) -#endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),((char *)(n))) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),((char *)(n))) + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #else - #define __Pyx_GetAttrString(o,n) PyObject_GetAttrString((o),(n)) - #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a)) - #define __Pyx_DelAttrString(o,n) PyObject_DelAttrString((o),(n)) + #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif -#if PY_VERSION_HEX < 0x02050000 - #define __Pyx_NAMESTR(n) ((char *)(n)) - #define __Pyx_DOCSTR(n) ((char *)(n)) +#if PY_VERSION_HEX >= 0x030500B1 +#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods +#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) +#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 +typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; +} __Pyx_PyAsyncMethodsStruct; +#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #else - #define __Pyx_NAMESTR(n) (n) - #define __Pyx_DOCSTR(n) (n) -#endif -#ifndef CYTHON_INLINE - #if defined(__GNUC__) - #define CYTHON_INLINE __inline__ - #elif defined(_MSC_VER) - #define CYTHON_INLINE __inline - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_INLINE inline - #else - #define CYTHON_INLINE - #endif +#define __Pyx_PyType_AsAsync(obj) NULL #endif #ifndef CYTHON_RESTRICT #if defined(__GNUC__) @@ -298,13 +189,37 @@ #define CYTHON_RESTRICT #endif #endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) + +#ifndef __cplusplus + #error "Cython files generated with the C++ option must be compiled with a C++ compiler." +#endif +#ifndef CYTHON_INLINE + #define CYTHON_INLINE inline +#endif +template +void __Pyx_call_destructor(T& x) { + x.~T(); +} +template +class __Pyx_FakeReference { + public: + __Pyx_FakeReference() : ptr(NULL) { } + __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } + T *operator->() { return ptr; } + operator T&() { return *ptr; } + private: + T *ptr; +}; + +#if defined(WIN32) || defined(MS_WINDOWS) + #define _USE_MATH_DEFINES +#endif +#include #ifdef NAN #define __PYX_NAN() ((float) NAN) #else static CYTHON_INLINE float __PYX_NAN() { - /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and - a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is - a quiet NaN. */ float value; memset(&value, 0xFF, sizeof(value)); return value; @@ -328,10 +243,6 @@ static CYTHON_INLINE float __PYX_NAN() { #endif #endif -#if defined(WIN32) || defined(MS_WINDOWS) -#define _USE_MATH_DEFINES -#endif -#include #define __PYX_HAVE__rtmidi_python #define __PYX_HAVE_API__rtmidi_python #include "string.h" @@ -363,31 +274,56 @@ static CYTHON_INLINE float __PYX_NAN() { # define CYTHON_UNUSED # endif #endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; - const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/ + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize -#define __Pyx_fits_Py_ssize_t(v, type, is_signed) ( \ - (sizeof(type) < sizeof(Py_ssize_t)) || \ - (sizeof(type) > sizeof(Py_ssize_t) && \ - likely(v < (type)PY_SSIZE_T_MAX || \ - v == (type)PY_SSIZE_T_MAX) && \ - (!is_signed || likely(v > (type)PY_SSIZE_T_MIN || \ - v == (type)PY_SSIZE_T_MIN))) || \ - (sizeof(type) == sizeof(Py_ssize_t) && \ - (is_signed || likely(v < (type)PY_SSIZE_T_MAX || \ +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) && defined (_M_X64) + #define __Pyx_sst_abs(value) _abs64(value) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #if PY_MAJOR_VERSION < 3 #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize @@ -397,17 +333,17 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); #endif #define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) -#define __Pyx_PyObject_FromUString(s) __Pyx_PyObject_FromString((char*)s) -#define __Pyx_PyBytes_FromUString(s) __Pyx_PyBytes_FromString((char*)s) -#define __Pyx_PyByteArray_FromUString(s) __Pyx_PyByteArray_FromString((char*)s) -#define __Pyx_PyStr_FromUString(s) __Pyx_PyStr_FromString((char*)s) -#define __Pyx_PyUnicode_FromUString(s) __Pyx_PyUnicode_FromString((char*)s) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) #if PY_MAJOR_VERSION < 3 static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; - return u_end - u - 1; + return (size_t)(u_end - u - 1); } #else #define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen @@ -415,8 +351,9 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode -#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False)) static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); @@ -430,18 +367,21 @@ static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { - PyObject* sys = NULL; + PyObject* sys; PyObject* default_encoding = NULL; PyObject* ascii_chars_u = NULL; PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; sys = PyImport_ImportModule("sys"); - if (sys == NULL) goto bad; - default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); - if (default_encoding == NULL) goto bad; - if (strcmp(PyBytes_AsString(default_encoding), "ascii") == 0) { + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { __Pyx_sys_getdefaultencoding_not_ascii = 0; } else { - const char* default_encoding_c = PyBytes_AS_STRING(default_encoding); char ascii_chars[128]; int c; for (c = 0; c < 128; c++) { @@ -449,23 +389,21 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) { } __Pyx_sys_getdefaultencoding_not_ascii = 1; ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); - if (ascii_chars_u == NULL) goto bad; + if (!ascii_chars_u) goto bad; ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); - if (ascii_chars_b == NULL || strncmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { PyErr_Format( PyExc_ValueError, "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", default_encoding_c); goto bad; } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); } - Py_XDECREF(sys); - Py_XDECREF(default_encoding); - Py_XDECREF(ascii_chars_u); - Py_XDECREF(ascii_chars_b); + Py_DECREF(default_encoding); return 0; bad: - Py_XDECREF(sys); Py_XDECREF(default_encoding); Py_XDECREF(ascii_chars_u); Py_XDECREF(ascii_chars_b); @@ -479,21 +417,22 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) { #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT static char* __PYX_DEFAULT_STRING_ENCODING; static int __Pyx_init_sys_getdefaultencoding_params(void) { - PyObject* sys = NULL; + PyObject* sys; PyObject* default_encoding = NULL; char* default_encoding_c; sys = PyImport_ImportModule("sys"); - if (sys == NULL) goto bad; + if (!sys) goto bad; default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); - if (default_encoding == NULL) goto bad; - default_encoding_c = PyBytes_AS_STRING(default_encoding); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); - Py_DECREF(sys); Py_DECREF(default_encoding); return 0; bad: - Py_XDECREF(sys); Py_XDECREF(default_encoding); return -1; } @@ -501,16 +440,11 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) { #endif -#ifdef __GNUC__ - /* Test for GCC > 2.95 */ - #if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) - #define likely(x) __builtin_expect(!!(x), 1) - #define unlikely(x) __builtin_expect(!!(x), 0) - #else /* __GNUC__ > 2 ... */ - #define likely(x) (x) - #define unlikely(x) (x) - #endif /* __GNUC__ > 2 ... */ -#else /* __GNUC__ */ +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ @@ -529,15 +463,14 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "rtmidi_python.pyx", "stringsource", - "stringsource", }; /*--- Type declarations ---*/ struct __pyx_obj_13rtmidi_python_MidiBase; -struct __pyx_obj_13rtmidi_python_MidiOut; struct __pyx_obj_13rtmidi_python_MidiIn; +struct __pyx_obj_13rtmidi_python_MidiOut; -/* "rtmidi_python.pyx":40 +/* "rtmidi_python.pyx":41 * * * cdef class MidiBase: # <<<<<<<<<<<<<< @@ -550,35 +483,35 @@ struct __pyx_obj_13rtmidi_python_MidiBase { }; -/* "rtmidi_python.pyx":107 - * +/* "rtmidi_python.pyx":74 * - * cdef class MidiOut(MidiBase): # <<<<<<<<<<<<<< - * cdef RtMidiOut* thisptr * + * cdef class MidiIn(MidiBase): # <<<<<<<<<<<<<< + * cdef RtMidiIn* thisptr + * cdef object py_callback */ -struct __pyx_obj_13rtmidi_python_MidiOut { +struct __pyx_obj_13rtmidi_python_MidiIn { struct __pyx_obj_13rtmidi_python_MidiBase __pyx_base; - RtMidiOut *thisptr; + RtMidiIn *thisptr; + PyObject *py_callback; }; -/* "rtmidi_python.pyx":67 +/* "rtmidi_python.pyx":117 * * - * cdef class MidiIn(MidiBase): # <<<<<<<<<<<<<< - * cdef RtMidiIn* thisptr - * cdef object py_callback + * cdef class MidiOut(MidiBase): # <<<<<<<<<<<<<< + * cdef RtMidiOut* thisptr + * */ -struct __pyx_obj_13rtmidi_python_MidiIn { +struct __pyx_obj_13rtmidi_python_MidiOut { struct __pyx_obj_13rtmidi_python_MidiBase __pyx_base; - RtMidiIn *thisptr; - PyObject *py_callback; + RtMidiOut *thisptr; }; -/* "rtmidi_python.pyx":40 +/* "rtmidi_python.pyx":41 * * * cdef class MidiBase: # <<<<<<<<<<<<<< @@ -592,7 +525,7 @@ struct __pyx_vtabstruct_13rtmidi_python_MidiBase { static struct __pyx_vtabstruct_13rtmidi_python_MidiBase *__pyx_vtabptr_13rtmidi_python_MidiBase; -/* "rtmidi_python.pyx":67 +/* "rtmidi_python.pyx":74 * * * cdef class MidiIn(MidiBase): # <<<<<<<<<<<<<< @@ -606,7 +539,7 @@ struct __pyx_vtabstruct_13rtmidi_python_MidiIn { static struct __pyx_vtabstruct_13rtmidi_python_MidiIn *__pyx_vtabptr_13rtmidi_python_MidiIn; -/* "rtmidi_python.pyx":107 +/* "rtmidi_python.pyx":117 * * * cdef class MidiOut(MidiBase): # <<<<<<<<<<<<<< @@ -618,6 +551,8 @@ struct __pyx_vtabstruct_13rtmidi_python_MidiOut { struct __pyx_vtabstruct_13rtmidi_python_MidiBase __pyx_base; }; static struct __pyx_vtabstruct_13rtmidi_python_MidiOut *__pyx_vtabptr_13rtmidi_python_MidiOut; + +/* --- Runtime support code (head) --- */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -631,22 +566,22 @@ static struct __pyx_vtabstruct_13rtmidi_python_MidiOut *__pyx_vtabptr_13rtmidi_p void (*FinishContext)(void**); } __Pyx_RefNannyAPIStruct; static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; - static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/ + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; #ifdef WITH_THREAD - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ - if (acquire_gil) { \ - PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ - PyGILState_Release(__pyx_gilstate_save); \ - } else { \ - __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \ + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\ } #else - #define __Pyx_RefNannySetupContext(name, acquire_gil) \ + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #endif - #define __Pyx_RefNannyFinishContext() \ + #define __Pyx_RefNannyFinishContext()\ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__) @@ -668,14 +603,14 @@ static struct __pyx_vtabstruct_13rtmidi_python_MidiOut *__pyx_vtabptr_13rtmidi_p #define __Pyx_XDECREF(r) Py_XDECREF(r) #define __Pyx_XGOTREF(r) #define __Pyx_XGIVEREF(r) -#endif /* CYTHON_REFNANNY */ -#define __Pyx_XDECREF_SET(r, v) do { \ - PyObject *tmp = (PyObject *) r; \ - r = v; __Pyx_XDECREF(tmp); \ +#endif +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ } while (0) -#define __Pyx_DECREF_SET(r, v) do { \ - PyObject *tmp = (PyObject *) r; \ - r = v; __Pyx_DECREF(tmp); \ +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ } while (0) #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) @@ -695,16 +630,28 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif -static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ - const char* function_name); /*proto*/ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ + const char* function_name); 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*/ + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { @@ -726,18 +673,35 @@ static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) { #define __PYX_FORCE_INIT_THREADS 0 #endif -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ +static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); static void __Pyx_WriteUnraisable(const char *name, int clineno, int lineno, const char *filename, - int full_traceback); /*proto*/ + int full_traceback, int nogil); static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse); static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_dealloc); -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); + +typedef struct { + int code_line; + PyCodeObject* code_object; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); + +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *); @@ -796,25 +760,13 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); static int __Pyx_check_binary_version(void); -typedef struct { - int code_line; - PyCodeObject* code_object; -} __Pyx_CodeObjectCacheEntry; -struct __Pyx_CodeObjectCache { - int count; - int max_count; - __Pyx_CodeObjectCacheEntry* entries; -}; -static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); -static PyCodeObject *__pyx_find_code_object(int code_line); -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); - -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename); /*proto*/ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ +static RtMidi *__pyx_f_13rtmidi_python_8MidiBase_baseptr(CYTHON_UNUSED struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self); /* proto*/ +static RtMidi *__pyx_f_13rtmidi_python_6MidiIn_baseptr(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto*/ +static RtMidi *__pyx_f_13rtmidi_python_7MidiOut_baseptr(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self); /* proto*/ +/* Module declarations from 'cpython.version' */ /* Module declarations from 'libc.string' */ @@ -824,39 +776,27 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'rtmidi_python' */ static PyTypeObject *__pyx_ptype_13rtmidi_python_MidiBase = 0; -static PyTypeObject *__pyx_ptype_13rtmidi_python_MidiOut = 0; static PyTypeObject *__pyx_ptype_13rtmidi_python_MidiIn = 0; -static void __pyx_f_13rtmidi_python_midi_in_callback(double, std::vector *, void *); /*proto*/ -static PyObject *__pyx_convert_vector_to_py_unsigned_char(const std::vector &); /*proto*/ -static std::vector __pyx_convert_vector_from_py_unsigned_char(PyObject *); /*proto*/ +static PyTypeObject *__pyx_ptype_13rtmidi_python_MidiOut = 0; +static void __pyx_f_13rtmidi_python_midi_in_callback(double, std::vector *, void *); /*proto*/ +static std::string __pyx_convert_string_from_py_std__in_string(PyObject *); /*proto*/ +static PyObject *__pyx_convert_vector_to_py_unsigned_char(const std::vector &); /*proto*/ +static std::vector __pyx_convert_vector_from_py_unsigned_char(PyObject *); /*proto*/ #define __Pyx_MODULE_NAME "rtmidi_python" int __pyx_module_is_main_rtmidi_python = 0; /* Implementation of 'rtmidi_python' */ static PyObject *__pyx_builtin_range; -static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_open_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self, PyObject *__pyx_v_port); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_2open_virtual_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self, PyObject *__pyx_v_port_name); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_5ports___get__(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_4close_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self); /* proto */ -static int __pyx_pf_13rtmidi_python_6MidiIn___cinit__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_client_name, PyObject *__pyx_v_queue_size_limit); /* proto */ -static void __pyx_pf_13rtmidi_python_6MidiIn_2__dealloc__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_8callback___get__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto */ -static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_callback); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_4ignore_types(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_midi_sysex, PyObject *__pyx_v_midi_time, PyObject *__pyx_v_midi_sense); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto */ -static int __pyx_pf_13rtmidi_python_7MidiOut___cinit__(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self, PyObject *__pyx_v_client_name); /* proto */ -static void __pyx_pf_13rtmidi_python_7MidiOut_2__dealloc__(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_13rtmidi_python_7MidiOut_4send_message(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self, PyObject *__pyx_v_message); /* proto */ -static PyObject *__pyx_tp_new_13rtmidi_python_MidiBase(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_13rtmidi_python_MidiOut(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_13rtmidi_python_MidiIn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static char __pyx_k_main[] = "__main__"; static char __pyx_k_port[] = "port"; static char __pyx_k_test[] = "__test__"; +static char __pyx_k_UTF_8[] = "UTF-8"; static char __pyx_k_index[] = "index"; static char __pyx_k_ports[] = "ports"; static char __pyx_k_range[] = "range"; static char __pyx_k_RtMidi[] = "RtMidi"; +static char __pyx_k_decode[] = "decode"; +static char __pyx_k_encode[] = "encode"; static char __pyx_k_midi_time[] = "midi_time"; static char __pyx_k_port_name[] = "port_name"; static char __pyx_k_midi_sense[] = "midi_sense"; @@ -869,7 +809,10 @@ static char __pyx_k_RtMidi_Output_Client[] = "RtMidi Output Client"; static PyObject *__pyx_n_s_RtMidi; static PyObject *__pyx_kp_s_RtMidi_Input_Client; static PyObject *__pyx_kp_s_RtMidi_Output_Client; +static PyObject *__pyx_kp_s_UTF_8; static PyObject *__pyx_n_s_client_name; +static PyObject *__pyx_n_s_decode; +static PyObject *__pyx_n_s_encode; static PyObject *__pyx_n_s_index; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_midi_sense; @@ -882,11 +825,31 @@ static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_queue_size_limit; static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_test; +static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_open_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self, PyObject *__pyx_v_port); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_2open_virtual_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self, PyObject *__pyx_v_port_name); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_5ports___get__(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_4close_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self); /* proto */ +static int __pyx_pf_13rtmidi_python_6MidiIn___cinit__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_client_name, PyObject *__pyx_v_queue_size_limit); /* proto */ +static void __pyx_pf_13rtmidi_python_6MidiIn_2__dealloc__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_8callback___get__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto */ +static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_callback); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_4ignore_types(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_midi_sysex, PyObject *__pyx_v_midi_time, PyObject *__pyx_v_midi_sense); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self); /* proto */ +static int __pyx_pf_13rtmidi_python_7MidiOut___cinit__(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self, PyObject *__pyx_v_client_name); /* proto */ +static void __pyx_pf_13rtmidi_python_7MidiOut_2__dealloc__(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_13rtmidi_python_7MidiOut_4send_message(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self, PyObject *__pyx_v_message); /* proto */ +static PyObject *__pyx_tp_new_13rtmidi_python_MidiBase(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_13rtmidi_python_MidiIn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_13rtmidi_python_MidiOut(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_0; static PyObject *__pyx_int_100; static PyObject *__pyx_tuple_; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; -/* "rtmidi_python.pyx":41 +/* "rtmidi_python.pyx":42 * * cdef class MidiBase: * cdef RtMidi* baseptr(self): # <<<<<<<<<<<<<< @@ -899,7 +862,7 @@ static RtMidi *__pyx_f_13rtmidi_python_8MidiBase_baseptr(CYTHON_UNUSED struct __ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("baseptr", 0); - /* "rtmidi_python.pyx":42 + /* "rtmidi_python.pyx":43 * cdef class MidiBase: * cdef RtMidi* baseptr(self): * return NULL # <<<<<<<<<<<<<< @@ -909,7 +872,7 @@ static RtMidi *__pyx_f_13rtmidi_python_8MidiBase_baseptr(CYTHON_UNUSED struct __ __pyx_r = NULL; goto __pyx_L0; - /* "rtmidi_python.pyx":41 + /* "rtmidi_python.pyx":42 * * cdef class MidiBase: * cdef RtMidi* baseptr(self): # <<<<<<<<<<<<<< @@ -923,7 +886,7 @@ static RtMidi *__pyx_f_13rtmidi_python_8MidiBase_baseptr(CYTHON_UNUSED struct __ return __pyx_r; } -/* "rtmidi_python.pyx":44 +/* "rtmidi_python.pyx":45 * return NULL * * def open_port(self, port=0): # <<<<<<<<<<<<<< @@ -962,7 +925,7 @@ static PyObject *__pyx_pw_13rtmidi_python_8MidiBase_1open_port(PyObject *__pyx_v } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "open_port") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "open_port") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -975,7 +938,7 @@ static PyObject *__pyx_pw_13rtmidi_python_8MidiBase_1open_port(PyObject *__pyx_v } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("open_port", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("open_port", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("rtmidi_python.MidiBase.open_port", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -990,6 +953,7 @@ static PyObject *__pyx_pw_13rtmidi_python_8MidiBase_1open_port(PyObject *__pyx_v static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_open_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self, PyObject *__pyx_v_port) { PyObject *__pyx_v_port_number = NULL; + PyObject *__pyx_v_x = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -997,13 +961,17 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_open_port(struct __pyx_obj_1 PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; - unsigned int __pyx_t_6; + PyObject *__pyx_t_6 = NULL; + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9 = NULL; + unsigned int __pyx_t_10; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("open_port", 0); - /* "rtmidi_python.pyx":45 + /* "rtmidi_python.pyx":46 * * def open_port(self, port=0): * if isinstance(port, int): # <<<<<<<<<<<<<< @@ -1014,56 +982,196 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_open_port(struct __pyx_obj_1 __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "rtmidi_python.pyx":46 + /* "rtmidi_python.pyx":47 * def open_port(self, port=0): * if isinstance(port, int): * port_number = port # <<<<<<<<<<<<<< * else: - * port_number = self.ports.index(port) + * if PY_MAJOR_VERSION < 3: */ __Pyx_INCREF(__pyx_v_port); __pyx_v_port_number = __pyx_v_port; + + /* "rtmidi_python.pyx":46 + * + * def open_port(self, port=0): + * if isinstance(port, int): # <<<<<<<<<<<<<< + * port_number = port + * else: + */ goto __pyx_L3; } + + /* "rtmidi_python.pyx":49 + * port_number = port + * else: + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * port_number = self.ports.index(port) + * else: + */ /*else*/ { + __pyx_t_2 = ((PY_MAJOR_VERSION < 3) != 0); + if (__pyx_t_2) { + + /* "rtmidi_python.pyx":50 + * else: + * if PY_MAJOR_VERSION < 3: + * port_number = self.ports.index(port) # <<<<<<<<<<<<<< + * else: + * port_number = [x.decode('UTF-8') for x in self.ports].index(port) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ports); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_index); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + } + } + if (!__pyx_t_4) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_port); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + } else { + __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL; + __Pyx_INCREF(__pyx_v_port); + __Pyx_GIVEREF(__pyx_v_port); + PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_port); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_port_number = __pyx_t_3; + __pyx_t_3 = 0; - /* "rtmidi_python.pyx":48 + /* "rtmidi_python.pyx":49 * port_number = port * else: - * port_number = self.ports.index(port) # <<<<<<<<<<<<<< + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * port_number = self.ports.index(port) + * else: + */ + goto __pyx_L4; + } + + /* "rtmidi_python.pyx":52 + * port_number = self.ports.index(port) + * else: + * port_number = [x.decode('UTF-8') for x in self.ports].index(port) # <<<<<<<<<<<<<< * * self.baseptr().openPort(port_number) */ - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ports); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_index); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_v_port); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_port); - __Pyx_GIVEREF(__pyx_v_port); - __pyx_t_5 = PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_port_number = __pyx_t_5; - __pyx_t_5 = 0; + /*else*/ { + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ports); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) { + __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0; + __pyx_t_8 = NULL; + } else { + __pyx_t_7 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + for (;;) { + if (likely(!__pyx_t_8)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + #endif + } else { + if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #else + __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + #endif + } + } else { + __pyx_t_6 = __pyx_t_8(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6); + __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_decode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_9))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_index); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + if (!__pyx_t_5) { + __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_port); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + } else { + __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL; + __Pyx_INCREF(__pyx_v_port); + __Pyx_GIVEREF(__pyx_v_port); + PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_port); + __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_port_number = __pyx_t_3; + __pyx_t_3 = 0; + } + __pyx_L4:; } __pyx_L3:; - /* "rtmidi_python.pyx":50 - * port_number = self.ports.index(port) + /* "rtmidi_python.pyx":54 + * port_number = [x.decode('UTF-8') for x in self.ports].index(port) * * self.baseptr().openPort(port_number) # <<<<<<<<<<<<<< * * def open_virtual_port(self, port_name="RtMidi"): */ - __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_v_port_number); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->openPort(__pyx_t_6); + __pyx_t_10 = __Pyx_PyInt_As_unsigned_int(__pyx_v_port_number); if (unlikely((__pyx_t_10 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->openPort(__pyx_t_10); - /* "rtmidi_python.pyx":44 + /* "rtmidi_python.pyx":45 * return NULL * * def open_port(self, port=0): # <<<<<<<<<<<<<< @@ -1078,21 +1186,24 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_open_port(struct __pyx_obj_1 __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("rtmidi_python.MidiBase.open_port", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_port_number); + __Pyx_XDECREF(__pyx_v_x); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "rtmidi_python.pyx":52 +/* "rtmidi_python.pyx":56 * self.baseptr().openPort(port_number) * * def open_virtual_port(self, port_name="RtMidi"): # <<<<<<<<<<<<<< - * self.baseptr().openVirtualPort(string(port_name)) - * + * if PY_MAJOR_VERSION < 3: + * self.baseptr().openVirtualPort(string(port_name)) */ /* Python wrapper */ @@ -1126,7 +1237,7 @@ static PyObject *__pyx_pw_13rtmidi_python_8MidiBase_3open_virtual_port(PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "open_virtual_port") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "open_virtual_port") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1139,7 +1250,7 @@ static PyObject *__pyx_pw_13rtmidi_python_8MidiBase_3open_virtual_port(PyObject } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("open_virtual_port", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("open_virtual_port", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("rtmidi_python.MidiBase.open_virtual_port", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1155,41 +1266,85 @@ static PyObject *__pyx_pw_13rtmidi_python_8MidiBase_3open_virtual_port(PyObject static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_2open_virtual_port(struct __pyx_obj_13rtmidi_python_MidiBase *__pyx_v_self, PyObject *__pyx_v_port_name) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - char *__pyx_t_1; - std::string __pyx_t_2; + int __pyx_t_1; + char *__pyx_t_2; + std::string __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("open_virtual_port", 0); - /* "rtmidi_python.pyx":53 + /* "rtmidi_python.pyx":57 + * + * def open_virtual_port(self, port_name="RtMidi"): + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * self.baseptr().openVirtualPort(string(port_name)) + * else: + */ + __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0); + if (__pyx_t_1) { + + /* "rtmidi_python.pyx":58 + * def open_virtual_port(self, port_name="RtMidi"): + * if PY_MAJOR_VERSION < 3: + * self.baseptr().openVirtualPort(string(port_name)) # <<<<<<<<<<<<<< + * else: + * self.baseptr().openVirtualPort(port_name.encode('UTF-8')) + */ + __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_port_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + try { + __pyx_t_3 = std::string(((char *)__pyx_t_2)); + } catch(...) { + __Pyx_CppExn2PyErr(); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->openVirtualPort(__pyx_t_3); + + /* "rtmidi_python.pyx":57 * * def open_virtual_port(self, port_name="RtMidi"): - * self.baseptr().openVirtualPort(string(port_name)) # <<<<<<<<<<<<<< + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * self.baseptr().openVirtualPort(string(port_name)) + * else: + */ + goto __pyx_L3; + } + + /* "rtmidi_python.pyx":60 + * self.baseptr().openVirtualPort(string(port_name)) + * else: + * self.baseptr().openVirtualPort(port_name.encode('UTF-8')) # <<<<<<<<<<<<<< * * property ports: */ - __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_port_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - try { - __pyx_t_2 = std::string(((char *)__pyx_t_1)); - } catch(...) { - __Pyx_CppExn2PyErr(); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_port_name, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __pyx_convert_string_from_py_std__in_string(__pyx_t_5); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->openVirtualPort(__pyx_t_3); } - ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->openVirtualPort(__pyx_t_2); + __pyx_L3:; - /* "rtmidi_python.pyx":52 + /* "rtmidi_python.pyx":56 * self.baseptr().openPort(port_number) * * def open_virtual_port(self, port_name="RtMidi"): # <<<<<<<<<<<<<< - * self.baseptr().openVirtualPort(string(port_name)) - * + * if PY_MAJOR_VERSION < 3: + * self.baseptr().openVirtualPort(string(port_name)) */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("rtmidi_python.MidiBase.open_virtual_port", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -1198,7 +1353,7 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_2open_virtual_port(struct __ return __pyx_r; } -/* "rtmidi_python.pyx":56 +/* "rtmidi_python.pyx":63 * * property ports: * def __get__(self): # <<<<<<<<<<<<<< @@ -1232,7 +1387,7 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_5ports___get__(struct __pyx_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); - /* "rtmidi_python.pyx":57 + /* "rtmidi_python.pyx":64 * property ports: * def __get__(self): * return [self.baseptr().getPortName(i).c_str() for i in range(self.baseptr().getPortCount())] # <<<<<<<<<<<<<< @@ -1240,21 +1395,21 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_5ports___get__(struct __pyx_ * def close_port(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->getPortCount(); for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v_i = __pyx_t_3; - __pyx_t_4 = __Pyx_PyBytes_FromString(((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->getPortName(__pyx_v_i).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyBytes_FromString(((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->getPortName(__pyx_v_i).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_4))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "rtmidi_python.pyx":56 + /* "rtmidi_python.pyx":63 * * property ports: * def __get__(self): # <<<<<<<<<<<<<< @@ -1274,7 +1429,7 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_5ports___get__(struct __pyx_ return __pyx_r; } -/* "rtmidi_python.pyx":59 +/* "rtmidi_python.pyx":66 * return [self.baseptr().getPortName(i).c_str() for i in range(self.baseptr().getPortCount())] * * def close_port(self): # <<<<<<<<<<<<<< @@ -1300,7 +1455,7 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_4close_port(struct __pyx_obj __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("close_port", 0); - /* "rtmidi_python.pyx":60 + /* "rtmidi_python.pyx":67 * * def close_port(self): * self.baseptr().closePort() # <<<<<<<<<<<<<< @@ -1309,7 +1464,7 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_4close_port(struct __pyx_obj */ ((struct __pyx_vtabstruct_13rtmidi_python_MidiBase *)__pyx_v_self->__pyx_vtab)->baseptr(__pyx_v_self)->closePort(); - /* "rtmidi_python.pyx":59 + /* "rtmidi_python.pyx":66 * return [self.baseptr().getPortName(i).c_str() for i in range(self.baseptr().getPortCount())] * * def close_port(self): # <<<<<<<<<<<<<< @@ -1324,7 +1479,7 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_4close_port(struct __pyx_obj return __pyx_r; } -/* "rtmidi_python.pyx":63 +/* "rtmidi_python.pyx":70 * * * cdef void midi_in_callback(double time_stamp, vector[unsigned char]* message_vector, void* py_callback) with gil: # <<<<<<<<<<<<<< @@ -1332,11 +1487,15 @@ static PyObject *__pyx_pf_13rtmidi_python_8MidiBase_4close_port(struct __pyx_obj * */ -static void __pyx_f_13rtmidi_python_midi_in_callback(double __pyx_v_time_stamp, std::vector *__pyx_v_message_vector, void *__pyx_v_py_callback) { +static void __pyx_f_13rtmidi_python_midi_in_callback(double __pyx_v_time_stamp, std::vector *__pyx_v_message_vector, void *__pyx_v_py_callback) { __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + Py_ssize_t __pyx_t_6; + PyObject *__pyx_t_7 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -1345,31 +1504,48 @@ static void __pyx_f_13rtmidi_python_midi_in_callback(double __pyx_v_time_stamp, #endif __Pyx_RefNannySetupContext("midi_in_callback", 0); - /* "rtmidi_python.pyx":64 + /* "rtmidi_python.pyx":71 * * cdef void midi_in_callback(double time_stamp, vector[unsigned char]* message_vector, void* py_callback) with gil: * (py_callback)(dereference(message_vector), time_stamp) # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __pyx_convert_vector_to_py_unsigned_char((*__pyx_v_message_vector)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyFloat_FromDouble(__pyx_v_time_stamp); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_convert_vector_to_py_unsigned_char((*__pyx_v_message_vector)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_time_stamp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2); + __Pyx_INCREF(((PyObject *)__pyx_v_py_callback)); + __pyx_t_4 = ((PyObject *)__pyx_v_py_callback); __pyx_t_5 = NULL; + __pyx_t_6 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_6 = 1; + } + } + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_1 = 0; + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)__pyx_v_py_callback), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "rtmidi_python.pyx":63 + /* "rtmidi_python.pyx":70 * * * cdef void midi_in_callback(double time_stamp, vector[unsigned char]* message_vector, void* py_callback) with gil: # <<<<<<<<<<<<<< @@ -1383,7 +1559,10 @@ static void __pyx_f_13rtmidi_python_midi_in_callback(double __pyx_v_time_stamp, __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_WriteUnraisable("rtmidi_python.midi_in_callback", __pyx_clineno, __pyx_lineno, __pyx_filename, 0); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_WriteUnraisable("rtmidi_python.midi_in_callback", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0); __pyx_L0:; __Pyx_RefNannyFinishContext(); #ifdef WITH_THREAD @@ -1391,12 +1570,12 @@ static void __pyx_f_13rtmidi_python_midi_in_callback(double __pyx_v_time_stamp, #endif } -/* "rtmidi_python.pyx":71 +/* "rtmidi_python.pyx":78 * cdef object py_callback * * def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): # <<<<<<<<<<<<<< - * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) - * self.py_callback = None + * if PY_MAJOR_VERSION < 3: + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) */ /* Python wrapper */ @@ -1438,7 +1617,7 @@ static int __pyx_pw_13rtmidi_python_6MidiIn_1__cinit__(PyObject *__pyx_v_self, P } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1453,7 +1632,7 @@ static int __pyx_pw_13rtmidi_python_6MidiIn_1__cinit__(PyObject *__pyx_v_self, P } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("rtmidi_python.MidiIn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1469,34 +1648,77 @@ static int __pyx_pw_13rtmidi_python_6MidiIn_1__cinit__(PyObject *__pyx_v_self, P static int __pyx_pf_13rtmidi_python_6MidiIn___cinit__(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self, PyObject *__pyx_v_client_name, PyObject *__pyx_v_queue_size_limit) { int __pyx_r; __Pyx_RefNannyDeclarations - char *__pyx_t_1; - std::string __pyx_t_2; - unsigned int __pyx_t_3; + int __pyx_t_1; + char *__pyx_t_2; + std::string __pyx_t_3; + unsigned int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "rtmidi_python.pyx":72 + /* "rtmidi_python.pyx":79 + * + * def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + * else: + */ + __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0); + if (__pyx_t_1) { + + /* "rtmidi_python.pyx":80 + * def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): + * if PY_MAJOR_VERSION < 3: + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) # <<<<<<<<<<<<<< + * else: + * self.thisptr = new RtMidiIn(UNSPECIFIED, client_name.encode('UTF-8'), queue_size_limit) + */ + __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_client_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + try { + __pyx_t_3 = std::string(((char *)__pyx_t_2)); + } catch(...) { + __Pyx_CppExn2PyErr(); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_t_4 = __Pyx_PyInt_As_unsigned_int(__pyx_v_queue_size_limit); if (unlikely((__pyx_t_4 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->thisptr = new RtMidiIn(RtMidi::UNSPECIFIED, __pyx_t_3, __pyx_t_4); + + /* "rtmidi_python.pyx":79 * * def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): - * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) # <<<<<<<<<<<<<< + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + * else: + */ + goto __pyx_L3; + } + + /* "rtmidi_python.pyx":82 + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + * else: + * self.thisptr = new RtMidiIn(UNSPECIFIED, client_name.encode('UTF-8'), queue_size_limit) # <<<<<<<<<<<<<< * self.py_callback = None * */ - __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_client_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - try { - __pyx_t_2 = std::string(((char *)__pyx_t_1)); - } catch(...) { - __Pyx_CppExn2PyErr(); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*else*/ { + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_client_name, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __pyx_convert_string_from_py_std__in_string(__pyx_t_6); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_4 = __Pyx_PyInt_As_unsigned_int(__pyx_v_queue_size_limit); if (unlikely((__pyx_t_4 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->thisptr = new RtMidiIn(RtMidi::UNSPECIFIED, __pyx_t_3, __pyx_t_4); } - __pyx_t_3 = __Pyx_PyInt_As_unsigned_int(__pyx_v_queue_size_limit); if (unlikely((__pyx_t_3 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->thisptr = new RtMidiIn(RtMidi::UNSPECIFIED, __pyx_t_2, __pyx_t_3); + __pyx_L3:; - /* "rtmidi_python.pyx":73 - * def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): - * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + /* "rtmidi_python.pyx":83 + * else: + * self.thisptr = new RtMidiIn(UNSPECIFIED, client_name.encode('UTF-8'), queue_size_limit) * self.py_callback = None # <<<<<<<<<<<<<< * * def __dealloc__(self): @@ -1507,18 +1729,20 @@ static int __pyx_pf_13rtmidi_python_6MidiIn___cinit__(struct __pyx_obj_13rtmidi_ __Pyx_DECREF(__pyx_v_self->py_callback); __pyx_v_self->py_callback = Py_None; - /* "rtmidi_python.pyx":71 + /* "rtmidi_python.pyx":78 * cdef object py_callback * * def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): # <<<<<<<<<<<<<< - * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) - * self.py_callback = None + * if PY_MAJOR_VERSION < 3: + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("rtmidi_python.MidiIn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -1526,7 +1750,7 @@ static int __pyx_pf_13rtmidi_python_6MidiIn___cinit__(struct __pyx_obj_13rtmidi_ return __pyx_r; } -/* "rtmidi_python.pyx":75 +/* "rtmidi_python.pyx":85 * self.py_callback = None * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -1549,7 +1773,7 @@ static void __pyx_pf_13rtmidi_python_6MidiIn_2__dealloc__(struct __pyx_obj_13rtm __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "rtmidi_python.pyx":76 + /* "rtmidi_python.pyx":86 * * def __dealloc__(self): * del self.thisptr # <<<<<<<<<<<<<< @@ -1558,7 +1782,7 @@ static void __pyx_pf_13rtmidi_python_6MidiIn_2__dealloc__(struct __pyx_obj_13rtm */ delete __pyx_v_self->thisptr; - /* "rtmidi_python.pyx":75 + /* "rtmidi_python.pyx":85 * self.py_callback = None * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -1570,7 +1794,7 @@ static void __pyx_pf_13rtmidi_python_6MidiIn_2__dealloc__(struct __pyx_obj_13rtm __Pyx_RefNannyFinishContext(); } -/* "rtmidi_python.pyx":78 +/* "rtmidi_python.pyx":88 * del self.thisptr * * cdef RtMidi* baseptr(self): # <<<<<<<<<<<<<< @@ -1583,7 +1807,7 @@ static RtMidi *__pyx_f_13rtmidi_python_6MidiIn_baseptr(struct __pyx_obj_13rtmidi __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("baseptr", 0); - /* "rtmidi_python.pyx":79 + /* "rtmidi_python.pyx":89 * * cdef RtMidi* baseptr(self): * return self.thisptr # <<<<<<<<<<<<<< @@ -1593,7 +1817,7 @@ static RtMidi *__pyx_f_13rtmidi_python_6MidiIn_baseptr(struct __pyx_obj_13rtmidi __pyx_r = __pyx_v_self->thisptr; goto __pyx_L0; - /* "rtmidi_python.pyx":78 + /* "rtmidi_python.pyx":88 * del self.thisptr * * cdef RtMidi* baseptr(self): # <<<<<<<<<<<<<< @@ -1607,7 +1831,7 @@ static RtMidi *__pyx_f_13rtmidi_python_6MidiIn_baseptr(struct __pyx_obj_13rtmidi return __pyx_r; } -/* "rtmidi_python.pyx":82 +/* "rtmidi_python.pyx":92 * * property callback: * def __get__(self): # <<<<<<<<<<<<<< @@ -1633,7 +1857,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_8callback___get__(struct __pyx __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__", 0); - /* "rtmidi_python.pyx":83 + /* "rtmidi_python.pyx":93 * property callback: * def __get__(self): * return self.py_callback # <<<<<<<<<<<<<< @@ -1645,7 +1869,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_8callback___get__(struct __pyx __pyx_r = __pyx_v_self->py_callback; goto __pyx_L0; - /* "rtmidi_python.pyx":82 + /* "rtmidi_python.pyx":92 * * property callback: * def __get__(self): # <<<<<<<<<<<<<< @@ -1660,7 +1884,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_8callback___get__(struct __pyx return __pyx_r; } -/* "rtmidi_python.pyx":85 +/* "rtmidi_python.pyx":95 * return self.py_callback * * def __set__(self, callback): # <<<<<<<<<<<<<< @@ -1688,7 +1912,7 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ int __pyx_t_2; __Pyx_RefNannySetupContext("__set__", 0); - /* "rtmidi_python.pyx":86 + /* "rtmidi_python.pyx":96 * * def __set__(self, callback): * if self.py_callback is not None: # <<<<<<<<<<<<<< @@ -1699,7 +1923,7 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "rtmidi_python.pyx":87 + /* "rtmidi_python.pyx":97 * def __set__(self, callback): * if self.py_callback is not None: * self.thisptr.cancelCallback() # <<<<<<<<<<<<<< @@ -1707,11 +1931,17 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ * self.py_callback = callback */ __pyx_v_self->thisptr->cancelCallback(); - goto __pyx_L3; + + /* "rtmidi_python.pyx":96 + * + * def __set__(self, callback): + * if self.py_callback is not None: # <<<<<<<<<<<<<< + * self.thisptr.cancelCallback() + * + */ } - __pyx_L3:; - /* "rtmidi_python.pyx":89 + /* "rtmidi_python.pyx":99 * self.thisptr.cancelCallback() * * self.py_callback = callback # <<<<<<<<<<<<<< @@ -1724,7 +1954,7 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ __Pyx_DECREF(__pyx_v_self->py_callback); __pyx_v_self->py_callback = __pyx_v_callback; - /* "rtmidi_python.pyx":91 + /* "rtmidi_python.pyx":101 * self.py_callback = callback * * if self.py_callback is not None: # <<<<<<<<<<<<<< @@ -1735,7 +1965,7 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ __pyx_t_1 = (__pyx_t_2 != 0); if (__pyx_t_1) { - /* "rtmidi_python.pyx":92 + /* "rtmidi_python.pyx":102 * * if self.py_callback is not None: * self.thisptr.setCallback(midi_in_callback, self.py_callback) # <<<<<<<<<<<<<< @@ -1743,11 +1973,17 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ * def ignore_types(self, midi_sysex=True, midi_time=True, midi_sense=True): */ __pyx_v_self->thisptr->setCallback(__pyx_f_13rtmidi_python_midi_in_callback, ((void *)__pyx_v_self->py_callback)); - goto __pyx_L4; + + /* "rtmidi_python.pyx":101 + * self.py_callback = callback + * + * if self.py_callback is not None: # <<<<<<<<<<<<<< + * self.thisptr.setCallback(midi_in_callback, self.py_callback) + * + */ } - __pyx_L4:; - /* "rtmidi_python.pyx":85 + /* "rtmidi_python.pyx":95 * return self.py_callback * * def __set__(self, callback): # <<<<<<<<<<<<<< @@ -1761,7 +1997,7 @@ static int __pyx_pf_13rtmidi_python_6MidiIn_8callback_2__set__(struct __pyx_obj_ return __pyx_r; } -/* "rtmidi_python.pyx":94 +/* "rtmidi_python.pyx":104 * self.thisptr.setCallback(midi_in_callback, self.py_callback) * * def ignore_types(self, midi_sysex=True, midi_time=True, midi_sense=True): # <<<<<<<<<<<<<< @@ -1816,7 +2052,7 @@ static PyObject *__pyx_pw_13rtmidi_python_6MidiIn_5ignore_types(PyObject *__pyx_ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ignore_types") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ignore_types") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1833,7 +2069,7 @@ static PyObject *__pyx_pw_13rtmidi_python_6MidiIn_5ignore_types(PyObject *__pyx_ } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("ignore_types", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("ignore_types", 0, 0, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("rtmidi_python.MidiIn.ignore_types", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1857,19 +2093,19 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_4ignore_types(struct __pyx_obj int __pyx_clineno = 0; __Pyx_RefNannySetupContext("ignore_types", 0); - /* "rtmidi_python.pyx":95 + /* "rtmidi_python.pyx":105 * * def ignore_types(self, midi_sysex=True, midi_time=True, midi_sense=True): * self.thisptr.ignoreTypes(midi_sysex, midi_time, midi_sense) # <<<<<<<<<<<<<< * * def get_message(self): */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_midi_sysex); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_midi_time); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_midi_sense); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_midi_sysex); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_midi_time); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_midi_sense); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->thisptr->ignoreTypes(__pyx_t_1, __pyx_t_2, __pyx_t_3); - /* "rtmidi_python.pyx":94 + /* "rtmidi_python.pyx":104 * self.thisptr.setCallback(midi_in_callback, self.py_callback) * * def ignore_types(self, midi_sysex=True, midi_time=True, midi_sense=True): # <<<<<<<<<<<<<< @@ -1889,7 +2125,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_4ignore_types(struct __pyx_obj return __pyx_r; } -/* "rtmidi_python.pyx":97 +/* "rtmidi_python.pyx":107 * self.thisptr.ignoreTypes(midi_sysex, midi_time, midi_sense) * * def get_message(self): # <<<<<<<<<<<<<< @@ -1911,7 +2147,7 @@ static PyObject *__pyx_pw_13rtmidi_python_6MidiIn_7get_message(PyObject *__pyx_v } static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_13rtmidi_python_MidiIn *__pyx_v_self) { - std::vector __pyx_v_message_vector; + std::vector __pyx_v_message_vector; double __pyx_v_delta_time; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1924,7 +2160,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("get_message", 0); - /* "rtmidi_python.pyx":99 + /* "rtmidi_python.pyx":109 * def get_message(self): * cdef vector[unsigned char] message_vector * delta_time = self.thisptr.getMessage(&message_vector) # <<<<<<<<<<<<<< @@ -1933,7 +2169,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_ */ __pyx_v_delta_time = __pyx_v_self->thisptr->getMessage((&__pyx_v_message_vector)); - /* "rtmidi_python.pyx":101 + /* "rtmidi_python.pyx":111 * delta_time = self.thisptr.getMessage(&message_vector) * * if message_vector.empty(): # <<<<<<<<<<<<<< @@ -1943,7 +2179,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_ __pyx_t_1 = (__pyx_v_message_vector.empty() != 0); if (__pyx_t_1) { - /* "rtmidi_python.pyx":102 + /* "rtmidi_python.pyx":112 * * if message_vector.empty(): * return None, None # <<<<<<<<<<<<<< @@ -1951,30 +2187,38 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_ * return message_vector, delta_time */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(__pyx_tuple_); - __pyx_r = __pyx_tuple_; + __Pyx_INCREF(__pyx_tuple__4); + __pyx_r = __pyx_tuple__4; goto __pyx_L0; + + /* "rtmidi_python.pyx":111 + * delta_time = self.thisptr.getMessage(&message_vector) + * + * if message_vector.empty(): # <<<<<<<<<<<<<< + * return None, None + * else: + */ } - /*else*/ { - /* "rtmidi_python.pyx":104 + /* "rtmidi_python.pyx":114 * return None, None * else: * return message_vector, delta_time # <<<<<<<<<<<<<< * * */ + /*else*/ { __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __pyx_convert_vector_to_py_unsigned_char(__pyx_v_message_vector); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_convert_vector_to_py_unsigned_char(__pyx_v_message_vector); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyFloat_FromDouble(__pyx_v_delta_time); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyFloat_FromDouble(__pyx_v_delta_time); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_r = __pyx_t_4; @@ -1982,7 +2226,7 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_ goto __pyx_L0; } - /* "rtmidi_python.pyx":97 + /* "rtmidi_python.pyx":107 * self.thisptr.ignoreTypes(midi_sysex, midi_time, midi_sense) * * def get_message(self): # <<<<<<<<<<<<<< @@ -2003,12 +2247,12 @@ static PyObject *__pyx_pf_13rtmidi_python_6MidiIn_6get_message(struct __pyx_obj_ return __pyx_r; } -/* "rtmidi_python.pyx":110 +/* "rtmidi_python.pyx":120 * cdef RtMidiOut* thisptr * * def __cinit__(self, client_name="RtMidi Output Client"): # <<<<<<<<<<<<<< - * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) - * + * if PY_MAJOR_VERSION < 3: + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) */ /* Python wrapper */ @@ -2042,7 +2286,7 @@ static int __pyx_pw_13rtmidi_python_7MidiOut_1__cinit__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2055,7 +2299,7 @@ static int __pyx_pw_13rtmidi_python_7MidiOut_1__cinit__(PyObject *__pyx_v_self, } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("rtmidi_python.MidiOut.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2071,41 +2315,85 @@ static int __pyx_pw_13rtmidi_python_7MidiOut_1__cinit__(PyObject *__pyx_v_self, static int __pyx_pf_13rtmidi_python_7MidiOut___cinit__(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self, PyObject *__pyx_v_client_name) { int __pyx_r; __Pyx_RefNannyDeclarations - char *__pyx_t_1; - std::string __pyx_t_2; + int __pyx_t_1; + char *__pyx_t_2; + std::string __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "rtmidi_python.pyx":111 + /* "rtmidi_python.pyx":121 + * + * def __cinit__(self, client_name="RtMidi Output Client"): + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + * else: + */ + __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0); + if (__pyx_t_1) { + + /* "rtmidi_python.pyx":122 + * def __cinit__(self, client_name="RtMidi Output Client"): + * if PY_MAJOR_VERSION < 3: + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) # <<<<<<<<<<<<<< + * else: + * self.thisptr = new RtMidiOut(UNSPECIFIED, client_name.encode('UTF-8')) + */ + __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_client_name); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + try { + __pyx_t_3 = std::string(((char *)__pyx_t_2)); + } catch(...) { + __Pyx_CppExn2PyErr(); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_v_self->thisptr = new RtMidiOut(RtMidi::UNSPECIFIED, __pyx_t_3); + + /* "rtmidi_python.pyx":121 * * def __cinit__(self, client_name="RtMidi Output Client"): - * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) # <<<<<<<<<<<<<< + * if PY_MAJOR_VERSION < 3: # <<<<<<<<<<<<<< + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + * else: + */ + goto __pyx_L3; + } + + /* "rtmidi_python.pyx":124 + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + * else: + * self.thisptr = new RtMidiOut(UNSPECIFIED, client_name.encode('UTF-8')) # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - __pyx_t_1 = __Pyx_PyObject_AsString(__pyx_v_client_name); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - try { - __pyx_t_2 = std::string(((char *)__pyx_t_1)); - } catch(...) { - __Pyx_CppExn2PyErr(); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /*else*/ { + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_client_name, __pyx_n_s_encode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __pyx_convert_string_from_py_std__in_string(__pyx_t_5); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_self->thisptr = new RtMidiOut(RtMidi::UNSPECIFIED, __pyx_t_3); } - __pyx_v_self->thisptr = new RtMidiOut(RtMidi::UNSPECIFIED, __pyx_t_2); + __pyx_L3:; - /* "rtmidi_python.pyx":110 + /* "rtmidi_python.pyx":120 * cdef RtMidiOut* thisptr * * def __cinit__(self, client_name="RtMidi Output Client"): # <<<<<<<<<<<<<< - * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) - * + * if PY_MAJOR_VERSION < 3: + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("rtmidi_python.MidiOut.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -2113,8 +2401,8 @@ static int __pyx_pf_13rtmidi_python_7MidiOut___cinit__(struct __pyx_obj_13rtmidi return __pyx_r; } -/* "rtmidi_python.pyx":113 - * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) +/* "rtmidi_python.pyx":126 + * self.thisptr = new RtMidiOut(UNSPECIFIED, client_name.encode('UTF-8')) * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.thisptr @@ -2136,7 +2424,7 @@ static void __pyx_pf_13rtmidi_python_7MidiOut_2__dealloc__(struct __pyx_obj_13rt __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "rtmidi_python.pyx":114 + /* "rtmidi_python.pyx":127 * * def __dealloc__(self): * del self.thisptr # <<<<<<<<<<<<<< @@ -2145,8 +2433,8 @@ static void __pyx_pf_13rtmidi_python_7MidiOut_2__dealloc__(struct __pyx_obj_13rt */ delete __pyx_v_self->thisptr; - /* "rtmidi_python.pyx":113 - * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + /* "rtmidi_python.pyx":126 + * self.thisptr = new RtMidiOut(UNSPECIFIED, client_name.encode('UTF-8')) * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.thisptr @@ -2157,7 +2445,7 @@ static void __pyx_pf_13rtmidi_python_7MidiOut_2__dealloc__(struct __pyx_obj_13rt __Pyx_RefNannyFinishContext(); } -/* "rtmidi_python.pyx":116 +/* "rtmidi_python.pyx":129 * del self.thisptr * * cdef RtMidi* baseptr(self): # <<<<<<<<<<<<<< @@ -2170,7 +2458,7 @@ static RtMidi *__pyx_f_13rtmidi_python_7MidiOut_baseptr(struct __pyx_obj_13rtmid __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("baseptr", 0); - /* "rtmidi_python.pyx":117 + /* "rtmidi_python.pyx":130 * * cdef RtMidi* baseptr(self): * return self.thisptr # <<<<<<<<<<<<<< @@ -2180,7 +2468,7 @@ static RtMidi *__pyx_f_13rtmidi_python_7MidiOut_baseptr(struct __pyx_obj_13rtmid __pyx_r = __pyx_v_self->thisptr; goto __pyx_L0; - /* "rtmidi_python.pyx":116 + /* "rtmidi_python.pyx":129 * del self.thisptr * * cdef RtMidi* baseptr(self): # <<<<<<<<<<<<<< @@ -2194,7 +2482,7 @@ static RtMidi *__pyx_f_13rtmidi_python_7MidiOut_baseptr(struct __pyx_obj_13rtmid return __pyx_r; } -/* "rtmidi_python.pyx":119 +/* "rtmidi_python.pyx":132 * return self.thisptr * * def send_message(self, message): # <<<<<<<<<<<<<< @@ -2216,32 +2504,32 @@ static PyObject *__pyx_pw_13rtmidi_python_7MidiOut_5send_message(PyObject *__pyx } static PyObject *__pyx_pf_13rtmidi_python_7MidiOut_4send_message(struct __pyx_obj_13rtmidi_python_MidiOut *__pyx_v_self, PyObject *__pyx_v_message) { - std::vector __pyx_v_message_vector; + std::vector __pyx_v_message_vector; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - std::vector __pyx_t_1; + std::vector __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("send_message", 0); - /* "rtmidi_python.pyx":120 + /* "rtmidi_python.pyx":133 * * def send_message(self, message): * cdef vector[unsigned char] message_vector = message # <<<<<<<<<<<<<< * self.thisptr.sendMessage(&message_vector) */ - __pyx_t_1 = __pyx_convert_vector_from_py_unsigned_char(__pyx_v_message); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_convert_vector_from_py_unsigned_char(__pyx_v_message); if (unlikely(PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 133; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_message_vector = __pyx_t_1; - /* "rtmidi_python.pyx":121 + /* "rtmidi_python.pyx":134 * def send_message(self, message): * cdef vector[unsigned char] message_vector = message * self.thisptr.sendMessage(&message_vector) # <<<<<<<<<<<<<< */ __pyx_v_self->thisptr->sendMessage((&__pyx_v_message_vector)); - /* "rtmidi_python.pyx":119 + /* "rtmidi_python.pyx":132 * return self.thisptr * * def send_message(self, message): # <<<<<<<<<<<<<< @@ -2261,7 +2549,62 @@ static PyObject *__pyx_pf_13rtmidi_python_7MidiOut_4send_message(struct __pyx_ob return __pyx_r; } -/* "vector.to_py":63 +/* "string.from_py":13 + * + * @cname("__pyx_convert_string_from_py_std__in_string") + * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *: # <<<<<<<<<<<<<< + * cdef Py_ssize_t length + * cdef char* data = __Pyx_PyObject_AsStringAndSize(o, &length) + */ + +static std::string __pyx_convert_string_from_py_std__in_string(PyObject *__pyx_v_o) { + Py_ssize_t __pyx_v_length; + char *__pyx_v_data; + std::string __pyx_r; + __Pyx_RefNannyDeclarations + char *__pyx_t_1; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_convert_string_from_py_std__in_string", 0); + + /* "string.from_py":15 + * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *: + * cdef Py_ssize_t length + * cdef char* data = __Pyx_PyObject_AsStringAndSize(o, &length) # <<<<<<<<<<<<<< + * return string(data, length) + * + */ + __pyx_t_1 = __Pyx_PyObject_AsStringAndSize(__pyx_v_o, (&__pyx_v_length)); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_data = __pyx_t_1; + + /* "string.from_py":16 + * cdef Py_ssize_t length + * cdef char* data = __Pyx_PyObject_AsStringAndSize(o, &length) + * return string(data, length) # <<<<<<<<<<<<<< + * + * + */ + __pyx_r = std::string(__pyx_v_data, __pyx_v_length); + goto __pyx_L0; + + /* "string.from_py":13 + * + * @cname("__pyx_convert_string_from_py_std__in_string") + * cdef string __pyx_convert_string_from_py_std__in_string(object o) except *: # <<<<<<<<<<<<<< + * cdef Py_ssize_t length + * cdef char* data = __Pyx_PyObject_AsStringAndSize(o, &length) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("string.from_py.__pyx_convert_string_from_py_std__in_string", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "vector.to_py":67 * * @cname("__pyx_convert_vector_to_py_unsigned_char") * cdef object __pyx_convert_vector_to_py_unsigned_char(vector[X]& v): # <<<<<<<<<<<<<< @@ -2269,7 +2612,7 @@ static PyObject *__pyx_pf_13rtmidi_python_7MidiOut_4send_message(struct __pyx_ob * */ -static PyObject *__pyx_convert_vector_to_py_unsigned_char(const std::vector &__pyx_v_v) { +static PyObject *__pyx_convert_vector_to_py_unsigned_char(const std::vector &__pyx_v_v) { size_t __pyx_v_i; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2282,7 +2625,7 @@ static PyObject *__pyx_convert_vector_to_py_unsigned_char(const std::vector __pyx_convert_vector_from_py_unsigned_char(PyObject *__pyx_v_o) { - std::vector __pyx_v_v; +static std::vector __pyx_convert_vector_from_py_unsigned_char(PyObject *__pyx_v_o) { + std::vector __pyx_v_v; PyObject *__pyx_v_item = NULL; - std::vector __pyx_r; + std::vector __pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; Py_ssize_t __pyx_t_2; @@ -2347,43 +2690,47 @@ static std::vector __pyx_convert_vector_from_py_unsigned_char(PyO int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__pyx_convert_vector_from_py_unsigned_char", 0); - /* "vector.from_py":47 + /* "vector.from_py":51 * cdef vector[X] __pyx_convert_vector_from_py_unsigned_char(object o) except *: * cdef vector[X] v * for item in o: # <<<<<<<<<<<<<< * v.push_back(X_from_py(item)) * return v */ - if (PyList_CheckExact(__pyx_v_o) || PyTuple_CheckExact(__pyx_v_o)) { + if (likely(PyList_CheckExact(__pyx_v_o)) || PyTuple_CheckExact(__pyx_v_o)) { __pyx_t_1 = __pyx_v_o; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = NULL; } else { - __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; + __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } for (;;) { - if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) { - if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif + if (likely(!__pyx_t_3)) { + if (likely(PyList_CheckExact(__pyx_t_1))) { + if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + #endif + } else { + if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #else + __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + #endif + } } else { __pyx_t_4 = __pyx_t_3(__pyx_t_1); if (unlikely(!__pyx_t_4)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[1]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -2392,19 +2739,27 @@ static std::vector __pyx_convert_vector_from_py_unsigned_char(PyO __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_4); __pyx_t_4 = 0; - /* "vector.from_py":48 + /* "vector.from_py":52 * cdef vector[X] v * for item in o: * v.push_back(X_from_py(item)) # <<<<<<<<<<<<<< * return v * */ - __pyx_t_5 = __Pyx_PyInt_As_unsigned_char(__pyx_v_item); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_As_unsigned_char(__pyx_v_item); if (unlikely(__pyx_t_5 == -1 && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_v.push_back(__pyx_t_5); + + /* "vector.from_py":51 + * cdef vector[X] __pyx_convert_vector_from_py_unsigned_char(object o) except *: + * cdef vector[X] v + * for item in o: # <<<<<<<<<<<<<< + * v.push_back(X_from_py(item)) + * return v + */ } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "vector.from_py":49 + /* "vector.from_py":53 * for item in o: * v.push_back(X_from_py(item)) * return v # <<<<<<<<<<<<<< @@ -2414,7 +2769,7 @@ static std::vector __pyx_convert_vector_from_py_unsigned_char(PyO __pyx_r = __pyx_v_v; goto __pyx_L0; - /* "vector.from_py":45 + /* "vector.from_py":49 * * @cname("__pyx_convert_vector_from_py_unsigned_char") * cdef vector[X] __pyx_convert_vector_from_py_unsigned_char(object o) except *: # <<<<<<<<<<<<<< @@ -2462,9 +2817,9 @@ static PyObject *__pyx_getprop_13rtmidi_python_8MidiBase_ports(PyObject *o, CYTH } static PyMethodDef __pyx_methods_13rtmidi_python_MidiBase[] = { - {__Pyx_NAMESTR("open_port"), (PyCFunction)__pyx_pw_13rtmidi_python_8MidiBase_1open_port, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("open_virtual_port"), (PyCFunction)__pyx_pw_13rtmidi_python_8MidiBase_3open_virtual_port, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("close_port"), (PyCFunction)__pyx_pw_13rtmidi_python_8MidiBase_5close_port, METH_NOARGS, __Pyx_DOCSTR(0)}, + {"open_port", (PyCFunction)__pyx_pw_13rtmidi_python_8MidiBase_1open_port, METH_VARARGS|METH_KEYWORDS, 0}, + {"open_virtual_port", (PyCFunction)__pyx_pw_13rtmidi_python_8MidiBase_3open_virtual_port, METH_VARARGS|METH_KEYWORDS, 0}, + {"close_port", (PyCFunction)__pyx_pw_13rtmidi_python_8MidiBase_5close_port, METH_NOARGS, 0}, {0, 0, 0, 0} }; @@ -2475,7 +2830,7 @@ static struct PyGetSetDef __pyx_getsets_13rtmidi_python_MidiBase[] = { static PyTypeObject __pyx_type_13rtmidi_python_MidiBase = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("rtmidi_python.MidiBase"), /*tp_name*/ + "rtmidi_python.MidiBase", /*tp_name*/ sizeof(struct __pyx_obj_13rtmidi_python_MidiBase), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_13rtmidi_python_MidiBase, /*tp_dealloc*/ @@ -2484,8 +2839,9 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiBase = { 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ - #else - 0, /*reserved*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ @@ -2524,62 +2880,109 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiBase = { 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ - #endif #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif }; -static struct __pyx_vtabstruct_13rtmidi_python_MidiOut __pyx_vtable_13rtmidi_python_MidiOut; +static struct __pyx_vtabstruct_13rtmidi_python_MidiIn __pyx_vtable_13rtmidi_python_MidiIn; -static PyObject *__pyx_tp_new_13rtmidi_python_MidiOut(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_13rtmidi_python_MidiOut *p; +static PyObject *__pyx_tp_new_13rtmidi_python_MidiIn(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_13rtmidi_python_MidiIn *p; PyObject *o = __pyx_tp_new_13rtmidi_python_MidiBase(t, a, k); if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_13rtmidi_python_MidiOut *)o); - p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_13rtmidi_python_MidiBase*)__pyx_vtabptr_13rtmidi_python_MidiOut; - if (unlikely(__pyx_pw_13rtmidi_python_7MidiOut_1__cinit__(o, a, k) < 0)) { + p = ((struct __pyx_obj_13rtmidi_python_MidiIn *)o); + p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_13rtmidi_python_MidiBase*)__pyx_vtabptr_13rtmidi_python_MidiIn; + p->py_callback = Py_None; Py_INCREF(Py_None); + if (unlikely(__pyx_pw_13rtmidi_python_6MidiIn_1__cinit__(o, a, k) < 0)) { Py_DECREF(o); o = 0; } return o; } -static void __pyx_tp_dealloc_13rtmidi_python_MidiOut(PyObject *o) { +static void __pyx_tp_dealloc_13rtmidi_python_MidiIn(PyObject *o) { + struct __pyx_obj_13rtmidi_python_MidiIn *p = (struct __pyx_obj_13rtmidi_python_MidiIn *)o; #if PY_VERSION_HEX >= 0x030400a1 - if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif + PyObject_GC_UnTrack(o); { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_13rtmidi_python_7MidiOut_3__dealloc__(o); + __pyx_pw_13rtmidi_python_6MidiIn_3__dealloc__(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } + Py_CLEAR(p->py_callback); + #if CYTHON_COMPILING_IN_CPYTHON + if (PyType_IS_GC(Py_TYPE(o)->tp_base)) + #endif + PyObject_GC_Track(o); __pyx_tp_dealloc_13rtmidi_python_MidiBase(o); } -static PyMethodDef __pyx_methods_13rtmidi_python_MidiOut[] = { - {__Pyx_NAMESTR("send_message"), (PyCFunction)__pyx_pw_13rtmidi_python_7MidiOut_5send_message, METH_O, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_13rtmidi_python_MidiIn(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_13rtmidi_python_MidiIn *p = (struct __pyx_obj_13rtmidi_python_MidiIn *)o; + e = ((likely(__pyx_ptype_13rtmidi_python_MidiBase)) ? ((__pyx_ptype_13rtmidi_python_MidiBase->tp_traverse) ? __pyx_ptype_13rtmidi_python_MidiBase->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_13rtmidi_python_MidiIn)); if (e) return e; + if (p->py_callback) { + e = (*v)(p->py_callback, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_13rtmidi_python_MidiIn(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_13rtmidi_python_MidiIn *p = (struct __pyx_obj_13rtmidi_python_MidiIn *)o; + if (likely(__pyx_ptype_13rtmidi_python_MidiBase)) { if (__pyx_ptype_13rtmidi_python_MidiBase->tp_clear) __pyx_ptype_13rtmidi_python_MidiBase->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_13rtmidi_python_MidiIn); + tmp = ((PyObject*)p->py_callback); + p->py_callback = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_13rtmidi_python_6MidiIn_callback(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_13rtmidi_python_6MidiIn_8callback_1__get__(o); +} + +static int __pyx_setprop_13rtmidi_python_6MidiIn_callback(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { + if (v) { + return __pyx_pw_13rtmidi_python_6MidiIn_8callback_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_13rtmidi_python_MidiIn[] = { + {"ignore_types", (PyCFunction)__pyx_pw_13rtmidi_python_6MidiIn_5ignore_types, METH_VARARGS|METH_KEYWORDS, 0}, + {"get_message", (PyCFunction)__pyx_pw_13rtmidi_python_6MidiIn_7get_message, METH_NOARGS, 0}, {0, 0, 0, 0} }; -static PyTypeObject __pyx_type_13rtmidi_python_MidiOut = { +static struct PyGetSetDef __pyx_getsets_13rtmidi_python_MidiIn[] = { + {(char *)"callback", __pyx_getprop_13rtmidi_python_6MidiIn_callback, __pyx_setprop_13rtmidi_python_6MidiIn_callback, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyTypeObject __pyx_type_13rtmidi_python_MidiIn = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("rtmidi_python.MidiOut"), /*tp_name*/ - sizeof(struct __pyx_obj_13rtmidi_python_MidiOut), /*tp_basicsize*/ + "rtmidi_python.MidiIn", /*tp_name*/ + sizeof(struct __pyx_obj_13rtmidi_python_MidiIn), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_13rtmidi_python_MidiOut, /*tp_dealloc*/ + __pyx_tp_dealloc_13rtmidi_python_MidiIn, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ - #else - 0, /*reserved*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ @@ -2591,17 +2994,17 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiOut = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_13rtmidi_python_MidiIn, /*tp_traverse*/ + __pyx_tp_clear_13rtmidi_python_MidiIn, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_13rtmidi_python_MidiOut, /*tp_methods*/ + __pyx_methods_13rtmidi_python_MidiIn, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_13rtmidi_python_MidiIn, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -2609,7 +3012,7 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiOut = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_13rtmidi_python_MidiOut, /*tp_new*/ + __pyx_tp_new_13rtmidi_python_MidiIn, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -2618,110 +3021,61 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiOut = { 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ - #endif #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif }; -static struct __pyx_vtabstruct_13rtmidi_python_MidiIn __pyx_vtable_13rtmidi_python_MidiIn; +static struct __pyx_vtabstruct_13rtmidi_python_MidiOut __pyx_vtable_13rtmidi_python_MidiOut; -static PyObject *__pyx_tp_new_13rtmidi_python_MidiIn(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_13rtmidi_python_MidiIn *p; +static PyObject *__pyx_tp_new_13rtmidi_python_MidiOut(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_13rtmidi_python_MidiOut *p; PyObject *o = __pyx_tp_new_13rtmidi_python_MidiBase(t, a, k); if (unlikely(!o)) return 0; - p = ((struct __pyx_obj_13rtmidi_python_MidiIn *)o); - p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_13rtmidi_python_MidiBase*)__pyx_vtabptr_13rtmidi_python_MidiIn; - p->py_callback = Py_None; Py_INCREF(Py_None); - if (unlikely(__pyx_pw_13rtmidi_python_6MidiIn_1__cinit__(o, a, k) < 0)) { + p = ((struct __pyx_obj_13rtmidi_python_MidiOut *)o); + p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_13rtmidi_python_MidiBase*)__pyx_vtabptr_13rtmidi_python_MidiOut; + if (unlikely(__pyx_pw_13rtmidi_python_7MidiOut_1__cinit__(o, a, k) < 0)) { Py_DECREF(o); o = 0; } return o; } -static void __pyx_tp_dealloc_13rtmidi_python_MidiIn(PyObject *o) { - struct __pyx_obj_13rtmidi_python_MidiIn *p = (struct __pyx_obj_13rtmidi_python_MidiIn *)o; +static void __pyx_tp_dealloc_13rtmidi_python_MidiOut(PyObject *o) { #if PY_VERSION_HEX >= 0x030400a1 - if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) { + if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif - PyObject_GC_UnTrack(o); { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); ++Py_REFCNT(o); - __pyx_pw_13rtmidi_python_6MidiIn_3__dealloc__(o); + __pyx_pw_13rtmidi_python_7MidiOut_3__dealloc__(o); --Py_REFCNT(o); PyErr_Restore(etype, eval, etb); } - Py_CLEAR(p->py_callback); - #if CYTHON_COMPILING_IN_CPYTHON - if (PyType_IS_GC(Py_TYPE(o)->tp_base)) - #endif - PyObject_GC_Track(o); __pyx_tp_dealloc_13rtmidi_python_MidiBase(o); } -static int __pyx_tp_traverse_13rtmidi_python_MidiIn(PyObject *o, visitproc v, void *a) { - int e; - struct __pyx_obj_13rtmidi_python_MidiIn *p = (struct __pyx_obj_13rtmidi_python_MidiIn *)o; - e = ((likely(__pyx_ptype_13rtmidi_python_MidiBase)) ? ((__pyx_ptype_13rtmidi_python_MidiBase->tp_traverse) ? __pyx_ptype_13rtmidi_python_MidiBase->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_13rtmidi_python_MidiIn)); if (e) return e; - if (p->py_callback) { - e = (*v)(p->py_callback, a); if (e) return e; - } - return 0; -} - -static int __pyx_tp_clear_13rtmidi_python_MidiIn(PyObject *o) { - PyObject* tmp; - struct __pyx_obj_13rtmidi_python_MidiIn *p = (struct __pyx_obj_13rtmidi_python_MidiIn *)o; - if (likely(__pyx_ptype_13rtmidi_python_MidiBase)) { if (__pyx_ptype_13rtmidi_python_MidiBase->tp_clear) __pyx_ptype_13rtmidi_python_MidiBase->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_13rtmidi_python_MidiIn); - tmp = ((PyObject*)p->py_callback); - p->py_callback = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - return 0; -} - -static PyObject *__pyx_getprop_13rtmidi_python_6MidiIn_callback(PyObject *o, CYTHON_UNUSED void *x) { - return __pyx_pw_13rtmidi_python_6MidiIn_8callback_1__get__(o); -} - -static int __pyx_setprop_13rtmidi_python_6MidiIn_callback(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) { - if (v) { - return __pyx_pw_13rtmidi_python_6MidiIn_8callback_3__set__(o, v); - } - else { - PyErr_SetString(PyExc_NotImplementedError, "__del__"); - return -1; - } -} - -static PyMethodDef __pyx_methods_13rtmidi_python_MidiIn[] = { - {__Pyx_NAMESTR("ignore_types"), (PyCFunction)__pyx_pw_13rtmidi_python_6MidiIn_5ignore_types, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("get_message"), (PyCFunction)__pyx_pw_13rtmidi_python_6MidiIn_7get_message, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_13rtmidi_python_MidiOut[] = { + {"send_message", (PyCFunction)__pyx_pw_13rtmidi_python_7MidiOut_5send_message, METH_O, 0}, {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_13rtmidi_python_MidiIn[] = { - {(char *)"callback", __pyx_getprop_13rtmidi_python_6MidiIn_callback, __pyx_setprop_13rtmidi_python_6MidiIn_callback, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyTypeObject __pyx_type_13rtmidi_python_MidiIn = { +static PyTypeObject __pyx_type_13rtmidi_python_MidiOut = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("rtmidi_python.MidiIn"), /*tp_name*/ - sizeof(struct __pyx_obj_13rtmidi_python_MidiIn), /*tp_basicsize*/ + "rtmidi_python.MidiOut", /*tp_name*/ + sizeof(struct __pyx_obj_13rtmidi_python_MidiOut), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_13rtmidi_python_MidiIn, /*tp_dealloc*/ + __pyx_tp_dealloc_13rtmidi_python_MidiOut, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ - #else - 0, /*reserved*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ @@ -2733,17 +3087,17 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiIn = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_13rtmidi_python_MidiIn, /*tp_traverse*/ - __pyx_tp_clear_13rtmidi_python_MidiIn, /*tp_clear*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_13rtmidi_python_MidiIn, /*tp_methods*/ + __pyx_methods_13rtmidi_python_MidiOut, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_13rtmidi_python_MidiIn, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -2751,7 +3105,7 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiIn = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_13rtmidi_python_MidiIn, /*tp_new*/ + __pyx_tp_new_13rtmidi_python_MidiOut, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -2760,9 +3114,7 @@ static PyTypeObject __pyx_type_13rtmidi_python_MidiIn = { 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ 0, /*tp_del*/ - #if PY_VERSION_HEX >= 0x02060000 0, /*tp_version_tag*/ - #endif #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif @@ -2779,7 +3131,7 @@ static struct PyModuleDef __pyx_moduledef = { #else PyModuleDef_HEAD_INIT, #endif - __Pyx_NAMESTR("rtmidi_python"), + "rtmidi_python", 0, /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, @@ -2794,7 +3146,10 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_RtMidi, __pyx_k_RtMidi, sizeof(__pyx_k_RtMidi), 0, 0, 1, 1}, {&__pyx_kp_s_RtMidi_Input_Client, __pyx_k_RtMidi_Input_Client, sizeof(__pyx_k_RtMidi_Input_Client), 0, 0, 1, 0}, {&__pyx_kp_s_RtMidi_Output_Client, __pyx_k_RtMidi_Output_Client, sizeof(__pyx_k_RtMidi_Output_Client), 0, 0, 1, 0}, + {&__pyx_kp_s_UTF_8, __pyx_k_UTF_8, sizeof(__pyx_k_UTF_8), 0, 0, 1, 0}, {&__pyx_n_s_client_name, __pyx_k_client_name, sizeof(__pyx_k_client_name), 0, 0, 1, 1}, + {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1}, + {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_midi_sense, __pyx_k_midi_sense, sizeof(__pyx_k_midi_sense), 0, 0, 1, 1}, @@ -2810,7 +3165,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -2820,16 +3175,60 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "rtmidi_python.pyx":102 + /* "rtmidi_python.pyx":52 + * port_number = self.ports.index(port) + * else: + * port_number = [x.decode('UTF-8') for x in self.ports].index(port) # <<<<<<<<<<<<<< + * + * self.baseptr().openPort(port_number) + */ + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_UTF_8); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "rtmidi_python.pyx":60 + * self.baseptr().openVirtualPort(string(port_name)) + * else: + * self.baseptr().openVirtualPort(port_name.encode('UTF-8')) # <<<<<<<<<<<<<< + * + * property ports: + */ + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_UTF_8); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "rtmidi_python.pyx":82 + * self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + * else: + * self.thisptr = new RtMidiIn(UNSPECIFIED, client_name.encode('UTF-8'), queue_size_limit) # <<<<<<<<<<<<<< + * self.py_callback = None + * + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_UTF_8); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "rtmidi_python.pyx":112 * * if message_vector.empty(): * return None, None # <<<<<<<<<<<<<< * else: * return message_vector, delta_time */ - __pyx_tuple_ = PyTuple_Pack(2, Py_None, Py_None); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_tuple_); - __Pyx_GIVEREF(__pyx_tuple_); + __pyx_tuple__4 = PyTuple_Pack(2, Py_None, Py_None); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "rtmidi_python.pyx":124 + * self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + * else: + * self.thisptr = new RtMidiOut(UNSPECIFIED, client_name.encode('UTF-8')) # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_UTF_8); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -2869,18 +3268,24 @@ PyMODINIT_FUNC PyInit_rtmidi_python(void) } #endif __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_rtmidi_python(void)", 0); - if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #ifdef __Pyx_CyFunction_USED - if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif #ifdef __Pyx_FusedFunction_USED if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif #ifdef __Pyx_Generator_USED if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS @@ -2890,25 +3295,25 @@ PyMODINIT_FUNC PyInit_rtmidi_python(void) #endif /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("rtmidi_python"), __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + __pyx_m = Py_InitModule4("rtmidi_python", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} Py_INCREF(__pyx_d); - __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); #endif - if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; /*--- Initialize various global constants etc. ---*/ - if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif if (__pyx_module_is_main_rtmidi_python) { - if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } #if PY_MAJOR_VERSION >= 3 { @@ -2919,74 +3324,82 @@ PyMODINIT_FUNC PyInit_rtmidi_python(void) } #endif /*--- Builtin init code ---*/ - if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Constants init code ---*/ - if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Global init code ---*/ /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ __pyx_vtabptr_13rtmidi_python_MidiBase = &__pyx_vtable_13rtmidi_python_MidiBase; __pyx_vtable_13rtmidi_python_MidiBase.baseptr = (RtMidi *(*)(struct __pyx_obj_13rtmidi_python_MidiBase *))__pyx_f_13rtmidi_python_8MidiBase_baseptr; - if (PyType_Ready(&__pyx_type_13rtmidi_python_MidiBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_13rtmidi_python_MidiBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_type_13rtmidi_python_MidiBase.tp_print = 0; - if (__Pyx_SetVtable(__pyx_type_13rtmidi_python_MidiBase.tp_dict, __pyx_vtabptr_13rtmidi_python_MidiBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "MidiBase", (PyObject *)&__pyx_type_13rtmidi_python_MidiBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_13rtmidi_python_MidiBase.tp_dict, __pyx_vtabptr_13rtmidi_python_MidiBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttrString(__pyx_m, "MidiBase", (PyObject *)&__pyx_type_13rtmidi_python_MidiBase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_13rtmidi_python_MidiBase = &__pyx_type_13rtmidi_python_MidiBase; - __pyx_vtabptr_13rtmidi_python_MidiOut = &__pyx_vtable_13rtmidi_python_MidiOut; - __pyx_vtable_13rtmidi_python_MidiOut.__pyx_base = *__pyx_vtabptr_13rtmidi_python_MidiBase; - __pyx_vtable_13rtmidi_python_MidiOut.__pyx_base.baseptr = (RtMidi *(*)(struct __pyx_obj_13rtmidi_python_MidiBase *))__pyx_f_13rtmidi_python_7MidiOut_baseptr; - __pyx_type_13rtmidi_python_MidiOut.tp_base = __pyx_ptype_13rtmidi_python_MidiBase; - if (PyType_Ready(&__pyx_type_13rtmidi_python_MidiOut) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_type_13rtmidi_python_MidiOut.tp_print = 0; - if (__Pyx_SetVtable(__pyx_type_13rtmidi_python_MidiOut.tp_dict, __pyx_vtabptr_13rtmidi_python_MidiOut) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "MidiOut", (PyObject *)&__pyx_type_13rtmidi_python_MidiOut) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_13rtmidi_python_MidiOut = &__pyx_type_13rtmidi_python_MidiOut; __pyx_vtabptr_13rtmidi_python_MidiIn = &__pyx_vtable_13rtmidi_python_MidiIn; __pyx_vtable_13rtmidi_python_MidiIn.__pyx_base = *__pyx_vtabptr_13rtmidi_python_MidiBase; __pyx_vtable_13rtmidi_python_MidiIn.__pyx_base.baseptr = (RtMidi *(*)(struct __pyx_obj_13rtmidi_python_MidiBase *))__pyx_f_13rtmidi_python_6MidiIn_baseptr; __pyx_type_13rtmidi_python_MidiIn.tp_base = __pyx_ptype_13rtmidi_python_MidiBase; - if (PyType_Ready(&__pyx_type_13rtmidi_python_MidiIn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_13rtmidi_python_MidiIn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_type_13rtmidi_python_MidiIn.tp_print = 0; - if (__Pyx_SetVtable(__pyx_type_13rtmidi_python_MidiIn.tp_dict, __pyx_vtabptr_13rtmidi_python_MidiIn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "MidiIn", (PyObject *)&__pyx_type_13rtmidi_python_MidiIn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetVtable(__pyx_type_13rtmidi_python_MidiIn.tp_dict, __pyx_vtabptr_13rtmidi_python_MidiIn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttrString(__pyx_m, "MidiIn", (PyObject *)&__pyx_type_13rtmidi_python_MidiIn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_13rtmidi_python_MidiIn = &__pyx_type_13rtmidi_python_MidiIn; + __pyx_vtabptr_13rtmidi_python_MidiOut = &__pyx_vtable_13rtmidi_python_MidiOut; + __pyx_vtable_13rtmidi_python_MidiOut.__pyx_base = *__pyx_vtabptr_13rtmidi_python_MidiBase; + __pyx_vtable_13rtmidi_python_MidiOut.__pyx_base.baseptr = (RtMidi *(*)(struct __pyx_obj_13rtmidi_python_MidiBase *))__pyx_f_13rtmidi_python_7MidiOut_baseptr; + __pyx_type_13rtmidi_python_MidiOut.tp_base = __pyx_ptype_13rtmidi_python_MidiBase; + if (PyType_Ready(&__pyx_type_13rtmidi_python_MidiOut) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_type_13rtmidi_python_MidiOut.tp_print = 0; + if (__Pyx_SetVtable(__pyx_type_13rtmidi_python_MidiOut.tp_dict, __pyx_vtabptr_13rtmidi_python_MidiOut) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttrString(__pyx_m, "MidiOut", (PyObject *)&__pyx_type_13rtmidi_python_MidiOut) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_13rtmidi_python_MidiOut = &__pyx_type_13rtmidi_python_MidiOut; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #endif - /* "rtmidi_python.pyx":12 + /* "rtmidi_python.pyx":14 * void PyEval_InitThreads() * * PyEval_InitThreads() # <<<<<<<<<<<<<< * - * + * cdef extern from "RtMidi/RtMidi.h": */ PyEval_InitThreads(); /* "rtmidi_python.pyx":1 - * from cython.operator import dereference # <<<<<<<<<<<<<< + * # distutils: language = c++ # <<<<<<<<<<<<<< * - * from libcpp.string cimport string + * from cython.operator import dereference */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "vector.from_py":45 + /* "vector.from_py":49 * * @cname("__pyx_convert_vector_from_py_unsigned_char") * cdef vector[X] __pyx_convert_vector_from_py_unsigned_char(object o) except *: # <<<<<<<<<<<<<< * cdef vector[X] v * for item in o: */ + + /*--- Wrapped vars code ---*/ + goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { - __Pyx_AddTraceback("init rtmidi_python", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__pyx_d) { + __Pyx_AddTraceback("init rtmidi_python", __pyx_clineno, __pyx_lineno, __pyx_filename); + } Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init rtmidi_python"); @@ -3000,7 +3413,7 @@ PyMODINIT_FUNC PyInit_rtmidi_python(void) #endif } -/* Runtime support code */ +/* --- Runtime support code --- */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; @@ -3015,7 +3428,7 @@ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } -#endif /* CYTHON_REFNANNY */ +#endif static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); @@ -3169,6 +3582,78 @@ static void __Pyx_RaiseArgtupleInvalid( (num_expected == 1) ? "" : "s", num_found); } +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = func->ob_type->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = PyCFunction_GET_FUNCTION(func); + self = PyCFunction_GET_SELF(func); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +#if CYTHON_COMPILING_IN_CPYTHON +static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_New(1); + if (unlikely(!args)) return NULL; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { +#ifdef __Pyx_CyFunction_USED + if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) { +#else + if (likely(PyCFunction_Check(func))) { +#endif + if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { + return __Pyx_PyObject_CallMethO(func, arg); + } + } + return __Pyx__PyObject_CallOneArg(func, arg); +} +#else +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_Pack(1, arg); + if (unlikely(!args)) return NULL; + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +#endif + static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { #if CYTHON_COMPILING_IN_CPYTHON PyObject *tmp_type, *tmp_value, *tmp_tb; @@ -3202,9 +3687,14 @@ static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyOb static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename, - int full_traceback) { + int full_traceback, CYTHON_UNUSED int nogil) { PyObject *old_exc, *old_val, *old_tb; PyObject *ctx; +#ifdef WITH_THREAD + PyGILState_STATE state; + if (nogil) + state = PyGILState_Ensure(); +#endif __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); if (full_traceback) { Py_XINCREF(old_exc); @@ -3225,6 +3715,10 @@ static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, PyErr_WriteUnraisable(ctx); Py_DECREF(ctx); } +#ifdef WITH_THREAD + if (nogil) + PyGILState_Release(state); +#endif } static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) { @@ -3249,7 +3743,7 @@ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) { } static int __Pyx_SetVtable(PyObject *dict, void *vtable) { -#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0) +#if PY_VERSION_HEX >= 0x02070000 PyObject *ob = PyCapsule_New(vtable, 0, 0); #else PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); @@ -3265,111 +3759,355 @@ static int __Pyx_SetVtable(PyObject *dict, void *vtable) { return -1; } -#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func) \ - { \ - func_type value = func(x); \ - if (sizeof(target_type) < sizeof(func_type)) { \ - if (unlikely(value != (func_type) (target_type) value)) { \ - func_type zero = 0; \ - PyErr_SetString(PyExc_OverflowError, \ - (is_unsigned && unlikely(value < zero)) ? \ - "can't convert negative value to " #target_type : \ - "value too large to convert to " #target_type); \ - return (target_type) -1; \ - } \ - } \ - return (target_type) value; \ +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; } - -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" - #endif -#endif -static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) { - const unsigned int neg_one = (unsigned int) -1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; -#if PY_MAJOR_VERSION < 3 - if (likely(PyInt_Check(x))) { - if (sizeof(unsigned int) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG) - } else { - long val = PyInt_AS_LONG(x); - if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned int"); - return (unsigned int) -1; - } - return (unsigned int) val; - } - } else -#endif - if (likely(PyLong_Check(x))) { - if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned int)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (unsigned int) ((PyLongObject*)x)->ob_digit[0]; - } - } - #endif -#endif - if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned int"); - return (unsigned int) -1; - } - if (sizeof(unsigned int) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, PyLong_AsUnsignedLong) - } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { - __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long long, PyLong_AsUnsignedLongLong) - } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned int)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(unsigned int) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(unsigned int) ((PyLongObject*)x)->ob_digit[0]; - } - } - #endif -#endif - if (sizeof(unsigned int) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT(unsigned int, long, PyLong_AsLong) - } else if (sizeof(unsigned int) <= sizeof(long long)) { - __PYX_VERIFY_RETURN_INT(unsigned int, long long, PyLong_AsLongLong) - } - } - { -#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) - PyErr_SetString(PyExc_RuntimeError, - "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); -#else - unsigned int val; - PyObject *v = __Pyx_PyNumber_Int(x); - #if PY_MAJOR_VERSION < 3 - if (likely(v) && !PyLong_Check(v)) { - PyObject *tmp = v; - v = PyNumber_Long(tmp); - Py_DECREF(tmp); - } - #endif - if (likely(v)) { - int one = 1; int is_little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&val; - int ret = _PyLong_AsByteArray((PyLongObject *)v, - bytes, sizeof(val), - is_little, !is_unsigned); - Py_DECREF(v); - if (likely(!ret)) - return val; - } -#endif - return (unsigned int) -1; + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + #if PY_MAJOR_VERSION < 3 + py_srcfile = PyString_FromString(filename); + #else + py_srcfile = PyUnicode_FromString(filename); + #endif + if (!py_srcfile) goto bad; + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + #else + py_funcname = PyUnicode_FromString(funcname); + #endif + } + if (!py_funcname) goto bad; + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + Py_DECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + 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; + py_code = __pyx_find_code_object(c_line ? c_line : py_line); + if (!py_code) { + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) goto bad; + __pyx_insert_code_object(c_line ? c_line : py_line, py_code); + } + py_frame = PyFrame_New( + PyThreadState_GET(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = py_line; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} + +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +#if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" +#endif + +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) { + const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0; + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(unsigned int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (unsigned int) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (unsigned int) 0; + case 1: __PYX_VERIFY_RETURN_INT(unsigned int, digit, digits[0]) + case 2: + if (8 * sizeof(unsigned int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) >= 2 * PyLong_SHIFT) { + return (unsigned int) (((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(unsigned int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) >= 3 * PyLong_SHIFT) { + return (unsigned int) (((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(unsigned int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) >= 4 * PyLong_SHIFT) { + return (unsigned int) (((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0])); + } + } + break; + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (unsigned int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if (sizeof(unsigned int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned long, PyLong_AsUnsignedLong(x)) + } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (unsigned int) 0; + case -1: __PYX_VERIFY_RETURN_INT(unsigned int, sdigit, -(sdigit) digits[0]) + case 1: __PYX_VERIFY_RETURN_INT(unsigned int, digit, +digits[0]) + case -2: + if (8 * sizeof(unsigned int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) { + return (unsigned int) (((unsigned int)-1)*(((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(unsigned int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) { + return (unsigned int) ((((((unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(unsigned int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) { + return (unsigned int) (((unsigned int)-1)*(((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(unsigned int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) { + return (unsigned int) ((((((((unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(unsigned int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT) { + return (unsigned int) (((unsigned int)-1)*(((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(unsigned int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned int) - 1 > 4 * PyLong_SHIFT) { + return (unsigned int) ((((((((((unsigned int)digits[3]) << PyLong_SHIFT) | (unsigned int)digits[2]) << PyLong_SHIFT) | (unsigned int)digits[1]) << PyLong_SHIFT) | (unsigned int)digits[0]))); + } + } + break; + } +#endif + if (sizeof(unsigned int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, long, PyLong_AsLong(x)) + } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned int, PY_LONG_LONG, PyLong_AsLongLong(x)) + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + unsigned int val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (unsigned int) -1; } } else { unsigned int val; @@ -3379,24 +4117,32 @@ static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) { Py_DECREF(tmp); return val; } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned int"); + return (unsigned int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned int"); + return (unsigned int) -1; } static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { - const unsigned int neg_one = (unsigned int) -1, const_zero = 0; + const unsigned int neg_one = (unsigned int) -1, const_zero = (unsigned int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned int) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); - } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { - return PyLong_FromUnsignedLongLong((unsigned long long) value); + } else if (sizeof(unsigned int) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); } } else { if (sizeof(unsigned int) <= sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(unsigned int) <= sizeof(long long)) { - return PyLong_FromLongLong((long long) value); + } else if (sizeof(unsigned int) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); } } { @@ -3408,21 +4154,21 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) } static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char value) { - const unsigned char neg_one = (unsigned char) -1, const_zero = 0; + const unsigned char neg_one = (unsigned char) -1, const_zero = (unsigned char) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(unsigned char) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(unsigned char) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); - } else if (sizeof(unsigned char) <= sizeof(unsigned long long)) { - return PyLong_FromUnsignedLongLong((unsigned long long) value); + } else if (sizeof(unsigned char) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); } } else { if (sizeof(unsigned char) <= sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(unsigned char) <= sizeof(long long)) { - return PyLong_FromLongLong((long long) value); + } else if (sizeof(unsigned char) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); } } { @@ -3433,24 +4179,17 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char valu } } -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" - #endif -#endif static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) { - const unsigned char neg_one = (unsigned char) -1, const_zero = 0; + const unsigned char neg_one = (unsigned char) -1, const_zero = (unsigned char) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(unsigned char) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(unsigned char, long, PyInt_AS_LONG) + __PYX_VERIFY_RETURN_INT(unsigned char, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned char"); - return (unsigned char) -1; + goto raise_neg_overflow; } return (unsigned char) val; } @@ -3458,42 +4197,125 @@ static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) { #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned char)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (unsigned char) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (unsigned char) 0; + case 1: __PYX_VERIFY_RETURN_INT(unsigned char, digit, digits[0]) + case 2: + if (8 * sizeof(unsigned char) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) >= 2 * PyLong_SHIFT) { + return (unsigned char) (((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(unsigned char) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) >= 3 * PyLong_SHIFT) { + return (unsigned char) (((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(unsigned char) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) >= 4 * PyLong_SHIFT) { + return (unsigned char) (((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0])); + } + } + break; } - #endif #endif +#if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned char"); - return (unsigned char) -1; + goto raise_neg_overflow; } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (unsigned char) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif if (sizeof(unsigned char) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, PyLong_AsUnsignedLong) - } else if (sizeof(unsigned char) <= sizeof(unsigned long long)) { - __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long long, PyLong_AsUnsignedLongLong) + __PYX_VERIFY_RETURN_INT_EXC(unsigned char, unsigned long, PyLong_AsUnsignedLong(x)) + } else if (sizeof(unsigned char) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) } } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(unsigned char)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(unsigned char) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(unsigned char) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (unsigned char) 0; + case -1: __PYX_VERIFY_RETURN_INT(unsigned char, sdigit, -(sdigit) digits[0]) + case 1: __PYX_VERIFY_RETURN_INT(unsigned char, digit, +digits[0]) + case -2: + if (8 * sizeof(unsigned char) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) { + return (unsigned char) (((unsigned char)-1)*(((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(unsigned char) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) { + return (unsigned char) ((((((unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(unsigned char) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) { + return (unsigned char) (((unsigned char)-1)*(((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(unsigned char) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) { + return (unsigned char) ((((((((unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(unsigned char) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) - 1 > 4 * PyLong_SHIFT) { + return (unsigned char) (((unsigned char)-1)*(((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(unsigned char) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(unsigned char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(unsigned char) - 1 > 4 * PyLong_SHIFT) { + return (unsigned char) ((((((((((unsigned char)digits[3]) << PyLong_SHIFT) | (unsigned char)digits[2]) << PyLong_SHIFT) | (unsigned char)digits[1]) << PyLong_SHIFT) | (unsigned char)digits[0]))); + } + } + break; } - #endif #endif if (sizeof(unsigned char) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT(unsigned char, long, PyLong_AsLong) - } else if (sizeof(unsigned char) <= sizeof(long long)) { - __PYX_VERIFY_RETURN_INT(unsigned char, long long, PyLong_AsLongLong) + __PYX_VERIFY_RETURN_INT_EXC(unsigned char, long, PyLong_AsLong(x)) + } else if (sizeof(unsigned char) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(unsigned char, PY_LONG_LONG, PyLong_AsLongLong(x)) } } { @@ -3531,26 +4353,27 @@ static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *x) { Py_DECREF(tmp); return val; } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to unsigned char"); + return (unsigned char) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to unsigned char"); + return (unsigned char) -1; } -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" - #endif -#endif static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { - const size_t neg_one = (size_t) -1, const_zero = 0; + const size_t neg_one = (size_t) -1, const_zero = (size_t) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(size_t) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG) + __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to size_t"); - return (size_t) -1; + goto raise_neg_overflow; } return (size_t) val; } @@ -3558,42 +4381,125 @@ static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(size_t)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (size_t) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (size_t) 0; + case 1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0]) + case 2: + if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) { + return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) { + return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) { + return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + } + break; } - #endif #endif +#if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to size_t"); - return (size_t) -1; + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (size_t) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; } +#endif if (sizeof(size_t) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, PyLong_AsUnsignedLong) - } else if (sizeof(size_t) <= sizeof(unsigned long long)) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long long, PyLong_AsUnsignedLongLong) + __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x)) + } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) } } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(size_t)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(size_t) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(size_t) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (size_t) 0; + case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, -(sdigit) digits[0]) + case 1: __PYX_VERIFY_RETURN_INT(size_t, digit, +digits[0]) + case -2: + if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) { + return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) { + return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) { + return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) { + return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) { + return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) { + return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]))); + } + } + break; } - #endif #endif if (sizeof(size_t) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT(size_t, long, PyLong_AsLong) - } else if (sizeof(size_t) <= sizeof(long long)) { - __PYX_VERIFY_RETURN_INT(size_t, long long, PyLong_AsLongLong) + __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x)) + } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x)) } } { @@ -3631,24 +4537,32 @@ static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { Py_DECREF(tmp); return val; } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to size_t"); + return (size_t) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to size_t"); + return (size_t) -1; } static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = 0; + const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); - } else if (sizeof(long) <= sizeof(unsigned long long)) { - return PyLong_FromUnsignedLongLong((unsigned long long) value); + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(long long)) { - return PyLong_FromLongLong((long long) value); + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); } } { @@ -3659,24 +4573,17 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { } } -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" - #endif -#endif static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { - const long neg_one = (long) -1, const_zero = 0; + const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(long) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG) + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long) -1; + goto raise_neg_overflow; } return (long) val; } @@ -3684,42 +4591,125 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (long) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0]) + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; } - #endif #endif +#if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to long"); - return (long) -1; + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; } +#endif if (sizeof(long) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong) - } else if (sizeof(long) <= sizeof(unsigned long long)) { - __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong) + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) } } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(long)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(long) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(long) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (long) 0; + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0]) + case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) + case -2: + if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(long) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(long) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(long) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; } - #endif #endif if (sizeof(long) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong) - } else if (sizeof(long) <= sizeof(long long)) { - __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong) + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) } } { @@ -3757,26 +4747,27 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { Py_DECREF(tmp); return val; } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; } -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" - #endif -#endif static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { - const int neg_one = (int) -1, const_zero = 0; + const int neg_one = (int) -1, const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { if (sizeof(int) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG) + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to int"); - return (int) -1; + goto raise_neg_overflow; } return (int) val; } @@ -3784,42 +4775,125 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { #endif if (likely(PyLong_Check(x))) { if (is_unsigned) { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(int)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return (int) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0]) + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; } - #endif #endif +#if CYTHON_COMPILING_IN_CPYTHON if (unlikely(Py_SIZE(x) < 0)) { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to int"); - return (int) -1; + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; } +#endif if (sizeof(int) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong) - } else if (sizeof(int) <= sizeof(unsigned long long)) { - __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong) + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) } } else { -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(int)) { - switch (Py_SIZE(x)) { - case 0: return 0; - case 1: return +(int) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(int) ((PyLongObject*)x)->ob_digit[0]; - } +#if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)x)->ob_digit; + switch (Py_SIZE(x)) { + case 0: return (int) 0; + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0]) + case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) + case -2: + if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if (8 * sizeof(int) > 1 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if (8 * sizeof(int) > 2 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if (8 * sizeof(int) > 3 * PyLong_SHIFT) { + if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; } - #endif #endif if (sizeof(int) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong) - } else if (sizeof(int) <= sizeof(long long)) { - __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong) + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) } } { @@ -3857,6 +4931,14 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { Py_DECREF(tmp); return val; } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; } static int __Pyx_check_binary_version(void) { @@ -3869,177 +4951,11 @@ static int __Pyx_check_binary_version(void) { "compiletime version %s of module '%.100s' " "does not match runtime version %s", ctversion, __Pyx_MODULE_NAME, rtversion); - #if PY_VERSION_HEX < 0x02050000 - return PyErr_Warn(NULL, message); - #else return PyErr_WarnEx(NULL, message, 1); - #endif } return 0; } -static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { - int start = 0, mid = 0, end = count - 1; - if (end >= 0 && code_line > entries[end].code_line) { - return count; - } - while (start < end) { - mid = (start + end) / 2; - if (code_line < entries[mid].code_line) { - end = mid; - } else if (code_line > entries[mid].code_line) { - start = mid + 1; - } else { - return mid; - } - } - if (code_line <= entries[mid].code_line) { - return mid; - } else { - return mid + 1; - } -} -static PyCodeObject *__pyx_find_code_object(int code_line) { - PyCodeObject* code_object; - int pos; - if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { - return NULL; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { - return NULL; - } - code_object = __pyx_code_cache.entries[pos].code_object; - Py_INCREF(code_object); - return code_object; -} -static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { - int pos, i; - __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; - if (unlikely(!code_line)) { - return; - } - if (unlikely(!entries)) { - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); - if (likely(entries)) { - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = 64; - __pyx_code_cache.count = 1; - entries[0].code_line = code_line; - entries[0].code_object = code_object; - Py_INCREF(code_object); - } - return; - } - pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); - if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { - PyCodeObject* tmp = entries[pos].code_object; - entries[pos].code_object = code_object; - Py_DECREF(tmp); - return; - } - if (__pyx_code_cache.count == __pyx_code_cache.max_count) { - int new_max = __pyx_code_cache.max_count + 64; - entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry)); - if (unlikely(!entries)) { - return; - } - __pyx_code_cache.entries = entries; - __pyx_code_cache.max_count = new_max; - } - for (i=__pyx_code_cache.count; i>pos; i--) { - entries[i] = entries[i-1]; - } - entries[pos].code_line = code_line; - entries[pos].code_object = code_object; - __pyx_code_cache.count++; - Py_INCREF(code_object); -} - -#include "compile.h" -#include "frameobject.h" -#include "traceback.h" -static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( - const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; - #if PY_MAJOR_VERSION < 3 - py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif - if (!py_srcfile) goto bad; - if (c_line) { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #else - py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); - #endif - } - else { - #if PY_MAJOR_VERSION < 3 - py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); - #endif - } - if (!py_funcname) goto bad; - py_code = __Pyx_PyCode_New( - 0, /*int argcount,*/ - 0, /*int kwonlyargcount,*/ - 0, /*int nlocals,*/ - 0, /*int stacksize,*/ - 0, /*int flags,*/ - __pyx_empty_bytes, /*PyObject *code,*/ - __pyx_empty_tuple, /*PyObject *consts,*/ - __pyx_empty_tuple, /*PyObject *names,*/ - __pyx_empty_tuple, /*PyObject *varnames,*/ - __pyx_empty_tuple, /*PyObject *freevars,*/ - __pyx_empty_tuple, /*PyObject *cellvars,*/ - py_srcfile, /*PyObject *filename,*/ - py_funcname, /*PyObject *name,*/ - py_line, /*int firstlineno,*/ - __pyx_empty_bytes /*PyObject *lnotab*/ - ); - Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); - return py_code; -bad: - Py_XDECREF(py_srcfile); - Py_XDECREF(py_funcname); - return NULL; -} -static void __Pyx_AddTraceback(const char *funcname, int c_line, - int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_globals = 0; - PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); - if (!py_code) { - py_code = __Pyx_CreateCodeObjectForTraceback( - funcname, c_line, py_line, filename); - if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); - } - py_globals = PyModule_GetDict(__pyx_m); - if (!py_globals) goto bad; - py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - py_globals, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ - ); - if (!py_frame) goto bad; - py_frame->f_lineno = py_line; - PyTraceBack_Here(py_frame); -bad: - Py_XDECREF(py_code); - Py_XDECREF(py_frame); -} - static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 @@ -4050,7 +4966,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { } else { *t->p = PyString_FromStringAndSize(t->s, t->n - 1); } - #else /* Python 3+ has unicode identifiers */ + #else if (t->is_unicode | t->is_str) { if (t->intern) { *t->p = PyUnicode_InternFromString(t->s); @@ -4070,15 +4986,15 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { return 0; } -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char* c_str) { - return __Pyx_PyUnicode_FromStringAndSize(c_str, strlen(c_str)); +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { -#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if ( #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII __Pyx_sys_getdefaultencoding_not_ascii && @@ -4100,26 +5016,26 @@ static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_ } } } -#endif /*__PYX_DEFAULT_STRING_ENCODING_IS_ASCII*/ +#endif *length = PyBytes_GET_SIZE(defenc); return defenc_c; -#else /* PY_VERSION_HEX < 0x03030000 */ - if (PyUnicode_READY(o) == -1) return NULL; +#else + if (__Pyx_PyUnicode_READY(o) == -1) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII if (PyUnicode_IS_ASCII(o)) { - *length = PyUnicode_GET_DATA_SIZE(o); + *length = PyUnicode_GET_LENGTH(o); return PyUnicode_AsUTF8(o); } else { PyUnicode_AsASCIIString(o); return NULL; } -#else /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */ +#else return PyUnicode_AsUTF8AndSize(o, length); -#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII */ -#endif /* PY_VERSION_HEX < 0x03030000 */ +#endif +#endif } else -#endif /* __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT */ -#if PY_VERSION_HEX >= 0x02060000 +#endif +#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) if (PyByteArray_Check(o)) { *length = PyByteArray_GET_SIZE(o); return PyByteArray_AS_STRING(o); @@ -4149,7 +5065,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { #else if (PyLong_Check(x)) #endif - return Py_INCREF(x), x; + return __Pyx_NewRef(x); m = Py_TYPE(x)->tp_as_number; #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { @@ -4185,33 +5101,61 @@ static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { } return res; } -#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" - #endif -#endif static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_ssize_t ival; PyObject *x; #if PY_MAJOR_VERSION < 3 - if (likely(PyInt_CheckExact(b))) - return PyInt_AS_LONG(b); + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(x); + } #endif if (likely(PyLong_CheckExact(b))) { - #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 - #if CYTHON_USE_PYLONG_INTERNALS - switch (Py_SIZE(b)) { - case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0]; - case 0: return 0; - case 1: return ((PyLongObject*)b)->ob_digit[0]; - } - #endif + #if CYTHON_USE_PYLONG_INTERNALS + const digit* digits = ((PyLongObject*)b)->ob_digit; + const Py_ssize_t size = Py_SIZE(b); + if (likely(__Pyx_sst_abs(size) <= 1)) { + ival = likely(size) ? digits[0] : 0; + if (size == -1) ival = -ival; + return ival; + } else { + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } #endif - #if PY_VERSION_HEX < 0x02060000 - return PyInt_AsSsize_t(b); - #else return PyLong_AsSsize_t(b); - #endif } x = PyNumber_Index(b); if (!x) return -1; @@ -4220,17 +5164,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { return ival; } static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { -#if PY_VERSION_HEX < 0x02050000 - if (ival <= LONG_MAX) - return PyInt_FromLong((long)ival); - else { - unsigned char *bytes = (unsigned char *) &ival; - int one = 1; int little = (int)*(unsigned char*)&one; - return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0); - } -#else - return PyInt_FromSize_t(ival); -#endif + return PyInt_FromSize_t(ival); } diff --git a/rtmidi_python.pyx b/rtmidi_python.pyx index bad9bc5..ee695a3 100644 --- a/rtmidi_python.pyx +++ b/rtmidi_python.pyx @@ -1,9 +1,11 @@ +# distutils: language = c++ + from cython.operator import dereference +from cpython.version cimport PY_MAJOR_VERSION from libcpp.string cimport string from libcpp.vector cimport vector - # Init Python threads and GIL, because RtMidi calls Python from native threads. # See http://permalink.gmane.org/gmane.comp.python.cython.user/5837 cdef extern from "Python.h": @@ -11,7 +13,6 @@ cdef extern from "Python.h": PyEval_InitThreads() - cdef extern from "RtMidi/RtMidi.h": ctypedef void (*RtMidiCallback)(double timeStamp, vector[unsigned char]* message, void* userData) @@ -45,12 +46,18 @@ cdef class MidiBase: if isinstance(port, int): port_number = port else: - port_number = self.ports.index(port) + if PY_MAJOR_VERSION < 3: + port_number = self.ports.index(port) + else: + port_number = [x.decode('UTF-8') for x in self.ports].index(port) self.baseptr().openPort(port_number) def open_virtual_port(self, port_name="RtMidi"): - self.baseptr().openVirtualPort(string(port_name)) + if PY_MAJOR_VERSION < 3: + self.baseptr().openVirtualPort(string(port_name)) + else: + self.baseptr().openVirtualPort(port_name.encode('UTF-8')) property ports: def __get__(self): @@ -69,7 +76,10 @@ cdef class MidiIn(MidiBase): cdef object py_callback def __cinit__(self, client_name="RtMidi Input Client", queue_size_limit=100): - self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + if PY_MAJOR_VERSION < 3: + self.thisptr = new RtMidiIn(UNSPECIFIED, string(client_name), queue_size_limit) + else: + self.thisptr = new RtMidiIn(UNSPECIFIED, client_name.encode('UTF-8'), queue_size_limit) self.py_callback = None def __dealloc__(self): @@ -108,7 +118,10 @@ cdef class MidiOut(MidiBase): cdef RtMidiOut* thisptr def __cinit__(self, client_name="RtMidi Output Client"): - self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + if PY_MAJOR_VERSION < 3: + self.thisptr = new RtMidiOut(UNSPECIFIED, string(client_name)) + else: + self.thisptr = new RtMidiOut(UNSPECIFIED, client_name.encode('UTF-8')) def __dealloc__(self): del self.thisptr diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..7a186d3 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist=py27,py34 + +[testenv] +skip_install=True +deps= + cython +commands= + python setup.py install --from-cython + python tests.py