Changeset View
Changeset View
Standalone View
Standalone View
contrib/binutils/include/obstack.h
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
/* Don't do the contents of this file more than once. */ | /* Don't do the contents of this file more than once. */ | ||||
#ifndef _OBSTACK_H | #ifndef _OBSTACK_H | ||||
#define _OBSTACK_H 1 | #define _OBSTACK_H 1 | ||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||
extern "C" { | extern "C" { | ||||
#endif | #endif | ||||
␌ | ␌ | ||||
theraven: C doesn't require that `int*` and `void*` have the same representation. On some (very) old… | |||||
/* We use subtraction of (char *) 0 instead of casting to int | /* We use subtraction of (char *) 0 instead of casting to int | ||||
because on word-addressable machines a simple cast to int | because on word-addressable machines a simple cast to int | ||||
may ignore the byte-within-word field of the pointer. */ | may ignore the byte-within-word field of the pointer. */ | ||||
#ifndef __PTR_TO_INT | #ifndef __PTR_TO_INT | ||||
# define __PTR_TO_INT(P) ((P) - (char *) 0) | # define __PTR_TO_INT(P) ((intptr_t)(P)) | ||||
#endif | #endif | ||||
#ifndef __INT_TO_PTR | #ifndef __INT_TO_PTR | ||||
# define __INT_TO_PTR(P) ((P) + (char *) 0) | # define __INT_TO_PTR(P) ((void*)(intptr_t)(P)) | ||||
#endif | #endif | ||||
/* We need the type of the resulting object. If __PTRDIFF_TYPE__ is | /* We need the type of the resulting object. If __PTRDIFF_TYPE__ is | ||||
defined, as with GNU C, use that; that way we don't pollute the | defined, as with GNU C, use that; that way we don't pollute the | ||||
namespace with <stddef.h>'s symbols. Otherwise, if <stddef.h> is | namespace with <stddef.h>'s symbols. Otherwise, if <stddef.h> is | ||||
available, include it and use ptrdiff_t. In traditional C, long is | available, include it and use ptrdiff_t. In traditional C, long is | ||||
the best that we can do. */ | the best that we can do. */ | ||||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Lines | |||||
__extension__ \ | __extension__ \ | ||||
({ struct obstack *__o1 = (OBSTACK); \ | ({ struct obstack *__o1 = (OBSTACK); \ | ||||
void *value; \ | void *value; \ | ||||
value = (void *) __o1->object_base; \ | value = (void *) __o1->object_base; \ | ||||
if (__o1->next_free == value) \ | if (__o1->next_free == value) \ | ||||
__o1->maybe_empty_object = 1; \ | __o1->maybe_empty_object = 1; \ | ||||
__o1->next_free \ | __o1->next_free \ | ||||
= __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\ | = __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\ | ||||
& ~ (__o1->alignment_mask)); \ | & ~(intptr_t)(__o1->alignment_mask)); \ | ||||
if (__o1->next_free - (char *)__o1->chunk \ | if (__o1->next_free - (char *)__o1->chunk \ | ||||
> __o1->chunk_limit - (char *)__o1->chunk) \ | > __o1->chunk_limit - (char *)__o1->chunk) \ | ||||
__o1->next_free = __o1->chunk_limit; \ | __o1->next_free = __o1->chunk_limit; \ | ||||
__o1->object_base = __o1->next_free; \ | __o1->object_base = __o1->next_free; \ | ||||
value; }) | value; }) | ||||
# define obstack_free(OBSTACK, OBJ) \ | # define obstack_free(OBSTACK, OBJ) \ | ||||
__extension__ \ | __extension__ \ | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |
C doesn't require that int* and void* have the same representation. On some (very) old machines, loads and stores worked only at the granularity of a machine word (typically 16 bits, though sometimes larger). An int* on such a machine was represented as a (word) address, but a char* might be a pair of an address and a byte offset. Accessing a char required a load an a shift or mask.
I think binutils still supports at least one such architecture (though FreeBSD doesn't).
Generally, I think we lower WARNS on contrib code, especially poor-quality GNU code, though when the fix is this simple it might be worth retaining - especially as binutils is due a de-orbit burn soon and is unlikely to ever receive an update..