Skip to content

Commit ca47063

Browse files
committed
replace Py_(u)intptr_t with the c99 standard types
1 parent 3c397e4 commit ca47063

21 files changed

+86
-86
lines changed

Include/pyatomic.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef enum _Py_memory_order {
6161
} _Py_memory_order;
6262

6363
typedef struct _Py_atomic_address {
64-
Py_uintptr_t _value;
64+
uintptr_t _value;
6565
} _Py_atomic_address;
6666

6767
typedef struct _Py_atomic_int {
@@ -98,7 +98,7 @@ typedef enum _Py_memory_order {
9898
} _Py_memory_order;
9999

100100
typedef struct _Py_atomic_address {
101-
Py_uintptr_t _value;
101+
uintptr_t _value;
102102
} _Py_atomic_address;
103103

104104
typedef struct _Py_atomic_int {

Include/pymacro.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@
7979
#define _Py_SIZE_ROUND_UP(n, a) (((size_t)(n) + \
8080
(size_t)((a) - 1)) & ~(size_t)((a) - 1))
8181
/* Round pointer "p" down to the closest "a"-aligned address <= "p". */
82-
#define _Py_ALIGN_DOWN(p, a) ((void *)((Py_uintptr_t)(p) & ~(Py_uintptr_t)((a) - 1)))
82+
#define _Py_ALIGN_DOWN(p, a) ((void *)((uintptr_t)(p) & ~(uintptr_t)((a) - 1)))
8383
/* Round pointer "p" up to the closest "a"-aligned address >= "p". */
84-
#define _Py_ALIGN_UP(p, a) ((void *)(((Py_uintptr_t)(p) + \
85-
(Py_uintptr_t)((a) - 1)) & ~(Py_uintptr_t)((a) - 1)))
84+
#define _Py_ALIGN_UP(p, a) ((void *)(((uintptr_t)(p) + \
85+
(uintptr_t)((a) - 1)) & ~(uintptr_t)((a) - 1)))
8686
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
87-
#define _Py_IS_ALIGNED(p, a) (!((Py_uintptr_t)(p) & (Py_uintptr_t)((a) - 1)))
87+
#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))
8888

8989
#ifdef __GNUC__
9090
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))

Include/pymem.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ typedef unsigned int _PyTraceMalloc_domain_t;
3737
If memory block is already tracked, update the existing trace. */
3838
PyAPI_FUNC(int) _PyTraceMalloc_Track(
3939
_PyTraceMalloc_domain_t domain,
40-
Py_uintptr_t ptr,
40+
uintptr_t ptr,
4141
size_t size);
4242

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

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

6464

Modules/_elementtree.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ do { memory -= size; printf("%8d - %s\n", memory, comment); } while (0)
5757
that all use of text and tail as object pointers must be wrapped in
5858
JOIN_OBJ. see comments in the ElementObject definition for more
5959
info. */
60-
#define JOIN_GET(p) ((Py_uintptr_t) (p) & 1)
61-
#define JOIN_SET(p, flag) ((void*) ((Py_uintptr_t) (JOIN_OBJ(p)) | (flag)))
62-
#define JOIN_OBJ(p) ((PyObject*) ((Py_uintptr_t) (p) & ~(Py_uintptr_t)1))
60+
#define JOIN_GET(p) ((uintptr_t) (p) & 1)
61+
#define JOIN_SET(p, flag) ((void*) ((uintptr_t) (JOIN_OBJ(p)) | (flag)))
62+
#define JOIN_OBJ(p) ((PyObject*) ((uintptr_t) (p) & ~(uintptr_t)1))
6363

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

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

Modules/_sre.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
15821582
skip = *code; \
15831583
VTRACE(("%lu (skip to %p)\n", \
15841584
(unsigned long)skip, code+skip)); \
1585-
if (skip-adj > (Py_uintptr_t)(end - code)) \
1585+
if (skip-adj > (uintptr_t)(end - code)) \
15861586
FAIL; \
15871587
code++; \
15881588
} while (0)
@@ -1616,15 +1616,15 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)
16161616

16171617
case SRE_OP_CHARSET:
16181618
offset = 256/SRE_CODE_BITS; /* 256-bit bitmap */
1619-
if (offset > (Py_uintptr_t)(end - code))
1619+
if (offset > (uintptr_t)(end - code))
16201620
FAIL;
16211621
code += offset;
16221622
break;
16231623

16241624
case SRE_OP_BIGCHARSET:
16251625
GET_ARG; /* Number of blocks */
16261626
offset = 256/sizeof(SRE_CODE); /* 256-byte table */
1627-
if (offset > (Py_uintptr_t)(end - code))
1627+
if (offset > (uintptr_t)(end - code))
16281628
FAIL;
16291629
/* Make sure that each byte points to a valid block */
16301630
for (i = 0; i < 256; i++) {
@@ -1633,7 +1633,7 @@ _validate_charset(SRE_CODE *code, SRE_CODE *end)
16331633
}
16341634
code += offset;
16351635
offset = arg * (256/SRE_CODE_BITS); /* 256-bit bitmap times arg */
1636-
if (offset > (Py_uintptr_t)(end - code))
1636+
if (offset > (uintptr_t)(end - code))
16371637
FAIL;
16381638
code += offset;
16391639
break;
@@ -1784,11 +1784,11 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
17841784
GET_ARG; prefix_len = arg;
17851785
GET_ARG;
17861786
/* Here comes the prefix string */
1787-
if (prefix_len > (Py_uintptr_t)(newcode - code))
1787+
if (prefix_len > (uintptr_t)(newcode - code))
17881788
FAIL;
17891789
code += prefix_len;
17901790
/* And here comes the overlap table */
1791-
if (prefix_len > (Py_uintptr_t)(newcode - code))
1791+
if (prefix_len > (uintptr_t)(newcode - code))
17921792
FAIL;
17931793
/* Each overlap value should be < prefix_len */
17941794
for (i = 0; i < prefix_len; i++) {
@@ -1917,7 +1917,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
19171917
to allow arbitrary jumps anywhere in the code; so we just look
19181918
for a JUMP opcode preceding our skip target.
19191919
*/
1920-
if (skip >= 3 && skip-3 < (Py_uintptr_t)(end - code) &&
1920+
if (skip >= 3 && skip-3 < (uintptr_t)(end - code) &&
19211921
code[skip-3] == SRE_OP_JUMP)
19221922
{
19231923
VTRACE(("both then and else parts present\n"));

Modules/_testcapimodule.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ test_sizeof_c_types(PyObject *self)
113113
CHECK_SIZEOF(Py_ssize_t, sizeof(void *));
114114
CHECK_SIGNNESS(Py_ssize_t, 1);
115115

116-
CHECK_SIZEOF(Py_uintptr_t, sizeof(void *));
117-
CHECK_SIGNNESS(Py_uintptr_t, 0);
118-
CHECK_SIZEOF(Py_intptr_t, sizeof(void *));
119-
CHECK_SIGNNESS(Py_intptr_t, 1);
116+
CHECK_SIZEOF(uintptr_t, sizeof(void *));
117+
CHECK_SIGNNESS(uintptr_t, 0);
118+
CHECK_SIZEOF(intptr_t, sizeof(void *));
119+
CHECK_SIGNNESS(intptr_t, 1);
120120

121121
Py_INCREF(Py_None);
122122
return Py_None;
@@ -3861,11 +3861,11 @@ tracemalloc_track(PyObject *self, PyObject *args)
38613861

38623862
if (release_gil) {
38633863
Py_BEGIN_ALLOW_THREADS
3864-
res = _PyTraceMalloc_Track(domain, (Py_uintptr_t)ptr, size);
3864+
res = _PyTraceMalloc_Track(domain, (uintptr_t)ptr, size);
38653865
Py_END_ALLOW_THREADS
38663866
}
38673867
else {
3868-
res = _PyTraceMalloc_Track(domain, (Py_uintptr_t)ptr, size);
3868+
res = _PyTraceMalloc_Track(domain, (uintptr_t)ptr, size);
38693869
}
38703870

38713871
if (res < 0) {
@@ -3890,7 +3890,7 @@ tracemalloc_untrack(PyObject *self, PyObject *args)
38903890
if (PyErr_Occurred())
38913891
return NULL;
38923892

3893-
res = _PyTraceMalloc_Untrack(domain, (Py_uintptr_t)ptr);
3893+
res = _PyTraceMalloc_Untrack(domain, (uintptr_t)ptr);
38943894
if (res < 0) {
38953895
PyErr_SetString(PyExc_RuntimeError, "_PyTraceMalloc_Track error");
38963896
return NULL;
@@ -3912,7 +3912,7 @@ tracemalloc_get_traceback(PyObject *self, PyObject *args)
39123912
if (PyErr_Occurred())
39133913
return NULL;
39143914

3915-
return _PyTraceMalloc_GetTraceback(domain, (Py_uintptr_t)ptr);
3915+
return _PyTraceMalloc_GetTraceback(domain, (uintptr_t)ptr);
39163916
}
39173917

39183918

Modules/_tracemalloc.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef struct
6767
__attribute__((packed))
6868
#endif
6969
{
70-
Py_uintptr_t ptr;
70+
uintptr_t ptr;
7171
_PyTraceMalloc_domain_t domain;
7272
} pointer_t;
7373

@@ -523,7 +523,7 @@ static int
523523
tracemalloc_use_domain_cb(_Py_hashtable_t *old_traces,
524524
_Py_hashtable_entry_t *entry, void *user_data)
525525
{
526-
Py_uintptr_t ptr;
526+
uintptr_t ptr;
527527
pointer_t key;
528528
_Py_hashtable_t *new_traces = (_Py_hashtable_t *)user_data;
529529
const void *pdata = _Py_HASHTABLE_ENTRY_PDATA(old_traces, entry);
@@ -538,7 +538,7 @@ tracemalloc_use_domain_cb(_Py_hashtable_t *old_traces,
538538
}
539539

540540

541-
/* Convert tracemalloc_traces from compact key (Py_uintptr_t) to pointer_t key.
541+
/* Convert tracemalloc_traces from compact key (uintptr_t) to pointer_t key.
542542
* Return 0 on success, -1 on error. */
543543
static int
544544
tracemalloc_use_domain(void)
@@ -572,7 +572,7 @@ tracemalloc_use_domain(void)
572572

573573

574574
static void
575-
tracemalloc_remove_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
575+
tracemalloc_remove_trace(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
576576
{
577577
trace_t trace;
578578
int removed;
@@ -595,11 +595,11 @@ tracemalloc_remove_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
595595
}
596596

597597
#define REMOVE_TRACE(ptr) \
598-
tracemalloc_remove_trace(DEFAULT_DOMAIN, (Py_uintptr_t)(ptr))
598+
tracemalloc_remove_trace(DEFAULT_DOMAIN, (uintptr_t)(ptr))
599599

600600

601601
static int
602-
tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
602+
tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
603603
size_t size)
604604
{
605605
pointer_t key = {ptr, domain};
@@ -617,7 +617,7 @@ tracemalloc_add_trace(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
617617

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

665665
#define ADD_TRACE(ptr, size) \
666-
tracemalloc_add_trace(DEFAULT_DOMAIN, (Py_uintptr_t)(ptr), size)
666+
tracemalloc_add_trace(DEFAULT_DOMAIN, (uintptr_t)(ptr), size)
667667

668668

669669
static void*
@@ -1023,7 +1023,7 @@ tracemalloc_init(void)
10231023
hashtable_compare_pointer_t);
10241024
}
10251025
else {
1026-
tracemalloc_traces = hashtable_new(sizeof(Py_uintptr_t),
1026+
tracemalloc_traces = hashtable_new(sizeof(uintptr_t),
10271027
sizeof(trace_t),
10281028
_Py_hashtable_hash_ptr,
10291029
_Py_hashtable_compare_direct);
@@ -1414,7 +1414,7 @@ py_tracemalloc_get_traces(PyObject *self, PyObject *obj)
14141414

14151415

14161416
static traceback_t*
1417-
tracemalloc_get_traceback(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
1417+
tracemalloc_get_traceback(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
14181418
{
14191419
trace_t trace;
14201420
int found;
@@ -1461,7 +1461,7 @@ py_tracemalloc_get_object_traceback(PyObject *self, PyObject *obj)
14611461
else
14621462
ptr = (void *)obj;
14631463

1464-
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (Py_uintptr_t)ptr);
1464+
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
14651465
if (traceback == NULL)
14661466
Py_RETURN_NONE;
14671467

@@ -1489,7 +1489,7 @@ _PyMem_DumpTraceback(int fd, const void *ptr)
14891489
traceback_t *traceback;
14901490
int i;
14911491

1492-
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (Py_uintptr_t)ptr);
1492+
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr);
14931493
if (traceback == NULL)
14941494
return;
14951495

@@ -1762,7 +1762,7 @@ _PyTraceMalloc_Fini(void)
17621762
}
17631763

17641764
int
1765-
_PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
1765+
_PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, uintptr_t ptr,
17661766
size_t size)
17671767
{
17681768
int res;
@@ -1791,7 +1791,7 @@ _PyTraceMalloc_Track(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr,
17911791

17921792

17931793
int
1794-
_PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
1794+
_PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
17951795
{
17961796
if (!tracemalloc_config.tracing) {
17971797
/* tracemalloc is not tracing: do nothing */
@@ -1807,7 +1807,7 @@ _PyTraceMalloc_Untrack(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
18071807

18081808

18091809
PyObject*
1810-
_PyTraceMalloc_GetTraceback(_PyTraceMalloc_domain_t domain, Py_uintptr_t ptr)
1810+
_PyTraceMalloc_GetTraceback(_PyTraceMalloc_domain_t domain, uintptr_t ptr)
18111811
{
18121812
traceback_t *traceback;
18131813

Modules/faulthandler.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1072,12 +1072,12 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
10721072
# pragma intel optimization_level 0
10731073
#endif
10741074
static
1075-
Py_uintptr_t
1076-
stack_overflow(Py_uintptr_t min_sp, Py_uintptr_t max_sp, size_t *depth)
1075+
uintptr_t
1076+
stack_overflow(uintptr_t min_sp, uintptr_t max_sp, size_t *depth)
10771077
{
10781078
/* allocate 4096 bytes on the stack at each call */
10791079
unsigned char buffer[4096];
1080-
Py_uintptr_t sp = (Py_uintptr_t)&buffer;
1080+
uintptr_t sp = (uintptr_t)&buffer;
10811081
*depth += 1;
10821082
if (sp < min_sp || max_sp < sp)
10831083
return sp;
@@ -1090,8 +1090,8 @@ static PyObject *
10901090
faulthandler_stack_overflow(PyObject *self)
10911091
{
10921092
size_t depth, size;
1093-
Py_uintptr_t sp = (Py_uintptr_t)&depth;
1094-
Py_uintptr_t stop;
1093+
uintptr_t sp = (uintptr_t)&depth;
1094+
uintptr_t stop;
10951095

10961096
faulthandler_suppress_crash_report();
10971097
depth = 0;

0 commit comments

Comments
 (0)