@@ -144,35 +144,11 @@ pylong_aspid(PyObject *module, PyObject *arg)
144144static PyObject *
145145layout_to_dict (const PyLongLayout * layout )
146146{
147- PyObject * dict = PyDict_New ();
148- if (dict == NULL ) {
149- goto error ;
150- }
151-
152- #define SET_DICT (KEY , EXPR ) \
153- do { \
154- PyObject *value = (EXPR); \
155- if (value == NULL) { \
156- goto error; \
157- } \
158- int res = PyDict_SetItemString(dict, KEY, value); \
159- Py_DECREF(value); \
160- if (res < 0) { \
161- goto error; \
162- } \
163- } while (0)
164-
165- SET_DICT ("bits_per_digit" , PyLong_FromUnsignedLong (layout -> bits_per_digit ));
166- SET_DICT ("digit_size" , PyLong_FromUnsignedLong (layout -> digit_size ));
167- SET_DICT ("digits_order" , PyLong_FromLong (layout -> digits_order ));
168- SET_DICT ("digit_endianness" , PyLong_FromLong (layout -> digit_endianness ));
169- #undef SET_DICT
170-
171- return dict ;
172-
173- error :
174- Py_XDECREF (dict );
175- return NULL ;
147+ return Py_BuildValue ("{sisisisi}" ,
148+ "bits_per_digit" , (int )layout -> bits_per_digit ,
149+ "digit_size" , (int )layout -> digit_size ,
150+ "digits_order" , (int )layout -> digits_order ,
151+ "digit_endianness" , (int )layout -> digit_endianness );
176152}
177153
178154
@@ -185,6 +161,9 @@ pylong_export(PyObject *module, PyObject *obj)
185161 }
186162
187163 if (export_long .digits == NULL ) {
164+ assert (export_long .negative == 0 );
165+ assert (export_long .ndigits == 0 );
166+ assert (export_long .digits == NULL );
188167 return PyLong_FromInt64 (export_long .value );
189168 // PyLong_FreeExport() is not needed in this case
190169 }
@@ -209,6 +188,7 @@ pylong_export(PyObject *module, PyObject *obj)
209188 Py_DECREF (item );
210189 }
211190
191+ assert (export_long .value == 0 );
212192 PyObject * res = Py_BuildValue ("(iN)" , export_long .negative , digits );
213193
214194 PyLong_FreeExport (& export_long );
@@ -228,6 +208,7 @@ pylongwriter_create(PyObject *module, PyObject *args)
228208{
229209 int negative ;
230210 PyObject * list ;
211+ // TODO(vstinner): write test for negative ndigits and digits==NULL
231212 if (!PyArg_ParseTuple (args , "iO!" , & negative , & PyList_Type , & list )) {
232213 return NULL ;
233214 }
0 commit comments