RPython: Argument Number Mismatch

This is the place for queries that don't fit in any of the other categories.

RPython: Argument Number Mismatch

Postby kirbyfan64sos » Sun Sep 01, 2013 12:06 am

I have this code:

Code: Select all
import os

def clear_fd(path):
   if os.path.exists(path):
      c = os.open(path, os.O_WRONLY)
   else:
      c = os.open(path, os.O_CREAT)
   os.write(c, '')
   os.close(c)

def main(argv):
   if len(argv) != 2:
      print 'Invalid number of arguments'
      return 1
   try:
      clear_fd(argv[1])
   except:
      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:
         break
   os.close(fd)

def target(driver, args):
   return main, None

if __name__ == '__main__':
   import sys
   main(sys.argv)


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

Code: Select all
[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]
[translation:ERROR] ==>                 c = os.open(path, os.O_CREAT)
[translation:ERROR]
[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.
This program is bug-free. If you see a bug, it's actually a feature.
kirbyfan64sos
 
Posts: 7
Joined: Sun Aug 25, 2013 10:45 pm

Re: RPython: Argument Number Mismatch

Postby Yoriz » Sun Sep 01, 2013 4:31 pm

cpython provides a defualt mode
os.open(file, flags[, mode])
Open the file file and set various flags according to flags and possibly its mode according to mode. The default mode is 0777 (octal), and the current umask value is first masked out. Return the file descriptor for the newly opened file.

Maybe rpython doesn't supply a default mode and requires that you set it each time yourself.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 566
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests