Commit 1bd40102 authored by Stefan Behnel's avatar Stefan Behnel

Document C inline properties.

parent abbe3eef
cdef extern from "complexobject.h":
struct Py_complex:
double real
double imag
ctypedef class __builtin__.complex [object PyComplexObject]:
cdef Py_complex cval
@property
cdef inline double real(self):
return self.cval.real
@property
cdef inline double imag(self):
return self.cval.imag
def cprint(complex c):
print(f"{c.real}+{c.imag}j") # uses C calls to the above property methods.
......@@ -959,6 +959,18 @@ code. No changes to Python need be made to achieve significant speedups, even
though the field names in Python and C are different. Of course, one should
make sure the fields are equivalent.
C inline properties
-------------------
Similar to Python property attributes, Cython provides a way to declare C-level
properties on external extension types. This is often used to shadow Python
attributes through faster C level data access, but can also be used to add certain
functionality to existing types when using them from Cython.
For example, the above ``complex`` type could also be declared like this:
.. literalinclude:: ../../examples/userguide/extension_types/c_property.pyx
Implicit importing
------------------
......
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