On Tue, 24 Oct 2006 13:20:03 -0500, Joshua Kantor <[EMAIL PROTECTED]>  
wrote:
> This idea is probably totally naive as my understanding of the
> exact mechanics of shared object libraries is still somewhat black
> boxish.
>
> Say I have a routine that takes a pointer to some C function. I define
> a
> shared object library of C function wrappers. Say it just has a C
> function foo. Then set up some system
> so that when I define foo in pyrex that shared object library gets
> recompiled with the code from my pyrex foo (or so that function always
> just calls the pyrex foo).  I always pass a C function pointer to foo
> from the shared object library, however now each time the user defines
> foo in pyrex, that is the foo that the pointer will point at. Now
> everything is pure C the whole time.
>
> Is there anything that would make this technically impossible.

This is definitely possible, but the mechanism I would use would
be a bit different.

1) Define a class as part of your Pyrex module, e.g.,

    cdef class MyFunction:
        cdef call(self, double x):
            ...

Make sure this is declared in a pxd file.

2) In user code they would write:

    cdef class UserFunc(MyFunction):
        def call(self, double x):
            return x**3 - x - 1    # for example

    f = UserFunc()

3) The user passes f to your Pyrex code, e.g., a function like

    def solve_hard_numerical_problem(MyFunction f):
        ...
           f.call(x)

The "f.call(x)" will be converted to pure C code.

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to