Skip to content

Commit 30b179f

Browse files
committed
FEAT: added simple test extension + handling RXR_BAD_ARGS value from extension command call
resolves: Oldes/Rebol-issues#1867
1 parent 5d512fc commit 30b179f

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

make/rebol3.nest

+16
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,20 @@ eggs: [
886886
shared: %lib-rebol3-core-x64-osx
887887
]
888888
]
889+
"Test extension 32bit" [
890+
name: %test-x86.rebx
891+
files: only %tests/extension/test.c
892+
:arch-x86
893+
compiler: gcc
894+
flags: [-O2 shared]
895+
#if Linux? [ flag: -fPIC ]
896+
]
897+
"Test extension 64bit" [
898+
name: %test-x64.rebx
899+
files: only %tests/extension/test.c
900+
:arch-x64
901+
compiler: gcc
902+
flags: [-O2 shared]
903+
#if Linux? [ flag: -fPIC ]
904+
]
889905
]

src/core/f-extension.c

+3
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ x*/ int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result)
449449
REBCNT n;
450450
RXIFRM frm; // args stored here
451451

452+
CLEARS(&frm);
453+
452454
// All of these were checked above on definition:
453455
val = BLK_HEAD(VAL_FUNC_BODY(value));
454456
cmd = (int)VAL_INT64(val+1);
@@ -485,6 +487,7 @@ x*/ int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result)
485487
case RXR_FALSE:
486488
SET_FALSE(val);
487489
break;
490+
case RXR_BAD_ARGS:
488491
case RXR_ERROR:
489492
{
490493
const char* errmsg = frm.args[1].series;

src/tests/extension/test.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "reb-host.h"
2+
#include "host-lib.h"
3+
//#include <stdio.h>
4+
5+
RL_LIB *RL; // Link back to reb-lib from embedded extensions
6+
7+
const char *init_block =
8+
"REBOL [\n"
9+
"Title: {Add two integers}\n"
10+
"Type: module\n"
11+
"Exports: [addi ]\n" // exporting just the first command!
12+
"]\n"
13+
"addi: command [i1 [integer!] i2 [integer!]]\n"
14+
"addi2: command [i1 [integer!] i2 [integer!]]\n" // this one is not exported
15+
"bad-args: command [{generic error}]\n"
16+
"error: command [{throws an error with text}]\n"
17+
;
18+
19+
RXIEXT const char *RX_Init(int opts, RL_LIB *lib) {
20+
RL = lib;
21+
//printf("RXinit %llu %llu\n", sizeof(REBREQ) , sizeof(REBEVT));
22+
if (!CHECK_STRUCT_ALIGN) return 0;
23+
return init_block;
24+
}
25+
26+
RXIEXT int RX_Quit(int opts) {
27+
return 0;
28+
}
29+
30+
RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
31+
//printf("RX_Call cmd: %i\n", cmd);
32+
switch(cmd) {
33+
case 0:
34+
RXA_INT64(frm,1) = RXA_INT64(frm, 1) + RXA_INT64(frm, 2);
35+
break;
36+
case 1:
37+
RXA_INT64(frm,1) = 2 * (RXA_INT64(frm, 1) + RXA_INT64(frm, 2));
38+
break;
39+
case 2:
40+
return RXR_BAD_ARGS; //https://github.com/Oldes/Rebol-issues/issues/1867
41+
case 3:
42+
RXA_SERIES(frm,1) = "test error!";
43+
return RXR_ERROR;
44+
45+
}
46+
return RXR_VALUE;
47+
}

0 commit comments

Comments
 (0)