[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Binding mdb_set_compare with Go



Bryan Matsuo wrote:
I also believe you have misunderstood the practical problems of passing Go
function pointers to C. But to be fair, I think the wording of that quoted
paragraph could be better.

 > Sorry but there is no other Go function for the mdb_cmp() function to call,
the only one it knows about is the function pointer that you pass.

It may be of benefit to see how the I've used the context argument in a
binding being developed for the mdb_reader_list function.

https://github.com/bmatsuo/lmdb-go/blob/bmatsuo/reader-list-context-fix/lmdb/lmdbgo.c

The callback passed to mdb_reader_list is always the same static function
because correctly calling a Go function from C requires an annotated static Go
function. The context argument allows dispatch to the correct Go function that
was configured at runtime. I believe that is the "other" Go function you
mentioned.

The implementation would be similar for mdb_set_compare. The callback would
always be the same static function which handles the dynamic dispatch.

And this is the part that I really don't understand - why not let the user pass their own static Go function? Bouncing through a dispatcher like this will be even slower.

--
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/