diff -r 8d572bf526e6 Objects/typeobject.c --- a/Objects/typeobject.c Sun Jan 26 21:35:22 2014 -0500 +++ b/Objects/typeobject.c Mon Jan 27 18:30:38 2014 +0800 @@ -6,6 +6,10 @@ #include +/*[clinic input] +class type "PyObject *" "PyType_Type" +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ /* Support type attribute cache */ @@ -3991,28 +3995,91 @@ return res; } +/*[clinic input] +type.__reduce__ + + proto: int = 0 + / + +Helper for pickle +[clinic start generated code]*/ + +PyDoc_STRVAR(type___reduce____doc__, +"__reduce__(self, proto=0)\n" +"Helper for pickle"); + +#define TYPE___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)type___reduce__, METH_VARARGS, type___reduce____doc__}, + static PyObject * -object_reduce(PyObject *self, PyObject *args) -{ +type___reduce___impl(PyObject *self, int proto); + +static PyObject * +type___reduce__(PyObject *self, PyObject *args) +{ + PyObject *return_value = NULL; int proto = 0; - if (!PyArg_ParseTuple(args, "|i:__reduce__", &proto)) - return NULL; - + if (!PyArg_ParseTuple(args, + "|i:__reduce__", + &proto)) + goto exit; + return_value = type___reduce___impl(self, proto); + +exit: + return return_value; +} + +static PyObject * +type___reduce___impl(PyObject *self, int proto) +/*[clinic end generated code: checksum=2100f8c49ec9b80cb7c71487adfd92bcf09c7735]*/ +{ return _common_reduce(self, proto); } +/*[clinic input] +type.__reduce_ex__ + + proto: int = 0 + / + +Helper for pickle +[clinic start generated code]*/ + +PyDoc_STRVAR(type___reduce_ex____doc__, +"__reduce_ex__(self, proto=0)\n" +"Helper for pickle"); + +#define TYPE___REDUCE_EX___METHODDEF \ + {"__reduce_ex__", (PyCFunction)type___reduce_ex__, METH_VARARGS, type___reduce_ex____doc__}, + static PyObject * -object_reduce_ex(PyObject *self, PyObject *args) +type___reduce_ex___impl(PyObject *self, int proto); + +static PyObject * +type___reduce_ex__(PyObject *self, PyObject *args) +{ + PyObject *return_value = NULL; + int proto = 0; + + if (!PyArg_ParseTuple(args, + "|i:__reduce_ex__", + &proto)) + goto exit; + return_value = type___reduce_ex___impl(self, proto); + +exit: + return return_value; +} + +static PyObject * +type___reduce_ex___impl(PyObject *self, int proto) +/*[clinic end generated code: checksum=cc219b3e186648a5e4b57eb1abc6635660e83c24]*/ { static PyObject *objreduce; PyObject *reduce, *res; - int proto = 0; _Py_IDENTIFIER(__reduce__); - if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto)) - return NULL; - if (objreduce == NULL) { objreduce = _PyDict_GetItemId(PyBaseObject_Type.tp_dict, &PyId___reduce__); @@ -4068,16 +4135,48 @@ def __format__(self, format_spec): return format(str(self), format_spec) */ +/*[clinic input] +type.__format__ + + format_spec: unicode + / + +Default object formatter +[clinic start generated code]*/ + +PyDoc_STRVAR(type___format____doc__, +"__format__(self, format_spec)\n" +"Default object formatter"); + +#define TYPE___FORMAT___METHODDEF \ + {"__format__", (PyCFunction)type___format__, METH_VARARGS, type___format____doc__}, + static PyObject * -object_format(PyObject *self, PyObject *args) -{ +type___format___impl(PyObject *self, PyObject *format_spec); + +static PyObject * +type___format__(PyObject *self, PyObject *args) +{ + PyObject *return_value = NULL; PyObject *format_spec; + + if (!PyArg_ParseTuple(args, + "U:__format__", + &format_spec)) + goto exit; + return_value = type___format___impl(self, format_spec); + +exit: + return return_value; +} + +static PyObject * +type___format___impl(PyObject *self, PyObject *format_spec) +/*[clinic end generated code: checksum=d1f547dd1ff1d236c653fcd13c927494b7110ffa]*/ +{ PyObject *self_as_str = NULL; PyObject *result = NULL; - if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) - return NULL; - self_as_str = PyObject_Str(self); if (self_as_str != NULL) { /* Issue 7994: If we're converting to a string, we @@ -4097,8 +4196,35 @@ return result; } +/*[clinic input] +type.__sizeof__ + +__sizeof__() -> int + +size of object in memory, in bytes +[clinic start generated code]*/ + +PyDoc_STRVAR(type___sizeof____doc__, +"__sizeof__(self)\n" +"__sizeof__() -> int\n" +"\n" +"size of object in memory, in bytes"); + +#define TYPE___SIZEOF___METHODDEF \ + {"__sizeof__", (PyCFunction)type___sizeof__, METH_NOARGS, type___sizeof____doc__}, + static PyObject * -object_sizeof(PyObject *self, PyObject *args) +type___sizeof___impl(PyObject *self); + +static PyObject * +type___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return type___sizeof___impl(self); +} + +static PyObject * +type___sizeof___impl(PyObject *self) +/*[clinic end generated code: checksum=24f5c379e8e84814161ff9655bd8d75cfb4c029d]*/ { Py_ssize_t res, isize; @@ -4114,8 +4240,35 @@ /* __dir__ for generic objects: returns __dict__, __class__, and recursively up the __class__.__bases__ chain. */ +/*[clinic input] +type.__dir__ + +__dir__() -> list + +default dir() implementation +[clinic start generated code]*/ + +PyDoc_STRVAR(type___dir____doc__, +"__dir__(self)\n" +"__dir__() -> list\n" +"\n" +"default dir() implementation"); + +#define TYPE___DIR___METHODDEF \ + {"__dir__", (PyCFunction)type___dir__, METH_NOARGS, type___dir____doc__}, + static PyObject * -object_dir(PyObject *self, PyObject *args) +type___dir___impl(PyObject *self); + +static PyObject * +type___dir__(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ + return type___dir___impl(self); +} + +static PyObject * +type___dir___impl(PyObject *self) +/*[clinic end generated code: checksum=71aac6d2e8c487c19269c50b8de87ac6f120d263]*/ { PyObject *result = NULL; PyObject *dict = NULL; @@ -4159,18 +4312,13 @@ } static PyMethodDef object_methods[] = { - {"__reduce_ex__", object_reduce_ex, METH_VARARGS, - PyDoc_STR("helper for pickle")}, - {"__reduce__", object_reduce, METH_VARARGS, - PyDoc_STR("helper for pickle")}, + TYPE___REDUCE_EX___METHODDEF + TYPE___REDUCE___METHODDEF {"__subclasshook__", object_subclasshook, METH_CLASS | METH_VARARGS, object_subclasshook_doc}, - {"__format__", object_format, METH_VARARGS, - PyDoc_STR("default object formatter")}, - {"__sizeof__", object_sizeof, METH_NOARGS, - PyDoc_STR("__sizeof__() -> int\nsize of object in memory, in bytes")}, - {"__dir__", object_dir, METH_NOARGS, - PyDoc_STR("__dir__() -> list\ndefault dir() implementation")}, + TYPE___FORMAT___METHODDEF + TYPE___SIZEOF___METHODDEF + TYPE___DIR___METHODDEF {0} };