Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3297,12 +3297,12 @@ static bool _collect_alloc_stats(
static void
py_mimalloc_print_stats(FILE *out)
{
fprintf(out, "Small block threshold = %zd, in %u size classes.\n",
MI_SMALL_OBJ_SIZE_MAX, MI_BIN_HUGE);
fprintf(out, "Medium block threshold = %zd\n",
MI_MEDIUM_OBJ_SIZE_MAX);
fprintf(out, "Large object max size = %zd\n",
MI_LARGE_OBJ_SIZE_MAX);
fprintf(out, "Small block threshold = %zu, in %u size classes.\n",
(size_t)MI_SMALL_OBJ_SIZE_MAX, MI_BIN_HUGE);
fprintf(out, "Medium block threshold = %zu\n",
(size_t)MI_MEDIUM_OBJ_SIZE_MAX);
fprintf(out, "Large object max size = %zu\n",
(size_t)MI_LARGE_OBJ_SIZE_MAX);

mi_heap_t *heap = mi_heap_get_default();
struct _alloc_stats stats;
Expand Down
14 changes: 7 additions & 7 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ typedef struct {
} gc_span_stack_t;

typedef struct {
unsigned int in;
unsigned int out;
Py_ssize_t in;
Py_ssize_t out;
Copy link
Member

Choose a reason for hiding this comment

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

Warnings could also be fixed by changing this line:

Py_ssize_t space = BUFFER_HI - gc_mark_buffer_len(args);

to

unsigned int space = BUFFER_HI - gc_mark_buffer_len(args);

The assert should be changed in that case, since size can't be negative.

assert(space <= gc_mark_buffer_avail(args));
assert(space <= BUFFER_HI);

Performance wise I would doubt that using Py_ssize_t makes any difference. On 32-bit platforms maybe a little since it would use a 64-bit int rather than a 32-bit one?

I would still prefer to use the unsigned integer types since my understanding is that the C standard defines overflow behavior for unsigned integers but not signed ones. The buffer "in" and "out" calculations depend on the overflow behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense -- I switched back to unsigned int.

On 32-bit platforms maybe a little since it would use a 64-bit int rather than a 32-bit one?

Py_ssize_t is the same size as size_t, so typically 32-bits on a 32-bit platform.

_PyObjectStack stack;
gc_span_stack_t spans;
PyObject *buffer[BUFFER_SIZE];
Expand All @@ -574,14 +574,14 @@ typedef struct {


// Returns number of entries in buffer
static inline unsigned int
static inline Py_ssize_t
gc_mark_buffer_len(gc_mark_args_t *args)
{
return args->in - args->out;
}

// Returns number of free entry slots in buffer
static inline unsigned int
static inline Py_ssize_t
gc_mark_buffer_avail(gc_mark_args_t *args)
{
return BUFFER_SIZE - gc_mark_buffer_len(args);
Expand Down Expand Up @@ -1074,14 +1074,14 @@ mark_heap_visitor(const mi_heap_t *heap, const mi_heap_area_t *area,
return true;
}

_PyObject_ASSERT_WITH_MSG(op, gc_get_refs(op) >= 0,
"refcount is too small");

if (gc_is_alive(op) || !gc_is_unreachable(op)) {
// Object was already marked as reachable.
return true;
}

_PyObject_ASSERT_WITH_MSG(op, gc_get_refs(op) >= 0,
"refcount is too small");

// GH-129236: If we've seen an active frame without a valid stack pointer,
// then we can't collect objects with deferred references because we may
// have missed some reference to the object on the stack. In that case,
Expand Down
Loading