[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&qu