Skip to content

Commit

Permalink
gh-90815: Fix _PyMem_MimallocEnabled() compiler warning
Browse files Browse the repository at this point in the history
Don't declare _PyMem_MimallocEnabled() if WITH_PYMALLOC macro is not
defined (./configure --without-pymalloc).

Fix also a typo in _PyInterpreterState_FinalizeAllocatedBlocks().
  • Loading branch information
vstinner committed Oct 30, 2023
1 parent cd6e0a0 commit e7fb985
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,13 @@ _PyMem_GetCurrentAllocatorName(void)
}


#if defined(WITH_PYMALLOC) || defined(WITH_MIMALLOC)
#ifdef WITH_PYMALLOC
static int
_PyMem_DebugEnabled(void)
{
return (_PyObject.malloc == _PyMem_DebugMalloc);
}

#ifdef WITH_PYMALLOC
static int
_PyMem_PymallocEnabled(void)
{
Expand All @@ -579,7 +578,7 @@ _PyMem_PymallocEnabled(void)
return (_PyObject.malloc == _PyObject_Malloc);
}
}
#endif

#ifdef WITH_MIMALLOC
static int
_PyMem_MimallocEnabled(void)
Expand All @@ -591,8 +590,8 @@ _PyMem_MimallocEnabled(void)
return (_PyObject.malloc == _PyObject_MiMalloc);
}
}
#endif
#endif // defined(WITH_PYMALLOC) || defined(WITH_MIMALLOC)
#endif // WITH_MIMALLOC
#endif // WITH_PYMALLOC


static void
Expand Down Expand Up @@ -1028,7 +1027,6 @@ static bool count_blocks(
Py_ssize_t
_PyInterpreterState_GetAllocatedBlocks(PyInterpreterState *interp)
{
#ifdef WITH_MIMALLOC
// TODO(sgross): this only counts the current thread's blocks.
if (_PyMem_MimallocEnabled()) {

Check warning on line 1031 in Objects/obmalloc.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_PyMem_MimallocEnabled' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 1031 in Objects/obmalloc.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_PyMem_MimallocEnabled' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 1031 in Objects/obmalloc.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'_PyMem_MimallocEnabled' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 1031 in Objects/obmalloc.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'_PyMem_MimallocEnabled' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
size_t allocated_blocks = 0;
Expand All @@ -1038,7 +1036,6 @@ _PyInterpreterState_GetAllocatedBlocks(PyInterpreterState *interp)

return allocated_blocks;
}
#endif

#ifdef Py_DEBUG
assert(has_own_state(interp));
Expand Down Expand Up @@ -1073,7 +1070,7 @@ _PyInterpreterState_GetAllocatedBlocks(PyInterpreterState *interp)
void
_PyInterpreterState_FinalizeAllocatedBlocks(PyInterpreterState *interp)
{
#ifdef WITH_MIAMLLOC
#ifdef WITH_MIMALLOC
if (_PyMem_MimallocEnabled()) {
return;
}
Expand Down

0 comments on commit e7fb985

Please sign in to comment.