Skip to content

Commit 385e1dc

Browse files
committed
implemented append_ssize_t to consolidate appending
1 parent a4c4536 commit 385e1dc

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/auto_map.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616
# include "auto_map.h"
1717
# include "utilities.h"
1818

19-
20-
// # define DEBUG_MSG_OBJ(msg, obj) \
21-
// fprintf(stderr, "--- %s: %i: %s: ", __FILE__, __LINE__, __FUNCTION__); \
22-
// fprintf(stderr, #msg " "); \
23-
// PyObject_Print(obj, stderr, 0); \
24-
// fprintf(stderr, "\n"); \
25-
// fflush(stderr); \
26-
2719
//------------------------------------------------------------------------------
2820
// Common
2921

@@ -1921,6 +1913,20 @@ fam_get_all(FAMObject *self, PyObject *key) {
19211913
# undef GET_ALL_FLEXIBLE
19221914

19231915

1916+
static inline int
1917+
append_ssize_t(
1918+
PyObject* list,
1919+
Py_ssize_t value)
1920+
{
1921+
PyObject* v = PyLong_FromSsize_t(value);
1922+
if (v == NULL) {
1923+
return -1;
1924+
}
1925+
int err = PyList_Append(list, v);
1926+
Py_DECREF(v);
1927+
return err;
1928+
}
1929+
19241930
// Give an array of the same kind as KAT, lookup and load any keys_pos. Depends on self, key_size, key_array, table_pos, i, k, values
19251931
# define GET_ANY_SCALARS(npy_type_src, npy_type_dst, kat, lookup_func, hash_func, post_deref) \
19261932
{ \
@@ -1936,13 +1942,10 @@ fam_get_all(FAMObject *self, PyObject *key) {
19361942
continue; \
19371943
} \
19381944
keys_pos = self->table[table_pos].keys_pos; \
1939-
PyObject* p = PyLong_FromSsize_t(keys_pos); \
1940-
if (PyList_Append(values, p)) { \
1941-
Py_DECREF(p); \
1945+
if (append_ssize_t(values, keys_pos)) { \
19421946
Py_DECREF(values); \
19431947
return NULL; \
19441948
} \
1945-
Py_DECREF(p); \
19461949
} \
19471950
} \
19481951

@@ -1963,13 +1966,10 @@ fam_get_all(FAMObject *self, PyObject *key) {
19631966
continue; \
19641967
} \
19651968
keys_pos = self->table[table_pos].keys_pos; \
1966-
PyObject* p = PyLong_FromSsize_t(keys_pos); \
1967-
if (PyList_Append(values, p)) { \
1968-
Py_DECREF(p); \
1969+
if (append_ssize_t(values, keys_pos)) { \
19691970
Py_DECREF(values); \
19701971
return NULL; \
19711972
} \
1972-
Py_DECREF(p); \
19731973
} \
19741974
} \
19751975

@@ -2012,12 +2012,10 @@ fam_get_any(FAMObject *self, PyObject *key) {
20122012
}
20132013
continue;
20142014
}
2015-
PyObject* p = PyLong_FromSsize_t(keys_pos);
2016-
if (PyList_Append(values, p)) {
2015+
if (append_ssize_t(values, keys_pos)) {
20172016
Py_DECREF(values);
20182017
return NULL;
20192018
}
2020-
Py_DECREF(p);
20212019
}
20222020
}
20232021
else {
@@ -2093,12 +2091,10 @@ fam_get_any(FAMObject *self, PyObject *key) {
20932091
}
20942092
continue; // do not raise
20952093
}
2096-
PyObject* p = PyLong_FromSsize_t(keys_pos);
2097-
if (PyList_Append(values, p)) {
2094+
if (append_ssize_t(values, keys_pos)) {
20982095
Py_DECREF(values);
20992096
return NULL;
21002097
}
2101-
Py_DECREF(p);
21022098
}
21032099
}
21042100
}

0 commit comments

Comments
 (0)