summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2013-12-22 18:21:18 +0100
committerStefan Behnel <stefan_ml@behnel.de>2013-12-22 18:21:18 +0100
commitcaea47a42fcc4548b36faf12dcbfd4e7705f6e16 (patch)
treefc4722ccc40e964de816617f59fc5aa26ea5a948 /Cython/Compiler/ModuleNode.py
parentb0618a0779be787d79cf7b133740aae9da5d8a97 (diff)
downloadcython-caea47a42fcc4548b36faf12dcbfd4e7705f6e16.tar.gz
avoid redundant NULL inits for extension type fields in tp_new()
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r--Cython/Compiler/ModuleNode.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index c1b5b8be5..481b3a144 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -1074,8 +1074,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
base_type = type.base_type
have_entries, (py_attrs, py_buffers, memoryview_slices) = \
- scope.get_refcounted_entries(include_weakref=True)
- cpp_class_attrs = [entry for entry in scope.var_entries if entry.type.is_cpp_class]
+ scope.get_refcounted_entries()
+ if scope.is_internal:
+ # internal classes (should) never need None inits, normal zeroing will do
+ py_attrs = []
+ cpp_class_attrs = [entry for entry in scope.var_entries
+ if entry.type.is_cpp_class]
new_func_entry = scope.lookup_here("__new__")
if base_type or (new_func_entry and new_func_entry.is_special
@@ -1105,7 +1109,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"static PyObject *%s(PyTypeObject *t, %sPyObject *a, %sPyObject *k) {"
% (slot_func, unused_marker, unused_marker))
- need_self_cast = type.vtabslot_cname or have_entries or cpp_class_attrs
+ need_self_cast = (type.vtabslot_cname or
+ (py_buffers or memoryview_slices or py_attrs) or
+ cpp_class_attrs)
if need_self_cast:
code.putln("%s;" % scope.parent_type.declaration_code("p"))
if base_type:
@@ -1153,11 +1159,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
(entry.cname, entry.type.declaration_code("")))
for entry in py_attrs:
- if scope.is_internal or entry.name == "__weakref__":
- # internal classes do not need None inits
- code.putln("p->%s = 0;" % entry.cname)
- else:
- code.put_init_var_to_py_none(entry, "p->%s", nanny=False)
+ code.put_init_var_to_py_none(entry, "p->%s", nanny=False)
for entry in memoryview_slices:
code.putln("p->%s.data = NULL;" % entry.cname)