[Python-checkins] python/dist/src/Include modsupport.h,2.39,2.40 stringobject.h,2.36,2.37

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
2002年8月19日 14:43:20 -0700


Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv2517/Include
Modified Files:
	modsupport.h stringobject.h 
Log Message:
SF patch 576101, by Oren Tirosh: alternative implementation of
interning. I modified Oren's patch significantly, but the basic idea
and most of the implementation is unchanged. Interned strings created
with PyString_InternInPlace() are now mortal, and you must keep a
reference to the resulting string around; use the new function
PyString_InternImmortal() to create immortal interned strings.
Index: modsupport.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/modsupport.h,v
retrieving revision 2.39
retrieving revision 2.40
diff -C2 -d -r2.39 -r2.40
*** modsupport.h	12 Aug 2002 07:21:57 -0000	2.39
--- modsupport.h	19 Aug 2002 21:43:18 -0000	2.40
***************
*** 24,29 ****
 PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, char *, char *);
 
! #define PYTHON_API_VERSION 1011
! #define PYTHON_API_STRING "1011"
 /* The API version is maintained (independently from the Python version)
 so we can detect mismatches between the interpreter and dynamically
--- 24,29 ----
 PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, char *, char *);
 
! #define PYTHON_API_VERSION 1012
! #define PYTHON_API_STRING "1012"
 /* The API version is maintained (independently from the Python version)
 so we can detect mismatches between the interpreter and dynamically
***************
*** 38,41 ****
--- 38,44 ----
 Please add a line or two to the top of this log for each API
 version change:
+ 
+ 19-Aug-2002 GvR	1012	Changes to string object struct for
+ 				interning changes, saving 3 bytes.
 
 17-Jul-2001	GvR	1011	Descr-branch, just to be on the safe side
Index: stringobject.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/stringobject.h,v
retrieving revision 2.36
retrieving revision 2.37
diff -C2 -d -r2.36 -r2.37
*** stringobject.h	14 Aug 2002 07:46:22 -0000	2.36
--- stringobject.h	19 Aug 2002 21:43:18 -0000	2.37
***************
*** 26,30 ****
 
 /* Caching the hash (ob_shash) saves recalculation of a string's hash value.
! Interning strings (ob_sinterned) tries to ensure that only one string
 object with a given value exists, so equality tests can be one pointer
 comparison. This is generally restricted to strings that "look like"
--- 26,30 ----
 
 /* Caching the hash (ob_shash) saves recalculation of a string's hash value.
! Interning strings (ob_sstate) tries to ensure that only one string
 object with a given value exists, so equality tests can be one pointer
 comparison. This is generally restricted to strings that "look like"
***************
*** 36,43 ****
 PyObject_VAR_HEAD
 long ob_shash;
! PyObject *ob_sinterned;
 char ob_sval[1];
 } PyStringObject;
 
 PyAPI_DATA(PyTypeObject) PyBaseString_Type;
 PyAPI_DATA(PyTypeObject) PyString_Type;
--- 36,47 ----
 PyObject_VAR_HEAD
 long ob_shash;
! int ob_sstate;
 char ob_sval[1];
 } 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;
***************
*** 67,72 ****
--- 71,80 ----
 
 PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
+ PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
 PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
 PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
+ 
+ /* Use only if you know it's a string */
+ #define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
 
 /* Macro, trading safety for speed */

AltStyle によって変換されたページ (->オリジナル) /