cdef extern from "Python.h":
- ctypedef struct Py_complex
+
+ ctypedef struct Py_complex:
+ double imag
+ double real
############################################################################
# 7.2.5.2 Complex Numbers as Python Objects
# PyComplexObject
# This subtype of PyObject represents a Python complex number object.
+ ctypedef class __builtin__.complex [object PyComplexObject]:
+ cdef Py_complex cval
+ # not making these available to keep them read-only:
+ #cdef double imag "cval.imag"
+ #cdef double real "cval.real"
+
# PyTypeObject PyComplex_Type
# This instance of PyTypeObject represents the Python complex
# number type. It is the same object as complex and
--- /dev/null
+
+from cpython.complex cimport complex
+
+def complex_attributes():
+ """
+ >>> complex_attributes()
+ (1.0, 2.0)
+ """
+ cdef complex c = 1+2j
+ return (c.real, c.imag)
+
+def complex_attributes_assign():
+ """
+ >>> complex_attributes_assign()
+ (10.0, 20.0)
+ """
+ cdef complex c = 1+2j
+ c.cval.real, c.cval.imag = 10, 20
+ return (c.real, c.imag)
+
+def complex_cstruct_assign():
+ """
+ >>> complex_cstruct_assign()
+ (10.0, 20.0)
+ """
+ cdef complex c = 1+2j
+ cval = &c.cval
+ cval.real, cval.imag = 10, 20
+ return (c.real, c.imag)