Skip to content

bpo-40521: Make empty Unicode string per interpreter #21096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ struct _Py_bytes_state {
};

struct _Py_unicode_state {
// The empty Unicode object is a singleton to improve performance.
PyObject *empty;
struct _Py_unicode_fs_codec fs_codec;
};

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc);

/* Various one-time initializers */

extern PyStatus _PyUnicode_Init(void);
extern PyStatus _PyUnicode_Init(PyThreadState *tstate);
extern int _PyStructSequence_Init(void);
extern int _PyLong_Init(PyThreadState *tstate);
extern PyStatus _PyFaulthandler_Init(int enable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Each interpreter now its has own free lists, singletons and caches:

* Free lists: float, tuple, list, dict, frame, context,
asynchronous generator, MemoryError.
* Singletons: empty tuple, empty bytes string,
* Singletons: empty tuple, empty bytes string, empty Unicode string,
single byte character.
* Slice cache.

Expand Down
1 change: 0 additions & 1 deletion Objects/stringlib/asciilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define STRINGLIB_CHAR Py_UCS1
#define STRINGLIB_TYPE_NAME "unicode"
#define STRINGLIB_PARSE_CODE "U"
#define STRINGLIB_GET_EMPTY() unicode_empty
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
Expand Down
7 changes: 6 additions & 1 deletion Objects/stringlib/partition.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/* stringlib: partition implementation */

#ifndef STRINGLIB_FASTSEARCH_H
#error must include "stringlib/fastsearch.h" before including this module
# error must include "stringlib/fastsearch.h" before including this module
#endif

#if !STRINGLIB_MUTABLE && !defined(STRINGLIB_GET_EMPTY)
# error "STRINGLIB_GET_EMPTY must be defined if STRINGLIB_MUTABLE is zero"
#endif


Py_LOCAL_INLINE(PyObject*)
STRINGLIB(partition)(PyObject* str_obj,
const STRINGLIB_CHAR* str, Py_ssize_t str_len,
Expand Down
4 changes: 0 additions & 4 deletions Objects/stringlib/stringdefs.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef STRINGLIB_STRINGDEFS_H
#define STRINGLIB_STRINGDEFS_H

#ifndef STRINGLIB_GET_EMPTY
# error "STRINGLIB_GET_EMPTY macro must be defined"
#endif

/* this is sort of a hack. there's at least one place (formatting
floats) where some stringlib code takes a different path if it's
compiled as unicode. */
Expand Down
1 change: 0 additions & 1 deletion Objects/stringlib/ucs1lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define STRINGLIB_CHAR Py_UCS1
#define STRINGLIB_TYPE_NAME "unicode"
#define STRINGLIB_PARSE_CODE "U"
#define STRINGLIB_GET_EMPTY() unicode_empty
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
Expand Down
1 change: 0 additions & 1 deletion Objects/stringlib/ucs2lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define STRINGLIB_CHAR Py_UCS2
#define STRINGLIB_TYPE_NAME "unicode"
#define STRINGLIB_PARSE_CODE "U"
#define STRINGLIB_GET_EMPTY() unicode_empty
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
Expand Down
1 change: 0 additions & 1 deletion Objects/stringlib/ucs4lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define STRINGLIB_CHAR Py_UCS4
#define STRINGLIB_TYPE_NAME "unicode"
#define STRINGLIB_PARSE_CODE "U"
#define STRINGLIB_GET_EMPTY() unicode_empty
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
Expand Down
1 change: 0 additions & 1 deletion Objects/stringlib/unicodedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define STRINGLIB_CHAR Py_UNICODE
#define STRINGLIB_TYPE_NAME "unicode"
#define STRINGLIB_PARSE_CODE "U"
#define STRINGLIB_GET_EMPTY() unicode_empty
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
Expand Down
Loading