Commit ca2d577d authored by Robert Bradshaw's avatar Robert Bradshaw

finish merging, fix weakref segfault, all SAGE doctests pass

parent 94be1d80
......@@ -719,7 +719,10 @@ class NameNode(AtomicExprNode):
# 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:
......@@ -755,12 +758,12 @@ class NameNode(AtomicExprNode):
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):
......@@ -3405,7 +3408,6 @@ static void __Pyx_UnpackError(void) {
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))) {
......@@ -3413,8 +3415,8 @@ static PyObject *__Pyx_UnpackItem(PyObject *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))) {
......@@ -3426,6 +3428,7 @@ static int __Pyx_EndUnpack(PyObject *iter) {
return 0;
else
return -1;
}
"""]
#------------------------------------------------------------------------------------
......
......@@ -23,7 +23,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
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:
......@@ -459,7 +459,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
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__")
......@@ -485,11 +485,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
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:
......@@ -533,7 +533,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
% 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(
......@@ -569,7 +569,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
% 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)
......@@ -596,7 +596,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
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(
......
......@@ -2,7 +2,7 @@
# Pyrex - Parse tree nodes
#
import string, sys
import string, sys, os, time
import Code
from Errors import error, warning, InternalError
......@@ -218,6 +218,7 @@ class CNameDeclaratorNode(CDeclaratorNode):
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
......@@ -741,7 +742,7 @@ class CFuncDefNode(FuncDefNode):
# 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,
......@@ -1589,12 +1590,12 @@ class InPlaceAssignmentNode(AssignmentNode):
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:
......@@ -1607,12 +1608,12 @@ class InPlaceAssignmentNode(AssignmentNode):
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)
......@@ -2592,8 +2593,13 @@ utility_function_predeclarations = \
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 = \
......@@ -2630,7 +2636,7 @@ static int __Pyx_PrintItem(PyObject *v) {
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] != ' ')
......@@ -2685,9 +2691,11 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
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 {
......@@ -2706,12 +2714,10 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
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;
......@@ -2779,7 +2785,7 @@ static int __Pyx_GetStarArgs(
PyObject **args,
PyObject **kwds,
char *kwd_list[],
Py_ssize_t nargs,
int nargs,
PyObject **args2,
PyObject **kwds2)
{
......@@ -2839,8 +2845,12 @@ static int __Pyx_GetStarArgs(
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;
}
"""]
......@@ -2860,12 +2870,8 @@ static void __Pyx_WriteUnraisable(char *name) {
if (!ctx)
ctx = Py_None;
PyErr_WriteUnraisable(ctx);
if (*args2) {
Py_XDECREF(*args2);
}
if (*kwds2) {
Py_XDECREF(*kwds2);
}
}
"""]
#------------------------------------------------------------------------------------
......
......@@ -1084,8 +1084,10 @@ class CClassScope(ClassScope):
else:
if defining and entry.func_cname:
error(pos, "'%s' already defined" % name)
if type.narrower_c_signature_than(entry.type, as_cmethod = 1):
entry.type = type
if type.same_c_signature_as(entry.type, as_cmethod = 1):
pass
# if type.narrower_c_signature_than(entry.type, as_cmethod = 1):
# entry.type = type
else:
error(pos, "Signature not compatible with previous declaration")
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