@@ -39,6 +39,18 @@ typedef union _npy_static_string_u {
39
39
_short_string_buffer direct_buffer ;
40
40
} _npy_static_string_u ;
41
41
42
+ // room for two more flags with values 0x20 and 0x10
43
+ #define NPY_STRING_MISSING 0x80 // 1000 0000
44
+ #define NPY_STRING_SHORT 0x40 // 0100 0000
45
+
46
+ // short string sizes fit in a 4-bit integer
47
+ #define NPY_SHORT_STRING_SIZE_MASK 0x0F // 0000 1111
48
+ #define NPY_SHORT_STRING_MAX_SIZE \
49
+ (sizeof(npy_static_string) - 1) // 15 or 7 depending on arch
50
+
51
+ // one byte in size is reserved for flags and small string optimization
52
+ #define NPY_MAX_STRING_SIZE (1 << (sizeof(size_t) - 1)) - 1
53
+
42
54
// Since this has no flags set, technically this is a heap-allocated string
43
55
// with size zero. Practically, that doesn't matter because we always do size
44
56
// checks before accessing heap data, but that may be confusing. The nice part
106
118
npy_string_newsize (const char * init , size_t size ,
107
119
npy_packed_static_string * to_init )
108
120
{
109
- if (to_init == NULL || size > MAX_STRING_SIZE ) {
121
+ if (to_init == NULL || size > NPY_MAX_STRING_SIZE ) {
110
122
return -2 ;
111
123
}
112
124
@@ -145,7 +157,7 @@ npy_string_newsize(const char *init, size_t size,
145
157
int
146
158
npy_string_newemptysize (size_t size , npy_packed_static_string * out )
147
159
{
148
- if (out == NULL || size > MAX_STRING_SIZE ) {
160
+ if (out == NULL || size > NPY_MAX_STRING_SIZE ) {
149
161
return -2 ;
150
162
}
151
163
0 commit comments