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
02e08b9b
Commit
02e08b9b
authored
May 27, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow conversion from PyObject to CyObject
parent
2045368a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+15
-0
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+25
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
02e08b9b
...
...
@@ -4214,6 +4214,21 @@ class CypClassType(CppClassType):
self
.
to_py_function
=
"__Pyx_PyObject_FromCyObject"
return
True
def
create_from_py_utility_code
(
self
,
env
):
if
not
self
.
wrapper_type
:
return
False
wrapper_objstruct
=
self
.
wrapper_type
.
objstruct_cname
underlying_type_name
=
self
.
cname
self
.
from_py_function
=
"__Pyx_PyObject_AsCyObject<%s, %s>"
%
(
wrapper_objstruct
,
underlying_type_name
)
return
True
def
from_py_call_code
(
self
,
source_code
,
result_code
,
error_pos
,
code
,
from_py_function
=
None
,
error_condition
=
None
):
extra_args
=
[
self
.
wrapper_type
.
typeptr_cname
if
self
.
wrapper_type
else
None
]
return
self
.
_assign_from_py_code
(
source_code
,
result_code
,
error_pos
,
code
,
from_py_function
,
error_condition
,
extra_args
=
extra_args
)
def
empty_declaration_code
(
self
):
if
self
.
_empty_declaration
is
None
:
self
.
_empty_declaration
=
self
.
declaration_code
(
''
,
deref
=
1
)
...
...
Cython/Utility/CyObjects.cpp
View file @
02e08b9b
...
...
@@ -185,6 +185,31 @@
return
ob
;
}
/*
* Cast from CyObject to PyObject:
* - borrow an Python reference
* - return a new atomic reference
*
* template:
* - W: the type of the extension type wrapper
* - U: the type of the underlying cypclass
* - T: pointer to the PyTypeObject instance of the wrapper
*/
template
<
typename
W
,
typename
U
>
static
inline
U
*
__Pyx_PyObject_AsCyObject
(
PyObject
*
ob
,
PyTypeObject
*
type
)
{
// the PyObject is not of the expected type
if
(
ob
->
ob_type
!=
type
)
return
NULL
;
W
*
wrapper
=
(
W
*
)
ob
;
U
*
underlying
=
dynamic_cast
<
U
*>
(
wrapper
->
nogil_cyobject
);
// no underlying cyobject: shouldn't happen, playing it safe for now
if
(
underlying
==
NULL
)
return
NULL
;
// return a new atomic reference
underlying
->
CyObject_INCREF
();
return
underlying
;
}
/* Cast argument to CyObject* type. */
#define _CyObject_CAST(op) op
...
...
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