8000 py/gc: Adjust gc_alloc() signature to be able to accept multiple flags. · msuszko/micropython@5ed578e · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ed578e

Browse files
pfalcondpgeorge
authored andcommitted
py/gc: Adjust gc_alloc() signature to be able to accept multiple flags.
The older "bool has_finaliser" gets recast as GC_ALLOC_FLAG_HAS_FINALISER=1 so this is a backwards compatible change to the signature. Since bool gets implicitly converted to 1 this patch doesn't include conversion of all calls.
1 parent a261d8b commit 5ed578e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

py/gc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ void gc_info(gc_info_t *info) {
433433
GC_EXIT();
434434
}
435435

436-
void *gc_alloc(size_t n_bytes, bool has_finaliser) {
436+
void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
437+
bool has_finaliser = alloc_flags & GC_ALLOC_FLAG_HAS_FINALISER;
437438
size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
438439
DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks);
439440

py/gc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ void gc_collect_end(void);
4848
// Use this function to sweep the whole heap and run all finalisers
4949
void gc_sweep_all(void);
5050

51-
void *gc_alloc(size_t n_bytes, bool has_finaliser);
51+
enum {
52+
GC_ALLOC_FLAG_HAS_FINALISER = 1,
53+
};
54+
55+
void *gc_alloc(size_t n_bytes, unsigned int alloc_flags);
5256
void gc_free(void *ptr); // does not call finaliser
5357
size_t gc_nbytes(const void *ptr);
5458
void *gc_realloc(void *ptr, size_t n_bytes, bool allow_move);

0 commit comments

Comments
 (0)
0