Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
1bd40102
Commit
1bd40102
authored
Jul 09, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document C inline properties.
parent
abbe3eef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
docs/examples/userguide/extension_types/c_property.pyx
docs/examples/userguide/extension_types/c_property.pyx
+20
-0
docs/src/userguide/extension_types.rst
docs/src/userguide/extension_types.rst
+12
-0
No files found.
docs/examples/userguide/extension_types/c_property.pyx
0 → 100644
View file @
1bd40102
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.
docs/src/userguide/extension_types.rst
View file @
1bd40102
...
...
@@ -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
------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment