{0},
};
+/* bozo: __getstate__ that raises TypeError */
+
+static PyObject *
+bozo_func(PyObject *self, PyObject *args)
+{
+ PyErr_SetString(PyExc_TypeError,
+ "a class that defines __slots__ without "
+ "defining __getstate__ cannot be pickled");
+ return NULL;
+}
+
+static PyMethodDef bozo_ml = {"__getstate__", bozo_func};
+
+static PyObject *bozo_obj = NULL;
+
static PyObject *
type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
{
/* XXX Check against null bytes in name */
}
}
+ if (slots != NULL) {
+ /* See if *this* class defines __getstate__ */
+ PyObject *getstate = PyDict_GetItemString(dict,
+ "__getstate__");
+ if (getstate == NULL) {
+ /* If not, provide a bozo that raises TypeError */
+ if (bozo_obj == NULL) {
+ bozo_obj = PyCFunction_New(&bozo_ml, NULL);
+ if (bozo_obj == NULL) {
+ /* XXX decref various things */
+ return NULL;
+ }
+ }
+ if (PyDict_SetItemString(dict,
+ "__getstate__",
+ bozo_obj) < 0) {
+ /* XXX decref various things */
+ return NULL;
+ }
+ }
+ }
if (slots == NULL && base->tp_dictoffset == 0 &&
(base->tp_setattro == PyObject_GenericSetAttr ||
base->tp_setattro == NULL)) {
descr = PyDescr_NewMethod(type, meth);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict,meth->ml_name,descr) < 0)
+ if (PyDict_SetItemString(dict,meth->ml_name, descr) < 0)
return -1;
Py_DECREF(descr);
}