diff -r 7394e5f85284 Misc/NEWS --- a/Misc/NEWS Sun Oct 12 05:11:40 2014 +0300 +++ b/Misc/NEWS Sun Oct 12 04:44:46 2014 +0100 @@ -1260,6 +1260,10 @@ Tools/Demos ----------- +- Issue #22615: Argument Clinic now supports the "type" argument for the + int converter. This permits using the int converter with enums and + typedefs. + - Issue #20076: The makelocalealias.py script no longer ignores UTF-8 mapping. - Issue #20079: The makelocalealias.py script now can parse the SUPPORTED file diff -r 7394e5f85284 Modules/arraymodule.c --- a/Modules/arraymodule.c Sun Oct 12 05:11:40 2014 +0300 +++ b/Modules/arraymodule.c Sun Oct 12 04:44:46 2014 +0100 @@ -59,7 +59,50 @@ #define PyArrayIter_Check(op) PyObject_TypeCheck(op, &PyArrayIter_Type) -/* Must come after arrayobject and arrayiterobject definitions. */ +enum machine_format_code { + UNKNOWN_FORMAT = -1, + /* UNKNOWN_FORMAT is used to indicate that the machine format for an + * array type code cannot be interpreted. When this occurs, a list of + * Python objects is used to represent the content of the array + * instead of using the memory content of the array directly. In that + * case, the array_reconstructor mechanism is bypassed completely, and + * the standard array constructor is used instead. + * + * This is will most likely occur when the machine doesn't use IEEE + * floating-point numbers. + */ + + UNSIGNED_INT8 = 0, + SIGNED_INT8 = 1, + UNSIGNED_INT16_LE = 2, + UNSIGNED_INT16_BE = 3, + SIGNED_INT16_LE = 4, + SIGNED_INT16_BE = 5, + UNSIGNED_INT32_LE = 6, + UNSIGNED_INT32_BE = 7, + SIGNED_INT32_LE = 8, + SIGNED_INT32_BE = 9, + UNSIGNED_INT64_LE = 10, + UNSIGNED_INT64_BE = 11, + SIGNED_INT64_LE = 12, + SIGNED_INT64_BE = 13, + IEEE_754_FLOAT_LE = 14, + IEEE_754_FLOAT_BE = 15, + IEEE_754_DOUBLE_LE = 16, + IEEE_754_DOUBLE_BE = 17, + UTF16_LE = 18, + UTF16_BE = 19, + UTF32_LE = 20, + UTF32_BE = 21 +}; +#define MACHINE_FORMAT_CODE_MIN 0 +#define MACHINE_FORMAT_CODE_MAX 21 + + +/* + * Must come after arrayobject, arrayiterobject, + * and enum machine_code_type definitions. + */ #include "clinic/arraymodule.c.h" #define array_Check(op) PyObject_TypeCheck(op, &Arraytype) @@ -1712,45 +1755,6 @@ /*********************** Pickling support ************************/ -enum machine_format_code { - UNKNOWN_FORMAT = -1, - /* UNKNOWN_FORMAT is used to indicate that the machine format for an - * array type code cannot be interpreted. When this occurs, a list of - * Python objects is used to represent the content of the array - * instead of using the memory content of the array directly. In that - * case, the array_reconstructor mechanism is bypassed completely, and - * the standard array constructor is used instead. - * - * This is will most likely occur when the machine doesn't use IEEE - * floating-point numbers. - */ - - UNSIGNED_INT8 = 0, - SIGNED_INT8 = 1, - UNSIGNED_INT16_LE = 2, - UNSIGNED_INT16_BE = 3, - SIGNED_INT16_LE = 4, - SIGNED_INT16_BE = 5, - UNSIGNED_INT32_LE = 6, - UNSIGNED_INT32_BE = 7, - SIGNED_INT32_LE = 8, - SIGNED_INT32_BE = 9, - UNSIGNED_INT64_LE = 10, - UNSIGNED_INT64_BE = 11, - SIGNED_INT64_LE = 12, - SIGNED_INT64_BE = 13, - IEEE_754_FLOAT_LE = 14, - IEEE_754_FLOAT_BE = 15, - IEEE_754_DOUBLE_LE = 16, - IEEE_754_DOUBLE_BE = 17, - UTF16_LE = 18, - UTF16_BE = 19, - UTF32_LE = 20, - UTF32_BE = 21 -}; -#define MACHINE_FORMAT_CODE_MIN 0 -#define MACHINE_FORMAT_CODE_MAX 21 - static const struct mformatdescr { size_t size; int is_signed; @@ -1939,8 +1943,8 @@ [clinic start generated code]*/ static PyObject * -array__array_reconstructor_impl(PyModuleDef *module, PyTypeObject *arraytype, int typecode, int mformat_code, PyObject *items) -/*[clinic end generated code: output=a0a4ab61c2fbc17a input=450d59a5373c4eea]*/ +array__array_reconstructor_impl(PyModuleDef *module, PyTypeObject *arraytype, int typecode, enum machine_format_code mformat_code, PyObject *items) +/*[clinic end generated code: output=c51081ec91caf7e9 input=f72492708c0a1d50]*/ { PyObject *converted_items; PyObject *result; diff -r 7394e5f85284 Modules/clinic/arraymodule.c.h --- a/Modules/clinic/arraymodule.c.h Sun Oct 12 05:11:40 2014 +0300 +++ b/Modules/clinic/arraymodule.c.h Sun Oct 12 04:44:46 2014 +0100 @@ -446,7 +446,7 @@ {"_array_reconstructor", (PyCFunction)array__array_reconstructor, METH_VARARGS, array__array_reconstructor__doc__}, static PyObject * -array__array_reconstructor_impl(PyModuleDef *module, PyTypeObject *arraytype, int typecode, int mformat_code, PyObject *items); +array__array_reconstructor_impl(PyModuleDef *module, PyTypeObject *arraytype, int typecode, enum machine_format_code mformat_code, PyObject *items); static PyObject * array__array_reconstructor(PyModuleDef *module, PyObject *args) @@ -454,7 +454,7 @@ PyObject *return_value = NULL; PyTypeObject *arraytype; int typecode; - int mformat_code; + enum machine_format_code mformat_code; PyObject *items; if (!PyArg_ParseTuple(args, @@ -502,4 +502,4 @@ #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=dff8eae01f0ab208 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e1deb61c6a3bc8c8 input=a9049054013a1b77]*/ diff -r 7394e5f85284 Objects/bytesobject.c --- a/Objects/bytesobject.c Sun Oct 12 05:11:40 2014 +0300 +++ b/Objects/bytesobject.c Sun Oct 12 04:44:46 2014 +0100 @@ -1819,7 +1819,7 @@ static PyObject * bytes_translate_impl(PyBytesObject *self, PyObject *table, int group_right_1, PyObject *deletechars) -/*[clinic end generated code: output=f0f29a57f41df5d8 input=a90fad893c3c88d7]*/ +/*[clinic end generated code: output=f0f29a57f41df5d8 input=d8fa5519d7cc4be7]*/ { char *input, *output; const char *table_chars; diff -r 7394e5f85284 Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Sun Oct 12 05:11:40 2014 +0300 +++ b/Tools/clinic/clinic.py Sun Oct 12 04:44:46 2014 +0100 @@ -2426,11 +2426,13 @@ format_unit = 'i' c_ignored_default = "0" - def converter_init(self, *, types='int'): + def converter_init(self, *, types='int', type=None): if types == 'str': self.format_unit = 'C' elif types != 'int': fail("int_converter: illegal 'types' argument") + if type != None: + self.type = type class unsigned_int_converter(CConverter): type = 'unsigned int'