code.put_decref("((PyObject*)%s)" % type.typeptr_cname, PyrexTypes.py_object_type)
if Options.cache_builtins:
code.putln("/*--- Builtin cleanup code ---*/")
- for entry in env.builtin_scope().cached_entries:
+ for entry in env.cached_builtins:
code.put_var_decref_clear(entry)
code.putln("/*--- Intern cleanup code ---*/")
for entry in env.pynum_entries:
def generate_builtin_init_code(self, env, code):
# Lookup and cache builtin objects.
if Options.cache_builtins:
- for entry in env.builtin_scope().cached_entries:
+ for entry in env.cached_builtins:
if Options.intern_names:
#assert entry.interned_cname is not None
code.putln(
for name, definition in self.builtin_entries.iteritems():
cname, type = definition
self.declare_var(name, type, None, cname)
- self.cached_entries = []
- self.undeclared_cached_entries = []
def declare_builtin(self, name, pos):
if not hasattr(__builtin__, name):
return self.outer_scope.declare_builtin(name, pos)
else:
error(pos, "undeclared name not builtin: %s"%name)
- entry = self.declare(name, name, py_object_type, pos)
- if Options.cache_builtins:
- entry.is_builtin = 1
- entry.is_const = 1
- entry.cname = Naming.builtin_prefix + name
- self.cached_entries.append(entry)
- self.undeclared_cached_entries.append(entry)
- else:
- entry.is_builtin = 1
- return entry
def declare_builtin_cfunction(self, name, type, cname, python_equiv = None,
utility_code = None):
self.types_imported = {}
self.pynum_entries = []
self.has_extern_class = 0
+ self.cached_builtins = []
+ self.undeclared_cached_builtins = []
def qualifying_scope(self):
return self.parent_module
return self
def declare_builtin(self, name, pos):
- entry = Scope.declare_builtin(self, name, pos)
- #entry.interned_cname = self.intern(name)
+ if not hasattr(__builtin__, name):
+ if self.outer_scope is not None:
+ return self.outer_scope.declare_builtin(name, pos)
+ else:
+ error(pos, "undeclared name not builtin: %s"%name)
+ entry = self.declare(name, name, py_object_type, pos)
+ if Options.cache_builtins:
+ entry.is_builtin = 1
+ entry.is_const = 1
+ entry.cname = Naming.builtin_prefix + name
+ self.cached_builtins.append(entry)
+ self.undeclared_cached_builtins.append(entry)
+ else:
+ entry.is_builtin = 1
return entry
def intern(self, name):