Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial callback handling.
It works, but it'll leak memory since all the information needed to handle a
callback is recreated (and allocated on the heap) on each call without ever
being freed.
  • Loading branch information
arnsholt committed Jul 20, 2012
1 parent cbc33cd commit 3a126fd
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 73 deletions.
14 changes: 14 additions & 0 deletions src/6model/reprs/NativeCall.c
Expand Up @@ -77,6 +77,8 @@ static void gc_cleanup(PARROT_INTERP, STable *st, void *data) {
dlFreeLibrary(body->lib_handle);
if (body->arg_types)
mem_sys_free(body->arg_types);
if (body->arg_info)
mem_sys_free(body->arg_info);
}

/* This Parrot-specific addition to the API is used to free an object. */
Expand All @@ -86,6 +88,18 @@ static void gc_free(PARROT_INTERP, PMC *obj) {
PMC_data(obj) = NULL;
}

static void gc_mark(PARROT_INTERP, STable *st, void *data) {
NativeCallBody *body = (NativeCallBody *)data;

if (body->arg_info) {
INTVAL i;
for (i = 0; i < body->num_args; i++) {
if (body->arg_info[i])
Parrot_gc_mark_PMC_alive(interp, body->arg_info[i]);
}
}
}

/* Gets the storage specification for this representation. */
static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
storage_spec spec;
Expand Down
6 changes: 4 additions & 2 deletions src/6model/reprs/NativeCall.h
@@ -1,8 +1,9 @@
#ifndef NATIVECALL_H_GUARD
#define NATIVECALL_H_GUARD

#include "dyncall/dyncall.h"
#include "dynload/dynload.h"
#include "dyncall.h"
#include "dynload.h"
#include "dyncall_callback.h"

/* Body of a NativeCall. */
typedef struct {
Expand All @@ -13,6 +14,7 @@ typedef struct {
INTVAL num_args;
INTVAL *arg_types;
INTVAL ret_type;
PMC **arg_info;
} NativeCallBody;

/* This is how an instance with the NativeCall representation looks. */
Expand Down

0 comments on commit 3a126fd

Please sign in to comment.