diff -r a62072cf50a2 Modules/xxlimited.c --- a/Modules/xxlimited.c Wed Jan 22 12:26:01 2014 +0100 +++ b/Modules/xxlimited.c Wed Jan 22 18:18:30 2014 +0200 @@ -14,6 +14,12 @@ /* Xxo objects */ +/*[clinic input] +module xx +class xx.Xxo +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + #include "Python.h" static PyObject *ErrorObject; @@ -47,12 +53,45 @@ PyObject_Del(self); } +/*[clinic input] +xx.Xxo.demo + + obj: object = NULL + / + +Return obj. +[clinic start generated code]*/ + +PyDoc_STRVAR(xx_Xxo_demo__doc__, +"demo(obj=None)\n" +"Return obj."); + +#define XX_XXO_DEMO_METHODDEF \ + {"demo", (PyCFunction)xx_Xxo_demo, METH_VARARGS, xx_Xxo_demo__doc__}, + static PyObject * -Xxo_demo(XxoObject *self, PyObject *args) +xx_Xxo_demo_impl(PyObject *self, PyObject *obj); + +static PyObject * +xx_Xxo_demo(PyObject *self, PyObject *args) { - PyObject *o = NULL; - if (!PyArg_ParseTuple(args, "|O:demo", &o)) - return NULL; + PyObject *return_value = NULL; + PyObject *obj = NULL; + + if (!PyArg_UnpackTuple(args, "demo", + 0, 1, + &obj)) + goto exit; + return_value = xx_Xxo_demo_impl(self, obj); + +exit: + return return_value; +} + +static PyObject * +xx_Xxo_demo_impl(PyObject *self, PyObject *obj) +/*[clinic end generated code: checksum=f83663e46cb426aeb3f81f9fb6dd57370d23cf11]*/ +{ /* Test availability of fast type checks */ if (o != NULL && PyUnicode_Check(o)) { Py_INCREF(o); @@ -121,18 +160,49 @@ /* Function of two integers returning integer */ -PyDoc_STRVAR(xx_foo_doc, -"foo(i,j)\n\ -\n\ -Return the sum of i and j."); +/*[clinic input] +xx.foo + + i: long + j: long + / + +Return the sum of i and j. +[clinic start generated code]*/ + +PyDoc_STRVAR(xx_foo__doc__, +"foo(i, j)\n" +"Return the sum of i and j."); + +#define XX_FOO_METHODDEF \ + {"foo", (PyCFunction)xx_foo, METH_VARARGS, xx_foo__doc__}, static PyObject * -xx_foo(PyObject *self, PyObject *args) +xx_foo_impl(PyModuleDef *module, long i, long j); + +static PyObject * +xx_foo(PyModuleDef *module, PyObject *args) { - long i, j; + PyObject *return_value = NULL; + long i; + long j; + + if (!PyArg_ParseTuple(args, + "ll:foo", + &i, &j)) + goto exit; + return_value = xx_foo_impl(module, i, j); + +exit: + return return_value; +} + +static PyObject * +xx_foo_impl(PyModuleDef *module, long i, long j) +/*[clinic end generated code: checksum=7991a072acfb837a3162c33816f28b46056e5277]*/ +{ long res; - if (!PyArg_ParseTuple(args, "ll:foo", &i, &j)) - return NULL; + res = i+j; /* XXX Do something here */ return PyLong_FromLong(res); } @@ -140,13 +210,34 @@ /* Function of no arguments returning new Xxo object */ +/*[clinic input] +xx.new + +Create a new Xxo object. +[clinic start generated code]*/ + +PyDoc_STRVAR(xx_new__doc__, +"new()\n" +"Create a new Xx object."); + +#define XX_NEW_METHODDEF \ + {"new", (PyCFunction)xx_new, METH_NOARGS, xx_new__doc__}, + static PyObject * -xx_new(PyObject *self, PyObject *args) +xx_new_impl(PyModuleDef *module); + +static PyObject * +xx_new(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return xx_new_impl(module); +} + +static PyObject * +xx_new_impl(PyModuleDef *module) +/*[clinic end generated code: checksum=93a319e1f5314637abbbdbc1ef3f6105f5ab8de5]*/ { XxoObject *rv; - if (!PyArg_ParseTuple(args, ":new")) - return NULL; rv = newXxoObject(args); if (rv == NULL) return NULL; @@ -212,10 +303,8 @@ static PyMethodDef xx_methods[] = { {"roj", xx_roj, METH_VARARGS, PyDoc_STR("roj(a,b) -> None")}, - {"foo", xx_foo, METH_VARARGS, - xx_foo_doc}, - {"new", xx_new, METH_VARARGS, - PyDoc_STR("new() -> new Xx object")}, + XX_FOO_METHODDEF + XX_NEW_METHODDEF {NULL, NULL} /* sentinel */ }; diff -r a62072cf50a2 Modules/xxmodule.c --- a/Modules/xxmodule.c Wed Jan 22 12:26:01 2014 +0100 +++ b/Modules/xxmodule.c Wed Jan 22 18:18:30 2014 +0200 @@ -14,6 +14,12 @@ /* Xxo objects */ +/*[clinic input] +module xx +class xx.Xxo +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + #include "Python.h" static PyObject *ErrorObject; @@ -47,11 +53,32 @@ PyObject_Del(self); } +/*[clinic input] +xx.Xxo.demo + +Return None. +[clinic start generated code]*/ + +PyDoc_STRVAR(xx_Xxo_demo__doc__, +"demo()\n" +"Return None."); + +#define XX_XXO_DEMO_METHODDEF \ + {"demo", (PyCFunction)xx_Xxo_demo, METH_NOARGS, xx_Xxo_demo__doc__}, + static PyObject * -Xxo_demo(XxoObject *self, PyObject *args) +xx_Xxo_demo_impl(PyObject *self); + +static PyObject * +xx_Xxo_demo(PyObject *self, PyObject *Py_UNUSED(ignored)) { - if (!PyArg_ParseTuple(args, ":demo")) - return NULL; + return xx_Xxo_demo_impl(self); +} + +static PyObject * +xx_Xxo_demo_impl(PyObject *self) +/*[clinic end generated code: checksum=0c451349930ab983aca4d3133e3a3486a2b34602]*/ +{ Py_INCREF(Py_None); return Py_None; } @@ -143,18 +170,18 @@ /* Function of two integers returning integer */ -PyDoc_STRVAR(xx_foo_doc, -"foo(i,j)\n\ -\n\ -Return the sum of i and j."); +/*[clinic input] +xx.foo -static PyObject * -xx_foo(PyObject *self, PyObject *args) + i: long + j: long + / + +Return the sum of i and j. +[clinic start generated code]*/ { - long i, j; long res; - if (!PyArg_ParseTuple(args, "ll:foo", &i, &j)) - return NULL; + res = i+j; /* XXX Do something here */ return PyLong_FromLong(res); } @@ -162,13 +189,14 @@ /* Function of no arguments returning new Xxo object */ -static PyObject * -xx_new(PyObject *self, PyObject *args) +/*[clinic input] +xx.new + +Create a new Xxo object. +[clinic start generated code]*/ { XxoObject *rv; - if (!PyArg_ParseTuple(args, ":new")) - return NULL; rv = newXxoObject(args); if (rv == NULL) return NULL; @@ -322,10 +350,8 @@ static PyMethodDef xx_methods[] = { {"roj", xx_roj, METH_VARARGS, PyDoc_STR("roj(a,b) -> None")}, - {"foo", xx_foo, METH_VARARGS, - xx_foo_doc}, - {"new", xx_new, METH_VARARGS, - PyDoc_STR("new() -> new Xx object")}, + XX_FOO_METHODDEF + XX_NEW_METHODDEF {"bug", xx_bug, METH_VARARGS, PyDoc_STR("bug(o) -> None")}, {NULL, NULL} /* sentinel */ diff -r a62072cf50a2 Modules/xxsubtype.c --- a/Modules/xxsubtype.c Wed Jan 22 12:26:01 2014 +0100 +++ b/Modules/xxsubtype.c Wed Jan 22 18:18:30 2014 +0200 @@ -1,6 +1,13 @@ #include "Python.h" #include "structmember.h" +/*[clinic input] +module xxsubtype +class xxsubtype.spamlist +class xxsubtype.spamdict +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + PyDoc_STRVAR(xxsubtype__doc__, "xxsubtype is an example module showing how to subtype builtin types from C.\n" "test_descr.py in the standard test suite requires it in order to complete.\n" @@ -23,21 +30,77 @@ int state; } spamlistobject; +/*[clinic input] +xxsubtype.spamlist.getstate + + self: self(type="spamlistobject *") + +Return the state. +[clinic start generated code]*/ + +PyDoc_STRVAR(xxsubtype_spamlist_getstate__doc__, +"getstate()\n" +"Return the state."); + +#define XXSUBTYPE_SPAMLIST_GETSTATE_METHODDEF \ + {"getstate", (PyCFunction)xxsubtype_spamlist_getstate, METH_NOARGS, xxsubtype_spamlist_getstate__doc__}, + static PyObject * -spamlist_getstate(spamlistobject *self, PyObject *args) +xxsubtype_spamlist_getstate_impl(spamlistobject *self); + +static PyObject * +xxsubtype_spamlist_getstate(PyObject *self, PyObject *Py_UNUSED(ignored)) { - if (!PyArg_ParseTuple(args, ":getstate")) - return NULL; + return xxsubtype_spamlist_getstate_impl((spamlistobject *)self); +} + +static PyObject * +xxsubtype_spamlist_getstate_impl(spamlistobject *self) +/*[clinic end generated code: checksum=fa0f90dfe7fcdc66947fccfa54d4425c828d23a3]*/ +{ return PyLong_FromLong(self->state); } +/*[clinic input] +xxsubtype.spamlist.setstate + + self: self(type="spamlistobject *") + state: int + / + +Set the state. +[clinic start generated code]*/ + +PyDoc_STRVAR(xxsubtype_spamlist_setstate__doc__, +"setstate(state)\n" +"Set the state."); + +#define XXSUBTYPE_SPAMLIST_SETSTATE_METHODDEF \ + {"setstate", (PyCFunction)xxsubtype_spamlist_setstate, METH_VARARGS, xxsubtype_spamlist_setstate__doc__}, + static PyObject * -spamlist_setstate(spamlistobject *self, PyObject *args) +xxsubtype_spamlist_setstate_impl(spamlistobject *self, int state); + +static PyObject * +xxsubtype_spamlist_setstate(PyObject *self, PyObject *args) { + PyObject *return_value = NULL; int state; - if (!PyArg_ParseTuple(args, "i:setstate", &state)) - return NULL; + if (!PyArg_ParseTuple(args, + "i:setstate", + &state)) + goto exit; + return_value = xxsubtype_spamlist_setstate_impl((spamlistobject *)self, state); + +exit: + return return_value; +} + +static PyObject * +xxsubtype_spamlist_setstate_impl(spamlistobject *self, int state) +/*[clinic end generated code: checksum=7755b9a7e3e62d7bf201e55631d76a1a40bf410f]*/ +{ self->state = state; Py_INCREF(Py_None); return Py_None; @@ -64,10 +127,8 @@ } static PyMethodDef spamlist_methods[] = { - {"getstate", (PyCFunction)spamlist_getstate, METH_VARARGS, - PyDoc_STR("getstate() -> state")}, - {"setstate", (PyCFunction)spamlist_setstate, METH_VARARGS, - PyDoc_STR("setstate(state)")}, + XXSUBTYPE_SPAMLIST_GETSTATE_METHODDEF + XXSUBTYPE_SPAMLIST_SETSTATE_METHODDEF /* These entries differ only in the flags; they are used by the tests in test.test_descr. */ {"classmeth", (PyCFunction)spamlist_specialmeth, @@ -148,31 +209,85 @@ int state; } spamdictobject; +/*[clinic input] +xxsubtype.spamdict.getstate + + self: self(type="spamdictobject *") + +Set the state. +[clinic start generated code]*/ + +PyDoc_STRVAR(xxsubtype_spamdict_getstate__doc__, +"getstate()\n" +"Set the state."); + +#define XXSUBTYPE_SPAMDICT_GETSTATE_METHODDEF \ + {"getstate", (PyCFunction)xxsubtype_spamdict_getstate, METH_NOARGS, xxsubtype_spamdict_getstate__doc__}, + static PyObject * -spamdict_getstate(spamdictobject *self, PyObject *args) +xxsubtype_spamdict_getstate_impl(spamdictobject *self); + +static PyObject * +xxsubtype_spamdict_getstate(PyObject *self, PyObject *Py_UNUSED(ignored)) { - if (!PyArg_ParseTuple(args, ":getstate")) - return NULL; + return xxsubtype_spamdict_getstate_impl((spamdictobject *)self); +} + +static PyObject * +xxsubtype_spamdict_getstate_impl(spamdictobject *self) +/*[clinic end generated code: checksum=6ab40fe27ebed136a16e5e8fb9d14f878902f701]*/ +{ return PyLong_FromLong(self->state); } +/*[clinic input] +xxsubtype.spamdict.setstate + + self: self(type="spamdictobject *") + state: int + / + +Set the state. +[clinic start generated code]*/ + +PyDoc_STRVAR(xxsubtype_spamdict_setstate__doc__, +"setstate(state)\n" +"Set the state."); + +#define XXSUBTYPE_SPAMDICT_SETSTATE_METHODDEF \ + {"setstate", (PyCFunction)xxsubtype_spamdict_setstate, METH_VARARGS, xxsubtype_spamdict_setstate__doc__}, + static PyObject * -spamdict_setstate(spamdictobject *self, PyObject *args) +xxsubtype_spamdict_setstate_impl(spamdictobject *self, int state); + +static PyObject * +xxsubtype_spamdict_setstate(PyObject *self, PyObject *args) { + PyObject *return_value = NULL; int state; - if (!PyArg_ParseTuple(args, "i:setstate", &state)) - return NULL; + if (!PyArg_ParseTuple(args, + "i:setstate", + &state)) + goto exit; + return_value = xxsubtype_spamdict_setstate_impl((spamdictobject *)self, state); + +exit: + return return_value; +} + +static PyObject * +xxsubtype_spamdict_setstate_impl(spamdictobject *self, int state) +/*[clinic end generated code: checksum=35750c3d587736a0aa655aa6e2d53744bd11120c]*/ +{ self->state = state; Py_INCREF(Py_None); return Py_None; } static PyMethodDef spamdict_methods[] = { - {"getstate", (PyCFunction)spamdict_getstate, METH_VARARGS, - PyDoc_STR("getstate() -> state")}, - {"setstate", (PyCFunction)spamdict_setstate, METH_VARARGS, - PyDoc_STR("setstate(state)")}, + XXSUBTYPE_SPAMDICT_GETSTATE_METHODDEF + XXSUBTYPE_SPAMDICT_SETSTATE_METHODDEF {NULL, NULL}, }; @@ -232,15 +347,49 @@ 0, /* tp_new */ }; +/*[clinic input] +xxsubtype.bench + + obj: object + name: PyBytesObject + n: int = 1000 + / +[clinic start generated code]*/ + +PyDoc_STRVAR(xxsubtype_bench__doc__, +"bench(obj, name, n=1000)"); + +#define XXSUBTYPE_BENCH_METHODDEF \ + {"bench", (PyCFunction)xxsubtype_bench, METH_VARARGS, xxsubtype_bench__doc__}, + static PyObject * -spam_bench(PyObject *self, PyObject *args) +xxsubtype_bench_impl(PyModuleDef *module, PyObject *obj, PyBytesObject *name, int n); + +static PyObject * +xxsubtype_bench(PyModuleDef *module, PyObject *args) { - PyObject *obj, *name, *res; + PyObject *return_value = NULL; + PyObject *obj; + PyBytesObject *name; int n = 1000; + + if (!PyArg_ParseTuple(args, + "OS|i:bench", + &obj, &name, &n)) + goto exit; + return_value = xxsubtype_bench_impl(module, obj, name, n); + +exit: + return return_value; +} + +static PyObject * +xxsubtype_bench_impl(PyModuleDef *module, PyObject *obj, PyBytesObject *name, int n) +/*[clinic end generated code: checksum=1ce30bf623e78d51f9124966c5d28af2a77e6bdd]*/ +{ + PyObject *res; time_t t0, t1; - if (!PyArg_ParseTuple(args, "OS|i", &obj, &name, &n)) - return NULL; t0 = clock(); while (--n >= 0) { res = PyObject_GetAttr(obj, name); @@ -253,7 +402,7 @@ } static PyMethodDef xxsubtype_functions[] = { - {"bench", spam_bench, METH_VARARGS}, + XXSUBTYPE_BENCH_METHODDEF {NULL, NULL} /* sentinel */ };