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
a782a197
Commit
a782a197
authored
May 29, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise an exception when conversion to CyObject fail
parent
99456781
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
4 deletions
+24
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+9
-2
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+2
-0
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+13
-2
No files found.
Cython/Compiler/Nodes.py
View file @
a782a197
...
...
@@ -1658,12 +1658,19 @@ class CppClassNode(CStructOrUnionDefNode, BlockNode):
# some types have not yet resolved that they can coerce to PyObject
# in particular, any cypclass not yet examined ?
if
cfunc_return_type
.
is_cyp_class
:
if
cfunc_return_type
.
templates
:
return
# only skip templated cypclasses for now
# we pass the global scope as argument, should not affect the result (?)
if
not
cfunc_return_type
.
can_coerce_to_pyobject
(
env
.
global_scope
()):
el
if
not
cfunc_return_type
.
can_coerce_to_pyobject
(
env
.
global_scope
()):
return
# skip c methods with Python-incompatible return types
for
argtype
in
cfunc_type
.
args
:
if
not
argtype
.
type
.
can_coerce_to_pyobject
(
env
.
global_scope
()):
if
argtype
.
type
.
is_cyp_class
:
if
argtype
.
type
.
templates
:
return
# only skip templated cypclasses for now
elif
not
argtype
.
type
.
can_coerce_to_pyobject
(
env
.
global_scope
()):
return
# skip c methods with Python-incompatible argument types
from
.CypclassWrapper
import
underlying_name
...
...
Cython/Compiler/PyrexTypes.py
View file @
a782a197
...
...
@@ -4228,6 +4228,8 @@ class CypClassType(CppClassType):
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
]
if
not
error_condition
:
error_condition
=
"!%s"
%
result_code
return
self
.
_assign_from_py_code
(
source_code
,
result_code
,
error_pos
,
code
,
from_py_function
,
error_condition
,
extra_args
=
extra_args
)
...
...
Cython/Utility/CyObjects.cpp
View file @
a782a197
...
...
@@ -190,6 +190,10 @@
* - borrow an Python reference
* - return a new atomic reference
*
* In case of conversion failure:
* - raise an exception
* - return NULL
*
* template:
* - W: the type of the extension type wrapper
* - U: the type of the underlying cypclass
...
...
@@ -198,13 +202,20 @@
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
)
if
(
ob
->
ob_type
!=
type
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Conversion Error: Could not convert to CyObject"
);
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
)
if
(
underlying
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Conversion Error: CyObject wrapper has no underlying CyObject"
);
return
NULL
;
}
// return a new atomic reference
underlying
->
CyObject_INCREF
();
return
underlying
;
...
...
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