1.1 --- a/templates/native/common.c Tue Mar 21 01:15:38 2017 +0100
1.2 +++ b/templates/native/common.c Tue Mar 21 18:45:42 2017 +0100
1.3 @@ -29,7 +29,7 @@
1.4 __attr __new_int(int i)
1.5 {
1.6 /* Create a new integer and mutate the __data__ attribute. */
1.7 - __attr attr = __NEWINSTANCE(__builtins___int_int);
1.8 + __attr attr = __NEWINSTANCEIM(__builtins___int_int);
1.9 attr.value->attrs[__ATTRPOS(__data__)].intvalue = i;
1.10 return attr;
1.11 }
2.1 --- a/templates/ops.c Tue Mar 21 01:15:38 2017 +0100
2.2 +++ b/templates/ops.c Tue Mar 21 18:45:42 2017 +0100
2.3 @@ -396,6 +396,14 @@
2.4 return ptr;
2.5 }
2.6
2.7 +void *__ALLOCATEIM(size_t nmemb, size_t size)
2.8 +{
2.9 + void *ptr = GC_MALLOC_ATOMIC(nmemb * size); /* sets memory to zero */
2.10 + if (ptr == NULL)
2.11 + __raise_memory_error();
2.12 + return ptr;
2.13 +}
2.14 +
2.15 void *__REALLOCATE(void *ptr, size_t size)
2.16 {
2.17 void *nptr = GC_REALLOC(ptr, size);
3.1 --- a/templates/ops.h Tue Mar 21 01:15:38 2017 +0100
3.2 +++ b/templates/ops.h Tue Mar 21 18:45:42 2017 +0100
3.3 @@ -133,6 +133,7 @@
3.4 /* Memory allocation. */
3.5
3.6 void *__ALLOCATE(size_t nmemb, size_t size);
3.7 +void *__ALLOCATEIM(size_t nmemb, size_t size);
3.8 void *__REALLOCATE(void *ptr, size_t size);
3.9
3.10 /* Copying of structures. */
4.1 --- a/templates/progops.c Tue Mar 21 01:15:38 2017 +0100
4.2 +++ b/templates/progops.c Tue Mar 21 18:45:42 2017 +0100
4.3 @@ -27,9 +27,9 @@
4.4
4.5 /* Generic instantiation operations, defining common members. */
4.6
4.7 -__attr __new(const __table * table, __ref cls, size_t size)
4.8 +__attr __new(const __table * table, __ref cls, size_t size, int immutable)
4.9 {
4.10 - __ref obj = (__ref) __ALLOCATE(1, size);
4.11 + __ref obj = (__ref) (immutable ? __ALLOCATEIM : __ALLOCATE)(1, size);
4.12 obj->table = table;
4.13 obj->pos = __INSTANCEPOS;
4.14 __store_via_object(obj, __class__, (__attr) {.value=cls});
5.1 --- a/templates/progops.h Tue Mar 21 01:15:38 2017 +0100
5.2 +++ b/templates/progops.h Tue Mar 21 18:45:42 2017 +0100
5.3 @@ -24,7 +24,7 @@
5.4
5.5 /* Generic instantiation operations, defining common members. */
5.6
5.7 -__attr __new(const __table *table, __ref cls, size_t size);
5.8 +__attr __new(const __table *table, __ref cls, size_t size, int immutable);
5.9 __attr __new_wrapper(__ref context, __attr attr);
5.10
5.11 /* Generic internal data allocation. */
5.12 @@ -77,7 +77,8 @@
5.13
5.14 /* Convenience definitions. */
5.15
5.16 -#define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS))
5.17 +#define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS), 0)
5.18 +#define __NEWINSTANCEIM(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS), 1)
5.19 #define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE}))
5.20
5.21 #endif /* __PROGOPS_H__ */