@@ -112,47 +112,80 @@ 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
+ {
122
+ assert (_PyUnicode_CHECK (op ));
123
+ if (PyUnicode_IS_COMPACT_ASCII (op )) {
124
+ return ((char * )(_PyASCIIObject_CAST (op ) + 1 ));
125
+ }
126
+ else {
127
+ return _PyUnicode_UTF8 (op );
128
+ }
129
+ }
130
+
131
+ static inline void PyUnicode_SET_UTF8 (PyObject * op , char * utf8 )
132
+ {
133
+ _PyCompactUnicodeObject_CAST (op )-> utf8 = utf8 ;
134
+ }
135
+
136
+ static inline Py_ssize_t PyUnicode_UTF8_LENGTH (PyObject * op )
137
+ {
138
+ assert (_PyUnicode_CHECK (op ));
139
+ if (PyUnicode_IS_COMPACT_ASCII (op )) {
140
+ return _PyASCIIObject_CAST (op )-> length ;
141
+ }
142
+ else {
143
+ return _PyCompactUnicodeObject_CAST (op )-> utf8_length ;
144
+ }
145
+ }
146
+
147
+ static inline void PyUnicode_SET_UTF8_LENGTH (PyObject * op , Py_ssize_t length )
148
+ {
149
+ _PyCompactUnicodeObject_CAST (op )-> utf8_length = length ;
150
+ }
129
151
130
152
#define _PyUnicode_LENGTH (op ) \
131
153
(_PyASCIIObject_CAST(op)->length)
132
154
#define _PyUnicode_STATE (op ) \
133
155
(_PyASCIIObject_CAST(op)->state)
134
156
#define _PyUnicode_HASH (op ) \
135
157
(_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)
158
+
159
+ static inline Py_hash_t PyUnicode_HASH (PyObject * op )
160
+ {
161
+ assert (_PyUnicode_CHECK (op ));
162
+ return FT_ATOMIC_LOAD_SSIZE_RELAXED (_PyASCIIObject_CAST (op )-> hash );
163
+ }
164
+
165
+ static inline void PyUnicode_SET_HASH (PyObject * op , Py_hash_t hash )
166
+ {
167
+ FT_ATOMIC_STORE_SSIZE_RELAXED (_PyASCIIObject_CAST (op )-> hash , hash );
168
+ }
169
+
142
170
#define _PyUnicode_DATA_ANY (op ) \
143
171
(_PyUnicodeObject_CAST(op)->data.any)
144
172
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)))
173
+ static inline int _PyUnicode_SHARE_UTF8 (PyObject * op )
174
+ {
175
+ assert (_PyUnicode_CHECK (op ));
176
+ assert (!PyUnicode_IS_COMPACT_ASCII (op ));
177
+ return (_PyUnicode_UTF8 (op ) == PyUnicode_DATA (op ));
178
+ }
149
179
150
180
/* true if the Unicode object has an allocated UTF-8 memory block
151
181
(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)))
182
+ static inline int _PyUnicode_HAS_UTF8_MEMORY (PyObject * op )
183
+ {
184
+ return (!PyUnicode_IS_COMPACT_ASCII (op )
185
+ && _PyUnicode_UTF8 (op ) != NULL
186
+ && _PyUnicode_UTF8 (op ) != PyUnicode_DATA (op ));
187
+ }
188
+
156
189
157
190
/* Generic helper macro to convert characters of different types.
158
191
from_type and to_type have to be valid type names, begin and end
@@ -1123,8 +1156,8 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
1123
1156
1124
1157
if (_PyUnicode_HAS_UTF8_MEMORY (unicode )) {
1125
1158
PyMem_Free (_PyUnicode_UTF8 (unicode ));
1126
- _PyUnicode_UTF8 (unicode ) = NULL ;
1127
- _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
1159
+ PyUnicode_SET_UTF8 (unicode , NULL ) ;
1160
+ PyUnicode_SET_UTF8_LENGTH (unicode , 0 ) ;
1128
1161
}
1129
1162
#ifdef Py_TRACE_REFS
1130
1163
_Py_ForgetReference (unicode );
@@ -1177,8 +1210,8 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
1177
1210
if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY (unicode ))
1178
1211
{
1179
1212
PyMem_Free (_PyUnicode_UTF8 (unicode ));
1180
- _PyUnicode_UTF8 (unicode ) = NULL ;
1181
- _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
1213
+ PyUnicode_SET_UTF8 (unicode , NULL ) ;
1214
+ PyUnicode_SET_UTF8_LENGTH (unicode , 0 ) ;
1182
1215
}
1183
1216
1184
1217
data = (PyObject * )PyObject_Realloc (data , new_size );
@@ -1188,8 +1221,8 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
1188
1221
}
1189
1222
_PyUnicode_DATA_ANY (unicode ) = data ;
1190
1223
if (share_utf8 ) {
1191
- _PyUnicode_UTF8 (unicode ) = data ;
1192
- _PyUnicode_UTF8_LENGTH (unicode ) = length ;
1224
+ PyUnicode_SET_UTF8 (unicode , data ) ;
1225
+ PyUnicode_SET_UTF8_LENGTH (unicode , length ) ;
1193
1226
}
1194
1227
_PyUnicode_LENGTH (unicode ) = length ;
1195
1228
PyUnicode_WRITE (PyUnicode_KIND (unicode ), data , length , 0 );
@@ -1769,7 +1802,7 @@ unicode_modifiable(PyObject *unicode)
1769
1802
assert (_PyUnicode_CHECK (unicode ));
1770
1803
if (Py_REFCNT (unicode ) != 1 )
1771
1804
return 0 ;
1772
- if (FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( unicode ) ) != -1 )
1805
+ if (PyUnicode_HASH ( unicode ) != -1 )
1773
1806
return 0 ;
1774
1807
if (PyUnicode_CHECK_INTERNED (unicode ))
1775
1808
return 0 ;
@@ -5862,8 +5895,8 @@ unicode_fill_utf8(PyObject *unicode)
5862
5895
PyErr_NoMemory ();
5863
5896
return -1 ;
5864
5897
}
5865
- _PyUnicode_UTF8 (unicode ) = cache ;
5866
- _PyUnicode_UTF8_LENGTH (unicode ) = len ;
5898
+ PyUnicode_SET_UTF8 (unicode , cache ) ;
5899
+ PyUnicode_SET_UTF8_LENGTH (unicode , len ) ;
5867
5900
memcpy (cache , start , len );
5868
5901
cache [len ] = '\0' ;
5869
5902
_PyBytesWriter_Dealloc (& writer );
@@ -11434,9 +11467,9 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
11434
11467
return 0 ;
11435
11468
}
11436
11469
11437
- Py_hash_t right_hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( right_uni ) );
11470
+ Py_hash_t right_hash = PyUnicode_HASH ( right_uni );
11438
11471
assert (right_hash != -1 );
11439
- Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( left ) );
11472
+ Py_hash_t hash = PyUnicode_HASH ( left );
11440
11473
if (hash != -1 && hash != right_hash ) {
11441
11474
return 0 ;
11442
11475
}
@@ -11916,14 +11949,14 @@ unicode_hash(PyObject *self)
11916
11949
#ifdef Py_DEBUG
11917
11950
assert (_Py_HashSecret_Initialized );
11918
11951
#endif
11919
- Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( self ) );
11952
+ Py_hash_t hash = PyUnicode_HASH ( self );
11920
11953
if (hash != -1 ) {
11921
11954
return hash ;
11922
11955
}
11923
11956
x = Py_HashBuffer (PyUnicode_DATA (self ),
11924
11957
PyUnicode_GET_LENGTH (self ) * PyUnicode_KIND (self ));
11925
11958
11926
- FT_ATOMIC_STORE_SSIZE_RELAXED ( _PyUnicode_HASH ( self ) , x );
11959
+ PyUnicode_SET_HASH ( self , x );
11927
11960
return x ;
11928
11961
}
11929
11962
@@ -15427,8 +15460,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
15427
15460
_PyUnicode_STATE (self ).compact = 0 ;
15428
15461
_PyUnicode_STATE (self ).ascii = _PyUnicode_STATE (unicode ).ascii ;
15429
15462
_PyUnicode_STATE (self ).statically_allocated = 0 ;
15430
- _PyUnicode_UTF8_LENGTH (self ) = 0 ;
15431
- _PyUnicode_UTF8 (self ) = NULL ;
15463
+ PyUnicode_SET_UTF8_LENGTH (self , 0 ) ;
15464
+ PyUnicode_SET_UTF8 (self , NULL ) ;
15432
15465
_PyUnicode_DATA_ANY (self ) = NULL ;
15433
15466
15434
15467
share_utf8 = 0 ;
@@ -15458,8 +15491,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
15458
15491
15459
15492
_PyUnicode_DATA_ANY (self ) = data ;
15460
15493
if (share_utf8 ) {
15461
- _PyUnicode_UTF8_LENGTH (self ) = length ;
15462
- _PyUnicode_UTF8 (self ) = data ;
15494
+ PyUnicode_SET_UTF8_LENGTH (self , length ) ;
15495
+ PyUnicode_SET_UTF8 (self , data ) ;
15463
15496
}
15464
15497
15465
15498
memcpy (data , PyUnicode_DATA (unicode ), kind * (length + 1 ));
0 commit comments