Le 22/09/2020 à 19:16, Jorge Cardoso Leitão a écrit :
> Hi,
> 
> I had some time to look at https://issues.apache.org/jira/browse/ARROW-10039,
> wrt to the alignment requirements that rust implementation currently
> imposes.
> 
> The gist is that it is not that easy, and I would like to request some
> guidance.
> 
> Some facts:
> 1. Our current implementation does not accept a pointer if that pointer is
> not memory aligned (we panic)
> 2. Our rust implementation's alignment is a static/const that depends on
> the architecture and therefore constant throughout the program
> 3. Rust alloc/dealloc both require an argument denoting memory alignment.
> 4. calling dealloc with the wrong alignment is undefined behavior
> 
> 3-4 imply that removing our safeguard against unaligned memory (wrt to the
> constant alignment) leads to undefined behavior: we take ownership of a
> pointer with an alignment X != our alignment and when we try to free it, we
> enter undefined world.

If you are given a foreign pointer (e.g. coming from Python or C++), you
should simply never deallocate it yourself.  You don't know which
allocator gave you the pointer, and it's probably not the Rust allocator
(so it can't manage the pointer anyway).

What you should do is call the destructor, if any, that comes with the
buffer pointer.

I'll note again that the C data interface addresses those issues ;-)

Regards

Antoine.

Reply via email to