Help with pointers when calling from python to C

Carolyn MacLeod Carolyn_MacLeod at ca.ibm.com
Fri Oct 8 17:23:19 CEST 2010


Hi. 

This is kind of a cross-product question, having to do with accessibility 
on Linux using ATK (AT-SPI).
However, I think it really boils down to a python question: "How do I pass 
an integer by reference to a C function?"

I am using Accerciser (http://live.gnome.org/Accerciser), an accessibility 
testing tool that has an ipython console.
It uses pyatspi to interact with AT-SPI through pyORBit.

I need to test my handling of 
atk_editable_text_insert_text(AtkEditableText *text, const gchar *string, 
gint length, gint *position). 
In the example below, the variable 'acc' has been bound (by Accerciser) to 
an accessible object that implements the AtkEditableText  interface.

The problem is that the pesky "position" parameter wants a pointer to an 
integer.

I have tried all sorts of ways to get Accerciser's iPython console to 
accept the last parameter, but I always get: "TypeError: could not marshal 
arg 'position'." 

Has anyone done this? If so, then how is it done?

Here's a sample of the things I tried: 

In [1]: t=acc.queryEditableText() 
In [2]: t.getText(0,45) 
Out[2]: 'The quick brown fox jumps over the lazy dog.\n' 
In [3]: t.deleteText(10,15) 
Out[3]: True 
In [4]: t.getText(0,40) 
Out[4]: 'The quick  fox jumps over the lazy dog.\n' 
In [5]: pos=10 
In [6]: t.insertText("brown",5,pos) 
--------------------------------------------------------------------------- 

TypeError                                 Traceback (most recent call 
last) 

/usr/lib/python2.6/dist-packages/pyatspi/__init__.pyc in <module>() 
----> 1 
      2 
      3 
      4 
      5 

/usr/lib/python2.6/dist-packages/pyatspi/accessible.pyc in _inner(self, 
*args, **kwargs) 
    230     try: 
    231       # try calling the original func 

--> 232       return func(self, *args, **kwargs) 
    233     except ORBit.CORBA.NO_IMPLEMENT, e: 
    234       # raise Python exception 

TypeError: could not marshal arg 'position' 

In [7]: t.insertText("brown",5,id(pos)) 
--------------------------------------------------------------------------- 

TypeError                                 Traceback (most recent call 
last) 

/usr/lib/python2.6/dist-packages/pyatspi/__init__.pyc in <module>() 
----> 1 
      2 
      3 
      4 
      5 

/usr/lib/python2.6/dist-packages/pyatspi/accessible.pyc in _inner(self, 
*args, **kwargs) 
    230     try: 
    231       # try calling the original func 

--> 232       return func(self, *args, **kwargs) 
    233     except ORBit.CORBA.NO_IMPLEMENT, e: 
    234       # raise Python exception 

TypeError: could not marshal arg 'position' 

In [8]: pos=[10] 
In [9]: t.insertText("brown",5,pos) 
--------------------------------------------------------------------------- 

TypeError                                 Traceback (most recent call 
last) 

/usr/lib/python2.6/dist-packages/pyatspi/__init__.pyc in <module>() 
----> 1 
      2 
      3 
      4 
      5 

/usr/lib/python2.6/dist-packages/pyatspi/accessible.pyc in _inner(self, 
*args, **kwargs) 
    230     try: 
    231       # try calling the original func 

--> 232       return func(self, *args, **kwargs) 
    233     except ORBit.CORBA.NO_IMPLEMENT, e: 
    234       # raise Python exception 

TypeError: could not marshal arg 'position' 

In [7]: pos=array([10]) 
--------------------------------------------------------------------------- 

NameError                                 Traceback (most recent call 
last) 

/usr/lib/python2.6/dist-packages/pyatspi/__init__.pyc in <module>() 
----> 1 
      2 
      3 
      4 
      5 

NameError: name 'array' is not defined 

Thanks, 
Carolyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101008/bdd9c7e5/attachment.html>


More information about the Python-list mailing list