diff options
| author | da-woods <dw-git@d-woods.co.uk> | 2020-04-12 15:29:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-12 16:29:18 +0200 |
| commit | 92a2da00a769a267139325dfe058d8b37b0929dc (patch) | |
| tree | 1521622ba3690c23360ab22d2094b057f484aa4f | |
| parent | 46bdd807306b30677772537f1e740eef1e6fd36a (diff) | |
| download | cython-92a2da00a769a267139325dfe058d8b37b0929dc.tar.gz | |
Fixed all assignments being added to the module in the limited API (GH-3501)
Mainly helps for adding attributes to classes, but undoubtedly fixes other things too.
| -rw-r--r-- | Cython/Compiler/ExprNodes.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index bfd518ffb..96ae0a8f0 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2314,6 +2314,12 @@ class NameNode(AtomicExprNode): elif entry.scope.is_module_scope: setter = 'PyDict_SetItem' namespace = Naming.moddict_cname + code.putln("{") + code.putln("#if CYTHON_COMPILING_IN_LIMITED_API") + # global module dict doesn't seems to exist in the limited API so create a temp variable + code.putln("PyObject *%s = PyModule_GetDict(%s); %s" % ( + namespace, Naming.module_cname, code.error_goto_if_null(namespace, self.pos))) + code.putln("#endif") elif entry.is_pyclass_attr: # Special-case setting __new__ n = "SetNewInClass" if self.name == "__new__" else "SetNameInClass" @@ -2321,14 +2327,6 @@ class NameNode(AtomicExprNode): setter = '__Pyx_' + n else: assert False, repr(entry) - code.putln("#if CYTHON_COMPILING_IN_LIMITED_API") - code.put_incref(rhs.py_result(), py_object_type) - code.put_error_if_neg(self.pos, '%s(%s, %s, %s)' % ( - "PyModule_AddObject", - Naming.module_cname, - code.get_string_const(self.entry.name), - rhs.py_result())) - code.putln("#else") code.put_error_if_neg( self.pos, '%s(%s, %s, %s)' % ( @@ -2336,7 +2334,6 @@ class NameNode(AtomicExprNode): namespace, interned_cname, rhs.py_result())) - code.putln("#endif") if debug_disposal_code: print("NameNode.generate_assignment_code:") print("...generating disposal code for %s" % rhs) @@ -2346,6 +2343,8 @@ class NameNode(AtomicExprNode): # in Py2.6+, we need to invalidate the method cache code.putln("PyType_Modified(%s);" % entry.scope.parent_type.typeptr_cname) + elif entry.scope.is_module_scope: + code.putln("}") else: if self.type.is_memoryviewslice: self.generate_acquire_memoryviewslice(rhs, code) |
