Skip to content

Commit 485414c

Browse files
ft build interns and immortilizes everything anyway
1 parent 45129f8 commit 485414c

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

Include/internal/pycore_unicodeobject.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ extern "C" {
1515
// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111).
1616
#define _Py_MAX_UNICODE 0x10ffff
1717

18+
/* This hashtable holds statically allocated interned strings.
19+
* See InternalDocs/string_interning.md for details.
20+
*/
21+
#define INTERNED_STRINGS _PyRuntime.cached_objects.interned_strings
1822

1923
extern int _PyUnicode_IsModifiable(PyObject *unicode);
2024
extern void _PyUnicodeWriter_InitWithBuffer(

Objects/codeobject.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525

2626
#define INITIAL_SPECIALIZED_CODE_SIZE 16
2727

28-
// copypaste from unicodeobject.c
29-
#define INTERNED_STRINGS _PyRuntime.cached_objects.interned_strings
30-
3128
static const char *
3229
code_event_name(PyCodeEvent event) {
3330
switch (event) {
@@ -206,15 +203,17 @@ static int
206203
intern_constants(PyObject *tuple, int *modified)
207204
{
208205
PyInterpreterState *interp = _PyInterpreterState_GET();
206+
#if !defined(Py_GIL_DISABLED)
209207
PyObject *interned_dict = _Py_INTERP_CACHED_OBJECT(interp, interned_strings);
210208
Py_INCREF(interned_dict);
209+
#endif
211210
for (Py_ssize_t i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
212211
PyObject *v = PyTuple_GET_ITEM(tuple, i);
213212
if (PyUnicode_CheckExact(v) && PyUnicode_GET_LENGTH(v) > 1) {
214213
if (PyUnicode_CHECK_INTERNED(v) != 0) {
215214
continue;
216215
}
217-
Py_BEGIN_CRITICAL_SECTION(interned_dict);
216+
#if !defined(Py_GIL_DISABLED)
218217
PyObject *interned = PyDict_GetItemWithError(interned_dict, v);
219218
if (interned == NULL && PyErr_Occurred()) {
220219
goto error;
@@ -232,7 +231,9 @@ intern_constants(PyObject *tuple, int *modified)
232231
if (modified) {
233232
*modified = 1;
234233
}
235-
} else if (should_intern_string(v)) {
234+
} else
235+
#endif
236+
if (should_intern_string(v)) {
236237
PyObject *w = v;
237238
_PyUnicode_InternMortal(interp, &v);
238239
if (w != v) {
@@ -242,7 +243,6 @@ intern_constants(PyObject *tuple, int *modified)
242243
}
243244
}
244245
}
245-
Py_END_CRITICAL_SECTION();
246246
}
247247
else if (PyTuple_CheckExact(v)) {
248248
if (intern_constants(v, NULL) < 0) {
@@ -327,11 +327,15 @@ intern_constants(PyObject *tuple, int *modified)
327327
}
328328
#endif
329329
}
330+
#if !defined(Py_GIL_DISABLED)
330331
Py_DECREF(interned_dict);
332+
#endif
331333
return 0;
332334

333335
error:
336+
#if !defined(Py_GIL_DISABLED)
334337
Py_DECREF(interned_dict);
338+
#endif
335339
return -1;
336340
}
337341

Objects/unicodeobject.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,6 @@ static inline PyObject *get_interned_dict(PyInterpreterState *interp)
215215
return _Py_INTERP_CACHED_OBJECT(interp, interned_strings);
216216
}
217217

218-
/* This hashtable holds statically allocated interned strings.
219-
* See InternalDocs/string_interning.md for details.
220-
*/
221-
#define INTERNED_STRINGS _PyRuntime.cached_objects.interned_strings
222-
223218
/* Get number of all interned strings for the current interpreter. */
224219
Py_ssize_t
225220
_PyUnicode_InternedSize(void)

0 commit comments

Comments
 (0)