Embedding Python in C
Jesse Ibarra
jesse.ibarra.1996 at gmail.com
Fri Jul 19 10:24:00 EDT 2019
On Thursday, July 18, 2019 at 1:46:05 PM UTC-6, Christian Gollwitzer wrote:
> Am 18.07.19 um 16:18 schrieb Jesse Ibarra:
> > On Wednesday, July 17, 2019 at 2:20:51 PM UTC-6, Christian Gollwitzer wrote:
> >> What level of integration do you want to achieve? Do you want
> >>
> >> a) to call Python functions from Smalltalk
> >> b) call Smalltalk functions from Python
> >> c) pass callbacks around, e.g. use a Smalltalk function within a Python
> >> list comprehension, and if so, which way
> >> d) integrate the class systems - derive a Python class from a Smalltalk
> >> base or the other way round
> >>
>
> >
> > For right now, I need to call a .so file from Smalltalk. I can't explicitly use Python libraries since Smalltalk does not support Python. I need to use the C/Python API (in Smalltalk) to create a bridge where I can call a .so and a function in that .so file with a PyObject (This will be called back to Smalltalk from the .so file). I can't figure out a way to do that since the C/API can't call C or .so files.
> >
> > sorry for the confusion on my part
> >
>
> I still don't get it, sorry. To me it is unclear which part of the
> integration you manage to do so far, and which part is the problem.
>
> Which Smalltalk interpreter are you using? The answer to the following
> will heavily depend on that.
>
>
> Suppose I'd give you a C file with the following simple function:
>
>
> double add(double a, double b) {
> return a+b;
> }
>
> Do you know how to compile this code and make it usable from Smalltalk?
>
> One level up, consider a C function working on an array:
>
> double arrsum(int n, double *arr) {
> double sum=0.0;
> for (int i=0; i<n; i++) sum+=arr[i];
> return sum;
> }
>
>
> How would you compile and link this with your Smalltalk implementation,
> such that you can pass it a Smalltalk array?
>
> Once you can do this, you can proceed to call a Python function, which
> in C means that you invoke the function PyObject_CallObject(). A basic
> example is shown here:
>
> https://docs.python.org/2/extending/embedding.html#pure-embedding
>
> Christian
I am using Visualworks 8.3. I can write that double arrsum function in Smalltalk. No Problem.
I can also make shared library and bring those function into Smalltalk with C (Since VW 8.3 supports C and C types). No Problem.
Smalltalk does not support Python. So I can use C/API to bring in Python libs,types and files. No Problem
Now ,I need to bring in shared libraries using C/Python API using Smalltalk. It seems like I can't directly bring in C shared libraries (.so files). PROBLEM.
HOW CAN I BRING THESE IN DIRECTLY?
Why do I want to call a C shared lib (.so file) using C/Python API from Smalltalk?
Because I want to make C shared libs that bring in individual Python libraries into Smalltalk, such as as (Scipy,NumPy,etc). That can be called using that C/Python API in Smalltalk
More information about the Python-list
mailing list