From: Aredridel Date: 2006-09-19T03:44:12+09:00 Subject: Re: C extension question --=-rmbS1jpbPbi92zuUBOFd Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Tue, 2006-09-19 at 03:39 +0900, Francis Cianfrocca wrote: > On 9/18/06, snacktime wrote: > > > > In kerberos when doing an administration function I first need to > > initialize the system with the credentials of an administrative user > > like so, with handle being a void pointer initialized to NULL. The > > following kerberos function will fill handle with a handle for the > > connection which I can use in subsequent calls to other kadm5 > > functions. > > > > kadm5_init_with_password(auser, apass, KADM5_ADMIN_SERVICE, NULL, > > KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, &handle); > > > > Now what I'd like is to return that handle to ruby and be able to pass > > it back into my C extension when it's needed, such as when needing to > > call the following kerberos function. > > > > kadm5_create_principal(handle, &princ, mask, pass); > > > > So how would I do this? If I understand void pointers correctly, > > handle could be any type after the call to kadm5_init_with_password, > > so it seems I would want to check it's type after it's set, then find > > the right type/structure to convert it to or wrap it in before passing > > it back to ruby? Not that I know how to do that:) > Void* is almost always the same size as the native integer. (There is > legitimate controversy over this point but you can depend on it for all e= nds > and intents.) Better to wrap it as a data type in Ruby, which gives you a ruby VALUE which references the native data. There's a simple macro to grab the original pointer given the VALUE. DEC Alpha doesn't necessarily have sizeof(int) =3D=3D sizeof(void *), so please don't assume so. I hate fixing code that does that. ;-) Aria (A kerberos user, too!) --=-rmbS1jpbPbi92zuUBOFd Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iD8DBQBFDuittP09exA3hooRAqoyAJ0QlG8VUtN26I7KJ5Pxo0vFpic6VACdHxno lPeJH8/d68U3KWuiRiZtXU8= =5FA5 -----END PGP SIGNATURE----- --=-rmbS1jpbPbi92zuUBOFd--