Skip to content

Commit 55159cf

Browse files
committed
Use resource in functions
1 parent 9d6e57e commit 55159cf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libp2p/libp2p.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ ERL_FUNCTION(listen_addr_strings)
108108

109109
uintptr_t handle = ListenAddrStrings(listen_addr);
110110

111-
return get_handle_result(env, handle);
111+
IF_ERROR(handle == 0, "invalid handle returned");
112+
uintptr_t *obj = enif_alloc_resource(Option_type, sizeof(uintptr_t));
113+
IF_ERROR(obj == NULL, "couldn't create resource");
114+
*obj = handle;
115+
ERL_NIF_TERM term = enif_make_resource(env, obj);
116+
return make_ok_tuple2(env, term);
112117
}
113118

114119
/****************/
@@ -125,7 +130,10 @@ ERL_FUNCTION(host_new)
125130
while (!enif_is_empty_list(env, tail) && i < MAX_OPTIONS)
126131
{
127132
enif_get_list_cell(env, tail, &head, &tail);
128-
options[i++] = GET_HANDLE(head, "option");
133+
uintptr_t *obj;
134+
enif_get_resource(env, head, Option_type, (void **)&obj);
135+
IF_ERROR(obj == NULL, "invalid option");
136+
options[i++] = *obj;
129137
}
130138
GoSlice go_options = {options, i, MAX_OPTIONS};
131139
uintptr_t result = HostNew(go_options);

0 commit comments

Comments
 (0)