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
c23e1b61
Commit
c23e1b61
authored
May 22, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CypclassWrapper.py to regroup code generation process
parent
5ec3a112
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 @
c23e1b61
#
# 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
)
Cython/Compiler/ModuleNode.py
View file @
c23e1b61
...
@@ -19,6 +19,7 @@ from .PyrexTypes import CPtrType
...
@@ -19,6 +19,7 @@ from .PyrexTypes import CPtrType
from
.
import
Future
from
.
import
Future
from
.
import
Annotate
from
.
import
Annotate
from
.
import
Code
from
.
import
Code
from
.
import
CypclassWrapper
from
.
import
Naming
from
.
import
Naming
from
.
import
Nodes
from
.
import
Nodes
from
.
import
Options
from
.
import
Options
...
@@ -615,7 +616,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -615,7 +616,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
modulecode
.
putln
(
""
)
modulecode
.
putln
(
""
)
modulecode
.
putln
(
"/* Module declarations from '%s' */"
%
module
.
qualified_name
)
modulecode
.
putln
(
"/* Module declarations from '%s' */"
%
module
.
qualified_name
)
self
.
generate_c_class_declarations
(
module
,
modulecode
,
defined_here
)
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_cvariable_declarations
(
module
,
modulecode
,
defined_here
)
self
.
generate_cfunction_declarations
(
module
,
modulecode
,
defined_here
)
self
.
generate_cfunction_declarations
(
module
,
modulecode
,
defined_here
)
...
@@ -1805,16 +1806,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1805,16 +1806,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
definition
or
entry
.
defined_in_pxd
:
if
definition
or
entry
.
defined_in_pxd
:
code
.
putln
(
"static PyTypeObject *%s = 0;"
%
(
code
.
putln
(
"static PyTypeObject *%s = 0;"
%
(
entry
.
type
.
typeptr_cname
))
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
):
def
generate_cvariable_declarations
(
self
,
env
,
code
,
definition
):
if
env
.
is_cython_builtin
:
if
env
.
is_cython_builtin
:
...
...
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