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
Kirill Smelkov
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
Hide 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,59 +1899,47 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1899,59 +1899,47 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def
generate_binop_function
(
self
,
scope
,
slot
,
code
):
def
generate_binop_function
(
self
,
scope
,
slot
,
code
):
func_name
=
scope
.
mangle_internal
(
slot
.
slot_name
)
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
()
code
.
putln
()
preprocessor_guard
=
slot
.
preprocessor_guard_code
()
preprocessor_guard
=
slot
.
preprocessor_guard_code
()
if
preprocessor_guard
:
if
preprocessor_guard
:
code
.
putln
(
preprocessor_guard
)
code
.
putln
(
preprocessor_guard
)
if
scope
.
directives
[
'c_api_binop_methods'
]:
if
slot
.
left_slot
.
signature
==
TypeSlots
.
binaryfunc
:
code
.
putln
(
'#define %s %s'
%
(
func_name
,
slot
.
left_slot
.
slot_code
(
scope
)))
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
:
else
:
error
(
entry
.
pos
,
"Unexpected type lost signature: %s"
%
slot
)
if
slot
.
left_slot
.
signature
==
TypeSlots
.
binaryfunc
:
extra_arg
=
extra_arg_decl
=
''
def
has_slot_method
(
method_name
):
elif
slot
.
left_slot
.
signature
==
TypeSlots
.
ternaryfunc
:
entry
=
scope
.
lookup
(
method_name
)
extra_arg
=
', extra_arg'
return
bool
(
entry
and
entry
.
is_special
and
entry
.
func_cname
)
extra_arg_decl
=
', PyObject* extra_arg'
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
)
else
:
else
:
return
'%s_maybe_call_slot(%s, left, right %s)'
%
(
error
(
entry
.
pos
,
"Unexpected type lost signature: %s"
%
slot
)
func_name
,
def
has_slot_method
(
method_name
):
'Py_TYPE(right)->tp_base'
if
reverse
else
'Py_TYPE(left)->tp_base'
,
entry
=
scope
.
lookup
(
method_name
)
extra_arg
)
return
bool
(
entry
and
entry
.
is_special
and
entry
.
func_cname
)
def
call_slot_method
(
method_name
,
reverse
):
code
.
putln
(
entry
=
scope
.
lookup
(
method_name
)
TempitaUtilityCode
.
load_as_string
(
if
entry
and
entry
.
is_special
and
entry
.
func_cname
:
"BinopSlot"
,
"ExtensionTypes.c"
,
return
"%s(%s%s)"
%
(
entry
.
func_cname
,
"right, left"
if
reverse
else
"left, right"
,
extra_arg
)
context
=
{
else
:
"func_name"
:
func_name
,
super
=
'Py_TYPE(right)->tp_base'
if
reverse
else
'Py_TYPE(left)->tp_base'
"slot_name"
:
slot
.
slot_name
,
return
(
'(%s->tp_as_number && %s->tp_as_number->%s)'
"overloads_left"
:
int
(
has_slot_method
(
slot
.
left_slot
.
method_name
)),
' ? %s->tp_as_number->%s(left, right %s)'
"call_left"
:
call_slot_method
(
slot
.
left_slot
.
method_name
,
reverse
=
False
),
' : (Py_INCREF(Py_NotImplemented), Py_NotImplemented)'
)
%
(
"call_right"
:
call_slot_method
(
slot
.
right_slot
.
method_name
,
reverse
=
True
),
super
,
super
,
slot
.
slot_name
,
super
,
slot
.
slot_name
,
extra_arg
)
"type_cname"
:
scope
.
parent_type
.
typeptr_cname
,
code
.
putln
(
"slot_type"
:
slot_type
,
TempitaUtilityCode
.
load_cached
(
"extra_arg"
:
extra_arg
,
"BinopSlot"
,
"ExtensionTypes.c"
,
"extra_arg_decl"
:
extra_arg_decl
,
context
=
{
})[
1
])
"func_name"
:
func_name
,
"slot_name"
:
slot
.
slot_name
,
"overloads_left"
:
int
(
has_slot_method
(
slot
.
left_slot
.
method_name
)),
"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
,
"extra_arg"
:
extra_arg
,
"extra_arg_decl"
:
extra_arg_decl
,
}).
impl
.
strip
())
code
.
putln
()
if
preprocessor_guard
:
if
preprocessor_guard
:
code
.
putln
(
"#endif"
)
code
.
putln
(
"#endif"
)
...
...
Cython/Utility/ExtensionTypes.c
View file @
5a8a513a
...
@@ -281,39 +281,24 @@ __PYX_GOOD:
...
@@ -281,39 +281,24 @@ __PYX_GOOD:
/////////////// BinopSlot ///////////////
/////////////// 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
}})
{
static
PyObject
*
{{
func_name
}}(
PyObject
*
left
,
PyObject
*
right
{{
extra_arg_decl
}})
{
PyObject
*
res
;
PyObject
*
res
;
int
maybe_self_is_left
,
maybe_self_is_right
=
0
;
int
maybe_self_is_left
,
maybe_self_is_right
=
0
;
maybe_self_is_left
=
Py_TYPE
(
left
)
==
Py_TYPE
(
right
)
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
}})
||
(
Py_TYPE
(
left
)
->
tp_as_number
&&
Py_TYPE
(
left
)
->
tp_as_number
->
{{
slot_name
}}
==
&
{{
func_name
}})
#endif
||
PyType_IsSubtype
(
Py_TYPE
(
left
),
{{
type_cname
}});
||
__Pyx_TypeCheck
(
left
,
{{
type_cname
}});
// Optimize for the common case where the left operation is defined (and successful).
// Optimize for the common case where the left operation is defined (and successful).
if
(
!
{{
overloads_left
}})
{
if
(
!
{{
overloads_left
}})
{
maybe_self_is_right
=
Py_TYPE
(
left
)
==
Py_TYPE
(
right
)
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
}})
||
(
Py_TYPE
(
right
)
->
tp_as_number
&&
Py_TYPE
(
right
)
->
tp_as_number
->
{{
slot_name
}}
==
&
{{
func_name
}})
#endif
||
PyType_IsSubtype
(
Py_TYPE
(
right
),
{{
type_cname
}});
||
__Pyx_TypeCheck
(
right
,
{{
type_cname
}});
}
}
if
(
maybe_self_is_left
)
{
if
(
maybe_self_is_left
)
{
if
(
maybe_self_is_right
&&
!
{{
overloads_left
}})
{
if
(
maybe_self_is_right
&&
!
{{
overloads_left
}})
{
res
=
{{
call_right
}};
res
=
{{
call_right
}};
if
(
res
!=
Py_NotImplemented
)
return
res
;
if
(
res
!=
Py_NotImplemented
)
return
res
;
Py_DECREF
(
res
);
Py_DECREF
(
res
);
// Don't bother calling it again.
maybe_self_is_right
=
0
;
// Don't bother calling it again.
maybe_self_is_right
=
0
;
}
}
res
=
{{
call_left
}};
res
=
{{
call_left
}};
if
(
res
!=
Py_NotImplemented
)
return
res
;
if
(
res
!=
Py_NotImplemented
)
return
res
;
...
@@ -321,13 +306,11 @@ static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}
...
@@ -321,13 +306,11 @@ static PyObject *{{func_name}}(PyObject *left, PyObject *right {{extra_arg_decl}
}
}
if
({{
overloads_left
}})
{
if
({{
overloads_left
}})
{
maybe_self_is_right
=
Py_TYPE
(
left
)
==
Py_TYPE
(
right
)
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
}})
||
(
Py_TYPE
(
right
)
->
tp_as_number
&&
Py_TYPE
(
right
)
->
tp_as_number
->
{{
slot_name
}}
==
&
{{
func_name
}})
#endif
||
PyType_IsSubtype
(
Py_TYPE
(
right
),
{{
type_cname
}});
||
PyType_IsSubtype
(
Py_TYPE
(
right
),
{{
type_cname
}});
}
}
if
(
maybe_self_is_right
)
{
if
(
maybe_self_is_right
)
{
return
{{
call_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