From avodonosov at yandex.ru Mon May 29 01:56:19 2017 From: avodonosov at yandex.ru (Anton Vodonosov) Date: Mon, 29 May 2017 04:56:19 +0300 Subject: invoking renamed foreign function Message-ID: <6124471496022979@web47g.yandex.ru> An HTML attachment was scrubbed... URL: From luismbo at gmail.com Mon May 29 02:17:47 2017 From: luismbo at gmail.com (=?UTF-8?Q?Lu=C3=ADs_Oliveira?=) Date: Mon, 29 May 2017 02:17:47 +0000 Subject: invoking renamed foreign function In-Reply-To: <6124471496022979@web47g.yandex.ru> References: <6124471496022979@web47g.yandex.ru> Message-ID: You can look up both functions using foreign-symbol-pointer to decide which one to call. You'd usually call the right one using foreign-funcall-pointer, but perhaps you can defcfun both and call the right one based on the lookup. defcfun-ing non-existent functions will yield runtime warnings on some implementations (notably SBCL) so perhaps you might want to implement both the foreign-funcall-pointer and defcfun approaches and conditionalise them accordingly. HTH, Lu?s On Mon, May 29, 2017, 02:56 Anton Vodonosov wrote: > Hello, > > OpenSSL renamed function SSLeay to OpenSSL_version_num. > So, so depending on what version of library we work with we > need to call either SSLeay or OpenSSL_version_num. > > What is the best way to do it? > > The following is one approach: > > (or (ignore-errors > (cffi:foreign-funcall "OpenSSL_version_num" :long)) > (ignore-errors > (cffi:foreign-funcall "SSLeay" :long))) > > > but it won't work on Corman Lisp because it doesn't > support cffi:foreign-funcall. > > I would like to be fully portable. Is there a better way? > > Best regards, > - Anton > -------------- next part -------------- An HTML attachment was scrubbed... URL: From avodonosov at yandex.ru Mon May 29 02:25:42 2017 From: avodonosov at yandex.ru (Anton Vodonosov) Date: Mon, 29 May 2017 05:25:42 +0300 Subject: invoking renamed foreign function In-Reply-To: References: <6124471496022979@web47g.yandex.ru> Message-ID: <5962541496024742@web22g.yandex.ru> Luis, thanks for the response 29.05.2017, 05:18, "Lu?s Oliveira" : > You can look up both functions using foreign-symbol-pointer > to decide which one to call. You'd usually call the right one using > foreign-funcall-pointer, but perhaps you can defcfun both and > call the right one based on the lookup. Will that work on Corman? > > defcfun-ing non-existent functions will yield runtime warnings on some implementations > (notably SBCL) so perhaps you might want to implement both the foreign-funcall-pointer > and defcfun approaches and conditionalise them accordingly. BTW, CMUCL fails with error in this case. > > HTH, > Lu?s > > On Mon, May 29, 2017, 02:56 Anton Vodonosov wrote: >> Hello, >> >> OpenSSL renamed function SSLeay to OpenSSL_version_num. >> So, so depending on what version of library we work with we >> need to call either SSLeay or OpenSSL_version_num. >> >> What is the best way to do it? >> >> The following is one approach: >> >> (or (ignore-errors >> ? ? ? (cffi:foreign-funcall "OpenSSL_version_num" :long)) >> ? ? (ignore-errors >> ? ? ? (cffi:foreign-funcall "SSLeay" :long))) >> >> but it won't work on Corman Lisp because it doesn't >> support cffi:foreign-funcall. >> >> I would like to be fully portable. Is there a better way? >> >> Best regards, >> - Anton From luismbo at gmail.com Mon May 29 02:42:38 2017 From: luismbo at gmail.com (=?UTF-8?Q?Lu=C3=ADs_Oliveira?=) Date: Mon, 29 May 2017 02:42:38 +0000 Subject: invoking renamed foreign function In-Reply-To: <5962541496024742@web22g.yandex.ru> References: <6124471496022979@web47g.yandex.ru> <5962541496024742@web22g.yandex.ru> Message-ID: foreign-symbol-pointer should work on Corman, yes. Hopefully defcfun-ing an unexisting function won't yield an error. Some alternative ideas, if that doesn't work: 1. Handle/ignore the defcfun error. 2. Implement foreign-funcall on Corman Lisp (src/cffi-corman.lisp has some suggestions on how to do that) 3. Ask the Corman Lisp developers to implement foreign-funcall(-pointer). 4. Ignore the problem until #2 or #3 are implemented. (Possibly not a big issue since Corman Lisp is not as widely used as other Lisps.) Cheers, Lu?s On Mon, May 29, 2017, 03:25 Anton Vodonosov wrote: > Luis, thanks for the response > > 29.05.2017, 05:18, "Lu?s Oliveira" : > > You can look up both functions using foreign-symbol-pointer > > to decide which one to call. You'd usually call the right one using > > foreign-funcall-pointer, but perhaps you can defcfun both and > > call the right one based on the lookup. > > Will that work on Corman? > > > > > defcfun-ing non-existent functions will yield runtime warnings on some > implementations > > (notably SBCL) so perhaps you might want to implement both the > foreign-funcall-pointer > > and defcfun approaches and conditionalise them accordingly. > > BTW, CMUCL fails with error in this case. > > > > > HTH, > > Lu?s > > > > On Mon, May 29, 2017, 02:56 Anton Vodonosov > wrote: > >> Hello, > >> > >> OpenSSL renamed function SSLeay to OpenSSL_version_num. > >> So, so depending on what version of library we work with we > >> need to call either SSLeay or OpenSSL_version_num. > >> > >> What is the best way to do it? > >> > >> The following is one approach: > >> > >> (or (ignore-errors > >> (cffi:foreign-funcall "OpenSSL_version_num" :long)) > >> (ignore-errors > >> (cffi:foreign-funcall "SSLeay" :long))) > >> > >> but it won't work on Corman Lisp because it doesn't > >> support cffi:foreign-funcall. > >> > >> I would like to be fully portable. Is there a better way? > >> > >> Best regards, > >> - Anton > -------------- next part -------------- An HTML attachment was scrubbed... URL: From avodonosov at yandex.ru Mon May 29 02:48:24 2017 From: avodonosov at yandex.ru (Anton Vodonosov) Date: Mon, 29 May 2017 05:48:24 +0300 Subject: invoking renamed foreign function In-Reply-To: References: <6124471496022979@web47g.yandex.ru> <5962541496024742@web22g.yandex.ru> Message-ID: <6211691496026104@web27m.yandex.ru> 29.05.2017, 05:42, "Lu?s Oliveira" : > foreign-symbol-pointer should work on Corman, yes. If so, maybe this is the best solution? (if (cffi:foreign-symbol-pointer "OpenSSL_version_num") (cffi:defcfun ("OpenSSL_version_num" ssleay) :long) (cffi:defcfun ("SSLeay" ssleay) :long)) > Hopefully defcfun-ing an unexisting function won't yield an error. > > Some alternative ideas, if that doesn't work: > > 1. Handle/ignore the defcfun error. At what time? (compile, load time, invocation time?) I was thinking about handling defcfun error but can't understand how to do that correctly? > 2. Implement foreign-funcall on Corman Lisp (src/cffi-corman.lisp has some suggestions on how to do that) > 3. Ask the Corman Lisp developers to implement foreign-funcall(-pointer). > 4. Ignore the problem until #2 or #3 are implemented. (Possibly not a big issue since Corman Lisp is not as widely used as other Lisps.) > > Cheers, > Lu?s > > On Mon, May 29, 2017, 03:25 Anton Vodonosov wrote: >> Luis, thanks for the response >> >> 29.05.2017, 05:18, "Lu?s Oliveira" : >>> You can look up both functions using foreign-symbol-pointer >>> to decide which one to call. You'd usually call the right one using >>> foreign-funcall-pointer, but perhaps you can defcfun both and >>> call the right one based on the lookup. >> >> Will that work on Corman? >> >>> >>> defcfun-ing non-existent functions will yield runtime warnings on some implementations >>> (notably SBCL) so perhaps you might want to implement both the foreign-funcall-pointer >>> and defcfun approaches and conditionalise them accordingly. >> >> BTW, CMUCL fails with error in this case. >> >>> >>> HTH, >>> Lu?s >>> >>> On Mon, May 29, 2017, 02:56 Anton Vodonosov wrote: >>>> Hello, >>>> >>>> OpenSSL renamed function SSLeay to OpenSSL_version_num. >>>> So, so depending on what version of library we work with we >>>> need to call either SSLeay or OpenSSL_version_num. >>>> >>>> What is the best way to do it? >>>> >>>> The following is one approach: >>>> >>>> (or (ignore-errors >>>> ? ? ? (cffi:foreign-funcall "OpenSSL_version_num" :long)) >>>> ? ? (ignore-errors >>>> ? ? ? (cffi:foreign-funcall "SSLeay" :long))) >>>> >>>> but it won't work on Corman Lisp because it doesn't >>>> support cffi:foreign-funcall. >>>> >>>> I would like to be fully portable. Is there a better way? >>>> >>>> Best regards, >>>> - Anton From luismbo at gmail.com Mon May 29 03:02:10 2017 From: luismbo at gmail.com (=?UTF-8?Q?Lu=C3=ADs_Oliveira?=) Date: Mon, 29 May 2017 03:02:10 +0000 Subject: invoking renamed foreign function In-Reply-To: <6211691496026104@web27m.yandex.ru> References: <6124471496022979@web47g.yandex.ru> <5962541496024742@web22g.yandex.ru> <6211691496026104@web27m.yandex.ru> Message-ID: That solution looks interesting. Does it work? I'm not sure about the defcfun error handling on CMUCL, sorry. I'd have to try it out. Cheers, Lu?s On Mon, May 29, 2017, 03:48 Anton Vodonosov wrote: > > > 29.05.2017, 05:42, "Lu?s Oliveira" : > > foreign-symbol-pointer should work on Corman, yes. > > If so, maybe this is the best solution? > > (if (cffi:foreign-symbol-pointer "OpenSSL_version_num") > (cffi:defcfun ("OpenSSL_version_num" ssleay) :long) > (cffi:defcfun ("SSLeay" ssleay) :long)) > > > > Hopefully defcfun-ing an unexisting function won't yield an error. > > > > Some alternative ideas, if that doesn't work: > > > > 1. Handle/ignore the defcfun error. > > At what time? (compile, load time, invocation time?) > I was thinking about handling defcfun error but can't understand how to do > that correctly? > > > 2. Implement foreign-funcall on Corman Lisp (src/cffi-corman.lisp has > some suggestions on how to do that) > > 3. Ask the Corman Lisp developers to implement foreign-funcall(-pointer). > > 4. Ignore the problem until #2 or #3 are implemented. (Possibly not a > big issue since Corman Lisp is not as widely used as other Lisps.) > > > > Cheers, > > Lu?s > > > > On Mon, May 29, 2017, 03:25 Anton Vodonosov > wrote: > >> Luis, thanks for the response > >> > >> 29.05.2017, 05:18, "Lu?s Oliveira" : > >>> You can look up both functions using foreign-symbol-pointer > >>> to decide which one to call. You'd usually call the right one using > >>> foreign-funcall-pointer, but perhaps you can defcfun both and > >>> call the right one based on the lookup. > >> > >> Will that work on Corman? > >> > >>> > >>> defcfun-ing non-existent functions will yield runtime warnings on some > implementations > >>> (notably SBCL) so perhaps you might want to implement both the > foreign-funcall-pointer > >>> and defcfun approaches and conditionalise them accordingly. > >> > >> BTW, CMUCL fails with error in this case. > >> > >>> > >>> HTH, > >>> Lu?s > >>> > >>> On Mon, May 29, 2017, 02:56 Anton Vodonosov > wrote: > >>>> Hello, > >>>> > >>>> OpenSSL renamed function SSLeay to OpenSSL_version_num. > >>>> So, so depending on what version of library we work with we > >>>> need to call either SSLeay or OpenSSL_version_num. > >>>> > >>>> What is the best way to do it? > >>>> > >>>> The following is one approach: > >>>> > >>>> (or (ignore-errors > >>>> (cffi:foreign-funcall "OpenSSL_version_num" :long)) > >>>> (ignore-errors > >>>> (cffi:foreign-funcall "SSLeay" :long))) > >>>> > >>>> but it won't work on Corman Lisp because it doesn't > >>>> support cffi:foreign-funcall. > >>>> > >>>> I would like to be fully portable. Is there a better way? > >>>> > >>>> Best regards, > >>>> - Anton > -------------- next part -------------- An HTML attachment was scrubbed... URL: From avodonosov at yandex.ru Mon May 29 03:12:33 2017 From: avodonosov at yandex.ru (Anton Vodonosov) Date: Mon, 29 May 2017 06:12:33 +0300 Subject: invoking renamed foreign function In-Reply-To: References: <6124471496022979@web47g.yandex.ru> <5962541496024742@web22g.yandex.ru> <6211691496026104@web27m.yandex.ru> Message-ID: <6218891496027553@web19j.yandex.ru> It does on SBCL. Is it correct theoretically to call DEFCFUN from inside of IF? Also, when somebody saves lisp image and the image opened next time, possibly different version of OpenSSL is loaded. The defcfun done before saving the image, will it conflict with the new library? 29.05.2017, 06:02, "Lu?s Oliveira" : > That solution looks interesting. Does it work? > > On Mon, May 29, 2017, 03:48 Anton Vodonosov wrote: > >> 29.05.2017, 05:42, "Lu?s Oliveira" : >>> foreign-symbol-pointer should work on Corman, yes. >> >> If so, maybe this is the best solution? >> >> ? ? (if (cffi:foreign-symbol-pointer "OpenSSL_version_num") >> ? ? ? ? (cffi:defcfun ("OpenSSL_version_num" ssleay) :long) >> ? ? ? ? (cffi:defcfun ("SSLeay" ssleay) :long)) >> From luismbo at gmail.com Mon May 29 03:20:38 2017 From: luismbo at gmail.com (=?UTF-8?Q?Lu=C3=ADs_Oliveira?=) Date: Mon, 29 May 2017 03:20:38 +0000 Subject: invoking renamed foreign function In-Reply-To: <6218891496027553@web19j.yandex.ru> References: <6124471496022979@web47g.yandex.ru> <5962541496024742@web22g.yandex.ru> <6211691496026104@web27m.yandex.ru> <6218891496027553@web19j.yandex.ru> Message-ID: Good catch. That approach won't be very robust when saving images. Lu?s On Mon, May 29, 2017, 04:12 Anton Vodonosov wrote: > > It does on SBCL. Is it correct theoretically to call DEFCFUN from inside > of IF? > > Also, when somebody saves lisp image and the image opened next time, > possibly different version of OpenSSL is loaded. The defcfun done > before saving the image, will it conflict with the new library? > > 29.05.2017, 06:02, "Lu?s Oliveira" : > > That solution looks interesting. Does it work? > > > > On Mon, May 29, 2017, 03:48 Anton Vodonosov > wrote: > > > >> 29.05.2017, 05:42, "Lu?s Oliveira" : > >>> foreign-symbol-pointer should work on Corman, yes. > >> > >> If so, maybe this is the best solution? > >> > >> (if (cffi:foreign-symbol-pointer "OpenSSL_version_num") > >> (cffi:defcfun ("OpenSSL_version_num" ssleay) :long) > >> (cffi:defcfun ("SSLeay" ssleay) :long)) > >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: