[Openmcl-devel] Simple FFI Newb questions...

Ron Garret ron at flownet.com
Fri Aug 7 16:58:52 PDT 2009


Unless you're doing this as an exercise, I already have all this up  
and running and would be happy to send you the code.

rg

On Aug 7, 2009, at 4:05 PM, Michael Kohout wrote:

> Thanks fellas; that seems to have gotten me somewhere.
>
> I was able to open the shared lib and the interface file to  
> initialize the interpreter:
> CL-USER> (open-shared-library "/usr/lib/libpython2.5.so")
> #<SHLIB libpython2.5.so.1.0 #x30004138361D>
> CL-USER> (use-interface-dir :python25)
> #<INTERFACE-DIR :PYTHON25 #P"python25/" #x3000414D738D>
> CL-USER> (#_Py_Initialize)
> NIL
>
> Next, I try to call a function that cakes a simple char array but am  
> getting an error:
>  (with-cstrs ((simple "print 'hello'")) (#_PyRun_SimpleString simple))
> errors with:
> Foreign function not found: X86-LINUX64::|PyRun_SimpleString|
>
>
> I can find the symbol (or whatever) via  (external  
> "PyRun_SimpleString"), so what am I doing wrong?
>
> thanks again,
> Mike
>
>
> On Fri, Aug 7, 2009 at 1:33 PM, Gary Byers <gb at clozure.com> wrote:
>
> The #_ reader macro expects to read a case-sensitive foreign  
> function name,
> as in:
>
> (#_Py_Initialize [whatever args it takes if any])
>
> At some point, #_ winds up interning a mixed-case symbol in the OS
> package and defining that symbol as a macro that expands into some
> sort of foreign-function call.  Those symbols might show up in error
> messages or backtraces, but you don't generally deal with them  
> directly.
>
> Foreign types (and field accessors) are represented as keywords with
> upper-case substrings surrounded by angle brackets.  The canonical
> rectangle type used in Cocoa is called "NSRect" in ObjC, which is
> represented as :<NSR>ect in CCL's FFI.  That can get pretty difficult
> to type (and to read); the #> reader macro reads a case-sensitive  
> string
> and returns a keyword with angle brackets in the right places:
>
> ? #>NSRect
> :<NSR>ect
>
> which is at least slightly better than having to type the angle  
> brackets
> yourself.
>
> If you mix the two (#_ and #>), you get the behavior that you got: the
> FFI can't find a foreign function named by a keyword that contains  
> angle
> brackets in its name.  (I suppose that we -could- try to interpret  
> that
> as a foreign function name and install a macro on the keyword, but  
> we don't.)
>
>
>
>
> On Fri, 7 Aug 2009, Michael Kohout wrote:
>
> Hi all-
> Inspired by a previous post, I'm trying to import python2.5 using  
> ccl's ffi,
> but I'm having troubles.
>
> I've built and run ffigen, written my populate.sh script, called it  
> from
> within ccl with (ccl:create-interfaces :python25), and referenced  
> those
> interfaces with  (use-interface-dir :python25).
>
> After which I try to call a function defined by python's c api:  (#_
> #>Py_Initialize)
>
> However, when I try to call a function defined in python's c lib, I  
> get an
> error:
> Foreign function not found: :<P>Y_<I>NITIALIZE
>
>
> Any suggestions?  Am I missing any steps?
> thanks
> Mike Kohout
>
>
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel




More information about the Openmcl-devel mailing list