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
5a8a513a
Commit
5a8a513a
authored
Jun 17, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Limited API updates and cleanup for #2056. GH-3635)"
This reverts commit
02bb311d
.
parent
e46296d0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
68 deletions
+39
-68
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+35
-47
Cython/Utility/ExtensionTypes.c
Cython/Utility/ExtensionTypes.c
+4
-21
No files found.
Cython/Compiler/ModuleNode.py
View file @
5a8a513a
...
...
@@ -1899,47 +1899,35 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def
generate_binop_function
(
self
,
scope
,
slot
,
code
):
func_name
=
scope
.
mangle_internal
(
slot
.
slot_name
)
if
scope
.
directives
[
'c_api_binop_methods'
]:
code
.
putln
(
'#define %s %s'
%
(
func_name
,
slot
.
left_slot
.
slot_code
(
scope
)))
return
else
:
error
(
self
.
pos
,
"The 'c_api_binop_methods' directive is only supported for forward compatibility"
" and must be True."
)
code
.
putln
()
preprocessor_guard
=
slot
.
preprocessor_guard_code
()
if
preprocessor_guard
:
code
.
putln
(
preprocessor_guard
)
if
scope
.
directives
[
'c_api_binop_methods'
]:
code
.
putln
(
'#define %s %s'
%
(
func_name
,
slot
.
left_slot
.
slot_code
(
scope
)))
else
:
if
slot
.
left_slot
.
signature
==
TypeSlots
.
binaryfunc
:
slot_type
=
'binaryfunc'
extra_arg
=
extra_arg_decl
=
''
elif
slot
.
left_slot
.
signature
==
TypeSlots
.
ternaryfunc
:
slot_type
=
'ternaryfunc'
extra_arg
=
', extra_arg'
extra_arg_decl
=
', PyObject* extra_arg'
else
:
error
(
entry
.
pos
,
"Unexpected type lost signature: %s"
%
slot
)
def
has_slot_method
(
method_name
):
entry
=
scope
.
lookup
(
method_name
)
return
bool
(
entry
and
entry
.
is_special
and
entry
.
func_cname
)
def
call_slot_method
(
method_name
,
reverse
):
entry
=
scope
.
lookup
(
method_name
)
if
entry
and
entry
.
is_special
and
entry
.
func_cname
:
return
"%s(%s%s)"
%
(
entry
.
func_cname
,
"right, left"
if
reverse
else
"left, right"
,
extra_arg
)
return
"%s(%s%s)"
%
(
entry
.
func_cname
,
"right, left"
if
reverse
else
"left, right"
,
extra_arg
)
else
:
return
'%s_maybe_call_slot(%s, left, right %s)'
%
(
func_name
,
'Py_TYPE(right)->tp_base'
if
reverse
else
'Py_TYPE(left)->tp_base'
,
extra_arg
)
super
=
'Py_TYPE(right)->tp_base'
if
reverse
else
'Py_TYPE(left)->tp_base'
return
(
'(%s->tp_as_number && %s->tp_as_number->%s)'
' ? %s->tp_as_number->%s(left, right %s)'
' : (Py_INCREF(Py_NotImplemented), Py_NotImplemented)'
)
%
(
super
,
super
,
slot
.
slot_name
,
super
,
slot
.
slot_name
,
extra_arg
)
code
.
putln
(
TempitaUtilityCode
.
load_as_string
(
TempitaUtilityCode
.
load_cached
(
"BinopSlot"
,
"ExtensionTypes.c"
,
context
=
{
"func_name"
:
func_name
,
...
...
@@ -1948,10 +1936,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"call_left"
:
call_slot_method
(
slot
.
left_slot
.
method_name
,
reverse
=
False
),
"call_right"
:
call_slot_method
(
slot
.
right_slot
.
method_name
,
reverse
=
True
),
"type_cname"
:
scope
.
parent_type
.
typeptr_cname
,
"slot_type"
:
slot_type
,
"extra_arg"
:
extra_arg
,
"extra_arg_decl"
:
extra_arg_decl
,
})[
1
])
}).
impl
.
strip
())
code
.
putln
()
if
preprocessor_guard
:
code
.
putln
(
"#endif"
)
...
...
Cython/Utility/ExtensionTypes.c
View file @
5a8a513a
...
...
@@ -281,39 +281,24 @@ __PYX_GOOD:
/////////////// BinopSlot ///////////////
static
CYTHON_INLINE
PyObject
*
{{
func_name
}}
_maybe_call_slot
(
PyTypeObject
*
type
,
PyObject
*
left
,
PyObject
*
right
{{
extra_arg_decl
}})
{
{{
slot_type
}}
slot
;
#if CYTHON_USE_TYPE_SLOTS
slot
=
type
->
tp_as_number
?
type
->
tp_as_number
->
{{
slot_name
}}
:
NULL
;
#else
slot
=
({{
slot_type
}})
PyType_GetSlot
(
type
,
Py_
{{
slot_name
}});
#endif
return
slot
?
slot
(
left
,
right
{{
extra_arg
}})
:
__Pyx_NewRef
(
Py_NotImplemented
);
}
static
PyObject
*
{{
func_name
}}(
PyObject
*
left
,
PyObject
*
right
{{
extra_arg_decl
}})
{
PyObject
*
res
;
int
maybe_self_is_left
,
maybe_self_is_right
=
0
;
maybe_self_is_left
=
Py_TYPE
(
left
)
==
Py_TYPE
(
right
)
#if CYTHON_USE_TYPE_SLOTS
||
(
Py_TYPE
(
left
)
->
tp_as_number
&&
Py_TYPE
(
left
)
->
tp_as_number
->
{{
slot_name
}}
==
&
{{
func_name
}})
#endif
||
__Pyx_TypeCheck
(
left
,
{{
type_cname
}});
||
PyType_IsSubtype
(
Py_TYPE
(
left
),
{{
type_cname
}});
// Optimize for the common case where the left operation is defined (and successful).
if
(
!
{{
overloads_left
}})
{
maybe_self_is_right
=
Py_TYPE
(
left
)
==
Py_TYPE
(
right
)
#if CYTHON_USE_TYPE_SLOTS
||
(
Py_TYPE
(
right
)
->
tp_as_number
&&
Py_TYPE
(
right
)
->
tp_as_number
->
{{
slot_name
}}
==
&
{{
func_name
}})
#endif
||
__Pyx_TypeCheck
(
right
,
{{
type_cname
}});
||
PyType_IsSubtype
(
Py_TYPE
(
right
),
{{
type_cname
}});
}
if
(
maybe_self_is_left
)
{
if
(
maybe_self_is_right
&&
!
{{
overloads_left
}})
{
res
=
{{
call_right
}};
if
(
res
!=
Py_NotImplemented
)
return
res
;
Py_DECREF
(
res
);
// Don't bother calling it again.
maybe_self_is_right
=
0
;
maybe_self_is_right
=
0
;
// Don't bother calling it again.
}
res
=
{{
call_left
}};
if
(
res
!=
Py_NotImplemented
)
return
res
;
...
...
@@ -321,13 +306,11 @@ static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}
}
if
({{
overloads_left
}})
{
maybe_self_is_right
=
Py_TYPE
(
left
)
==
Py_TYPE
(
right
)
#if CYTHON_USE_TYPE_SLOTS
||
(
Py_TYPE
(
right
)
->
tp_as_number
&&
Py_TYPE
(
right
)
->
tp_as_number
->
{{
slot_name
}}
==
&
{{
func_name
}})
#endif
||
PyType_IsSubtype
(
Py_TYPE
(
right
),
{{
type_cname
}});
}
if
(
maybe_self_is_right
)
{
return
{{
call_right
}};
}
return
__Pyx_NewRef
(
Py_NotImplemented
)
;
return
Py_INCREF
(
Py_NotImplemented
),
Py_NotImplemented
;
}
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