Commit 01e07901 authored by Stefan Behnel's avatar Stefan Behnel

merge

parents cc9c688a c0f91a65
...@@ -10,7 +10,7 @@ import Naming ...@@ -10,7 +10,7 @@ import Naming
class AutoTestDictTransform(ScopeTrackingTransform): class AutoTestDictTransform(ScopeTrackingTransform):
# Handles autotestdict directive # Handles autotestdict directive
blacklist = ['__cinit__', '__dealloc__', '__richcmp__'] blacklist = ['__cinit__', '__dealloc__', '__richcmp__', '__nonzero__']
def visit_ModuleNode(self, node): def visit_ModuleNode(self, node):
self.scope_type = 'module' self.scope_type = 'module'
......
...@@ -16,7 +16,7 @@ from Errors import error, warning, InternalError ...@@ -16,7 +16,7 @@ from Errors import error, warning, InternalError
import Naming import Naming
import PyrexTypes import PyrexTypes
import TypeSlots import TypeSlots
from PyrexTypes import py_object_type, error_type, CTypedefType, CFuncType from PyrexTypes import py_object_type, error_type, CFuncType
from Symtab import ModuleScope, LocalScope, GeneratorLocalScope, \ from Symtab import ModuleScope, LocalScope, GeneratorLocalScope, \
StructOrUnionScope, PyClassScope, CClassScope StructOrUnionScope, PyClassScope, CClassScope
from Cython.Utils import open_new_file, replace_suffix from Cython.Utils import open_new_file, replace_suffix
......
...@@ -150,6 +150,15 @@ class PyrexType(BaseType): ...@@ -150,6 +150,15 @@ class PyrexType(BaseType):
# type information of the struct. # type information of the struct.
return 1 return 1
def create_typedef_type(cname, base_type, is_external=0):
if base_type.is_complex:
if is_external:
raise ValueError("Complex external typedefs not supported")
return base_type
else:
return CTypedefType(cname, base_type, is_external)
class CTypedefType(BaseType): class CTypedefType(BaseType):
# #
# Pseudo-type defined with a ctypedef statement in a # Pseudo-type defined with a ctypedef statement in a
...@@ -170,6 +179,7 @@ class CTypedefType(BaseType): ...@@ -170,6 +179,7 @@ class CTypedefType(BaseType):
def __init__(self, cname, base_type, is_external=0): def __init__(self, cname, base_type, is_external=0):
assert not base_type.is_complex
self.typedef_cname = cname self.typedef_cname = cname
self.typedef_base_type = base_type self.typedef_base_type = base_type
self.typedef_is_external = is_external self.typedef_is_external = is_external
...@@ -877,8 +887,6 @@ class CComplexType(CNumericType): ...@@ -877,8 +887,6 @@ class CComplexType(CNumericType):
None, None,
visibility="extern") visibility="extern")
scope.parent_type = self scope.parent_type = self
scope.declare_var("real", self.real_type, None, "real", is_cdef=True) scope.declare_var("real", self.real_type, None, "real", is_cdef=True)
scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True) scope.declare_var("imag", self.real_type, None, "imag", is_cdef=True)
entry = scope.declare_cfunction( entry = scope.declare_cfunction(
......
...@@ -342,7 +342,11 @@ class Scope(object): ...@@ -342,7 +342,11 @@ class Scope(object):
cname = name cname = name
else: else:
cname = self.mangle(Naming.type_prefix, name) cname = self.mangle(Naming.type_prefix, name)
type = PyrexTypes.CTypedefType(cname, base_type, (visibility == 'extern')) try:
type = PyrexTypes.create_typedef_type(cname, base_type, (visibility == 'extern'))
except ValueError, e:
error(pos, e.message)
type = PyrexTypes.error_type
entry = self.declare_type(name, type, pos, cname, visibility) entry = self.declare_type(name, type, pos, cname, visibility)
type.qualified_name = entry.qualified_name type.qualified_name = entry.qualified_name
return entry return entry
......
...@@ -293,12 +293,6 @@ cdef extern from "numpy/arrayobject.h": ...@@ -293,12 +293,6 @@ cdef extern from "numpy/arrayobject.h":
ctypedef long double npy_float96 ctypedef long double npy_float96
ctypedef long double npy_float128 ctypedef long double npy_float128
ctypedef float complex npy_complex64
ctypedef double complex npy_complex128
ctypedef long double complex npy_complex120
ctypedef long double complex npy_complex192
ctypedef long double complex npy_complex256
ctypedef struct npy_cfloat: ctypedef struct npy_cfloat:
double real double real
double imag double imag
...@@ -311,6 +305,26 @@ cdef extern from "numpy/arrayobject.h": ...@@ -311,6 +305,26 @@ cdef extern from "numpy/arrayobject.h":
double real double real
double imag double imag
ctypedef struct npy_complex64:
double real
double imag
ctypedef struct npy_complex128:
double real
double imag
ctypedef struct npy_complex160:
double real
double imag
ctypedef struct npy_complex192:
double real
double imag
ctypedef struct npy_complex256:
double real
double imag
ctypedef struct PyArray_Dims: ctypedef struct PyArray_Dims:
npy_intp *ptr npy_intp *ptr
int len int len
......
...@@ -102,5 +102,12 @@ cdef class MyCdefClass: ...@@ -102,5 +102,12 @@ cdef class MyCdefClass:
False False
""" """
def __nonzero__(self):
"""
Should not be included, as it can't be looked up with getattr in Py 3.1
>>> True
False
"""
...@@ -11,11 +11,15 @@ if sys.version_info[0] >= 3: ...@@ -11,11 +11,15 @@ if sys.version_info[0] >= 3:
b'abcdefg' b'abcdefg'
>>> m1 = memoryview(b1) >>> m1 = memoryview(b1)
__getbuffer__ called
>>> m1.tobytes() >>> m1.tobytes()
__getbuffer__ called
b'abcdefg' b'abcdefg'
>>> m2 = memoryview(b2) >>> m2 = memoryview(b2)
__getbuffer__ called
>>> m2.tobytes() >>> m2.tobytes()
__getbuffer__ called
releasing! releasing!
b'abcdefg' b'abcdefg'
...@@ -24,10 +28,11 @@ b'abcdefg' ...@@ -24,10 +28,11 @@ b'abcdefg'
releasing! releasing!
""" """
s = "abcdefg" s = b"abcdefg"
cdef class TestBuffer: cdef class TestBuffer:
def __getbuffer__(self, Py_buffer* buffer, int flags): def __getbuffer__(self, Py_buffer* buffer, int flags):
print u"__getbuffer__ called"
buffer.buf = <char*>s buffer.buf = <char*>s
buffer.obj = self buffer.obj = self
buffer.len = len(s) buffer.len = len(s)
......
...@@ -116,3 +116,8 @@ def test_conjugate(float complex z): ...@@ -116,3 +116,8 @@ def test_conjugate(float complex z):
def test_conjugate_double(double complex z): def test_conjugate_double(double complex z):
return z.conjugate() return z.conjugate()
ctypedef double complex cdouble
def test_conjugate_typedef(cdouble z):
return z.conjugate()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment