@@ -1189,7 +1189,11 @@ lookup(FAMObject *self, PyObject *key) {
11891189
11901190// Insert a key_pos, hash pair into the table. Assumes table already has appropriate size. When inserting a new itme, `hash` is -1, forcing a fresh hash to be computed here. Return 0 on success, -1 on error.
11911191static int
1192- insert_obj (FAMObject * self , PyObject * key , Py_ssize_t keys_pos , Py_hash_t hash )
1192+ insert_obj (
1193+ FAMObject * self ,
1194+ PyObject * key ,
1195+ Py_ssize_t keys_pos ,
1196+ Py_hash_t hash )
11931197{
11941198 if (hash == -1 ) {
11951199 hash = PyObject_Hash (key );
@@ -1819,6 +1823,9 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
18191823
18201824 if (!keys ) {
18211825 keys = PyList_New (0 );
1826+ if (!keys ) {
1827+ return -1 ;
1828+ }
18221829 }
18231830 else if (PyObject_TypeCheck (keys , & FAMType )) {
18241831 // Use `keys` as old, `self` as new, and fill from old to new. This returns the same error codes as this function.
@@ -1831,6 +1838,8 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
18311838 return -1 ;
18321839 }
18331840 int array_t = PyArray_TYPE (a );
1841+ keys_size = PyArray_SIZE (a );
1842+
18341843 if (cls != & AMType &&
18351844 (PyTypeNum_ISINTEGER (array_t ) // signed and unsigned
18361845 || PyTypeNum_ISFLOAT (array_t )
@@ -1843,25 +1852,26 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
18431852 keys_array_type = at_to_kat (array_t );
18441853 Py_INCREF (keys );
18451854 }
1846- else { // if an AutoMap or an array that we do not custom-hash, we create a list
1855+ else { // if an AutoMap or an array that we do not handle, create a list
18471856 if (array_t == NPY_DATETIME || array_t == NPY_TIMEDELTA ){
18481857 keys = PySequence_List (keys ); // force scalars
18491858 }
18501859 else {
18511860 keys = PyArray_ToList (a ); // converts to objs
18521861 }
1862+ if (!keys ) {
1863+ return -1 ;
1864+ }
18531865 }
1854- keys_size = PyArray_SIZE (a );
18551866 }
18561867 else { // assume an arbitrary iterable
18571868 keys = PySequence_List (keys );
1869+ if (!keys ) {
1870+ return -1 ;
1871+ }
18581872 keys_size = PyList_GET_SIZE (keys );
18591873 }
18601874
1861- if (!keys ) {
1862- return -1 ;
1863- }
1864-
18651875 fam -> keys = keys ;
18661876 fam -> keys_array_type = keys_array_type ;
18671877 fam -> keys_size = keys_size ;
@@ -1870,7 +1880,6 @@ fam_init(PyObject *self, PyObject *args, PyObject *kwargs)
18701880
18711881 // NOTE: on itialization, grow_table() does not use keys
18721882 if (grow_table (fam , keys_size )) {
1873- // assume `fam->keys` will be decrefed by the caller
18741883 return -1 ;
18751884 }
18761885 Py_ssize_t i = 0 ;
0 commit comments