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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
cd7afe2a
Commit
cd7afe2a
authored
May 27, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose simple cypclass methods to Python
parent
f401af05
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+7
-3
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+6
-3
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+7
-8
No files found.
Cython/Compiler/CypclassWrapper.py
View file @
cd7afe2a
...
...
@@ -742,10 +742,14 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
# initialise PyObject fields
if
is_new_return_type
and
type
.
wrapper_type
:
objstruct_cname
=
type
.
wrapper_type
.
objstruct_cname
code
.
putln
(
"if(self) {"
)
code
.
putln
(
"self->ob_cypyobject = new CyPyObject(); // fow now"
)
# % type.wrapper_type.objstruct_cname
code
.
putln
(
"self->ob_cypyobject->ob_refcnt = 0;"
)
code
.
putln
(
"self->ob_cypyobject->ob_type = %s;"
%
type
.
wrapper_type
.
typeptr_cname
)
code
.
putln
(
"%s * wrapper = new %s();"
%
(
objstruct_cname
,
objstruct_cname
))
code
.
putln
(
"wrapper->nogil_cyobject = self;"
)
code
.
putln
(
"PyObject * wrapper_as_py = (PyObject *) wrapper;"
)
code
.
putln
(
"wrapper_as_py->ob_refcnt = 0;"
)
code
.
putln
(
"wrapper_as_py->ob_type = %s;"
%
type
.
wrapper_type
.
typeptr_cname
)
code
.
putln
(
"self->cy_pyobject = wrapper_as_py;"
)
code
.
putln
(
"}"
)
if
init_entry
:
...
...
Cython/Compiler/ModuleNode.py
View file @
cd7afe2a
...
...
@@ -589,9 +589,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
""
)
code
.
putln
(
"/* PyTypeObject pointer declarations for all c classes */"
)
self
.
generate_c_class_declarations
(
module
,
code
,
definition
)
code
.
putln
(
""
)
code
.
putln
(
"/* Deferred definitions for cypclasses */"
)
CypclassWrapper
.
generate_cyp_class_deferred_definitions
(
env
,
code
,
definition
)
for
entry
in
vtabslot_list
:
self
.
generate_objstruct_definition
(
entry
.
type
,
code
)
...
...
@@ -602,6 +599,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_exttype_vtabptr_declaration
(
entry
,
code
)
self
.
generate_exttype_final_methods_declaration
(
entry
,
code
)
for
module
in
modules
:
definition
=
module
is
env
code
.
putln
(
""
)
code
.
putln
(
"/* Deferred definitions for cypclasses */"
)
CypclassWrapper
.
generate_cyp_class_deferred_definitions
(
env
,
code
,
definition
)
def
generate_declarations_for_modules
(
self
,
env
,
modules
,
globalstate
):
typecode
=
globalstate
[
'type_declarations'
]
typecode
.
putln
(
""
)
...
...
Cython/Utility/CyObjects.cpp
View file @
cd7afe2a
...
...
@@ -56,19 +56,13 @@
int
trywlock
();
};
class
CyObject
;
struct
CyPyObject
:
public
PyObject
{
CyObject
*
nogil_cyobject
;
};
class
CyObject
{
private:
CyObject_ATOMIC_REFCOUNT_TYPE
nogil_ob_refcnt
;
//pthread_rwlock_t ob_lock;
RecursiveUpgradeableRWLock
ob_lock
;
public:
CyPyObject
*
ob_cy
pyobject
;
PyObject
*
cy_
pyobject
;
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
virtual
~
CyObject
()
{}
void
CyObject_INCREF
();
...
...
@@ -177,7 +171,12 @@
* reference would mean that Cy_DECREF should not be called after this.
*/
static
inline
PyObject
*
__Pyx_PyObject_FromCyObject
(
CyObject
*
cy
)
{
CyPyObject
*
ob
=
cy
->
ob_cypyobject
;
// convert NULL to None
if
(
cy
==
NULL
)
{
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyObject
*
ob
=
cy
->
cy_pyobject
;
// artificial atomic increment the first time Python gets a reference
if
(
ob
->
ob_refcnt
==
0
)
cy
->
CyObject_INCREF
();
...
...
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