Author: Armin Rigo <[email protected]>
Branch:
Changeset: r2825:d0f7cb27f93f
Date: 2016-12-06 22:29 +0100
http://bitbucket.org/cffi/cffi/changeset/d0f7cb27f93f/
Log: test and fix for b6adad5f4ea3, actually reverting some C changes
that are not necessary and cause segfaults
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1605,13 +1605,6 @@
#endif
}
-static PyObject *
-cdataowning_no_generic_alloc(PyTypeObject *type, Py_ssize_t nitems)
-{
- PyErr_SetString(PyExc_SystemError, "cdataowning: no generic alloc");
- return NULL;
-}
-
static void cdataowning_dealloc(CDataObject *cd)
{
assert(!(cd->c_type->ct_flags & (CT_IS_VOID_PTR | CT_FUNCTIONPTR)));
@@ -2882,8 +2875,8 @@
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
- PyType_GenericAlloc, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
PyObject_Del, /* tp_free */
};
@@ -2924,8 +2917,8 @@
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
- cdataowning_no_generic_alloc, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
free, /* tp_free */
};
@@ -2967,8 +2960,8 @@
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
- PyType_GenericAlloc, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
diff --git a/testing/cffi0/test_ffi_backend.py
b/testing/cffi0/test_ffi_backend.py
--- a/testing/cffi0/test_ffi_backend.py
+++ b/testing/cffi0/test_ffi_backend.py
@@ -493,3 +493,15 @@
def test_negative_array_size(self):
ffi = FFI()
py.test.raises(ValueError, ffi.cast, "int[-5]", 0)
+
+ def test_cannot_instantiate_manually(self):
+ ffi = FFI()
+ ct = type(ffi.typeof("void *"))
+ py.test.raises(TypeError, ct)
+ py.test.raises(TypeError, ct, ffi.NULL)
+ for cd in [type(ffi.cast("void *", 0)),
+ type(ffi.new("char[]", 3)),
+ type(ffi.gc(ffi.NULL, lambda x: None))]:
+ py.test.raises(TypeError, cd)
+ py.test.raises(TypeError, cd, ffi.NULL)
+ py.test.raises(TypeError, cd, ffi.typeof("void *"))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit