diff --git a/include/ink.h b/include/ink.h index 5105173..b0ebe1c 100644 --- a/include/ink.h +++ b/include/ink.h @@ -306,6 +306,9 @@ void ink_pop_fn(struct context *ctx); */ void ink_pop(struct context *ctx); +typedef void (*collect_fn)(struct context*,void*); +typedef struct ink_collection_list (*gc_fn)(struct context*,void*); + /** * Declares a new type that can be stored within the interpreter * @param ctx The context in which to add the file @@ -317,11 +320,11 @@ void ink_pop(struct context *ctx); * @internal user defined type ids minimal value is 15, we keep the first 16 types as reserved, just like negative type ids */ int ink_new_type( - struct context* ctx, - const char* type_name, - int size, - void (*collect)(struct context*,void*), - struct ink_collection_list (*gc)(struct context*,void*) + struct context* ctx, + const char* type_name, + int size, + collect_fn collect, + gc_fn gc ); /** diff --git a/lib.c b/lib.c index ee5e0d0..99eb54c 100644 --- a/lib.c +++ b/lib.c @@ -1226,8 +1226,8 @@ int ink_new_type( struct context* ctx, const char* type_name, int size, - void (*collect)(struct context*,void*), - struct ink_collection_list (*gc)(struct context*,void*) + collect_fn collect, + gc_fn gc ) { if(ctx->panic) return -128; /* Resize for push */ @@ -1332,9 +1332,6 @@ struct elem ink_make_native_unsafe(struct context* ctx, int type, void* ptr, int g = ctx->types[type_id].elements_capacity; for(i = 0; i < g; ++i) { if(! ctx->types[type_id].elements[i].in_use) { - ctx->types[type_id].elements[i].in_use = 1; - ctx->types[type_id].elements[i].uses = 1; - ctx->types[type_id].elements[i].is_protected = is_protected; if(ctx->types[type_id].element_size < 0) { ctx->types[type_id].elements[i].data = ptr; } else { @@ -1346,6 +1343,9 @@ struct elem ink_make_native_unsafe(struct context* ctx, int type, void* ptr, int } memcpy(new_ptr, ptr, ctx->types[type_id].element_size); ctx->types[type_id].elements[i].data = new_ptr; + ctx->types[type_id].elements[i].is_protected = is_protected; + ctx->types[type_id].elements[i].uses = 1; + ctx->types[type_id].elements[i].in_use = 1; } ctx->types[type_id].elements_top = max(ctx->types[type_id].elements_top, i+1); ret.type = type;