Skip to content

Commit

Permalink
Pull request numpy#22: Port few more smaller parts of the module init…
Browse files Browse the repository at this point in the history
…ialization

Merge in numpy-hpy from ss/port-more-init to labs-hpy-port

* commit '3cd9bf37f3355055482d0b3404189c606468f7bc':
  Remove debugging printf
  Add one more missing C API warning
  Remove busdaycalendar for the HPy example port
  multiarray mod init: convert setting of remaining types on module dict
  multiarray mod init: add C API warnings for unported parts
  multiarray mod init: convert setting of "flatiter" on module dict
  multiarray mod init: convert setting of "ndarray" on module dict
  multiarray mod init: do not leak the h_d handle
  multiarray mod init: convert datetime capsules creation
  multiarray mod init: convert API capsules creation
  multiarray mod init: convert HPyContext capsule creation
  Remove PyObject* for module from the multiarray module init
  Port initumath
  Convert set_flaginfo
  • Loading branch information
steve-s committed Apr 20, 2022
2 parents 4e428f0 + 3cd9bf3 commit 2b2d6ea
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 123 deletions.
4 changes: 2 additions & 2 deletions numpy/core/numerictypes.py
Expand Up @@ -83,7 +83,7 @@

from numpy.core.multiarray import (
ndarray, array, dtype, datetime_data, datetime_as_string,
busday_offset, busday_count, is_busday, busdaycalendar
busday_offset, busday_count, is_busday
)
from numpy.core.overrides import set_module

Expand All @@ -92,7 +92,7 @@
'ScalarType', 'obj2sctype', 'cast', 'nbytes', 'sctype2char',
'maximum_sctype', 'issctype', 'typecodes', 'find_common_type',
'issubdtype', 'datetime_data', 'datetime_as_string',
'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar',
'busday_offset', 'busday_count', 'is_busday',
]

# we don't need all these imports, but we need to keep them for compatibility
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/common/umathmodule.h
Expand Up @@ -9,6 +9,6 @@ get_sfloat_dtype(PyObject *NPY_UNUSED(mod), PyObject *NPY_UNUSED(args));

PyObject * add_newdoc_ufunc(PyObject *NPY_UNUSED(dummy), PyObject *args);
PyObject * ufunc_frompyfunc(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *NPY_UNUSED(kwds));
int initumath(HPyContext *ctx, PyObject *m, HPy module_dict);
int initumath(HPyContext *ctx, HPy m, HPy module_dict);

#endif /* NUMPY_CORE_SRC_COMMON_UMATHMODULE_H_ */
7 changes: 5 additions & 2 deletions numpy/core/src/multiarray/alloc.c
Expand Up @@ -407,7 +407,7 @@ PyDataMem_Handler default_handler = {
PyObject *PyDataMem_DefaultHandler;

#if (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x07030600)
HPy current_handler;
HPyGlobal current_handler;
#endif

int uo_index=0; /* user_override index */
Expand Down Expand Up @@ -590,9 +590,12 @@ HPyDataMem_GetHandler(HPyContext *ctx)
{
HPy handler;
#if (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x07030600)
if (HPyContextVar_Get(ctx, current_handler, HPy_NULL, &handler)) {
HPy h_current_handler = HPyGlobal_Load(ctx, current_handler);
if (HPyContextVar_Get(ctx, h_current_handler, HPy_NULL, &handler)) {
HPy_Close(ctx, h_current_handler);
return HPy_NULL;
}
HPy_Close(ctx, h_current_handler);
return handler;
#else
hpy_abort_not_implemented("HPyDataMem_GetHandler on older Pypy versions");
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/alloc.h
Expand Up @@ -48,7 +48,7 @@ npy_free_cache_dim_array(PyArrayObject * arr)

extern PyDataMem_Handler default_handler;
#if (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x07030600)
extern HPy current_handler; /* PyContextVar/PyCapsule */
extern HPyGlobal current_handler; /* PyContextVar/PyCapsule */
#endif

NPY_NO_EXPORT PyObject *
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/arraytypes.c.src
Expand Up @@ -4437,6 +4437,7 @@ static HPy _hpy_builtin_descrs[] = {
// still statically allocated PyObjects, but cannot have dynamically
// allocated type in their static initializers...
NPY_NO_EXPORT void init_static_descrs_type_objs(HPyContext *ctx) {
CAPI_WARN("X_Descr.typeobj = _PyXArrType_p");
/**begin repeat
*
* #from = VOID, STRING, UNICODE, BOOL,
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/multiarray/convert_datatype.c
Expand Up @@ -4171,6 +4171,7 @@ PyArray_InitializeObjectToObjectCast(void)
NPY_NO_EXPORT int
PyArray_InitializeCasts()
{
CAPI_WARN("startup: PyArray_InitializeCasts");
if (PyArray_InitializeNumericCasts() < 0) {
return -1;
}
Expand Down

0 comments on commit 2b2d6ea

Please sign in to comment.