@@ -112,47 +112,73 @@ NOTE: In the interpreter's initialization phase, some globals are currently
112
112
# define _PyUnicode_CHECK (op ) PyUnicode_Check(op)
113
113
#endif
114
114
115
- #define _PyUnicode_UTF8 (op ) \
116
- (_PyCompactUnicodeObject_CAST(op)->utf8)
117
- #define PyUnicode_UTF8 (op ) \
118
- (assert(_PyUnicode_CHECK(op)), \
119
- PyUnicode_IS_COMPACT_ASCII(op) ? \
120
- ((char*)(_PyASCIIObject_CAST(op) + 1)) : \
121
- _PyUnicode_UTF8(op))
122
- #define _PyUnicode_UTF8_LENGTH (op ) \
123
- (_PyCompactUnicodeObject_CAST(op)->utf8_length)
124
- #define PyUnicode_UTF8_LENGTH (op ) \
125
- (assert(_PyUnicode_CHECK(op)), \
126
- PyUnicode_IS_COMPACT_ASCII(op) ? \
127
- _PyASCIIObject_CAST(op)->length : \
128
- _PyUnicode_UTF8_LENGTH(op))
115
+ static inline char * _PyUnicode_UTF8 (PyObject * op )
116
+ {
117
+ return (_PyCompactUnicodeObject_CAST (op )-> utf8 );
118
+ }
119
+
120
+ static inline char * PyUnicode_UTF8 (PyObject * op ) {
121
+ assert (_PyUnicode_CHECK (op ));
122
+ if (PyUnicode_IS_COMPACT_ASCII (op )) {
123
+ return ((char * )(_PyASCIIObject_CAST (op ) + 1 ));
124
+ }
125
+ else {
126
+ return _PyUnicode_UTF8 (op );
127
+ }
128
+ }
129
+
130
+ static inline void PyUnicode_SET_UTF8 (PyObject * op , char * utf8 )
131
+ {
132
+ _PyCompactUnicodeObject_CAST (op )-> utf8 = utf8 ;
133
+ }
134
+
135
+ static inline Py_ssize_t PyUnicode_UTF8_LENGTH (PyObject * op ) {
136
+ assert (_PyUnicode_CHECK (op ));
137
+ if (PyUnicode_IS_COMPACT_ASCII (op )) {
138
+ return _PyASCIIObject_CAST (op )-> length ;
139
+ }
140
+ else {
141
+ return _PyCompactUnicodeObject_CAST (op )-> utf8_length ;
142
+ }
143
+ }
144
+
145
+ static inline void PyUnicode_SET_UTF8_LENGTH (PyObject * op , Py_ssize_t length ) {
146
+ _PyCompactUnicodeObject_CAST (op )-> utf8_length = length ;
147
+ }
129
148
130
149
#define _PyUnicode_LENGTH (op ) \
131
150
(_PyASCIIObject_CAST(op)->length)
132
151
#define _PyUnicode_STATE (op ) \
133
152
(_PyASCIIObject_CAST(op)->state)
134
153
#define _PyUnicode_HASH (op ) \
135
154
(_PyASCIIObject_CAST(op)->hash)
136
- #define _PyUnicode_KIND (op ) \
137
- (assert(_PyUnicode_CHECK(op)), \
138
- _PyASCIIObject_CAST(op)->state.kind)
139
- #define _PyUnicode_GET_LENGTH (op ) \
140
- (assert(_PyUnicode_CHECK(op)), \
141
- _PyASCIIObject_CAST(op)->length)
155
+
156
+ static inline Py_hash_t PyUnicode_HASH (PyObject * op ) {
157
+ assert (_PyUnicode_CHECK (op ));
158
+ return FT_ATOMIC_LOAD_SSIZE_RELAXED (_PyASCIIObject_CAST (op )-> hash );
159
+ }
160
+
161
+ static inline void PyUnicode_SET_HASH (PyObject * op , Py_hash_t hash ) {
162
+ FT_ATOMIC_STORE_SSIZE_RELAXED (_PyASCIIObject_CAST (op )-> hash , hash );
163
+ }
164
+
142
165
#define _PyUnicode_DATA_ANY (op ) \
143
166
(_PyUnicodeObject_CAST(op)->data.any)
144
167
145
- #define _PyUnicode_SHARE_UTF8 (op ) \
146
- (assert(_PyUnicode_CHECK(op)), \
147
- assert(!PyUnicode_IS_COMPACT_ASCII(op)), \
148
- (_PyUnicode_UTF8(op) == PyUnicode_DATA(op)))
168
+ static inline int _PyUnicode_SHARE_UTF8 (PyObject * op ) {
169
+ assert (_PyUnicode_CHECK (op ));
170
+ assert (!PyUnicode_IS_COMPACT_ASCII (op ));
171
+ return (_PyUnicode_UTF8 (op ) == PyUnicode_DATA (op ));
172
+ }
149
173
150
174
/* true if the Unicode object has an allocated UTF-8 memory block
151
175
(not shared with other data) */
152
- #define _PyUnicode_HAS_UTF8_MEMORY (op ) \
153
- ((!PyUnicode_IS_COMPACT_ASCII(op) \
154
- && _PyUnicode_UTF8(op) \
155
- && _PyUnicode_UTF8(op) != PyUnicode_DATA(op)))
176
+ static inline int _PyUnicode_HAS_UTF8_MEMORY (PyObject * op ) {
177
+ return (!PyUnicode_IS_COMPACT_ASCII (op )
178
+ && _PyUnicode_UTF8 (op ) != NULL
179
+ && _PyUnicode_UTF8 (op ) != PyUnicode_DATA (op ));
180
+ }
181
+
156
182
157
183
/* Generic helper macro to convert characters of different types.
158
184
from_type and to_type have to be valid type names, begin and end
@@ -1123,8 +1149,8 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
1123
1149
1124
1150
if (_PyUnicode_HAS_UTF8_MEMORY (unicode )) {
1125
1151
PyMem_Free (_PyUnicode_UTF8 (unicode ));
1126
- _PyUnicode_UTF8 (unicode ) = NULL ;
1127
- _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
1152
+ PyUnicode_SET_UTF8 (unicode , NULL ) ;
1153
+ PyUnicode_SET_UTF8_LENGTH (unicode , 0 ) ;
1128
1154
}
1129
1155
#ifdef Py_TRACE_REFS
1130
1156
_Py_ForgetReference (unicode );
@@ -1177,8 +1203,8 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
1177
1203
if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY (unicode ))
1178
1204
{
1179
1205
PyMem_Free (_PyUnicode_UTF8 (unicode ));
1180
- _PyUnicode_UTF8 (unicode ) = NULL ;
1181
- _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
1206
+ PyUnicode_SET_UTF8 (unicode , NULL ) ;
1207
+ PyUnicode_SET_UTF8_LENGTH (unicode , 0 ) ;
1182
1208
}
1183
1209
1184
1210
data = (PyObject * )PyObject_Realloc (data , new_size );
@@ -1188,8 +1214,8 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
1188
1214
}
1189
1215
_PyUnicode_DATA_ANY (unicode ) = data ;
1190
1216
if (share_utf8 ) {
1191
- _PyUnicode_UTF8 (unicode ) = data ;
1192
- _PyUnicode_UTF8_LENGTH (unicode ) = length ;
1217
+ PyUnicode_SET_UTF8 (unicode , data ) ;
1218
+ PyUnicode_SET_UTF8_LENGTH (unicode , length ) ;
1193
1219
}
1194
1220
_PyUnicode_LENGTH (unicode ) = length ;
1195
1221
PyUnicode_WRITE (PyUnicode_KIND (unicode ), data , length , 0 );
@@ -1769,7 +1795,7 @@ unicode_modifiable(PyObject *unicode)
1769
1795
assert (_PyUnicode_CHECK (unicode ));
1770
1796
if (Py_REFCNT (unicode ) != 1 )
1771
1797
return 0 ;
1772
- if (FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( unicode ) ) != -1 )
1798
+ if (PyUnicode_HASH ( unicode ) != -1 )
1773
1799
return 0 ;
1774
1800
if (PyUnicode_CHECK_INTERNED (unicode ))
1775
1801
return 0 ;
@@ -5862,8 +5888,8 @@ unicode_fill_utf8(PyObject *unicode)
5862
5888
PyErr_NoMemory ();
5863
5889
return -1 ;
5864
5890
}
5865
- _PyUnicode_UTF8 (unicode ) = cache ;
5866
- _PyUnicode_UTF8_LENGTH (unicode ) = len ;
5891
+ PyUnicode_SET_UTF8 (unicode , cache ) ;
5892
+ PyUnicode_SET_UTF8_LENGTH (unicode , len ) ;
5867
5893
memcpy (cache , start , len );
5868
5894
cache [len ] = '\0' ;
5869
5895
_PyBytesWriter_Dealloc (& writer );
@@ -11434,9 +11460,9 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
11434
11460
return 0 ;
11435
11461
}
11436
11462
11437
- Py_hash_t right_hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( right_uni ) );
11463
+ Py_hash_t right_hash = PyUnicode_HASH ( right_uni );
11438
11464
assert (right_hash != -1 );
11439
- Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( left ) );
11465
+ Py_hash_t hash = PyUnicode_HASH ( left );
11440
11466
if (hash != -1 && hash != right_hash ) {
11441
11467
return 0 ;
11442
11468
}
@@ -11916,14 +11942,14 @@ unicode_hash(PyObject *self)
11916
11942
#ifdef Py_DEBUG
11917
11943
assert (_Py_HashSecret_Initialized );
11918
11944
#endif
11919
- Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( self ) );
11945
+ Py_hash_t hash = PyUnicode_HASH ( self );
11920
11946
if (hash != -1 ) {
11921
11947
return hash ;
11922
11948
}
11923
11949
x = Py_HashBuffer (PyUnicode_DATA (self ),
11924
11950
PyUnicode_GET_LENGTH (self ) * PyUnicode_KIND (self ));
11925
11951
11926
- FT_ATOMIC_STORE_SSIZE_RELAXED ( _PyUnicode_HASH ( self ) , x );
11952
+ PyUnicode_SET_HASH ( self , x );
11927
11953
return x ;
11928
11954
}
11929
11955
@@ -15427,8 +15453,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
15427
15453
_PyUnicode_STATE (self ).compact = 0 ;
15428
15454
_PyUnicode_STATE (self ).ascii = _PyUnicode_STATE (unicode ).ascii ;
15429
15455
_PyUnicode_STATE (self ).statically_allocated = 0 ;
15430
- _PyUnicode_UTF8_LENGTH (self ) = 0 ;
15431
- _PyUnicode_UTF8 (self ) = NULL ;
15456
+ PyUnicode_SET_UTF8_LENGTH (self , 0 ) ;
15457
+ PyUnicode_SET_UTF8 (self , NULL ) ;
15432
15458
_PyUnicode_DATA_ANY (self ) = NULL ;
15433
15459
15434
15460
share_utf8 = 0 ;
@@ -15458,8 +15484,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
15458
15484
15459
15485
_PyUnicode_DATA_ANY (self ) = data ;
15460
15486
if (share_utf8 ) {
15461
- _PyUnicode_UTF8_LENGTH (self ) = length ;
15462
- _PyUnicode_UTF8 (self ) = data ;
15487
+ PyUnicode_SET_UTF8_LENGTH (self , length ) ;
15488
+ PyUnicode_SET_UTF8 (self , data ) ;
15463
15489
}
15464
15490
15465
15491
memcpy (data , PyUnicode_DATA (unicode ), kind * (length + 1 ));
0 commit comments