[Python-3000-checkins] r53912 - in python/branches/p3yk: Doc/lib/libetree.tex Include/dictobject.h Include/listobject.h Include/longobject.h Include/object.h Include/pyerrors.h Include/stringobject.h Include/tupleobject.h Include/unicodeobject.h Objects/dictobject.c Objects/exceptions.c Objects/intobject.c Objects/listobject.c Objects/longobject.c Objects/stringobject.c Objects/tupleobject.c Objects/typeobject.c Objects/unicodeobject.c

thomas.wouters python-3000-checkins at python.org
Sun Feb 25 21:39:16 CET 2007


Author: thomas.wouters
Date: Sun Feb 25 21:39:11 2007
New Revision: 53912

Modified:
   python/branches/p3yk/   (props changed)
   python/branches/p3yk/Doc/lib/libetree.tex
   python/branches/p3yk/Include/dictobject.h
   python/branches/p3yk/Include/listobject.h
   python/branches/p3yk/Include/longobject.h
   python/branches/p3yk/Include/object.h
   python/branches/p3yk/Include/pyerrors.h
   python/branches/p3yk/Include/stringobject.h
   python/branches/p3yk/Include/tupleobject.h
   python/branches/p3yk/Include/unicodeobject.h
   python/branches/p3yk/Objects/dictobject.c
   python/branches/p3yk/Objects/exceptions.c
   python/branches/p3yk/Objects/intobject.c
   python/branches/p3yk/Objects/listobject.c
   python/branches/p3yk/Objects/longobject.c
   python/branches/p3yk/Objects/stringobject.c
   python/branches/p3yk/Objects/tupleobject.c
   python/branches/p3yk/Objects/typeobject.c
   python/branches/p3yk/Objects/unicodeobject.c
Log:

Merged revisions 53875-53911 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r53899 | neal.norwitz | 2007-02-25 16:52:27 +0100 (Sun, 25 Feb 2007) | 1 line
  
  Add more details when releasing interned strings
........
  r53900 | neal.norwitz | 2007-02-25 16:53:36 +0100 (Sun, 25 Feb 2007) | 1 line
  
  Whitespace only changes
........
  r53901 | jeremy.hylton | 2007-02-25 16:57:45 +0100 (Sun, 25 Feb 2007) | 8 lines
  
  Fix crash in exec when unicode filename can't be decoded.
  
  I can't think of an easy way to test this behavior.  It only occurs
  when the file system default encoding and the interpreter default
  encoding are different, such that you can open the file but not decode
  its name.
........
  r53902 | jeremy.hylton | 2007-02-25 17:01:58 +0100 (Sun, 25 Feb 2007) | 2 lines
  
  Put declarations before code.
........
  r53910 | fred.drake | 2007-02-25 18:56:27 +0100 (Sun, 25 Feb 2007) | 3 lines
  
  - SF patch #1657613: add documentation for the Element interface
  - clean up bogus use of the {datadescni} environment everywhere
........
  r53911 | neal.norwitz | 2007-02-25 20:44:48 +0100 (Sun, 25 Feb 2007) | 17 lines
  
  Variation of patch # 1624059 to speed up checking if an object is a subclass
  of some of the common builtin types.
  
  Use a bit in tp_flags for each common builtin type.  Check the bit
  to determine if any instance is a subclass of these common types.
  The check avoids a function call and O(n) search of the base classes.
  The check is done in the various Py*_Check macros rather than calling
  PyType_IsSubtype().
  
  All the bits are set in tp_flags when the type is declared 
  in the Objects/*object.c files because PyType_Ready() is not called
  for all the types.  Should PyType_Ready() be called for all types?
  If so and the change is made, the changes to the Objects/*object.c files
  can be reverted (remove setting the tp_flags).  Objects/typeobject.c
  would also have to be modified to add conditions 
  for Py*_CheckExact() in addition to each the PyType_IsSubtype check.
........



Modified: python/branches/p3yk/Doc/lib/libetree.tex
==============================================================================
--- python/branches/p3yk/Doc/lib/libetree.tex	(original)
+++ python/branches/p3yk/Doc/lib/libetree.tex	Sun Feb 25 21:39:11 2007
@@ -38,10 +38,7 @@
 The comment string can be either an 8-bit ASCII string or a Unicode
 string.
 \var{text} is a string containing the comment string.
-
-\begin{datadescni}{Returns:}
-An element instance, representing a comment.
-\end{datadescni}
+Returns an element instance representing a comment.
 \end{funcdesc}
 
 \begin{funcdesc}{dump}{elem}
@@ -65,28 +62,19 @@
 \var{tag} is the element name.
 \var{attrib} is an optional dictionary, containing element attributes.
 \var{extra} contains additional attributes, given as keyword arguments.
-
-\begin{datadescni}{Returns:}
-An element instance.
-\end{datadescni}
+Returns an element instance.
 \end{funcdesc}
 
 \begin{funcdesc}{fromstring}{text}
 Parses an XML section from a string constant.  Same as XML.
 \var{text} is a string containing XML data.
-
-\begin{datadescni}{Returns:}
-An Element instance.
-\end{datadescni}
+Returns an Element instance.
 \end{funcdesc}
 
 \begin{funcdesc}{iselement}{element}
 Checks if an object appears to be a valid element object.
 \var{element} is an element instance.
-
-\begin{datadescni}{Returns:}
-A true value if this is an element object.
-\end{datadescni}
+Returns a true value if this is an element object.
 \end{funcdesc}
 
 \begin{funcdesc}{iterparse}{source\optional{, events}}
@@ -95,10 +83,7 @@
 \var{source} is a filename or file object containing XML data.
 \var{events} is a list of events to report back.  If omitted, only ``end''
 events are reported.
-
-\begin{datadescni}{Returns:}
-A (event, elem) iterator.
-\end{datadescni}
+Returns an iterator providing \code{(\var{event}, \var{elem})} pairs.
 \end{funcdesc}
 
 \begin{funcdesc}{parse}{source\optional{, parser}}
@@ -106,10 +91,7 @@
 \var{source} is a filename or file object containing XML data.
 \var{parser} is an optional parser instance.  If not given, the
 standard XMLTreeBuilder parser is used.
-
-\begin{datadescni}{Returns:}
-An ElementTree instance
-\end{datadescni}
+Returns an ElementTree instance.
 \end{funcdesc}
 
 \begin{funcdesc}{ProcessingInstruction}{target\optional{, text}}
@@ -117,13 +99,11 @@
 that will be serialized as an XML processing instruction.
 \var{target} is a string containing the PI target.
 \var{text} is a string containing the PI contents, if given.
-
-\begin{datadescni}{Returns:}
-An element instance, representing a PI.
-\end{datadescni}
+Returns an element instance, representing a processing instruction.
 \end{funcdesc}
 
-\begin{funcdesc}{SubElement}{parent, tag\optional{, attrib} \optional{, **extra}}
+\begin{funcdesc}{SubElement}{parent, tag\optional{,
+                             attrib\optional{,  **extra}}}
 Subelement factory.  This function creates an element instance, and
 appends it to an existing element.
 
@@ -133,10 +113,7 @@
 \var{tag} is the subelement name.
 \var{attrib} is an optional dictionary, containing element attributes.
 \var{extra} contains additional attributes, given as keyword arguments.
-
-\begin{datadescni}{Returns:}
-An element instance.
-\end{datadescni}
+Returns an element instance.
 \end{funcdesc}
 
 \begin{funcdesc}{tostring}{element\optional{, encoding}}
@@ -144,33 +121,162 @@
 subelements.
 \var{element} is an Element instance.
 \var{encoding} is the output encoding (default is US-ASCII).
-
-\begin{datadescni}{Returns:}
-An encoded string containing the XML data.
-\end{datadescni}
+Returns an encoded string containing the XML data.
 \end{funcdesc}
 
 \begin{funcdesc}{XML}{text}
 Parses an XML section from a string constant.  This function can
 be used to embed ``XML literals'' in Python code.
 \var{text} is a string containing XML data.
-
-\begin{datadescni}{Returns:}
-An Element instance.
-\end{datadescni}
+Returns an Element instance.
 \end{funcdesc}
 
 \begin{funcdesc}{XMLID}{text}
 Parses an XML section from a string constant, and also returns
 a dictionary which maps from element id:s to elements.
 \var{text} is a string containing XML data.
-
-\begin{datadescni}{Returns:}
-A tuple containing an Element instance and a dictionary.
-\end{datadescni}
+Returns a tuple containing an Element instance and a dictionary.
 \end{funcdesc}
 
 
+\subsection{The Element Interface\label{elementtree-element-interface}}
+
+Element objects returned by Element or SubElement have the 
+following methods and attributes.
+
+\begin{memberdesc}{tag}
+A string identifying what kind of data this element represents
+(the element type, in other words).
+\end{memberdesc}
+
+\begin{memberdesc}{text}
+The \var{text} attribute can be used to hold additional data
+associated with the element.
+As the name implies this attribute is usually a string but may be any
+application-specific object.
+If the element is created from an XML file the attribute will contain
+any text found between the element tags.
+\end{memberdesc}
+
+\begin{memberdesc}{tail}
+The \var{tail} attribute can be used to hold additional data
+associated with the element.
+This attribute is usually a string but may be any application-specific object.
+If the element is created from an XML file the attribute will contain
+any text found after the element's end tag and before the next tag.
+\end{memberdesc}
+
+\begin{memberdesc}{attrib}
+A dictionary containing the element's attributes.
+Note that while the \var{attrib} value is always a real mutable Python
+dictionary, an ElementTree implementation may choose to use another
+internal representation, and create the dictionary only if someone
+asks for it. To take advantage of such implementations, use the
+dictionary methods below whenever possible.
+\end{memberdesc}
+
+The following dictionary-like methods work on the element attributes.
+
+\begin{methoddesc}{clear}{}
+Resets an element.  This function removes all subelements, clears
+all attributes, and sets the text and tail attributes to None.
+\end{methoddesc}
+
+\begin{methoddesc}{get}{key\optional{, default=None}}
+Gets the element attribute named \var{key}.
+
+Returns the attribute value, or \var{default} if the
+attribute was not found.
+\end{methoddesc}
+
+\begin{methoddesc}{items}{}
+Returns the element attributes as a sequence of (name, value) pairs.
+The attributes are returned in an arbitrary order.
+\end{methoddesc}
+
+\begin{methoddesc}{keys}{}
+Returns the elements attribute names as a list.
+The names are returned in an arbitrary order.
+\end{methoddesc}
+
+\begin{methoddesc}{set}{key, value}
+Set the attribute \var{key} on the element to \var{value}.  
+\end{methoddesc}
+
+The following methods work on the element's children (subelements).
+
+\begin{methoddesc}{append}{subelement}
+Adds the element \var{subelement} to the end of this elements internal list
+of subelements.
+\end{methoddesc}
+
+\begin{methoddesc}{find}{match}
+Finds the first subelement matching \var{match}. 
+\var{match} may be a tag name or path.
+Returns an element instance or \code{None}.
+\end{methoddesc}
+
+\begin{methoddesc}{findall}{match}
+Finds all subelements matching \var{match}. 
+\var{match} may be a tag name or path.
+Returns an iterable yielding all matching elements in document order.
+\end{methoddesc}
+
+\begin{methoddesc}{findtext}{condition\optional{, default=None}}
+Finds text for the first subelement matching \var{condition}. 
+\var{condition} may be a tag name or path.
+Returns the text content of the first matching element, or
+\var{default} if no element was found.  Note that if the
+matching element has no text content an empty string is returned.
+\end{methoddesc}
+
+\begin{methoddesc}{getchildren}{}
+Returns all subelements.  The elements are returned in document order.
+\end{methoddesc}
+
+\begin{methoddesc}{getiterator}{\optional{tag=None}}
+Creates a tree iterator with the current element as the root.  
+The iterator iterates over this element and all elements below it 
+that match the given tag. If tag
+is \code{None} or \code{'*'} then all elements are iterated over.
+Returns an iterable that provides element objects in document (depth first)
+order.
+\end{methoddesc}
+
+\begin{methoddesc}{insert}{index, element}
+Inserts a subelement at the given position in this element.
+\end{methoddesc}
+
+\begin{methoddesc}{makeelement}{tag, attrib}
+Creates a new element object of the same type as this element.
+Do not call this method, use the SubElement factory function instead.
+\end{methoddesc}
+
+\begin{methoddesc}{remove}{subelement}
+Removes \var{subelement} from the element.  
+Unlike the findXXX methods this method compares elements based on 
+the instance identity, not on tag value or contents.
+\end{methoddesc}
+
+Element objects also support the following sequence type methods for
+working with subelements: \method{__delitem__()},
+\method{__getitem__()}, \method{__setitem__()}, \method{__len__()}.
+
+Caution: Because Element objects do not define a
+\method{__nonzero__()} method, elements with no subelements will test
+as \code{False}.
+
+\begin{verbatim}
+element = root.find('foo')
+
+if not element: # careful!
+    print "element not found, or element has no subelements"
+
+if element is None:
+    print "element not found"
+\end{verbatim}
+
+
 \subsection{ElementTree Objects\label{elementtree-elementtree-objects}}
 
 \begin{classdesc}{ElementTree}{\optional{element,} \optional{file}}
@@ -193,21 +299,15 @@
 Finds the first toplevel element with given tag.
 Same as getroot().find(path).
 \var{path} is the element to look for.
-
-\begin{datadescni}{Returns:}
-The first matching element, or None if no element was found.
-\end{datadescni}
+Returns the first matching element, or \code{None} if no element was found.
 \end{methoddesc}
 
 \begin{methoddesc}{findall}{path}
 Finds all toplevel elements with the given tag.
 Same as getroot().findall(path).
 \var{path} is the element to look for.
-
-\begin{datadescni}{Returns:}
-A list or iterator containing all matching elements,
-in section order.
-\end{datadescni}
+Returns a list or iterator containing all matching elements,
+in document order.
 \end{methoddesc}
 
 \begin{methoddesc}{findtext}{path\optional{, default}}
@@ -215,31 +315,20 @@
 tag.  Same as getroot().findtext(path).
 \var{path} is the toplevel element to look for.
 \var{default} is the value to return if the element was not found.
-
-\begin{datadescni}{Returns:}
-The text content of the first matching element, or the
+Returns the text content of the first matching element, or the
 default value no element was found.  Note that if the element
 has is found, but has no text content, this method returns an
 empty string.
-\end{datadescni}
 \end{methoddesc}
 
 \begin{methoddesc}{getiterator}{\optional{tag}}
-Creates a tree iterator for the root element.  The iterator loops
+Creates and returns a tree iterator for the root element.  The iterator loops
 over all elements in this tree, in section order.
 \var{tag} is the tag to look for (default is to return all elements)
-
-\begin{datadescni}{Returns:}
-An iterator.
-\end{datadescni}
 \end{methoddesc}
 
 \begin{methoddesc}{getroot}{}
-Gets the root element for this tree.
-
-\begin{datadescni}{Returns:}
-An element instance.
-\end{datadescni}
+Returns the root element for this tree.
 \end{methoddesc}
 
 \begin{methoddesc}{parse}{source\optional{, parser}}
@@ -247,10 +336,7 @@
 \var{source} is a file name or file object.
 \var{parser} is an optional parser instance.  If not given, the
 standard XMLTreeBuilder parser is used.
-
-\begin{datadescni}{Returns:}
-The section root element.
-\end{datadescni}
+Returns the section root element.
 \end{methoddesc}
 
 \begin{methoddesc}{write}{file\optional{, encoding}}
@@ -270,10 +356,7 @@
 the URI part of a QName.
 If \var{tag} is given, the first argument is interpreted as
 an URI, and this argument is interpreted as a local name.
-
-\begin{datadescni}{Returns:}
-An opaque object, representing the QName.
-\end{datadescni}
+\class{QName} instances are opaque.
 \end{classdesc}
 
 
@@ -291,10 +374,7 @@
 \begin{methoddesc}{close}{}
 Flushes the parser buffers, and returns the toplevel documen
 element.
-
-\begin{datadescni}{Returns:}
-An Element instance.
-\end{datadescni}
+Returns an Element instance.
 \end{methoddesc}
 
 \begin{methoddesc}{data}{data}
@@ -306,20 +386,14 @@
 \begin{methoddesc}{end}{tag}
 Closes the current element.
 \var{tag} is the element name.
-
-\begin{datadescni}{Returns:}
-The closed element.
-\end{datadescni}
+Returns the closed element.
 \end{methoddesc}
 
 \begin{methoddesc}{start}{tag, attrs}
 Opens a new element.
 \var{tag} is the element name.
 \var{attrs} is a dictionary containing element attributes.
-
-\begin{datadescni}{Returns:}
-The opened element.
-\end{datadescni}
+Returns the opened element.
 \end{methoddesc}
 
 
@@ -336,10 +410,7 @@
 
 \begin{methoddesc}{close}{}
 Finishes feeding data to the parser.
-
-\begin{datadescni}{Returns:}
-An element structure.
-\end{datadescni}
+Returns an element structure.
 \end{methoddesc}
 
 \begin{methoddesc}{doctype}{name, pubid, system}
@@ -351,6 +422,5 @@
 
 \begin{methoddesc}{feed}{data}
 Feeds data to the parser.
-
 \var{data} is encoded data.
 \end{methoddesc}

Modified: python/branches/p3yk/Include/dictobject.h
==============================================================================
--- python/branches/p3yk/Include/dictobject.h	(original)
+++ python/branches/p3yk/Include/dictobject.h	Sun Feb 25 21:39:11 2007
@@ -90,7 +90,8 @@
 
 PyAPI_DATA(PyTypeObject) PyDict_Type;
 
-#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type)
+#define PyDict_Check(op) \
+                 PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_DICT_SUBCLASS)
 #define PyDict_CheckExact(op) ((op)->ob_type == &PyDict_Type)
 
 PyAPI_FUNC(PyObject *) PyDict_New(void);

Modified: python/branches/p3yk/Include/listobject.h
==============================================================================
--- python/branches/p3yk/Include/listobject.h	(original)
+++ python/branches/p3yk/Include/listobject.h	Sun Feb 25 21:39:11 2007
@@ -40,7 +40,8 @@
 
 PyAPI_DATA(PyTypeObject) PyList_Type;
 
-#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
+#define PyList_Check(op) \
+		PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LIST_SUBCLASS)
 #define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
 
 PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);

Modified: python/branches/p3yk/Include/longobject.h
==============================================================================
--- python/branches/p3yk/Include/longobject.h	(original)
+++ python/branches/p3yk/Include/longobject.h	Sun Feb 25 21:39:11 2007
@@ -11,7 +11,8 @@
 
 PyAPI_DATA(PyTypeObject) PyLong_Type;
 
-#define PyLong_Check(op) PyObject_TypeCheck(op, &PyLong_Type)
+#define PyLong_Check(op) \
+		PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_LONG_SUBCLASS)
 #define PyLong_CheckExact(op) ((op)->ob_type == &PyLong_Type)
 
 PyAPI_FUNC(PyObject *) PyLong_FromLong(long);

Modified: python/branches/p3yk/Include/object.h
==============================================================================
--- python/branches/p3yk/Include/object.h	(original)
+++ python/branches/p3yk/Include/object.h	Sun Feb 25 21:39:11 2007
@@ -357,7 +357,8 @@
 PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
 PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
 
-#define PyType_Check(op) PyObject_TypeCheck(op, &PyType_Type)
+#define PyType_Check(op) \
+	PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TYPE_SUBCLASS)
 #define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type)
 
 PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
@@ -469,11 +470,23 @@
 #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
 #endif
 
+/* These flags are used to determine if a type is a subclass. */
+#define Py_TPFLAGS_INT_SUBCLASS		(1L<<23)
+#define Py_TPFLAGS_LONG_SUBCLASS	(1L<<24)
+#define Py_TPFLAGS_LIST_SUBCLASS	(1L<<25)
+#define Py_TPFLAGS_TUPLE_SUBCLASS	(1L<<26)
+#define Py_TPFLAGS_STRING_SUBCLASS	(1L<<27)
+#define Py_TPFLAGS_UNICODE_SUBCLASS	(1L<<28)
+#define Py_TPFLAGS_DICT_SUBCLASS	(1L<<29)
+#define Py_TPFLAGS_BASE_EXC_SUBCLASS	(1L<<30)
+#define Py_TPFLAGS_TYPE_SUBCLASS	(1L<<31)
+
 #define Py_TPFLAGS_DEFAULT  ( \
                              Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
                             0)
 
 #define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)
+#define PyType_FastSubclass(t,f)  PyType_HasFeature(t,f)
 
 
 /*

Modified: python/branches/p3yk/Include/pyerrors.h
==============================================================================
--- python/branches/p3yk/Include/pyerrors.h	(original)
+++ python/branches/p3yk/Include/pyerrors.h	Sun Feb 25 21:39:11 2007
@@ -94,13 +94,12 @@
 
 /* */
 
-#define PyExceptionClass_Check(x) \
-	    (PyType_Check((x)) && PyType_IsSubtype(			\
-		     (PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException))
+#define PyExceptionClass_Check(x)					\
+	(PyType_Check((x)) &&						\
+	 PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
 
-
-#define PyExceptionInstance_Check(x) \
-	 (PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException))
+#define PyExceptionInstance_Check(x)			\
+	PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
 
 #define PyExceptionClass_Name(x) \
 	 ((char *)(((PyTypeObject*)(x))->tp_name))

Modified: python/branches/p3yk/Include/stringobject.h
==============================================================================
--- python/branches/p3yk/Include/stringobject.h	(original)
+++ python/branches/p3yk/Include/stringobject.h	Sun Feb 25 21:39:11 2007
@@ -55,7 +55,8 @@
 PyAPI_DATA(PyTypeObject) PyBaseString_Type;
 PyAPI_DATA(PyTypeObject) PyString_Type;
 
-#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
+#define PyString_Check(op) \
+                 PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_STRING_SUBCLASS)
 #define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
 
 PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);

Modified: python/branches/p3yk/Include/tupleobject.h
==============================================================================
--- python/branches/p3yk/Include/tupleobject.h	(original)
+++ python/branches/p3yk/Include/tupleobject.h	Sun Feb 25 21:39:11 2007
@@ -33,7 +33,8 @@
 
 PyAPI_DATA(PyTypeObject) PyTuple_Type;
 
-#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type)
+#define PyTuple_Check(op) \
+                 PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_TUPLE_SUBCLASS)
 #define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
 
 PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);

Modified: python/branches/p3yk/Include/unicodeobject.h
==============================================================================
--- python/branches/p3yk/Include/unicodeobject.h	(original)
+++ python/branches/p3yk/Include/unicodeobject.h	Sun Feb 25 21:39:11 2007
@@ -392,7 +392,8 @@
 
 PyAPI_DATA(PyTypeObject) PyUnicode_Type;
 
-#define PyUnicode_Check(op) PyObject_TypeCheck(op, &PyUnicode_Type)
+#define PyUnicode_Check(op) \
+                 PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_UNICODE_SUBCLASS)
 #define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type)
 
 /* Fast access macros */

Modified: python/branches/p3yk/Objects/dictobject.c
==============================================================================
--- python/branches/p3yk/Objects/dictobject.c	(original)
+++ python/branches/p3yk/Objects/dictobject.c	Sun Feb 25 21:39:11 2007
@@ -2027,7 +2027,7 @@
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-		Py_TPFLAGS_BASETYPE,		/* tp_flags */
+		Py_TPFLAGS_BASETYPE | Py_TPFLAGS_DICT_SUBCLASS,	/* tp_flags */
 	dictionary_doc,				/* tp_doc */
 	dict_traverse,				/* tp_traverse */
 	dict_tp_clear,				/* tp_clear */

Modified: python/branches/p3yk/Objects/exceptions.c
==============================================================================
--- python/branches/p3yk/Objects/exceptions.c	(original)
+++ python/branches/p3yk/Objects/exceptions.c	Sun Feb 25 21:39:11 2007
@@ -300,7 +300,8 @@
     PyObject_GenericGetAttr,    /*tp_getattro*/
     PyObject_GenericSetAttr,    /*tp_setattro*/
     0,                          /*tp_as_buffer*/
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,  /*tp_flags*/
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+    	Py_TPFLAGS_BASE_EXC_SUBCLASS,  /*tp_flags*/
     PyDoc_STR("Common base class for all exceptions"), /* tp_doc */
     (traverseproc)BaseException_traverse, /* tp_traverse */
     (inquiry)BaseException_clear, /* tp_clear */

Modified: python/branches/p3yk/Objects/intobject.c
==============================================================================
--- python/branches/p3yk/Objects/intobject.c	(original)
+++ python/branches/p3yk/Objects/intobject.c	Sun Feb 25 21:39:11 2007
@@ -1115,7 +1115,8 @@
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+		Py_TPFLAGS_INT_SUBCLASS,	/* tp_flags */
 	int_doc,				/* tp_doc */
 	0,					/* tp_traverse */
 	0,					/* tp_clear */

Modified: python/branches/p3yk/Objects/listobject.c
==============================================================================
--- python/branches/p3yk/Objects/listobject.c	(original)
+++ python/branches/p3yk/Objects/listobject.c	Sun Feb 25 21:39:11 2007
@@ -2683,7 +2683,7 @@
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-		Py_TPFLAGS_BASETYPE,		/* tp_flags */
+		Py_TPFLAGS_BASETYPE | Py_TPFLAGS_LIST_SUBCLASS,	/* tp_flags */
  	list_doc,				/* tp_doc */
  	(traverseproc)list_traverse,		/* tp_traverse */
  	(inquiry)list_clear,			/* tp_clear */

Modified: python/branches/p3yk/Objects/longobject.c
==============================================================================
--- python/branches/p3yk/Objects/longobject.c	(original)
+++ python/branches/p3yk/Objects/longobject.c	Sun Feb 25 21:39:11 2007
@@ -3643,7 +3643,8 @@
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+		Py_TPFLAGS_LONG_SUBCLASS,	/* tp_flags */
 	long_doc,				/* tp_doc */
 	0,					/* tp_traverse */
 	0,					/* tp_clear */

Modified: python/branches/p3yk/Objects/stringobject.c
==============================================================================
--- python/branches/p3yk/Objects/stringobject.c	(original)
+++ python/branches/p3yk/Objects/stringobject.c	Sun Feb 25 21:39:11 2007
@@ -1131,8 +1131,7 @@
 		   much time, since Py_NE is rarely used.  */
 		if (a->ob_size == b->ob_size
 		    && (a->ob_sval[0] == b->ob_sval[0]
-			&& memcmp(a->ob_sval, b->ob_sval,
-				  a->ob_size) == 0)) {
+			&& memcmp(a->ob_sval, b->ob_sval, a->ob_size) == 0)) {
 			result = Py_True;
 		} else {
 			result = Py_False;
@@ -1145,7 +1144,7 @@
 		c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
 		if (c==0)
 			c = memcmp(a->ob_sval, b->ob_sval, min_len);
-	}else
+	} else
 		c = 0;
 	if (c == 0)
 		c = (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
@@ -4018,7 +4017,8 @@
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	&string_as_buffer,			/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+		Py_TPFLAGS_STRING_SUBCLASS,	/* tp_flags */
 	string_doc,				/* tp_doc */
 	0,					/* tp_traverse */
 	0,					/* tp_clear */
@@ -4981,6 +4981,7 @@
 	PyObject *keys;
 	PyStringObject *s;
 	Py_ssize_t i, n;
+	Py_ssize_t immortal_size = 0, mortal_size = 0;
 
 	if (interned == NULL || !PyDict_Check(interned))
 		return;
@@ -4995,8 +4996,9 @@
 	   give them their stolen references back, and then clear and DECREF
 	   the interned dict. */
 
-	fprintf(stderr, "releasing interned strings\n");
 	n = PyList_GET_SIZE(keys);
+	fprintf(stderr, "releasing %" PY_FORMAT_SIZE_T "d interned strings\n",
+		n);
 	for (i = 0; i < n; i++) {
 		s = (PyStringObject *) PyList_GET_ITEM(keys, i);
 		switch (s->ob_sstate) {
@@ -5005,15 +5007,20 @@
 			break;
 		case SSTATE_INTERNED_IMMORTAL:
 			s->ob_refcnt += 1;
+			immortal_size += s->ob_size;
 			break;
 		case SSTATE_INTERNED_MORTAL:
 			s->ob_refcnt += 2;
+			mortal_size += s->ob_size;
 			break;
 		default:
 			Py_FatalError("Inconsistent interned string state.");
 		}
 		s->ob_sstate = SSTATE_NOT_INTERNED;
 	}
+	fprintf(stderr, "total size of all interned strings: "
+			"%" PY_FORMAT_SIZE_T "d/%" PY_FORMAT_SIZE_T "d "
+			"mortal/immortal\n", mortal_size, immortal_size);
 	Py_DECREF(keys);
 	PyDict_Clear(interned);
 	Py_DECREF(interned);

Modified: python/branches/p3yk/Objects/tupleobject.c
==============================================================================
--- python/branches/p3yk/Objects/tupleobject.c	(original)
+++ python/branches/p3yk/Objects/tupleobject.c	Sun Feb 25 21:39:11 2007
@@ -669,7 +669,7 @@
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-		Py_TPFLAGS_BASETYPE,		/* tp_flags */
+		Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TUPLE_SUBCLASS, /* tp_flags */
 	tuple_doc,				/* tp_doc */
  	(traverseproc)tupletraverse,		/* tp_traverse */
 	0,					/* tp_clear */

Modified: python/branches/p3yk/Objects/typeobject.c
==============================================================================
--- python/branches/p3yk/Objects/typeobject.c	(original)
+++ python/branches/p3yk/Objects/typeobject.c	Sun Feb 25 21:39:11 2007
@@ -2205,7 +2205,7 @@
 	(setattrofunc)type_setattro,		/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
-		Py_TPFLAGS_BASETYPE,		/* tp_flags */
+		Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TYPE_SUBCLASS,	/* tp_flags */
 	type_doc,				/* tp_doc */
 	(traverseproc)type_traverse,		/* tp_traverse */
 	(inquiry)type_clear,			/* tp_clear */
@@ -2874,6 +2874,24 @@
 	COPYVAL(tp_itemsize);
 	COPYVAL(tp_weaklistoffset);
 	COPYVAL(tp_dictoffset);
+
+	/* Setup fast subclass flags */
+	if (PyType_IsSubtype(base, (PyTypeObject*)PyExc_BaseException))
+		type->tp_flags |= Py_TPFLAGS_BASE_EXC_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyType_Type))
+		type->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyLong_Type))
+		type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyString_Type))
+		type->tp_flags |= Py_TPFLAGS_STRING_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyUnicode_Type))
+		type->tp_flags |= Py_TPFLAGS_UNICODE_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyTuple_Type))
+		type->tp_flags |= Py_TPFLAGS_TUPLE_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyList_Type))
+		type->tp_flags |= Py_TPFLAGS_LIST_SUBCLASS;
+	else if (PyType_IsSubtype(base, &PyDict_Type))
+		type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
 }
 
 /* Map rich comparison operators to their __xx__ namesakes */

Modified: python/branches/p3yk/Objects/unicodeobject.c
==============================================================================
--- python/branches/p3yk/Objects/unicodeobject.c	(original)
+++ python/branches/p3yk/Objects/unicodeobject.c	Sun Feb 25 21:39:11 2007
@@ -7971,7 +7971,8 @@
     PyObject_GenericGetAttr, 		/* tp_getattro */
     0,			 		/* tp_setattro */
     &unicode_as_buffer,			/* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | 
+        Py_TPFLAGS_UNICODE_SUBCLASS,	/* tp_flags */
     unicode_doc,			/* tp_doc */
     0,					/* tp_traverse */
     0,					/* tp_clear */


More information about the Python-3000-checkins mailing list