Larry Hastings added the comment: 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? ---------- nosy: +larry _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10044> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com