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
8b158e72
Commit
8b158e72
authored
4 years ago
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CypclassWrapper.py to regroup code generation process
parent
ae6700cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
11 deletions
+42
-11
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+40
-0
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+2
-11
No files found.
Cython/Compiler/CypclassWrapper.py
0 → 100644
View file @
8b158e72
#
# Code generation for wrapping cypclass as a Python Extension Type
#
# Will be generated:
# - a PyTypeObject definition for each user defined cypclass
# - Python wrappers for cypclass methods
# - Python getters/setters for cypclass attributes
# - Specific 'tp slots' for handling cycplass objects from Python:
# . tp_new
# . tp_init
# . tp_dealloc
# ...
#
# Functions defined here will be called from ModuleNode.py
#
# Reasons for using a separate file:
# - avoid cluttering ModuleNode.py
# - regroup common logic
# - decouple the code generation process from that of 'cdef class'
#
# Code generation for cypclass will be similar to code generation for 'cdef class' in ModuleNode.py,
# but differences are significant enough that it is better to introduce some redundancy than try to
# handle both 'cdef class' and 'cypclass' in ModuleNode.py.
#
def
generate_cypclass_typeobj_declarations
(
env
,
code
,
definition
):
"""
Generate declarations of global pointers to the PyTypeObject for each cypclass
"""
for
entry
in
env
.
cypclass_entries
:
if
definition
or
entry
.
defined_in_pxd
:
code
.
putln
(
"static PyTypeObject *%s = 0;"
%
(
entry
.
type
.
typeptr_cname
))
cyp_scope
=
entry
.
type
.
scope
if
cyp_scope
:
# generate declarations for nested cycplasses
generate_cypclass_typeobj_declarations
(
cyp_scope
,
code
,
definition
)
This diff is collapsed.
Click to expand it.
Cython/Compiler/ModuleNode.py
View file @
8b158e72
...
...
@@ -19,6 +19,7 @@ from .PyrexTypes import CPtrType
from
.
import
Future
from
.
import
Annotate
from
.
import
Code
from
.
import
CypclassWrapper
from
.
import
Naming
from
.
import
Nodes
from
.
import
Options
...
...
@@ -615,7 +616,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
modulecode
.
putln
(
""
)
modulecode
.
putln
(
"/* Module declarations from '%s' */"
%
module
.
qualified_name
)
self
.
generate_c_class_declarations
(
module
,
modulecode
,
defined_here
)
self
.
generate_cypclass_typeobj_declarations
(
module
,
modulecode
,
defined_here
)
CypclassWrapper
.
generate_cypclass_typeobj_declarations
(
module
,
modulecode
,
defined_here
)
self
.
generate_cvariable_declarations
(
module
,
modulecode
,
defined_here
)
self
.
generate_cfunction_declarations
(
module
,
modulecode
,
defined_here
)
...
...
@@ -1807,16 +1808,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
definition
or
entry
.
defined_in_pxd
:
code
.
putln
(
"static PyTypeObject *%s = 0;"
%
(
entry
.
type
.
typeptr_cname
))
def
generate_cypclass_typeobj_declarations
(
self
,
env
,
code
,
definition
):
for
entry
in
env
.
cypclass_entries
:
if
definition
or
entry
.
defined_in_pxd
:
code
.
putln
(
"static PyTypeObject *%s = 0;"
%
(
entry
.
type
.
typeptr_cname
))
cyp_scope
=
entry
.
type
.
scope
if
cyp_scope
:
# generate declarations for nested cycplasses
self
.
generate_cypclass_typeobj_declarations
(
cyp_scope
,
code
,
definition
)
def
generate_cvariable_declarations
(
self
,
env
,
code
,
definition
):
if
env
.
is_cython_builtin
:
...
...
This diff is collapsed.
Click to expand it.
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