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.
This commit is contained in:
Paul Sokolovsky 2018-10-26 22:27:44 +03:00 committed by Damien George
parent a261d8b615
commit 5ed578e5b4
2 changed files with 7 additions and 2 deletions

View File

@ -433,7 +433,8 @@ void gc_info(gc_info_t *info) {
GC_EXIT(); GC_EXIT();
} }
void *gc_alloc(size_t n_bytes, bool has_finaliser) { void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
bool has_finaliser = alloc_flags & GC_ALLOC_FLAG_HAS_FINALISER;
size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK; size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks); DEBUG_printf("gc_alloc(" UINT_FMT " bytes -> " UINT_FMT " blocks)\n", n_bytes, n_blocks);

View File

@ -48,7 +48,11 @@ void gc_collect_end(void);
// Use this function to sweep the whole heap and run all finalisers // Use this function to sweep the whole heap and run all finalisers
void gc_sweep_all(void); void gc_sweep_all(void);
void *gc_alloc(size_t n_bytes, bool has_finaliser); enum {
GC_ALLOC_FLAG_HAS_FINALISER = 1,
};
void *gc_alloc(size_t n_bytes, unsigned int alloc_flags);
void gc_free(void *ptr); // does not call finaliser void gc_free(void *ptr); // does not call finaliser
size_t gc_nbytes(const void *ptr); size_t gc_nbytes(const void *ptr);
void *gc_realloc(void *ptr, size_t n_bytes, bool allow_move); void *gc_realloc(void *ptr, size_t n_bytes, bool allow_move);