1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Rep Power

    RPython: Argument Number Mismatch

    I have this code:

    Python Code:
    import os
    def clear_fd(path):
    	if os.path.exists(path):
    		c = os.open(path, os.O_WRONLY)
    		c = os.open(path, os.O_CREAT)
    	os.write(c, '')
    def main(argv):
    	if len(argv) != 2:
    		print 'Invalid number of arguments'
    		return 1
    		print 'Error: Invalid file path'
    		return 1
    	fd = os.open(argv[1], os.O_APPEND | os.O_WRONLY)
    	res = True
    	while res:
    		if res == True:
    			res = ''
    		res += os.read(0, 1)
    		if res.endswith('\n'):
    			print res,
    			os.write(fd, res)
    			res = True
    		if not res:
    def target(driver, args):
    	return main, None
    if __name__ == '__main__':
    	import sys

    The code works fine in the normal CPython interpreter, but RPython gives me this:

    [translation:ERROR] Error:
    [translation:ERROR]  Traceback (most recent call last):
    [translation:ERROR]    File "C:\pypy_src\rpython\translator\goal\translate.py", line 321, in main
    [translation:ERROR]     drv.proceed(goals)
    [translation:ERROR]    File "C:\pypy_src\rpython\translator\driver.py", line 733, in proceed
    [translation:ERROR]     return self._execute(goals, task_skip = self._maybe_skip())
    [translation:ERROR]    File "C:\pypy_src\rpython\translator\tool\taskengine.py", line 114, in _execute
    [translation:ERROR]     res = self._do(goal, taskcallable, *args, **kwds)
    [translation:ERROR]    File "C:\pypy_src\rpython\translator\driver.py", line 284, in _do
    [translation:ERROR]     res = func()
    [translation:ERROR]    File "C:\pypy_src\rpython\translator\driver.py", line 321, in task_annotate
    [translation:ERROR]     s = annotator.build_types(self.entry_point, self.inputtypes)
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 93, in build_types
    [translation:ERROR]     return self.build_graph_types(flowgraph, inputcells, complete_now=complete_now)
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 149, in build_graph_types
    [translation:ERROR]     self.complete()
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 203, in complete
    [translation:ERROR]     self.complete_pending_blocks()
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 198, in complete_pending_blocks
    [translation:ERROR]     self.processblock(graph, block)
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 348, in processblock
    [translation:ERROR]     self.flowin(graph, block)
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 412, in flowin
    [translation:ERROR]     self.consider_op(block, i)
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\annrpython.py", line 606, in consider_op
    [translation:ERROR]     resultcell = consider_meth(*argcells)
    [translation:ERROR]    File "<43-codegen C:\pypy_src\rpython\annotator\annrpython.py:646>", line 3, in consider_op_simple_call
    [translation:ERROR]     return arg.simple_call(*args)
    [translation:ERROR]    File "C:\pypy_src\rpython\annotator\unaryop.py", line 711, in simple_call
    [translation:ERROR]     return bltn.analyser(*args)
    [translation:ERROR]    File "C:\pypy_src\rpython\tool\descriptor.py", line 18, in __call__
    [translation:ERROR]     return self.im_func(firstarg, *args, **kwds)
    [translation:ERROR]    File "C:\pypy_src\rpython\rtyper\extfunc.py", line 148, in compute_result_annotation
    [translation:ERROR]     self.normalize_args(*args_s)   # check arguments
    [translation:ERROR]    File "C:\pypy_src\rpython\rtyper\extfunc.py", line 130, in normalize_args
    [translation:ERROR]     "Argument number mismatch"
    [translation:ERROR]  AssertionError: ('Argument number mismatch', <[translation:ERROR] Occurred processing the following simple_call:
    [translation:ERROR]       (KeyError getting at the binding!)
    [translation:ERROR]  v1 = simple_call((builtin_function_or_method open), v0, (256))
    [translation:ERROR] In <FunctionGraph of (tee:3)clear_fd at 0x31501f0>:
    [translation:ERROR] Happened at file tee.py line 7
    [translation:ERROR] ==>                 c = os.open(path, os.O_CREAT)
    [translation:ERROR] Known variable annotations:
    [translation:ERROR]  v0 = SomeString(no_nul=True)>)
    [translation:ERROR] Processing block:
    [translation:ERROR]  block@57 is a <class 'rpython.flowspace.flowcontext.SpamBlock'>
    [translation:ERROR]  in (tee:3)clear_fd
    [translation:ERROR]  containing the following operations:
    [translation:ERROR]        v1 = simple_call((builtin_function_or_method open), v0, (256))
    [translation:ERROR]  --end--
    [translation] start debugger...
    > c:\pypy_src\rpython\rtyper\extfunc.py(130)normalize_args()
    -> "Argument number mismatch"
    I don't know what's wrong. Note: I use os.open because RPython doesn't support the built-in open function.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    Providing the mode argument might help.
    >>> import os
    >>> help(os.open)
    Help on built-in function open in module posix:
        open(filename, flag [, mode=0777]) -> fd
        Open a file (for low level IO).
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo