# self.type = self.type.element_ptr_type()
if entry.is_pyglobal or entry.is_builtin:
assert self.type.is_pyobject, "Python global or builtin not a Python object"
- self.is_temp = 1
+ if Options.cache_builtins and entry.is_builtin:
+ self.is_temp = 0
+ else:
+ self.is_temp = 1
if Options.intern_names:
env.use_utility_code(get_name_interned_utility_code)
else:
def check_const(self):
entry = self.entry
- if not (entry.is_const or entry.is_cfunction):
+ if not (entry.is_const or entry.is_cfunction or entry.is_builtin):
self.not_const()
def check_const_addr(self):
entry = self.entry
- if not (entry.is_cglobal or entry.is_cfunction):
+ if not (entry.is_cglobal or entry.is_cfunction or entry.is_builtin):
self.addr_not_const()
def is_lvalue(self):
PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size");
}
-static PyObject *__Pyx_UnpackItem(PyObject *seq, Py_ssize_t i) {
static PyObject *__Pyx_UnpackItem(PyObject *iter) {
PyObject *item;
if (!(item = PyIter_Next(iter))) {
__Pyx_UnpackError();
}
return item;
+}
-static int __Pyx_EndUnpack(PyObject *seq, Py_ssize_t i) {
static int __Pyx_EndUnpack(PyObject *iter) {
PyObject *item;
if ((item = PyIter_Next(iter))) {
return 0;
else
return -1;
+}
"""]
#------------------------------------------------------------------------------------
def analyse_declarations(self, env):
if Options.embed_pos_in_docstring:
- env.doc = 'File: %s (starting at line %s)'%relative_position(self.pos)
+ env.doc = 'File: %s (starting at line %s)'%Nodes.relative_position(self.pos)
if not self.doc is None:
env.doc = env.doc + '\\n' + self.doc
else:
type.vtabptr_cname))
for entry in py_attrs:
if entry.name == "__weakref__":
- code.putln("p->%s = NULL;" % entry.cname)
+ code.putln("p->%s = 0;" % entry.cname)
else:
code.put_init_var_to_py_none(entry, "p->%s")
entry = scope.lookup_here("__new__")
for entry in scope.var_entries:
if entry.type.is_pyobject and entry.name <> "__weakref__":
py_attrs.append(entry)
- if py_attrs:
+ if py_attrs or scope.lookup_here("__weakref__"):
self.generate_self_cast(scope, code)
self.generate_usr_dealloc_call(scope, code)
if scope.lookup_here("__weakref__"):
- code.putln("PyObject_ClearWeakRefs(o);")
+ code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);")
for entry in py_attrs:
code.put_xdecref("p->%s" % entry.cname, entry.type)
if base_type:
% scope.mangle_internal("tp_traverse"))
py_attrs = []
for entry in scope.var_entries:
- if entry.type.is_pyobject:
+ if entry.type.is_pyobject and entry.name != "__weakref__":
py_attrs.append(entry)
if base_type or py_attrs:
code.putln(
% scope.mangle_internal("tp_clear"))
py_attrs = []
for entry in scope.var_entries:
- if entry.type.is_pyobject:
+ if entry.type.is_pyobject and entry.name != "__weakref__":
py_attrs.append(entry)
if py_attrs:
self.generate_self_cast(scope, code)
code.putln(
"PyObject *r;")
code.putln(
- "PyObject *x = PyInt_FromSsize(i); if(!x) return 0;")
+ "PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;")
code.putln(
"r = o->ob_type->tp_as_mapping->mp_subscript(o, x);")
code.putln(
# Pyrex - Parse tree nodes
#
-import string, sys
+import string, sys, os, time
import Code
from Errors import error, warning, InternalError
def analyse_expressions(self, env):
self.entry = env.lookup(self.name)
if self.rhs is not None:
+ self.entry.used = 1
if self.type.is_pyobject:
self.entry.init_to_none = False
self.entry.init = 0
# Generate type test for one argument.
if arg.type.typeobj_is_available():
typeptr_cname = arg.type.typeptr_cname
- arg_code = "((PyObject *)%s)" % arg.entry.cname
+ arg_code = "((PyObject *)%s)" % arg.cname
code.putln(
'if (!__Pyx_ArgTypeTest(%s, %s, %d, "%s")) %s' % (
arg_code,
self.lhs.analyse_target_declaration(env)
def analyse_types(self, env):
- import ExprNodes
self.dup = self.create_dup_node(env) # re-assigns lhs to a shallow copy
self.rhs.analyse_types(env)
self.lhs.analyse_target_types(env)
def allocate_rhs_temps(self, env):
+ import ExprNodes
if self.lhs.type.is_pyobject or self.rhs.type.is_pyobject:
self.rhs = self.rhs.coerce_to(self.lhs.type, env)
if self.lhs.type.is_pyobject:
self.dup.allocate_temp(env)
def allocate_lhs_temps(self, env):
- self.lhs.allocate_target_temps(env)
- self.lhs.release_target_temp(env)
+ self.lhs.allocate_target_temps(env, self.rhs)
+# self.lhs.release_target_temp(env)
self.dup.release_temp(env)
if self.dup.is_temp:
self.dup.release_subexpr_temps(env)
- self.rhs.release_temp(env)
+# self.rhs.release_temp(env)
if self.lhs.type.is_pyobject:
self.result.release_temp(env)
typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
-#DEFINE __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
-#DEFINE __Pyx_PyObject_IsTrue(x) ({PyObject *_x = (x); _x == Py_True ? 1 : (_x) == Py_False ? 0 : PyObject_IsTrue(_x)})
+#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
+static inline int __Pyx_PyObject_IsTrue(PyObject* x) {
+ if (x == Py_True) return 1;
+ else if (x == Py_False) return 0;
+ else return PyObject_IsTrue(x);
+}
+
"""
#get_name_predeclaration = \
return -1;
if (PyString_Check(v)) {
char *s = PyString_AsString(v);
- Py_ssize_t len = PyString_Size(v);
+ int len = PyString_Size(v);
if (len > 0 &&
isspace(Py_CHARMASK(s[len-1])) &&
s[len-1] != ' ')
Py_INCREF(type);
Py_DECREF(tmp);
}
- if (PyString_Check(type))
- ;
-/* else if (PyClass_Check(type)) */
+ if (PyString_Check(type)) {
+ if (PyErr_Warn(PyExc_DeprecationWarning,
+ "raising a string exception is deprecated"))
+ goto raise_error;
+ }
else if (PyType_Check(type) || PyClass_Check(type))
; /*PyErr_NormalizeException(&type, &value, &tb);*/
else {
type = (PyObject*) type->ob_type;
Py_INCREF(type);
}
- if (PyString_Check(type)) {
- if (PyErr_Warn(PyExc_DeprecationWarning,
- "raising a string exception is deprecated"))
- goto raise_error;
- }
- else if (PyType_Check(type) || PyClass_Check(type))
+ PyErr_Restore(type, value, tb);
+ return;
+raise_error:
+ Py_XDECREF(value);
Py_XDECREF(type);
Py_XDECREF(tb);
return;
PyObject **args,
PyObject **kwds,
char *kwd_list[],
- Py_ssize_t nargs,
+ int nargs,
PyObject **args2,
PyObject **kwds2)
{
bad:
Py_XDECREF(args1);
Py_XDECREF(kwds1);
- Py_XDECREF(*args2);
- Py_XDECREF(*kwds2);
+ if (*args2) {
+ Py_XDECREF(*args2);
+ }
+ if (*kwds2) {
+ Py_XDECREF(*kwds2);
+ }
return -1;
}
"""]
if (!ctx)
ctx = Py_None;
PyErr_WriteUnraisable(ctx);
- if (*args2) {
- Py_XDECREF(*args2);
- }
- if (*kwds2) {
- Py_XDECREF(*kwds2);
- }
+}
+"""]
#------------------------------------------------------------------------------------