@@ -39,6 +39,18 @@ typedef union _npy_static_string_u {
3939 _short_string_buffer direct_buffer ;
4040} _npy_static_string_u ;
4141
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+
4254// Since this has no flags set, technically this is a heap-allocated string
4355// with size zero. Practically, that doesn't matter because we always do size
4456// checks before accessing heap data, but that may be confusing. The nice part
106118npy_string_newsize (const char * init , size_t size ,
107119 npy_packed_static_string * to_init )
108120{
109- if (to_init == NULL || size > MAX_STRING_SIZE ) {
121+ if (to_init == NULL || size > NPY_MAX_STRING_SIZE ) {
110122 return -2 ;
111123 }
112124
@@ -145,7 +157,7 @@ npy_string_newsize(const char *init, size_t size,
145157int
146158npy_string_newemptysize (size_t size , npy_packed_static_string * out )
147159{
148- if (out == NULL || size > MAX_STRING_SIZE ) {
160+ if (out == NULL || size > NPY_MAX_STRING_SIZE ) {
149161 return -2 ;
150162 }
151163
0 commit comments