[xml] patches for python type management



Here are two patches which provide better type mapping between xpath
types and python types which accepting values from python code (for
example in extension functions).

The first patch applies to libxslt:


--- /libxslt-1.1.16/python/types.c~     2006-02-22 14:59:29.000000000 +0000
+++ /libxslt-1.1.16/python/types.c      2006-05-11 16:06:50.000000000 +0100
@@ -425,6 +425,19 @@
     if PyFloat_Check
         (obj) {
         ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
+    } else if PyInt_Check(obj) {
+
+        ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
+
+    } else if PyBool_Check (obj) {
+
+        if (obj == Py_True) {
+          ret = xmlXPathNewBoolean(1);
+        }
+        else {
+          ret = xmlXPathNewBoolean(0);
+        }
+
     } else if PyString_Check
         (obj) {
         xmlChar *str;


The second applies to libxml2:

--- /libxml2-2.6.24.dfsg/python/types.c~        2006-05-08 22:03:23.000000000 +0100
+++ /libxml2-2.6.24.dfsg/python/types.c 2006-05-11 16:06:28.000000000 +0100
@@ -422,6 +422,20 @@
     if PyFloat_Check
         (obj) {
         ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
+
+    } else if PyInt_Check(obj) {
+
+        ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
+
+    } else if PyBool_Check (obj) {
+
+        if (obj == Py_True) {
+          ret = xmlXPathNewBoolean(1);
+        }
+        else {
+          ret = xmlXPathNewBoolean(0);
+        }
+
     } else if PyString_Check
         (obj) {
         xmlChar *str;



I have 2 questions about this that I'd be interested in answers to:

1. It's a bit wierd that the method is duplicated. Would it not be
sensible for libxslt to simply call libxml2's implementation?

2. what code style is this? I've got a bunch of patches that I want to
   provide (for dynamic function binding and lazy node implementation)
   and I'd like to be able to write them in the code style here... my
   emacs doesn't have a code style that matches the one in these
   files. Any pointers?



Nic Ferrier





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]