[cffi-devel] Strange... Help!

dherring at tentpost.com dherring at tentpost.com
Mon Jan 18 18:18:07 UTC 2010


> Nobody ? Really nobody ? Well, please !!

Patience.  This is a mailing list, not instant chat.  ;)

> Am 18.01.2010 um 00:40 schrieb Frank Goenninger:
>> typedef struct amqp_connection_state_t_ *amqp_connection_state_t;
>> extern amqp_rpc_reply_t amqp_login(amqp_connection_state_t state,
>> 				   char const *vhost,
>> 				   int channel_max,
>> 				   int frame_max,
>> 				   int heartbeat,
>> 				   amqp_sasl_method_enum sasl_method, ...);
>>
>> which I hand-translated to the following CFFI statements:
>> (defctype amqp-connection-state-t :pointer)
>>
>> (defcfun ("amqp_login" %amqp-login) amqp-rpc-reply-t
>>   (state       amqp-connection-state-t)
>>   (vhost       :string)
>>   (channel-max :int)
>>   (frame-max   :int)
>>   (heartbeat   :int)
>>   (sasl-method amqp-sasl-method-enum)
>>   &rest) ;; varargs !
>> (let* ((conn   (%amqp-new-connection))
>>        (sockfd (%amqp-open-socket *hostname* *port*)))
>>
>>       (%amqp-login conn
>>                    *vhost*
>>                    0
>>                    131072
>>                    0
>>                    :AMQP-SASL-METHOD-PLAIN
>>                    :string *user*
>>                    :string *password*)
>>
>> ***     AMQP_LOGIN sees:
>>         -> state       = 0x64034010
>>         -> vhost       = (null)
>>         -> channel_max = 131072
>>         -> frame_max   = 0
>>         -> heartbeat   = 0
>>         -> sasl_method = 1677934672

These appear to be shifted by one.  If you print the value of CONN and the
address of *VHOST*'s c string, which is appearing in STATE?

Running blind, I'd suggest changing your prototype to
 (defcfun ("amqp_login" %amqp-login) amqp-rpc-reply-t
   (state       :pointer)
   (vhost       :pointer)
   (channel-max :int)
   (frame-max   :int)
   (heartbeat   :int)
   (sasl-method amqp-sasl-method-enum)
   &rest)
but that shouldn't make a difference.

Since you're apparently already recompiling amqp_login, would it help if
you compiled a variant that didn't use varargs?  i.e. hard-code two extra
parameters that take normal username and password parameters after those
listed above?

Its also sometimes instructive to attach gdb to your lisp when doing FFI
work.  I've found the following procedure to work best.  Be sure to
compile your library with debugging enabled (-g) for best results.

# ps ax | grep sbcl # identify a pid in the following list
sbcl> set up the FFI call
# gdb /path/to/sbcl
gdb> attach $pid
gdb> break amqp_login
gdb> continue
sbcl> start the FFI call
gdb> backtrace
gdb> frame N
gdb> info locals
etc.
gdb> detach

Hope that helps,
Daniel






More information about the cffi-devel mailing list