chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] NULL in calls to C functions with bind


From: Kristian Lein-Mathisen
Subject: Re: [Chicken-users] NULL in calls to C functions with bind
Date: Sat, 23 Mar 2019 11:18:47 +0300


Hi Christoph,

I think that NULL should be correct and work - since you're creating a pointer object to address 0. However, the FFI has a convenience for null-pointers: you can pass in #f instead. That's easier and requires one less GC object. It's mentioned in the manual on c-pointer foreign type: http://wiki.call-cc.org/man/5/Foreign%20type%20specifiers#pointers

That takes me to my personal experience which I want to share: when creating foreign bindings, just use foriegn-lambda and skip the bind dependency. Maybe when you have huge API's, bind can save you some time. But I'd say that hand-written foreign-lambdas give you more control of what's going on, force you to think about every function and make sure it's safe and generally produce better interfaces. 

I hope this may give you some pointers.
K.


On Fri, Mar 22, 2019, 17:50 Christoph Lange <address@hidden wrote:
I wrote the following in my attempt to interface to the mosquitto MQTT library:


(bind* "struct mosquitto *mosquitto_new(const char *id,
                                        ___bool clean_session,
                                        void *obj);")

(define NULL (object->pointer 0))
(define mqttc (mosquitto-new NULL #t NULL))

But I'm unsure about my adventurous definition of `NULL`. It works, but is it correct?


Another thing: on the bind egg's documentation page, `___blob` is not mentioned, but I luckily found it in the sql-de-lite code, and it saved me a lot of headaches :-) Shouldn't it be there?

/Christoph
_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users

reply via email to

[Prev in Thread] Current Thread [Next in Thread]