summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-25 13:52:07 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-05-25 13:52:07 (GMT)
commit1680713e524016d93a94114c4a874ad71a090b95 (patch)
treeef1f75a1a9748b50ab4a4e66d4c81662062546f7 /Include
parent34a042d301d6ab88645046a6dfa6c38265ca4b39 (diff)
downloadcpython-1680713e524016d93a94114c4a874ad71a090b95.zip
cpython-1680713e524016d93a94114c4a874ad71a090b95.tar.gz
cpython-1680713e524016d93a94114c4a874ad71a090b95.tar.bz2
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.
Diffstat (limited to 'Include')
-rw-r--r--Include/stringobject.h4
-rw-r--r--Include/unicodeobject.h15
2 files changed, 15 insertions, 4 deletions
diff --git a/Include/stringobject.h b/Include/stringobject.h
index 8156193..2b8cc2f 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -48,10 +48,6 @@ typedef struct {
*/
} PyStringObject;
-#define SSTATE_NOT_INTERNED 0
-#define SSTATE_INTERNED_MORTAL 1
-#define SSTATE_INTERNED_IMMORTAL 2
-
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyString_Type;
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 131278d..2a27dbc 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -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