@@ -23,8 +23,8 @@ new_stringdtype_instance(PyObject *na_object, int coerce)
23
23
return NULL ;
24
24
}
25
25
26
- allocator = npy_string_new_allocator (PyMem_RawMalloc , PyMem_RawFree ,
27
- PyMem_RawRealloc );
26
+ allocator = NpyString_new_allocator (PyMem_RawMalloc , PyMem_RawFree ,
27
+ PyMem_RawRealloc );
28
28
29
29
if (allocator == NULL ) {
30
30
PyErr_SetString (PyExc_MemoryError ,
@@ -49,8 +49,8 @@ new_stringdtype_instance(PyObject *na_object, int coerce)
49
49
has_string_na = 1 ;
50
50
Py_ssize_t size = 0 ;
51
51
const char * buf = PyUnicode_AsUTF8AndSize (na_object , & size );
52
- if (npy_string_newsize (buf , (size_t )size , & packed_default_string ,
53
- allocator ) < 0 ) {
52
+ if (NpyString_newsize (buf , (size_t )size , & packed_default_string ,
53
+ allocator ) < 0 ) {
54
54
PyErr_SetString (PyExc_MemoryError ,
55
55
"Failed to allocate string while creating "
56
56
"StringDType instance." );
@@ -86,8 +86,8 @@ new_stringdtype_instance(PyObject *na_object, int coerce)
86
86
Py_DECREF (na_pystr );
87
87
goto fail ;
88
88
}
89
- if (npy_string_newsize (utf8_ptr , (size_t )size , & packed_na_name ,
90
- allocator ) < 0 ) {
89
+ if (NpyString_newsize (utf8_ptr , (size_t )size , & packed_na_name ,
90
+ allocator ) < 0 ) {
91
91
PyErr_SetString (PyExc_MemoryError ,
92
92
"Failed to allocate string while creating "
93
93
"StringDType instance." );
@@ -109,8 +109,8 @@ new_stringdtype_instance(PyObject *na_object, int coerce)
109
109
snew -> array_owned = 0 ;
110
110
111
111
npy_static_string default_string = {0 , NULL };
112
- if (npy_string_load (allocator , & snew -> packed_default_string ,
113
- & default_string ) == -1 ) {
112
+ if (NpyString_load (allocator , & snew -> packed_default_string ,
113
+ & default_string ) == -1 ) {
114
114
PyErr_SetString (PyExc_MemoryError ,
115
115
"Failed to load packed string while "
116
116
"creating StringDType instance." );
@@ -119,7 +119,7 @@ new_stringdtype_instance(PyObject *na_object, int coerce)
119
119
}
120
120
121
121
npy_static_string na_name = {0 , NULL };
122
- if (npy_string_load (allocator , & snew -> packed_na_name , & na_name ) == -1 ) {
122
+ if (NpyString_load (allocator , & snew -> packed_na_name , & na_name ) == -1 ) {
123
123
PyErr_SetString (PyExc_MemoryError ,
124
124
"Failed to load packed string while "
125
125
"creating StringDType instance." );
@@ -150,9 +150,9 @@ new_stringdtype_instance(PyObject *na_object, int coerce)
150
150
// this only makes sense if the allocator isn't attached to new yet
151
151
Py_DECREF (new );
152
152
if (allocator != NULL ) {
153
- npy_string_free (& packed_na_name , allocator );
154
- npy_string_free (& packed_default_string , allocator );
155
- npy_string_free_allocator (allocator );
153
+ NpyString_free (& packed_na_name , allocator );
154
+ NpyString_free (& packed_default_string , allocator );
155
+ NpyString_free_allocator (allocator );
156
156
}
157
157
if (allocator_lock != NULL ) {
158
158
PyThread_free_lock (allocator_lock );
@@ -291,7 +291,7 @@ stringdtype_setitem(StringDTypeObject *descr, PyObject *obj, char **dataptr)
291
291
292
292
// free if dataptr holds preexisting string data,
293
293
// npy_string_free does a NULL check and checks for small strings
294
- if (npy_string_free (sdata , descr -> allocator ) < 0 ) {
294
+ if (NpyString_free (sdata , descr -> allocator ) < 0 ) {
295
295
PyErr_SetString (PyExc_MemoryError ,
296
296
"String deallocation failed in StringDType setitem" );
297
297
goto fail ;
@@ -319,7 +319,7 @@ stringdtype_setitem(StringDTypeObject *descr, PyObject *obj, char **dataptr)
319
319
goto fail ;
320
320
}
321
321
322
- if (npy_string_newsize (val , length , sdata , descr -> allocator ) < 0 ) {
322
+ if (NpyString_newsize (val , length , sdata , descr -> allocator ) < 0 ) {
323
323
PyErr_SetString (PyExc_MemoryError ,
324
324
"Failed to allocate string during StringDType "
325
325
"setitem" );
@@ -347,7 +347,7 @@ stringdtype_getitem(StringDTypeObject *descr, char **dataptr)
347
347
npy_static_string sdata = {0 , NULL };
348
348
int hasnull = descr -> na_object != NULL ;
349
349
NPY_STRING_ACQUIRE_ALLOCATOR (descr );
350
- int is_null = npy_string_load (descr -> allocator , psdata , & sdata );
350
+ int is_null = NpyString_load (descr -> allocator , psdata , & sdata );
351
351
352
352
if (is_null < 0 ) {
353
353
PyErr_SetString (PyExc_MemoryError ,
@@ -399,7 +399,7 @@ stringdtype_getitem(StringDTypeObject *descr, char **dataptr)
399
399
npy_bool
400
400
nonzero (void * data , void * NPY_UNUSED (arr ))
401
401
{
402
- return npy_string_size ((npy_packed_static_string * )data ) != 0 ;
402
+ return NpyString_size ((npy_packed_static_string * )data ) != 0 ;
403
403
}
404
404
405
405
// Implementation of PyArray_CompareFunc.
@@ -429,10 +429,10 @@ _compare(void *a, void *b, StringDTypeObject *descr_a,
429
429
npy_static_string * default_string = & descr_a -> default_string ;
430
430
const npy_packed_static_string * ps_a = (npy_packed_static_string * )a ;
431
431
npy_static_string s_a = {0 , NULL };
432
- int a_is_null = npy_string_load (allocator_a , ps_a , & s_a );
432
+ int a_is_null = NpyString_load (allocator_a , ps_a , & s_a );
433
433
const npy_packed_static_string * ps_b = (npy_packed_static_string * )b ;
434
434
npy_static_string s_b = {0 , NULL };
435
- int b_is_null = npy_string_load (allocator_b , ps_b , & s_b );
435
+ int b_is_null = NpyString_load (allocator_b , ps_b , & s_b );
436
436
if (NPY_UNLIKELY (a_is_null == -1 || b_is_null == -1 )) {
437
437
char * msg = "Failed to load string in string comparison" ;
438
438
if (hasnull && !(has_string_na && has_nan_na )) {
@@ -476,7 +476,7 @@ _compare(void *a, void *b, StringDTypeObject *descr_a,
476
476
}
477
477
}
478
478
}
479
- return npy_string_cmp (& s_a , & s_b );
479
+ return NpyString_cmp (& s_a , & s_b );
480
480
}
481
481
482
482
// PyArray_ArgFunc
@@ -526,7 +526,7 @@ stringdtype_clear_loop(void *NPY_UNUSED(traverse_context),
526
526
while (size -- ) {
527
527
npy_packed_static_string * sdata = (npy_packed_static_string * )data ;
528
528
if (data != NULL ) {
529
- if (npy_string_free (sdata , sdescr -> allocator ) < 0 ) {
529
+ if (NpyString_free (sdata , sdescr -> allocator ) < 0 ) {
530
530
gil_error (PyExc_MemoryError ,
531
531
"String deallocation failed in clear loop" );
532
532
goto fail ;
@@ -703,9 +703,9 @@ stringdtype_dealloc(StringDTypeObject *self)
703
703
if (self -> allocator != NULL ) {
704
704
// can we assume the destructor for an instance will only get called
705
705
// inside of one C thread?
706
- npy_string_free (& self -> packed_default_string , self -> allocator );
707
- npy_string_free (& self -> packed_na_name , self -> allocator );
708
- npy_string_free_allocator (self -> allocator );
706
+ NpyString_free (& self -> packed_default_string , self -> allocator );
707
+ NpyString_free (& self -> packed_na_name , self -> allocator );
708
+ NpyString_free_allocator (self -> allocator );
709
709
PyThread_free_lock (self -> allocator_lock );
710
710
}
711
711
PyArrayDescr_Type .tp_dealloc ((PyObject * )self );
@@ -958,14 +958,14 @@ free_and_copy(npy_string_allocator *in_allocator,
958
958
const npy_packed_static_string * in ,
959
959
npy_packed_static_string * out , const char * location )
960
960
{
961
- if (npy_string_free (out , out_allocator ) < 0 ) {
961
+ if (NpyString_free (out , out_allocator ) < 0 ) {
962
962
char message [200 ];
963
963
snprintf (message , sizeof (message ), "Failed to deallocate string in %s" ,
964
964
location );
965
965
gil_error (PyExc_MemoryError , message );
966
966
return -1 ;
967
967
}
968
- if (npy_string_dup (in , out , in_allocator , out_allocator ) < 0 ) {
968
+ if (NpyString_dup (in , out , in_allocator , out_allocator ) < 0 ) {
969
969
char message [200 ];
970
970
snprintf (message , sizeof (message ), "Failed to allocate string in %s" ,
971
971
location );
0 commit comments