[pypy-dev] Help with Exception: unexpected prebuilt constant

2009-10-09 Thread Philip Guo
Sorry for another newbish question, but I'm having trouble getting PyPy
translated into C code.  I added some calls to open() throughout the
interpreter codebase (to log some info to files), but it failed translation
with the following error:

  [translation:ERROR]  Exception: unexpected prebuilt constant: built-in
function open

I then tried doing 'import os' and then using os.fdopen, but with the same
error:

  [translation:ERROR]  Exception: unexpected prebuilt constant: built-in
function fdopen


In general, what Python standard library calls can I make from my modified
PyPy code and still have it translate properly?  Specifically, how do I
read/write files from within PyPy?

Thanks!
Philip
___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev

Re: [pypy-dev] Help with Exception: unexpected prebuilt constant

2009-10-09 Thread Antonio Cuni
Hi Philip,

Philip Guo wrote:
 Sorry for another newbish question, but I'm having trouble getting PyPy 
 translated into C code.  I added some calls to open() throughout the 
 interpreter codebase (to log some info to files), but it failed 
 translation with the following error:
 
   [translation:ERROR]  Exception: unexpected prebuilt constant: 
 built-in function open
 
 I then tried doing 'import os' and then using os.fdopen, but with the 
 same error:
 
   [translation:ERROR]  Exception: unexpected prebuilt constant: 
 built-in function fdopen

as you have noticed, neither os.open nor os.fdopen are supported by RPython.
The only low-level supported way to deal with files is using 
os.open/os.read/os.write.

However, you might want to have a look to rlib.streamio, that provides a 
higher level API to deal with files, offering features such as buffering, 
CR/LF conversions etc.  In particular, you can use 
streamio.open_file_as_stream to get a file like object similar to the builtin 
python ones.

 In general, what Python standard library calls can I make from my 
 modified PyPy code and still have it translate properly?  Specifically, 
 how do I read/write files from within PyPy?

see above :-)

ciao,
Anto
___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev


Re: [pypy-dev] Help with Exception: unexpected prebuilt constant

2009-10-09 Thread Philip Guo
Thanks for the informative reply, Antonio!  My (probably dumb) follow-up
question is: Is pickle (or cPickle) supported by RPython?  The bottom line
is that I need to serialize some data structures from my modified PyPy
interpreter to disk so that data can persist across successive interpreter
runs.  Pickling is the most obvious way to do so, but it requires a Python
built-in file object.

If pickling doesn't work, what other way of persisting data on disk do you
suggest?  (e.g., printing it to a file as plaintext and then eval-ing it
again?  does eval() even work in RPython?)


On Fri, Oct 9, 2009 at 1:46 AM, Antonio Cuni anto.c...@gmail.com wrote:

 Hi Philip,

 Philip Guo wrote:

 Sorry for another newbish question, but I'm having trouble getting PyPy
 translated into C code.  I added some calls to open() throughout the
 interpreter codebase (to log some info to files), but it failed translation
 with the following error:

  [translation:ERROR]  Exception: unexpected prebuilt constant: built-in
 function open

 I then tried doing 'import os' and then using os.fdopen, but with the same
 error:

  [translation:ERROR]  Exception: unexpected prebuilt constant: built-in
 function fdopen


 as you have noticed, neither os.open nor os.fdopen are supported by
 RPython.
 The only low-level supported way to deal with files is using
 os.open/os.read/os.write.

 However, you might want to have a look to rlib.streamio, that provides a
 higher level API to deal with files, offering features such as buffering,
 CR/LF conversions etc.  In particular, you can use
 streamio.open_file_as_stream to get a file like object similar to the
 builtin python ones.

  In general, what Python standard library calls can I make from my modified
 PyPy code and still have it translate properly?  Specifically, how do I
 read/write files from within PyPy?


 see above :-)

 ciao,
 Anto

___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev

Re: [pypy-dev] Help with Exception: unexpected prebuilt constant

2009-10-09 Thread Antonio Cuni
Philip Guo wrote:
 Thanks for the informative reply, Antonio!  My (probably dumb) follow-up 
 question is: Is pickle (or cPickle) supported by RPython?  The bottom 
 line is that I need to serialize some data structures from my modified 
 PyPy interpreter to disk so that data can persist across successive 
 interpreter runs.  Pickling is the most obvious way to do so, but it 
 requires a Python built-in file object.

pickle and cpickle are not supported by RPython.

If you need to serialize interp-level objects, I fear the only way is to 
manually write the code to write them to disk and read back. You might want to 
have a look at rlib.rmarshal, which can be used to serialize simple objects 
such as numbers, lists and tuples.

On the other hand, remember that you have the whole PyPy python interpreter in 
your hands: depending on what you are trying to do, you could use it to 
interact with the fully working cPickle modules.  But please notice that this 
solution works only if you want to serialize app-level objects (i.e. all the 
objects that are called as w_* inside the pypy sources).

 If pickling doesn't work, what other way of persisting data on disk do 
 you suggest?  (e.g., printing it to a file as plaintext and then 
 eval-ing it again?  does eval() even work in RPython?)

no, eval() doesn't work in RPython.


ciao,
Anto
___
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev