env.use_utility_code(force_init_threads_utility_code)
code.putln("PyGILState_STATE _save = PyGILState_Ensure();")
# ----- Automatic lead-ins for certain special functions
- if profile:
- code.put_trace_call(self.entry.name, self.pos)
if not lenv.nogil:
code.put_setup_refcount_context(self.entry.name)
+ if profile:
+ code.put_trace_call(self.entry.name, self.pos)
if is_getbuffer_slot:
self.getbuffer_init(code)
+ # ----- Create closure scope object
+ if self.needs_closure:
+ code.putln("%s = (%s)%s->tp_new(%s, %s, NULL);" % (
+ Naming.cur_scope_cname,
+ lenv.scope_class.type.declaration_code(''),
+ lenv.scope_class.type.typeptr_cname,
+ lenv.scope_class.type.typeptr_cname,
+ Naming.empty_tuple))
+ # TODO: error handling
+ code.put_gotref(Naming.cur_scope_cname)
+ # Note that it is unsafe to decref the scope at this point.
+ if env.is_closure_scope:
+ code.putln("%s = (%s)%s;" % (
+ outer_scope_cname,
+ env.scope_class.type.declaration_code(''),
+ Naming.self_cname))
+ if self.needs_closure:
+ # inner closures own a reference to their outer parent
+ code.put_incref(outer_scope_cname, env.scope_class.type)
+ code.put_giveref(outer_scope_cname)
# ----- Fetch arguments
self.generate_argument_parsing_code(env, code)
# If an argument is assigned to in the body, we must
if arg.not_none and not arg.type.is_extension_type:
error(self.pos,
"Only extension type arguments can have 'not None'")
- self.declare_pyfunction(env)
+ if self.name == '<lambda>':
+ self.declare_lambda_function(env)
+ else:
+ self.declare_pyfunction(env)
self.analyse_signature(env)
self.return_type = self.entry.signature.return_type()
+ self.create_local_scope(env)
def analyse_signature(self, env):
any_type_tests_needed = 0