Skip to content

Commit

Permalink
MAINT: Remove final NPY_PY3K (numpygh-15283)
Browse files Browse the repository at this point in the history
These were the not-obviously-trivial cases for removing NPY_PY3K, others will follow in a seperate commit in numpygh-15281.
  • Loading branch information
sethtroisi authored and seberg committed Jan 7, 2020
1 parent 2a68c14 commit 7d159b4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 39 deletions.
9 changes: 2 additions & 7 deletions numpy/core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ static cache_bucket datacache[NBUCKETS];
static cache_bucket dimcache[NBUCKETS_DIM];

/* as the cache is managed in global variables verify the GIL is held */
#if defined(NPY_PY3K)
#define NPY_CHECK_GIL_HELD() PyGILState_Check()
#else
#define NPY_CHECK_GIL_HELD() 1
#endif

/*
* very simplistic small memory block cache to avoid more expensive libc
Expand All @@ -67,7 +62,7 @@ _npy_alloc_cache(npy_uintp nelem, npy_uintp esz, npy_uint msz,
void * p;
assert((esz == 1 && cache == datacache) ||
(esz == sizeof(npy_intp) && cache == dimcache));
assert(NPY_CHECK_GIL_HELD());
assert(PyGILState_Check());
if (nelem < msz) {
if (cache[nelem].available > 0) {
return cache[nelem].ptrs[--(cache[nelem].available)];
Expand Down Expand Up @@ -102,7 +97,7 @@ static NPY_INLINE void
_npy_free_cache(void * p, npy_uintp nelem, npy_uint msz,
cache_bucket * cache, void (*dealloc)(void *))
{
assert(NPY_CHECK_GIL_HELD());
assert(PyGILState_Check());
if (p != NULL && nelem < msz) {
if (cache[nelem].available < NCACHE) {
cache[nelem].ptrs[cache[nelem].available++] = p;
Expand Down
8 changes: 2 additions & 6 deletions numpy/core/src/multiarray/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,22 +1004,18 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op,
{
PyArrayObject *result;
PyArrayMultiIterObject *mit;
int val, cast = 0;
int val;

/* Cast arrays to a common type */
if (PyArray_TYPE(self) != PyArray_DESCR(other)->type_num) {
#if defined(NPY_PY3K)
/*
* Comparison between Bytes and Unicode is not defined in Py3K;
* we follow.
*/
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
#else
cast = 1;
#endif /* define(NPY_PY3K) */
}
if (cast || (PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(other))) {
if (PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(other)) {
PyObject *new;
if (PyArray_TYPE(self) == NPY_STRING &&
PyArray_DESCR(other)->type_num == NPY_UNICODE) {
Expand Down
10 changes: 2 additions & 8 deletions numpy/core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ OBJECT_to_@TOTYPE@(void *input, void *output, npy_intp n,
* #convert = 1*18, 0*3, 1*2,
* 1*18, 0*3, 1*2,
* 0*23#
* #convstr = (Int*9, Long*2, Float*4, Complex*3, Tuple*3, Long*2)*3#
* #convstr = (Long*9, Long*2, Float*4, Complex*3, Tuple*3, Long*2)*3#
*/

#if @convert@
Expand All @@ -1556,7 +1556,7 @@ static void
return;
}

#if defined(NPY_PY3K) && defined(IS_STRING)
#if defined(IS_STRING)
/* Work around some Python 3K */
new = PyUnicode_FromEncodedObject(temp, "ascii", "strict");
Py_DECREF(temp);
Expand All @@ -1571,13 +1571,7 @@ static void

/* call out to the Python builtin given by convstr */
args = Py_BuildValue("(N)", temp);
#if defined(NPY_PY3K)
#define PyInt_Type PyLong_Type
#endif
new = Py@convstr@_Type.tp_new(&Py@convstr@_Type, args, NULL);
#if defined(NPY_PY3K)
#undef PyInt_Type
#endif
Py_DECREF(args);
temp = new;
if (temp == NULL) {
Expand Down
12 changes: 0 additions & 12 deletions numpy/core/src/multiarray/conversion_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,18 +812,6 @@ PyArray_PyIntAsIntp_ErrMsg(PyObject *o, const char * msg)
* Since it is the usual case, first check if o is an integer. This is
* an exact check, since otherwise __index__ is used.
*/
#if !defined(NPY_PY3K)
if (PyInt_CheckExact(o)) {
#if (NPY_SIZEOF_LONG <= NPY_SIZEOF_INTP)
/* No overflow is possible, so we can just return */
return PyInt_AS_LONG(o);
#else
long_value = PyInt_AS_LONG(o);
goto overflow_check;
#endif
}
else
#endif
if (PyLong_CheckExact(o)) {
#if (NPY_SIZEOF_LONG < NPY_SIZEOF_INTP)
long_value = PyLong_AsLongLong(o);
Expand Down
6 changes: 0 additions & 6 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,6 @@ ulong_arrtype_hash(PyObject *obj)
return x;
}

#if (NPY_SIZEOF_INT != NPY_SIZEOF_LONG) || defined(NPY_PY3K)
static npy_hash_t
int_arrtype_hash(PyObject *obj)
{
Expand All @@ -3166,7 +3165,6 @@ int_arrtype_hash(PyObject *obj)
}
return x;
}
#endif

#if defined(NPY_PY3K)
static npy_hash_t
Expand Down Expand Up @@ -4359,20 +4357,16 @@ initialize_numeric_types(void)

/**end repeat**/

#if (NPY_SIZEOF_INT != NPY_SIZEOF_LONG) || defined(NPY_PY3K)
/* We won't be inheriting from Python Int type. */
PyIntArrType_Type.tp_hash = int_arrtype_hash;
#endif

#if defined(NPY_PY3K)
/* We won't be inheriting from Python Int type. */
PyLongArrType_Type.tp_hash = long_arrtype_hash;
#endif

#if (NPY_SIZEOF_LONG != NPY_SIZEOF_LONGLONG) || defined(NPY_PY3K)
/* We won't be inheriting from Python Int type. */
PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;
#endif

/**begin repeat
* #name = repr, str#
Expand Down

0 comments on commit 7d159b4

Please sign in to comment.