Skip to content

Commit

Permalink
Fix extsample to cleanup all memory used for cnex CI heap debug testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlarryf committed Apr 11, 2024
1 parent 2e6b024 commit 9f90e14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/extsample/extsample.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>


#include "neonext.h"

const char *neon = "Neon!";
const struct Ne_MethodTable *Ne;
struct Ne_Cell *g_cb;

Expand Down Expand Up @@ -161,14 +165,22 @@ Ne_EXPORT int Ne_raiseException(struct Ne_Cell *retval, struct Ne_ParameterList

Ne_EXPORT int Ne_allocHandle(struct Ne_Cell *retval, struct Ne_ParameterList *in_params, struct Ne_ParameterList *out_params)
{
void *p = malloc(1);
void *p = malloc(sizeof(neon));
memcpy(p, neon, sizeof(neon));
Ne->cell_set_pointer(retval, p);
return Ne_SUCCESS;
}

Ne_EXPORT int Ne_freeHandle(struct Ne_Cell *retval, struct Ne_ParameterList *in_params, struct Ne_ParameterList *out_params)
{
void *p = Ne->cell_get_pointer(Ne->parameterlist_get_cell(in_params, 0));
char *p = Ne->cell_get_pointer(Ne->parameterlist_get_cell(in_params, 0));
assert(memcmp(p, neon, sizeof(neon)) == 0);
free(p);
return Ne_SUCCESS;
}

Ne_EXPORT int Ne_shutdownExtension(struct Ne_Cell *retval, struct Ne_ParameterList *in_params, struct Ne_ParameterList *out_params)
{
Ne->cell_free(g_cb);
return Ne_SUCCESS;
}
2 changes: 2 additions & 0 deletions lib/extsample/extsample.neon
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ EXPORT DECLARE EXTENSION FUNCTION raiseException()

EXPORT DECLARE EXTENSION FUNCTION allocHandle(): Handle
EXPORT DECLARE EXTENSION FUNCTION freeHandle(h: Handle)

EXPORT DECLARE EXTENSION FUNCTION shutdownExtension()
2 changes: 2 additions & 0 deletions lib/extsample/t/extsample-test.neon
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ END TRY
LET h: extsample.Handle := extsample.allocHandle()
TESTCASE h <> NIL
extsample.freeHandle(h)

extsample.shutdownExtension()

0 comments on commit 9f90e14

Please sign in to comment.