On Thu, Oct 2, 2008 at 5:41 PM, Lisandro Dalcin <[EMAIL PROTECTED]> wrote:
> OK, send the final patch (and possibly the test cases) when you finish it.
Ok, here is the final patch, with some test cases.
didier
diff -r 2976d81a9ac9 Cython/Compiler/Builtin.py
--- a/Cython/Compiler/Builtin.py Thu Oct 02 12:33:14 2008 -0400
+++ b/Cython/Compiler/Builtin.py Fri Oct 03 00:53:46 2008 -0400
@@ -105,14 +105,18 @@ builtin_types_table = [
("keys", "O", "O", "PyDict_Keys"),
("values","O", "O", "PyDict_Values")]),
- ("set", "PySet_Type", []),
+ ("set", "PySet_Type", [("clear", "O", "i", "PySet_Clear"),
+ ("discard", "OO", "i", "PySet_Discard"),
+ ("add", "OO", "i", "PySet_Add"),
+ ("pop", "O", "O", "PySet_Pop")]),
+
("frozenset", "PyFrozenSet_Type", []),
("slice", "PySlice_Type", []),
("file", "PyFile_Type", []),
]
-
+
builtin_structs_table = [
('Py_buffer', 'Py_buffer',
[("buf", PyrexTypes.c_void_ptr_type),
diff -r 2976d81a9ac9 Cython/Compiler/PyrexTypes.py
--- a/Cython/Compiler/PyrexTypes.py Thu Oct 02 12:33:14 2008 -0400
+++ b/Cython/Compiler/PyrexTypes.py Fri Oct 03 00:53:46 2008 -0400
@@ -5,7 +5,6 @@ import StringEncoding
import StringEncoding
import Naming
import copy
-
class BaseType:
#
@@ -295,7 +294,12 @@ class BuiltinObjectType(PyObjectType):
return type.is_pyobject and self.assignable_from(type)
def type_test_code(self, arg):
- return 'likely(Py%s_CheckExact(%s)) || (%s) == Py_None ||
(PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name),
0)' % (self.name[0].upper() + self.name[1:], arg, arg, self.name, arg)
+ type = self.name.capitalize()
+ if type == 'Set':
+ type = 'AnySet'
+ elif type == 'Frozenset':
+ type = 'FrozenSet'
+ return 'likely(Py%s_CheckExact(%s)) || (%s) == Py_None ||
(PyErr_Format(PyExc_TypeError, "Expected %s, got %%s", Py_TYPE(%s)->tp_name),
0)' % (type, arg, arg, self.name, arg)
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
diff -r 2976d81a9ac9 tests/run/set.pyx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/run/set.pyx Fri Oct 03 00:53:46 2008 -0400
@@ -0,0 +1,42 @@
+__doc__ = u"""
+>>> test_set_add()
+set(['a', 1])
+>>> test_set_clear()
+set([])
+>>> test_set_pop()
+set([])
+>>> test_set_discard()
+set([233, '12'])
+"""
+
+def test_set_add():
+ cdef set s1
+ s1 = set([1])
+ s1.add(1)
+ s1.add('a')
+ s1.add(1)
+ return s1
+
+def test_set_clear():
+ cdef set s1
+ s1 = set([1])
+ s1.clear()
+ return s1
+
+def test_set_pop():
+ cdef set s1
+ s1 = set()
+ s1.add('2')
+ two = s1.pop()
+ return s1
+
+def test_set_discard():
+ cdef set s1
+ s1 = set()
+ s1.add('12')
+ s1.add(3)
+ s1.add(233)
+ s1.discard('3')
+ s1.discard(3)
+ return s1
+
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev