Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:glaubitz:branches:devel:languages:python
python-Cython
6085.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 6085.patch of Package python-Cython
From 0e3e721c7cf1a00e6d285e011b99c136c7ecce51 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin <dalcinl@gmail.com> Date: Wed, 27 Mar 2024 13:25:47 +0300 Subject: [PATCH] Fix self cast when calling final methods --- Cython/Compiler/ExprNodes.py | 11 ------ Cython/Compiler/ModuleNode.py | 3 +- Cython/Compiler/Symtab.py | 4 ++ tests/bugs.txt | 1 - tests/run/inherited_final_method.pyx | 57 ++++++++++++++++++++++++---- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 66770e0e7cb..dde5e20ce97 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -6521,18 +6521,7 @@ def generate_result_code(self, code): goto_error = code.error_goto_if(" && ".join(exc_checks), self.pos) else: goto_error = "" - undo_gh2747_hack = False - if (self.function.is_attribute and - self.function.entry and self.function.entry.final_func_cname and - not code.funcstate.scope.is_cpp() - ): - # Hack around https://github.com/cython/cython/issues/2747 - # Disable GCC warnings/errors for wrong self casts. - code.putln('#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"') - undo_gh2747_hack = True code.putln("%s%s; %s" % (lhs, rhs, goto_error)) - if undo_gh2747_hack: - code.putln("#pragma GCC diagnostic pop") if self.type.is_pyobject and self.result(): self.generate_gotref(code) if self.has_optional_args: diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index d16ad8a7f07..3d3057765a1 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -3935,7 +3935,8 @@ def generate_exttype_vtable_init_code(self, entry, code): if entry.func_cname] if c_method_entries: for meth_entry in c_method_entries: - cast = meth_entry.type.signature_cast_string() + vtable_type = meth_entry.vtable_type or meth_entry.type + cast = vtable_type.signature_cast_string() code.putln( "%s.%s = %s%s;" % ( type.vtable_cname, diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 421ce802815..94aec1e237d 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -242,6 +242,7 @@ class Entry(object): known_standard_library_import = None pytyping_modifiers = None enum_int_value = None + vtable_type = None def __init__(self, name, cname, type, pos = None, init = None): self.name = name @@ -2551,6 +2552,9 @@ def declare_cfunction(self, name, type, pos, if self.parent_type.is_final_type or entry.is_inline_cmethod or self.directives.get('final'): entry.is_final_cmethod = True entry.final_func_cname = entry.func_cname + if not type.is_fused: + entry.vtable_type = entry.type + entry.type = type return entry diff --git a/tests/bugs.txt b/tests/bugs.txt index a39f5896aee..b25f8cd2b42 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -9,7 +9,6 @@ cfunc_call_tuple_args_T408 generator_expressions_in_class for_from_pyvar_loop_T601 temp_sideeffects_T654 # not really a bug, Cython warns about it -inherited_final_method cimport_alias_subclass # PEP-489 is currently disabled diff --git a/tests/run/inherited_final_method.pyx b/tests/run/inherited_final_method.pyx index 763eee4c36b..8aa0c501465 100644 --- a/tests/run/inherited_final_method.pyx +++ b/tests/run/inherited_final_method.pyx @@ -3,32 +3,73 @@ cimport cython +cdef class TopBase: + cdef method(self): + return None + -cdef class BaseClass: +cdef class BaseClass(TopBase): """ >>> obj = BaseClass() >>> obj.call_base() - True + 'base' """ + cdef base(self): + return '@base' + cdef method(self): - return True + return 'base' def call_base(self): return self.method() @cython.final -cdef class Child(BaseClass): +cdef class ChildClass(BaseClass): """ - >>> obj = Child() + >>> obj = ChildClass() >>> obj.call_base() - True + 'child' >>> obj.call_child() - True + 'child' """ + cdef child(self): + return '@child' + cdef method(self): - return True + return 'child' def call_child(self): # original bug: this requires a proper cast for self return self.method() + + +def test_BaseClass(): + """ + >>> test_BaseClass() + '@base' + 'base' + """ + cdef BaseClass obj = BaseClass() + print(repr(obj.base())) + print(repr(obj.method())) + + +def test_ChildClass(): + """ + >>> test_ChildClass() + '@base' + '@child' + 'child' + '@base' + '@child' + 'child' + """ + cdef ChildClass obj = ChildClass() + print(repr(obj.base())) + print(repr(obj.child())) + print(repr(obj.method())) + cdef BaseClass bobj = obj + print(repr(obj.base())) + print(repr(obj.child())) + print(repr(bobj.method()))
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor