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
10388ed9
Commit
10388ed9
authored
May 24, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP method wrapper generation
parent
8a0d878a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
18 deletions
+37
-18
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+26
-9
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+11
-9
No files found.
Cython/Compiler/CypclassWrapper.py
View file @
10388ed9
...
@@ -114,7 +114,7 @@ def generate_cypclass_method_py_wrappers(method_entry, cyp_entry, code):
...
@@ -114,7 +114,7 @@ def generate_cypclass_method_py_wrappers(method_entry, cyp_entry, code):
# header
# header
self_arg_cname
=
"%s_self"
%
Naming
.
arg_prefix
self_arg_cname
=
"%s_self"
%
Naming
.
arg_prefix
self_arg_decl
=
"PyObject *%s"
%
self_arg_cname
self_arg_decl
=
"
Cy
PyObject *%s"
%
self_arg_cname
code
.
put
(
"PyObject *%s(%s"
%
(
py_wrapper_cname
,
self_arg_decl
))
code
.
put
(
"PyObject *%s(%s"
%
(
py_wrapper_cname
,
self_arg_decl
))
for
i
in
range
(
0
,
max_args
):
for
i
in
range
(
0
,
max_args
):
code
.
put
(
", PyObject *%s%d"
%
(
Naming
.
arg_prefix
,
i
))
code
.
put
(
", PyObject *%s%d"
%
(
Naming
.
arg_prefix
,
i
))
...
@@ -124,6 +124,10 @@ def generate_cypclass_method_py_wrappers(method_entry, cyp_entry, code):
...
@@ -124,6 +124,10 @@ def generate_cypclass_method_py_wrappers(method_entry, cyp_entry, code):
code
.
putln
(
"{"
)
code
.
putln
(
"{"
)
code
.
enter_cfunc_scope
()
code
.
enter_cfunc_scope
()
this_var_cname
=
"%s_this"
%
Naming
.
var_prefix
this_var_decl
=
"%s *%s"
%
(
cyp_entry
.
cname
,
this_var_cname
)
code
.
putln
(
"%s = reinterpret_cast<%s *>(%s->nogil_cyobject);"
%
(
this_var_decl
,
cyp_entry
.
cname
,
self_arg_cname
))
# - the simple case: only 1 signature
# - the simple case: only 1 signature
if
(
nb_alt
==
1
):
if
(
nb_alt
==
1
):
...
@@ -143,11 +147,25 @@ def generate_cypclass_method_py_wrappers(method_entry, cyp_entry, code):
...
@@ -143,11 +147,25 @@ def generate_cypclass_method_py_wrappers(method_entry, cyp_entry, code):
code
.
putln
(
"%s;"
%
c_var_decl
)
code
.
putln
(
"%s;"
%
c_var_decl
)
code
.
putln
(
cast_code
)
code
.
putln
(
cast_code
)
# call C method
# declare result, mangle with existing argument to avoid collision
# code.put("%s->%s(" % (this_var_cname, method_entry.cname))
c_return_type
=
method_entry
.
type
.
return_type
# for i, c_arg in enumerate(c_arg_names, 1):
if
not
c_return_type
.
is_void
:
# code.put("%s%s" % (c_arg, ", " if i < len(c_arg_names) else ""))
c_result_cname
=
"%s_%s_result"
%
(
Naming
.
var_prefix
,
c_arg_names
[
0
]
if
c_arg_names
else
""
)
# code.put(")")
c_result_decl
=
method_entry
.
type
.
return_type
.
declaration_code
(
c_result_cname
)
code
.
putln
(
"%s;"
%
c_result_decl
)
# store result
c_call_code_begin
=
"%s = %s->%s"
%
(
c_result_cname
,
this_var_cname
,
method_entry
.
cname
)
else
:
# no result to be stored
c_call_code_begin
=
"%s->%s"
%
(
this_var_cname
,
method_entry
.
cname
)
# call c method
code
.
put
(
"%s("
%
c_call_code_begin
)
for
i
,
c_arg
in
enumerate
(
c_arg_names
,
1
):
code
.
put
(
"%s%s"
%
(
c_arg
,
", "
if
i
<
len
(
c_arg_names
)
else
""
))
code
.
putln
(
");"
)
# else:
# else:
code
.
putln
(
"return %s; // for now"
%
self_arg_cname
)
code
.
putln
(
"return %s; // for now"
%
self_arg_cname
)
...
@@ -651,9 +669,8 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
...
@@ -651,9 +669,8 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
# initialise PyObject fields
# initialise PyObject fields
if
(
is_new_return_type
):
if
(
is_new_return_type
):
code
.
putln
(
"if(self) {"
)
code
.
putln
(
"if(self) {"
)
code
.
putln
(
"self->ob_refcnt = 0;"
)
code
.
putln
(
"self->ob_cypyobject->ob_refcnt = 0;"
)
# code.putln("self->ob_type = NULL;")
code
.
putln
(
"self->ob_cypyobject->ob_type = &%s;"
%
type
.
typeobj_cname
)
code
.
putln
(
"self->ob_type = &%s;"
%
type
.
typeobj_cname
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
if
init_entry
:
if
init_entry
:
...
...
Cython/Utility/CyObjects.cpp
View file @
10388ed9
...
@@ -56,11 +56,11 @@
...
@@ -56,11 +56,11 @@
int
trywlock
();
int
trywlock
();
};
};
template
<
typename
T
>
class
CyObject
;
struct
CyPyObject
{
PyObject_HEAD
struct
CyPyObject
:
public
PyObject
{
T
*
cyobject
;
CyObject
*
nogil_
cyobject
;
}
}
;
class
CyObject
{
class
CyObject
{
private:
private:
...
@@ -68,6 +68,7 @@
...
@@ -68,6 +68,7 @@
//pthread_rwlock_t ob_lock;
//pthread_rwlock_t ob_lock;
RecursiveUpgradeableRWLock
ob_lock
;
RecursiveUpgradeableRWLock
ob_lock
;
public:
public:
CyPyObject
*
ob_cypyobject
;
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
virtual
~
CyObject
()
{}
virtual
~
CyObject
()
{}
void
CyObject_INCREF
();
void
CyObject_INCREF
();
...
@@ -175,13 +176,14 @@
...
@@ -175,13 +176,14 @@
* are likely (certain even?) to be followed by a Cy_DECREF; stealing the
* are likely (certain even?) to be followed by a Cy_DECREF; stealing the
* 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
*
ob
)
{
static
inline
PyObject
*
__Pyx_PyObject_FromCyObject
(
CyObject
*
cy
)
{
CyPyObject
*
ob
=
cy
->
ob_cypyobject
;
// 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
)
ob
->
CyObject_INCREF
();
cy
->
CyObject_INCREF
();
// return a new Python reference
// return a new Python reference
Py_INCREF
(
(
PyObject
*
)
ob
);
Py_INCREF
(
ob
);
return
(
PyObject
*
)
ob
;
return
ob
;
}
}
/* Cast argument to CyObject* type. */
/* Cast argument to CyObject* type. */
...
...
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