Browse Source

Minor refactoring of function pointers and field order

main
Ludovic 'Archivist' Lagouardette 3 months ago
parent
commit
98fa605018
2 changed files with 13 additions and 10 deletions
  1. +8
    -5
      include/ink.h
  2. +5
    -5
      lib.c

+ 8
- 5
include/ink.h View File

@ -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
);
/**

+ 5
- 5
lib.c View File

@ -1226,8 +1226,8 @@ int ink_new_type(
struct context* ctx,
const char* type_name,
int size,
kt">void (*collect)(struct context*,void*),
k">struct ink_collection_list (*gc)(struct context*,void*)
n">collect_fn collect,
n">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;

Loading…
Cancel
Save