Skip to content

Commit

Permalink
replace Py_(u)intptr_t with the c99 standard types
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminp committed Sep 6, 2016
1 parent 3c397e4 commit ca47063
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions Include/pyatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef enum _Py_memory_order {
} _Py_memory_order;

typedef struct _Py_atomic_address {
Py_uintptr_t _value;
uintptr_t _value;
} _Py_atomic_address;

typedef struct _Py_atomic_int {
Expand Down Expand Up @@ -98,7 +98,7 @@ typedef enum _Py_memory_order {
} _Py_memory_order;

typedef struct _Py_atomic_address {
Py_uintptr_t _value;
uintptr_t _value;
} _Py_atomic_address;

typedef struct _Py_atomic_int {
Expand Down
8 changes: 4 additions & 4 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
#define _Py_SIZE_ROUND_UP(n, a) (((size_t)(n) + \
(size_t)((a) - 1)) & ~(size_t)((a) - 1))
/* Round pointer "p" down to the closest "a"-aligned address <= "p". */
#define _Py_ALIGN_DOWN(p, a) ((void *)((Py_uintptr_t)(p) & ~(Py_uintptr_t)((a) - 1)))
#define _Py_ALIGN_DOWN(p, a) ((void *)((uintptr_t)(p) & ~(uintptr_t)((a) - 1)))
/* Round pointer "p" up to the closest "a"-aligned address >= "p". */
#define _Py_ALIGN_UP(p, a) ((void *)(((Py_uintptr_t)(p) + \
(Py_uintptr_t)((a) - 1)) & ~(Py_uintptr_t)((a) - 1)))
#define _Py_ALIGN_UP(p, a) ((void *)(((uintptr_t)(p) + \
(uintptr_t)((a) - 1)) & ~(uintptr_t)((a) - 1)))
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
#define _Py_IS_ALIGNED(p, a) (!((Py_uintptr_t)(p) & (Py_uintptr_t)((a) - 1)))
#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))

#ifdef __GNUC__
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
Expand Down
6 changes: 3 additions & 3 deletions Include/pymem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef unsigned int _PyTraceMalloc_domain_t;
If memory block is already tracked, update the existing trace. */
PyAPI_FUNC(int) _PyTraceMalloc_Track(
_PyTraceMalloc_domain_t domain,
Py_uintptr_t ptr,
uintptr_t ptr,
size_t size);

/* Untrack an allocated memory block in the tracemalloc module.
Expand All @@ -46,7 +46,7 @@ PyAPI_FUNC(int) _PyTraceMalloc_Track(
Return -2 if tracemalloc is disabled, otherwise return 0. */
PyAPI_FUNC(int) _PyTraceMalloc_Untrack(
_PyTraceMalloc_domain_t domain,
Py_uintptr_t ptr);
uintptr_t ptr);

/* Get the traceback where a memory block was allocated.
Expand All @@ -58,7 +58,7 @@ PyAPI_FUNC(int) _PyTraceMalloc_Untrack(
Raise an exception and return NULL on error. */
PyAPI_FUNC(PyObject*) _PyTraceMalloc_GetTraceback(
_PyTraceMalloc_domain_t domain,
Py_uintptr_t ptr);
uintptr_t ptr);
#endif /* !Py_LIMITED_API */


Expand Down
8 changes: 4 additions & 4 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0)
that all use of text and tail as object pointers must be wrapped in
JOIN_OBJ. see comments in the ElementObject definition for more
info. */
#define JOIN_GET(p) ((Py_uintptr_t) (p) & 1)
#define JOIN_SET(p, flag) ((void*) ((Py_uintptr_t) (JOIN_OBJ(p)) | (flag)))
#define JOIN_OBJ(p) ((PyObject*) ((Py_uintptr_t) (p) & ~(Py_uintptr_t)1))
#define JOIN_GET(p) ((uintptr_t) (p) & 1)
#define JOIN_SET(p, flag) ((void*) ((uintptr_t) (JOIN_OBJ(p)) | (flag)))
#define JOIN_OBJ(p) ((PyObject*) ((uintptr_t) (p) & ~(uintptr_t)1))

/* Py_CLEAR for a PyObject* that uses a join flag. Pass the pointer by
* reference since this function sets it to NULL.
Expand Down Expand Up @@ -797,7 +797,7 @@ _elementtree_Element___deepcopy__(ElementObject *self, PyObject *memo)
}

/* add object to memo dictionary (so deepcopy won't visit it again) */
id = PyLong_FromSsize_t((Py_uintptr_t) self);
id = PyLong_FromSsize_t((uintptr_t) self);
if (!id)
goto error;

Expand Down
14 changes: 7 additions & 7 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
skip = *code; \
VTRACE(("%lu (skip to %p)\n", \
(unsigned long)skip, code+skip)); \
if (skip-adj > (Py_uintptr_t)(end - code)) \
if (skip-adj > (uintptr_t)(end - code)) \
FAIL; \
code++; \
} while (0)
Expand Down Expand Up @@ -1616,15 +1616,15 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)

case SRE_OP_CHARSET:
offset = 256/SRE_CODE_BITS; /* 256-bit bitmap */
if (offset > (Py_uintptr_t)(end - code))
if (offset > (uintptr_t)(end - code))
FAIL;
code += offset;
break;

case SRE_OP_BIGCHARSET:
GET_ARG; /* Number of blocks */
offset = 256/sizeof(SRE_CODE); /* 256-byte table */
if (offset > (Py_uintptr_t)(end - code))
if (offset > (uintptr_t)(end - code))
FAIL;
/* Make sure that each byte points to a valid block */
for (i = 0; i < 256; i++) {
Expand All @@ -1633,7 +1633,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)
}
code += offset;
offset = arg * (256/SRE_CODE_BITS); /* 256-bit bitmap times arg */
if (offset > (Py_uintptr_t)(end - code))
if (offset > (uintptr_t)(end - code))
FAIL;
code += offset;
break;
Expand Down Expand Up @@ -1784,11 +1784,11 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
GET_ARG; prefix_len = arg;
GET_ARG;
/* Here comes the prefix string */
if (prefix_len > (Py_uintptr_t)(newcode - code))
if (prefix_len > (uintptr_t)(newcode - code))
FAIL;
code += prefix_len;
/* And here comes the overlap table */
if (prefix_len > (Py_uintptr_t)(newcode - code))
if (prefix_len > (uintptr_t)(newcode - code))
FAIL;
/* Each overlap value should be < prefix_len */
for (i = 0; i < prefix_len; i++) {
Expand Down Expand Up @@ -1917,7 +1917,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
to allow arbitrary jumps anywhere in the code; so we just look
for a JUMP opcode preceding our skip target.
*/
if (skip >= 3 && skip-3 < (Py_uintptr_t)(end - code) &&
if (skip >= 3 && skip-3 < (uintptr_t)(end - code) &&
code[skip-3] == SRE_OP_JUMP)
{
VTRACE(("both then and else parts present\n"));
Expand Down
16 changes: 8 additions & 8 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ test_sizeof_c_types(PyObject *self)
CHECK_SIZEOF(Py_ssize_t, sizeof(void *));
CHECK_SIGNNESS(Py_ssize_t, 1);

CHECK_SIZEOF(Py_uintptr_t, sizeof(void *));
CHECK_SIGNNESS(Py_uintptr_t, 0);
CHECK_SIZEOF(Py_intptr_t, sizeof(void *));
CHECK_SIGNNESS(Py_intptr_t, 1);
CHECK_SIZEOF(uintptr_t, sizeof(void *));
CHECK_SIGNNESS(uintptr_t, 0);
CHECK_SIZEOF(intptr_t, sizeof(void *));
CHECK_SIGNNESS(intptr_t, 1);

Py_INCREF(Py_None);
return Py_None;
Expand Down Expand Up @@ -3861,11 +3861,11 @@ tracemalloc_track(PyObject *self, PyObject *args)

if (release_gil) {
Py_BEGIN_ALLOW_THREADS
res = _PyTraceMalloc_Track(domain, (Py_uintptr_t)ptr, size);
res = _PyTraceMalloc_Track(domain, (uintptr_t)ptr, size);
Py_END_ALLOW_THREADS
}
else {
res = _PyTraceMalloc_Track(domain, (Py_uintptr_t)ptr, size);
res = _PyTraceMalloc_Track(domain, (uintptr_t)ptr, size);
}

if (res < 0) {
Expand All @@ -3890,7 +3890,7 @@ tracemalloc_untrack(PyObject *self, PyObject *args)
if (PyErr_Occurred())
return NULL;

res = _PyTraceMalloc_Untrack(domain, (Py_uintptr_t)ptr);
res = _PyTraceMalloc_Untrack(domain, (uintptr_t)ptr);
if (res < 0) {
PyErr_SetString(PyExc_RuntimeError, "_PyTraceMalloc_Track error");
return NULL;
Expand All @@ -3912,7 +3912,7 @@ tracemalloc_get_traceback(PyObject *self, PyObject *args)
if (PyErr_Occurred())
return NULL;

return _PyTraceMalloc_GetTraceback(domain, (Py_uintptr_t)ptr);
return _PyTraceMalloc_GetTraceback(domain, (uintptr_t)ptr);
}


Expand Down
30 changes: 15 additions & 15 deletions Modules/_tracemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct
__attribute__((packed))
#endif
{
Py_uintptr_t ptr;
uintptr_t ptr;
_PyTraceMalloc_domain_t domain;
} pointer_t;

Expand Down Expand Up @@ -523,7 +523,7 @@ static int
tracemalloc_use_domain_cb(_Py_hashtable_t *old_traces,
_Py_hashtable_entry_t *entry, void *user_data)
{
Py_uintptr_t ptr;
uintptr_t ptr;
pointer_t key;
_Py_hashtable_t *new_traces = (_Py_hashtable_t *)user_data;
const void *pdata = _Py_HASHTABLE_ENTRY_PDATA(old_traces, entry);
Expand All @@ -538,7 +538,7 @@ tracemalloc_use_domain_cb(_Py_hashtable_t *old_traces,
}


/* Convert tracemalloc_traces from compact key (Py_uintptr_t) to pointer_t key.
/* Convert tracemalloc_traces from compact key (uintptr_t) to pointer_t key.
* Return 0 on success, -1 on error. */
static int
tracemalloc_use_domain(void)
Expand Down Expand Up @@ -572,7 +572,7 @@ tracemalloc_use_domain(void)


static void
tracemalloc_remove_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
tracemalloc_remove_trace(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
{
trace_t trace;
int removed;
Expand All @@ -595,11 +595,11 @@ tracemalloc_remove_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
}

#define REMOVE_TRACE(ptr) \
tracemalloc_remove_trace(DEFAULT_DOMAIN, (Py_uintptr_t)(ptr))
tracemalloc_remove_trace(DEFAULT_DOMAIN, (uintptr_t)(ptr))


static int
tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
size_t size)
{
pointer_t key = {ptr, domain};
Expand All @@ -617,7 +617,7 @@ tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,

if (!tracemalloc_config.use_domain && domain != DEFAULT_DOMAIN) {
/* first trace using a non-zero domain whereas traces use compact
(Py_uintptr_t) keys: switch to pointer_t keys. */
(uintptr_t) keys: switch to pointer_t keys. */
if (tracemalloc_use_domain() < 0) {
return -1;
}
Expand Down Expand Up @@ -663,7 +663,7 @@ tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
}

#define ADD_TRACE(ptr, size) \
tracemalloc_add_trace(DEFAULT_DOMAIN, (Py_uintptr_t)(ptr), size)
tracemalloc_add_trace(DEFAULT_DOMAIN, (uintptr_t)(ptr), size)


static void*
Expand Down Expand Up @@ -1023,7 +1023,7 @@ tracemalloc_init(void)
hashtable_compare_pointer_t);
}
else {
tracemalloc_traces = hashtable_new(sizeof(Py_uintptr_t),
tracemalloc_traces = hashtable_new(sizeof(uintptr_t),
sizeof(trace_t),
_Py_hashtable_hash_ptr,
_Py_hashtable_compare_direct);
Expand Down Expand Up @@ -1414,7 +1414,7 @@ py_tracemalloc_get_traces(PyObject *self, PyObject *obj)


static traceback_t*
tracemalloc_get_traceback(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
tracemalloc_get_traceback(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
{
trace_t trace;
int found;
Expand Down Expand Up @@ -1461,7 +1461,7 @@ py_tracemalloc_get_object_traceback(PyObject *self, PyObject *obj)
else
ptr = (void *)obj;

traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (Py_uintptr_t)ptr);
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
if (traceback == NULL)
Py_RETURN_NONE;

Expand Down Expand Up @@ -1489,7 +1489,7 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
traceback_t *traceback;
int i;

traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (Py_uintptr_t)ptr);
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
if (traceback == NULL)
return;

Expand Down Expand Up @@ -1762,7 +1762,7 @@ _PyTraceMalloc_Fini(void)
}

int
_PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
_PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
size_t size)
{
int res;
Expand Down Expand Up @@ -1791,7 +1791,7 @@ _PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,


int
_PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
_PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
{
if (!tracemalloc_config.tracing) {
/* tracemalloc is not tracing: do nothing */
Expand All @@ -1807,7 +1807,7 @@ _PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)


PyObject*
_PyTraceMalloc_GetTraceback(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
_PyTraceMalloc_GetTraceback(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
{
traceback_t *traceback;

Expand Down
10 changes: 5 additions & 5 deletions Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,12 +1072,12 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
# pragma intel optimization_level 0
#endif
static
Py_uintptr_t
stack_overflow(Py_uintptr_t min_sp, Py_uintptr_t max_sp, size_t *depth)
uintptr_t
stack_overflow(uintptr_t min_sp, uintptr_t max_sp, size_t *depth)
{
/* allocate 4096 bytes on the stack at each call */
unsigned char buffer[4096];
Py_uintptr_t sp = (Py_uintptr_t)&buffer;
uintptr_t sp = (uintptr_t)&buffer;
*depth += 1;
if (sp < min_sp || max_sp < sp)
return sp;
Expand All @@ -1090,8 +1090,8 @@ static PyObject *
faulthandler_stack_overflow(PyObject *self)
{
size_t depth, size;
Py_uintptr_t sp = (Py_uintptr_t)&depth;
Py_uintptr_t stop;
uintptr_t sp = (uintptr_t)&depth;
uintptr_t stop;

faulthandler_suppress_crash_report();
depth = 0;
Expand Down
Loading

0 comments on commit ca47063

Please sign in to comment.