[xml] [bnwest rice edu: xml mailing list ...]



Forwarding for a colleague who can't seem to get his email subscription
to work. He's starting with a quote of an email from Daniel earlier up
the list, when we ran over the missing python implemention of the range
types.

Ross


----- Forwarded message from "Brian N. West" <bnwest rice edu> -----

Delivery-date: Thu, 21 Sep 2006 15:51:52 -0500
Date: Thu, 21 Sep 2006 15:44:46 -0500
From: "Brian N. West" <bnwest rice edu>
To: "Ross J. Reedstrom" <reedstrm rice edu>
Subject: xml mailing list ...

Daniel Veillard said:
  Hum, yeah, that must be the binding missing support from the extra
XPath types (XPATH_POINT, XPATH_RANGE and XPATH_LOCATIONSET), I guess
nobody tried to really use them from Python, you're in unknown land.
  Probably libxml_xmlXPathObjectPtrWrap() should be augmented to
handle them (python/types.c around line 397), and convert them to Python
type. I don't know what would be the best way to represent a point,
maybe a tuple made of a node and an index.
  I would be glad to get patches and some example to run the regression 
tests
from python/test/ !

  Thanks in advance :-)


We made the following changes to libxml_xmlXPathObjectPtrWrap():

case XPATH_POINT:

We create a 'point' tuple with contains the node and an index:

node = libxml_xmlNodePtrWrap(obj->user);
indexIntoNode = PyInt_FromLong((long) obj->index);

ret = PyTuple_New(2);
PyTuple_SetItem(ret, 0, node);
PyTuple_SetItem(ret, 1, indexIntoNode);

case XPATH_RANGE:

We create a list (PyList) with two point tuples (PyTuples),
or one point tuple if range is collapsed.

case XPATH_LOCATIONSET:

We create a list (PyList) with an entry per XPath Object contained in the 
location set.  We call libxml_xmlXPathObjectPtrWrap() recursively for each
XPath Object.

for our python test of interest:

xp='xpointer(string-range(id("para1"),"Geometric",9,1))'

libxml_xmlXPathObjectPtrWrap() gets called with a Location Set with one 
XPath Object which is a Range. We build :

a PyList (Location Set) which contain one PyList (Range)
which contains two point PyTuples.

At some point after libxml_xmlXPathObjectPtrWrap() is returned, a call is 
made to libxml_type() where we experience a memory access error.  Within a 
call is made to

PyArg_ParseTuple(args, (char *) "O:last", &obj)

followed by

cur = PyxmlNode_Get(obj)

which leaves us with a 'cur' of value 1, instead of a valid memory pointer.
Deferencing cur causes the memory access error.

FWIW stack trace at error is:

(gdb) where
#0  libxml_type (self=0x0, args=0xb7dcc14c) at libxml.c:2566
#1  0x080b6a11 in PyEval_EvalFrame ()
#2  0x080b580c in PyEval_EvalFrame ()
#3  0x080b726d in PyEval_EvalCodeEx ()
#4  0x080fb6fd in PyFunction_SetClosure ()
#5  0x0805950c in PyObject_Call ()
#6  0x080afed7 in PyEval_CallObjectWithKeywords ()
#7  0x080a995f in _PyUnicodeUCS4_IsNumeric ()
#8  0x080b6a11 in PyEval_EvalFrame ()
#9  0x080b580c in PyEval_EvalFrame ()
#10 0x080b580c in PyEval_EvalFrame ()
#11 0x080b726d in PyEval_EvalCodeEx ()
#12 0x080b73ae in PyEval_EvalCode ()
#13 0x080d8ffc in PyRun_FileExFlags ()
#14 0x080d929c in PyRun_SimpleFileExFlags ()
#15 0x08055a06 in Py_Main ()
#16 0xb7e52ea2 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
#17 0x08054f21 in _start ()

and obj has a value of

(gdb) print obj
$1 = (PyObject *) 0xb7dc5dec
(gdb) print *obj
$2 = {ob_refcnt = 6, ob_type = 0x81168c0}

The initial stack trace to the first call of libxml_xmlXPathObjectPtrWrap() 
is

(gdb) where
#0  libxml_xmlXPathObjectPtrWrap (obj=0x830fac8) at types.c:486
#1  0xb7b223a5 in libxml_xmlXPtrEval (self=0x0, args=0xb7d48e2c) at 
libxml2-py.c:7107
#2  0x080b6a11 in PyEval_EvalFrame ()
#3  0x080b580c in PyEval_EvalFrame ()
#4  0x080b726d in PyEval_EvalCodeEx ()
#5  0x080b73ae in PyEval_EvalCode ()
#6  0x080d8ffc in PyRun_FileExFlags ()
#7  0x080d929c in PyRun_SimpleFileExFlags ()
#8  0x08055a06 in Py_Main ()
#9  0xb7dceea2 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
#10 0x08054f21 in _start ()

It is a mystery to us why libxml_type() is being called.

Any thoughts?

thanks in advance.

----- End forwarded message -----



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