@@ -104,12 +104,40 @@ _check_tuple_item_is_NULL(PyObject *Py_UNUSED(module), PyObject *args)
104104}
105105
106106
107+ static PyObject *
108+ tuple_fromarray (PyObject * Py_UNUSED (module ), PyObject * args )
109+ {
110+ PyObject * src ;
111+ Py_ssize_t size = UNINITIALIZED_SIZE ;
112+ if (!PyArg_ParseTuple (args , "O|n" , & src , & size )) {
113+ return NULL ;
114+ }
115+ if (src != Py_None && !PyTuple_Check (src )) {
116+ PyErr_SetString (PyExc_TypeError , "expect a tuple" );
117+ return NULL ;
118+ }
119+
120+ PyObject * * items ;
121+ if (src != Py_None ) {
122+ items = & PyTuple_GET_ITEM (src , 0 );
123+ if (size == UNINITIALIZED_SIZE ) {
124+ size = PyTuple_GET_SIZE (src );
125+ }
126+ }
127+ else {
128+ items = NULL ;
129+ }
130+ return PyTuple_FromArray (items , size );
131+ }
132+
133+
107134static PyMethodDef test_methods [] = {
108135 {"tuple_get_size" , tuple_get_size , METH_O },
109136 {"tuple_get_item" , tuple_get_item , METH_VARARGS },
110137 {"tuple_set_item" , tuple_set_item , METH_VARARGS },
111138 {"_tuple_resize" , _tuple_resize , METH_VARARGS },
112139 {"_check_tuple_item_is_NULL" , _check_tuple_item_is_NULL , METH_VARARGS },
140+ {"tuple_fromarray" , tuple_fromarray , METH_VARARGS },
113141 {NULL },
114142};
115143
0 commit comments