# body StatListNode
def analyse_declarations(self, env):
- env.doc = self.doc
+ if Options.embed_pos_in_docstring:
+ env.doc = 'File: %s (starting at line %s)'%relative_position(self.pos)
+ if not self.doc is None:
+ env.doc = env.doc + '\\n' + self.doc
+ else:
+ env.doc = self.doc
self.body.analyse_declarations(env)
def process_implementation(self, env, result):
self.generate_const_definitions(env, code)
self.generate_interned_name_decls(env, code)
self.generate_py_string_decls(env, code)
+ self.generate_cached_builtins_decls(env, code)
self.body.generate_function_definitions(env, code)
self.generate_interned_name_table(env, code)
self.generate_py_string_table(env, code)
code.putln('/* Generated by Pyrex %s on %s */' % (
Version.version, time.asctime()))
code.putln('')
+ code.putln('#define PY_SSIZE_T_CLEAN')
for filename in env.python_include_files:
code.putln('#include "%s"' % filename)
code.putln("#ifndef PY_LONG_LONG")
code.putln(" #define PY_LONG_LONG LONG_LONG")
code.putln("#endif")
+ code.putln("#if PY_VERSION_HEX < 0x02050000")
+ code.putln(" typedef int Py_ssize_t;")
+ code.putln(" #define PY_SSIZE_T_MAX INT_MAX")
+ code.putln(" #define PY_SSIZE_T_MIN INT_MIN")
+ code.putln(" #define PyInt_FromSsize_t(z) PyInt_FromLong(z)")
+ code.putln(" #define PyInt_AsSsize_t(o) PyInt_AsLong(o)")
+ code.putln("#endif")
self.generate_extern_c_macro_definition(code)
code.putln("%s double pow(double, double);" % Naming.extern_c_macro)
self.generate_includes(env, cimported_modules, code)
type.vtabptr_cname))
for entry in py_attrs:
if entry.name == "__weakref__":
- code.putln("p->%s = 0;" % entry.cname)
+ code.putln("p->%s = NULL;" % entry.cname)
else:
code.put_init_var_to_py_none(entry, "p->%s")
entry = scope.lookup_here("__new__")
# a __getitem__ method is present. It converts its
# argument to a Python integer and calls mp_subscript.
code.putln(
- "static PyObject *%s(PyObject *o, int i) {" %
+ "static PyObject *%s(PyObject *o, Py_ssize_t i) {" %
scope.mangle_internal("sq_item"))
code.putln(
"PyObject *r;")
code.putln(
- "PyObject *x = PyInt_FromLong(i); if(!x) return 0;")
+ "PyObject *x = PyInt_FromSsize(i); if(!x) return 0;")
code.putln(
"r = o->ob_type->tp_as_mapping->mp_subscript(o, x);")
code.putln(
del_entry = scope.lookup_here("__delslice__")
code.putln("")
code.putln(
- "static int %s(PyObject *o, int i, int j, PyObject *v) {" %
+ "static int %s(PyObject *o, Py_ssize_t i, Py_ssize_t j, PyObject *v) {" %
scope.mangle_internal("sq_ass_slice"))
code.putln(
"if (v) {")
"0, /*ob_size*/")
code.putln(
'"%s.%s", /*tp_name*/' % (
- modname, scope.class_name))
+ self.full_module_name, scope.class_name))
if type.typedef_flag:
objstruct = type.objstruct_cname
else:
self.generate_intern_code(env, code)
#code.putln("/*--- String init code ---*/")
self.generate_string_init_code(env, code)
+ #code.putln("/*--- Builtin init code ---*/")
+ self.generate_builtin_init_code(env, code)
#code.putln("/*--- Global init code ---*/")
self.generate_global_init_code(env, code)
"if (__Pyx_InitStrings(%s) < 0) %s;" % (
Naming.stringtab_cname,
code.error_goto(self.pos)))
+
+ 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:
+ if Options.intern_names:
+ #assert entry.interned_cname is not None
+ code.putln(
+ '%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
+ entry.cname,
+ Naming.builtins_cname,
+ entry.interned_cname,
+ entry.cname,
+ code.error_goto(entry.pos)))
+ else:
+ code.putln(
+ '%s = __Pyx_GetName(%s, "%s"); if (!%s) %s' % (
+ entry.cname,
+ Naming.builtins_cname,
+ self.entry.name,
+ entry.cname,
+ code.error_goto(entry.pos)))
def generate_global_init_code(self, env, code):
# Generate code to initialise global PyObject *