[SciPy-Dev] qhull FFI

Nil Goyette nil.goyette at imeka.ca
Mon Jul 5 11:24:50 EDT 2021


Hi Robert,

Thank you, this is an excellent answer. You only define what you need
because it becomes a part of SciPy code, like any other pyx file is. This
is not FFI at all.

Copying SciPy/qhull structures and types wasn't my best idea after all :D
I'll continue my work using only the qhull source then.

Nil Goyette

Le lun. 5 juill. 2021, à 10 h 19, Robert Kern <robert.kern at gmail.com> a
écrit :

> On Mon, Jul 5, 2021 at 10:12 AM Nil Goyette <nil.goyette at imeka.ca> wrote:
>
>> Hi all,
>>
>> I've been trying to use qhull in a Rust project so of course I wondered
>> how SciPy managed to do it before I tried to code my own FFI. When my
>> version didn't work, I looked deeper in SciPy and there's something I don't
>> understand. We can find several definitions In qhull_src/src/libqhull_r.h,
>> like facetT
>>
>> ctypedef struct facetT:
>>     coordT offset
>>     coordT *center
>>     coordT *normal
>>     facetT  *previous;
>>     facetT  *next;
>>     ... a total of 16 fields
>>
>> And the "corresponding" definitions in qhull.pyx
>>
>> struct facetT {
>>     coordT   offset;
>>     coordT  *normal;
>>     union { 6 fields }
>>     coordT  *center;
>>     facetT *next
>>     facetT *previoust
>>     ... A total of 37 fields
>>
>> Now I'm puzzled. There are several missing fields and they are wrongly
>> ordered! I'm not a FFI expert at all but, as a programmer, I would have
>> thought that the definitions needed to match perfectly, at least for the
>> order and the number of bytes (total and per field).
>>
>> Can someone please explain to me why only some fields match and why this
>> is not a problem? Thank you.
>>
>
> Cython is not an FFI per se. It is a language that is transpiled to C and
> is exposed to Python using Python's standard C extension module mechanism.
> When describing the `ctypedef struct`, it only needs to describe the struct
> members that you are going to refer to in the Cython code so that it can
> deal with their types properly. Because it transpiles source-to-source, it
> doesn't need to know the full details of the binary API. The C compiler is
> doing that job, and it sees the original `.h` file from QHull.
>
> --
> Robert Kern
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>


-- 
Nil Goyette
Développeur principal
www.imeka.ca

-- 
During this time of social distancing, we offer free webinars on subjects 
that matter. <https://www.imeka.ca/webinars/>

CONFIDENTIALITY NOTICE: This 
message, and any attachments, is intended only for the use of the addressee 
or his authorized representative. It may contain information that is 
privileged, confidential and exempt from disclosure under applicable law. 
If the reader of this message is not the intended recipient, or his 
authorized representative, you are hereby notified that any dissemination, 
distribution or copying of this message and any attachments is strictly 
prohibited. The integrity of this message cannot be guaranteed on the 
Internet, IMEKA shall not be liable for its content if altered, changed or 
falsified. If you have received this message in error, please contact 
immediately the sender and delete this message and any attachments from 
your system.


AVIS DE CONFIDENTIALITÉ : Ce message, ainsi que tout fichier 
qui y est joint, est destiné exclusivement aux personnes à qui il est 
adressé. Il peut contenir des informations de nature confidentielle qui ne 
doivent être divulguées en vertu des lois applicables. Si vous n'êtes pas 
le destinataire de ce message ou un mandataire autorisé de celui-ci, vous 
êtes avisé par la présente que toute impression, diffusion, distribution ou 
reproduction de ce message et de tout fichier qui y est joint est 
strictement interdite. L'intégrité de ce message n'étant pas assurée sur 
Internet, IMEKA ne peut être tenue responsable de son contenu s'il a été 
altéré, déformé ou falsifié. Si ce message vous a été transmis par erreur, 
veuillez en aviser sans délai l'expéditeur et l'effacer ainsi que tout 
fichier joint sans en conserver de copie.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scipy-dev/attachments/20210705/ba3f9330/attachment.html>


More information about the SciPy-Dev mailing list