Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions numpy/core/src/multiarray/scalarapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
CASE(TIMEDELTA, Timedelta);
#undef CASE
case NPY_STRING:
return (void *)PyString_AS_STRING(scalar);
return (void *)PyBytes_AsString(scalar);
case NPY_UNICODE:
/* lazy initialization, to reduce the memory used by string scalars */
if (PyArrayScalar_VAL(scalar, Unicode) == NULL) {
Expand Down Expand Up @@ -141,7 +141,18 @@ scalar_value(PyObject *scalar, PyArray_Descr *descr)
return (void *)PyString_AS_STRING(scalar);
}
if (_CHK(Unicode)) {
return (void *)PyUnicode_AS_DATA(scalar);
/* Treat this the same as the NPY_UNICODE base class */

/* lazy initialization, to reduce the memory used by string scalars */
if (PyArrayScalar_VAL(scalar, Unicode) == NULL) {
Py_UCS4 *raw_data = PyUnicode_AsUCS4Copy(scalar);
if (raw_data == NULL) {
return NULL;
}
PyArrayScalar_VAL(scalar, Unicode) = raw_data;
return (void *)raw_data;
}
return PyArrayScalar_VAL(scalar, Unicode);
}
if (_CHK(Void)) {
/* Note: no & needed here, so can't use _IFCASE */
Expand Down