question on using ctypes
Hi, I added a module that uses ctypes under pypy/module/ but I'm getting ImportError while running translate.py for targetpypystandalone.py The error message is like, ..... cut ... [translation:ERROR] w_value = loader(space) [translation:ERROR] File "/u/jiwon/proj/pypy-dist/pypy/interpreter/mixedmodule.py", line 135, in ifileloader [translation:ERROR] d[name] = __import__(name, None, None, [name]) [translation:ERROR] ImportError': No module named tcc [translation:ERROR] .. v0 = getattr(self_0, ('w_dict')) [translation:ERROR] Processing block: [translation:ERROR] block@-1 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'> [translation:ERROR] in (pypy.interpreter.mixedmodule:33)MixedModule.MixedModule.getdictvalue [translation:ERROR] containing the following operations: [translation:ERROR] v1 = getattr(space_0, ('finditem')) [translation:ERROR] v0 = getattr(self_0, ('w_dict')) [translation:ERROR] v2 = simple_call(v1, v0, w_name_0) [translation:ERROR] v3 = getattr(self_0, ('lazy')) [translation:ERROR] v4 = is_true(v3) [translation:ERROR] --end-- and the part I added is pypy/module/tcc/__init__.py and pypy/module/tcc/tcc.py ### __init__.py # Package initialisation from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): appleveldefs = {} interpleveldefs = { 'print0': 'tcc.tcc_print0' } ### tcc.py from pypy.interpreter.baseobjspace import ObjSpace from ctypes import * libtcc = CDLL('/path/to/lib.so') print0 = libtcc.TCC_Print print0.argtypes = [c_char_p] print0.restype = c_int def tcc_print0(space, msg): print0(msg) tcc_print0.unwrap_spec = [ObjSpace, str] What have I done wrong? Thaniks, -Jiwon
2006/7/4, Jiwon Seo <seojiwon@gmail.com>:
Hi,
I added a module that uses ctypes under pypy/module/ but I'm getting ImportError while running translate.py for targetpypystandalone.py
The error message is like,
..... cut ... [translation:ERROR] w_value = loader(space) [translation:ERROR] File "/u/jiwon/proj/pypy-dist/pypy/interpreter/mixedmodule.py", line 135, in ifileloader [translation:ERROR] d[name] = __import__(name, None, None, [name]) [translation:ERROR] ImportError': No module named tcc [translation:ERROR] .. v0 = getattr(self_0, ('w_dict')) [translation:ERROR] Processing block: [translation:ERROR] block@-1 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'> [translation:ERROR] in (pypy.interpreter.mixedmodule:33)MixedModule.MixedModule.getdictvalue [translation:ERROR] containing the following operations: [translation:ERROR] v1 = getattr(space_0, ('finditem')) [translation:ERROR] v0 = getattr(self_0, ('w_dict')) [translation:ERROR] v2 = simple_call(v1, v0, w_name_0) [translation:ERROR] v3 = getattr(self_0, ('lazy')) [translation:ERROR] v4 = is_true(v3) [translation:ERROR] --end--
and the part I added is pypy/module/tcc/__init__.py and pypy/module/tcc/tcc.py
Hello, Don't know if it helps, but I have already seen this problem: sometimes an ImportError can mask another ImportError. The code in mixedmodule.py looks like this: try: d[name] = __import__(pkgroot+'.'+name, None, None, [name]) except ImportError: d[name] = __import__(name, None, None, [name]) The first call is supposed to be the good one, but if it fails with an ImportError, you get the error from the second call. Is the ctypes module correctly installed? -- Amaury Forgeot d'Arc
Hello,
Don't know if it helps, but I have already seen this problem: sometimes an ImportError can mask another ImportError. The code in mixedmodule.py looks like this: try: d[name] = __import__(pkgroot+'.'+name, None, None, [name]) except ImportError: d[name] = __import__(name, None, None, [name])
The first call is supposed to be the good one, but if it fails with an ImportError, you get the error from the second call. Is the ctypes module correctly installed?
Yeah, I think so. (I installed in my home directory, and I think I properly set up PYTHONSTARTUP and did sys.path.append... in the PYTHONSTARTUP file. And, 'p name' in the pdb tells me it's tcc modue. So, I think ctypes might not be related to this. (but I could be wrong) Any other suggestions? -Jiwon
On further inspection, it is actually ctypes problem. It seems like setting sys.path in PYTHONSTARTUP file isn't enough. I guess I should just install it in system-wide python site-package directory. Thanks. On 7/4/06, Jiwon Seo <seojiwon@gmail.com> wrote:
Hello,
Don't know if it helps, but I have already seen this problem: sometimes an ImportError can mask another ImportError. The code in mixedmodule.py looks like this: try: d[name] = __import__(pkgroot+'.'+name, None, None, [name]) except ImportError: d[name] = __import__(name, None, None, [name])
The first call is supposed to be the good one, but if it fails with an ImportError, you get the error from the second call. Is the ctypes module correctly installed?
Yeah, I think so. (I installed in my home directory, and I think I properly set up PYTHONSTARTUP and did sys.path.append... in the PYTHONSTARTUP file. And, 'p name' in the pdb tells me it's tcc modue. So, I think ctypes might not be related to this. (but I could be wrong)
Any other suggestions?
-Jiwon
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@-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? -Jiwon
participants (2)
-
Amaury Forgeot d'Arc
-
Jiwon Seo