Commit ca2d577d authored by Robert Bradshaw's avatar Robert Bradshaw

finish merging, fix weakref segfault, all SAGE doctests pass

parent 94be1d80
...@@ -719,6 +719,9 @@ class NameNode(AtomicExprNode): ...@@ -719,6 +719,9 @@ class NameNode(AtomicExprNode):
# self.type = self.type.element_ptr_type() # self.type = self.type.element_ptr_type()
if entry.is_pyglobal or entry.is_builtin: if entry.is_pyglobal or entry.is_builtin:
assert self.type.is_pyobject, "Python global or builtin not a Python object" assert self.type.is_pyobject, "Python global or builtin not a Python object"
if Options.cache_builtins and entry.is_builtin:
self.is_temp = 0
else:
self.is_temp = 1 self.is_temp = 1
if Options.intern_names: if Options.intern_names:
env.use_utility_code(get_name_interned_utility_code) env.use_utility_code(get_name_interned_utility_code)
...@@ -755,12 +758,12 @@ class NameNode(AtomicExprNode): ...@@ -755,12 +758,12 @@ class NameNode(AtomicExprNode):
def check_const(self): def check_const(self):
entry = self.entry 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() self.not_const()
def check_const_addr(self): def check_const_addr(self):
entry = self.entry 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() self.addr_not_const()
def is_lvalue(self): def is_lvalue(self):
...@@ -3405,7 +3408,6 @@ static void __Pyx_UnpackError(void) { ...@@ -3405,7 +3408,6 @@ static void __Pyx_UnpackError(void) {
PyErr_SetString(PyExc_ValueError, "unpack sequence of wrong size"); 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) { static PyObject *__Pyx_UnpackItem(PyObject *iter) {
PyObject *item; PyObject *item;
if (!(item = PyIter_Next(iter))) { if (!(item = PyIter_Next(iter))) {
...@@ -3413,8 +3415,8 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter) { ...@@ -3413,8 +3415,8 @@ static PyObject *__Pyx_UnpackItem(PyObject *iter) {
__Pyx_UnpackError(); __Pyx_UnpackError();
} }
return item; return item;
}
static int __Pyx_EndUnpack(PyObject *seq, Py_ssize_t i) {
static int __Pyx_EndUnpack(PyObject *iter) { static int __Pyx_EndUnpack(PyObject *iter) {
PyObject *item; PyObject *item;
if ((item = PyIter_Next(iter))) { if ((item = PyIter_Next(iter))) {
...@@ -3426,6 +3428,7 @@ static int __Pyx_EndUnpack(PyObject *iter) { ...@@ -3426,6 +3428,7 @@ static int __Pyx_EndUnpack(PyObject *iter) {
return 0; return 0;
else else
return -1; return -1;
}
"""] """]
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
......
...@@ -23,7 +23,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -23,7 +23,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def analyse_declarations(self, env): def analyse_declarations(self, env):
if Options.embed_pos_in_docstring: 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: if not self.doc is None:
env.doc = env.doc + '\\n' + self.doc env.doc = env.doc + '\\n' + self.doc
else: else:
...@@ -459,7 +459,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -459,7 +459,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
type.vtabptr_cname)) type.vtabptr_cname))
for entry in py_attrs: for entry in py_attrs:
if entry.name == "__weakref__": if entry.name == "__weakref__":
code.putln("p->%s = NULL;" % entry.cname) code.putln("p->%s = 0;" % entry.cname)
else: else:
code.put_init_var_to_py_none(entry, "p->%s") code.put_init_var_to_py_none(entry, "p->%s")
entry = scope.lookup_here("__new__") entry = scope.lookup_here("__new__")
...@@ -485,11 +485,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -485,11 +485,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
for entry in scope.var_entries: for entry in scope.var_entries:
if entry.type.is_pyobject and entry.name <> "__weakref__": if entry.type.is_pyobject and entry.name <> "__weakref__":
py_attrs.append(entry) py_attrs.append(entry)
if py_attrs: if py_attrs or scope.lookup_here("__weakref__"):
self.generate_self_cast(scope, code) self.generate_self_cast(scope, code)
self.generate_usr_dealloc_call(scope, code) self.generate_usr_dealloc_call(scope, code)
if scope.lookup_here("__weakref__"): if scope.lookup_here("__weakref__"):
code.putln("PyObject_ClearWeakRefs(o);") code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);")
for entry in py_attrs: for entry in py_attrs:
code.put_xdecref("p->%s" % entry.cname, entry.type) code.put_xdecref("p->%s" % entry.cname, entry.type)
if base_type: if base_type:
...@@ -533,7 +533,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -533,7 +533,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
% scope.mangle_internal("tp_traverse")) % scope.mangle_internal("tp_traverse"))
py_attrs = [] py_attrs = []
for entry in scope.var_entries: for entry in scope.var_entries:
if entry.type.is_pyobject: if entry.type.is_pyobject and entry.name != "__weakref__":
py_attrs.append(entry) py_attrs.append(entry)
if base_type or py_attrs: if base_type or py_attrs:
code.putln( code.putln(
...@@ -569,7 +569,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -569,7 +569,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
% scope.mangle_internal("tp_clear")) % scope.mangle_internal("tp_clear"))
py_attrs = [] py_attrs = []
for entry in scope.var_entries: for entry in scope.var_entries:
if entry.type.is_pyobject: if entry.type.is_pyobject and entry.name != "__weakref__":
py_attrs.append(entry) py_attrs.append(entry)
if py_attrs: if py_attrs:
self.generate_self_cast(scope, code) self.generate_self_cast(scope, code)
...@@ -596,7 +596,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -596,7 +596,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln( code.putln(
"PyObject *r;") "PyObject *r;")
code.putln( code.putln(
"PyObject *x = PyInt_FromSsize(i); if(!x) return 0;") "PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;")
code.putln( code.putln(
"r = o->ob_type->tp_as_mapping->mp_subscript(o, x);") "r = o->ob_type->tp_as_mapping->mp_subscript(o, x);")
code.putln( code.putln(
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Pyrex - Parse tree nodes # Pyrex - Parse tree nodes
# #
import string, sys import string, sys, os, time
import Code import Code
from Errors import error, warning, InternalError from Errors import error, warning, InternalError
...@@ -218,6 +218,7 @@ class CNameDeclaratorNode(CDeclaratorNode): ...@@ -218,6 +218,7 @@ class CNameDeclaratorNode(CDeclaratorNode):
def analyse_expressions(self, env): def analyse_expressions(self, env):
self.entry = env.lookup(self.name) self.entry = env.lookup(self.name)
if self.rhs is not None: if self.rhs is not None:
self.entry.used = 1
if self.type.is_pyobject: if self.type.is_pyobject:
self.entry.init_to_none = False self.entry.init_to_none = False
self.entry.init = 0 self.entry.init = 0
...@@ -741,7 +742,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -741,7 +742,7 @@ class CFuncDefNode(FuncDefNode):
# Generate type test for one argument. # Generate type test for one argument.
if arg.type.typeobj_is_available(): if arg.type.typeobj_is_available():
typeptr_cname = arg.type.typeptr_cname typeptr_cname = arg.type.typeptr_cname
arg_code = "((PyObject *)%s)" % arg.entry.cname arg_code = "((PyObject *)%s)" % arg.cname
code.putln( code.putln(
'if (!__Pyx_ArgTypeTest(%s, %s, %d, "%s")) %s' % ( 'if (!__Pyx_ArgTypeTest(%s, %s, %d, "%s")) %s' % (
arg_code, arg_code,
...@@ -1589,12 +1590,12 @@ class InPlaceAssignmentNode(AssignmentNode): ...@@ -1589,12 +1590,12 @@ class InPlaceAssignmentNode(AssignmentNode):
self.lhs.analyse_target_declaration(env) self.lhs.analyse_target_declaration(env)
def analyse_types(self, env): def analyse_types(self, env):
import ExprNodes
self.dup = self.create_dup_node(env) # re-assigns lhs to a shallow copy self.dup = self.create_dup_node(env) # re-assigns lhs to a shallow copy
self.rhs.analyse_types(env) self.rhs.analyse_types(env)
self.lhs.analyse_target_types(env) self.lhs.analyse_target_types(env)
def allocate_rhs_temps(self, env): def allocate_rhs_temps(self, env):
import ExprNodes
if self.lhs.type.is_pyobject or self.rhs.type.is_pyobject: if self.lhs.type.is_pyobject or self.rhs.type.is_pyobject:
self.rhs = self.rhs.coerce_to(self.lhs.type, env) self.rhs = self.rhs.coerce_to(self.lhs.type, env)
if self.lhs.type.is_pyobject: if self.lhs.type.is_pyobject:
...@@ -1607,12 +1608,12 @@ class InPlaceAssignmentNode(AssignmentNode): ...@@ -1607,12 +1608,12 @@ class InPlaceAssignmentNode(AssignmentNode):
self.dup.allocate_temp(env) self.dup.allocate_temp(env)
def allocate_lhs_temps(self, env): def allocate_lhs_temps(self, env):
self.lhs.allocate_target_temps(env) self.lhs.allocate_target_temps(env, self.rhs)
self.lhs.release_target_temp(env) # self.lhs.release_target_temp(env)
self.dup.release_temp(env) self.dup.release_temp(env)
if self.dup.is_temp: if self.dup.is_temp:
self.dup.release_subexpr_temps(env) self.dup.release_subexpr_temps(env)
self.rhs.release_temp(env) # self.rhs.release_temp(env)
if self.lhs.type.is_pyobject: if self.lhs.type.is_pyobject:
self.result.release_temp(env) self.result.release_temp(env)
...@@ -2592,8 +2593,13 @@ utility_function_predeclarations = \ ...@@ -2592,8 +2593,13 @@ utility_function_predeclarations = \
typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*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_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)}) 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 = \ #get_name_predeclaration = \
...@@ -2630,7 +2636,7 @@ static int __Pyx_PrintItem(PyObject *v) { ...@@ -2630,7 +2636,7 @@ static int __Pyx_PrintItem(PyObject *v) {
return -1; return -1;
if (PyString_Check(v)) { if (PyString_Check(v)) {
char *s = PyString_AsString(v); char *s = PyString_AsString(v);
Py_ssize_t len = PyString_Size(v); int len = PyString_Size(v);
if (len > 0 && if (len > 0 &&
isspace(Py_CHARMASK(s[len-1])) && isspace(Py_CHARMASK(s[len-1])) &&
s[len-1] != ' ') s[len-1] != ' ')
...@@ -2685,9 +2691,11 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { ...@@ -2685,9 +2691,11 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
Py_INCREF(type); Py_INCREF(type);
Py_DECREF(tmp); Py_DECREF(tmp);
} }
if (PyString_Check(type)) if (PyString_Check(type)) {
; if (PyErr_Warn(PyExc_DeprecationWarning,
/* else if (PyClass_Check(type)) */ "raising a string exception is deprecated"))
goto raise_error;
}
else if (PyType_Check(type) || PyClass_Check(type)) else if (PyType_Check(type) || PyClass_Check(type))
; /*PyErr_NormalizeException(&type, &value, &tb);*/ ; /*PyErr_NormalizeException(&type, &value, &tb);*/
else { else {
...@@ -2706,12 +2714,10 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { ...@@ -2706,12 +2714,10 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
type = (PyObject*) type->ob_type; type = (PyObject*) type->ob_type;
Py_INCREF(type); Py_INCREF(type);
} }
if (PyString_Check(type)) { PyErr_Restore(type, value, tb);
if (PyErr_Warn(PyExc_DeprecationWarning, return;
"raising a string exception is deprecated")) raise_error:
goto raise_error; Py_XDECREF(value);
}
else if (PyType_Check(type) || PyClass_Check(type))
Py_XDECREF(type); Py_XDECREF(type);
Py_XDECREF(tb); Py_XDECREF(tb);
return; return;
...@@ -2779,7 +2785,7 @@ static int __Pyx_GetStarArgs( ...@@ -2779,7 +2785,7 @@ static int __Pyx_GetStarArgs(
PyObject **args, PyObject **args,
PyObject **kwds, PyObject **kwds,
char *kwd_list[], char *kwd_list[],
Py_ssize_t nargs, int nargs,
PyObject **args2, PyObject **args2,
PyObject **kwds2) PyObject **kwds2)
{ {
...@@ -2839,8 +2845,12 @@ static int __Pyx_GetStarArgs( ...@@ -2839,8 +2845,12 @@ static int __Pyx_GetStarArgs(
bad: bad:
Py_XDECREF(args1); Py_XDECREF(args1);
Py_XDECREF(kwds1); Py_XDECREF(kwds1);
if (*args2) {
Py_XDECREF(*args2); Py_XDECREF(*args2);
}
if (*kwds2) {
Py_XDECREF(*kwds2); Py_XDECREF(*kwds2);
}
return -1; return -1;
} }
"""] """]
...@@ -2860,12 +2870,8 @@ static void __Pyx_WriteUnraisable(char *name) { ...@@ -2860,12 +2870,8 @@ static void __Pyx_WriteUnraisable(char *name) {
if (!ctx) if (!ctx)
ctx = Py_None; ctx = Py_None;
PyErr_WriteUnraisable(ctx); PyErr_WriteUnraisable(ctx);
if (*args2) { }
Py_XDECREF(*args2); """]
}
if (*kwds2) {
Py_XDECREF(*kwds2);
}
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
......
...@@ -1084,8 +1084,10 @@ class CClassScope(ClassScope): ...@@ -1084,8 +1084,10 @@ class CClassScope(ClassScope):
else: else:
if defining and entry.func_cname: if defining and entry.func_cname:
error(pos, "'%s' already defined" % name) error(pos, "'%s' already defined" % name)
if type.narrower_c_signature_than(entry.type, as_cmethod = 1): if type.same_c_signature_as(entry.type, as_cmethod = 1):
entry.type = type pass
# if type.narrower_c_signature_than(entry.type, as_cmethod = 1):
# entry.type = type
else: else:
error(pos, "Signature not compatible with previous declaration") error(pos, "Signature not compatible with previous declaration")
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment