Calling PyPy interpreter from C?
Hi, I have a question about PyPy - I hope this mailing list is the right place for it, let me know if not. Is there any way to link PyPy's Python interpreter with a C program and call it from C? I'm interested in embedding the interpreter in another program as its scripting engine. (The reason I'm looking at PyPy instead of CPython is that I'd like to use the sandboxing feature.) Thanks for any information you can give me. - Bryan Buck
2009/6/3 Bryan Buck <bbuck3898@emailias.com>:
Hi,
I have a question about PyPy - I hope this mailing list is the right place for it, let me know if not.
Is there any way to link PyPy's Python interpreter with a C program and call it from C? I'm interested in embedding the interpreter in another program as its scripting engine. (The reason I'm looking at PyPy instead of CPython is that I'd like to use the sandboxing feature.)
Not easily. The best way would probably be to run pypy in a subprocess.
Thanks for any information you can give me.
-- Regards, Benjamin
2009/6/3 Bryan Buck <bbuck3898@emailias.com>:
Hi,
I have a question about PyPy - I hope this mailing list is the right place for it, let me know if not.
Is there any way to link PyPy's Python interpreter with a C program and call it from C? I'm interested in embedding the interpreter in another program as its scripting engine. (The reason I'm looking at PyPy instead of CPython is that I'd like to use the sandboxing feature.)
Not easily. The best way would probably be to run pypy in a subprocess.
Thanks for any information you can give me.
-- Regards, Benjamin
Thank you for your reply. A subprocess is a possibility, although I'd like to avoid it if I can. Of course I was hoping there was some already- available way to do this that I had overlooked, but if necessary modifying PyPy isn't totally out of the question. How difficult is not easily? I guess I would have to change the translator to produce a library instead of an executable, and create an API for calling the interpreter from C? It does seem like a somewhat involved project, but I'm just trying to gauge the relative difficulty vs. the other possibilities I have in mind (all of which would also take significant effort). Thanks, Bryan Buck On Wed, 03 Jun 2009 12:17 -0500, "Benjamin Peterson" <benjamin@python.org> wrote: th
2009/6/3 Bryan Buck <bbuck3898@emailias.com>:
Thank you for your reply. A subprocess is a possibility, although I'd like to avoid it if I can. Of course I was hoping there was some already- available way to do this that I had overlooked, but if necessary modifying PyPy isn't totally out of the question. How difficult is not easily? I guess I would have to change the translator to produce a library instead of an executable, and create an API for calling the interpreter from C? It does seem like a somewhat involved project, but I'm just trying to gauge the relative difficulty vs. the other possibilities I have in mind (all of which would also take significant effort).
Because the translation framework bridges such a large gap in languages, it would take significant effort to pin down a human-usable PyPy API at the C level. I don't know what your other options are, but they are almost certainly easier than creating a C-API for PyPy. :) -- Regards, Benjamin
Okay, thanks. I guess I'll look into either running the PyPy interpreter as a subprocess or using something else. Thanks again! - Bryan Buck On Wed, 03 Jun 2009 13:34 -0500, "Benjamin Peterson" <benjamin@python.org> wrote:
2009/6/3 Bryan Buck <bbuck3898@emailias.com>:
Thank you for your reply. A subprocess is a possibility, although I'd like to avoid it if I can. Of course I was hoping there was some already- available way to do this that I had overlooked, but if necessary modifying PyPy isn't totally out of the question. How difficult is not easily? I guess I would have to change the translator to produce a library instead of an executable, and create an API for calling the interpreter from C? It does seem like a somewhat involved project, but I'm just trying to gauge the relative difficulty vs. the other possibilities I have in mind (all of which would also take significant effort).
Because the translation framework bridges such a large gap in languages, it would take significant effort to pin down a human-usable PyPy API at the C level. I don't know what your other options are, but they are almost certainly easier than creating a C-API for PyPy. :)
-- Regards, Benjamin
On Jun 3, 2009, at 2:16 PM, Bryan Buck wrote:
Hi,
I have a question about PyPy - I hope this mailing list is the right place for it, let me know if not.
Is there any way to link PyPy's Python interpreter with a C program and call it from C? I'm interested in embedding the interpreter in another program as its scripting engine. (The reason I'm looking at PyPy instead of CPython is that I'd like to use the sandboxing feature.)
I think that specially because of the sandbox you don't want to link the interpreter with your c program. The whole idea of the sandbox is to comunicate with the intepreter only thru a controlling program that uses stdin/stdout to control the pypy interpreter in a subprocess. Take a look at the sandboxing page: http://codespeak.net/pypy/dist/pypy/doc/sandbox.html see: ''we can translate PyPy to a special "pypy-c-sandbox" executable, which is safe in the sense that it doesn't do any library or system calls - instead, whenever it would like to perform such an operation, it marshals the operation name and the arguments to its stdout and it waits for the marshalled result on its stdin. This pypy-c-sandbox process is meant to be run by an outer "controller" program that answers these operation requests.'' -- Leonardo Santagada santagada at gmail.com
participants (3)
-
Benjamin Peterson
-
Bryan Buck
-
Leonardo Santagada