Message170998
I must be missing something--because I thought Python *already* depended on this apparently-undefined behavior. The small-block object allocator in Objects/obmalloc.c determines whether a pointer belongs to a particular arena using exactly this trick. I quote from the gigantic comment at the top of that file:
Let B be the arena base address associated with the pool,
B = arenas[(POOL)->arenaindex].address. Then P belongs to
the arena if and only if
B <= P < B + ARENA_SIZE
Subtracting B throughout, this is true iff
0 <= P-B < ARENA_SIZE
This test is implemented as the following macro:
#define Py_ADDRESS_IN_RANGE(P, POOL) \
((arenaindex_temp = (POOL)->arenaindex) < maxarenas && \
(uptr)(P) - arenas[arenaindex_temp].address < (uptr)ARENA_SIZE && \
arenas[arenaindex_temp].address != 0)
Why is that permissible but _PyLong_IS_SMALL_INT is not? |
|
Date |
User |
Action |
Args |
2012-09-22 14:11:26 | larry | set | recipients:
+ larry, loewis, rhettinger, amaury.forgeotdarc, mark.dickinson, pitrou, vstinner, eric.smith, stutzbach, asvetlov, meador.inge, xuanji, sdaoden, serhiy.storchaka |
2012-09-22 14:11:25 | larry | set | messageid: <1348323085.71.0.969906710557.issue10044@psf.upfronthosting.co.za> |
2012-09-22 14:11:25 | larry | link | issue10044 messages |
2012-09-22 14:11:22 | larry | create | |
|