Author: Armin Rigo <[email protected]>
Branch:
Changeset: r159:c6e3bdeb49c5
Date: 2014-12-05 12:35 +0100
http://bitbucket.org/cffi/creflect/changeset/c6e3bdeb49c5/
Log: re-enable the XXX'ed parts of ffi.new()
diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -349,8 +349,8 @@
ct->ct_size = arraysize;
ct->ct_length = length;
ct->ct_flags = CT_ARRAY;
- Py_INCREF(ctptr);
- ct->ct_stuff = (PyObject *)ctptr;
+ ct->ct_itemdescr = ctitem; Py_INCREF(ctitem);
+ ct->ct_stuff = (PyObject *)ctptr; Py_INCREF(ctptr);
if (cb != NULL) {
if (length < 0 && ctptr->ct_stuff == NULL) {
diff --git a/zeffir/ffi_obj.c b/zeffir/ffi_obj.c
--- a/zeffir/ffi_obj.c
+++ b/zeffir/ffi_obj.c
@@ -203,15 +203,13 @@
if (ctitem->ct_flags & CT_PRIMITIVE_CHAR)
datasize *= 2; /* forcefully add another character: a null */
- /* XXX
if ((ctitem->ct_flags & CT_WITH_VAR_ARRAY) && init != Py_None) {
Py_ssize_t optvarsize = datasize;
if (convert_struct_from_object(NULL,ctitem, init, &optvarsize) < 0)
return NULL;
datasize = optvarsize;
- }*/
+ }
}
- /* XXX
else if (ct->ct_flags & CT_ARRAY) {
dataoffset = offsetof(CDataObject_own_nolength, alignment);
datasize = ct->ct_size;
@@ -229,7 +227,7 @@
return NULL;
}
}
- }*/
+ }
else {
PyErr_Format(PyExc_TypeError,
"expected a pointer or array ctype, got '%s'",
@@ -247,12 +245,11 @@
memset(cd->c_data, 0, datasize);
if (init != Py_None) {
- /* XXX
if (convert_from_object(cd->c_data,
(ct->ct_flags & CT_POINTER) ? ct->ct_itemdescr : ct, init) < 0) {
Py_DECREF(cd);
return NULL;
- }*/
+ }
}
return (PyObject *)cd;
}
diff --git a/zeffir/test/test_cdata.py b/zeffir/test/test_cdata.py
--- a/zeffir/test/test_cdata.py
+++ b/zeffir/test/test_cdata.py
@@ -13,3 +13,15 @@
assert p[0] == 0
p[0] = 43
assert p[0] == 43
+
+def test_cdata_array_fixed():
+ ffi = support.new_ffi()
+ p = ffi.new("int[5]")
+ assert p[4] == 0
+ p[4] = 43
+ assert p[4] == 43
+
+def test_cdata_array_incomplete():
+ ffi = support.new_ffi()
+ p = ffi.new("int[]", [10, 20, 30])
+ assert p[2] == 30
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit