[pypy-dev] pypy callback function pointer become invalid

Yicong Huang hengha.mao at gmail.com
Mon Aug 17 08:40:02 CEST 2015


The problem is there is *only one* entry python program.
>From the document example (
http://pypy.readthedocs.org/en/latest/embedding.html#more-complete-example),
yes, we could use a structure to wrap severl python callback function
pointers in one execution.
However, the issue is that we might not be able to get all python functions
that would be executed at the beginning.

Thinking of typical scenario of interactive usage:
1. Case 1: c++ call to python function -> python execute and return results
-> c++ process python results and choose the next python function to execute
If there is *only one* entry, we need to wrap all possible python functions
that might be called at one time.

2. Case 2: A client-server service that also serve to run python code
submited by users
C/S server infrastuture were written in C++, and the python code is
submited by user. The client submits python code to server, and server runs
the code and return result to the client. In this case, we've no ideas what
python code might execute in future.
Alternatively, we could create and destory a C++ process every time to
embed pypy, but it is inefficient.

On Sun, Aug 16, 2015 at 5:00 PM, Maciej Fijalkowski <fijall at gmail.com>
wrote:

> Think about the API that way: there is only one "entry" python program
> that you run and you can still execute arbitrary code.
>
> On Sun, Aug 16, 2015 at 10:01 AM, Eric Driggers <admalledd at gmail.com>
> wrote:
> > Agreed, have been doing basically that for some internal code, as the
> > docs kind of hint:
> >
> >
> http://pypy.readthedocs.org/en/latest/embedding.html#more-complete-example
> >
> > Basically call the pypy_execute_source_ptr() once, passing in a API
> > struct to fill out for low-level call-backs. (And passing in at the
> > same time functions for python to call to C).
> >
> > On Sun, Aug 16, 2015 at 12:42 AM, Maciej Fijalkowski <fijall at gmail.com>
> wrote:
> >> On Sun, Aug 16, 2015 at 6:12 AM, Yicong Huang <hengha.mao at gmail.com>
> wrote:
> >>> Thanks for reminding!
> >>> I looked at the code, and observed the gloal new dict might leak
> memory.
> >>>
> >>> Calling pypy_execute_source_ptr() multiple times might be a common
> usage:
> >>> you might have several python files to execute, or you might get
> python code
> >>> segment from input one by one ...
> >>> I am thinking could we have better ways to do such calls, e.g.:
> >>
> >> That use case is much better handled from python (e.g. using exec() or
> >> import or any other way to execute more python code)
> >> _______________________________________________
> >> pypy-dev mailing list
> >> pypy-dev at python.org
> >> https://mail.python.org/mailman/listinfo/pypy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150817/d5689bbf/attachment.html>


More information about the pypy-dev mailing list