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
2045368a
Commit
2045368a
authored
May 27, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose simple cypclass methods to Python
parent
10a2c693
Changes
3
Hide 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 @
2045368a
...
@@ -742,10 +742,14 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
...
@@ -742,10 +742,14 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
# initialise PyObject fields
# initialise PyObject fields
if
is_new_return_type
and
type
.
wrapper_type
:
if
is_new_return_type
and
type
.
wrapper_type
:
objstruct_cname
=
type
.
wrapper_type
.
objstruct_cname
code
.
putln
(
"if(self) {"
)
code
.
putln
(
"if(self) {"
)
code
.
putln
(
"self->ob_cypyobject = new CyPyObject(); // fow now"
)
# % type.wrapper_type.objstruct_cname
code
.
putln
(
"%s * wrapper = new %s();"
%
(
objstruct_cname
,
objstruct_cname
))
code
.
putln
(
"self->ob_cypyobject->ob_refcnt = 0;"
)
code
.
putln
(
"wrapper->nogil_cyobject = self;"
)
code
.
putln
(
"self->ob_cypyobject->ob_type = %s;"
%
type
.
wrapper_type
.
typeptr_cname
)
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
(
"}"
)
code
.
putln
(
"}"
)
if
init_entry
:
if
init_entry
:
...
...
Cython/Compiler/ModuleNode.py
View file @
2045368a
...
@@ -654,9 +654,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -654,9 +654,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
""
)
code
.
putln
(
""
)
code
.
putln
(
"/* PyTypeObject pointer declarations for all c classes */"
)
code
.
putln
(
"/* PyTypeObject pointer declarations for all c classes */"
)
self
.
generate_c_class_declarations
(
module
,
code
,
definition
,
globalstate
)
self
.
generate_c_class_declarations
(
module
,
code
,
definition
,
globalstate
)
code
.
putln
(
""
)
code
.
putln
(
"/* Deferred definitions for cypclasses */"
)
CypclassWrapper
.
generate_cyp_class_deferred_definitions
(
env
,
code
,
definition
)
for
entry
in
vtabslot_list
:
for
entry
in
vtabslot_list
:
self
.
generate_objstruct_definition
(
entry
.
type
,
code
)
self
.
generate_objstruct_definition
(
entry
.
type
,
code
)
...
@@ -666,6 +663,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -666,6 +663,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_exttype_vtable_struct
(
entry
,
code
)
self
.
generate_exttype_vtable_struct
(
entry
,
code
)
self
.
generate_exttype_vtabptr_declaration
(
entry
,
code
)
self
.
generate_exttype_vtabptr_declaration
(
entry
,
code
)
self
.
generate_exttype_final_methods_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
):
def
generate_declarations_for_modules
(
self
,
env
,
modules
,
globalstate
):
typecode
=
globalstate
[
'type_declarations'
]
typecode
=
globalstate
[
'type_declarations'
]
...
...
Cython/Utility/CyObjects.cpp
View file @
2045368a
...
@@ -56,19 +56,13 @@
...
@@ -56,19 +56,13 @@
int
trywlock
();
int
trywlock
();
};
};
class
CyObject
;
struct
CyPyObject
:
public
PyObject
{
CyObject
*
nogil_cyobject
;
};
class
CyObject
{
class
CyObject
{
private:
private:
CyObject_ATOMIC_REFCOUNT_TYPE
nogil_ob_refcnt
;
CyObject_ATOMIC_REFCOUNT_TYPE
nogil_ob_refcnt
;
//pthread_rwlock_t ob_lock;
//pthread_rwlock_t ob_lock;
RecursiveUpgradeableRWLock
ob_lock
;
RecursiveUpgradeableRWLock
ob_lock
;
public:
public:
CyPyObject
*
ob_cy
pyobject
;
PyObject
*
cy_
pyobject
;
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
virtual
~
CyObject
()
{}
virtual
~
CyObject
()
{}
void
CyObject_INCREF
();
void
CyObject_INCREF
();
...
@@ -177,7 +171,12 @@
...
@@ -177,7 +171,12 @@
* reference would mean that Cy_DECREF should not be called after this.
* reference would mean that Cy_DECREF should not be called after this.
*/
*/
static
inline
PyObject
*
__Pyx_PyObject_FromCyObject
(
CyObject
*
cy
)
{
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
// artificial atomic increment the first time Python gets a reference
if
(
ob
->
ob_refcnt
==
0
)
if
(
ob
->
ob_refcnt
==
0
)
cy
->
CyObject_INCREF
();
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