Skip to content

Commit

Permalink
tweaks discovered when building for PyPY
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Oct 23, 2023
1 parent a1f0ad0 commit 23f4a18
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def gl_if_msvc(build_cmd):
],
'extra_compiler_args': [gl_if_msvc],
#'macros': [('HPY_ABI_HYBRID', None)],
'macros': [('HPY_ABI_CPYTHON', None)],
# 'macros': [('HPY_ABI_CPYTHON', None)],
})
config.add_npy_pkg_config("npymath.ini.in", "lib/npy-pkg-config",
subst_dict)
Expand Down
9 changes: 2 additions & 7 deletions numpy/core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -4824,7 +4824,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
NULL, NULL, NULL
},
#endif
NULL,
HPyField_NULL,
(PyArray_ScalarKindFunc*)NULL,
NULL,
NULL,
Expand Down Expand Up @@ -4972,7 +4972,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
NULL, NULL, NULL
},
#endif
NULL,
HPyField_NULL,
(PyArray_ScalarKindFunc*)NULL,
NULL,
NULL,
Expand Down Expand Up @@ -5139,11 +5139,6 @@ HPyArray_DescrFromType(HPyContext *ctx, int type)
h_ret = HPyGlobal_Load(ctx, _hpy_builtin_descrs[num]);
}
}
if (HPy_IsNull(h_ret)) {
HPyErr_SetString(ctx, ctx->h_ValueError,
"Invalid data-type for array");
}

return h_ret;
}

Expand Down
18 changes: 17 additions & 1 deletion numpy/core/src/multiarray/dtypemeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ hdiscover_descr_from_pyobject_function_trampoline(HPyContext *ctx, HPy cls, HPy
* @param descr The descriptor that should be wrapped.
* @param name The name for the DType, if NULL the type character is used.
*
* @returns 0 on success, -1 on failure.
* @returns a new handle of the descriptor on success
*/
NPY_NO_EXPORT HPy
dtypemeta_init_legacy_descriptor(HPyContext *ctx, int type_num, PyArray_ArrFuncs *f, HPy h_typeobj, HPy array_descr_type)
Expand Down Expand Up @@ -852,6 +852,22 @@ dtypemeta_init_legacy_descriptor(HPyContext *ctx, int type_num, PyArray_ArrFuncs
HPy_Close(ctx, h_PyArrayDTypeMeta_Type);
HPy_Close(ctx, h_new_dtype_type);
// HPy_Close(ctx, array_descr_type);

// Callers of dtypemeta_init_legacy_descriptor return void, so they cannot
// report an error to their callers
size_t err_length = strlen(scalar_name) + 40;
char *err_str = MEM_MALLOC(err_length);
HPy h_where;
if (!err_str) {
h_where = HPyUnicode_FromString(ctx, "dtypemeta_init_legacy_descriptor");
}
else {
snprintf(err_str, err_length, "dtypemeta_init_legacy_descriptor of %s", scalar_name);
h_where = HPyUnicode_FromString(ctx, err_str);
}
HPyErr_WriteUnraisable(ctx, h_where);
PyMem_Free(tp_name);
HPy_Close(ctx, h_where);
return HPy_NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -4500,8 +4500,9 @@ NPY_NO_EXPORT int init_scalartypes_basetypes(HPyContext *ctx)
#define ADD_TYPE_OBJ(global) \
tmp = HPyGlobal_Load(ctx, global); \
name = HPyType_GetName(ctx, tmp); \
HPy_Close(ctx, tmp); \
if (! name) return -1; \
hpy_typeobjects[i++].name = (const char *)strdup(name); \
HPy_Close(ctx, tmp);

ADD_TYPE_OBJ(HPyBoolArrType_Type);
ADD_TYPE_OBJ(HPyByteArrType_Type);
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ requires = [
"wheel==0.37.0",
"Cython==0.29.24", # pin until PyPy releases v7.3.8
# "Cython==0.29.24,<3.0", # Note: keep in sync with tools/cythonize.py
"hpy @ git+https://github.com/hpyproject/hpy.git@92990828f064b174b52e7dfe39dd0226b47b92eb#egg=hpy"
"hpy==0.9.0",
]


Expand Down

0 comments on commit 23f4a18

Please sign in to comment.