@@ -111,47 +111,80 @@ NOTE: In the interpreter's initialization phase, some globals are currently
111
111
# define _PyUnicode_CHECK (op ) PyUnicode_Check(op)
112
112
#endif
113
113
114
- #define _PyUnicode_UTF8 (op ) \
115
- (_PyCompactUnicodeObject_CAST(op)->utf8)
116
- #define PyUnicode_UTF8 (op ) \
117
- (assert(_PyUnicode_CHECK(op)), \
118
- PyUnicode_IS_COMPACT_ASCII(op) ? \
119
- ((char*)(_PyASCIIObject_CAST(op) + 1)) : \
120
- _PyUnicode_UTF8(op))
121
- #define _PyUnicode_UTF8_LENGTH (op ) \
122
- (_PyCompactUnicodeObject_CAST(op)->utf8_length)
123
- #define PyUnicode_UTF8_LENGTH (op ) \
124
- (assert(_PyUnicode_CHECK(op)), \
125
- PyUnicode_IS_COMPACT_ASCII(op) ? \
126
- _PyASCIIObject_CAST(op)->length : \
127
- _PyUnicode_UTF8_LENGTH(op))
114
+ static inline char * _PyUnicode_UTF8 (PyObject * op )
115
+ {
116
+ return (_PyCompactUnicodeObject_CAST (op )-> utf8 );
117
+ }
118
+
119
+ static inline char * PyUnicode_UTF8 (PyObject * op )
120
+ {
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
+ {
137
+ assert (_PyUnicode_CHECK (op ));
138
+ if (PyUnicode_IS_COMPACT_ASCII (op )) {
139
+ return _PyASCIIObject_CAST (op )-> length ;
140
+ }
141
+ else {
142
+ return _PyCompactUnicodeObject_CAST (op )-> utf8_length ;
143
+ }
144
+ }
145
+
146
+ static inline void PyUnicode_SET_UTF8_LENGTH (PyObject * op , Py_ssize_t length )
147
+ {
148
+ _PyCompactUnicodeObject_CAST (op )-> utf8_length = length ;
149
+ }
128
150
129
151
#define _PyUnicode_LENGTH (op ) \
130
152
(_PyASCIIObject_CAST(op)->length)
131
153
#define _PyUnicode_STATE (op ) \
132
154
(_PyASCIIObject_CAST(op)->state)
133
155
#define _PyUnicode_HASH (op ) \
134
156
(_PyASCIIObject_CAST(op)->hash)
135
- #define _PyUnicode_KIND (op ) \
136
- (assert(_PyUnicode_CHECK(op)), \
137
- _PyASCIIObject_CAST(op)->state.kind)
138
- #define _PyUnicode_GET_LENGTH (op ) \
139
- (assert(_PyUnicode_CHECK(op)), \
140
- _PyASCIIObject_CAST(op)->length)
157
+
158
+ static inline Py_hash_t PyUnicode_HASH (PyObject * op )
159
+ {
160
+ assert (_PyUnicode_CHECK (op ));
161
+ return FT_ATOMIC_LOAD_SSIZE_RELAXED (_PyASCIIObject_CAST (op )-> hash );
162
+ }
163
+
164
+ static inline void PyUnicode_SET_HASH (PyObject * op , Py_hash_t hash )
165
+ {
166
+ FT_ATOMIC_STORE_SSIZE_RELAXED (_PyASCIIObject_CAST (op )-> hash , hash );
167
+ }
168
+
141
169
#define _PyUnicode_DATA_ANY (op ) \
142
170
(_PyUnicodeObject_CAST(op)->data.any)
143
171
144
- #define _PyUnicode_SHARE_UTF8 (op ) \
145
- (assert(_PyUnicode_CHECK(op)), \
146
- assert(!PyUnicode_IS_COMPACT_ASCII(op)), \
147
- (_PyUnicode_UTF8(op) == PyUnicode_DATA(op)))
172
+ static inline int _PyUnicode_SHARE_UTF8 (PyObject * op )
173
+ {
174
+ assert (_PyUnicode_CHECK (op ));
175
+ assert (!PyUnicode_IS_COMPACT_ASCII (op ));
176
+ return (_PyUnicode_UTF8 (op ) == PyUnicode_DATA (op ));
177
+ }
148
178
149
179
/* true if the Unicode object has an allocated UTF-8 memory block
150
180
(not shared with other data) */
151
- #define _PyUnicode_HAS_UTF8_MEMORY (op ) \
152
- ((!PyUnicode_IS_COMPACT_ASCII(op) \
153
- && _PyUnicode_UTF8(op) \
154
- && _PyUnicode_UTF8(op) != PyUnicode_DATA(op)))
181
+ static inline int _PyUnicode_HAS_UTF8_MEMORY (PyObject * op )
182
+ {
183
+ return (!PyUnicode_IS_COMPACT_ASCII (op )
184
+ && _PyUnicode_UTF8 (op ) != NULL
185
+ && _PyUnicode_UTF8 (op ) != PyUnicode_DATA (op ));
186
+ }
187
+
155
188
156
189
/* Generic helper macro to convert characters of different types.
157
190
from_type and to_type have to be valid type names, begin and end
@@ -1115,8 +1148,8 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
1115
1148
1116
1149
if (_PyUnicode_HAS_UTF8_MEMORY (unicode )) {
1117
1150
PyMem_Free (_PyUnicode_UTF8 (unicode ));
1118
- _PyUnicode_UTF8 (unicode ) = NULL ;
1119
- _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
1151
+ PyUnicode_SET_UTF8 (unicode , NULL ) ;
1152
+ PyUnicode_SET_UTF8_LENGTH (unicode , 0 ) ;
1120
1153
}
1121
1154
#ifdef Py_TRACE_REFS
1122
1155
_Py_ForgetReference (unicode );
@@ -1169,8 +1202,8 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
1169
1202
if (!share_utf8 && _PyUnicode_HAS_UTF8_MEMORY (unicode ))
1170
1203
{
1171
1204
PyMem_Free (_PyUnicode_UTF8 (unicode ));
1172
- _PyUnicode_UTF8 (unicode ) = NULL ;
1173
- _PyUnicode_UTF8_LENGTH (unicode ) = 0 ;
1205
+ PyUnicode_SET_UTF8 (unicode , NULL ) ;
1206
+ PyUnicode_SET_UTF8_LENGTH (unicode , 0 ) ;
1174
1207
}
1175
1208
1176
1209
data = (PyObject * )PyObject_Realloc (data , new_size );
@@ -1180,8 +1213,8 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
1180
1213
}
1181
1214
_PyUnicode_DATA_ANY (unicode ) = data ;
1182
1215
if (share_utf8 ) {
1183
- _PyUnicode_UTF8 (unicode ) = data ;
1184
- _PyUnicode_UTF8_LENGTH (unicode ) = length ;
1216
+ PyUnicode_SET_UTF8 (unicode , data ) ;
1217
+ PyUnicode_SET_UTF8_LENGTH (unicode , length ) ;
1185
1218
}
1186
1219
_PyUnicode_LENGTH (unicode ) = length ;
1187
1220
PyUnicode_WRITE (PyUnicode_KIND (unicode ), data , length , 0 );
@@ -1801,7 +1834,7 @@ unicode_modifiable(PyObject *unicode)
1801
1834
assert (_PyUnicode_CHECK (unicode ));
1802
1835
if (Py_REFCNT (unicode ) != 1 )
1803
1836
return 0 ;
1804
- if (FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( unicode ) ) != -1 )
1837
+ if (PyUnicode_HASH ( unicode ) != -1 )
1805
1838
return 0 ;
1806
1839
if (PyUnicode_CHECK_INTERNED (unicode ))
1807
1840
return 0 ;
@@ -5442,8 +5475,8 @@ unicode_fill_utf8(PyObject *unicode)
5442
5475
PyErr_NoMemory ();
5443
5476
return -1 ;
5444
5477
}
5445
- _PyUnicode_UTF8 (unicode ) = cache ;
5446
- _PyUnicode_UTF8_LENGTH (unicode ) = len ;
5478
+ PyUnicode_SET_UTF8 (unicode , cache ) ;
5479
+ PyUnicode_SET_UTF8_LENGTH (unicode , len ) ;
5447
5480
memcpy (cache , start , len );
5448
5481
cache [len ] = '\0' ;
5449
5482
_PyBytesWriter_Dealloc (& writer );
@@ -10996,9 +11029,9 @@ _PyUnicode_EqualToASCIIId(PyObject *left, _Py_Identifier *right)
10996
11029
return 0 ;
10997
11030
}
10998
11031
10999
- Py_hash_t right_hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( right_uni ) );
11032
+ Py_hash_t right_hash = PyUnicode_HASH ( right_uni );
11000
11033
assert (right_hash != -1 );
11001
- Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( left ) );
11034
+ Py_hash_t hash = PyUnicode_HASH ( left );
11002
11035
if (hash != -1 && hash != right_hash ) {
11003
11036
return 0 ;
11004
11037
}
@@ -11484,14 +11517,14 @@ unicode_hash(PyObject *self)
11484
11517
#ifdef Py_DEBUG
11485
11518
assert (_Py_HashSecret_Initialized );
11486
11519
#endif
11487
- Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED ( _PyUnicode_HASH ( self ) );
11520
+ Py_hash_t hash = PyUnicode_HASH ( self );
11488
11521
if (hash != -1 ) {
11489
11522
return hash ;
11490
11523
}
11491
11524
x = _Py_HashBytes (PyUnicode_DATA (self ),
11492
11525
PyUnicode_GET_LENGTH (self ) * PyUnicode_KIND (self ));
11493
11526
11494
- FT_ATOMIC_STORE_SSIZE_RELAXED ( _PyUnicode_HASH ( self ) , x );
11527
+ PyUnicode_SET_HASH ( self , x );
11495
11528
return x ;
11496
11529
}
11497
11530
@@ -14888,8 +14921,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
14888
14921
_PyUnicode_STATE (self ).compact = 0 ;
14889
14922
_PyUnicode_STATE (self ).ascii = _PyUnicode_STATE (unicode ).ascii ;
14890
14923
_PyUnicode_STATE (self ).statically_allocated = 0 ;
14891
- _PyUnicode_UTF8_LENGTH (self ) = 0 ;
14892
- _PyUnicode_UTF8 (self ) = NULL ;
14924
+ PyUnicode_SET_UTF8_LENGTH (self , 0 ) ;
14925
+ PyUnicode_SET_UTF8 (self , NULL ) ;
14893
14926
_PyUnicode_DATA_ANY (self ) = NULL ;
14894
14927
14895
14928
share_utf8 = 0 ;
@@ -14919,8 +14952,8 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
14919
14952
14920
14953
_PyUnicode_DATA_ANY (self ) = data ;
14921
14954
if (share_utf8 ) {
14922
- _PyUnicode_UTF8_LENGTH (self ) = length ;
14923
- _PyUnicode_UTF8 (self ) = data ;
14955
+ PyUnicode_SET_UTF8_LENGTH (self , length ) ;
14956
+ PyUnicode_SET_UTF8 (self , data ) ;
14924
14957
}
14925
14958
14926
14959
memcpy (data , PyUnicode_DATA (unicode ), kind * (length + 1 ));
0 commit comments