bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#65491: [PATCH] Improve performance allocating vectors


From: Stefan Monnier
Subject: bug#65491: [PATCH] Improve performance allocating vectors
Date: Mon, 18 Sep 2023 00:10:25 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

>      When casting from pointer to integer and back again, the resulting
>      pointer must reference the same object as the original pointer,
>      otherwise the behavior is undefined.  That is, one may not use
>      integer arithmetic to avoid the undefined behavior of pointer
>      arithmetic as proscribed in C99 and C11 6.5.6/8.

Then they're (still) warning about a different situation than ours,
i.e. the case where the integer is not the same, e.g. you cast to
integer, do some arithmetic giving you a *different* number and then
cast it back to a pointer.  The way they write it means that even if the
number is different it can still be "well"-defined (in the case where
the pointer is still pointing to the same object).  I'd guess this can
happen if you the integer arithmetic ends up moving from one slot to
another inside an array, for example.

But in any case our TAG+UNTAG is simpler since (barring bugs) we always
cast back the exact same integer, so the condition that "the resulting
pointer must reference the same object as the original pointer" can only
fail if the object was deallocated in the mean time, or if the integer
was too small to contain the pointer (and both of those conditions
should be true in our case, barring bugs).


        Stefan






reply via email to

[Prev in Thread] Current Thread [Next in Thread]