From fe77570aceeb848f45b90638b2f89aa2ae4c26ea Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 2 Nov 2013 22:00:04 +0100 Subject: [PATCH] fix C pointer coercion problem when coercing bytes to signed char* --- Cython/Compiler/PyrexTypes.py | 5 ++++- Cython/Utility/TypeConversion.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 0051d3d..9acb103 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -2085,7 +2085,10 @@ class CPointerBaseType(CType): if base_type.signed: self.to_py_function = "__Pyx_PyObject_FromString" if self.is_ptr: - self.from_py_function = "__Pyx_PyObject_AsString" + if base_type.signed == 2: + self.from_py_function = "__Pyx_PyObject_AsSString" + else: + self.from_py_function = "__Pyx_PyObject_AsString" else: self.to_py_function = "__Pyx_PyObject_FromUString" if self.is_ptr: diff --git a/Cython/Utility/TypeConversion.c b/Cython/Utility/TypeConversion.c index 7046d60..2a41caa 100644 --- a/Cython/Utility/TypeConversion.c +++ b/Cython/Utility/TypeConversion.c @@ -19,6 +19,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(char*); #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #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) -- 2.7.4