# HG changeset patch # User Paul Boddie # Date 1490118342 -3600 # Node ID 195b15f90472d5128ac8bc34a3a35dc9a1d87303 # Parent 332483cd7ba31863288fcbe8d890b7ce0466dad5 Allocate integers using a different allocator employing GC_MALLOC_ATOMIC. diff -r 332483cd7ba3 -r 195b15f90472 templates/native/common.c --- a/templates/native/common.c Tue Mar 21 01:15:38 2017 +0100 +++ b/templates/native/common.c Tue Mar 21 18:45:42 2017 +0100 @@ -29,7 +29,7 @@ __attr __new_int(int i) { /* Create a new integer and mutate the __data__ attribute. */ - __attr attr = __NEWINSTANCE(__builtins___int_int); + __attr attr = __NEWINSTANCEIM(__builtins___int_int); attr.value->attrs[__ATTRPOS(__data__)].intvalue = i; return attr; } diff -r 332483cd7ba3 -r 195b15f90472 templates/ops.c --- a/templates/ops.c Tue Mar 21 01:15:38 2017 +0100 +++ b/templates/ops.c Tue Mar 21 18:45:42 2017 +0100 @@ -396,6 +396,14 @@ return ptr; } +void *__ALLOCATEIM(size_t nmemb, size_t size) +{ + void *ptr = GC_MALLOC_ATOMIC(nmemb * size); /* sets memory to zero */ + if (ptr == NULL) + __raise_memory_error(); + return ptr; +} + void *__REALLOCATE(void *ptr, size_t size) { void *nptr = GC_REALLOC(ptr, size); diff -r 332483cd7ba3 -r 195b15f90472 templates/ops.h --- a/templates/ops.h Tue Mar 21 01:15:38 2017 +0100 +++ b/templates/ops.h Tue Mar 21 18:45:42 2017 +0100 @@ -133,6 +133,7 @@ /* Memory allocation. */ void *__ALLOCATE(size_t nmemb, size_t size); +void *__ALLOCATEIM(size_t nmemb, size_t size); void *__REALLOCATE(void *ptr, size_t size); /* Copying of structures. */ diff -r 332483cd7ba3 -r 195b15f90472 templates/progops.c --- a/templates/progops.c Tue Mar 21 01:15:38 2017 +0100 +++ b/templates/progops.c Tue Mar 21 18:45:42 2017 +0100 @@ -27,9 +27,9 @@ /* Generic instantiation operations, defining common members. */ -__attr __new(const __table * table, __ref cls, size_t size) +__attr __new(const __table * table, __ref cls, size_t size, int immutable) { - __ref obj = (__ref) __ALLOCATE(1, size); + __ref obj = (__ref) (immutable ? __ALLOCATEIM : __ALLOCATE)(1, size); obj->table = table; obj->pos = __INSTANCEPOS; __store_via_object(obj, __class__, (__attr) {.value=cls}); diff -r 332483cd7ba3 -r 195b15f90472 templates/progops.h --- a/templates/progops.h Tue Mar 21 01:15:38 2017 +0100 +++ b/templates/progops.h Tue Mar 21 18:45:42 2017 +0100 @@ -24,7 +24,7 @@ /* Generic instantiation operations, defining common members. */ -__attr __new(const __table *table, __ref cls, size_t size); +__attr __new(const __table *table, __ref cls, size_t size, int immutable); __attr __new_wrapper(__ref context, __attr attr); /* Generic internal data allocation. */ @@ -77,7 +77,8 @@ /* Convenience definitions. */ -#define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS)) +#define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS), 0) +#define __NEWINSTANCEIM(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS), 1) #define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE})) #endif /* __PROGOPS_H__ */