[pypy-dev] question on using ctypes

Amaury Forgeot d'Arc amauryfa at gmail.com
Wed Jul 5 11:47:00 CEST 2006


Hello,

2006/7/5, Jiwon Seo <seojiwon at gmail.com>:
> After properly installing ctypes, translate.py now gives this error.
>
> ##################################################################
>
> [translation:ERROR] Error:
> [translation:ERROR]  Traceback (most recent call last):
> [translation:ERROR]    File "./translate.py", line 332, in main
> [translation:ERROR]     drv.proceed(goals)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/translator/driver.py", line 506, in
> proceed
> [translation:ERROR]     return self._execute(goals, task_skip =
> self._maybe_skip())
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/translator/tool/taskengine.py", line
> 108, in _execute
> [translation:ERROR]     res = self._do(goal, taskcallable, *args, **kwds)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/translator/driver.py", line 195, in _do
> [translation:ERROR]     res = func()
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/translator/driver.py", line 208, in
> task_annotate
> [translation:ERROR]     s = annotator.build_types(self.entry_point,
> self.inputtypes)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 100, in
> build_types
> [translation:ERROR]     return self.build_graph_types(flowgraph,
> inputcells, complete_now=complete_now)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 143, in
> build_graph_types
> [translation:ERROR]     self.complete()
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 188, in
> complete
> [translation:ERROR]     self.processblock(graph, block)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 434, in
> processblock
> [translation:ERROR]     self.flowin(graph, block)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 490, in
> flowin
> [translation:ERROR]     self.consider_op(block.operations[i])
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 661, in
> consider_op
> [translation:ERROR]     argcells = [self.binding(a) for a in op.args]
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/annrpython.py", line 238, in
> binding
> [translation:ERROR]     return self.bookkeeper.immutableconstant(arg)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/bookkeeper.py", line 297, in
> immutableconstant
> [translation:ERROR]     return self.immutablevalue(const.value)
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/bookkeeper.py", line 393, in
> immutablevalue
> [translation:ERROR]     result = SomePBC([self.getdesc(x)])
> [translation:ERROR]    File
> "/u/jiwon/proj/pypy-dist/pypy/annotation/bookkeeper.py", line 524, in
> getdesc
> [translation:ERROR]     return self.descs[pyobj]
> [translation:ERROR]  TypeError: unhashable type
> [translation:ERROR] Processing block:
> [translation:ERROR]  block at -1 is a <class
> 'pypy.objspace.flow.flowcontext.SpamBlock'>
> [translation:ERROR]  in (pypy.module.tcc.tcc:9)tcc_print0
> [translation:ERROR]  containing the following operations:
> [translation:ERROR]        v107 = simple_call((_FuncPtr TCC_Print), msg_0)
> [translation:ERROR]  --end--
>
> ############# end of error message ##################################
>
> pypy/module/tcc/__init__.py is like following
> # Package initialisation
> from pypy.interpreter.mixedmodule import MixedModule
>
> class Module(MixedModule):
>     appleveldefs = {}
>     interpleveldefs = {
>         'print0':   'tcc.tcc_print0'
>     }
>
> and pypy/module/tcc/tcc.py is like following
>
> from pypy.interpreter.baseobjspace import ObjSpace
> from ctypes import *
>
> libtcc = CDLL('/u/jiwon/proj/less-bus/libLESS.so')
> myprint0 = libtcc.TCC_Print
> myprint0.argtypes = [c_char_p]
> myprint0.restype = c_int
>
> def tcc_print0(space, msg):
>     return myprint0(msg)
> tcc_print0.unwrap_spec = [ObjSpace, str]
>
>
> What am I missing here?

I think the currently supported way to compile modules using rctypes
is the pypy/bin/compilemodule.py script, and indeed your code
translates well with it.

I suggest (but I did not test) adding this line somewhere in
targetstandalone.py:
    import pypy.rpython.rctypes.implementation
This should register the annotation for calling ctypes functions.


-- 
Amaury Forgeot d'Arc



More information about the Pypy-dev mailing list