Skip to content

Commit

Permalink
FIX: pass all 12 tuple bytes in the extension argument including info…
Browse files Browse the repository at this point in the history
… about tuple's size

related to: Oldes/Rebol-issues#2462
  • Loading branch information
Oldes committed Dec 26, 2021
1 parent ea3e47a commit 015441e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/boot/types-ext.reb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ percent * 64

char 10 32
pair * 64
tuple * 64
tuple * tuple
time * 64
date * date

Expand Down
9 changes: 9 additions & 0 deletions src/core/f-extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum {
RXE_IMAGE, // image
RXE_DATE, // from upper section
RXE_OBJECT, // any object
RXE_TUPLE, // 3-12 bytes tuple value
RXE_MAX
};

Expand Down Expand Up @@ -113,6 +114,10 @@ x*/ RXIARG Value_To_RXI(REBVAL *val)
arg.width = VAL_IMAGE_WIDE(val);
arg.height = VAL_IMAGE_HIGH(val);
break;
case RXE_TUPLE:
arg.tuple_len = VAL_TUPLE_LEN(val);
COPY_MEM(arg.tuple_bytes, VAL_TUPLE(val), MAX_TUPLE);
break;
case RXE_NULL:
default:
arg.int64 = 0;
Expand Down Expand Up @@ -161,6 +166,10 @@ x*/ void RXI_To_Value(REBVAL *val, RXIARG arg, REBCNT type)
VAL_IMAGE_WIDE(val) = arg.width;
VAL_IMAGE_HIGH(val) = arg.height;
break;
case RXE_TUPLE:
VAL_TUPLE_LEN(val) = arg.tuple_len;
COPY_MEM(VAL_TUPLE(val), arg.tuple_bytes, MAX_TUPLE);
break;
case RXE_NULL:
VAL_INT64(val) = 0;
break;
Expand Down
14 changes: 13 additions & 1 deletion src/include/reb-ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
*/

// Value structure (for passing args to and from):
// o: originaly (before 64bit) it was designed to fit to 8bytes
// o: but tuple was still allowed to have 10 bytes, so one could not receive
// o: all possible tuple values in the extension side!!
// Now, when there can be stored all 12 allowed tuple bytes, the value must have 16bytes
// on both (32 and 64bit) targets, so maximum number of arguments could be extended (from 7 to 15)
#pragma pack(4)
typedef union rxi_arg_val {
void *addr;
Expand Down Expand Up @@ -72,6 +77,12 @@ typedef union rxi_arg_val {
REBFLG flags:16; // Handle_Flags
REBCNT index:16; // Index into Reb_Handle_Spec value
} handle;
struct {
// keeping the same layout how it was before (first byte is size)
// there could probably be a more optimal way how to pass colors!
REBYTE tuple_len;
REBYTE tuple_bytes[MAX_TUPLE];
};
} RXIARG;

// For direct access to arg array:
Expand Down Expand Up @@ -108,7 +119,8 @@ typedef int (*RXICAL)(int cmd, RXIFRM *args, REBCEC *ctx);
#define RXA_DATE(f,n) (RXA_ARG(f,n).int32a)
#define RXA_WORD(f,n) (RXA_ARG(f,n).int32a)
#define RXA_PAIR(f,n) (RXA_ARG(f,n).pair)
#define RXA_TUPLE(f,n) (RXA_ARG(f,n).bytes)
#define RXA_TUPLE(f,n) (RXA_ARG(f,n).tuple_bytes)
#define RXA_TUPLE_SIZE(f,n) (RXA_ARG(f,n).tuple_size)
#define RXA_SERIES(f,n) (RXA_ARG(f,n).series)
#define RXA_INDEX(f,n) (RXA_ARG(f,n).index)
#define RXA_OBJECT(f,n) (RXA_ARG(f,n).addr)
Expand Down

0 comments on commit 015441e

Please sign in to comment.