[4suite-checkins] In 4Suite/Ft/Xml/src/domlette, files attr.c, attr.h, characterdata.c, characterdata.h, comment.c, comment.h, content_model.c, document.c, document.h, documentfragment.c, documentfragment.h, domimplementation.c, domimplementation.h, domlette.c, domlette.h, domlette_interface.h, element.c, element.h, expat_interface.h, expat_module.c, expat_module.h, namednodemap.c, node.c, node.h, nss.c, nss.h, parse_event_handler.c, parse_event_handler.h, processinginstruction.c, processinginstruction.h, refcounts.c, text.c, text.h, xmlparser.c, xpathnamespace.c, xpathnamespace.h

Jeremy Kloth jkloth at 4suite.org
Wed Dec 20 23:13:37 MST 2006


Modified Files:
    attr.c attr.h characterdata.c characterdata.h comment.c comment.h
    content_model.c document.c document.h domimplementation.c
    domimplementation.h domlette.c domlette.h domlette_interface.h
    element.c element.h expat_interface.h expat_module.c expat_module.h
    namednodemap.c node.c node.h nss.c nss.h parse_event_handler.c
    parse_event_handler.h processinginstruction.c
    processinginstruction.h refcounts.c text.c text.h xmlparser.c
    xpathnamespace.c xpathnamespace.h
Removed Files:
    documentfragment.c documentfragment.h

Log Message:
- Domlette nodes no longer require an ownerDocument. This means now that
ownerDocument may be None for any or all Nodes if they have yet to be
appended to a tree rooted at a Document.
- Also in these changes, DocumentFragments have been removed as the Document
node type supports the same types of children that DocumentFragments did.
- Saxlette now fully supports the EntityResolver interface, and defaults
to the previous behavior of using the InputSource if no resolver has been
registered.

ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/attr.c.diff?r1=1.34&r2=1.35
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/attr.c?rev=1.35&content-type=text/vnd.viewcvs-markup

Index: attr.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/attr.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -U2 -r1.34 -r1.35
--- attr.c	24 Nov 2006 21:36:39 -0000	1.34
+++ attr.c	21 Dec 2006 06:13:36 -0000	1.35
@@ -1,22 +1,19 @@
 #include "domlette.h"
 
-
 /** Private Routines **************************************************/
 
-
-#define Attr_VerifyState(ob)                          \
-  if (!PyAttr_Check(ob) ||                            \
-      ((PyAttrObject *)(ob))->nodeValue == NULL ||    \
-      ((PyAttrObject *)(ob))->namespaceURI == NULL || \
-      ((PyAttrObject *)(ob))->localName == NULL ||    \
-      ((PyAttrObject *)(ob))->nodeName == NULL)       \
+#define Attr_VerifyState(op)                \
+  if (!Attr_Check(op) ||                    \
+      Attr_GET_NODE_VALUE(op) == NULL ||    \
+      Attr_GET_NAMESPACE_URI(op) == NULL || \
+      Attr_GET_LOCAL_NAME(op) == NULL ||    \
+      Attr_GET_NODE_NAME(op) == NULL)       \
      return DOMException_InvalidStateErr("Attr in inconsistent state");
 
-
-static int attr_init(PyAttrObject *self, PyObject *namespaceURI,
+static int attr_init(AttrObject *self, PyObject *namespaceURI,
                      PyObject *qualifiedName, PyObject *localName,
                      PyObject *value)
 {
-  if ((self == NULL || !PyAttr_Check(self)) ||
+  if ((self == NULL || !Attr_Check(self)) ||
       (namespaceURI == NULL || !XmlString_NullCheck(namespaceURI)) ||
       (qualifiedName == NULL || !XmlString_Check(qualifiedName)) ||
@@ -28,5 +25,5 @@
 
   if (value == NULL) {
-    value = PyUnicode_FromUnicode(NULL, (Py_ssize_t)0);
+    value = PyUnicode_FromUnicode(NULL, 0);
     if (value == NULL) return -1;
   } else {
@@ -50,15 +47,12 @@
 }
 
-
 /** Public C API ******************************************************/
 
-
-PyAttrObject *Attr_New(PyDocumentObject *ownerDocument,
-                       PyObject *namespaceURI, PyObject *qualifiedName,
-                       PyObject *localName, PyObject *value)
+AttrObject *Attr_New(PyObject *namespaceURI, PyObject *qualifiedName,
+                     PyObject *localName, PyObject *value)
 {
-  PyAttrObject *self;
+  AttrObject *self;
 
-  self = Node_New(PyAttrObject, &DomletteAttr_Type, ownerDocument);
+  self = Node_New(AttrObject, &DomletteAttr_Type);
   if (self != NULL) {
     if (attr_init(self, namespaceURI, qualifiedName, localName, value) < 0) {
@@ -74,9 +68,8 @@
 
 
-PyAttrObject *Attr_CloneNode(PyObject *node, int deep,
-                             PyDocumentObject *newOwnerDocument)
+AttrObject *Attr_CloneNode(PyObject *node, int deep)
 {
   PyObject *namespaceURI, *qualifiedName, *localName, *value;
-  PyAttrObject *attr;
+  AttrObject *attr;
 
   namespaceURI = PyObject_GetAttrString(node, "namespaceURI");
@@ -97,6 +90,5 @@
   }
 
-  attr = Attr_New(newOwnerDocument, namespaceURI, qualifiedName,
-                  localName, value);
+  attr = Attr_New(namespaceURI, qualifiedName, localName, value);
   Py_DECREF(value);
   Py_DECREF(localName);
@@ -107,36 +99,30 @@
 }
 
-
 /** Python Methods ****************************************************/
 
-
 /* No additional interface methods defined */
 
-
 /** Python Members ****************************************************/
 
-
 static struct PyMemberDef attr_members[] = {
-  { "name",         T_OBJECT, offsetof(PyAttrObject, nodeName),     RO },
-  { "nodeName",     T_OBJECT, offsetof(PyAttrObject, nodeName),     RO },
-  { "namespaceURI", T_OBJECT, offsetof(PyAttrObject, namespaceURI), RO },
-  { "localName",    T_OBJECT, offsetof(PyAttrObject, localName),    RO },
-  { "ownerElement", T_OBJECT, offsetof(PyAttrObject, parentNode),   RO },
+  { "name",         T_OBJECT, offsetof(AttrObject, nodeName),     RO },
+  { "nodeName",     T_OBJECT, offsetof(AttrObject, nodeName),     RO },
+  { "namespaceURI", T_OBJECT, offsetof(AttrObject, namespaceURI), RO },
+  { "localName",    T_OBJECT, offsetof(AttrObject, localName),    RO },
+  { "ownerElement", T_OBJECT, offsetof(AttrObject, parentNode),   RO },
   { NULL }
 };
 
-
 /** Python Computed Members *******************************************/
 
-
-static PyObject *get_prefix(PyAttrObject *self, void *arg)
+static PyObject *get_prefix(AttrObject *self, void *arg)
 {
   Py_UNICODE *p = PyUnicode_AS_UNICODE(self->nodeName);
-  int i, len;
+  Py_ssize_t i, size;
 
-  len = PyUnicode_GET_SIZE(self->nodeName);
-  for (i = 0; i < len; i++) {
+  size = PyUnicode_GET_SIZE(self->nodeName);
+  for (i = 0; i < size; i++) {
     if (p[i] == ':') {
-      return PyUnicode_FromUnicode(p, (Py_ssize_t)i);
+      return PyUnicode_FromUnicode(p, i);
     }
   }
@@ -145,11 +131,10 @@
 }
 
-
-static int set_prefix(PyAttrObject *self, PyObject *v, void *arg)
+static int set_prefix(AttrObject *self, PyObject *v, char *arg)
 {
   PyObject *qualifiedName, *prefix;
   Py_ssize_t size;
 
-  prefix = XmlString_ConvertArgument(v, (char *)arg, 1);
+  prefix = XmlString_ConvertArgument(v, arg, 1);
   if (prefix == NULL) {
     return -1;
@@ -188,6 +173,5 @@
 }
 
-
-static PyObject *get_value(PyAttrObject *self, void *arg)
+static PyObject *get_value(AttrObject *self, char *arg)
 {
   Py_INCREF(self->nodeValue);
@@ -195,8 +179,7 @@
 }
 
-
-static int set_value(PyAttrObject *self, PyObject *v, void *arg)
+static int set_value(AttrObject *self, PyObject *v, char *arg)
 {
-  PyObject *nodeValue = XmlString_ConvertArgument(v, (char *)arg, 0);
+  PyObject *nodeValue = XmlString_ConvertArgument(v, arg, 0);
   if (nodeValue == NULL) return -1;
 
@@ -206,5 +189,4 @@
 }
 
-
 static struct PyGetSetDef attr_getset[] = {
   { "prefix",    (getter)get_prefix, (setter)set_prefix, NULL, "prefix" },
@@ -214,34 +196,21 @@
 };
 
-
 /** Type Object ********************************************************/
 
-
-static void attr_dealloc(PyAttrObject *node)
+static void attr_dealloc(AttrObject *self)
 {
-
-  PyObject_GC_UnTrack((PyObject *) node);
-
-  Py_XDECREF(node->namespaceURI);
-  node->namespaceURI = NULL;
-
-  Py_XDECREF(node->localName);
-  node->localName = NULL;
-
-  Py_XDECREF(node->nodeName);
-  node->nodeName = NULL;
-
-  Py_XDECREF(node->nodeValue);
-  node->nodeValue = NULL;
-
-  Node_Del(node);
+  PyObject_GC_UnTrack((PyObject *)self);
+  Py_CLEAR(self->namespaceURI);
+  Py_CLEAR(self->localName);
+  Py_CLEAR(self->nodeName);
+  Py_CLEAR(self->nodeValue);
+  Node_Del(self);
 }
 
-
-static PyObject *attr_repr(PyAttrObject *attr)
+static PyObject *attr_repr(AttrObject *self)
 {
   PyObject *repr;
-  PyObject *name = PyObject_Repr(attr->nodeName);
-  PyObject *value = PyObject_Repr(attr->nodeValue);
+  PyObject *name = PyObject_Repr(self->nodeName);
+  PyObject *value = PyObject_Repr(self->nodeValue);
   if (name == NULL || value == NULL) {
     Py_XDECREF(name);
@@ -249,7 +218,7 @@
     return NULL;
   }
-  repr = PyString_FromFormat("<Attr at %p: name %s, value %s>", attr,
-                             PyString_AS_STRING(name),
-                             PyString_AS_STRING(value));
+  repr = PyString_FromFormat("<Attr at %p: name %s, value %s>", self,
+                             PyString_AsString(name),
+                             PyString_AsString(value));
   Py_DECREF(name);
   Py_DECREF(value);
@@ -257,15 +226,12 @@
 }
 
-
 static PyObject *attr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-  PyDocumentObject *doc;
   PyObject *namespaceURI, *qualifiedName, *prefix, *localName;
-  static char *kwlist[] = { "ownerDocument", "namespaceURI", "qualifiedName",
+  static char *kwlist[] = { "namespaceURI", "qualifiedName",
                             NULL };
-  PyAttrObject *attr;
+  AttrObject *attr;
 
-  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!OO:Attr", kwlist,
-                                   &DomletteDocument_Type, &doc,
+  if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:Attr", kwlist,
                                    &namespaceURI, &qualifiedName)) {
     return NULL;
@@ -296,7 +262,7 @@
 
   if (type != &DomletteAttr_Type) {
-    attr = (PyAttrObject *) type->tp_alloc(type, 0);
+    attr = (AttrObject *) type->tp_alloc(type, 0);
     if (attr != NULL) {
-      _Node_INIT(attr, doc);
+      _Node_INIT(attr);
       if (attr_init(attr, namespaceURI, qualifiedName, localName, NULL) < 0) {
         Py_DECREF(attr);
@@ -305,5 +271,5 @@
     }
   } else {
-    attr = Attr_New(doc, namespaceURI, qualifiedName, localName, NULL);
+    attr = Attr_New(namespaceURI, qualifiedName, localName, NULL);
   }
   Py_DECREF(namespaceURI);
@@ -314,7 +280,6 @@
 }
 
-
 static char attr_doc[] = "\
-Attr(ownerDocument, namespaceURI, qualifiedName) -> Attr object\n\
+Attr(namespaceURI, qualifiedName) -> Attr object\n\
 \n\
 The Attr interface represents an attribute in an Element object.";
@@ -324,5 +289,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "Attr",
-  /* tp_basicsize      */ sizeof(PyAttrObject),
+  /* tp_basicsize      */ sizeof(AttrObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) attr_dealloc,
@@ -345,5 +310,5 @@
   /* tp_doc            */ (char *) attr_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -364,8 +329,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteAttr_Init(PyObject *module)
 {
@@ -405,5 +368,4 @@
 }
 
-
 void DomletteAttr_Fini(void)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/attr.h.diff?r1=1.15&r2=1.16
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/attr.h?rev=1.16&content-type=text/vnd.viewcvs-markup

Index: attr.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/attr.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -U2 -r1.15 -r1.16
--- attr.h	24 Nov 2006 21:36:39 -0000	1.15
+++ attr.h	21 Dec 2006 06:13:36 -0000	1.16
@@ -11,5 +11,5 @@
 
   typedef struct {
-    PyNode_HEAD
+    Node_HEAD
     PyObject *namespaceURI;
     PyObject *localName;
@@ -17,11 +17,12 @@
     PyObject *nodeValue;
     AttributeType type;
-  } PyAttrObject;
+  } AttrObject;
 
-#define PyAttr_NAMESPACE_URI(op) (((PyAttrObject *)(op))->namespaceURI)
-#define PyAttr_LOCAL_NAME(op) (((PyAttrObject *)(op))->localName)
-#define PyAttr_NODE_NAME(op) (((PyAttrObject *)(op))->nodeName)
-#define PyAttr_NODE_VALUE(op) (((PyAttrObject *)(op))->nodeValue)
-#define Attr_GET_TYPE(op) (((PyAttrObject *)(op))->type)
+#define Attr(op) ((AttrObject *)(op))
+#define Attr_GET_NAMESPACE_URI(op) (Attr(op)->namespaceURI)
+#define Attr_GET_LOCAL_NAME(op) (Attr(op)->localName)
+#define Attr_GET_NODE_NAME(op) (Attr(op)->nodeName)
+#define Attr_GET_NODE_VALUE(op) (Attr(op)->nodeValue)
+#define Attr_GET_TYPE(op) (Attr(op)->type)
 
 #ifdef Domlette_BUILDING_MODULE
@@ -29,6 +30,6 @@
   extern PyTypeObject DomletteAttr_Type;
 
-#define PyAttr_Check(op) PyObject_TypeCheck((op), &DomletteAttr_Type)
-#define PyAttr_CheckExact(op) ((op)->ob_type == &DomletteAttr_Type)
+#define Attr_Check(op) PyObject_TypeCheck((op), &DomletteAttr_Type)
+#define Attr_CheckExact(op) ((op)->ob_type == &DomletteAttr_Type)
 
   /* Module Methods */
@@ -37,10 +38,8 @@
 
   /* Attr Methods */
-  PyAttrObject *Attr_New(PyDocumentObject *ownerDocument,
-                         PyObject *namespaceURI, PyObject *qualifiedName,
-                         PyObject *localName, PyObject *value);
+  AttrObject *Attr_New(PyObject *namespaceURI, PyObject *qualifiedName,
+                       PyObject *localName, PyObject *value);
 
-  PyAttrObject *Attr_CloneNode(PyObject *node, int deep,
-                               PyDocumentObject *newOwnerDocument);
+  AttrObject *Attr_CloneNode(PyObject *node, int deep);
 
 #endif
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/characterdata.c.diff?r1=1.16&r2=1.17
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/characterdata.c?rev=1.17&content-type=text/vnd.viewcvs-markup

Index: characterdata.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/characterdata.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -U2 -r1.16 -r1.17
--- characterdata.c	24 Nov 2006 21:36:39 -0000	1.16
+++ characterdata.c	21 Dec 2006 06:13:36 -0000	1.17
@@ -10,7 +10,7 @@
 #define CHARACTERDATA_REPR_LIMIT 20
 
-static int characterdata_init(PyCharacterDataObject *self, PyObject *data)
+static int characterdata_init(CharacterDataObject *self, PyObject *data)
 {
-  if ((self == NULL || !PyCharacterData_Check(self)) ||
+  if ((self == NULL || !CharacterData_Check(self)) ||
       (data == NULL || !XmlString_Check(data))) {
     PyErr_BadInternalCall();
@@ -28,11 +28,9 @@
 
 
-PyCharacterDataObject *_CharacterData_New(PyTypeObject *type,
-                                          PyDocumentObject *ownerDocument,
-                                          PyObject *data)
+CharacterDataObject *_CharacterData_New(PyTypeObject *type, PyObject *data)
 {
-  PyCharacterDataObject *self;
+  CharacterDataObject *self;
 
-  self = Node_New(PyCharacterDataObject, type, ownerDocument);
+  self = Node_New(CharacterDataObject, type);
   if (self != NULL) {
     if (characterdata_init(self, data) < 0) {
@@ -48,10 +46,9 @@
 
 
-PyCharacterDataObject *_CharacterData_CloneNode(
-  PyTypeObject *type, PyObject *node, int deep,
-  PyDocumentObject *newOwnerDocument)
+CharacterDataObject *_CharacterData_CloneNode(PyTypeObject *type,
+                                              PyObject *node, int deep)
 {
   PyObject *nodeValue;
-  PyCharacterDataObject *newNode;
+  CharacterDataObject *newNode;
 
   nodeValue = PyObject_GetAttrString(node, "nodeValue");
@@ -59,5 +56,5 @@
   if (nodeValue == NULL) return NULL;
 
-  newNode = _CharacterData_New(type, newOwnerDocument, nodeValue);
+  newNode = _CharacterData_New(type, nodeValue);
   Py_DECREF(nodeValue);
 
@@ -66,28 +63,33 @@
 
 
-PyObject *CharacterData_SubstringData(PyCharacterDataObject *self, int index,
-                                      int count)
+PyObject *CharacterData_SubstringData(CharacterDataObject *self,
+                                      Py_ssize_t index, Py_ssize_t count)
 {
   PyObject *newValue;
 
-  newValue = PyUnicode_FromUnicode(NULL, (Py_ssize_t)count);
-  if (!newValue) return NULL;
-
-  Py_UNICODE_COPY(PyUnicode_AS_UNICODE(newValue),
-                  PyUnicode_AS_UNICODE(self->nodeValue) + index,
-                  count);
+  newValue = PyUnicode_FromUnicode(NULL, count);
+  if (newValue) {
+    Py_UNICODE_COPY(PyUnicode_AS_UNICODE(newValue),
+                    PyUnicode_AS_UNICODE(self->nodeValue) + index,
+                    count);
+  }
   return newValue;
 }
 
 
-int CharacterData_AppendData(PyCharacterDataObject *self, PyObject *arg)
+int CharacterData_AppendData(CharacterDataObject *self, PyObject *arg)
 {
   PyObject *oldValue = self->nodeValue;
   PyObject *newValue;
 
+  if (arg == NULL || !PyUnicode_Check(arg)) {
+    PyErr_BadInternalCall();
+    return -1;
+  }
+
   newValue = PyUnicode_FromUnicode(NULL,
                                    PyUnicode_GET_SIZE(oldValue) + \
                                    PyUnicode_GET_SIZE(arg));
-  if (!newValue) return -1;
+  if (newValue == NULL) return -1;
 
   Py_UNICODE_COPY(PyUnicode_AS_UNICODE(newValue),
@@ -104,5 +106,5 @@
 
 
-int CharacterData_InsertData(PyCharacterDataObject *self, int offset,
+int CharacterData_InsertData(CharacterDataObject *self, Py_ssize_t offset,
                              PyObject *arg)
 {
@@ -110,8 +112,13 @@
   PyObject *newValue;
 
+  if (arg == NULL || !PyUnicode_Check(arg)) {
+    PyErr_BadInternalCall();
+    return -1;
+  }
+
   newValue = PyUnicode_FromUnicode(NULL,
                                    PyUnicode_GET_SIZE(oldValue) + \
                                    PyUnicode_GET_SIZE(arg));
-  if (!newValue) return -1;
+  if (newValue == NULL) return -1;
 
   Py_UNICODE_COPY(PyUnicode_AS_UNICODE(newValue),
@@ -131,6 +138,6 @@
 
 
-int CharacterData_DeleteData(PyCharacterDataObject *self, int offset,
-                             int count)
+int CharacterData_DeleteData(CharacterDataObject *self, Py_ssize_t offset,
+                             Py_ssize_t count)
 {
   PyObject *oldValue = self->nodeValue;
@@ -138,5 +145,5 @@
 
   newValue = PyUnicode_FromUnicode(NULL, PyUnicode_GET_SIZE(oldValue) - count);
-  if (!newValue) return -1;
+  if (newValue == NULL) return -1;
 
   Py_UNICODE_COPY(PyUnicode_AS_UNICODE(newValue),
@@ -153,14 +160,19 @@
 
 
-int CharacterData_ReplaceData(PyCharacterDataObject *self, int offset,
-                              int count, PyObject *arg)
+int CharacterData_ReplaceData(CharacterDataObject *self, Py_ssize_t offset,
+                              Py_ssize_t count, PyObject *arg)
 {
   PyObject *oldValue = self->nodeValue;
   PyObject *newValue;
 
+  if (arg == NULL || !PyUnicode_Check(arg)) {
+    PyErr_BadInternalCall();
+    return -1;
+  }
+
   newValue = PyUnicode_FromUnicode(NULL,
                                    PyUnicode_GET_SIZE(oldValue) - count + \
                                    PyUnicode_GET_SIZE(arg));
-  if (!newValue) return -1;
+  if (newValue == NULL) return -1;
 
   Py_UNICODE_COPY(PyUnicode_AS_UNICODE(newValue),
@@ -188,10 +200,11 @@
 static PyObject *characterdata_substring(PyObject *self, PyObject *args)
 {
-  int offset, count;
+  Py_ssize_t offset, count;
 
-  if (!PyArg_ParseTuple(args, "ii:substringData", &offset, &count))
+  if (!PyArg_ParseTuple(args, PY_ARG_SSIZE_T PY_ARG_SSIZE_T ":substringData",
+                        &offset, &count))
     return NULL;
 
-  return CharacterData_SubstringData((PyCharacterDataObject *)self, offset, count);
+  return CharacterData_SubstringData(CharacterData(self), offset, count);
 }
 
@@ -210,5 +223,5 @@
     return NULL;
 
-  if (CharacterData_AppendData((PyCharacterDataObject *)self, data) == -1) {
+  if (CharacterData_AppendData(CharacterData(self), data) < 0) {
     Py_DECREF(data);
     return NULL;
@@ -226,8 +239,8 @@
 static PyObject *characterdata_insert(PyObject *self, PyObject *args)
 {
-  int offset;
+  Py_ssize_t offset;
   PyObject *data;
 
-  if (!PyArg_ParseTuple(args, "iO:insertData", &offset, &data))
+  if (!PyArg_ParseTuple(args, PY_ARG_SSIZE_T "O:insertData", &offset, &data))
     return NULL;
 
@@ -235,5 +248,5 @@
     return NULL;
 
-  if (CharacterData_InsertData((PyCharacterDataObject *)self, offset, data) == -1) {
+  if (CharacterData_InsertData(CharacterData(self), offset, data) < 0) {
     Py_DECREF(data);
     return NULL;
@@ -251,10 +264,11 @@
 static PyObject *characterdata_delete(PyObject *self, PyObject *args)
 {
-  int offset, count;
+  Py_ssize_t offset, count;
 
-  if (!PyArg_ParseTuple(args, "ii:deleteData", &offset, &count))
+  if (!PyArg_ParseTuple(args, PY_ARG_SSIZE_T PY_ARG_SSIZE_T ":deleteData",
+                        &offset, &count))
     return NULL;
 
-  if (CharacterData_DeleteData((PyCharacterDataObject *)self, offset, count) == -1)
+  if (CharacterData_DeleteData(CharacterData(self), offset, count) < 0)
     return NULL;
 
@@ -270,8 +284,9 @@
 static PyObject *characterdata_replace(PyObject *self, PyObject *args)
 {
-  int offset, count;
+  Py_ssize_t offset, count;
   PyObject *data;
 
-  if (!PyArg_ParseTuple(args, "iiO:replaceData", &offset, &count, &data))
+  if (!PyArg_ParseTuple(args, PY_ARG_SSIZE_T PY_ARG_SSIZE_T "O:replaceData",
+                        &offset, &count, &data))
     return NULL;
 
@@ -279,5 +294,5 @@
     return NULL;
 
-  if (CharacterData_DeleteData((PyCharacterDataObject *)self, offset, count) == -1) {
+  if (CharacterData_DeleteData(CharacterData(self), offset, count) < 0) {
     Py_DECREF(data);
     return NULL;
@@ -309,5 +324,5 @@
 
 
-static PyObject *get_data(PyCharacterDataObject *self, void *arg)
+static PyObject *get_data(CharacterDataObject *self, void *arg)
 {
   Py_INCREF(self->nodeValue);
@@ -316,5 +331,5 @@
 
 
-static int set_data(PyCharacterDataObject *self, PyObject *v, void *arg)
+static int set_data(CharacterDataObject *self, PyObject *v, void *arg)
 {
   PyObject *nodeValue = XmlString_ConvertArgument(v, (char *)arg, 0);
@@ -327,7 +342,11 @@
 
 
-static PyObject *get_length(PyCharacterDataObject *self, void *arg)
+static PyObject *get_length(CharacterDataObject *self, void *arg)
 {
+#if PY_VERSION_HEX < 0x02050000
     return PyInt_FromLong(PyUnicode_GET_SIZE(self->nodeValue));
+#else
+    return PyInt_FromSsize_t(PyUnicode_GET_SIZE(self->nodeValue));
+#endif
 }
 
@@ -344,5 +363,5 @@
 
 
-static void characterdata_dealloc(PyCharacterDataObject *self)
+static void characterdata_dealloc(CharacterDataObject *self)
 {
   PyObject_GC_UnTrack((PyObject *) self);
@@ -354,23 +373,30 @@
 
 
-static PyObject *characterdata_repr(PyCharacterDataObject *self)
+static PyObject *characterdata_repr(CharacterDataObject *self)
 {
   PyObject *obj, *repr, *name;
 
   if (PyUnicode_GET_SIZE(self->nodeValue) > CHARACTERDATA_REPR_LIMIT) {
-    Py_UNICODE dots[] = { '.', '.', '.' };
-    PyObject *slice, *ellipsis;
-    slice = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(self->nodeValue),
-                                  (Py_ssize_t)(CHARACTERDATA_REPR_LIMIT - sizeof(dots)));
-    ellipsis = PyUnicode_FromUnicode(dots, 3);
-    if (slice == NULL || ellipsis == NULL) {
-      Py_XDECREF(slice);
-      Py_XDECREF(ellipsis);
+    Py_UNICODE *src, *dst;
+
+    obj = PyUnicode_FromUnicode(NULL, CHARACTERDATA_REPR_LIMIT + 3);
+    if (obj == NULL) {
       return NULL;
     }
-    obj = PyUnicode_Concat(slice, ellipsis);
-    Py_DECREF(slice);
-    Py_DECREF(ellipsis);
-    if (obj == NULL) return NULL;
+    /* copy the first part of the node value */
+    src = PyUnicode_AS_UNICODE(self->nodeValue);
+    dst = PyUnicode_AS_UNICODE(obj);
+    Py_UNICODE_COPY(dst, src, (CHARACTERDATA_REPR_LIMIT / 2));
+    dst += (CHARACTERDATA_REPR_LIMIT / 2);
+
+    /* add the ellipsis */
+    *dst++ = '.';
+    *dst++ = '.';
+    *dst++ = '.';
+
+    /* copy the last part of the node value */
+    src += PyUnicode_GET_SIZE(self->nodeValue);
+    src -= (CHARACTERDATA_REPR_LIMIT / 2);
+    Py_UNICODE_COPY(dst, src, (CHARACTERDATA_REPR_LIMIT / 2));
   } else {
     obj = self->nodeValue;
@@ -378,16 +404,21 @@
   }
 
-  repr = PyObject_Repr(obj);
-  Py_DECREF(obj);
-  if (repr == NULL) return NULL;
-
   name = PyObject_GetAttrString((PyObject *)self->ob_type, "__name__");
   if (name == NULL) {
-    Py_DECREF(repr);
+    Py_DECREF(obj);
+    return NULL;
+  }
+
+  repr = PyObject_Repr(obj);
+  Py_DECREF(obj);
+  if (repr == NULL) {
+    Py_DECREF(name);
     return NULL;
   }
 
-  obj = PyString_FromFormat("<%s at %p: %s>", PyString_AS_STRING(name), self,
-                            PyString_AS_STRING(repr));
+  /* `name` and `repr` should be PyStringObject, but play it safe and use
+   * the error-checking function instead of the lookup macro. */
+  obj = PyString_FromFormat("<%s at %p: %s>", PyString_AsString(name), self,
+                            PyString_AsString(repr));
   Py_DECREF(name);
   Py_DECREF(repr);
@@ -399,8 +430,7 @@
                                    PyObject *kwds)
 {
-  PyDocumentObject *doc;
   PyObject *data;
-  static char *kwlist[] = { "ownerDocument", "data", NULL };
-  PyCharacterDataObject *self;
+  static char *kwlist[] = { "data", NULL };
+  CharacterDataObject *self;
 
   if (type == &DomletteCharacterData_Type) {
@@ -410,6 +440,6 @@
   }
 
-  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O:CharacterData", kwlist,
-                                   &DomletteDocument_Type, &doc, &data)) {
+  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:CharacterData", kwlist,
+                                   &data)) {
     return NULL;
   }
@@ -418,7 +448,7 @@
     return NULL;
 
-  self = (PyCharacterDataObject *) type->tp_alloc(type, 0);
+  self = CharacterData(type->tp_alloc(type, 0));
   if (self != NULL) {
-    _Node_INIT(self, doc);
+    _Node_INIT(self);
     if (characterdata_init(self, data) < 0) {
       Py_DECREF(self);
@@ -433,5 +463,5 @@
 
 static char characterdata_doc[] = "\
-CharacterData(ownerDocument, data) -> CharacterData object\n\
+CharacterData(data) -> CharacterData object\n\
 \n\
 This interface represents a block of XML character data.";
@@ -441,5 +471,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "CharacterData",
-  /* tp_basicsize      */ sizeof(PyCharacterDataObject),
+  /* tp_basicsize      */ sizeof(CharacterDataObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) characterdata_dealloc,
@@ -462,5 +492,5 @@
   /* tp_doc            */ (char *) characterdata_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/characterdata.h.diff?r1=1.8&r2=1.9
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/characterdata.h?rev=1.9&content-type=text/vnd.viewcvs-markup

Index: characterdata.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/characterdata.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -U2 -r1.8 -r1.9
--- characterdata.h	24 Nov 2006 21:36:39 -0000	1.8
+++ characterdata.h	21 Dec 2006 06:13:36 -0000	1.9
@@ -10,9 +10,10 @@
 
   typedef struct {
-    PyNode_HEAD
+    Node_HEAD
     PyObject *nodeValue;
-  } PyCharacterDataObject;
+  } CharacterDataObject;
 
-#define PyCharacterData_NODE_VALUE(op) (((PyCharacterDataObject *)(op))->nodeValue)
+#define CharacterData(op) ((CharacterDataObject *)(op))
+#define CharacterData_GET_NODE_VALUE(op) (CharacterData(op)->nodeValue)
 
 #ifdef Domlette_BUILDING_MODULE
@@ -20,7 +21,7 @@
   extern PyTypeObject DomletteCharacterData_Type;
 
-#define PyCharacterData_Check(op) \
+#define CharacterData_Check(op) \
   PyObject_TypeCheck((op), &DomletteCharacterData_Type)
-#define PyCharacterData_CheckExact(op) \
+#define CharacterData_CheckExact(op) \
   ((op)->ob_type, &DomletteCharacterData_Type)
 
@@ -30,30 +31,26 @@
 
   /* CharacterData Methods */
-  PyCharacterDataObject *_CharacterData_New(PyTypeObject *type,
-                                            PyDocumentObject *ownerDocument,
-                                            PyObject *data);
-#define CharacterData_New(type, typeobj, ownerdoc, data) \
-  ((type *) _CharacterData_New((typeobj), (ownerdoc), (data)))
-
-  PyCharacterDataObject *_CharacterData_CloneNode(
-    PyTypeObject *type, PyObject *node, int deep,
-    PyDocumentObject *newOwnerDocument);
-#define CharacterData_CloneNode(type, typeobj, node, deep, ownerdoc) \
-  ((type *) _CharacterData_CloneNode((typeobj), (node), (deep), (ownerdoc)))
+  CharacterDataObject *_CharacterData_New(PyTypeObject *type, PyObject *data);
+#define CharacterData_New(type, typeobj, data) \
+  ((type *) _CharacterData_New((typeobj), (data)))
 
-  PyObject *CharacterData_SubstringData(PyCharacterDataObject *node,
-                                        int offset, int count);
+  CharacterDataObject *_CharacterData_CloneNode(PyTypeObject *type,
+                                                PyObject *node, int deep);
+#define CharacterData_CloneNode(type, typeobj, node, deep) \
+  ((type *) _CharacterData_CloneNode((typeobj), (node), (deep)))
 
-  int CharacterData_AppendData(PyCharacterDataObject *node,
-                               PyObject *arg);
+  PyObject *CharacterData_SubstringData(CharacterDataObject *node,
+                                        Py_ssize_t offset, Py_ssize_t count);
+
+  int CharacterData_AppendData(CharacterDataObject *node, PyObject *arg);
 
-  int CharacterData_InsertData(PyCharacterDataObject *node,
-                               int offset, PyObject *arg);
+  int CharacterData_InsertData(CharacterDataObject *node, Py_ssize_t offset,
+                               PyObject *arg);
 
-  int CharacterData_DeleteData(PyCharacterDataObject *node,
-                               int offset, int count);
+  int CharacterData_DeleteData(CharacterDataObject *node, Py_ssize_t offset,
+                               Py_ssize_t count);
 
-  int CharacterData_ReplaceData(PyCharacterDataObject *node,
-                                int offset, int count, PyObject *arg);
+  int CharacterData_ReplaceData(CharacterDataObject *node, Py_ssize_t offset,
+                                Py_ssize_t count,PyObject *arg);
 
 #endif /* Domlette_BUILDING_MODULE */
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/comment.c.diff?r1=1.25&r2=1.26
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/comment.c?rev=1.26&content-type=text/vnd.viewcvs-markup

Index: comment.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/comment.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -U2 -r1.25 -r1.26
--- comment.c	24 Nov 2006 21:36:39 -0000	1.25
+++ comment.c	21 Dec 2006 06:13:36 -0000	1.26
@@ -1,7 +1,7 @@
 #include "domlette.h"
 
-
 /** Private Routines **************************************************/
 
+/* nothing to see here */
 
 /** Public C API *******************************************************/
@@ -10,41 +10,38 @@
 
 #undef Comment_New
-PyCommentObject *Comment_New(PyDocumentObject *ownerDocument, PyObject *data)
+CommentObject *Comment_New(PyObject *data)
 {
-  return CharacterData_New(PyCommentObject, &DomletteComment_Type,
-                           ownerDocument, data);
+  return CharacterData_New(CommentObject, &DomletteComment_Type, data);
 }
 
 #undef Comment_CloneNode
-PyCommentObject *Comment_CloneNode(PyObject *node, int deep,
-                                   PyDocumentObject *newOwnerDocument)
+CommentObject *Comment_CloneNode(PyObject *node, int deep)
 {
-  return CharacterData_CloneNode(PyCommentObject, &DomletteComment_Type,
-                                 node, deep, newOwnerDocument);
+  return CharacterData_CloneNode(CommentObject, &DomletteComment_Type,
+                                 node, deep);
 }
 
 /** Python Methods ****************************************************/
 
-
-/* No additional interface methods defined */
-
+static PyMethodDef comment_methods[] = {
+  { NULL }
+};
 
 /** Python Members *****************************************************/
 
-
-/* No additional interface members defined */
-
+static PyMethodDef comment_members[] = {
+  { NULL }
+};
 
 /** Python Computed Members ********************************************/
 
-
-/* No additional interface members defined */
-
+static PyGetSetDef comment_getset[] = {
+  { NULL }
+};
 
 /** Type Object ********************************************************/
 
-
 static char comment_doc[] = "\
-Comment(ownerDocument, data) -> Comment object\n\
+Comment(data) -> Comment object\n\
 \n\
 This interface represents the content of a comment, i.e., all the characters\n\
@@ -55,5 +52,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "Comment",
-  /* tp_basicsize      */ sizeof(PyCommentObject),
+  /* tp_basicsize      */ sizeof(CommentObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) 0,
@@ -76,12 +73,12 @@
   /* tp_doc            */ (char *) comment_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
   /* tp_iter           */ (getiterfunc) 0,
   /* tp_iternext       */ (iternextfunc) 0,
-  /* tp_methods        */ (PyMethodDef *) 0,
-  /* tp_members        */ (PyMemberDef *) 0,
-  /* tp_getset         */ (PyGetSetDef *) 0,
+  /* tp_methods        */ (PyMethodDef *) comment_methods,
+  /* tp_members        */ (PyMemberDef *) comment_members,
+  /* tp_getset         */ (PyGetSetDef *) comment_getset,
   /* tp_base           */ (PyTypeObject *) 0,
   /* tp_dict           */ (PyObject *) 0,
@@ -95,8 +92,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteComment_Init(PyObject *module)
 {
@@ -116,5 +111,5 @@
   Py_DECREF(value);
 
-  value = PyUnicode_DecodeASCII("#comment", (Py_ssize_t)8, NULL);
+  value = XmlString_FromASCII("#comment");
   if (value == NULL)
     return -1;
@@ -128,5 +123,4 @@
 }
 
-
 void DomletteComment_Fini(void)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/comment.h.diff?r1=1.10&r2=1.11
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/comment.h?rev=1.11&content-type=text/vnd.viewcvs-markup

Index: comment.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/comment.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -U2 -r1.10 -r1.11
--- comment.h	24 Nov 2006 21:36:39 -0000	1.10
+++ comment.h	21 Dec 2006 06:13:36 -0000	1.11
@@ -9,7 +9,7 @@
 #include "characterdata.h"
 
-  typedef PyCharacterDataObject PyCommentObject;
+  typedef CharacterDataObject CommentObject;
 
-#define Comment_GET_DATA(op) PyCharacterData_NODE_VALUE(op)
+#define Comment_GET_DATA(op) CharacterData_NODE_VALUE(op)
 #define Comment_SET_DATA(op, v) (Comment_GET_DATA(op) = (v))
 
@@ -18,6 +18,6 @@
   extern PyTypeObject DomletteComment_Type;
 
-#define PyComment_Check(op) PyObject_TypeCheck((op), &DomletteComment_Type)
-#define PyComment_CheckExact(op) ((op)->ob_type == &DomletteComment_Type)
+#define Comment_Check(op) PyObject_TypeCheck((op), &DomletteComment_Type)
+#define Comment_CheckExact(op) ((op)->ob_type == &DomletteComment_Type)
 
   /* Module Methods */
@@ -26,14 +26,11 @@
 
   /* Comment Methods */
-  PyCommentObject *Comment_New(PyDocumentObject *ownerDocument, PyObject *data);
-#define Comment_New(ownerDocument, data) \
-  CharacterData_New(PyCommentObject, &DomletteComment_Type, \
-                    (ownerDocument), (data))
-
-  PyCommentObject *Comment_CloneNode(PyObject *node, int deep,
-                                     PyDocumentObject *newOwnerDocument);
-#define Comment_CloneNode(node, deep, newOwnerDocument) \
-  CharacterData_CloneNode(PyCommentObject, &DomletteComment_Type, (node), \
-                         (deep), (newOwnerDocument))
+  CommentObject *Comment_New(PyObject *data);
+#define Comment_New(data) \
+  CharacterData_New(CommentObject, &DomletteComment_Type, (data))
+
+  CommentObject *Comment_CloneNode(PyObject *node, int deep);
+#define Comment_CloneNode(node, deep) \
+  CharacterData_CloneNode(CommentObject, &DomletteComment_Type, (node), (deep))
 
 #endif /* Domlette_BUILDING_MODULE */
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/content_model.c.diff?r1=1.9&r2=1.10
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/content_model.c?rev=1.10&content-type=text/vnd.viewcvs-markup

Index: content_model.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/content_model.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -U2 -r1.9 -r1.10
--- content_model.c	31 Oct 2006 00:05:46 -0000	1.9
+++ content_model.c	21 Dec 2006 06:13:36 -0000	1.10
@@ -1182,5 +1182,5 @@
   /* tp_doc            */ (char *) model_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/document.c.diff?r1=1.57&r2=1.58
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/document.c?rev=1.58&content-type=text/vnd.viewcvs-markup

Index: document.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/document.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -U2 -r1.57 -r1.58
--- document.c	24 Nov 2006 21:36:39 -0000	1.57
+++ document.c	21 Dec 2006 06:13:36 -0000	1.58
@@ -1,12 +1,9 @@
 #include "domlette.h"
 
-
 /** Private Routines **************************************************/
 
-
 static PyObject *creation_counter, *counter_inc;
 
-
-static int document_init(PyDocumentObject *self, PyObject *documentURI)
+static int document_init(DocumentObject *self, PyObject *documentURI)
 {
   PyObject *creationIndex, *unparsedEntities;
@@ -55,19 +52,18 @@
 }
 
-
 /* returns borrowed reference */
-static PyObject *get_element_by_id(PyNodeObject *node, PyObject *elementId)
+static PyObject *get_element_by_id(NodeObject *node, PyObject *elementId)
 {
   int i;
 
   for (i = 0; i < ContainerNode_GET_COUNT(node); i++) {
-    PyNodeObject *child = ContainerNode_GET_CHILD(node, i);
-    if (PyElement_Check(child)) {
+    NodeObject *child = ContainerNode_GET_CHILD(node, i);
+    if (Element_Check(child)) {
       PyObject *tmp, *attr;
       Py_ssize_t pos = 0;
       /* Searth the attributes for an ID attr */
-      while (PyDict_Next(PyElement_ATTRIBUTES(child), &pos, &tmp, &attr)) {
+      while (PyDict_Next(Element_GET_ATTRIBUTES(child), &pos, &tmp, &attr)) {
         if (Attr_GET_TYPE(attr) == ATTRIBUTE_TYPE_ID) {
-          tmp = PyAttr_NODE_VALUE(attr);
+          tmp = Attr_GET_NODE_VALUE(attr);
           switch (PyObject_RichCompareBool(tmp, elementId, Py_EQ)) {
           case 1:
@@ -90,14 +86,11 @@
 }
 
-
 /** Public C API ******************************************************/
 
-
-PyDocumentObject *Document_New(PyObject *documentURI)
+DocumentObject *Document_New(PyObject *documentURI)
 {
-  PyDocumentObject *self;
+  DocumentObject *self;
 
-  self = Node_NewContainer(PyDocumentObject, &DomletteDocument_Type,
-                           (PyDocumentObject *) Py_None);
+  self = Node_NewContainer(DocumentObject, &DomletteDocument_Type);
   if (self != NULL) {
     if (document_init(self, documentURI) < 0) {
@@ -112,8 +105,6 @@
 }
 
-
 /** Python Methods ****************************************************/
 
-
 static char document_createElementNS_doc[] =
 "createElementNS(namespaceURI, qualifiedName) -> new Element\n\
@@ -129,9 +120,7 @@
     return NULL;
 
-  return PyObject_CallFunction((PyObject *)(&DomletteElement_Type), "OOO",
-                               self, namespaceURI, qualifiedName);
+  return PyObject_Call((PyObject *)(&DomletteElement_Type), args, NULL);
 }
 
-
 static char document_createAttributeNS_doc[] =
 "createAttributeNS(namespaceURI, qualifiedName) -> new Attribute\n\
@@ -147,9 +136,7 @@
     return NULL;
 
-  return PyObject_CallFunction((PyObject *)(&DomletteAttr_Type), "OOO",
-                               self, namespaceURI, qualifiedName);
+  return PyObject_Call((PyObject *)(&DomletteAttr_Type), args, NULL);
 }
 
-
 static char document_createTextNode_doc[] =
 "createTextNode(data) -> new Text\n\
@@ -164,9 +151,7 @@
     return NULL;
 
-  return PyObject_CallFunction((PyObject *)(&DomletteText_Type), "OO",
-                               self, data);
+  return PyObject_Call((PyObject *)(&DomletteText_Type), args, NULL);
 }
 
-
 static char document_createProcessingInstruction_doc[] =
 "createProcessingInstruction(target, data) -> new ProcessingInstruction\n\
@@ -183,10 +168,8 @@
     return NULL;
 
-  return PyObject_CallFunction(
-    (PyObject *)(&DomletteProcessingInstruction_Type),
-    "OOO", self, target, data);
+  return PyObject_Call((PyObject *)(&DomletteProcessingInstruction_Type),
+                       args, NULL);
 }
 
-
 static char document_createComment_doc[] =
 "createComment(data) -> new Comment\n\
@@ -201,21 +184,5 @@
     return NULL;
 
-  return PyObject_CallFunction((PyObject *)(&DomletteComment_Type), "OO",
-                               self, data);
-}
-
-static char document_createDocumentFragment_doc[] =
-"createDocumentFragment() -> new DocumentFragment\n\
-\n\
-Creates an empty DocumentFragment object.";
-
-static PyObject *document_createDocumentFragment(PyObject *self,
-                                                 PyObject *args)
-{
-  if (!PyArg_ParseTuple(args, ":createDocumentFragment"))
-    return NULL;
-
-  return PyObject_CallFunction((PyObject *)(&DomletteDocumentFragment_Type),
-                               "O", self);
+  return PyObject_Call((PyObject *)(&DomletteComment_Type), args, NULL);
 }
 
@@ -240,5 +207,5 @@
     return NULL;
 
-  return (PyObject *)Node_CloneNode(node, deep, (PyDocumentObject *) self);
+  return (PyObject *)Node_CloneNode(node, deep);
 }
 
@@ -261,6 +228,6 @@
   /* our "document" can have multiple element children */
   for (i = 0; i < ContainerNode_GET_COUNT(self); i++) {
-    PyNodeObject *node = ContainerNode_GET_CHILD(self, i);
-    if (PyElement_Check(node)) {
+    NodeObject *node = ContainerNode_GET_CHILD(self, i);
+    if (Element_Check(node)) {
       element = get_element_by_id(node, elementId);
       if (element == NULL) return NULL;
@@ -276,40 +243,31 @@
 }
 
-
-#define document_method(NAME) \
-  { #NAME, document_##NAME, METH_VARARGS, document_##NAME##_doc }
+#define Document_METHOD(name) \
+  { #name, document_##name, METH_VARARGS, document_##name##_doc }
 
 static struct PyMethodDef document_methods[] = {
-  document_method(createElementNS),
-  document_method(createAttributeNS),
-  document_method(createTextNode),
-  document_method(createProcessingInstruction),
-  document_method(createComment),
-  document_method(createDocumentFragment),
-  document_method(importNode),
-  document_method(getElementById),
+  Document_METHOD(createElementNS),
+  Document_METHOD(createAttributeNS),
+  Document_METHOD(createTextNode),
+  Document_METHOD(createProcessingInstruction),
+  Document_METHOD(createComment),
+  Document_METHOD(importNode),
+  Document_METHOD(getElementById),
   { NULL }
 };
 
-
 /** Python Members ****************************************************/
 
-
 #define Document_MEMBER(name, member) \
-  { name, T_OBJECT, offsetof(PyDocumentObject, member), RO }
+  { name, T_OBJECT, offsetof(DocumentObject, member), RO }
 
 static struct PyMemberDef document_members[] = {
   Document_MEMBER("unparsedEntities", unparsedEntities),
-  /* deprecated */
-  Document_MEMBER("refUri", documentURI),
-  Document_MEMBER("xmlBase", documentURI),
   { NULL }
 };
 
-
 /** Python Computed Members *******************************************/
 
-
-static PyObject *get_root_node(PyDocumentObject *self, void *arg)
+static PyObject *get_root_node(DocumentObject *self, void *arg)
 {
   Py_INCREF(self);
@@ -317,11 +275,10 @@
 }
 
-
-static PyObject *get_document_element(PyDocumentObject *self, void *arg)
+static PyObject *get_document_element(DocumentObject *self, void *arg)
 {
   int i;
   for (i = 0; i < ContainerNode_GET_COUNT(self); i++) {
-    PyNodeObject *child = ContainerNode_GET_CHILD(self, i);
-    if (PyElement_Check(child)) {
+    NodeObject *child = ContainerNode_GET_CHILD(self, i);
+    if (Element_Check(child)) {
       Py_INCREF(child);
       return (PyObject *) child;
@@ -332,6 +289,5 @@
 }
 
-
-static PyObject *get_document_uri(PyDocumentObject *self, void *arg)
+static PyObject *get_document_uri(DocumentObject *self, void *arg)
 {
   Py_INCREF(self->documentURI);
@@ -339,6 +295,5 @@
 }
 
-
-static int set_document_uri(PyDocumentObject *self, PyObject *v, void *arg)
+static int set_document_uri(DocumentObject *self, PyObject *v, void *arg)
 {
   if ((v = XmlString_ConvertArgument(v, "documentURI", 1)) == NULL)
@@ -349,6 +304,5 @@
 }
 
-
-static PyObject *get_public_id(PyDocumentObject *self, void *arg)
+static PyObject *get_public_id(DocumentObject *self, void *arg)
 {
   Py_INCREF(self->publicId);
@@ -356,6 +310,5 @@
 }
 
-
-static int set_public_id(PyDocumentObject *self, PyObject *v, void *arg)
+static int set_public_id(DocumentObject *self, PyObject *v, void *arg)
 {
   if ((v = XmlString_ConvertArgument(v, "publicId", 1)) == NULL)
@@ -366,6 +319,5 @@
 }
 
-
-static PyObject *get_system_id(PyDocumentObject *self, void *arg)
+static PyObject *get_system_id(DocumentObject *self, void *arg)
 {
   Py_INCREF(self->systemId);
@@ -373,6 +325,5 @@
 }
 
-
-static int set_system_id(PyDocumentObject *self, PyObject *v, void *arg)
+static int set_system_id(DocumentObject *self, PyObject *v, void *arg)
 {
   if ((v = XmlString_ConvertArgument(v, "systemId", 1)) == NULL)
@@ -383,5 +334,4 @@
 }
 
-
 static struct PyGetSetDef document_getset[] = {
   { "rootNode",        (getter)get_root_node },
@@ -393,12 +343,9 @@
 };
 
-
 /** Type Object ********************************************************/
 
-
-static void document_dealloc(PyDocumentObject *self)
+static void document_dealloc(DocumentObject *self)
 {
   PyObject_GC_UnTrack((PyObject *) self);
-
   Py_CLEAR(self->documentURI);
   Py_CLEAR(self->publicId);
@@ -406,31 +353,26 @@
   Py_CLEAR(self->unparsedEntities);
   Py_CLEAR(self->creationIndex);
-
   Node_Del(self);
 }
 
-
-static PyObject *document_repr(PyDocumentObject *document)
+static PyObject *document_repr(DocumentObject *self)
 {
-  return PyString_FromFormat("<Document at %p: %d children>", document,
-                             ContainerNode_GET_COUNT(document));
+  return PyString_FromFormat("<Document at %p: "
+                             "%" PY_FORMAT_SIZE_T "d children>",
+                             self, ContainerNode_GET_COUNT(self));
 }
 
-
-static int document_traverse(PyDocumentObject *self, visitproc visit,
-                             void *arg)
+static int document_traverse(DocumentObject *self, visitproc visit, void *arg)
 {
   Py_VISIT(self->unparsedEntities);
-  return DomletteNode_Type.tp_traverse((PyObject *) self, visit, arg);
+  return DomletteNode_Type.tp_traverse((PyObject *)self, visit, arg);
 }
 
-
-static int document_clear(PyObject *self)
+static int document_clear(DocumentObject *self)
 {
-  Py_CLEAR(((PyDocumentObject *)self)->unparsedEntities);
-  return DomletteNode_Type.tp_clear(self);
+  Py_CLEAR(self->unparsedEntities);
+  return DomletteNode_Type.tp_clear((PyObject *)self);
 }
 
-
 static PyObject *document_new(PyTypeObject *type, PyObject *args,
                               PyObject *kwds)
@@ -438,5 +380,5 @@
   PyObject *documentURI = Py_None;
   static char *kwlist[] = { "documentURI", NULL };
-  PyDocumentObject *self;
+  DocumentObject *self;
 
   if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:Document", kwlist,
@@ -451,7 +393,7 @@
 
   if (type != &DomletteDocument_Type) {
-    self = (PyDocumentObject *) type->tp_alloc(type, 0);
+    self = Document(type->tp_alloc(type, 0));
     if (self != NULL) {
-      _Node_INIT_CONTAINER(self, (PyDocumentObject *) Py_None);
+      _Node_INIT_CONTAINER(self);
       if (document_init(self, documentURI) < 0) {
         Py_DECREF(self);
@@ -468,5 +410,4 @@
 }
 
-
 static char document_doc[] = "\
 Document([documentURI]) -> Document object\n\
@@ -476,10 +417,9 @@
 document's data.";
 
-
 PyTypeObject DomletteDocument_Type = {
   /* PyObject_HEAD     */ PyObject_HEAD_INIT(NULL)
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "Document",
-  /* tp_basicsize      */ sizeof(PyDocumentObject),
+  /* tp_basicsize      */ sizeof(DocumentObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) document_dealloc,
@@ -503,5 +443,5 @@
   /* tp_doc            */ (char *) document_doc,
   /* tp_traverse       */ (traverseproc) document_traverse,
-  /* tp_clear          */ document_clear,
+  /* tp_clear          */ (inquiry) document_clear,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -522,8 +462,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteDocument_Init(PyObject *module)
 {
@@ -543,5 +481,5 @@
   Py_DECREF(value);
 
-  value = PyUnicode_DecodeASCII("#document", (Py_ssize_t)9, NULL);
+  value = XmlString_FromASCII("#document");
   if (value == NULL)
     return -1;
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/document.h.diff?r1=1.17&r2=1.18
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/document.h?rev=1.18&content-type=text/vnd.viewcvs-markup

Index: document.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/document.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -U2 -r1.17 -r1.18
--- document.h	24 Nov 2006 21:36:39 -0000	1.17
+++ document.h	21 Dec 2006 06:13:36 -0000	1.18
@@ -9,6 +9,6 @@
 #include "node.h"
 
-  typedef struct PyDocumentObject {
-    PyContainerNode_HEAD
+  typedef struct {
+    ContainerNode_HEAD
     PyObject *documentURI;
     PyObject *publicId;
@@ -16,10 +16,11 @@
     PyObject *unparsedEntities;
     PyObject *creationIndex;
-  } PyDocumentObject;
+  } DocumentObject;
 
-#define PyDocument_BASE_URI(op) (((PyDocumentObject *)(op))->documentURI)
-#define PyDocument_PUBLIC_ID(op) (((PyDocumentObject *)(op))->publicId)
-#define PyDocument_SYSTEM_ID(op) (((PyDocumentObject *)(op))->systemId)
-#define PyDocument_INDEX(op) (((PyDocumentObject *)(op))->creationIndex)
+#define Document(op) ((DocumentObject *)(op))
+#define Document_GET_DOCUMENT_URI(op) (Document(op)->documentURI)
+#define Document_GET_PUBLIC_ID(op) (Document(op)->publicId)
+#define Document_GET_SYSTEM_ID(op) (Document(op)->systemId)
+#define Document_GET_INDEX(op) (Document(op)->creationIndex)
 
 #ifdef Domlette_BUILDING_MODULE
@@ -27,6 +28,6 @@
   extern PyTypeObject DomletteDocument_Type;
 
-#define PyDocument_Check(op) PyObject_TypeCheck((op), &DomletteDocument_Type)
-#define PyDocument_CheckExact(op) ((op)->ob_type == &DomletteDocument_Type)
+#define Document_Check(op) PyObject_TypeCheck((op), &DomletteDocument_Type)
+#define Document_CheckExact(op) ((op)->ob_type == &DomletteDocument_Type)
 
   /* Module Methods */
@@ -35,5 +36,5 @@
 
   /* Document Methods */
-  PyDocumentObject *Document_New(PyObject *documentURI);
+  DocumentObject *Document_New(PyObject *documentURI);
 
 #endif /* Domlette_BUILDING_MODULE */
--- documentfragment.c DELETED ---
--- documentfragment.h DELETED ---
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domimplementation.c.diff?r1=1.41&r2=1.42
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domimplementation.c?rev=1.42&content-type=text/vnd.viewcvs-markup

Index: domimplementation.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/domimplementation.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -U2 -r1.41 -r1.42
--- domimplementation.c	24 Nov 2006 21:36:39 -0000	1.41
+++ domimplementation.c	21 Dec 2006 06:13:36 -0000	1.42
@@ -3,17 +3,12 @@
 /** Private Routines **************************************************/
 
-
 PyObject *g_implementation;
 
-
 /** Public C API ******************************************************/
 
-
-/* No C API defined */
-
+/* nothing to see here */
 
 /** Python Methods ****************************************************/
 
-
 static char domimp_hasFeature_doc[] = "\
 Test if the DOM implementation implements a specific feature.";
@@ -41,5 +36,4 @@
 }
 
-
 static char domimp_createDocument_doc[] = "\
 Creates a Document object of the specified type with its document element.";
@@ -47,9 +41,9 @@
 static PyObject *domimp_createDocument(PyObject *self, PyObject *args)
 {
-  PyObject *namespaceURI, *doctype, *qualifiedName, *documentURI = Py_None;
-  PyDocumentObject *doc;
+  PyObject *namespaceURI, *doctype, *qualifiedName, *documentURI=Py_None;
+  DocumentObject *doc;
 
-  if(!PyArg_ParseTuple(args,"OOO|O:createDocument",
-                       &namespaceURI, &qualifiedName, &doctype, &documentURI))
+  if (!PyArg_ParseTuple(args,"OOO|O:createDocument",
+                        &namespaceURI, &qualifiedName, &doctype, &documentURI))
     return NULL;
 
@@ -60,5 +54,5 @@
  - else:
     - if the namespace arg is a non-empty Unicode string, OK
-    - else if the namespace arg is EMPTY_NAMESPACE, OK
+    - else if the namespace arg is EMPTY_NAMESPACE (None), OK
     - else complain
    */
@@ -90,39 +84,31 @@
 
   doc = Document_New(documentURI);
+  if (doc == NULL) goto except;
 
   /* See if we need to add a documentElement */
   if (qualifiedName != Py_None) {
-    PyObject *prefix, *localName;
-    PyElementObject *elem;
-
-    if (!XmlString_SplitQName(qualifiedName, &prefix, &localName)) {
-      Py_DECREF(namespaceURI);
-      Py_DECREF(qualifiedName);
-      Py_DECREF(doc);
-      return NULL;
-    }
-    Py_DECREF(prefix);
-
-    elem = Element_New(doc, namespaceURI, qualifiedName, localName);
-
-    Py_DECREF(localName);
-
-    if (elem == NULL) {
-      Py_DECREF(doc);
-      doc = NULL;
-    }
-    else {
-      Node_AppendChild((PyNodeObject *)doc, (PyNodeObject *)elem);
+    PyObject *elem = PyObject_CallFunction((PyObject *)&DomletteElement_Type,
+                                           "OO", namespaceURI, qualifiedName);
+    if (elem == NULL) goto except;
+    if (Node_AppendChild((NodeObject *)doc, (NodeObject *)elem) < 0) {
       Py_DECREF(elem);
+      goto except;
     }
+    Py_DECREF(elem);
   }
 
+ finally:
   Py_DECREF(namespaceURI);
   Py_DECREF(qualifiedName);
   Py_DECREF(documentURI);
-
   return (PyObject *)doc;
-}
 
+ except:
+  if (doc != NULL) {
+    Py_DECREF(doc);
+    doc = NULL;
+  }
+  goto finally;
+}
 
 static char domimp_createRootNode_doc[] = "\
@@ -134,45 +120,41 @@
 }
 
-
-#define domimp_method(NAME) \
-  { #NAME, domimp_##NAME, METH_VARARGS, domimp_##NAME##_doc }
+#define DOMImplementation_METHOD(name) \
+  { #name, (PyCFunction) domimp_##name, METH_VARARGS, domimp_##name##_doc }
 
 static struct PyMethodDef domimp_methods[] = {
-  domimp_method(hasFeature),
-  domimp_method(createDocument),
-  domimp_method(createRootNode),
+  DOMImplementation_METHOD(hasFeature),
+  DOMImplementation_METHOD(createDocument),
+  DOMImplementation_METHOD(createRootNode),
   { NULL }
 };
 
-#undef domimp_method
-
-
 /** Python Members ****************************************************/
 
+#define DOMImplementation_MEMBER(name, member) \
+  { #name, T_OBJECT, offsetof(DOMImplementationObject, member), RO }
 
-/* No additional interface members defined */
-
+static PyMethodDef domimp_members[] = {
+  { NULL }
+};
 
 /** Python Computed Members *******************************************/
 
-
-/* No additional interface members defined */
-
+static PyGetSetDef domimp_getset[] = {
+  { NULL }
+};
 
 /** Type Object *******************************************************/
 
-
-static void domimp_dealloc(PyDOMImplementationObject *self)
+static void domimp_dealloc(DOMImplementationObject *self)
 {
   PyObject_Del(self);
 }
 
-
-static PyObject *domimp_repr(PyDOMImplementationObject *domimp)
+static PyObject *domimp_repr(DOMImplementationObject *self)
 {
-  return PyString_FromFormat("<DOMImplementation at %p>", domimp);
+  return PyString_FromFormat("<DOMImplementation at %p>", self);
 }
 
-
 static char domimp_doc[] =
 "The DOMImplementation interface provides a number of methods for performing\n\
@@ -184,5 +166,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "DOMImplementation",
-  /* tp_basicsize      */ sizeof(PyDOMImplementationObject),
+  /* tp_basicsize      */ sizeof(DOMImplementationObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) domimp_dealloc,
@@ -204,5 +186,5 @@
   /* tp_doc            */ (char *) domimp_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -210,6 +192,6 @@
   /* tp_iternext       */ (iternextfunc) 0,
   /* tp_methods        */ (PyMethodDef *) domimp_methods,
-  /* tp_members        */ (PyMemberDef *) 0,
-  /* tp_getset         */ (PyGetSetDef *) 0,
+  /* tp_members        */ (PyMemberDef *) domimp_members,
+  /* tp_getset         */ (PyGetSetDef *) domimp_getset,
   /* tp_base           */ (PyTypeObject *) 0,
   /* tp_dict           */ (PyObject *) 0,
@@ -223,8 +205,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteDOMImplementation_Init(PyObject *module)
 {
@@ -233,5 +213,5 @@
     return -1;
 
-  g_implementation = (PyObject *)PyObject_New(PyDOMImplementationObject,
+  g_implementation = (PyObject *)PyObject_New(DOMImplementationObject,
                                               &DomletteDOMImplementation_Type);
   if (g_implementation == NULL) return -1;
@@ -247,5 +227,4 @@
 }
 
-
 void DomletteDOMImplementation_Fini(void)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domimplementation.h.diff?r1=1.5&r2=1.6
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domimplementation.h?rev=1.6&content-type=text/vnd.viewcvs-markup

Index: domimplementation.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/domimplementation.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -U2 -r1.5 -r1.6
--- domimplementation.h	19 Mar 2005 00:48:01 -0000	1.5
+++ domimplementation.h	21 Dec 2006 06:13:36 -0000	1.6
@@ -10,9 +10,14 @@
   typedef struct {
     PyObject_HEAD
-  } PyDOMImplementationObject;
+  } DOMImplementationObject;
+
+#ifdef Domlette_BUILDING_MODULE
+
+  extern PyObject *g_implementation;
 
   extern PyTypeObject DomletteDOMImplementation_Type;
 
-#define PyDOMImplementation_Check(op) ((op)->ob_type == &DomletteDOMImplementation_Type)
+#define DOMImplementation_Check(op) \
+  ((op)->ob_type == &DomletteDOMImplementation_Type)
 
   /* Module Methods */
@@ -20,5 +25,5 @@
   void DomletteDOMImplementation_Fini(void);
 
-  extern PyObject *g_implementation;
+#endif /* Domlette_BUILDING_MODULE */
 
 #ifdef __cplusplus
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domlette.c.diff?r1=1.58&r2=1.59
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domlette.c?rev=1.59&content-type=text/vnd.viewcvs-markup

Index: domlette.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/domlette.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -U2 -r1.58 -r1.59
--- domlette.c	24 Nov 2006 21:36:39 -0000	1.58
+++ domlette.c	21 Dec 2006 06:13:36 -0000	1.59
@@ -31,13 +31,16 @@
 */
 
-#define UNICODE_FROM_CHAR(str) PyUnicode_DecodeASCII((str), (Py_ssize_t)strlen(str), NULL);
-
-#define CHECK_DOCUMENT_REFS(num, where) if (doc->ob_refcnt != (num)) {  \
-    PyErr_Format(PyExc_MemoryError,                                     \
-                 "%s expected %d refcount"          \
-                 " found %" PY_FORMAT_SIZE_T "d",                       \
-                 (where), (num), doc->ob_refcnt);                       \
-    return NULL;                                                        \
-}
+#define CHECK_REFS(op, refs) do {                         \
+  Py_ssize_t expected = (Py_ssize_t)(refs);               \
+  Py_ssize_t compared = (op)->ob_refcnt;                  \
+  if (expected != compared) {                             \
+    PyErr_Format(PyExc_MemoryError,                       \
+                 "%s:%d: refcount mismatch: "             \
+                 "expected %" PY_FORMAT_SIZE_T "d "       \
+                 "compared %" PY_FORMAT_SIZE_T "d",       \
+                 __FILE__, __LINE__, expected, compared); \
+    return NULL;                                          \
+  }                                                       \
+} while (0)
 
 /* The test tree XML:
@@ -55,10 +58,10 @@
 {
   /*Build a test tree*/
-  PyDocumentObject *doc;
-  PyProcessingInstructionObject *pi;
-  PyElementObject *documentElement, *element;
-  PyTextObject *text;
-  PyCommentObject *comment;
-  PyAttrObject *attr;
+  DocumentObject *doc;
+  ProcessingInstructionObject *pi;
+  ElementObject *documentElement, *element;
+  TextObject *text;
+  CommentObject *comment;
+  AttrObject *attr;
   PyObject *namespaceURI, *qualifiedName, *localName;
   PyObject *target, *data, *value;
@@ -67,181 +70,408 @@
 
   doc = Document_New(Py_None);
-  CHECK_DOCUMENT_REFS(1, "Doc Creation");
+  if (doc == NULL) return NULL;
+  CHECK_REFS(doc, 1);
 
   /* Add processing instruction */
-  target = UNICODE_FROM_CHAR("xml-stylesheet");
-  data = UNICODE_FROM_CHAR("href=\"addr_book1.xsl\" type=\"text/xml\"");
-  pi = ProcessingInstruction_New(doc, target, data);
-  Py_DECREF(data);
+  target = XmlString_FromASCII("xml-stylesheet");
+  data = XmlString_FromASCII("href=\"addr_book1.xsl\" type=\"text/xml\"");
+  if (target == NULL || data == NULL) {
+    Py_XDECREF(target);
+    Py_XDECREF(data);
+    Py_DECREF(doc);
+    return NULL;
+  }
+  pi = ProcessingInstruction_New(target, data);
   Py_DECREF(target);
-  if (Node_AppendChild((PyNodeObject *)doc, (PyNodeObject *)pi) < 0)
+  Py_DECREF(data);
+  if (pi == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)doc, (NodeObject *)pi) < 0) {
+    Py_DECREF(pi);
+    Py_DECREF(doc);
     return NULL;
-  /*We are all done with pi, so DECREF it once*/
+  }
   Py_DECREF(pi);
 
-  CHECK_DOCUMENT_REFS(2, "PI Creation");
+  CHECK_REFS(doc, 2);
+  CHECK_REFS(pi, 1);
 
   /* Add documentElement */
   namespaceURI = Py_None;
-  qualifiedName = UNICODE_FROM_CHAR("docelem");
-  localName = qualifiedName;
-  documentElement = Element_New(doc, namespaceURI, qualifiedName, localName);
+  qualifiedName = localName = XmlString_FromASCII("docelem");
+  if (qualifiedName == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  documentElement = Element_New(namespaceURI, qualifiedName, localName);
   Py_DECREF(qualifiedName);
-  Node_AppendChild((PyNodeObject *)doc, (PyNodeObject *)documentElement);
+  if (documentElement == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)doc, (NodeObject *)documentElement) < 0) {
+    Py_DECREF(documentElement);
+    Py_DECREF(doc);
+    return NULL;
+  }
+  Py_DECREF(documentElement);
 
-  CHECK_DOCUMENT_REFS(3,"Doc Elem Creation");
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 1);
 
   /* Add documentElement namespace declartion */
   namespaceURI = g_xmlnsNamespace;
-  qualifiedName = UNICODE_FROM_CHAR("xmlns:ft");
-  localName = UNICODE_FROM_CHAR("ft");
-  value = UNICODE_FROM_CHAR("http://fourthought.com");
+  qualifiedName = XmlString_FromASCII("xmlns:ft");
+  localName = XmlString_FromASCII("ft");
+  value = XmlString_FromASCII("http://fourthought.com");
+  if (qualifiedName == NULL || localName == NULL || value == NULL) {
+    Py_XDECREF(qualifiedName);
+    Py_XDECREF(localName);
+    Py_XDECREF(value);
+    Py_DECREF(doc);
+    return NULL;
+  }
   attr = Element_SetAttributeNS(documentElement, namespaceURI, qualifiedName,
                                 localName, value);
-  Py_DECREF(attr);
-  Py_DECREF(value);
-  Py_DECREF(localName);
   Py_DECREF(qualifiedName);
+  Py_DECREF(localName);
+  Py_DECREF(value);
+  if (attr == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  Py_DECREF(attr);
 
-  CHECK_DOCUMENT_REFS(4,"NS DECL");
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 2);
+  CHECK_REFS(attr, 1);
 
   /* Add text 1 to documentElement */
-  data = UNICODE_FROM_CHAR("\n  ");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("\n  ");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(5,"1st Text");
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 3);
+  CHECK_REFS(text, 1);
 
   /* Add element 1 to documentElement */
   namespaceURI = Py_None;
-  qualifiedName = UNICODE_FROM_CHAR("child");
-  localName = qualifiedName;
-  element = Element_New(doc, namespaceURI, qualifiedName, localName);
+  qualifiedName = localName = XmlString_FromASCII("child");
+  if (qualifiedName == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  element = Element_New(namespaceURI, qualifiedName, localName);
   Py_DECREF(qualifiedName);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)element);
-  CHECK_DOCUMENT_REFS(6,"First Child");
+  if (element == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)element) < 0) {
+    Py_DECREF(element);
+    Py_DECREF(doc);
+    return NULL;
+  }
+  Py_DECREF(element);
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 4);
+  CHECK_REFS(element, 1);
 
   /* Add element 1 attribute */
   namespaceURI = Py_None;
-  qualifiedName = UNICODE_FROM_CHAR("foo");
-  localName = qualifiedName;
-  value = UNICODE_FROM_CHAR("bar");
+  qualifiedName = localName = XmlString_FromASCII("foo");
+  value = XmlString_FromASCII("bar");
+  if (qualifiedName == NULL || value == NULL) {
+    Py_XDECREF(qualifiedName);
+    Py_XDECREF(value);
+    Py_DECREF(doc);
+    return NULL;
+  }
   attr = Element_SetAttributeNS(element, namespaceURI, qualifiedName,
                                 localName, value);
-  Py_DECREF(attr);
   Py_DECREF(qualifiedName);
   Py_DECREF(value);
-  CHECK_DOCUMENT_REFS(7,"First Child Attr");
+  if (attr == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  Py_DECREF(attr);
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(element, 2);
+  CHECK_REFS(attr, 1);
 
   /* Add element 1 text */
-  data = UNICODE_FROM_CHAR("Some Text");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("Some Text");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)element, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)element, (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(8,"First Child Text");
 
-  /*We are all done with element 1, so DECREF it once*/
-  Py_DECREF(element);
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(element, 3);
+  CHECK_REFS(text, 1);
 
   /* Add text 2 to documentElement */
-  data = UNICODE_FROM_CHAR("\n  ");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("\n  ");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(9,"2nd Text");
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 5);
+  CHECK_REFS(text, 1);
 
   /* Add comment to documentElement */
-  data = UNICODE_FROM_CHAR("A comment");
-  comment = Comment_New(doc, data);
+  data = XmlString_FromASCII("A comment");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  comment = Comment_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)comment);
-  /*We are all done with comment so DECREF it once*/
+  if (comment == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)comment) < 0) {
+    Py_DECREF(comment);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(comment);
-  CHECK_DOCUMENT_REFS(10,"Comment");
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 6);
+  CHECK_REFS(comment, 1);
 
   /* Add text 3 to documentElement */
-  data = UNICODE_FROM_CHAR("\n  ");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("\n  ");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(11,"3rd Text");
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 7);
+  CHECK_REFS(text, 1);
 
   /* Add element 2 to documentElement */
-  namespaceURI = UNICODE_FROM_CHAR("http://fourthought.com");
-  qualifiedName = UNICODE_FROM_CHAR("ft:nschild");
-  localName = UNICODE_FROM_CHAR("nschild");
-  element = Element_New(doc, namespaceURI, qualifiedName, localName);
+  namespaceURI = XmlString_FromASCII("http://fourthought.com");
+  qualifiedName = XmlString_FromASCII("ft:nschild");
+  localName = XmlString_FromASCII("nschild");
+  if (namespaceURI == NULL || qualifiedName == NULL || localName == NULL) {
+    Py_XDECREF(namespaceURI);
+    Py_XDECREF(qualifiedName);
+    Py_XDECREF(localName);
+    Py_DECREF(doc);
+    return NULL;
+  }
+  element = Element_New(namespaceURI, qualifiedName, localName);
   Py_DECREF(localName);
   Py_DECREF(qualifiedName);
   Py_DECREF(namespaceURI);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)element);
-  CHECK_DOCUMENT_REFS(12,"2nd Child");
+  if (element == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)element) < 0) {
+    Py_DECREF(element);
+    Py_DECREF(doc);
+    return NULL;
+  }
+  Py_DECREF(element);
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 8);
+  CHECK_REFS(element, 1);
 
   /* Add element 2 attribute */
-  namespaceURI = UNICODE_FROM_CHAR("http://fourthought.com");
-  qualifiedName = UNICODE_FROM_CHAR("ft:foo");
-  localName = UNICODE_FROM_CHAR("foo");
-  value = UNICODE_FROM_CHAR("nsbar");
+  namespaceURI = XmlString_FromASCII("http://fourthought.com");
+  qualifiedName = XmlString_FromASCII("ft:foo");
+  localName = XmlString_FromASCII("foo");
+  value = XmlString_FromASCII("nsbar");
+  if (namespaceURI == NULL || qualifiedName == NULL || localName == NULL ||
+      value == NULL) {
+    Py_XDECREF(namespaceURI);
+    Py_XDECREF(qualifiedName);
+    Py_XDECREF(localName);
+    Py_XDECREF(value);
+    Py_DECREF(doc);
+    return NULL;
+  }
   attr = Element_SetAttributeNS(element, namespaceURI, qualifiedName,
                                 localName, value);
-  Py_DECREF(attr);
   Py_DECREF(value);
   Py_DECREF(localName);
   Py_DECREF(qualifiedName);
   Py_DECREF(namespaceURI);
-  CHECK_DOCUMENT_REFS(13,"2nd Child Attr");
+  if (attr == NULL) {
+    Py_DECREF(element);
+    Py_DECREF(doc);
+    return NULL;
+  }
+  Py_DECREF(attr);
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(element, 2);
+  CHECK_REFS(attr, 1);
 
   /* Add element 2 text node */
-  data = UNICODE_FROM_CHAR("Some More Text");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("Some More Text");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)element, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)element, (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(14,"2nd Child Text");
 
-  /*We are all done with element 2, so DECREF it once*/
-  Py_DECREF(element);
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(element, 3);
+  CHECK_REFS(text, 1);
 
   /* Add text 4 to documentElement */
-  data = UNICODE_FROM_CHAR("\n  ");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("\n  ");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(15,"4th Text");
+
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 9);
+  CHECK_REFS(text, 1);
 
   /* Add element 3 to documentElement */
   namespaceURI = Py_None;
-  qualifiedName = UNICODE_FROM_CHAR("appendChild");
-  localName = qualifiedName;
-  element = Element_New(doc, namespaceURI, qualifiedName, localName);
+  qualifiedName = localName = XmlString_FromASCII("appendChild");
+  if (qualifiedName == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  element = Element_New(namespaceURI, qualifiedName, localName);
   Py_DECREF(qualifiedName);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)element);
-  CHECK_DOCUMENT_REFS(16,"Append Child");
-
-  /* We are all done with element 3, so DECREF it once*/
+  if (element == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)element) < 0) {
+    Py_DECREF(element);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(element);
 
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 10);
+  CHECK_REFS(element, 1);
+
   /* Add text 5 to documentElement */
-  data = UNICODE_FROM_CHAR("\n  ");
-  text = Text_New(doc, data);
+  data = XmlString_FromASCII("\n  ");
+  if (data == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  text = Text_New(data);
   Py_DECREF(data);
-  Node_AppendChild((PyNodeObject *)documentElement, (PyNodeObject *)text);
-  /*We are all done with text, so DECREF it once*/
+  if (text == NULL) {
+    Py_DECREF(doc);
+    return NULL;
+  }
+  if (Node_AppendChild((NodeObject *)documentElement,
+                       (NodeObject *)text) < 0) {
+    Py_DECREF(text);
+    Py_DECREF(doc);
+    return NULL;
+  }
   Py_DECREF(text);
-  CHECK_DOCUMENT_REFS(17,"5th Text");
 
-  /* We are all done with documentElement, so DECREF it once */
-  Py_DECREF(documentElement);
+  CHECK_REFS(doc, 3);
+  CHECK_REFS(documentElement, 11);
+  CHECK_REFS(text, 1);
 
   return (PyObject *)doc;
@@ -257,11 +487,11 @@
 static PyMethodDef cDomlettecMethods[] = {
   /* from reader.c */
-  Domlette_METHOD(NonvalParse, METH_VARARGS | METH_KEYWORDS),
-  Domlette_METHOD(ValParse, METH_VARARGS | METH_KEYWORDS),
-  Domlette_METHOD(Parse, METH_VARARGS | METH_KEYWORDS),
-  Domlette_METHOD(ParseFragment, METH_VARARGS | METH_KEYWORDS),
+  Domlette_METHOD(NonvalParse, METH_KEYWORDS),
+  Domlette_METHOD(ValParse, METH_KEYWORDS),
+  Domlette_METHOD(Parse, METH_KEYWORDS),
+  Domlette_METHOD(ParseFragment, METH_KEYWORDS),
 
   /* from xmlparser.c */
-  Domlette_METHOD(CreateParser, METH_VARARGS | METH_KEYWORDS),
+  Domlette_METHOD(CreateParser, METH_KEYWORDS),
 
   /* from nss.c */
@@ -270,5 +500,5 @@
 
   /* defined here (regression tests) */
-  { "TestTree",          PyTestTree,         METH_VARARGS,
+  { "TestTree", PyTestTree, METH_VARARGS,
     "TestTree() -> Document\n\nFor regression testing." },
 
@@ -285,5 +515,4 @@
   &DomletteComment_Type,
   &DomletteProcessingInstruction_Type,
-  &DomletteDocumentFragment_Type,
   &DomletteXPathNamespace_Type,
 
@@ -291,4 +520,5 @@
   Node_AppendChild,
   Node_InsertBefore,
+  Node_ReplaceChild,
 
   Document_New,
@@ -327,5 +557,4 @@
   DomletteComment_Fini();
   DomletteDocument_Fini();
-  DomletteDocumentFragment_Fini();
   DomletteXPathNamespace_Fini();
 
@@ -382,5 +611,4 @@
   if (DomletteComment_Init(module) == -1) return;
   if (DomletteDocument_Init(module) == -1) return;
-  if (DomletteDocumentFragment_Init(module) == -1) return;
   if (DomletteXPathNamespace_Init(module) == -1) return;
 
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domlette.h.diff?r1=1.17&r2=1.18
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domlette.h?rev=1.18&content-type=text/vnd.viewcvs-markup

Index: domlette.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/domlette.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -U2 -r1.17 -r1.18
--- domlette.h	24 Nov 2006 21:36:39 -0000	1.17
+++ domlette.h	21 Dec 2006 06:13:36 -0000	1.18
@@ -25,5 +25,4 @@
 #include "element.h"
 #include "attr.h"
-#include "documentfragment.h"
 #include "domimplementation.h"
 #include "text.h"
@@ -37,13 +36,4 @@
   extern PyObject *g_xincludeNamespace;
 
-
-#define PyNode_Children_Check(op) (PyDocument_Check(op) ||              \
-                                   PyElement_Check(op) ||               \
-                                   PyDocumentFragment_Check(op))
-
-#define PyNode_Childless_Check(op) (PyText_Check(op) ||                 \
-                                    PyProcessingInstruction_Check(op) || \
-                                    PyComment_Check(op))
-
 #define DOMLETTE_PACKAGE  "Ft.Xml.cDomlette."
 
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domlette_interface.h.diff?r1=1.3&r2=1.4
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/domlette_interface.h?rev=1.4&content-type=text/vnd.viewcvs-markup

Index: domlette_interface.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/domlette_interface.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -U2 -r1.3 -r1.4
--- domlette_interface.h	24 Nov 2006 21:36:39 -0000	1.3
+++ domlette_interface.h	21 Dec 2006 06:13:36 -0000	1.4
@@ -37,48 +37,50 @@
     PyTypeObject *Comment_Type;
     PyTypeObject *ProcessingInstruction_Type;
-    PyTypeObject *DocumentFragment_Type;
     PyTypeObject *XPathNamespace_Type;
 
     /* Node Methods */
-    int (*Node_RemoveChild)(PyNodeObject *parent, PyNodeObject *oldChild);
-    int (*Node_AppendChild)(PyNodeObject *parent, PyNodeObject *newChild);
-    int (*Node_InsertBefore)(PyNodeObject *parent, PyNodeObject *newChild,
-                             PyNodeObject *refChild);
+    int (*Node_RemoveChild)(NodeObject *parent, NodeObject *oldChild);
+    int (*Node_AppendChild)(NodeObject *parent, NodeObject *newChild);
+    int (*Node_InsertBefore)(NodeObject *parent, NodeObject *newChild,
+                             NodeObject *refChild);
+    int (*Node_ReplaceChild)(NodeObject *parent, NodeObject *newChild,
+                             NodeObject *oldChild);
 
     /* Document Methods */
-    PyDocumentObject *(*Document_New)(PyObject *documentURI);
+    DocumentObject *(*Document_New)(PyObject *documentURI);
 
     /* Element Methods */
-    PyElementObject *(*Element_New)(PyDocumentObject *document,
-                                    PyObject *namespaceURI,
-                                    PyObject *qualifiedName,
-                                    PyObject *localName);
-    PyAttrObject *(*Element_SetAttributeNS)(PyElementObject *element,
-                                            PyObject *namespaceURI,
-                                            PyObject *qualifiedName,
-                                            PyObject *localName,
-                                            PyObject *value);
+    ElementObject *(*Element_New)(PyObject *namespaceURI,
+                                  PyObject *qualifiedName,
+                                  PyObject *localName);
+    AttrObject *(*Element_SetAttributeNS)(ElementObject *element,
+                                          PyObject *namespaceURI,
+                                          PyObject *qualifiedName,
+                                          PyObject *localName,
+                                          PyObject *value);
 
     /* CharacterData Methods */
-    PyObject *(*CharacterData_SubstringData)(PyCharacterDataObject *node,
-                                             int offset, int count);
-    int (*CharacterData_AppendData)(PyCharacterDataObject *node,
+    PyObject *(*CharacterData_SubstringData)(CharacterDataObject *node,
+                                             Py_ssize_t offset,
+                                             Py_ssize_t count);
+    int (*CharacterData_AppendData)(CharacterDataObject *node,
                                     PyObject *data);
-    int (*CharacterData_InsertData)(PyCharacterDataObject *node,
-                                    int offset, PyObject *data);
-    int (*CharacterData_DeleteData)(PyCharacterDataObject *node,
-                                    int offset, int count);
-    int (*CharacterData_ReplaceData)(PyCharacterDataObject *node,
-                                     int offset, int count, PyObject *data);
+    int (*CharacterData_InsertData)(CharacterDataObject *node,
+                                    Py_ssize_t offset, PyObject *data);
+    int (*CharacterData_DeleteData)(CharacterDataObject *node,
+                                    Py_ssize_t offset, Py_ssize_t count);
+    int (*CharacterData_ReplaceData)(CharacterDataObject *node,
+                                     Py_ssize_t offset, Py_ssize_t count,
+                                     PyObject *data);
 
     /* Text Methods */
-    PyTextObject *(*Text_New)(PyDocumentObject *document, PyObject *data);
+    TextObject *(*Text_New)(PyObject *data);
 
     /* Comment Methods */
-    PyCommentObject *(*Comment_New)(PyDocumentObject *document, PyObject *data);
+    CommentObject *(*Comment_New)(PyObject *data);
 
     /* ProcessingInstruction Methods */
-    PyProcessingInstructionObject *(*ProcessingInstruction_New)(
-      PyDocumentObject *document, PyObject *target, PyObject *data);
+    ProcessingInstructionObject *(*ProcessingInstruction_New)(PyObject *target,
+                                                              PyObject *data);
 
   } Domlette_APIObject;
@@ -98,4 +100,5 @@
 #define Node_AppendChild Domlette->Node_AppendChild
 #define Node_InsertBefore Domlette->Node_InsertBefore
+#define Node_ReplaceChild Domlette->Node_ReplaceChild
 
 #define Document_Check(op) PyObject_TypeCheck((op), Domlette->Document_Type)
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/element.c.diff?r1=1.46&r2=1.47
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/element.c?rev=1.47&content-type=text/vnd.viewcvs-markup

Index: element.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/element.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -U2 -r1.46 -r1.47
--- element.c	24 Nov 2006 21:36:39 -0000	1.46
+++ element.c	21 Dec 2006 06:13:36 -0000	1.47
@@ -2,14 +2,12 @@
 #include "nss.h"
 
-
 /** Private Routines **************************************************/
 
-
 #define Element_VerifyState(ob)                                     \
-  if (!PyElement_Check(ob) ||                                       \
-      ((PyElementObject *)(ob))->namespaceURI == NULL ||            \
-      ((PyElementObject *)(ob))->localName == NULL ||               \
-      ((PyElementObject *)(ob))->nodeName == NULL ||                \
-      ((PyElementObject *)(ob))->attributes == NULL) {              \
+  if (!Element_Check(ob) ||                                         \
+      Element_GET_NAMESPACE_URI(ob) == NULL ||                      \
+      Element_GET_LOCAL_NAME(ob) == NULL ||                         \
+      Element_GET_NODE_NAME(ob) == NULL ||                          \
+      Element_GET_ATTRIBUTES(ob) == NULL) {                         \
      DOMException_InvalidStateErr("Element in inconsistent state"); \
      return NULL;                                                   \
@@ -18,10 +16,10 @@
 static PyObject *shared_empty_attributes;
 
-static int element_init(PyElementObject *self,
+static int element_init(ElementObject *self,
                         PyObject *namespaceURI,
                         PyObject *qualifiedName,
                         PyObject *localName)
 {
-  if ((self == NULL || !PyElement_Check(self)) ||
+  if ((self == NULL || !Element_Check(self)) ||
       (namespaceURI == NULL || !XmlString_NullCheck(namespaceURI)) ||
       (qualifiedName == NULL || !XmlString_Check(qualifiedName)) ||
@@ -46,20 +44,20 @@
 }
 
-
-static PyObject *buildAttrKey(PyAttrObject *attr)
+static PyObject *buildAttrKey(AttrObject *attr)
 {
   PyObject *key;
   PyObject *local;
 
-  switch (PyObject_RichCompareBool(attr->namespaceURI, g_xmlnsNamespace, Py_EQ)) {
+  switch (PyObject_RichCompareBool(Attr_GET_NAMESPACE_URI(attr),
+                                   g_xmlnsNamespace, Py_EQ)) {
   case 0:
     /* normal attribute */
-    local = attr->localName;
+    local = Attr_GET_LOCAL_NAME(attr);
     break;
   case 1:
     /* namespace attribute */
-    if (PyUnicode_AS_UNICODE(attr->nodeName)[5] == ':') {
+    if (PyUnicode_AS_UNICODE(Attr_GET_NODE_NAME(attr))[5] == ':') {
       /* xmlns:prefix = 'namespaceURI' */
-      local = attr->localName;
+      local = Attr_GET_LOCAL_NAME(attr);
     }
     else {
@@ -73,8 +71,8 @@
   }
 
-  key = PyTuple_New((Py_ssize_t)2);
+  key = PyTuple_New(2);
 
-  Py_INCREF(attr->namespaceURI);
-  PyTuple_SET_ITEM(key, 0, attr->namespaceURI);
+  Py_INCREF(Attr_GET_NAMESPACE_URI(attr));
+  PyTuple_SET_ITEM(key, 0, Attr_GET_NAMESPACE_URI(attr));
 
   Py_INCREF(local);
@@ -84,17 +82,13 @@
 }
 
-
 /** Public C API ******************************************************/
 
-
-PyElementObject *Element_New(PyDocumentObject *ownerDocument,
-                             PyObject *namespaceURI,
-                             PyObject *qualifiedName,
-                             PyObject *localName)
+ElementObject *Element_New(PyObject *namespaceURI,
+                           PyObject *qualifiedName,
+                           PyObject *localName)
 {
-  PyElementObject *self;
+  ElementObject *self;
 
-  self = Node_NewContainer(PyElementObject, &DomletteElement_Type,
-                           ownerDocument);
+  self = Node_NewContainer(ElementObject, &DomletteElement_Type);
   if (self != NULL) {
     if (element_init(self, namespaceURI, qualifiedName, localName) < 0) {
@@ -109,44 +103,46 @@
 }
 
-
 /* returns a new reference */
-PyAttrObject *Element_SetAttributeNS(PyElementObject *self,
-				     PyObject *namespaceURI,
-                                     PyObject *qualifiedName,
-				     PyObject *localName,
-                                     PyObject *value)
+AttrObject *Element_SetAttributeNS(ElementObject *self,
+                                   PyObject *namespaceURI,
+                                   PyObject *qualifiedName,
+                                   PyObject *localName,
+                                   PyObject *value)
 {
-  PyObject *key;
-  register PyAttrObject *attr;
+  PyObject *attributes, *key;
+  AttrObject *attr;
 
   Element_VerifyState(self);
 
-  if (self->attributes == shared_empty_attributes) {
-    PyObject *attrs = PyDict_New();
-    if (attrs == NULL) return NULL;
+  attributes = self->attributes;
+  if (attributes == shared_empty_attributes) {
+    attributes = PyDict_New();
+    if (attributes == NULL) return NULL;
     Py_DECREF(self->attributes);
-    self->attributes = attrs;
+    self->attributes = attributes;
   }
 
   /* new reference */
-  attr = Attr_New(self->ownerDocument, namespaceURI, qualifiedName, localName,
-                  value);
+  attr = Attr_New(namespaceURI, qualifiedName, localName, value);
   if (attr == NULL) return NULL;
-  Node_SET_PARENT(attr, (PyNodeObject *) self);
+  Py_INCREF(self);
+  assert(Node_GET_PARENT(attr) == NULL);
+  Node_SET_PARENT(attr, (NodeObject *) self);
 
   key = buildAttrKey(attr);
-  if (key) {
-    PyDict_SetItem(self->attributes, key, (PyObject *)attr);
+  if (key == NULL) {
+    Py_DECREF(attr);
+    return NULL;
+  }
+  if (PyDict_SetItem(attributes, key, (PyObject *)attr) < 0) {
     Py_DECREF(key);
-  } else {
     Py_DECREF(attr);
-    attr = NULL;
+    return NULL;
   }
-
   return attr;
 }
 
-
-PyObject *Element_GetAttributeNodeNS(PyElementObject *self,
+/* returns a borrowed reference */
+PyObject *Element_GetAttributeNodeNS(ElementObject *self,
                                      PyObject *namespaceURI,
                                      PyObject *localName)
@@ -161,7 +157,7 @@
   Py_INCREF(localName);
   /* steals reference */
-  key = PyTuple_New((Py_ssize_t)2);
-  PyTuple_SetItem(key, (Py_ssize_t)0, namespaceURI);
-  PyTuple_SetItem(key, (Py_ssize_t)1, localName);
+  key = PyTuple_New(2);
+  PyTuple_SetItem(key, 0, namespaceURI);
+  PyTuple_SetItem(key, 1, localName);
 
   attr = PyDict_GetItem(self->attributes, key);
@@ -171,8 +167,7 @@
 }
 
-PyElementObject *Element_CloneNode(PyObject *node, int deep,
-				   PyDocumentObject *newOwnerDocument)
+ElementObject *Element_CloneNode(PyObject *node, int deep)
 {
-  PyElementObject *element;
+  ElementObject *element;
   PyObject *namespaceURI, *localName, *qualifiedName;
   PyObject *attributes;
@@ -204,6 +199,5 @@
 
   /* We now have everything we need to create a shallow copy, do it */
-  element = Element_New(newOwnerDocument, namespaceURI, qualifiedName,
-                        localName);
+  element = Element_New(namespaceURI, qualifiedName, localName);
 
   /* Done with these */
@@ -220,10 +214,8 @@
   count = PySequence_Length(attributes);
   for (i = 0; i < count; i++) {
-    PyAttrObject *attr;
-    PyObject *value;
-    PyObject *old_attr;
+    PyObject *attr, *value;
 
-    old_attr = PySequence_GetItem(attributes, i);
-    if (old_attr == NULL) {
+    attr = PySequence_GetItem(attributes, i);
+    if (attr == NULL) {
       Py_DECREF(element);
       Py_DECREF(attributes);
@@ -231,13 +223,13 @@
     }
 
-    namespaceURI = PyObject_GetAttrString(old_attr, "namespaceURI");
+    namespaceURI = PyObject_GetAttrString(attr, "namespaceURI");
     namespaceURI = XmlString_FromObjectInPlace(namespaceURI);
-    qualifiedName = PyObject_GetAttrString(old_attr, "nodeName");
+    qualifiedName = PyObject_GetAttrString(attr, "nodeName");
     qualifiedName = XmlString_FromObjectInPlace(qualifiedName);
-    localName = PyObject_GetAttrString(old_attr, "localName");
+    localName = PyObject_GetAttrString(attr, "localName");
     localName = XmlString_FromObjectInPlace(localName);
-    value = PyObject_GetAttrString(old_attr, "value");
+    value = PyObject_GetAttrString(attr, "value");
     value = XmlString_FromObjectInPlace(value);
-    Py_DECREF(old_attr);
+    Py_DECREF(attr);
     if (namespaceURI == NULL || localName == NULL || qualifiedName == NULL ||
         value == NULL) {
@@ -251,6 +243,6 @@
     }
 
-    attr = Element_SetAttributeNS(element, namespaceURI, qualifiedName,
-                                  localName, value);
+    attr = (PyObject *)Element_SetAttributeNS(element, namespaceURI,
+                                              qualifiedName, localName, value);
     Py_DECREF(value);
     Py_DECREF(localName);
@@ -277,22 +269,27 @@
     for (i = 0; i < count; i++) {
       PyObject *child;
-      PyNodeObject *cloned_child;
+      NodeObject *cloned_child;
 
       child = PySequence_GetItem(childNodes, i);
       if (child == NULL) {
-		Py_DECREF(childNodes);
-		Py_DECREF(element);
-		return NULL;
+        Py_DECREF(childNodes);
+        Py_DECREF(element);
+        return NULL;
       }
 
-      cloned_child = Node_CloneNode(child, deep, newOwnerDocument);
+      cloned_child = Node_CloneNode(child, deep);
       Py_DECREF(child);
       if (cloned_child == NULL) {
-		Py_DECREF(childNodes);
-		Py_DECREF(element);
-		return NULL;
+        Py_DECREF(childNodes);
+        Py_DECREF(element);
+        return NULL;
       }
 
-      Node_AppendChild((PyNodeObject *)element, cloned_child);
+      if (Node_AppendChild((NodeObject *)element, cloned_child) < 0) {
+        Py_DECREF(cloned_child);
+        Py_DECREF(childNodes);
+        Py_DECREF(element);
+        return NULL;
+      }
       Py_DECREF(cloned_child);
     }
@@ -303,12 +300,11 @@
 }
 
-
 /** Python Methods ****************************************************/
 
-
 static char element_getAttributeNodeNS_doc[] =
 "Retrieves an Attr node by local name and namespace URI.";
 
-static PyObject *element_getAttributeNodeNS(PyObject *self, PyObject *args)
+static PyObject *element_getAttributeNodeNS(ElementObject *self,
+                                            PyObject *args)
 {
   PyObject *namespaceURI, *localName;
@@ -332,6 +328,5 @@
   }
 
-  attr = Element_GetAttributeNodeNS((PyElementObject *)self, namespaceURI, localName);
-
+  attr = Element_GetAttributeNodeNS(self, namespaceURI, localName);
   Py_DECREF(namespaceURI);
   Py_DECREF(localName);
@@ -341,9 +336,8 @@
 }
 
-
 static char element_getAttributeNS_doc[] =
 "Retrieves an attribute value by local name and namespace URI.";
 
-static PyObject *element_getAttributeNS(PyObject *self, PyObject *args)
+static PyObject *element_getAttributeNS(ElementObject *self, PyObject *args)
 {
   PyObject *namespaceURI, *localName;
@@ -366,6 +360,5 @@
   }
 
-  attr = Element_GetAttributeNodeNS((PyElementObject *)self, namespaceURI, localName);
-
+  attr = Element_GetAttributeNodeNS(self, namespaceURI, localName);
   Py_DECREF(namespaceURI);
   Py_DECREF(localName);
@@ -373,17 +366,16 @@
   if (attr == Py_None) {
     /* empty unicode string */
-    return PyUnicode_FromUnicode(NULL, (Py_ssize_t)0);
+    return PyUnicode_FromUnicode(NULL, 0);
   } else {
-    Py_INCREF(PyAttr_NODE_VALUE(attr));
-    return PyAttr_NODE_VALUE(attr);
+    Py_INCREF(Attr_GET_NODE_VALUE(attr));
+    return Attr_GET_NODE_VALUE(attr);
   }
 }
 
-
 static char element_hasAttributeNS_doc[] =
 "Returns True when an attribute with a given local name and namespace URI\n\
 is specified on this element or has a default value, False otherwise.";
 
-static PyObject *element_hasAttributeNS(PyObject *self, PyObject *args)
+static PyObject *element_hasAttributeNS(ElementObject *self, PyObject *args)
 {
   PyObject *namespaceURI, *localName;
@@ -406,6 +398,5 @@
   }
 
-  attr = Element_GetAttributeNodeNS((PyElementObject *)self, namespaceURI, localName);
-
+  attr = Element_GetAttributeNodeNS(self, namespaceURI, localName);
   Py_DECREF(namespaceURI);
   Py_DECREF(localName);
@@ -420,5 +411,4 @@
 }
 
-
 static char element_setAttributeNS_doc[] =
 "Adds a new attribute.  If an attribute with the same local name and\n\
@@ -427,8 +417,8 @@
 be the value parameter.";
 
-static PyObject *element_setAttributeNS(PyObject *self, PyObject *args)
+static PyObject *element_setAttributeNS(ElementObject *self, PyObject *args)
 {
   PyObject *namespaceURI, *qualifiedName, *value, *prefix, *localName;
-  PyAttrObject *attr;
+  PyObject *attr;
 
   Element_VerifyState(self);
@@ -463,6 +453,6 @@
 
   /* returns new reference */
-  attr = Element_SetAttributeNS((PyElementObject *)self, namespaceURI,
-                                qualifiedName, localName, value);
+  attr = (PyObject *)Element_SetAttributeNS(self, namespaceURI, qualifiedName,
+                                            localName, value);
   Py_DECREF(namespaceURI);
   Py_DECREF(qualifiedName);
@@ -471,8 +461,7 @@
   Py_DECREF(value);
 
-  return (PyObject *) attr;
+  return attr;
 }
 
-
 static char element_setAttributeNodeNS_doc[] =
 "Adds a new attribute. If an attribute with that local name and that\n\
@@ -480,8 +469,8 @@
 new one. Replacing an attribute node by itself has no effect.";
 
-static PyObject *element_setAttributeNodeNS(PyElementObject *self,
+static PyObject *element_setAttributeNodeNS(ElementObject *self,
                                             PyObject *args)
 {
-  PyAttrObject *attr;
+  AttrObject *attr;
   PyObject *oldAttr, *key;
 
@@ -503,19 +492,23 @@
 
   /* Get the return value */
-  oldAttr = PyDict_GetItem(PyElement_ATTRIBUTES(self), key);
-
-  PyDict_SetItem(PyElement_ATTRIBUTES(self), key, (PyObject *)attr);
+  oldAttr = PyDict_GetItem(self->attributes, key);
+  if (PyDict_SetItem(self->attributes, key, (PyObject *)attr) < 0) {
+    Py_DECREF(key);
+    return NULL;
+  }
   Py_DECREF(key);
 
   /* Set the new attributes owner */
-  Node_SET_PARENT(attr, (PyNodeObject *) self);
+  Py_XDECREF(Node_GET_PARENT(attr));
+  Py_INCREF(self);
+  Node_SET_PARENT(attr, (NodeObject *)self);
 
   if (oldAttr == NULL) {
     /* new attribute */
     oldAttr = Py_None;
-  }
-  else {
+  } else {
     /* Reset the removed attributes owner */
-    Node_SET_PARENT(oldAttr, (PyNodeObject *) Py_None);
+    Py_DECREF(Node_GET_PARENT(oldAttr));
+    Node_SET_PARENT(oldAttr, NULL);
   }
 
@@ -524,11 +517,11 @@
 }
 
-
 static char element_removeAttributeNode_doc[] =
 "Removes the specified attribute node.";
 
-static PyObject *element_removeAttributeNode(PyObject *self, PyObject *args)
+static PyObject *element_removeAttributeNode(ElementObject *self,
+                                             PyObject *args)
 {
-  PyAttrObject *attr;
+  AttrObject *attr;
   PyObject *key;
 
@@ -540,5 +533,5 @@
 
   key = buildAttrKey(attr);
-  if (PyDict_DelItem(PyElement_ATTRIBUTES(self), key) == -1) {
+  if (PyDict_DelItem(self->attributes, key) == -1) {
     if (PyErr_ExceptionMatches(PyExc_KeyError)) {
       DOMException_NotFoundErr("attribute not found");
@@ -550,5 +543,7 @@
 
   /* Reset the removed attributes owner */
-  Node_SET_PARENT(attr, (PyNodeObject *) Py_None);
+  assert(Node_GET_PARENT(attr) == self);
+  Py_DECREF(Node_GET_PARENT(attr));
+  Node_SET_PARENT(attr, NULL);
 
   Py_INCREF(Py_None);
@@ -560,5 +555,5 @@
 "Removes an attribute by local name and namespace URI.";
 
-static PyObject *element_removeAttributeNS(PyObject *self, PyObject *args)
+static PyObject *element_removeAttributeNS(ElementObject *self, PyObject *args)
 {
   PyObject *namespaceURI, *qualifiedName, *prefix, *localName, *key, *attr;
@@ -591,26 +586,21 @@
   Py_DECREF(prefix);
 
-  key = PyTuple_New((Py_ssize_t)2);
+  key = PyTuple_New(2);
   /* Let the tuple own these */
-  PyTuple_SetItem(key, (Py_ssize_t)0, namespaceURI);
-  PyTuple_SetItem(key, (Py_ssize_t)1, localName);
+  PyTuple_SetItem(key, 0, namespaceURI);
+  PyTuple_SetItem(key, 1, localName);
 
-  attr = PyDict_GetItem(PyElement_ATTRIBUTES(self), key);
+  attr = PyDict_GetItem(self->attributes, key);
   if (attr) {
-    /* Ensure that this doesn't go away while we're changing it */
-    Py_INCREF(attr);
+    assert(Node_GET_PARENT(attr) == self);
+    /* Unset the parent node relationship */
+    Py_DECREF(Node_GET_PARENT(attr));
+    Node_SET_PARENT(attr, NULL);
 
     /* Remove the entry from the attributes mapping */
-    if (PyDict_DelItem(PyElement_ATTRIBUTES(self), key) == -1) {
-      Py_DECREF(attr);
+    if (PyDict_DelItem(self->attributes, key) == -1) {
       Py_DECREF(key);
       return NULL;
     }
-
-    /* Unset the parent node relationship */
-    Node_SET_PARENT(attr, (PyNodeObject *) Py_None);
-
-    /* Done with our changes */
-    Py_DECREF(attr);
   }
 
@@ -622,26 +612,22 @@
 }
 
-#define element_method(NAME) \
+#define Element_METHOD(NAME) \
   { #NAME, (PyCFunction) element_##NAME, METH_VARARGS, element_##NAME##_doc }
 
 static struct PyMethodDef element_methods[] = {
-  element_method(getAttributeNS),
-  element_method(getAttributeNodeNS),
-  element_method(setAttributeNS),
-  element_method(setAttributeNodeNS),
-  element_method(removeAttributeNS),
-  element_method(removeAttributeNode),
-  element_method(hasAttributeNS),
-  { NULL }      /* sentinel */
+  Element_METHOD(getAttributeNS),
+  Element_METHOD(getAttributeNodeNS),
+  Element_METHOD(setAttributeNS),
+  Element_METHOD(setAttributeNodeNS),
+  Element_METHOD(removeAttributeNS),
+  Element_METHOD(removeAttributeNode),
+  Element_METHOD(hasAttributeNS),
+  { NULL }
 };
 
-#undef element_method
-
-
 /** Python Members ****************************************************/
 
-
 #define Element_MEMBER(name, member) \
-  { name, T_OBJECT, offsetof(PyElementObject, member), RO }
+  { name, T_OBJECT, offsetof(ElementObject, member), RO }
 
 static struct PyMemberDef element_members[] = {
@@ -653,16 +639,14 @@
 };
 
-
 /** Python Computed Members *******************************************/
 
-
-static PyObject *get_prefix(PyElementObject *self, void *arg)
+static PyObject *get_prefix(ElementObject *self, void *arg)
 {
   Py_UNICODE *p;
-  Py_ssize_t len, i;
+  Py_ssize_t size, i;
 
   p = PyUnicode_AS_UNICODE(self->nodeName);
-  len = PyUnicode_GET_SIZE(self->nodeName);
-  for (i = 0; i < len; i++) {
+  size = PyUnicode_GET_SIZE(self->nodeName);
+  for (i = 0; i < size; i++) {
     if (p[i] == ':') {
       return PyUnicode_FromUnicode(p, i);
@@ -673,6 +657,5 @@
 }
 
-
-static int set_prefix(PyElementObject *self, PyObject *v, void *arg)
+static int set_prefix(ElementObject *self, PyObject *v, void *arg)
 {
   PyObject *qualifiedName, *prefix;
@@ -716,19 +699,17 @@
 }
 
-
-static PyObject *get_attributes(PyElementObject *self, void *arg)
+static PyObject *get_attributes(ElementObject *self, void *arg)
 {
   return NamedNodeMap_New(self->attributes);
 }
 
-
-static PyObject *get_xpath_attributes(PyElementObject *self, void *arg)
+static PyObject *get_xpath_attributes(ElementObject *self, void *arg)
 {
-  PyObject *attributes = PyList_New((Py_ssize_t)0);
+  PyObject *attributes = PyList_New(0);
   if (attributes != NULL) {
     PyObject *key, *attr;
     Py_ssize_t pos = 0;
     while (PyDict_Next(self->attributes, &pos, &key, &attr)) {
-      switch (PyObject_RichCompareBool(PyAttr_NAMESPACE_URI(attr),
+      switch (PyObject_RichCompareBool(Attr_GET_NAMESPACE_URI(attr),
                                        g_xmlnsNamespace, Py_NE)) {
       case 0: /* namespace attribute */
@@ -749,12 +730,11 @@
 }
 
-
-static PyObject *get_xpath_namespaces(PyElementObject *self, void *arg)
+static PyObject *get_xpath_namespaces(ElementObject *self, void *arg)
 {
   PyObject *namespaces;
-  PyObject *nss = Domlette_GetNamespaces((PyNodeObject *) self);
+  PyObject *nss = Domlette_GetNamespaces((NodeObject *) self);
   if (nss == NULL) return NULL;
 
-  namespaces = PyList_New((Py_ssize_t)0);
+  namespaces = PyList_New(0);
   if (namespaces != NULL) {
     PyObject *xns, *prefix, *uri;
@@ -780,5 +760,4 @@
 }
 
-
 static struct PyGetSetDef element_getset[] = {
   { "prefix", (getter)get_prefix, (setter)set_prefix, NULL, "prefix" },
@@ -790,40 +769,25 @@
 };
 
-
 /** Type Object ********************************************************/
 
-
-static void element_dealloc(PyElementObject *self)
+static void element_dealloc(ElementObject *self)
 {
   PyObject_GC_UnTrack((PyObject *) self);
-
-  Py_XDECREF(self->namespaceURI);
-  self->namespaceURI = NULL;
-
-  Py_XDECREF(self->localName);
-  self->localName = NULL;
-
-  Py_XDECREF(self->nodeName);
-  self->nodeName = NULL;
-
-  if (self->attributes) {
-    PyDict_Clear(self->attributes);
-    Py_DECREF(self->attributes);
-    self->attributes = NULL;
-  }
-
+  Py_CLEAR(self->namespaceURI);
+  Py_CLEAR(self->localName);
+  Py_CLEAR(self->nodeName);
+  Py_CLEAR(self->attributes);
   Node_Del(self);
 }
 
-
-static PyObject *element_repr(PyElementObject *element)
+static PyObject *element_repr(ElementObject *element)
 {
-  PyObject *repr;
-  PyObject *name = PyObject_Repr(element->nodeName);
+  PyObject *repr, *name = PyObject_Repr(element->nodeName);
   if (name == NULL) return NULL;
 
-  repr = PyString_FromFormat("<Element at %p: name %s, %" PY_FORMAT_SIZE_T "d attributes, %d children>",
-                             element,
-                             PyString_AS_STRING(name),
+  repr = PyString_FromFormat("<Element at %p: name %s, "
+                             "%" PY_FORMAT_SIZE_T "d attributes, "
+                             "%" PY_FORMAT_SIZE_T "d children>",
+                             element, PyString_AsString(name),
                              PyDict_Size(element->attributes),
                              ContainerNode_GET_COUNT(element));
@@ -832,32 +796,26 @@
 }
 
-
-static int element_traverse(PyElementObject *self, visitproc visit, void *arg)
+static int element_traverse(ElementObject *self, visitproc visit, void *arg)
 {
   if (self->attributes != shared_empty_attributes) {
     Py_VISIT(self->attributes);
   }
-  return DomletteNode_Type.tp_traverse((PyObject *) self, visit, arg);
+  return DomletteNode_Type.tp_traverse((PyObject *)self, visit, arg);
 }
 
-
-static int element_clear(PyObject *self)
+static int element_clear(ElementObject *self)
 {
-  Py_CLEAR(((PyElementObject *)self)->attributes);
-  return DomletteNode_Type.tp_clear(self);
+  Py_CLEAR(self->attributes);
+  return DomletteNode_Type.tp_clear((PyObject *)self);
 }
 
-
 static PyObject *element_new(PyTypeObject *type, PyObject *args,
                              PyObject *kwds)
 {
-  PyDocumentObject *doc;
   PyObject *namespaceURI, *qualifiedName, *prefix, *localName;
-  static char *kwlist[] = { "ownerDocument", "namespaceURI", "qualifiedName",
-                            NULL };
-  PyElementObject *self;
+  static char *kwlist[] = { "namespaceURI", "qualifiedName", NULL };
+  ElementObject *self;
 
-  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!OO:Element", kwlist,
-                                   &DomletteDocument_Type, &doc,
+  if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:Element", kwlist,
                                    &namespaceURI, &qualifiedName)) {
     return NULL;
@@ -888,7 +846,7 @@
 
   if (type != &DomletteElement_Type) {
-    self = (PyElementObject *) type->tp_alloc(type, 0);
+    self = Element(type->tp_alloc(type, 0));
     if (self != NULL) {
-      _Node_INIT_CONTAINER(self, doc);
+      _Node_INIT_CONTAINER(self);
       if (element_init(self, namespaceURI, qualifiedName, localName) < 0) {
         Py_DECREF(self);
@@ -897,5 +855,5 @@
     }
   } else {
-    self = Element_New(doc, namespaceURI, qualifiedName, localName);
+    self = Element_New(namespaceURI, qualifiedName, localName);
   }
   Py_DECREF(namespaceURI);
@@ -906,7 +864,6 @@
 }
 
-
 static char element_doc[] = "\
-Element(ownerDocument, namespaceURI, qualifiedName) -> Element object\n\
+Element(namespaceURI, qualifiedName) -> Element object\n\
 \n\
 The Element interface represents an element in an XML document.";
@@ -916,5 +873,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "Element",
-  /* tp_basicsize      */ sizeof(PyElementObject),
+  /* tp_basicsize      */ sizeof(ElementObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) element_dealloc,
@@ -938,5 +895,5 @@
   /* tp_doc            */ (char *) element_doc,
   /* tp_traverse       */ (traverseproc) element_traverse,
-  /* tp_clear          */ element_clear,
+  /* tp_clear          */ (inquiry) element_clear,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -957,8 +914,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteElement_Init(PyObject *module)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/element.h.diff?r1=1.20&r2=1.21
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/element.h?rev=1.21&content-type=text/vnd.viewcvs-markup

Index: element.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/element.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -U2 -r1.20 -r1.21
--- element.h	24 Nov 2006 21:36:39 -0000	1.20
+++ element.h	21 Dec 2006 06:13:36 -0000	1.21
@@ -11,15 +11,16 @@
 
   typedef struct {
-    PyContainerNode_HEAD
+    ContainerNode_HEAD
     PyObject *namespaceURI;
     PyObject *localName;
     PyObject *nodeName;
     PyObject *attributes;
-  } PyElementObject;
+  } ElementObject;
 
-#define PyElement_NAMESPACE_URI(op) (((PyElementObject *)(op))->namespaceURI)
-#define PyElement_LOCAL_NAME(op) (((PyElementObject *)(op))->localName)
-#define PyElement_NODE_NAME(op) (((PyElementObject *)(op))->nodeName)
-#define PyElement_ATTRIBUTES(op) (((PyElementObject *)(op))->attributes)
+#define Element(op) ((ElementObject *)(op))
+#define Element_GET_NAMESPACE_URI(op) (Element(op)->namespaceURI)
+#define Element_GET_LOCAL_NAME(op) (Element(op)->localName)
+#define Element_GET_NODE_NAME(op) (Element(op)->nodeName)
+#define Element_GET_ATTRIBUTES(op) (Element(op)->attributes)
 
 #ifdef Domlette_BUILDING_MODULE
@@ -27,6 +28,6 @@
   extern PyTypeObject DomletteElement_Type;
 
-#define PyElement_Check(op) PyObject_TypeCheck((op), &DomletteElement_Type)
-#define PyElement_CheckExact(op) ((op)->ob_type == &DomletteElement_Type)
+#define Element_Check(op) PyObject_TypeCheck((op), &DomletteElement_Type)
+#define Element_CheckExact(op) ((op)->ob_type == &DomletteElement_Type)
 
   /* Module Methods */
@@ -35,21 +36,19 @@
 
   /* Element Methods */
-  PyElementObject *Element_New(PyDocumentObject *ownerDocument,
-                               PyObject *namespaceURI,
-                               PyObject *qualifiedName,
-                               PyObject *localName);
+  ElementObject *Element_New(PyObject *namespaceURI,
+                             PyObject *qualifiedName,
+                             PyObject *localName);
+
+  AttrObject *Element_SetAttributeNS(ElementObject *self,
+                                     PyObject *namespaceURI,
+                                     PyObject *qualifiedName,
+                                     PyObject *localName,
+                                     PyObject *value);
 
-  PyAttrObject *Element_SetAttributeNS(PyElementObject *self,
-                                       PyObject *namespaceURI,
-                                       PyObject *qualifiedName,
-                                       PyObject *localName,
-                                       PyObject *value);
-
-  PyObject *Element_GetAttributeNodeNS(PyElementObject *self,
+  PyObject *Element_GetAttributeNodeNS(ElementObject *self,
                                        PyObject *namespaceURI,
                                        PyObject *localName);
 
-  PyElementObject *Element_CloneNode(PyObject *node, int deep,
-                                     PyDocumentObject *newOwnerDocument);
+  ElementObject *Element_CloneNode(PyObject *node, int deep);
 
 #endif /* Domlette_BUILDING_MODULE */
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/expat_interface.h.diff?r1=1.11&r2=1.12
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/expat_interface.h?rev=1.12&content-type=text/vnd.viewcvs-markup

Index: expat_interface.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/expat_interface.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -U2 -r1.11 -r1.12
--- expat_interface.h	25 Nov 2006 02:57:48 -0000	1.11
+++ expat_interface.h	21 Dec 2006 06:13:36 -0000	1.12
@@ -180,4 +180,8 @@
                                     PyObject *exception);
 
+  typedef PyObject *(*ExpatResolveEntityHandler)(void *userData,
+                                                 PyObject *publicId,
+                                                 PyObject *systemId);
+
   typedef struct {
     ExpatParser (*ParserCreate)(void *userState);
@@ -283,4 +287,7 @@
                                     ExpatExternalEntityDeclHandler handler);
 
+    void (*SetResolveEntityHandler)(ExpatParser parser,
+                                    ExpatResolveEntityHandler handler);
+
     void (*SetParamEntityParsing)(ExpatParser parser, int doParamEntityParsing);
 
@@ -370,4 +377,7 @@
   Expat_API->SetExternalEntityDeclHandler
 
+#define Expat_SetResolveEntityHandler \
+  Expat_API->SetResolveEntityHandler
+
 #define Expat_SetParamEntityParsing \
   Expat_API->SetParamEntityParsing
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/expat_module.c.diff?r1=1.115&r2=1.116
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/expat_module.c?rev=1.116&content-type=text/vnd.viewcvs-markup

Index: expat_module.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/expat_module.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -U2 -r1.115 -r1.116
--- expat_module.c	20 Dec 2006 00:57:10 -0000	1.115
+++ expat_module.c	21 Dec 2006 06:13:36 -0000	1.116
@@ -99,5 +99,4 @@
 
 static PyObject *xinclude_hint_string;
-static PyObject *external_entity_hint_string;
 static PyObject *absolutize_function;
 static PyObject *expat_library_error;
@@ -280,4 +279,6 @@
   ExpatNotificationHandler fatal_error_handler;
 
+  ExpatResolveEntityHandler resolve_entity_handler;
+
   /* caching members */
   HashTable *name_cache;        /* element name parts */
@@ -3468,14 +3469,14 @@
     if (XMLChar_NCmp(name, expat_xinclude_namespace,
                      EXPAT_NAME_LEN(expat_xinclude_namespace)) == 0) {
-      const XML_Char *xinclude_name =
+      const XML_Char *expat_xinclude_name =
         name + EXPAT_NAME_LEN(expat_xinclude_namespace);
 
       /* check for xi:include */
-      if (EXPAT_NAME_COMPARE(xinclude_name, expat_include_name)) {
+      if (EXPAT_NAME_COMPARE(expat_xinclude_name, expat_include_name)) {
         /* fall through regardless of return status */
         (void) beginXInclude(parser, atts);
       }
       /* check for xi:fallback */
-      else if (EXPAT_NAME_COMPARE(xinclude_name, expat_fallback_name)) {
+      else if (EXPAT_NAME_COMPARE(expat_xinclude_name, expat_fallback_name)) {
         /* fatal error, xi:fallback not in xi:include */
         XIncludeException_FallbackNotInInclude();
@@ -4791,6 +4792,15 @@
   }
 
-  source = PyObject_CallMethod(parser->context->source, "resolveEntity", "NN",
-                               python_publicId, python_systemId);
+  /* If no resolver is provided, use the default behavior from the
+   * InputSource object. */
+  if (parser->resolve_entity_handler) {
+    source = parser->resolve_entity_handler(parser->userState, python_publicId,
+                                            python_systemId);
+    Py_DECREF(python_publicId);
+    Py_DECREF(python_systemId);
+  } else {
+    source = PyObject_CallMethod(parser->context->source, "resolveEntity",
+                                 "NN", python_publicId, python_systemId);
+  }
   if (source == NULL) {
     XML_ParserFree(new_parser);
@@ -5386,4 +5396,11 @@
 
 
+void Expat_SetResolveEntityHandler(ExpatParser parser,
+                                   ExpatResolveEntityHandler handler)
+{
+  parser->resolve_entity_handler = handler;
+}
+
+
 void Expat_SetValidation(ExpatParser parser, int doValidation)
 {
@@ -5745,4 +5762,6 @@
   Expat_SetExternalEntityDeclHandler,
 
+  Expat_SetResolveEntityHandler,
+
   Expat_SetParamEntityParsing,
   Expat_SetXIncludeProcessing,
@@ -5770,6 +5789,6 @@
 #define DEFINE_STRING(name, s) \
   DEFINE_OBJECT(name, PyString_FromString(s))
-#define DEFINE_UNICODE(name, s) \
-  DEFINE_OBJECT(name, PyUnicode_DecodeASCII((s), sizeof(s) - 1, NULL))
+#define DEFINE_XMLSTRING(name, s) \
+  DEFINE_OBJECT(name, XmlString_FromASCII(s))
 
   DEFINE_STRING(encoding_string, "encoding");
@@ -5780,25 +5799,24 @@
   if (empty_string == NULL) return -1;
 
-  DEFINE_UNICODE(asterisk_string, "*");
-  DEFINE_UNICODE(space_string, "space");
-  DEFINE_UNICODE(preserve_string, "preserve");
-  DEFINE_UNICODE(default_string, "default");
-  DEFINE_UNICODE(id_string, "id");
-  DEFINE_UNICODE(xml_space_string, "xml:space");
-  DEFINE_UNICODE(xml_base_string, "xml:base");
-  DEFINE_UNICODE(xml_lang_string, "xml:lang");
-  DEFINE_UNICODE(base_string, "base");
-  DEFINE_UNICODE(lang_string, "lang");
-  DEFINE_UNICODE(unicode_space_char, " ");
-  DEFINE_UNICODE(empty_event, "(#EMPTY)");
-  DEFINE_UNICODE(content_model_empty, "EMPTY");
-  DEFINE_UNICODE(content_model_any, "ANY");
-  DEFINE_UNICODE(content_model_pcdata, "(#PCDATA)");
-  DEFINE_UNICODE(attribute_decl_implied, "#IMPLIED");
-  DEFINE_UNICODE(attribute_decl_required, "#REQUIRED");
-  DEFINE_UNICODE(attribute_decl_fixed, "#FIXED");
+  DEFINE_XMLSTRING(asterisk_string, "*");
+  DEFINE_XMLSTRING(space_string, "space");
+  DEFINE_XMLSTRING(preserve_string, "preserve");
+  DEFINE_XMLSTRING(default_string, "default");
+  DEFINE_XMLSTRING(id_string, "id");
+  DEFINE_XMLSTRING(xml_space_string, "xml:space");
+  DEFINE_XMLSTRING(xml_base_string, "xml:base");
+  DEFINE_XMLSTRING(xml_lang_string, "xml:lang");
+  DEFINE_XMLSTRING(base_string, "base");
+  DEFINE_XMLSTRING(lang_string, "lang");
+  DEFINE_XMLSTRING(unicode_space_char, " ");
+  DEFINE_XMLSTRING(empty_event, "(#EMPTY)");
+  DEFINE_XMLSTRING(content_model_empty, "EMPTY");
+  DEFINE_XMLSTRING(content_model_any, "ANY");
+  DEFINE_XMLSTRING(content_model_pcdata, "(#PCDATA)");
+  DEFINE_XMLSTRING(attribute_decl_implied, "#IMPLIED");
+  DEFINE_XMLSTRING(attribute_decl_required, "#REQUIRED");
+  DEFINE_XMLSTRING(attribute_decl_fixed, "#FIXED");
 
   DEFINE_STRING(xinclude_hint_string, "XINCLUDE");
-  DEFINE_STRING(external_entity_hint_string, "EXTERNAL ENTITY");
 
   import = PyImport_ImportModule("Ft.Lib");
@@ -5944,5 +5962,4 @@
 
   Py_DECREF(xinclude_hint_string);
-  Py_DECREF(external_entity_hint_string);
   Py_DECREF(absolutize_function);
   Py_XDECREF(expat_library_error);
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/expat_module.h.diff?r1=1.30&r2=1.31
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/expat_module.h?rev=1.31&content-type=text/vnd.viewcvs-markup

Index: expat_module.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/expat_module.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -U2 -r1.30 -r1.31
--- expat_module.h	25 Nov 2006 02:57:48 -0000	1.30
+++ expat_module.h	21 Dec 2006 06:13:36 -0000	1.31
@@ -135,4 +135,7 @@
                                 ExpatExternalEntityDeclHandler handler);
 
+  void Expat_SetResolveEntityHandler(ExpatParser parser,
+                                     ExpatResolveEntityHandler handler);
+
   int DomletteExpat_Init(PyObject *module);
   void DomletteExpat_Fini(void);
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/namednodemap.c.diff?r1=1.3&r2=1.4
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/namednodemap.c?rev=1.4&content-type=text/vnd.viewcvs-markup

Index: namednodemap.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/namednodemap.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -U2 -r1.3 -r1.4
--- namednodemap.c	25 Sep 2006 17:33:11 -0000	1.3
+++ namednodemap.c	21 Dec 2006 06:13:36 -0000	1.4
@@ -326,5 +326,5 @@
   /* tp_doc            */ (char *) namednodemap_doc,
   /* tp_traverse       */ (traverseproc) namednodemap_traverse,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/node.c.diff?r1=1.47&r2=1.48
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/node.c?rev=1.48&content-type=text/vnd.viewcvs-markup

Index: node.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/node.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -U2 -r1.47 -r1.48
--- node.c	2 Dec 2006 21:55:11 -0000	1.47
+++ node.c	21 Dec 2006 06:13:36 -0000	1.48
@@ -3,5 +3,4 @@
 /** Private Routines **************************************************/
 
-
 static PyObject *shared_empty_nodelist;
 static PyObject *xml_base_key;
@@ -10,20 +9,19 @@
 
 #define ContainerNode_SET_COUNT(op, v) (ContainerNode_GET_COUNT(op) = (v))
-#define ContainerNode_GET_NODES(op) (((PyContainerNodeObject *)(op))->nodes)
+#define ContainerNode_GET_NODES(op) (((ContainerNodeObject *)(op))->nodes)
 #define ContainerNode_SET_NODES(op, v) (ContainerNode_GET_NODES(op) = (v))
 #define ContainerNode_GET_ALLOCATED(op)         \
-  (((PyContainerNodeObject *)(op))->allocated)
+  (((ContainerNodeObject *)(op))->allocated)
 #define ContainerNode_SET_ALLOCATED(op, v)      \
   (ContainerNode_GET_ALLOCATED(op) = (v))
 #define ContainerNode_GET_CHILD(op, i)          \
-  (((PyContainerNodeObject *)(op))->nodes[i])
+  (((ContainerNodeObject *)(op))->nodes[i])
 #define ContainerNode_SET_CHILD(op, i, v)       \
   (ContainerNode_GET_CHILD((op), (i)) = (v))
 
-
-static int node_resize(PyContainerNodeObject *self, int newsize) {
-  PyNodeObject **nodes;
+static int node_resize(ContainerNodeObject *self, Py_ssize_t newsize) {
+  NodeObject **nodes;
   size_t new_allocated;
-  int allocated = self->allocated;
+  Py_ssize_t allocated = self->allocated;
 
   /* Bypass realloc() when a previous overallocation is large enough
@@ -47,6 +45,6 @@
     new_allocated = 0;
   nodes = self->nodes;
-  if (new_allocated <= ((~(size_t)0) / sizeof(PyNodeObject *)))
-    PyMem_Resize(nodes, PyNodeObject *, new_allocated);
+  if (new_allocated <= ((~(size_t)0) / sizeof(NodeObject *)))
+    PyMem_Resize(nodes, NodeObject *, new_allocated);
   else
     nodes = NULL;
@@ -61,26 +59,7 @@
 }
 
-
-static int node_clear_nodes(PyContainerNodeObject *self)
+static int node_validate_child(NodeObject *self, NodeObject *child)
 {
-  PyNodeObject **nodes = self->nodes;
-  int i;
-  if (nodes != NULL) {
-    i = self->count;
-    self->nodes = NULL;
-    self->count = 0;
-    self->allocated = 0;
-    while (--i >= 0) {
-      Py_DECREF(nodes[i]);
-    }
-    PyMem_Free(nodes);
-  }
-  return 0;
-}
-
-
-static int node_validate_child(PyNodeObject *self, PyNodeObject *child)
-{
-  if (self == NULL || child == NULL || !PyNode_Check(self)) {
+  if (self == NULL || child == NULL || !Node_Check(self)) {
     PyErr_BadInternalCall();
     return 0;
@@ -90,10 +69,7 @@
   }
 
-  if (!(PyElement_Check(child) ||
-        PyProcessingInstruction_Check(child) ||
-        PyComment_Check(child) ||
-        PyText_Check(child) ||
-        PyDocumentFragment_Check(child))) {
-    if (!PyNode_Check(child)) {
+  if (!(Element_Check(child) || ProcessingInstruction_Check(child) ||
+        Comment_Check(child) || Text_Check(child))) {
+    if (!Node_Check(child)) {
       /* The child must be a Domlette Node first and foremost. */
       PyErr_BadInternalCall();
@@ -114,28 +90,19 @@
 }
 
-
 /** Public C API ******************************************************/
 
-
 /* Allocates memory for a new node object of the given type and initializes
-   part of it.
-*/
-PyNodeObject *_Node_New(PyTypeObject *type, PyDocumentObject *ownerDocument,
-                        long flags)
+ * part of it.
+ */
+NodeObject *_Node_New(PyTypeObject *type, long flags)
 {
-  PyNodeObject *node;
-
-  if (ownerDocument == NULL || (ownerDocument != (PyDocumentObject *) Py_None
-                                && !PyDocument_Check(ownerDocument))) {
-    PyErr_BadInternalCall();
-    return NULL;
-  }
+  NodeObject *node;
 
-  node = PyObject_GC_New(PyNodeObject, type);
+  node = PyObject_GC_New(NodeObject, type);
   if (node != NULL) {
 #ifdef DEBUG_NODE_CREATION
-    printf("Created %s node at 0x%p\n", type->tp_name, node);
+    fprintf(stderr, "Created %s node at %p\n", type->tp_name, node);
 #endif
-    _Node_INIT_FLAGS(node, ownerDocument, flags);
+    _Node_INIT_FLAGS(node, flags);
 
     if (flags & Node_FLAGS_CONTAINER) {
@@ -149,15 +116,14 @@
 }
 
-
-void _Node_Del(PyNodeObject *node)
+void _Node_Del(NodeObject *node)
 {
 #ifdef DEBUG_NODE_CREATION
-  printf("Destroyed %s node at 0x%p\n", node->ob_type->tp_name, node);
+  fprintf(stderr, "Destroyed %s node at %p\n", node->ob_type->tp_name, node);
 #endif
 
   if (node->flags & Node_FLAGS_CONTAINER) {
-    PyNodeObject **nodes = ContainerNode_GET_NODES(node);
+    NodeObject **nodes = ContainerNode_GET_NODES(node);
     if (nodes) {
-      int i = ContainerNode_GET_COUNT(node);
+      Py_ssize_t i = ContainerNode_GET_COUNT(node);
       while (--i >= 0) {
         Py_DECREF(nodes[i]);
@@ -167,16 +133,11 @@
   }
 
-  node->parentNode = NULL;
-
-  if (node->ownerDocument) {
-    Py_DECREF(node->ownerDocument);
-    node->ownerDocument = NULL;
-  }
+  Py_CLEAR(node->parentNode);
 
   PyObject_GC_Del((PyObject *) node);
 }
 
-
-void _Node_Dump(char *msg, PyNodeObject *self)
+/* For debugging convenience. */
+void _Node_Dump(char *msg, NodeObject *self)
 {
   int add_sep;
@@ -200,12 +161,11 @@
             "  type    : %s\n"
             "  refcount: %" PY_FORMAT_SIZE_T "d\n"
-            "  parent  : %p\n"
-            "  document: %p\n",
+            "  parent  : %p\n",
             self->ob_type == NULL ? "NULL" : self->ob_type->tp_name,
             self->ob_refcnt,
-            self->parentNode,
-            self->ownerDocument);
+            Node_GET_PARENT(self));
     if (Node_HasFlag(self, Node_FLAGS_CONTAINER)) {
-      fprintf(stderr, "  children: %d\n", ContainerNode_GET_COUNT(self));
+      fprintf(stderr, "  children: %" PY_FORMAT_SIZE_T "d\n",
+              ContainerNode_GET_COUNT(self));
     }
   }
@@ -213,15 +173,14 @@
 }
 
-
 /* Semi-private routine for bulk addition of children to a node.
  * This routine is valid for newly contructed container-style nodes which
  * haven't had any children added to them.
  */
-int _Node_SetChildren(PyNodeObject *self, PyNodeObject **array, int size)
+int _Node_SetChildren(NodeObject *self, NodeObject **array, Py_ssize_t size)
 {
-  PyNodeObject **nodes;
-  int i;
+  NodeObject **nodes;
+  Py_ssize_t i;
 
-  if (!PyNode_Check(self) || !Node_HasFlag(self, Node_FLAGS_CONTAINER) ||
+  if (!Node_Check(self) || !Node_HasFlag(self, Node_FLAGS_CONTAINER) ||
       ContainerNode_GET_NODES(self) != NULL) {
     PyErr_BadInternalCall();
@@ -230,14 +189,17 @@
 
   /* Create a copy of the array */
-  nodes = PyMem_New(PyNodeObject *, size);
+  nodes = PyMem_New(NodeObject *, size);
   if (nodes == NULL) {
     PyErr_NoMemory();
     return -1;
   }
-  memcpy(nodes, array, sizeof(PyNodeObject *) * size);
+  memcpy(nodes, array, sizeof(NodeObject *) * size);
 
   /* Set the parent relationship */
-  for (i = 0; i < size; i++)
+  for (i = 0; i < size; i++) {
+    assert(Node_GET_PARENT(nodes[i]) == NULL);
+    Py_INCREF(self);
     Node_SET_PARENT(nodes[i], self);
+  }
 
   /* Save the new array */
@@ -249,11 +211,10 @@
 }
 
-
-int Node_RemoveChild(PyNodeObject *self, PyNodeObject *oldChild)
+int Node_RemoveChild(NodeObject *self, NodeObject *oldChild)
 {
-  PyNodeObject **nodes;
-  int count, index, i;
+  NodeObject **nodes;
+  Py_ssize_t count, index, i;
 
-  if (self == NULL || !PyNode_Check(self)) {
+  if (self == NULL || !Node_Check(self)) {
     PyErr_BadInternalCall();
     return -1;
@@ -282,4 +243,5 @@
     return -1;
   }
+  assert(Node_GET_PARENT(oldChild) == self);
 
 #ifdef DEBUG_NODE_REMOVE_CHILD
@@ -287,11 +249,12 @@
 #endif
 
-  /* Set the parent to Py_None, indicating no parent */
-  Node_SET_PARENT(oldChild, (PyNodeObject *) Py_None);
+  /* Set the parent to NULL, indicating no parent */
+  Py_DECREF(Node_GET_PARENT(oldChild));
+  Node_SET_PARENT(oldChild, NULL);
 
   /* Now shift the nodes in the array over the top of the removed node */
   memmove(&nodes[index], &nodes[index+1],
-          (count - (index + 1)) * sizeof(PyNodeObject *));
-  node_resize((PyContainerNodeObject *) self, count - 1);
+          (count - (index + 1)) * sizeof(NodeObject *));
+  node_resize((ContainerNodeObject *)self, count - 1);
 
   /* Drop the reference to the removed node as it is no longer in the array */
@@ -306,8 +269,7 @@
 }
 
-
-int Node_AppendChild(PyNodeObject *self, PyNodeObject *newChild)
+int Node_AppendChild(NodeObject *self, NodeObject *newChild)
 {
-  int count;
+  Py_ssize_t count;
 
   if (!node_validate_child(self, newChild)) {
@@ -320,40 +282,30 @@
 #endif
 
-  /* Perform special processing if the child is a DocumentFragment */
-  if (PyDocumentFragment_Check(newChild)) {
-#ifdef DEBUG_NODE_APPEND_CHILD
-    fprintf(stderr, "Node_AppendChild: processing DocumentFragment\n");
-#endif
-    /* Add each child of the DocumentFragment as a child of this node.  As
-     * the child as added, it is removed from the DocumentFragment.
-     */
-    while (ContainerNode_GET_COUNT(newChild)) {
-      if (Node_AppendChild(self, ContainerNode_GET_CHILD(newChild, 0)) == -1) {
-        return -1;
-      }
-    }
-#ifdef DEBUG_NODE_APPEND_CHILD
-    fprintf(stderr, "Node_AppendChild: DocumentFragment finished\n");
-#endif
-  } else {
-    /* Add the new child to the end of our array */
-    count = ContainerNode_GET_COUNT(self);
-    if (node_resize((PyContainerNodeObject *) self, count + 1) == -1)
+  /* Make room for the new child */
+  count = ContainerNode_GET_COUNT(self);
+  if (node_resize((ContainerNodeObject *)self, count + 1) == -1)
+    return -1;
+
+  /* If the child has a previous parent, remove it from that parent */
+  if (Node_GET_PARENT(newChild) != NULL) {
+    if (Node_RemoveChild(Node_GET_PARENT(newChild), newChild) < 0) {
+      /* Forget the new size; it is OK to leave the resize intact */
+      ContainerNode_SET_COUNT(self, count);
       return -1;
-    Py_INCREF(newChild);
-    ContainerNode_SET_CHILD(self, count, newChild);
+    }
+    assert(Node_GET_PARENT(newChild) == NULL);
+  }
+
+  /* Add the new child to the end of our array */
+  Py_INCREF(newChild);
+  ContainerNode_SET_CHILD(self, count, newChild);
 
 #ifdef DEBUG_NODE_APPEND_CHILD
-    _Node_Dump("Node_AppendChild: newChild after append", newChild);
+  _Node_Dump("Node_AppendChild: newChild after append", newChild);
 #endif
 
-    /* If the child has a previous parent, remove it from that parent */
-    if (Node_GET_PARENT(newChild) != (PyNodeObject *) Py_None) {
-      Node_RemoveChild(Node_GET_PARENT(newChild), newChild);
-    }
-
-    /* Set the parent relationship */
-    Node_SET_PARENT(newChild, self);
-  }
+  /* Set the parent relationship */
+  Py_INCREF(self);
+  Node_SET_PARENT(newChild, self);
 
 #ifdef DEBUG_NODE_APPEND_CHILD
@@ -365,10 +317,9 @@
 }
 
-
-int Node_InsertBefore(PyNodeObject *self, PyNodeObject *newChild,
-                      PyNodeObject *refChild)
+int Node_InsertBefore(NodeObject *self, NodeObject *newChild,
+                      NodeObject *refChild)
 {
-  PyNodeObject **nodes;
-  int count, index, i;
+  NodeObject **nodes;
+  Py_ssize_t count, index, i;
 
   if (!node_validate_child(self, newChild)) {
@@ -376,10 +327,10 @@
   }
 
-  if (refChild == (PyNodeObject *) Py_None) {
+  if (refChild == (NodeObject *) Py_None) {
 #ifdef DEBUG_NODE_INSERT_BEFORE
     fprintf(stderr, "Node_InsertBefore: refChild is None, doing append\n");
 #endif
     return Node_AppendChild(self, newChild);
-  } else if (!PyNode_Check(refChild)) {
+  } else if (!Node_Check(refChild)) {
     PyErr_BadInternalCall();
     return -1;
@@ -392,65 +343,53 @@
 #endif
 
-  if (PyDocumentFragment_Check(newChild)) {
-#ifdef DEBUG_NODE_INSERT_BEFORE
-    fprintf(stderr, "Node_InsertBefore: processing DocumentFragment\n");
-#endif
-    /* Add each child of the DocumentFragment as a child of this node.  As
-     * the child as added, it is removed from the DocumentFragment.
-     */
-    while (ContainerNode_GET_COUNT(newChild)) {
-      PyNodeObject *dfChild = ContainerNode_GET_CHILD(newChild, 0);
-      if (Node_InsertBefore(self, dfChild, refChild) == -1) {
-        return -1;
-      }
-    }
-#ifdef DEBUG_NODE_INSERT_BEFORE
-    fprintf(stderr, "Node_InsertBefore: DocumentFragment finished\n");
-#endif
-  } else {
-    /* Find the index of the reference node */
-    nodes = ContainerNode_GET_NODES(self);
-    count = ContainerNode_GET_COUNT(self);
-    index = -1;
-    for (i = count; --i >= 0;) {
-      if (nodes[i] == refChild) {
-        index = i;
-        break;
-      }
-    }
-    if (index == -1) {
-      DOMException_NotFoundErr("refChild not found");
-      return -1;
+  /* Find the index of the reference node */
+  nodes = ContainerNode_GET_NODES(self);
+  count = ContainerNode_GET_COUNT(self);
+  index = -1;
+  for (i = count; --i >= 0;) {
+    if (nodes[i] == refChild) {
+      index = i;
+      break;
     }
+  }
+  if (index == -1) {
+    DOMException_NotFoundErr("refChild not found");
+    return -1;
+  }
 
 #ifdef DEBUG_NODE_INSERT_BEFORE
-    fprintf(stderr, "Node_InsertBefore: refChild found at %d\n", index);
+  fprintf(stderr, "Node_InsertBefore: refChild found at %d\n", index);
 #endif
 
-    /* Insert the newChild at the found index in the array */
-    if (node_resize((PyContainerNodeObject *) self, count + 1) == -1)
+  /* Make room for the new child */
+  if (node_resize((ContainerNodeObject *)self, count + 1) == -1)
+    return -1;
+
+  /* If the child has a previous parent, remove it from that parent */
+  if (Node_GET_PARENT(newChild) != NULL) {
+    if (Node_RemoveChild(Node_GET_PARENT(newChild), newChild) < 0) {
+      /* Forget the new size; it is OK to leave the resize intact */
+      ContainerNode_SET_COUNT(self, count);
       return -1;
+    }
+    assert(Node_GET_PARENT(newChild) == NULL);
+  }
 
-    /* The pointer to nodes may have changed do to the resize */
-    nodes = ContainerNode_GET_NODES(self);
-    /* Shift the effected nodes up one */
-    for (i = count; --i >= index;)
-      nodes[i+1] = nodes[i];
-
-    /* Set the new child in the array */
-    Py_INCREF(newChild);
-    ContainerNode_SET_CHILD(self, index, newChild);
+  /* The pointer to nodes may have changed do to the resize */
+  nodes = ContainerNode_GET_NODES(self);
+  /* Shift the effected nodes up one */
+  for (i = count; --i >= index;)
+    nodes[i+1] = nodes[i];
+
+  /* Insert the newChild at the found index in the array */
+  Py_INCREF(newChild);
+  ContainerNode_SET_CHILD(self, index, newChild);
 
 #ifdef DEBUG_NODE_INSERT_BEFORE
-    _Node_Dump("Node_InsertBefore: newChild after insert", newChild);
+  _Node_Dump("Node_InsertBefore: newChild after insert", newChild);
 #endif
-    /* If the child has a previous parent, remove it from that parent */
-    if (Node_GET_PARENT(newChild) != (PyNodeObject *) Py_None) {
-      Node_RemoveChild(Node_GET_PARENT(newChild), newChild);
-    }
-
-    /* Set the parent relationship */
-    Node_SET_PARENT(newChild, self);
-  }
+  /* Set the parent relationship */
+  Py_INCREF(self);
+  Node_SET_PARENT(newChild, self);
 
 #ifdef DEBUG_NODE_INSERT_BEFORE
@@ -463,7 +402,71 @@
 }
 
+int Node_ReplaceChild(NodeObject *self, NodeObject *newChild,
+                      NodeObject *oldChild)
+{
+  NodeObject **nodes;
+  Py_ssize_t index;
+
+#ifdef DEBUG_NODE_REPLACE_CHILD
+  _Node_Dump("Node_ReplaceChild: initial state of self", self);
+  _Node_Dump("Node_ReplaceChild: initial state of newChild", newChild);
+  _Node_Dump("Node_ReplaceChild: initial state of oldChild", oldChild);
+#endif
+
+  /* Find the index of the reference node */
+  nodes = ContainerNode_GET_NODES(self);
+  for (index = ContainerNode_GET_COUNT(self); --index >= 0;) {
+    if (nodes[index] == oldChild) {
+      break;
+    }
+  }
+  if (index == -1) {
+    DOMException_NotFoundErr("oldChild not found");
+    return -1;
+  }
+  assert(Node_GET_PARENT(oldChild) == self);
+
+#ifdef DEBUG_NODE_REPLACE_CHILD
+  fprintf(stderr, "Node_ReplaceChild: oldChild found at %d\n", index);
+#endif
 
-PyNodeObject *Node_CloneNode(PyObject *node, int deep,
-			     PyDocumentObject *newOwnerDocument)
+  /* If `newChild` has a previous parent, remove it from that parent */
+  if (Node_GET_PARENT(newChild) != NULL) {
+    if (Node_RemoveChild(Node_GET_PARENT(newChild), newChild) < 0) {
+      return -1;
+    }
+    assert(Node_GET_PARENT(newChild) == NULL);
+  }
+
+  /* Set the parent for `oldChild` to NULL, indicating no parent */
+  Py_DECREF(Node_GET_PARENT(oldChild));
+  Node_SET_PARENT(oldChild, NULL);
+
+  /* Remove it from the nodes array (just drop the reference to it as its
+   * spot will soon be taken by `newChild`) */
+  Py_DECREF(oldChild);
+
+#ifdef DEBUG_NODE_REPLACE_CHILD
+  _Node_Dump("Node_ReplaceChild: oldChild after remove", oldChild);
+#endif
+
+  /* Insert `newChild` at the found index in the array */
+  Py_INCREF(newChild);
+  ContainerNode_SET_CHILD(self, index, newChild);
+
+  /* Set the parent relationship */
+  Py_INCREF(self);
+  Node_SET_PARENT(newChild, self);
+
+#ifdef DEBUG_NODE_REPLACE_CHILD
+  _Node_Dump("replaceChild: final state of self", self);
+  _Node_Dump("replaceChild: final state of newChild", newChild);
+  _Node_Dump("replaceChild: final state of oldChild", oldChild);
+#endif
+
+  return 0;
+}
+
+NodeObject *Node_CloneNode(PyObject *node, int deep)
 {
   PyObject *obj;
@@ -472,5 +475,5 @@
   /* Note that this section MUST use attribute lookup and the node type
    * constant (integer) checks instead in simple type checks, as the node
-   * to be cloned may be from a different implementation. */
+   * to be cloned may be from a different implementation (for importNode). */
 
   /* Get the nodeType as a plain integer */
@@ -480,20 +483,17 @@
   node_type = PyInt_AsLong(obj);
   Py_DECREF(obj);
+  if (node_type == -1 && PyErr_Occurred()) return NULL;
 
   switch (node_type) {
   case ELEMENT_NODE:
-    return (PyNodeObject *)Element_CloneNode(node, deep, newOwnerDocument);
+    return (NodeObject *)Element_CloneNode(node, deep);
   case ATTRIBUTE_NODE:
-    return (PyNodeObject *)Attr_CloneNode(node, deep, newOwnerDocument);
+    return (NodeObject *)Attr_CloneNode(node, deep);
   case TEXT_NODE:
-    return (PyNodeObject *)Text_CloneNode(node, deep, newOwnerDocument);
+    return (NodeObject *)Text_CloneNode(node, deep);
   case COMMENT_NODE:
-    return (PyNodeObject *)Comment_CloneNode(node, deep, newOwnerDocument);
-  case DOCUMENT_FRAGMENT_NODE:
-    return (PyNodeObject *)DocumentFragment_CloneNode(node, deep,
-						      newOwnerDocument);
+    return (NodeObject *)Comment_CloneNode(node, deep);
   case PROCESSING_INSTRUCTION_NODE:
-    return (PyNodeObject *)ProcessingInstruction_CloneNode(node, deep,
-							   newOwnerDocument);
+    return (NodeObject *)ProcessingInstruction_CloneNode(node, deep);
   default:
     /* FIXME: DOMException */
@@ -503,8 +503,6 @@
 }
 
-
 /** Python Methods *****************************************************/
 
-
 static char normalize_doc[] = "\
 Puts all Text nodes in the full depth of the sub-tree underneath this Node,\n\
@@ -514,7 +512,7 @@
 Text nodes nor empty Text nodes.";
 
-static PyObject *node_normalize(PyNodeObject *self, PyObject *args)
+static PyObject *node_normalize(NodeObject *self, PyObject *args)
 {
-  int ctr;
+  Py_ssize_t i, count;
 
   if (!PyArg_ParseTuple(args, ":normalize"))
@@ -535,37 +533,35 @@
   }
 
-  /*Count from 0 to 1 minus the length (the last node cannot be normalized with anything*/
-  for (ctr = 0; ctr < ContainerNode_GET_COUNT(self)-1;) {
-    PyNodeObject *current = ContainerNode_GET_CHILD(self, ctr);
+  /* Count to the length minus 1 as the last node has no following sibling
+   * with which to be merged. */
+  for (i = 0, count = ContainerNode_GET_COUNT(self); i < count; i++) {
+    NodeObject *current = ContainerNode_GET_CHILD(self, i);
 #ifdef DEBUG_NODE_NORMALIZE
     _Node_Dump("normalize: current node", current);
 #endif
-    /* If this node is a Text node, determine of following siblings are also
+    /* If this node is a Text node, determine if following siblings are also
      * Text nodes.
      */
-    if (PyText_Check(current)) {
-      PyNodeObject *next = ContainerNode_GET_CHILD(self, ctr+1);
+    if (Text_Check(current)) {
+      /* Loop over the following siblings */
+      for (i++; i < count; count--) {
+        NodeObject *next = ContainerNode_GET_CHILD(self, i);
 #ifdef DEBUG_NODE_NORMALIZE
-      _Node_Dump("normalize: next node", next);
+        _Node_Dump("normalize: next node", next);
 #endif
-      if (PyText_Check(next)) {
-        /* Adjacent Text nodes, merge their data and delete the second one. */
-        PyObject *data = PySequence_Concat(Text_GET_DATA(current),
-                                           Text_GET_DATA(next));
-        Py_DECREF(Text_GET_DATA(current));
-        Text_SET_DATA(current, data);
-
-	if (Node_RemoveChild(self, next) == -1)
+        if (!Text_Check(next)) break;
+        /* Adjacent Text nodes; merge their data. */
+        if (CharacterData_AppendData(Text(current), Text_GET_DATA(next)) < 0)
+          return NULL;
+#ifdef DEBUG_NODE_NORMALIZE
+        _Node_Dump("normalize: current after merge", current);
+#endif
+        /* Remove the sibling. */
+        if (Node_RemoveChild(self, next) < 0)
           return NULL;
-
 #ifdef DEBUG_NODE_NORMALIZE
         _Node_Dump("normalize: self after merge", self);
-	_Node_Dump("normalize: current after merge", current);
 #endif
-      } else {
-	ctr++;
       }
-    } else {
-      ctr++;
     }
   }
@@ -579,30 +575,28 @@
 }
 
-
 static char hasChildNodes_doc[] = "\
 Returns whether this node has any children.";
 
-static PyObject *node_hasChildNodes(PyNodeObject *self, PyObject *args)
+static PyObject *node_hasChildNodes(NodeObject *self, PyObject *args)
 {
-  PyObject *rt;
+  PyObject *result;
 
   if (!PyArg_ParseTuple(args, ":hasChildNodes"))
     return NULL;
 
-  rt = (Node_HasFlag(self, Node_FLAGS_CONTAINER) &&
-        ContainerNode_GET_COUNT(self) > 0) ? Py_True : Py_False;
+  result = (Node_HasFlag(self, Node_FLAGS_CONTAINER) &&
+            ContainerNode_GET_COUNT(self) > 0) ? Py_True : Py_False;
 
-  Py_INCREF(rt);
-  return rt;
+  Py_INCREF(result);
+  return result;
 }
 
-
 static char removeChild_doc[] = "\
 Removes the child node indicated by oldChild from the list of children, and\n\
 returns it.";
 
-static PyObject *node_removeChild(PyNodeObject *self, PyObject *args)
+static PyObject *node_removeChild(NodeObject *self, PyObject *args)
 {
-  PyNodeObject *oldChild;
+  NodeObject *oldChild;
 
   if (!PyArg_ParseTuple(args, "O!:removeChild", &DomletteNode_Type, &oldChild))
@@ -616,58 +610,10 @@
 }
 
-
-static char isSameNode_doc[] = "\
-Returns whether this node is the same node as the given one. (DOM Level 3)";
-
-static PyObject *node_isSameNode(PyNodeObject *self, PyObject *args)
-{
-  PyNodeObject *other;
-  PyObject *result;
-
-  if (!PyArg_ParseTuple(args, "O!:isSameNode", &DomletteNode_Type, &other))
-    return NULL;
-
-  result = (self == other) ? Py_True : Py_False;
-  Py_INCREF(result);
-  return result;
-}
-
-
-static char xpath_doc[] = "\
-Evaluates an XPath expression string using this node as context.";
-
-static PyObject *node_xpath(PyNodeObject *self, PyObject *args, PyObject *kw)
-{
-  PyObject *expr_text, *xpath_module, *eval, *result;
-  PyObject *explicit_nss = NULL;
-  static char *kwlist[] = {"expr", "explicitNss", NULL};
-
-  if (!PyArg_ParseTupleAndKeywords(args, kw, "O|O:xpath", kwlist,
-                                   &expr_text, &explicit_nss))
-    return NULL;
-
-  if (explicit_nss == NULL){
-    explicit_nss = Py_None;
-    /* No need to Py_INCREF in these circumstances */
-  }
-  xpath_module = PyImport_ImportModule("Ft.Xml.XPath.Util");
-  if (xpath_module == NULL) return NULL;
-  eval = PyObject_GetAttrString(xpath_module, "SimpleEvaluate");
-  Py_DECREF(xpath_module);
-  if (eval == NULL) return NULL;
-  result = PyObject_CallFunction(eval, "OOO", expr_text, self, explicit_nss);
-  Py_DECREF(eval);
-  if (result == NULL) return NULL;
-  /*_PyObject_Dump(result);*/
-  return result;
-}
-
-
 static char appendChild_doc[] = "\
 Adds the node newChild to the end of the list of children of this node.";
 
-static PyObject *node_appendChild(PyNodeObject *self, PyObject *args)
+static PyObject *node_appendChild(NodeObject *self, PyObject *args)
 {
-  PyNodeObject *newChild;
+  NodeObject *newChild;
 
   if (!PyArg_ParseTuple(args,"O!:appendChild", &DomletteNode_Type, &newChild))
@@ -681,11 +627,11 @@
 }
 
-
 static char insertBefore_doc[] = "\
 Inserts the node newChild before the existing child node refChild.";
 
-static PyObject *node_insertBefore(PyNodeObject *self, PyObject *args)
+static PyObject *node_insertBefore(NodeObject *self, PyObject *args)
 {
-  PyNodeObject *newChild, *refChild;
+  NodeObject *newChild;
+  PyObject *refChild;
 
   if (!PyArg_ParseTuple(args, "O!O:insertBefore",
@@ -693,10 +639,10 @@
     return NULL;
 
-  if (refChild != (PyNodeObject *) Py_None && !PyNode_Check(refChild)) {
+  if (refChild != Py_None && !Node_Check(refChild)) {
     PyErr_SetString(PyExc_TypeError, "arg 2 must be Node or None");
     return NULL;
   }
 
-  if (Node_InsertBefore(self, newChild, refChild) == -1)
+  if (Node_InsertBefore(self, newChild, (NodeObject *)refChild) == -1)
     return NULL;
 
@@ -705,145 +651,128 @@
 }
 
-
-static PyObject *get_next_sibling(PyNodeObject *self, void *arg);
-
 static char replaceChild_doc[] = "\
 Replaces the child node oldChild with newChild in the list of children, and\n\
 returns the oldChild node.";
 
-static PyObject *node_replaceChild(PyNodeObject *self, PyObject *args)
+static PyObject *node_replaceChild(NodeObject *self, PyObject *args)
 {
-  PyNodeObject *newChild, *oldChild, *sibling;
+  NodeObject *newChild, *oldChild;
 
-  if(!PyArg_ParseTuple(args,"O!O!:replaceChild",
-                       &DomletteNode_Type, &newChild,
-                       &DomletteNode_Type, &oldChild))
+  if (!PyArg_ParseTuple(args, "O!O!:replaceChild",
+                        &DomletteNode_Type, &newChild,
+                        &DomletteNode_Type, &oldChild))
     return NULL;
 
-#ifdef DEBUG_NODE_REPLACE_CHILD
-  printf("replace child initial state\n");
-  printf("self\n");
-  _PyObject_Dump(self);
-  printf("------------------\n");
-  printf("newChild\n");
-  _PyObject_Dump(newChild);
-  printf("------------------\n");
-  printf("oldChild\n");
-  _PyObject_Dump(oldChild);
-  printf("------------------\n");
-#endif
-
-  sibling = (PyNodeObject *) get_next_sibling(oldChild, NULL);
-
-#ifdef DEBUG_NODE_REPLACE_CHILD
-  printf("sibling\n");
-  _PyObject_Dump(sibling);
-  printf("------------------\n");
-#endif
-
-  /*INC the return value before we call remove incase this is the last reference*/
-  Py_INCREF(oldChild);
-
-  if (Node_RemoveChild(self, (PyNodeObject *)oldChild) == -1) {
+  if (Node_ReplaceChild(self, newChild, oldChild) < 0)
     return NULL;
-  }
 
-#ifdef DEBUG_NODE_REPLACE_CHILD
-  printf("oldChild after remove\n");
-  _PyObject_Dump(oldChild);
-  printf("------------------\n");
-#endif
-
-  /*Now insert it before the sibling (sibling could be Py_None but that is OK)*/
-  if (Node_InsertBefore(self, newChild, sibling) == -1)
-    return NULL;
-
-#ifdef DEBUG_NODE_REPLACE_CHILD
-  printf("newChild after insert\n");
-  _PyObject_Dump(oldChild);
-  printf("------------------\n");
-#endif
-
-  /*DECREF the sibling (getattr added one)*/
-  Py_DECREF(sibling);
-
-#ifdef DEBUG_NODE_REPLACE_CHILD
-  printf("replace child final state\n");
-  printf("self\n");
-  _PyObject_Dump(self);
-  printf("------------------\n");
-  printf("newChild\n");
-  _PyObject_Dump(newChild);
-  printf("------------------\n");
-  printf("oldChild\n");
-  _PyObject_Dump(oldChild);
-  printf("------------------\n");
-  printf("sibling\n");
-  _PyObject_Dump(oldChild);
-  printf("------------------\n");
-#endif
+  Py_INCREF(oldChild);
   return (PyObject *) oldChild;
 }
 
-
 static char cloneNode_doc[] = "\
 Returns a duplicate of this node, i.e., serves as a generic copy\n\
 constructor for nodes.";
 
-static PyObject *node_cloneNode(PyNodeObject *self, PyObject *args)
+static PyObject *node_cloneNode(NodeObject *self, PyObject *args)
 {
-  PyObject *boolean_deep = Py_False;
+  PyObject *deep_obj = Py_False;
   int deep;
-  PyNodeObject *result;
 
-  if (!PyArg_ParseTuple(args,"|O:cloneNode", &boolean_deep))
+  if (!PyArg_ParseTuple(args,"|O:cloneNode", &deep_obj))
     return NULL;
 
-  deep = PyObject_IsTrue(boolean_deep);
+  deep = PyObject_IsTrue(deep_obj);
   if (deep == -1)
     return NULL;
 
-  if (PyDocument_Check(self)) {
-    PyErr_SetString(PyExc_TypeError,"cloneNode not allowed on documents");
+  if (Document_Check(self)) {
+    PyErr_SetString(PyExc_TypeError, "cloneNode not allowed on documents");
     return NULL;
   }
 
-  result = Node_CloneNode((PyObject *) self, deep, Node_GET_DOCUMENT(self));
+  return (PyObject *)Node_CloneNode((PyObject *)self, deep);
+}
+
+static char isSameNode_doc[] = "\
+Returns whether this node is the same node as the given one. (DOM Level 3)";
 
-  return (PyObject *) result;
+static PyObject *node_isSameNode(NodeObject *self, PyObject *args)
+{
+  NodeObject *other;
+  PyObject *result;
+
+  if (!PyArg_ParseTuple(args, "O!:isSameNode", &DomletteNode_Type, &other))
+    return NULL;
+
+  result = (self == other) ? Py_True : Py_False;
+  Py_INCREF(result);
+  return result;
 }
 
-#define PyNode_METHOD(NAME, ARGSPEC) \
+static char xpath_doc[] = "\
+Evaluates an XPath expression string using this node as context.";
+
+static PyObject *node_xpath(NodeObject *self, PyObject *args, PyObject *kw)
+{
+  PyObject *expr, *explicit_nss = Py_None;
+  PyObject *module, *result;
+  static char *kwlist[] = { "expr", "explicitNss", NULL };
+
+  if (!PyArg_ParseTupleAndKeywords(args, kw, "O|O:xpath", kwlist,
+                                   &expr, &explicit_nss))
+    return NULL;
+
+  module = PyImport_ImportModule("Ft.Xml.XPath.Util");
+  if (module == NULL) return NULL;
+  result = PyObject_CallMethod(module, "SimpleEvaluate", "OOO",
+                               expr, self, explicit_nss);
+  Py_DECREF(module);
+  return result;
+}
+
+#define Node_METHOD(NAME, ARGSPEC) \
   { #NAME, (PyCFunction) node_##NAME, ARGSPEC, NAME##_doc }
 
 static struct PyMethodDef node_methods[] = {
-  PyNode_METHOD(normalize,     METH_VARARGS),
-  PyNode_METHOD(hasChildNodes, METH_VARARGS),
-  PyNode_METHOD(removeChild,   METH_VARARGS),
-  PyNode_METHOD(appendChild,   METH_VARARGS),
-  PyNode_METHOD(insertBefore,  METH_VARARGS),
-  PyNode_METHOD(replaceChild,  METH_VARARGS),
-  PyNode_METHOD(cloneNode,     METH_VARARGS),
-  PyNode_METHOD(isSameNode,    METH_VARARGS),
-  PyNode_METHOD(xpath,         METH_VARARGS | METH_KEYWORDS),
+  Node_METHOD(normalize,     METH_VARARGS),
+  Node_METHOD(hasChildNodes, METH_VARARGS),
+  Node_METHOD(removeChild,   METH_VARARGS),
+  Node_METHOD(appendChild,   METH_VARARGS),
+  Node_METHOD(insertBefore,  METH_VARARGS),
+  Node_METHOD(replaceChild,  METH_VARARGS),
+  Node_METHOD(cloneNode,     METH_VARARGS),
+  Node_METHOD(isSameNode,    METH_VARARGS),
+  Node_METHOD(xpath,         METH_KEYWORDS),
   { NULL }
 };
 
-
 /** Python Members ****************************************************/
 
+#define Node_MEMBER(NAME) \
+  { #NAME, T_OBJECT, offsetof(NodeObject, NAME), RO }
 
 static struct PyMemberDef node_members[] = {
-  { "parentNode",    T_OBJECT, offsetof(PyNodeObject, parentNode),    RO },
-  { "ownerDocument", T_OBJECT, offsetof(PyNodeObject, ownerDocument), RO },
-  { "rootNode",      T_OBJECT, offsetof(PyNodeObject, ownerDocument), RO },
+  Node_MEMBER(parentNode),
   { NULL }
 };
 
-
 /** Python Computed Members ********************************************/
 
+static PyObject *get_owner_document(NodeObject *self, void *arg)
+{
+  PyObject *node = (PyObject *)self;
+  while (!Document_Check(node)) {
+    node = (PyObject *) Node_GET_PARENT(node);
+    if (node == NULL) {
+      Py_INCREF(Py_None);
+      return Py_None;
+    }
+  }
+  Py_INCREF(node);
+  return node;
+}
 
-static PyObject *get_child_nodes(PyNodeObject *self, void *arg)
+static PyObject *get_child_nodes(NodeObject *self, void *arg)
 {
   register Py_ssize_t i;
@@ -867,20 +796,19 @@
 }
 
-
-static PyObject *get_base_uri(PyNodeObject *self, void *arg)
+static PyObject *get_base_uri(NodeObject *self, void *arg)
 {
-  PyNodeObject *node = self;
+  NodeObject *node = self;
   PyObject *base, *result;
 
   /* DOM3 baseURI is calculated according to XML Base */
 
-  while (Node_GET_PARENT(node) != (PyNodeObject *) Py_None) {
+  while (Node_GET_PARENT(node) != NULL) {
     /* 1. the base URI specified by an xml:base attribute on the element,
      *    if one exists, otherwise
      */
-    if (PyElement_Check(node)) {
-      base = PyDict_GetItem(PyElement_ATTRIBUTES(node), xml_base_key);
+    if (Element_Check(node)) {
+      base = PyDict_GetItem(Element_GET_ATTRIBUTES(node), xml_base_key);
       if (base) {
-        base = PyAttr_NODE_VALUE(base);
+        base = Attr_GET_NODE_VALUE(base);
         /* If the xml:base in scope for the current node is not absolute, we find
          * the element where that xml:base was declared, then Absolutize our
@@ -920,9 +848,6 @@
    *    element.
    */
-  if (PyDocumentFragment_Check(node)) {
-    node = (PyNodeObject *) Node_GET_DOCUMENT(node);
-  }
-  if (PyDocument_Check(node)) {
-    base = PyDocument_BASE_URI(node);
+  if (Document_Check(node)) {
+    base = Document_GET_DOCUMENT_URI(node);
     result = PyObject_CallFunction(is_absolute_function, "O", base);
     if (result == NULL) return NULL;
@@ -945,49 +870,42 @@
 }
 
-
-static PyObject *get_first_child(PyNodeObject *self, void *arg)
+static PyObject *get_first_child(NodeObject *self, void *arg)
 {
   PyObject *child;
 
   if (Node_HasFlag(self, Node_FLAGS_CONTAINER) &&
-      ContainerNode_GET_COUNT(self))
+      ContainerNode_GET_COUNT(self)) {
     child = (PyObject *) ContainerNode_GET_CHILD(self, 0);
-  else
+  } else {
     child = Py_None;
-
+  }
   Py_INCREF(child);
   return child;
 }
 
-
-static PyObject *get_last_child(PyNodeObject *self, void *arg)
+static PyObject *get_last_child(NodeObject *self, void *arg)
 {
   PyObject *child;
-  int size;
 
-  if (Node_HasFlag(self, Node_FLAGS_CONTAINER))
-    size = ContainerNode_GET_COUNT(self);
-  else
-    size = 0;
-
-  if (size)
-    child = (PyObject *) ContainerNode_GET_CHILD(self, size - 1);
-  else
+  if (Node_HasFlag(self, Node_FLAGS_CONTAINER) &&
+      ContainerNode_GET_COUNT(self)) {
+    child = (PyObject *)
+      ContainerNode_GET_CHILD(self, ContainerNode_GET_COUNT(self) - 1);
+  } else {
     child = Py_None;
-
+  }
   Py_INCREF(child);
   return child;
 }
 
-
-static PyObject *get_next_sibling(PyNodeObject *self, void *arg)
+static PyObject *get_next_sibling(NodeObject *self, void *arg)
 {
-  PyNodeObject *parentNode;
-  PyNodeObject **nodes;
+  NodeObject *parentNode;
+  NodeObject **nodes;
   PyObject *sibling;
-  int count, index;
+  Py_ssize_t count, index;
 
   parentNode = self->parentNode;
-  if (parentNode == (PyNodeObject *) Py_None) {
+  if (parentNode == NULL) {
     Py_INCREF(Py_None);
     return Py_None;
@@ -1012,14 +930,13 @@
 }
 
-
-static PyObject *get_previous_sibling(PyNodeObject *self, void *arg)
+static PyObject *get_previous_sibling(NodeObject *self, void *arg)
 {
-  PyNodeObject *parentNode;
-  PyNodeObject **nodes;
+  NodeObject *parentNode;
+  NodeObject **nodes;
   PyObject *sibling;
-  int count, index;
+  Py_ssize_t count, index;
 
   parentNode = self->parentNode;
-  if (parentNode == (PyNodeObject *) Py_None) {
+  if (parentNode == NULL) {
     Py_INCREF(Py_None);
     return Py_None;
@@ -1042,13 +959,13 @@
 }
 
-
 /* This is defined as a function to prevent corruption of shared "NodeList" */
-static PyObject *get_empty_list(PyNodeObject *self, void *arg)
+static PyObject *get_empty_list(NodeObject *self, void *arg)
 {
-  return PyList_New((Py_ssize_t)0);
+  return PyList_New(0);
 }
 
-
 static struct PyGetSetDef node_getset[] = {
+  { "ownerDocument",   (getter)get_owner_document },
+  { "rootNode",        (getter)get_owner_document },
   { "childNodes",      (getter)get_child_nodes },
   { "baseURI",         (getter)get_base_uri },
@@ -1063,36 +980,22 @@
 };
 
-
 /** Type Object ********************************************************/
 
-
-static PyObject *node_repr(PyNodeObject *self)
+static PyObject *node_repr(NodeObject *self)
 {
-  PyObject *name, *repr;
-
-  name = PyObject_GetAttrString((PyObject *)self->ob_type, "__name__");
-  if (name == NULL) {
-    return NULL;
-  }
-
-  repr = PyString_FromFormat("<%s at %p>", PyString_AS_STRING(name), self);
-  Py_DECREF(name);
-
-  return repr;
+  return PyString_FromFormat("<%s at %p>", self->ob_type->tp_name, self);
 }
 
-
-static int node_traverse(PyNodeObject *self, visitproc visit, void *arg)
+static int node_traverse(NodeObject *self, visitproc visit, void *arg)
 {
 #ifdef DEBUG_NODE_CREATION
-  printf("Traversing %s node at 0x%p\n", self->ob_type->tp_name, self);
+  printf("Traversing %s node at %p\n", self->ob_type->tp_name, self);
 #endif
-
-  Py_VISIT((PyObject *) self->ownerDocument);
+  Py_VISIT((PyObject *)Node_GET_PARENT(self));
   if (self->flags & Node_FLAGS_CONTAINER) {
-    PyNodeObject **nodes = ContainerNode_GET_NODES(self);
-    int i = ContainerNode_GET_COUNT(self);
+    NodeObject **nodes = ContainerNode_GET_NODES(self);
+    Py_ssize_t i = ContainerNode_GET_COUNT(self);
     while (--i >= 0) {
-      int rt = visit((PyObject *) nodes[i], arg);
+      int rt = visit((PyObject *)nodes[i], arg);
       if (rt) return rt;
     }
@@ -1101,20 +1004,27 @@
 }
 
-
-static int node_clear(PyObject *self)
+static int node_clear(NodeObject *self)
 {
 #ifdef DEBUG_NODE_CREATION
-  printf("Clearing %s node at 0x%p\n", self->ob_type->tp_name, self);
+  printf("Clearing %s node at %p\n", self->ob_type->tp_name, self);
 #endif
-
-  Py_CLEAR(((PyNodeObject *)self)->ownerDocument);
-  if (((PyNodeObject *)self)->flags & Node_FLAGS_CONTAINER) {
-    node_clear_nodes((PyContainerNodeObject *) self);
+  Py_CLEAR(Node_GET_PARENT(self));
+  if (Node_HasFlag(self, Node_FLAGS_CONTAINER)) {
+    NodeObject **nodes = ContainerNode_GET_NODES(self);
+    Py_ssize_t i = ContainerNode_GET_COUNT(self);
+    if (nodes != NULL) {
+      ContainerNode_SET_NODES(self, NULL);
+      ContainerNode_SET_COUNT(self, 0);
+      ContainerNode_SET_ALLOCATED(self, 0);
+      while (--i >= 0) {
+        Py_DECREF(nodes[i]);
+      }
+      PyMem_Free(nodes);
+    }
   }
   return 0;
 }
 
-
-static long node_hash(PyNodeObject *self)
+static long node_hash(NodeObject *self)
 {
 #if SIZEOF_LONG >= SIZEOF_VOID_P
@@ -1149,13 +1059,12 @@
 #define NODESTR(node) PyString_AS_STRING(PyObject_Repr(node))
 
-static PyObject *node_richcompare(PyNodeObject *a, PyNodeObject *b, int op)
+static PyObject *node_richcompare(NodeObject *a, NodeObject *b, int op)
 {
-  PyObject *result;
-  PyDocumentObject *doc_a, *doc_b;
-  PyNodeObject *parent_a, *parent_b;
+  PyObject *doc_a, *doc_b, *result;
+  NodeObject *parent_a, *parent_b;
   int depth_a, depth_b;
 
   /* Make sure both arguments are cDomlette nodes */
-  if (!(PyNode_Check(a) && PyNode_Check(b))) {
+  if (!(Node_Check(a) && Node_Check(b))) {
     Py_INCREF(Py_NotImplemented);
     return Py_NotImplemented;
@@ -1179,21 +1088,9 @@
   }
 
-  /* if different documents; just compare their creation indices */
-  doc_a = PyDocument_Check(a) ? (PyDocumentObject *) a
-                              : PyNode_OWNER_DOCUMENT(a);
-  doc_b = PyDocument_Check(b) ? (PyDocumentObject *) b
-                              : PyNode_OWNER_DOCUMENT(b);
-  if (doc_a != doc_b) {
-    return PyObject_RichCompare(PyDocument_INDEX(doc_a),
-                                PyDocument_INDEX(doc_b),
-                                op);
-  }
-
-  /* traverse to the top of each tree (document, document fragment, element
-     or the node itself)
+  /* traverse to the top of each tree (document, element or the node itself)
   */
   parent_a = a;
   depth_a = 0;
-  while (Node_GET_PARENT(parent_a) != (PyNodeObject *) Py_None) {
+  while (Node_GET_PARENT(parent_a)) {
     parent_a = Node_GET_PARENT(parent_a);
     depth_a++;
@@ -1202,11 +1099,18 @@
   parent_b = b;
   depth_b = 0;
-  while (Node_GET_PARENT(parent_b) != (PyNodeObject *) Py_None) {
+  while (Node_GET_PARENT(parent_b)) {
     parent_b = Node_GET_PARENT(parent_b);
     depth_b++;
   }
 
-  /* there is a dangling tree (not appended to the document yet) */
-  if (parent_a != parent_b) {
+  /* compare the top of each tree; for Documents use the creation index,
+   * otherwise None for trees not rooted in a Document. If both trees do
+   * not have a Document root, fall back to default Python comparison. */
+  doc_a = Document_Check(parent_a) ? Document_GET_INDEX(parent_a) : Py_None;
+  doc_b = Document_Check(parent_b) ? Document_GET_INDEX(parent_b) : Py_None;
+  if (doc_a != doc_b) {
+    return PyObject_RichCompare(doc_a, doc_b, op);
+  }
+  else if (parent_a != parent_b) {
     Py_INCREF(Py_NotImplemented);
     return Py_NotImplemented;
@@ -1215,6 +1119,6 @@
   /* if neither node is a document (depth>0), find the nodes common ancestor */
   if (depth_a > 0 && depth_b > 0) {
-    PyNodeObject **nodes;
-    int i, len;
+    NodeObject **nodes;
+    Py_ssize_t i, count;
 
     /* traverse to the same depth in the tree for both nodes */
@@ -1241,6 +1145,6 @@
       depth_a = depth_b = -1;
       nodes = ContainerNode_GET_NODES(parent_a);
-      len = ContainerNode_GET_COUNT(parent_a);
-      for (i = 0; i < len; i++) {
+      count = ContainerNode_GET_COUNT(parent_a);
+      for (i = 0; i < count; i++) {
         if (nodes[i] == a)
           depth_a = i;
@@ -1283,7 +1187,5 @@
 }
 
-
-static PyObject *node_iter(PyNodeObject *node);
-
+static PyObject *node_iter(NodeObject *node);
 
 static char node_doc[] = "\
@@ -1294,5 +1196,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "Node",
-  /* tp_basicsize      */ sizeof(PyNodeObject),
+  /* tp_basicsize      */ sizeof(NodeObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) _Node_Del,
@@ -1316,5 +1218,5 @@
   /* tp_doc            */ (char *) node_doc,
   /* tp_traverse       */ (traverseproc) node_traverse,
-  /* tp_clear          */ node_clear,
+  /* tp_clear          */ (inquiry) node_clear,
   /* tp_richcompare    */ (richcmpfunc) node_richcompare,
   /* tp_weaklistoffset */ 0,
@@ -1340,11 +1242,11 @@
 typedef struct {
   PyObject_HEAD
-  long index;
-  PyNodeObject *node; /* NULL when iterator is done */
+  Py_ssize_t index;
+  NodeObject *node; /* NULL when iterator is done */
 } NodeIterObject;
 
 static PyTypeObject NodeIter_Type;
 
-static PyObject *node_iter(PyNodeObject *node)
+static PyObject *node_iter(NodeObject *node)
 {
   NodeIterObject *iter;
@@ -1391,14 +1293,10 @@
 static PyObject *nodeiter_next(NodeIterObject *iter)
 {
-  PyNodeObject *node;
-  PyObject *item;
-
-  node = iter->node;
+  NodeObject *node = iter->node;
   if (node == NULL)
     return NULL;
 
   if (iter->index < ContainerNode_GET_COUNT(node)) {
-    item = (PyObject *) ContainerNode_GET_CHILD(node, iter->index);
-    iter->index++;
+    PyObject *item = (PyObject *) ContainerNode_GET_CHILD(node, iter->index++);
     Py_INCREF(item);
     return item;
@@ -1410,20 +1308,4 @@
 }
 
-static Py_ssize_t nodeiter_length(PyObject *iter)
-{
-  Py_ssize_t len;
-  if (((NodeIterObject *)iter)->node) {
-    len = ContainerNode_GET_COUNT(((NodeIterObject *)iter)->node) - ((NodeIterObject *)iter)->index;
-    if (len >= 0)
-      return len;
-  }
-  return 0;
-}
-
-static PySequenceMethods nodeiter_as_sequence = {
-  /* sq_length */ nodeiter_length,
-};
-
-
 static PyTypeObject NodeIter_Type = {
   /* PyObject_HEAD     */ PyObject_HEAD_INIT(NULL)
@@ -1439,5 +1321,5 @@
   /* tp_repr           */ (reprfunc) 0,
   /* tp_as_number      */ (PyNumberMethods *) 0,
-  /* tp_as_sequence    */ (PySequenceMethods *) &nodeiter_as_sequence,
+  /* tp_as_sequence    */ (PySequenceMethods *) 0,
   /* tp_as_mapping     */ (PyMappingMethods *) 0,
   /* tp_hash           */ (hashfunc) 0,
@@ -1451,5 +1333,5 @@
   /* tp_doc            */ (char *) 0,
   /* tp_traverse       */ (traverseproc) nodeiter_traverse,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -1458,8 +1340,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteNode_Init(PyObject *module)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/node.h.diff?r1=1.21&r2=1.22
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/node.h?rev=1.22&content-type=text/vnd.viewcvs-markup

Index: node.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/node.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -U2 -r1.21 -r1.22
--- node.h	24 Nov 2006 21:36:39 -0000	1.21
+++ node.h	21 Dec 2006 06:13:36 -0000	1.22
@@ -9,42 +9,38 @@
 #include "nodetype.h"
 
-  /* PyNode_HEAD defines the initial segment of every Domlette node. */
-#define PyNode_HEAD                    \
+  /* Node_HEAD defines the initial segment of every Domlette node. */
+#define Node_HEAD                      \
     PyObject_HEAD                      \
     long flags;                        \
-    struct PyNodeObject *parentNode;   \
-    struct PyDocumentObject *ownerDocument;
+    struct NodeObject *parentNode;
 
-#define PyContainerNode_HEAD           \
-    PyNode_HEAD                        \
-    int count;                         \
-    struct PyNodeObject **nodes;       \
-    int allocated;
+#define ContainerNode_HEAD             \
+    Node_HEAD                          \
+    Py_ssize_t count;                  \
+    struct NodeObject **nodes;         \
+    Py_ssize_t allocated;
 
 #include "document.h"
 
-  /* Nothing is actually declared to be a PyNodeObject, but every pointer to
-   * a Domlette object can be cast to a PyNodeObject*.  This is inheritance
+  /* Nothing is actually declared to be a NodeObject, but every pointer to
+   * a Domlette object can be cast to a NodeObject*.  This is inheritance
    * built by hand.
    */
-  typedef struct PyNodeObject {
-    PyNode_HEAD
-  } PyNodeObject;
+  typedef struct NodeObject {
+    Node_HEAD
+  } NodeObject;
+
+  typedef struct ContainerNodeObject {
+    ContainerNode_HEAD
+  } ContainerNodeObject;
 
-  typedef struct PyContainerNodeObject {
-    PyContainerNode_HEAD
-  } PyContainerNodeObject;
-
-#define PyNode_OWNER_DOCUMENT(op) (((PyNodeObject *)(op))->ownerDocument)
-
-#define Node_GET_PARENT(op) (((PyNodeObject *)(op))->parentNode)
+#define Node_GET_PARENT(op) (((NodeObject *)(op))->parentNode)
 #define Node_SET_PARENT(op, v) (Node_GET_PARENT(op) = (v))
-#define Node_GET_DOCUMENT(op) (((PyNodeObject *)(op))->ownerDocument)
 
-#define ContainerNode_GET_COUNT(op) (((PyContainerNodeObject *)(op))->count)
+#define ContainerNode_GET_COUNT(op) (((ContainerNodeObject *)(op))->count)
 #define ContainerNode_GET_CHILD(op, i)          \
-  (((PyContainerNodeObject *)(op))->nodes[i])
+  (((ContainerNodeObject *)(op))->nodes[i])
 
-  /* PyNodeObject Creatation */
+  /* NodeObject Creatation */
 #define Node_FLAGS_CONTAINER (1L<<0)
 
@@ -57,6 +53,6 @@
   extern PyTypeObject DomletteNode_Type;
 
-#define PyNode_Check(op) PyObject_TypeCheck((op), &DomletteNode_Type)
-#define PyNode_CheckExact(op) ((op)->ob_type == &DomletteNode_Type)
+#define Node_Check(op) PyObject_TypeCheck((op), &DomletteNode_Type)
+#define Node_CheckExact(op) ((op)->ob_type == &DomletteNode_Type)
 
   /* Module Methods */
@@ -64,34 +60,34 @@
   void DomletteNode_Fini(void);
 
-#define _Node_INIT_FLAGS(op, doc, f) \
+#define _Node_INIT_FLAGS(op, f) \
   ( (op)->flags = (f), \
-    (op)->parentNode = (PyNodeObject *) Py_None, \
-    (op)->ownerDocument = (doc), Py_INCREF(doc) )
+    (op)->parentNode = NULL )
 
-#define _Node_INIT(op, doc) \
-  _Node_INIT_FLAGS((op), (doc), 0)
-#define _Node_INIT_CONTAINER(op, doc) \
+#define _Node_INIT(op) \
+  _Node_INIT_FLAGS((op), 0)
+#define _Node_INIT_CONTAINER(op) \
   ( (op)->count = 0, (op)->allocated = 0, (op)->nodes = NULL, \
-    _Node_INIT_FLAGS((op), (doc), Node_FLAGS_CONTAINER) )
+    _Node_INIT_FLAGS((op), Node_FLAGS_CONTAINER) )
 
-  PyNodeObject *_Node_New(PyTypeObject *type, PyDocumentObject *ownerDocument,
-                          long flags);
-#define Node_New(type, typeobj, ownerdoc) \
-  ((type *) _Node_New((typeobj), (ownerdoc), 0))
-#define Node_NewContainer(type, typeobj, ownerdoc) \
-  ((type *) _Node_New((typeobj), (ownerdoc), Node_FLAGS_CONTAINER))
+  NodeObject *_Node_New(PyTypeObject *type, long flags);
+#define Node_New(type, typeobj) \
+  ((type *) _Node_New((typeobj), 0))
+#define Node_NewContainer(type, typeobj) \
+  ((type *) _Node_New((typeobj), Node_FLAGS_CONTAINER))
 
-  void _Node_Del(PyNodeObject *node);
-#define Node_Del(obj) _Node_Del((PyNodeObject *)(obj))
+  void _Node_Del(NodeObject *node);
+#define Node_Del(obj) _Node_Del((NodeObject *)(obj))
 
-  int _Node_SetChildren(PyNodeObject *self, PyNodeObject **children, int size);
+  int _Node_SetChildren(NodeObject *self, NodeObject **children,
+                        Py_ssize_t size);
 
   /* DOM Node Methods */
-  int Node_RemoveChild(PyNodeObject *self, PyNodeObject *oldChild);
-  int Node_AppendChild(PyNodeObject *self, PyNodeObject *newChild);
-  int Node_InsertBefore(PyNodeObject *self, PyNodeObject *newChild,
-                        PyNodeObject *refChild);
-  PyNodeObject *Node_CloneNode(PyObject *node, int deep,
-			       PyDocumentObject *newOwnerDocument);
+  int Node_RemoveChild(NodeObject *self, NodeObject *oldChild);
+  int Node_AppendChild(NodeObject *self, NodeObject *newChild);
+  int Node_InsertBefore(NodeObject *self, NodeObject *newChild,
+                        NodeObject *refChild);
+  int Node_ReplaceChild(NodeObject *self, NodeObject *newChild,
+                        NodeObject *oldChild);
+  NodeObject *Node_CloneNode(PyObject *node, int deep);
 
 #endif /* Domlette_BUILDING_MODULE */
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/nss.c.diff?r1=1.10&r2=1.11
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/nss.c?rev=1.11&content-type=text/vnd.viewcvs-markup

Index: nss.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/nss.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -U2 -r1.10 -r1.11
--- nss.c	24 Nov 2006 21:36:39 -0000	1.10
+++ nss.c	21 Dec 2006 06:13:36 -0000	1.11
@@ -19,9 +19,9 @@
 }
 
-static int get_all_ns_domlette(PyNodeObject *node, PyObject *nss)
+static int get_all_ns_domlette(NodeObject *node, PyObject *nss)
 {
   int res = 0;
 
-  if (PyElement_Check(node)) {
+  if (Element_Check(node)) {
     PyObject *key, *attr;
     PyObject *namespaceURI, *prefix;
@@ -29,10 +29,10 @@
 
     /* get the prefix */
-    prefix = get_prefix(PyElement_NODE_NAME(node));
+    prefix = get_prefix(Element_GET_NODE_NAME(node));
     if (prefix == NULL) return -1;
 
     /* add the declaration if prefix is not already defined */
     if (PyDict_GetItem(nss, prefix) == NULL) {
-      if (PyDict_SetItem(nss, prefix, PyElement_NAMESPACE_URI(node)) < 0) {
+      if (PyDict_SetItem(nss, prefix, Element_GET_NAMESPACE_URI(node)) < 0) {
         Py_DECREF(prefix);
         return -1;
@@ -43,20 +43,19 @@
     /* now process this element's attributes */
     i = 0;
-    while (PyDict_Next(PyElement_ATTRIBUTES(node), &i, &key, &attr)) {
+    while (PyDict_Next(Element_GET_ATTRIBUTES(node), &i, &key, &attr)) {
+      namespaceURI = Attr_GET_NAMESPACE_URI(attr);
       /* get the prefix/namespaceURI pair to add */
-      switch (PyObject_RichCompareBool(PyAttr_NAMESPACE_URI(attr),
-                                       g_xmlnsNamespace, Py_EQ)) {
+      switch (PyObject_RichCompareBool(namespaceURI, g_xmlnsNamespace, Py_EQ)) {
       case 0:
         /* normal attribute */
-        namespaceURI = PyAttr_NAMESPACE_URI(attr);
-        prefix = get_prefix(PyAttr_NODE_NAME(attr));
+        prefix = get_prefix(Attr_GET_NODE_NAME(attr));
         if (prefix == NULL) return -1;
         break;
       case 1:
         /* namespace attribute */
-        namespaceURI = PyAttr_NODE_VALUE(attr);
-        if (PyUnicode_AS_UNICODE(PyAttr_NODE_NAME(attr))[5] == ':') {
+        namespaceURI = Attr_GET_NODE_VALUE(attr);
+        if (PyUnicode_AS_UNICODE(Attr_GET_NODE_NAME(attr))[5] == ':') {
           /* xmlns:foo = 'namespaceURI' */
-          prefix = PyAttr_LOCAL_NAME(attr);
+          prefix = Attr_GET_LOCAL_NAME(attr);
         } else {
           /* xmlns = 'namespaceURI' */
@@ -89,5 +88,5 @@
   }
 
-  if (Node_GET_PARENT(node) != (PyNodeObject *) Py_None) {
+  if (Node_GET_PARENT(node)) {
     res = get_all_ns_domlette(Node_GET_PARENT(node), nss);
   }
@@ -97,19 +96,19 @@
 
 
-static PyObject *seek_nss_domlette(PyNodeObject *node, PyObject *nss)
+static PyObject *seek_nss_domlette(NodeObject *node, PyObject *nss)
 {
   Py_ssize_t i;
   PyObject *key, *attr;
 
-  if (PyElement_Check(node)) {
+  if (Element_Check(node)) {
     PyObject *prefix;
 
     /* get the prefix */
-    prefix = get_prefix(PyElement_NODE_NAME(node));
+    prefix = get_prefix(Element_GET_NODE_NAME(node));
     if (prefix == NULL) return NULL;
 
     /* don't replace existing ns decls */
     if (PyDict_GetItem(nss, prefix) == NULL) {
-      if (PyDict_SetItem(nss, prefix, PyElement_NAMESPACE_URI(node)) < 0) {
+      if (PyDict_SetItem(nss, prefix, Element_GET_NAMESPACE_URI(node)) < 0) {
         Py_DECREF(prefix);
         return NULL;
@@ -120,22 +119,21 @@
     /* now process this element's attributes */
     i = 0;
-    while (PyDict_Next(PyElement_ATTRIBUTES(node), &i, &key, &attr)) {
+    while (PyDict_Next(Element_GET_ATTRIBUTES(node), &i, &key, &attr)) {
       PyObject *namespaceURI, *prefix;
 
       /* get the prefix/namespaceURI pair to add */
-      switch (PyObject_RichCompareBool(PyAttr_NAMESPACE_URI(attr),
-                                       g_xmlnsNamespace, Py_EQ)) {
+      namespaceURI = Attr_GET_NAMESPACE_URI(attr);
+      switch (PyObject_RichCompareBool(namespaceURI, g_xmlnsNamespace, Py_EQ)) {
       case 0:
         /* normal attribute */
-        namespaceURI = PyAttr_NAMESPACE_URI(attr);
-        prefix = get_prefix(PyAttr_NODE_NAME(attr));
+        prefix = get_prefix(Attr_GET_NODE_NAME(attr));
         if (prefix == NULL) return NULL;
         break;
       case 1:
         /* namespace attribute */
-        namespaceURI = PyAttr_NODE_VALUE(attr);
-        if (PyUnicode_AS_UNICODE(PyAttr_NODE_NAME(attr))[5] == ':') {
+        namespaceURI = Attr_GET_NODE_VALUE(attr);
+        if (PyUnicode_AS_UNICODE(Attr_GET_NODE_NAME(attr))[5] == ':') {
           /* xmlns:foo = 'namespaceURI' */
-          prefix = PyAttr_LOCAL_NAME(attr);
+          prefix = Attr_GET_LOCAL_NAME(attr);
         } else {
           /* xmlns = 'namespaceURI' */
@@ -166,5 +164,5 @@
       Py_DECREF(prefix);
     }
-  } else if (!PyDocument_Check(node)) {
+  } else if (!Document_Check(node)) {
     /* non-container node */
     return nss;
@@ -172,6 +170,6 @@
 
   for (i = 0; i < ContainerNode_GET_COUNT(node); i++) {
-    PyNodeObject *child = ContainerNode_GET_CHILD(node, i);
-    if (PyElement_Check(child)) {
+    NodeObject *child = ContainerNode_GET_CHILD(node, i);
+    if (Element_Check(child)) {
       if (seek_nss_domlette(child, nss) == NULL) {
         return NULL;
@@ -508,5 +506,5 @@
 /** Public Methods ****************************************************/
 
-PyObject *Domlette_GetNamespaces(PyNodeObject *node)
+PyObject *Domlette_GetNamespaces(NodeObject *node)
 {
   PyObject *nss;
@@ -517,5 +515,5 @@
 
   /* add the XML namespace */
-  prefix = PyUnicode_DecodeASCII("xml", (Py_ssize_t)3, NULL);
+  prefix = XmlString_FromASCII("xml");
   if (prefix == NULL) {
     Py_DECREF(nss);
@@ -564,5 +562,5 @@
 
   /* add the XML namespace */
-  prefix = PyUnicode_DecodeASCII("xml", (Py_ssize_t)3, NULL);
+  prefix = XmlString_FromASCII("xml");
   if (prefix == NULL) {
     Py_DECREF(nss);
@@ -576,6 +574,6 @@
   Py_DECREF(prefix);
 
-  if (PyNode_Check(node))
-    result = get_all_ns_domlette((PyNodeObject *) node, nss);
+  if (Node_Check(node))
+    result = get_all_ns_domlette((NodeObject *) node, nss);
   else
     result = get_all_ns_dom(node, nss);
@@ -614,6 +612,6 @@
   if (nss == NULL) return NULL;
 
-  if (PyNode_Check(node))
-    result = seek_nss_domlette((PyNodeObject *)node, nss);
+  if (Node_Check(node))
+    result = seek_nss_domlette((NodeObject *)node, nss);
   else
     result = seek_nss_dom(node, nss);
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/nss.h.diff?r1=1.4&r2=1.5
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/nss.h?rev=1.5&content-type=text/vnd.viewcvs-markup

Index: nss.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/nss.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -U2 -r1.4 -r1.5
--- nss.h	16 Dec 2004 22:45:37 -0000	1.4
+++ nss.h	21 Dec 2006 06:13:36 -0000	1.5
@@ -7,6 +7,7 @@
 
 #include "Python.h"
+#include "node.h"
 
-  PyObject *Domlette_GetNamespaces(PyNodeObject *node);
+  PyObject *Domlette_GetNamespaces(NodeObject *node);
 
   extern char GetAllNs_doc[];
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/parse_event_handler.c.diff?r1=1.70&r2=1.71
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/parse_event_handler.c?rev=1.71&content-type=text/vnd.viewcvs-markup

Index: parse_event_handler.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/parse_event_handler.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -U2 -r1.70 -r1.71
--- parse_event_handler.c	25 Nov 2006 02:57:48 -0000	1.70
+++ parse_event_handler.c	21 Dec 2006 06:13:36 -0000	1.71
@@ -8,14 +8,14 @@
 typedef struct _context {
   struct _context *next;
-  PyNodeObject *node;
+  NodeObject *node;
 
-  PyNodeObject **children;
-  int children_allocated;
-  int children_size;
+  NodeObject **children;
+  Py_ssize_t children_allocated;
+  Py_ssize_t children_size;
 } Context;
 
 typedef struct {
   ExpatParser parser;
-  PyDocumentObject *owner_document;
+  DocumentObject *owner_document;
 
   Context *context;
@@ -33,9 +33,7 @@
 static PyObject *gc_isenabled_function;
 
-
 /** Context ************************************************************/
 
-
-static Context *Context_New(PyNodeObject *node)
+static Context *Context_New(NodeObject *node)
 {
   Context *self = PyMem_New(Context, 1);
@@ -48,5 +46,5 @@
   self->node = node;
 
-  self->children = PyMem_New(PyNodeObject *, INITIAL_CHILDREN);
+  self->children = PyMem_New(NodeObject *, INITIAL_CHILDREN);
   if (self->children == NULL) {
     PyErr_NoMemory();
@@ -58,8 +56,7 @@
 }
 
-
 static void Context_Del(Context *self)
 {
-  int i;
+  Py_ssize_t i;
 
   /* This will only be set when an error has occurred, so it must be freed. */
@@ -80,10 +77,7 @@
 }
 
-
 /** ParserState ********************************************************/
 
-
-static ParserState *ParserState_New(PyDocumentObject *doc,
-                                    PyNodeObject *rootNode)
+static ParserState *ParserState_New(DocumentObject *doc)
 {
   ParserState *self = PyMem_New(ParserState, 1);
@@ -94,5 +88,5 @@
 
   /* context */
-  if ((self->context = Context_New(rootNode)) == NULL) {
+  if ((self->context = Context_New((NodeObject *)doc)) == NULL) {
     PyMem_Free(self);
     return NULL;
@@ -102,4 +96,5 @@
   self->new_namespaces = NULL;
 
+  Py_INCREF(doc);
   self->owner_document = doc;
 
@@ -107,5 +102,4 @@
 }
 
-
 static void ParserState_Del(ParserState *self)
 {
@@ -113,20 +107,13 @@
     Context_Del(self->context);
   }
-
   if (self->free_context) {
     Context_Del(self->free_context);
   }
-
-  if (self->new_namespaces) {
-    Py_DECREF(self->new_namespaces);
-  }
-
-  Py_DECREF(self->owner_document);
-
+  Py_CLEAR(self->new_namespaces);
+  Py_CLEAR(self->owner_document);
   PyMem_Free(self);
 }
 
-
-static Context *ParserState_AddContext(ParserState *self, PyNodeObject *node)
+static Context *ParserState_AddContext(ParserState *self, NodeObject *node)
 {
   Context *context = self->free_context;
@@ -147,5 +134,4 @@
 }
 
-
 static void ParserState_FreeContext(ParserState *self)
 {
@@ -165,10 +151,9 @@
 }
 
-
-static int ParserState_AddNode(ParserState *self, PyNodeObject *node)
+static int ParserState_AddNode(ParserState *self, NodeObject *node)
 {
   Context *context = self->context;
-  PyNodeObject **children;
-  int newsize;
+  NodeObject **children;
+  Py_ssize_t newsize;
 
   if (node == NULL || context == NULL) {
@@ -177,5 +162,5 @@
 #else
     PyErr_BadInternalCall();
-    return 0;
+    return -1;
 #endif
   }
@@ -185,8 +170,8 @@
   newsize = context->children_size + 1;
   if (newsize >= context->children_allocated) {
-    int new_allocated = newsize << 1;
-    if (PyMem_Resize(children, PyNodeObject *, new_allocated) == NULL) {
+    size_t new_allocated = newsize << 1;
+    if (PyMem_Resize(children, NodeObject *, new_allocated) == NULL) {
       PyErr_NoMemory();
-      return 0;
+      return -1;
     }
     context->children = children;
@@ -197,11 +182,9 @@
   children[context->children_size] = node;
   context->children_size = newsize;
-  return 1;
+  return 0;
 }
 
-
 /** handlers ***********************************************************/
 
-
 static ExpatStatus builder_EndDocument(void *userState)
 {
@@ -224,5 +207,4 @@
 }
 
-
 static ExpatStatus builder_StartNamespaceDecl(void *userState,
                                               PyObject *prefix,
@@ -251,5 +233,5 @@
        Fixes SF#834917
     */
-    uri = PyUnicode_FromUnicode(NULL, (Py_ssize_t)0);
+    uri = PyUnicode_FromUnicode(NULL, 0);
     if (uri == NULL) {
       return EXPAT_STATUS_ERROR;
@@ -273,5 +255,5 @@
 {
   ParserState *state = (ParserState *)userState;
-  PyElementObject *elem = NULL;
+  ElementObject *elem = NULL;
   Py_ssize_t i;
   PyObject *key, *value;
@@ -293,6 +275,5 @@
 #endif
 
-  elem = Element_New(state->owner_document, name->namespaceURI,
-                     name->qualifiedName, name->localName);
+  elem = Element_New(name->namespaceURI, name->qualifiedName, name->localName);
   if (elem == NULL) {
     return EXPAT_STATUS_ERROR;
@@ -307,5 +288,5 @@
     i = 0;
     while (PyDict_Next(state->new_namespaces, &i, &key, &value)) {
-      PyAttrObject *nsattr;
+      AttrObject *nsattr;
       if (key != Py_None) {
         prefix = xmlns_string;
@@ -339,5 +320,5 @@
 
   for (i = 0; i < atts_len; i++) {
-    PyAttrObject *attr;
+    AttrObject *attr;
     attr = Element_SetAttributeNS(elem, atts[i].namespaceURI,
                                   atts[i].qualifiedName, atts[i].localName,
@@ -355,5 +336,5 @@
 
   /* save states on the context */
-  if (ParserState_AddContext(state, (PyNodeObject *) elem) == NULL) {
+  if (ParserState_AddContext(state, (NodeObject *) elem) == NULL) {
     Py_DECREF(elem);
     return EXPAT_STATUS_ERROR;
@@ -367,5 +348,5 @@
   ParserState *state = (ParserState *)userState;
   Context *context = state->context;
-  PyNodeObject *node;
+  NodeObject *node;
 
 #ifdef DEBUG_PARSER
@@ -387,5 +368,6 @@
 
   /* ParserState_AddNode steals the reference to the new node */
-  if (ParserState_AddNode(state, node) == 0) {
+  if (ParserState_AddNode(state, node) < 0) {
+    Py_DECREF(node);
     return EXPAT_STATUS_ERROR;
   }
@@ -397,5 +379,5 @@
 {
   ParserState *state = (ParserState *)userState;
-  PyNodeObject *node;
+  NodeObject *node;
 
 #ifdef DEBUG_PARSER
@@ -405,8 +387,9 @@
 #endif
 
-  node = (PyNodeObject *) Text_New(state->owner_document, data);
+  node = (NodeObject *) Text_New(data);
 
   /* ParserState_AddNode steals the reference to the new node */
-  if (ParserState_AddNode(state, node) == 0) {
+  if (ParserState_AddNode(state, node) < 0) {
+    Py_DECREF(node);
     return EXPAT_STATUS_ERROR;
   }
@@ -420,5 +403,5 @@
 {
   ParserState *state = (ParserState *)userState;
-  PyNodeObject *node;
+  NodeObject *node;
 
 #ifdef DEBUG_PARSER
@@ -430,9 +413,9 @@
 #endif
 
-  node = (PyNodeObject *) ProcessingInstruction_New(state->owner_document,
-                                                    target, data);
+  node = (NodeObject *) ProcessingInstruction_New(target, data);
 
   /* ParserState_AddNode steals the reference to the new node */
-  if (ParserState_AddNode(state, node) == 0) {
+  if (ParserState_AddNode(state, node) < 0) {
+    Py_DECREF(node);
     return EXPAT_STATUS_ERROR;
   }
@@ -444,5 +427,5 @@
 {
   ParserState *state = (ParserState *)userState;
-  PyNodeObject *node;
+  NodeObject *node;
 
 #ifdef DEBUG_PARSER
@@ -452,8 +435,9 @@
 #endif
 
-  node = (PyNodeObject *) Comment_New(state->owner_document, data);
+  node = (NodeObject *) Comment_New(data);
 
   /* ParserState_AddNode steals the reference to the new node */
-  if (ParserState_AddNode(state, node) == 0) {
+  if (ParserState_AddNode(state, node) < 0) {
+    Py_DECREF(node);
     return EXPAT_STATUS_ERROR;
   }
@@ -544,6 +528,5 @@
 {
   ParserState *state;
-  PyDocumentObject *document;
-  PyNodeObject *rootNode;
+  DocumentObject *document;
   PyObject *uri, *strip_elements;
   PyObject *temp;
@@ -567,20 +550,8 @@
   }
 
-  if (asEntity) {
-    rootNode = (PyNodeObject *) DocumentFragment_New(document);
-    if (rootNode == NULL) {
-      Py_DECREF(document);
-      return NULL;
-    }
-  } else {
-    Py_INCREF(document);
-    rootNode = (PyNodeObject *) document;
-  }
-
-  /* Takes ownership of both nodes */
-  state = ParserState_New(document, rootNode);
+  /* Takes ownership of `document` */
+  state = ParserState_New(document);
   if (state == NULL) {
     Py_DECREF(document);
-    Py_DECREF(rootNode);
     return NULL;
   }
@@ -657,5 +628,5 @@
 
   if (status == EXPAT_STATUS_OK)
-    return (PyObject *) rootNode;
+    return (PyObject *) document;
   else
     return NULL;
@@ -679,5 +650,5 @@
   PyObject *import;
 
-  xmlns_string = PyUnicode_DecodeASCII("xmlns", (Py_ssize_t)5, NULL);
+  xmlns_string = XmlString_FromASCII("xmlns");
   if (xmlns_string == NULL) return -1;
 
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/parse_event_handler.h.diff?r1=1.13&r2=1.14
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/parse_event_handler.h?rev=1.14&content-type=text/vnd.viewcvs-markup

Index: parse_event_handler.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/parse_event_handler.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -U2 -r1.13 -r1.14
--- parse_event_handler.h	15 Nov 2005 02:22:40 -0000	1.13
+++ parse_event_handler.h	21 Dec 2006 06:13:36 -0000	1.14
@@ -8,4 +8,6 @@
 #include "Python.h"
 
+#ifdef Domlette_BUILDING_MODULE
+
   typedef enum {
     PARSE_TYPE_STANDALONE = 0,
@@ -19,5 +21,7 @@
   int DomletteBuilder_Init(PyObject *module);
   void DomletteBuilder_Fini(void);
-  
+
+#endif /* Domlette_BUILDING_MODULE */
+
 #ifdef __cplusplus
 }
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/processinginstruction.c.diff?r1=1.27&r2=1.28
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/processinginstruction.c?rev=1.28&content-type=text/vnd.viewcvs-markup

Index: processinginstruction.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/processinginstruction.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -U2 -r1.27 -r1.28
--- processinginstruction.c	24 Nov 2006 21:36:39 -0000	1.27
+++ processinginstruction.c	21 Dec 2006 06:13:36 -0000	1.28
@@ -1,12 +1,10 @@
 #include "domlette.h"
 
-
 /** Private Routines **************************************************/
 
-
-static int pi_init(PyProcessingInstructionObject *self,
+static int pi_init(ProcessingInstructionObject *self,
                    PyObject *target, PyObject *data)
 {
-  if ((self == NULL || !PyProcessingInstruction_Check(self)) ||
+  if ((self == NULL || !ProcessingInstruction_Check(self)) ||
       (target == NULL || !XmlString_Check(target)) ||
       (data == NULL || !XmlString_Check(data))) {
@@ -24,15 +22,13 @@
 }
 
-
 /** Public C API ******************************************************/
 
-
-PyProcessingInstructionObject *ProcessingInstruction_New(
-  PyDocumentObject *ownerDocument, PyObject *target, PyObject *data)
+ProcessingInstructionObject *ProcessingInstruction_New(PyObject *target,
+                                                       PyObject *data)
 {
-  PyProcessingInstructionObject *self;
+  ProcessingInstructionObject *self;
 
-  self = Node_New(PyProcessingInstructionObject,
-                  &DomletteProcessingInstruction_Type, ownerDocument);
+  self = Node_New(ProcessingInstructionObject,
+                  &DomletteProcessingInstruction_Type);
   if (self != NULL) {
     if (pi_init(self, target, data) < 0) {
@@ -47,10 +43,9 @@
 }
 
-
-PyProcessingInstructionObject *ProcessingInstruction_CloneNode(
-  PyObject *node, int deep, PyDocumentObject *newOwnerDocument)
+ProcessingInstructionObject *ProcessingInstruction_CloneNode(PyObject *node,
+                                                             int deep)
 {
   PyObject *nodeValue, *target;
-  PyProcessingInstructionObject *newNode;
+  ProcessingInstructionObject *newNode;
 
   nodeValue = PyObject_GetAttrString(node, "nodeValue");
@@ -64,5 +59,5 @@
   }
 
-  newNode = ProcessingInstruction_New(newOwnerDocument, target, nodeValue);
+  newNode = ProcessingInstruction_New(target, nodeValue);
   Py_DECREF(target);
   Py_DECREF(nodeValue);
@@ -71,25 +66,27 @@
 }
 
-
 /** Python Methods ****************************************************/
 
+#define ProcessingInstruction_METHOD(name) \
+  { #name, (PyCFunction) pi_##name, METH_VARARGS, pi_##name##_doc }
 
-/* No additional interface methods defined */
-
+static struct PyMethodDef pi_methods[] = {
+  { NULL }
+};
 
 /** Python Members ****************************************************/
 
+#define ProcessingInstruction_MEMBER(name, member) \
+  { #name, T_OBJECT, offsetof(ProcessingInstructionObject, member), RO }
 
 static struct PyMemberDef pi_members[] = {
-  { "target",   T_OBJECT, offsetof(PyProcessingInstructionObject, nodeName), RO },
-  { "nodeName", T_OBJECT, offsetof(PyProcessingInstructionObject, nodeName), RO },
+  ProcessingInstruction_MEMBER(target, nodeName),
+  ProcessingInstruction_MEMBER(nodeName, nodeName),
   { NULL }
 };
 
-
 /** Python Computed Members *******************************************/
 
-
-static PyObject *get_data(PyProcessingInstructionObject *self, void *arg)
+static PyObject *get_data(ProcessingInstructionObject *self, void *arg)
 {
   Py_INCREF(self->nodeValue);
@@ -97,9 +94,7 @@
 }
 
-
-static int set_data(PyProcessingInstructionObject *self, PyObject *v,
-                    void *arg)
+static int set_data(ProcessingInstructionObject *self, PyObject *v, char *arg)
 {
-  PyObject *nodeValue = XmlString_ConvertArgument(v, (char *)arg, 0);
+  PyObject *nodeValue = XmlString_ConvertArgument(v, arg, 0);
   if (nodeValue == NULL) return -1;
 
@@ -109,5 +104,4 @@
 }
 
-
 static struct PyGetSetDef pi_getset[] = {
   { "data",      (getter)get_data, (setter)set_data, NULL, "data" },
@@ -116,27 +110,19 @@
 };
 
-
 /** Type Object *******************************************************/
 
-
-static void pi_dealloc(PyProcessingInstructionObject *self)
+static void pi_dealloc(ProcessingInstructionObject *self)
 {
   PyObject_GC_UnTrack((PyObject *)self);
-
-  Py_XDECREF(self->nodeName);
-  self->nodeName = NULL;
-
-  Py_XDECREF(self->nodeValue);
-  self->nodeValue = NULL;
-
+  Py_CLEAR(self->nodeName);
+  Py_CLEAR(self->nodeValue);
   Node_Del(self);
 }
 
-
-static PyObject *pi_repr(PyProcessingInstructionObject *pi)
+static PyObject *pi_repr(ProcessingInstructionObject *self)
 {
   PyObject *repr;
-  PyObject *target = PyObject_Repr(pi->nodeName);
-  PyObject *data = PyObject_Repr(pi->nodeValue);
+  PyObject *target = PyObject_Repr(self->nodeName);
+  PyObject *data = PyObject_Repr(self->nodeValue);
   if (target == NULL || data == NULL) {
     Py_XDECREF(target);
@@ -144,8 +130,7 @@
     return NULL;
   }
-  repr = PyString_FromFormat("<ProcessingInstruction at %p: target %s, data %s>",
-                             pi,
-                             PyString_AS_STRING(target),
-                             PyString_AS_STRING(data));
+  repr = PyString_FromFormat(
+    "<ProcessingInstruction at %p: target %s, data %s>",
+    self, PyString_AsString(target), PyString_AsString(data));
   Py_DECREF(target);
   Py_DECREF(data);
@@ -153,15 +138,12 @@
 }
 
-
 static PyObject *pi_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-  PyDocumentObject *doc;
   PyObject *target, *data;
-  static char *kwlist[] = { "ownerDocument", "target", "data", NULL };
-  PyProcessingInstructionObject *self;
+  static char *kwlist[] = { "target", "data", NULL };
+  ProcessingInstructionObject *self;
 
-  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!OO:ProcessingInstruction",
-                                   kwlist, &DomletteDocument_Type, &doc,
-                                   &target, &data)) {
+  if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:ProcessingInstruction",
+                                   kwlist, &target, &data)) {
     return NULL;
   }
@@ -177,7 +159,7 @@
 
   if (type != &DomletteProcessingInstruction_Type) {
-    self = (PyProcessingInstructionObject *) type->tp_alloc(type, 0);
+    self = ProcessingInstruction(type->tp_alloc(type, 0));
     if (self != NULL) {
-      _Node_INIT(self, doc);
+      _Node_INIT(self);
       if (pi_init(self, target, data) < 0) {
         Py_DECREF(self);
@@ -186,5 +168,5 @@
     }
   } else {
-    self = ProcessingInstruction_New(doc, target, data);
+    self = ProcessingInstruction_New(target, data);
   }
   Py_DECREF(data);
@@ -194,7 +176,6 @@
 }
 
-
 static char pi_doc[] = "\
-ProcessingInstruction(ownerDocument, target, data) -> ProcessingInstruction\n\
+ProcessingInstruction(target, data) -> ProcessingInstruction\n\
 \n\
 The ProcessingInstruction interface represents a \"processing instruction\",\n\
@@ -202,10 +183,9 @@
 the document.";
 
-
 PyTypeObject DomletteProcessingInstruction_Type = {
   /* PyObject_HEAD     */ PyObject_HEAD_INIT(NULL)
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "ProcessingInstruction",
-  /* tp_basicsize      */ sizeof(PyProcessingInstructionObject),
+  /* tp_basicsize      */ sizeof(ProcessingInstructionObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) pi_dealloc,
@@ -228,10 +208,10 @@
   /* tp_doc            */ (char *) pi_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
   /* tp_iter           */ (getiterfunc) 0,
   /* tp_iternext       */ (iternextfunc) 0,
-  /* tp_methods        */ (PyMethodDef *) 0,
+  /* tp_methods        */ (PyMethodDef *) pi_methods,
   /* tp_members        */ (PyMemberDef *) pi_members,
   /* tp_getset         */ (PyGetSetDef *) pi_getset,
@@ -247,8 +227,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteProcessingInstruction_Init(PyObject *module)
 {
@@ -272,5 +250,4 @@
 }
 
-
 void DomletteProcessingInstruction_Fini(void)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/processinginstruction.h.diff?r1=1.12&r2=1.13
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/processinginstruction.h?rev=1.13&content-type=text/vnd.viewcvs-markup

Index: processinginstruction.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/processinginstruction.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -U2 -r1.12 -r1.13
--- processinginstruction.h	24 Nov 2006 21:36:39 -0000	1.12
+++ processinginstruction.h	21 Dec 2006 06:13:36 -0000	1.13
@@ -10,13 +10,14 @@
 
   typedef struct {
-    PyNode_HEAD
+    Node_HEAD
     PyObject *nodeName;
     PyObject *nodeValue;
-  } PyProcessingInstructionObject;
+  } ProcessingInstructionObject;
 
+#define ProcessingInstruction(op) ((ProcessingInstructionObject *)(op))
 #define ProcessingInstruction_GET_TARGET(op) \
-(((PyProcessingInstructionObject *)(op))->nodeName)
+  (ProcessingInstruction(op)->nodeName)
 #define ProcessingInstruction_GET_DATA(op) \
-(((PyProcessingInstructionObject *)(op))->nodeValue)
+  (ProcessingInstruction(op)->nodeValue)
 
 #ifdef Domlette_BUILDING_MODULE
@@ -24,8 +25,8 @@
   extern PyTypeObject DomletteProcessingInstruction_Type;
 
-#define PyProcessingInstruction_Check(op) \
-PyObject_TypeCheck(op, &DomletteProcessingInstruction_Type)
-#define PyProcessingInstruction_CheckExact(op) \
-((op)->ob_type == &DomletteProcessingInstruction_Type)
+#define ProcessingInstruction_Check(op) \
+  PyObject_TypeCheck(op, &DomletteProcessingInstruction_Type)
+#define ProcessingInstruction_CheckExact(op) \
+  ((op)->ob_type == &DomletteProcessingInstruction_Type)
 
   /* Module Methods */
@@ -34,9 +35,9 @@
 
   /* ProcessingInstruction Methods */
-  PyProcessingInstructionObject *ProcessingInstruction_New(
-    PyDocumentObject *ownerDocument, PyObject *target, PyObject *data);
+  ProcessingInstructionObject *ProcessingInstruction_New(PyObject *target,
+                                                         PyObject *data);
 
-  PyProcessingInstructionObject *ProcessingInstruction_CloneNode(
-    PyObject *node, int deep, PyDocumentObject *newOwnerDocument);
+  ProcessingInstructionObject *ProcessingInstruction_CloneNode(PyObject *node,
+                                                               int deep);
 
 #endif /* Domlette_BUILDING_MODULE */
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/refcounts.c.diff?r1=1.5&r2=1.6
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/refcounts.c?rev=1.6&content-type=text/vnd.viewcvs-markup

Index: refcounts.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/refcounts.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -U2 -r1.5 -r1.6
--- refcounts.c	15 Sep 2006 16:53:27 -0000	1.5
+++ refcounts.c	21 Dec 2006 06:13:36 -0000	1.6
@@ -18,10 +18,11 @@
   Py_DECREF(rv);
 
-  rv = PyObject_CallMethod(tester, "compare", "ll", expected, actual);
+  rv = PyObject_CallMethod(tester, "compare", PY_ARG_SSIZE_T PY_ARG_SSIZE_T,
+                           expected, actual);
   if (rv == NULL)
     return 0;
   Py_DECREF(rv);
 
-  rv = PyObject_CallMethod(tester, "testDone", "");
+  rv = PyObject_CallMethod(tester, "testDone", NULL);
   if (rv == NULL)
     return 0;
@@ -31,5 +32,5 @@
 }
 
-static int node_refcounts(PyObject *tester, PyNodeObject *node,
+static int node_refcounts(PyObject *tester, NodeObject *node,
                           Py_ssize_t *counter)
 {
@@ -40,19 +41,18 @@
   (*counter)++;
 
-  if (PyElement_Check(node)) {
+  if (Element_Check(node)) {
     Py_ssize_t i;
-    PyObject *k;
-    PyNodeObject *v;
+    PyObject *k, *v;
 
     /* test element's children */
     for (i = 0; i < ContainerNode_GET_COUNT(node); i++) {
-      v = ContainerNode_GET_CHILD(node, i);
-      if (node_refcounts(tester, v, counter) == 0) return 0;
+      v = (PyObject *) ContainerNode_GET_CHILD(node, i);
+      if (node_refcounts(tester, (NodeObject *)v, counter) == 0) return 0;
     }
 
     /* test element's attributes */
     i = 0;
-    while (PyDict_Next(PyElement_ATTRIBUTES(node), &i, &k, (PyObject **)&v)) {
-      if (node_refcounts(tester, v, counter) == 0) return 0;
+    while (PyDict_Next(Element_GET_ATTRIBUTES(node), &i, &k, &v)) {
+      if (node_refcounts(tester, (NodeObject *)v, counter) == 0) return 0;
     }
 
@@ -60,22 +60,22 @@
     expected = 1;
   }
-  else if (PyText_Check(node)) {
+  else if (Text_Check(node)) {
     /* refcount = this */
     expected = 1;
   }
-  else if (PyComment_Check(node)) {
+  else if (Comment_Check(node)) {
     /* refcount = this */
     expected = 1;
   }
-  else if (PyAttr_Check(node)) {
+  else if (Attr_Check(node)) {
     /* refcount = this */
     expected = 1;
   }
-  else if (PyProcessingInstruction_Check(node)) {
+  else if (ProcessingInstruction_Check(node)) {
     /* refcount = this */
     expected = 1;
   }
   else {
-    sprintf(buf, "Unexpected object type '%.200s'" ,node->ob_type->tp_name);
+    sprintf(buf, "Unexpected object type '%.200s'", node->ob_type->tp_name);
     Py_XDECREF(PyObject_CallMethod(tester, "error", "s", buf));
     return 0;
@@ -96,6 +96,6 @@
 
   for (i = 0; i < ContainerNode_GET_COUNT(doc); i++) {
-    PyNodeObject *node = ContainerNode_GET_CHILD(doc, i);
-    if (node_refcounts(tester, (PyNodeObject *)node, &expected) == 0) return 0;
+    NodeObject *node = ContainerNode_GET_CHILD(doc, i);
+    if (node_refcounts(tester, node, &expected) == 0) return 0;
   }
 
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/text.c.diff?r1=1.26&r2=1.27
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/text.c?rev=1.27&content-type=text/vnd.viewcvs-markup

Index: text.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/text.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -U2 -r1.26 -r1.27
--- text.c	24 Nov 2006 21:36:39 -0000	1.26
+++ text.c	21 Dec 2006 06:13:36 -0000	1.27
@@ -1,7 +1,7 @@
 #include "domlette.h"
 
-
 /** Private Routines **************************************************/
 
+/* nothing to see here */
 
 /** Public C API *******************************************************/
@@ -10,43 +10,37 @@
 
 #undef Text_New
-PyTextObject *Text_New(PyDocumentObject *ownerDocument, PyObject *data)
+TextObject *Text_New(PyObject *data)
 {
-  return CharacterData_New(PyTextObject, &DomletteText_Type,
-                           ownerDocument, data);
+  return CharacterData_New(TextObject, &DomletteText_Type, data);
 }
 
 #undef Text_CloneNode
-PyTextObject *Text_CloneNode(PyObject *node, int deep,
-                             PyDocumentObject *newOwnerDocument)
+TextObject *Text_CloneNode(PyObject *node, int deep)
 {
-  return CharacterData_CloneNode(PyTextObject, &DomletteText_Type,
-                                 node, deep, newOwnerDocument);
+  return CharacterData_CloneNode(TextObject, &DomletteText_Type, node, deep);
 }
 
-
-
 /** Python Methods ****************************************************/
 
+static PyMethodDef text_methods[] = {
+  { NULL }
+};
 
-/* No additional interface methods defined */
-
-
-/** Python Members ****************************************************/
-
-
-/* No additional interface members defined */
+/** Python Members *****************************************************/
 
+static PyMethodDef text_members[] = {
+  { NULL }
+};
 
 /** Python Computed Members ********************************************/
 
-
-/* No additional interface members defined */
-
+static PyGetSetDef text_getset[] = {
+  { NULL }
+};
 
 /** Type Object ********************************************************/
 
-
 static char text_doc[] = "\
-Text(ownerDocument, data) -> Text object\n\
+Text(data) -> Text object\n\
 \n\
 This interface represents the contents of a text node.";
@@ -56,5 +50,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "Text",
-  /* tp_basicsize      */ sizeof(PyTextObject),
+  /* tp_basicsize      */ sizeof(TextObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) 0,
@@ -77,12 +71,12 @@
   /* tp_doc            */ (char *) text_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
   /* tp_iter           */ (getiterfunc) 0,
   /* tp_iternext       */ (iternextfunc) 0,
-  /* tp_methods        */ (PyMethodDef *) 0,
-  /* tp_members        */ (PyMemberDef *) 0,
-  /* tp_getset         */ (PyGetSetDef *) 0,
+  /* tp_methods        */ (PyMethodDef *) text_methods,
+  /* tp_members        */ (PyMemberDef *) text_members,
+  /* tp_getset         */ (PyGetSetDef *) text_getset,
   /* tp_base           */ (PyTypeObject *) 0,
   /* tp_dict           */ (PyObject *) 0,
@@ -96,8 +90,6 @@
 };
 
-
 /** Module Setup & Teardown *******************************************/
 
-
 int DomletteText_Init(PyObject *module)
 {
@@ -117,5 +109,5 @@
   Py_DECREF(value);
 
-  value = PyUnicode_DecodeASCII("#text", (Py_ssize_t)5, NULL);
+  value = XmlString_FromASCII("#text");
   if (value == NULL)
     return -1;
@@ -131,5 +123,4 @@
 }
 
-
 void DomletteText_Fini(void)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/text.h.diff?r1=1.11&r2=1.12
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/text.h?rev=1.12&content-type=text/vnd.viewcvs-markup

Index: text.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/text.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -U2 -r1.11 -r1.12
--- text.h	24 Nov 2006 21:36:39 -0000	1.11
+++ text.h	21 Dec 2006 06:13:36 -0000	1.12
@@ -9,7 +9,8 @@
 #include "characterdata.h"
 
-  typedef PyCharacterDataObject PyTextObject;
+  typedef CharacterDataObject TextObject;
 
-#define Text_GET_DATA(op) PyCharacterData_NODE_VALUE(op)
+#define Text(op) ((TextObject *)(op))
+#define Text_GET_DATA(op) CharacterData_GET_NODE_VALUE(op)
 #define Text_SET_DATA(op, v) (Text_GET_DATA(op) = (v))
 
@@ -18,6 +19,6 @@
   extern PyTypeObject DomletteText_Type;
 
-#define PyText_Check(op) PyObject_TypeCheck(op, &DomletteText_Type)
-#define PyText_CheckExact(op) ((op)->ob_type == &DomletteText_Type)
+#define Text_Check(op) PyObject_TypeCheck((op), &DomletteText_Type)
+#define Text_CheckExact(op) ((op)->ob_type == &DomletteText_Type)
 
   /* Module Methods */
@@ -26,14 +27,11 @@
 
   /* Text Methods */
-  PyTextObject *Text_New(PyDocumentObject *ownerDocument, PyObject *data);
-#define Text_New(ownerDocument, data) \
-  CharacterData_New(PyTextObject, &DomletteText_Type, \
-                    (ownerDocument), (data))
-
-  PyTextObject *Text_CloneNode(PyObject *node, int deep,
-                               PyDocumentObject *ownerDocument);
-#define Text_CloneNode(node, deep, newOwnerDocument) \
-  CharacterData_CloneNode(PyTextObject, &DomletteText_Type, (node), \
-                         (deep), (newOwnerDocument))
+  TextObject *Text_New(PyObject *data);
+#define Text_New(data) \
+  CharacterData_New(TextObject, &DomletteText_Type, (data))
+
+  TextObject *Text_CloneNode(PyObject *node, int deep);
+#define Text_CloneNode(node, deep) \
+  CharacterData_CloneNode(TextObject, &DomletteText_Type, (node), (deep))
 
 #endif /* Domlette_BUILDING_MODULE */
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/xmlparser.c.diff?r1=1.33&r2=1.34
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/xmlparser.c?rev=1.34&content-type=text/vnd.viewcvs-markup

Index: xmlparser.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/xmlparser.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -U2 -r1.33 -r1.34
--- xmlparser.c	25 Nov 2006 02:57:48 -0000	1.33
+++ xmlparser.c	21 Dec 2006 06:13:36 -0000	1.34
@@ -88,5 +88,5 @@
   PyObject *whitespace_rules;
   PyObject *yield_result;
-  PyNodeObject *dom_node;
+  NodeObject *dom_node;
   PyObject *decl_handler;
   PyObject *lexical_handler;
@@ -129,4 +129,5 @@
 typedef struct {
   PyObject_HEAD
+  XMLParserObject *parser;
   PyObject *uri;
   PyObject *stream;
@@ -134,9 +135,10 @@
 } InputSourceObject;
 
-static PyObject *InputSource_New(PyObject *uri, PyObject *stream,
-                                 PyObject *encoding);
+static PyObject *InputSource_New(XMLParserObject *parser, PyObject *uri,
+                                 PyObject *stream, PyObject *encoding);
 
 static void InputSource_Del(InputSourceObject *self)
 {
+  Py_DECREF(self->parser);
   Py_DECREF(self->uri);
   Py_DECREF(self->stream);
@@ -160,5 +162,5 @@
 
   Py_INCREF(Py_None);
-  return InputSource_New(uri, stream, Py_None);
+  return InputSource_New(self->parser, uri, stream, Py_None);
 }
 
@@ -221,5 +223,5 @@
   /* tp_doc            */ (char *) 0,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -240,6 +242,6 @@
 };
 
-static PyObject *InputSource_New(PyObject *uri, PyObject *stream,
-                                 PyObject *encoding)
+static PyObject *InputSource_New(XMLParserObject *parser, PyObject *uri,
+                                 PyObject *stream, PyObject *encoding)
 {
   InputSourceObject *self;
@@ -247,4 +249,6 @@
   self = PyObject_New(InputSourceObject, &InputSource_Type);
   if (self) {
+    Py_INCREF(parser);
+    self->parser = parser;
     self->uri = uri;
     self->stream = stream;
@@ -883,5 +887,5 @@
 
   if (handler != NULL) {
-    /* handler.comment(content) */
+    /* handler.notationDecl(name, publicId, systemId) */
     if ((args = PyTuple_New(3)) == NULL) return EXPAT_STATUS_ERROR;
     PyTuple_SET_ITEM(args, 0, name);
@@ -911,5 +915,5 @@
 
   if (handler != NULL) {
-    /* handler.comment(content) */
+    /* handler.unparsedEntityDecl(name, publicId, systemId, notationName) */
     if ((args = PyTuple_New(4)) == NULL) return EXPAT_STATUS_ERROR;
     PyTuple_SET_ITEM(args, 0, name);
@@ -978,5 +982,5 @@
 
   if (handler != NULL) {
-    /* handler.warning(exception) */
+    /* handler.error(exception) */
     if ((args = PyTuple_New(1)) == NULL) {
       Py_DECREF(exception);
@@ -1007,5 +1011,5 @@
 
   if (handler != NULL) {
-    /* handler.warning(exception) */
+    /* handler.fatalError(exception) */
     if ((args = PyTuple_New(1)) == NULL) {
       Py_DECREF(exception);
@@ -1034,5 +1038,5 @@
 
   if (handler != NULL) {
-    /* handler.comment(content) */
+    /* handler.elementDecl(name, model) */
     if ((args = PyTuple_New(2)) == NULL) return EXPAT_STATUS_ERROR;
     PyTuple_SET_ITEM(args, 0, name);
@@ -1058,5 +1062,5 @@
 
   if (handler != NULL) {
-    /* handler.comment(content) */
+    /* handler.attributeDecl(eName, aName, type, decl, value) */
     if ((args = PyTuple_New(5)) == NULL) return EXPAT_STATUS_ERROR;
     PyTuple_SET_ITEM(args, 0, eName);
@@ -1087,5 +1091,5 @@
 
   if (handler != NULL) {
-    /* handler.comment(content) */
+    /* handler.internalEntityDecl(name, value) */
     if ((args = PyTuple_New(2)) == NULL) return EXPAT_STATUS_ERROR;
     PyTuple_SET_ITEM(args, 0, name);
@@ -1112,5 +1116,5 @@
 
   if (handler != NULL) {
-    /* handler.comment(content) */
+    /* handler.externalEntityDecl(name, publicId, systemId) */
     if ((args = PyTuple_New(3)) == NULL) return EXPAT_STATUS_ERROR;
     PyTuple_SET_ITEM(args, 0, name);
@@ -1129,4 +1133,30 @@
 }
 
+static PyObject *parser_ResolveEntity(void *userData, PyObject *publicId,
+                                      PyObject *systemId)
+{
+  XMLParserObject *self = (XMLParserObject *) userData;
+  PyObject *handler = self->handlers[Handler_ResolveEntity];
+  PyObject *args, *result;
+
+  assert(handler != NULL);
+
+  /* handler.resolveEntity(publicId, systemId) */
+  if ((args = PyTuple_New(2)) == NULL) {
+    return EXPAT_STATUS_ERROR;
+  }
+  PyTuple_SET_ITEM(args, 0, publicId);
+  Py_INCREF(publicId); /* SET_ITEM steals reference */
+  PyTuple_SET_ITEM(args, 1, systemId);
+  Py_INCREF(systemId); /* SET_ITEM steals reference */
+
+  result = call_with_frame(getcode(ResolveEntity), handler, args);
+  Py_DECREF(args);
+  if (result == NULL) {
+    return EXPAT_STATUS_ERROR;
+  }
+  return result;
+}
+
 /** DOMWalker *********************************************************/
 
@@ -1148,9 +1178,9 @@
 
 static int domwalker_visit(XMLParserObject *parser,
-                           PyNodeObject *node,
+                           NodeObject *node,
                            PyObject *current_namespaces,
                            int preserve_whitespace)
 {
-  if (PyElement_Check(node)) {
+  if (Element_Check(node)) {
     AttributesObject *attrs;
     PyObject *new_namespaces, *prefixes, *namespaceURI, *prefix;
@@ -1174,10 +1204,10 @@
     /* Create expat-style attribute names and trim out namespaces */
     i = 0;
-    while (PyDict_Next(PyElement_ATTRIBUTES(node), &i, &key, &value)) {
+    while (PyDict_Next(Element_GET_ATTRIBUTES(node), &i, &key, &value)) {
       PyObject *nodeName, *localName, *nodeValue, *expandedName;
-      namespaceURI = PyAttr_NAMESPACE_URI(value);
-      nodeName = PyAttr_NODE_NAME(value);
-      localName = PyAttr_LOCAL_NAME(value);
-      nodeValue = PyAttr_NODE_VALUE(value);
+      namespaceURI = Attr_GET_NAMESPACE_URI(value);
+      nodeName = Attr_GET_NODE_NAME(value);
+      localName = Attr_GET_LOCAL_NAME(value);
+      nodeValue = Attr_GET_NODE_VALUE(value);
 
       /* get the prefix/namespaceURI pair to add */
@@ -1202,5 +1232,5 @@
         }
 
-        expandedName = PyTuple_New((Py_ssize_t)2);
+        expandedName = PyTuple_New(2);
         if (expandedName == NULL) {
           Py_DECREF(new_namespaces);
@@ -1249,6 +1279,6 @@
 
     /* DOM doesn't need separate namespace declarations */
-    namespaceURI = PyElement_NAMESPACE_URI(node);
-    prefix = get_prefix(PyElement_NODE_NAME(node));
+    namespaceURI = Element_GET_NAMESPACE_URI(node);
+    prefix = get_prefix(Element_GET_NODE_NAME(node));
     if (prefix == NULL) {
       Py_DECREF(new_namespaces);
@@ -1273,5 +1303,5 @@
       return 0;
     }
-    prefixes = PyList_New((Py_ssize_t)0);
+    prefixes = PyList_New(0);
     if (prefixes == NULL) {
       Py_DECREF(current_namespaces);
@@ -1311,7 +1341,7 @@
     if (handler != NULL) {
       args = Py_BuildValue("(OO)OO",
-                           PyElement_NAMESPACE_URI(node),
-                           PyElement_LOCAL_NAME(node),
-                           PyElement_NODE_NAME(node),
+                           Element_GET_NAMESPACE_URI(node),
+                           Element_GET_LOCAL_NAME(node),
+                           Element_GET_NODE_NAME(node),
                            attrs);
       if (args == NULL) {
@@ -1336,10 +1366,10 @@
     preserve_whitespace =
       Expat_IsWhitespacePreserving(parser->parser,
-                                   PyElement_NAMESPACE_URI(node),
-                                   PyElement_LOCAL_NAME(node));
+                                   Element_GET_NAMESPACE_URI(node),
+                                   Element_GET_LOCAL_NAME(node));
 
     /* process the children */
     for (i = 0; i < ContainerNode_GET_COUNT(node); i++) {
-      PyNodeObject *child = ContainerNode_GET_CHILD(node, i);
+      NodeObject *child = ContainerNode_GET_CHILD(node, i);
       if (domwalker_visit(parser, child, current_namespaces,
                           preserve_whitespace) == 0) {
@@ -1354,7 +1384,7 @@
     if (handler != NULL) {
       args = Py_BuildValue("(OO)O",
-                           PyElement_NAMESPACE_URI(node),
-                           PyElement_LOCAL_NAME(node),
-                           PyElement_NODE_NAME(node));
+                           Element_GET_NAMESPACE_URI(node),
+                           Element_GET_LOCAL_NAME(node),
+                           Element_GET_NODE_NAME(node));
       if (args == NULL) {
         Py_DECREF(current_namespaces);
@@ -1383,5 +1413,5 @@
     Py_DECREF(prefixes);
   }
-  else if (PyText_Check(node)) {
+  else if (Text_Check(node)) {
     PyObject *data = Text_GET_DATA(node);
     if (preserve_whitespace || !XmlString_IsSpace(data)) {
@@ -1406,5 +1436,5 @@
 
   for (i = 0; i < ContainerNode_GET_COUNT(parser->dom_node); i++) {
-    PyNodeObject *node = ContainerNode_GET_CHILD(parser->dom_node, i);
+    NodeObject *node = ContainerNode_GET_CHILD(parser->dom_node, i);
     if (domwalker_visit(parser, node, namespaces, 1) == 0) {
       Py_DECREF(namespaces);
@@ -1505,5 +1535,5 @@
   /* tp_doc            */ (char *) saxgen_doc,
   /* tp_traverse       */ (traverseproc) saxgen_traverse,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -1545,5 +1575,5 @@
 #define Py_XMLPARSER_MEMBER(NAME, TYPE) Py_MEMBER(NAME, TYPE, XMLParserObject)
 
-static PyObject *prepareInputSource(PyObject *source)
+static PyObject *prepareInputSource(XMLParserObject *parser, PyObject *source)
 {
   int rc;
@@ -1563,5 +1593,5 @@
       return NULL;
     }
-    source = InputSource_New(systemId, byteStream, encoding);
+    source = InputSource_New(parser, systemId, byteStream, encoding);
   }
   /* check for 4Suite InputSource */
@@ -1585,5 +1615,5 @@
     }
     Py_INCREF(source);
-    source = InputSource_New(systemId, source, encoding);
+    source = InputSource_New(parser, systemId, source, encoding);
   }
   /* check for URL */
@@ -1595,5 +1625,5 @@
     Py_INCREF(source);
     Py_INCREF(Py_None);
-    source = InputSource_New(source, byteStream, Py_None);
+    source = InputSource_New(parser, source, byteStream, Py_None);
   }
   else {
@@ -1605,4 +1635,5 @@
 }
 
+
 XMLPARSER_METHOD_DOC(getContentHandler) = \
 "getContentHandler()\n\
@@ -1639,6 +1670,9 @@
     return NULL;
 
+  if (handler == Py_None)
+    handler = NULL;
+  else
+    Py_INCREF(handler);
   temp = self->content_handler;
-  Py_INCREF(handler);
   self->content_handler = handler;
   Py_XDECREF(temp);
@@ -1669,4 +1703,5 @@
 }
 
+
 XMLPARSER_METHOD_DOC(getEntityResolver) = \
 "getEntityResolver()\n\
@@ -1694,25 +1729,23 @@
 "setEntityResolver(resolver)\n\
 \n\
-Registers a handler to receive resolveEntity events.\n\
-NOTE: FOR NOW THIS CALL IS A NO-OP\n\
-See also: http://docs.python.org/lib/entity-resolver-objects.html";
+Set the current EntityResolver.\n\
+\n\
+If no EntityResolver is set, attempts to resolve an external entity will\n\
+result in opening the system identifier for the entity, and fail if it is\n\
+not available.";
 
 XMLPARSER_METHOD_DEF(setEntityResolver)
 {
   PyObject *resolver, *temp;
+  ExpatResolveEntityHandler handler;
 
   if (!PyArg_ParseTuple(args, "O:setEntityResolver", &resolver))
     return NULL;
 
-  temp = NULL; /* Just to suppress the warning till following is uncommented */
-  /*
-  -- % --
-     There's not yet any true support for user entity resolution.
-     It would take more work than the code below.  For now this
-     method is a dummy to satisfy xml.sax.saxutils.XMLFilterBase,
-     which insists on calling setEntityResolver
-  -- % --
+  if (resolver == Py_None)
+    resolver = NULL;
+  else
+    Py_INCREF(resolver);
   temp = self->entity_resolver;
-  Py_INCREF(resolver);
   self->entity_resolver = resolver;
   Py_XDECREF(temp);
@@ -1723,12 +1756,15 @@
   Py_XDECREF(temp);
 
-  GET_CALLBACK(SetLocator, "resolveEntity");
+  GET_CALLBACK(ResolveEntity, "resolveEntity");
 #undef GET_CALLBACK
-  */
 
   /* ignore any undefined event handler errors */
-  /*
   PyErr_Clear();
-  */
+
+  if (self->handlers[Handler_ResolveEntity])
+    handler = parser_ResolveEntity;
+  else
+    handler = NULL;
+  Expat_SetResolveEntityHandler(self->parser, handler);
 
   Py_INCREF(Py_None);
@@ -1737,5 +1773,4 @@
 
 
-
 XMLPARSER_METHOD_DOC(getErrorHandler) = \
 "getErrorHandler()\n\
@@ -1775,6 +1810,9 @@
     return NULL;
 
+  if (handler == Py_None)
+    handler = NULL;
+  else
+    Py_INCREF(handler);
   temp = self->error_handler;
-  Py_INCREF(handler);
   self->error_handler = handler;
   Py_XDECREF(temp);
@@ -1833,6 +1871,9 @@
     return NULL;
 
+  if (handler == Py_None)
+    handler = NULL;
+  else
+    Py_INCREF(handler);
   temp = self->dtd_handler;
-  Py_INCREF(handler);
   self->dtd_handler = handler;
   Py_XDECREF(temp);
@@ -1874,5 +1915,5 @@
     status = ParseDOM(self);
   } else {
-    source = prepareInputSource(source);
+    source = prepareInputSource(self, source);
     if (source == NULL) return NULL;
 
@@ -2188,8 +2229,8 @@
                                     Py_EQ)) {
     /* create a "DOM Walker"-style parser */
-    if (PyDocument_Check(value)) {
+    if (Document_Check(value)) {
       Py_XDECREF(self->dom_node);
       Py_INCREF(value);
-      self->dom_node = (PyNodeObject *) value;
+      self->dom_node = (NodeObject *) value;
     } else {
       return SAXNotSupportedException("dom-node must be a Document node");
@@ -2284,5 +2325,5 @@
 
   if (self->dom_node) {
-    systemId = PyDocument_BASE_URI(self->dom_node);
+    systemId = Document_GET_DOCUMENT_URI(self->dom_node);
     Py_INCREF(systemId);
   } else {
@@ -2330,8 +2371,8 @@
   Py_XDECREF(self->lexical_handler);
   Py_XDECREF(self->decl_handler);
+  Py_XDECREF(self->entity_resolver);
   Py_XDECREF(self->error_handler);
   Py_XDECREF(self->dtd_handler);
   Py_XDECREF(self->content_handler);
-  Py_XDECREF(self->entity_resolver);
 
   for (i = 0; i < TotalHandlers; i++) {
@@ -2361,17 +2402,16 @@
 }
 
-static int parser_clear(PyObject *self)
+static int parser_clear(XMLParserObject *self)
 {
   int i;
-  XMLParserObject *xmlpobj = (XMLParserObject *)self;
 
-  Py_CLEAR(xmlpobj->content_handler);
-  Py_CLEAR(xmlpobj->dtd_handler);
-  Py_CLEAR(xmlpobj->error_handler);
-  Py_CLEAR(xmlpobj->entity_resolver);
-  Py_CLEAR(xmlpobj->decl_handler);
-  Py_CLEAR(xmlpobj->lexical_handler);
+  Py_CLEAR(self->content_handler);
+  Py_CLEAR(self->dtd_handler);
+  Py_CLEAR(self->error_handler);
+  Py_CLEAR(self->entity_resolver);
+  Py_CLEAR(self->decl_handler);
+  Py_CLEAR(self->lexical_handler);
   for (i = 0; i < TotalHandlers; i++) {
-    Py_CLEAR(xmlpobj->handlers[i]);
+    Py_CLEAR(self->handlers[i]);
   }
   return 0;
@@ -2415,5 +2455,5 @@
   /* tp_doc            */ (char *) parser_doc,
   /* tp_traverse       */ (traverseproc) parser_traverse,
-  /* tp_clear          */ parser_clear,
+  /* tp_clear          */ (inquiry) parser_clear,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
@@ -2810,21 +2850,8 @@
 }
 
-static int attributes_clear(PyObject *self)
+static int attributes_clear(AttributesObject *self)
 {
-  PyObject *tmp;
-  AttributesObject *aobj = (AttributesObject *)self;
-
-  if (aobj->values != NULL) {
-    tmp = aobj->values;
-    aobj->values = NULL;
-    Py_DECREF(tmp);
-  }
-
-  if (aobj->qnames != NULL) {
-    tmp = aobj->qnames;
-    aobj->qnames = NULL;
-    Py_DECREF(tmp);
-  }
-
+  Py_CLEAR(self->values);
+  Py_CLEAR(self->qnames);
   return 0;
 }
@@ -2864,5 +2891,5 @@
   /* tp_doc            */ (char *) attributes_doc,
   /* tp_traverse       */ (traverseproc) attributes_traverse,
-  /* tp_clear          */ attributes_clear,
+  /* tp_clear          */ (inquiry) attributes_clear,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/xpathnamespace.c.diff?r1=1.11&r2=1.12
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/xpathnamespace.c?rev=1.12&content-type=text/vnd.viewcvs-markup

Index: xpathnamespace.c
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/xpathnamespace.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -U2 -r1.11 -r1.12
--- xpathnamespace.c	24 Nov 2006 21:36:39 -0000	1.11
+++ xpathnamespace.c	21 Dec 2006 06:13:37 -0000	1.12
@@ -1,15 +1,11 @@
 #include "domlette.h"
 
-
 /** Private Routines **************************************************/
 
-
-static int xns_init(PyXPathNamespaceObject *self,
-                    PyElementObject *parentNode,
-                    PyObject *prefix,
-                    PyObject *namespaceURI)
+static int xns_init(XPathNamespaceObject *self, ElementObject *parentNode,
+                    PyObject *prefix, PyObject *namespaceURI)
 {
-  if ((self == NULL || !PyXPathNamespace_Check(self)) ||
-      (parentNode == NULL || !PyElement_Check(parentNode)) ||
+  if ((self == NULL || !XPathNamespace_Check(self)) ||
+      (parentNode == NULL || !Element_Check(parentNode)) ||
       (prefix == NULL || !XmlString_NullCheck(prefix)) ||
       (namespaceURI == NULL || !XmlString_Check(namespaceURI))) {
@@ -19,5 +15,5 @@
 
   if (prefix == Py_None) {
-    prefix = PyUnicode_FromUnicode(NULL, (Py_ssize_t)0);
+    prefix = PyUnicode_FromUnicode(NULL, 0);
     if (prefix == NULL) return -1;
   } else {
@@ -29,26 +25,25 @@
   self->nodeValue = namespaceURI;
 
-  Node_SET_PARENT(self, (PyNodeObject *) parentNode);
+  assert(Node_GET_PARENT(self) == NULL);
+  Py_INCREF(parentNode);
+  Node_SET_PARENT(self, (NodeObject *)parentNode);
 
   return 0;
 }
 
-
 /** C API **************************************************************/
 
-
-PyXPathNamespaceObject *XPathNamespace_New(PyElementObject *parentNode,
-                                           PyObject *prefix,
-                                           PyObject *namespaceURI)
+XPathNamespaceObject *XPathNamespace_New(ElementObject *parentNode,
+                                         PyObject *prefix,
+                                         PyObject *namespaceURI)
 {
-  PyXPathNamespaceObject *self;
+  XPathNamespaceObject *self;
 
-  if (parentNode == NULL || !PyElement_Check(parentNode)) {
+  if (parentNode == NULL || !Element_Check(parentNode)) {
     PyErr_BadInternalCall();
     return NULL;
   }
 
-  self = Node_New(PyXPathNamespaceObject, &DomletteXPathNamespace_Type,
-                  Node_GET_DOCUMENT(parentNode));
+  self = Node_New(XPathNamespaceObject, &DomletteXPathNamespace_Type);
   if (self != NULL) {
     if (xns_init(self, parentNode, prefix, namespaceURI) < 0) {
@@ -63,70 +58,67 @@
 }
 
-
 /** Python Methods ****************************************************/
 
+#define XPathNamespace_METHOD(name) \
+  { #name, (PyCFunction) xns_##name, METH_VARARGS, xns_##name##_doc }
 
-/* No additional interface methods defined */
-
+static PyMethodDef xns_methods[] = {
+  { NULL }
+};
 
 /** Python Members ****************************************************/
 
+#define XPathNamespace_MEMBER(name, member) \
+  { #name, T_OBJECT, offsetof(XPathNamespaceObject, member), RO }
 
 static struct PyMemberDef xns_members[] = {
-  { "nodeName",  T_OBJECT, offsetof(PyXPathNamespaceObject, nodeName),  RO },
-  { "localName", T_OBJECT, offsetof(PyXPathNamespaceObject, nodeName),  RO },
-  { "nodeValue", T_OBJECT, offsetof(PyXPathNamespaceObject, nodeValue), RO },
-  { "value",     T_OBJECT, offsetof(PyXPathNamespaceObject, nodeValue), RO },
+  XPathNamespace_MEMBER(nodeName, nodeName),
+  XPathNamespace_MEMBER(localName, nodeName),
+  XPathNamespace_MEMBER(nodeValue, nodeValue),
+  XPathNamespace_MEMBER(value, nodeValue),
   { NULL }
 };
 
-
 /** Python Computed Members *******************************************/
 
-
-/* No additional interface members defined */
-
+static PyGetSetDef xns_getset[] = {
+  { NULL }
+};
 
 /** Type Object ********************************************************/
 
-
-static void xns_dealloc(PyXPathNamespaceObject *self)
+static void xns_dealloc(XPathNamespaceObject *self)
 {
   PyObject_GC_UnTrack((PyObject *) self);
-
-  Py_DECREF(self->nodeValue);
-  self->nodeValue = NULL;
-
-  Py_DECREF(self->nodeName);
-  self->nodeName = NULL;
-
+  Py_CLEAR(self->nodeValue);
+  Py_CLEAR(self->nodeName);
   Node_Del(self);
 }
 
-
-static PyObject *xns_repr(PyXPathNamespaceObject *self)
+static PyObject *xns_repr(XPathNamespaceObject *self)
 {
-  char buf[256];
-
+  PyObject *repr;
   PyObject *name = PyObject_Repr(self->nodeName);
   PyObject *value = PyObject_Repr(self->nodeValue);
-
-  sprintf(buf, "<cXPathNamespace at %p: name %.50s, value %.100s>", self,
-          name == NULL ? "(null)" : PyString_AS_STRING(name),
-          value == NULL ? "(null)" : PyString_AS_STRING(value));
-
-  Py_XDECREF(name);
-  Py_XDECREF(value);
-
-  return PyString_FromString(buf);
+  if (name == NULL || value == NULL) {
+    Py_XDECREF(name);
+    Py_XDECREF(value);
+    return NULL;
+  }
+  repr = PyString_FromFormat("<XPathNamespace at %p: name %s, value %s>",
+                             self,
+                             PyString_AsString(name),
+                             PyString_AsString(value));
+  Py_DECREF(name);
+  Py_DECREF(value);
+  return repr;
 }
 
-
 static PyObject *xns_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
-  PyElementObject *parentNode;
+  ElementObject *parentNode;
   PyObject *prefix, *namespaceURI;
   static char *kwlist[] = { "parentNode", "prefix", "namespaceURI", NULL };
-  PyXPathNamespaceObject *self;
+  XPathNamespaceObject *self;
 
   if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!OO:Element", kwlist,
@@ -146,7 +138,7 @@
 
   if (type != &DomletteXPathNamespace_Type) {
-    self = (PyXPathNamespaceObject *) type->tp_alloc(type, 0);
+    self = XPathNamespace(type->tp_alloc(type, 0));
     if (self != NULL) {
-      _Node_INIT(self, Node_GET_DOCUMENT(parentNode));
+      _Node_INIT(self);
       if (xns_init(self, parentNode, prefix, namespaceURI) < 0) {
         Py_DECREF(self);
@@ -163,5 +155,4 @@
 }
 
-
 static char xns_doc[] = "\
 XPathNamespace(parentNode, prefix, namespaceURI) -> XPathNamespace object\n\
@@ -174,5 +165,5 @@
   /* ob_size           */ 0,
   /* tp_name           */ DOMLETTE_PACKAGE "XPathNamespace",
-  /* tp_basicsize      */ sizeof(PyXPathNamespaceObject),
+  /* tp_basicsize      */ sizeof(XPathNamespaceObject),
   /* tp_itemsize       */ 0,
   /* tp_dealloc        */ (destructor) xns_dealloc,
@@ -194,12 +185,12 @@
   /* tp_doc            */ (char *) xns_doc,
   /* tp_traverse       */ (traverseproc) 0,
-  /* tp_clear          */ 0,
+  /* tp_clear          */ (inquiry) 0,
   /* tp_richcompare    */ (richcmpfunc) 0,
   /* tp_weaklistoffset */ 0,
   /* tp_iter           */ (getiterfunc) 0,
   /* tp_iternext       */ (iternextfunc) 0,
-  /* tp_methods        */ (PyMethodDef *) 0,
+  /* tp_methods        */ (PyMethodDef *) xns_methods,
   /* tp_members        */ (PyMemberDef *) xns_members,
-  /* tp_getset         */ (PyGetSetDef *) 0,
+  /* tp_getset         */ (PyGetSetDef *) xns_getset,
   /* tp_base           */ (PyTypeObject *) 0,
   /* tp_dict           */ (PyObject *) 0,
@@ -213,4 +204,6 @@
 };
 
+/** Module Setup & Teardown *******************************************/
+
 int DomletteXPathNamespace_Init(PyObject *module)
 {
ViewCVS diff:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/xpathnamespace.h.diff?r1=1.3&r2=1.4
ViewCVS view:
  http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/src/domlette/xpathnamespace.h?rev=1.4&content-type=text/vnd.viewcvs-markup

Index: xpathnamespace.h
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/src/domlette/xpathnamespace.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -U2 -r1.3 -r1.4
--- xpathnamespace.h	22 Aug 2006 00:35:21 -0000	1.3
+++ xpathnamespace.h	21 Dec 2006 06:13:37 -0000	1.4
@@ -11,19 +11,20 @@
 
   typedef struct {
-    PyNode_HEAD
+    Node_HEAD
     PyObject *nodeName;
     PyObject *nodeValue;
-  } PyXPathNamespaceObject;
+  } XPathNamespaceObject;
 
-#define XPathNamespace_GET_NAME(op) \
-  (((PyXPathNamespaceObject *)(op))->nodeName)
-#define XPathNamespace_GET_VALUE(op) \
-  (((PyXPathNamespaceObject *)(op))->nodeValue)
+#define XPathNamespace(op) ((XPathNamespaceObject *)(op))
+#define XPathNamespace_GET_NAME(op) (XPathNamespace(op)->nodeName)
+#define XPathNamespace_GET_VALUE(op) (XPathNamespace(op)->nodeValue)
+
+#ifdef Domlette_BUILDING_MODULE
 
   extern PyTypeObject DomletteXPathNamespace_Type;
 
-#define PyXPathNamespace_Check(op) \
+#define XPathNamespace_Check(op) \
   PyObject_TypeCheck(op, &DomletteXPathNamespace_Type)
-#define PyXPathNamespace_CheckExact(op) \
+#define XPathNamespace_CheckExact(op) \
   ((op)->ob_type == &DomletteXPathNamespace_Type)
 
@@ -33,7 +34,9 @@
 
   /* XPathNamespace Methods */
-  PyXPathNamespaceObject *XPathNamespace_New(PyElementObject *parentNode,
-                                             PyObject *prefix,
-                                             PyObject *namespaceURI);
+  XPathNamespaceObject *XPathNamespace_New(ElementObject *parentNode,
+                                           PyObject *prefix,
+                                           PyObject *namespaceURI);
+
+#endif /* Domlette_BUILDING_MODULE */
 
 #ifdef __cplusplus


More information about the 4suite-checkins mailing list