Skip to content

gh-88929: remove outdated reference to Py_USING_MEMORY_DEBUGGER #27509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Include/internal/pycore_dtoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ Bigint {
ULong x[1];
};

#ifdef Py_USING_MEMORY_DEBUGGER

struct _dtoa_runtime_state {
int _not_used;
};
#define _dtoa_runtime_state_INIT {0}

#else // !Py_USING_MEMORY_DEBUGGER

/* The size of the Bigint freelist */
#define Bigint_Kmax 7

Expand All @@ -53,8 +44,6 @@ struct _dtoa_runtime_state {
.preallocated_next = runtime.dtoa.preallocated, \
}

#endif // !Py_USING_MEMORY_DEBUGGER


/* These functions are used by modules compiled as C extension like math:
they must be exported. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove the last place where the previously removed macro
``Py_USING_MEMORY_DEBUGGER`` is checked. Patch by Felipe Rodrigues.
3 changes: 0 additions & 3 deletions Misc/valgrind-python.supp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
# valgrind --tool=memcheck --suppressions=Misc/valgrind-python.supp \
# ./python -E ./Lib/test/regrtest.py -u gui,network
#
# You must edit Objects/obmalloc.c and uncomment Py_USING_MEMORY_DEBUGGER
# to use the preferred suppressions with address_in_range.
#
# If you do not want to recompile Python, you can uncomment
# suppressions for _PyObject_Free and _PyObject_Realloc.
#
Expand Down
97 changes: 0 additions & 97 deletions Python/dtoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ BCinfo {
// struct Bigint is defined in pycore_dtoa.h.
typedef struct Bigint Bigint;

#ifndef Py_USING_MEMORY_DEBUGGER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdickinson: Should we add a new macro to enable or disable the freelist, for debug purposes?


/* Memory management: memory is allocated from, and returned to, Kmax+1 pools
of memory, where pool k (0 <= k <= Kmax) is for Bigints b with b->maxwds ==
Expand Down Expand Up @@ -395,48 +394,6 @@ Bfree(Bigint *v)
#undef private_mem
#undef freelist

#else

/* Alternative versions of Balloc and Bfree that use PyMem_Malloc and
PyMem_Free directly in place of the custom memory allocation scheme above.
These are provided for the benefit of memory debugging tools like
Valgrind. */

/* Allocate space for a Bigint with up to 1<<k digits */

static Bigint *
Balloc(int k)
{
int x;
Bigint *rv;
unsigned int len;

x = 1 << k;
len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
/sizeof(double);

rv = (Bigint*)MALLOC(len*sizeof(double));
if (rv == NULL)
return NULL;

rv->k = k;
rv->maxwds = x;
rv->sign = rv->wds = 0;
return rv;
}

/* Free a Bigint allocated with Balloc */

static void
Bfree(Bigint *v)
{
if (v) {
FREE((void*)v);
}
}

#endif /* Py_USING_MEMORY_DEBUGGER */

#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int))

Expand Down Expand Up @@ -671,8 +628,6 @@ mult(Bigint *a, Bigint *b)
return c;
}

#ifndef Py_USING_MEMORY_DEBUGGER

/* multiply the Bigint b by 5**k. Returns a pointer to the result, or NULL on
failure; if the returned pointer is distinct from b then the original
Bigint b will have been Bfree'd. Ignores the sign of b. */
Expand Down Expand Up @@ -728,58 +683,6 @@ pow5mult(Bigint *b, int k)
return b;
}

#else

/* Version of pow5mult that doesn't cache powers of 5. Provided for
the benefit of memory debugging tools like Valgrind. */

static Bigint *
pow5mult(Bigint *b, int k)
{
Bigint *b1, *p5, *p51;
int i;
static const int p05[3] = { 5, 25, 125 };

if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0);
if (b == NULL)
return NULL;
}

if (!(k >>= 2))
return b;
p5 = i2b(625);
if (p5 == NULL) {
Bfree(b);
return NULL;
}

for(;;) {
if (k & 1) {
b1 = mult(b, p5);
Bfree(b);
b = b1;
if (b == NULL) {
Bfree(p5);
return NULL;
}
}
if (!(k >>= 1))
break;
p51 = mult(p5, p5);
Bfree(p5);
p5 = p51;
if (p5 == NULL) {
Bfree(b);
return NULL;
}
}
Bfree(p5);
return b;
}

#endif /* Py_USING_MEMORY_DEBUGGER */

/* shift a Bigint b left by k bits. Return a pointer to the shifted result,
or NULL on failure. If the returned pointer is distinct from b then the
original b will have been Bfree'd. Ignores the sign of b. */
Expand Down