Stefan, please review this patch. This fixes the recently added
tests/run/dictintindex.pyx testcase.
I had to add a new utility code, but I could not figure out how to
emit that utility code for the particular case of 'del obj[i]', I
mean, I do not know how to differentiate a setitem from a delitem.
Apart from that, the patch seems to work and all the testsuite pass.
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
diff -r 3421c9767918 Cython/Compiler/ExprNodes.py
--- a/Cython/Compiler/ExprNodes.py Mon Oct 27 02:04:41 2008 +0100
+++ b/Cython/Compiler/ExprNodes.py Mon Oct 27 10:35:14 2008 -0300
@@ -1561,6 +1561,7 @@ class IndexNode(ExprNode):
env.use_utility_code(getitem_int_utility_code)
if setting:
env.use_utility_code(setitem_int_utility_code)
+ env.use_utility_code(delitem_int_utility_code)
else:
self.index = self.index.coerce_to_pyobject(env)
self.type = py_object_type
@@ -1708,16 +1709,17 @@ class IndexNode(ExprNode):
self.generate_subexpr_evaluation_code(code)
#if self.type.is_pyobject:
if self.index.type.is_int:
- function = "PySequence_DelItem"
+ function = "__Pyx_DelItemInt"
index_code = self.index.result()
else:
function = "PyObject_DelItem"
index_code = self.index.py_result()
code.putln(
- "if (%s(%s, %s) < 0) %s" % (
+ "if (%s(%s, %s%s) < 0) %s" % (
function,
self.base.py_result(),
index_code,
+ self.index_unsigned_parameter(),
code.error_goto(self.pos)))
self.generate_subexpr_disposal_code(code)
@@ -4930,6 +4932,28 @@ impl = """
#------------------------------------------------------------------------------------
+delitem_int_utility_code = UtilityCode(
+proto = """
+static INLINE int __Pyx_DelItemInt(PyObject *o, Py_ssize_t i, int is_unsigned) {
+ int r;
+ PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ if (m && m->sq_ass_item && (likely(i >= 0) || !is_unsigned))
+ r = PySequence_DelItem(o, i);
+ else {
+ PyObject *j = (likely(i >= 0) || !is_unsigned) ? PyInt_FromLong(i) : PyLong_FromUnsignedLongLong((sizeof(unsigned long long) > sizeof(Py_ssize_t) ? (1ULL << (sizeof(Py_ssize_t)*8)) : 0) + i);
+ if (!j)
+ return -1;
+ r = PyObject_DelItem(o, j);
+ Py_DECREF(j);
+ }
+ return r;
+}
+""",
+impl = """
+""")
+
+#------------------------------------------------------------------------------------
+
raise_noneattr_error_utility_code = UtilityCode(
proto = """
static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname);
diff -r 3421c9767918 tests/run/dictintindex.pyx
--- a/tests/run/dictintindex.pyx Mon Oct 27 02:04:41 2008 +0100
+++ b/tests/run/dictintindex.pyx Mon Oct 27 10:56:01 2008 -0300
@@ -1,18 +1,35 @@ __doc__ = u"""
__doc__ = u"""
->>> test_index()
+>>> test_int_get()
1
->>> test_del()
+>>> test_int_del()
Traceback (most recent call last):
KeyError: 0
+>>> test_longlong_get()
+1
+>>> test_longlong_del() #doctest: +ELLIPSIS
+Traceback (most recent call last):
+KeyError: 0...
"""
-def test_index():
+def test_int_get():
cdef int key = 0
d = {0:1}
return d[key]
-def test_del():
+def test_int_del():
cdef int key = 0
d = {0:1}
del d[key]
return d[key]
+
+
+def test_longlong_get():
+ cdef long long key = 0
+ d = {0:1}
+ return d[key]
+
+def test_longlong_del():
+ cdef long long key = 0
+ d = {0:1}
+ del d[key]
+ return d[key]
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev