Add interning of unicode strings by copying the functionality from

stringobject.c.

Intern "True" and "False" in bool_repr() again as it was in the
8bit string era.
This commit is contained in:
Walter Dörwald 2007-05-25 13:52:07 +00:00
parent 34a042d301
commit 1680713e52
5 changed files with 158 additions and 7 deletions

View file

@ -390,6 +390,9 @@ typedef struct {
Py_ssize_t length; /* Length of raw Unicode data in buffer */
Py_UNICODE *str; /* Raw Unicode buffer */
long hash; /* Hash value; -1 if not set */
int state; /* != 0 if interned. In this case the two
* references from the dictionary to this object
* are *not* counted in ob_refcnt. */
PyObject *defenc; /* (Default) Encoded version as Python
string, or NULL; this is used for
implementing the buffer protocol */
@ -397,6 +400,10 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyUnicode_Type;
#define SSTATE_NOT_INTERNED 0
#define SSTATE_INTERNED_MORTAL 1
#define SSTATE_INTERNED_IMMORTAL 2
#define PyUnicode_Check(op) \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_UNICODE_SUBCLASS)
#define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type)
@ -529,6 +536,14 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromObject(
PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char*, va_list);
PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char*, ...);
PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **);
PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(const char *);
PyAPI_FUNC(void) _Py_ReleaseInternedUnicodeStrings(void);
/* Use only if you know it's a string */
#define PyUnicode_CHECK_INTERNED(op) (((PyUnicodeObject *)(op))->state)
/* --- wchar_t support for platforms which support it --------------------- */
#ifdef HAVE_WCHAR_H