Skip to content

Commit 1ebf222

Browse files
committed
x.c:widget_values_get(), args_to_pairs(): restructure, rename xt_args_to_pairs.
widget_values_get(): store values in an XtArgVal array initialized to zero. xt_args_to_pairs(): expect a pointer to a value,
1 parent 6a4cf9b commit 1ebf222

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/motif/_xm.sml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ functor Xm (structure List: LIST) : XM =
10111011
| pairToRep (MESSAGE_WINDOW, WIDGET w) =
10121012
("messageWindow", ARGUNBOXED (ref (cast w)))
10131013
| pairToRep (WIDTH, INT i) =
1014-
("width", ARGSHORT (ref i))
1014+
("width", ARGSHORT (ref i ))
10151015
| pairToRep (HEIGHT, INT i) =
10161016
("height", ARGSHORT (ref i))
10171017
| pairToRep (X, INT i) =

src/rts/src/OS/Unix/x.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ static void pairs_to_args(Arg args[], Cardinal *nr_args_return, mlval list)
11351135

11361136

11371137

1138-
static void args_to_pairs(Arg args[], mlval list)
1138+
static void xt_args_to_pairs(Arg args[], mlval list)
11391139
{
11401140
Cardinal nr_args = 0;
11411141
mlval ref= MLUNIT;
@@ -1152,24 +1152,24 @@ static void args_to_pairs(Arg args[], mlval list)
11521152
switch(FIELD(argument, 0)) {
11531153
case mlw_x_arg_bool:
11541154
/* Need to cast the pointer before dereferencing */
1155-
mlw_ref_update(ref, MLBOOL(*(Boolean *)(&(args[nr_args].value))));
1155+
mlw_ref_update(ref, MLBOOL(*(Boolean *)(args[nr_args].value)));
11561156
break;
11571157

11581158
case mlw_x_arg_boxed:
11591159
{
1160-
mlval string = box((unsigned long int)args[nr_args].value);
1160+
mlval string = box(*(unsigned long int*)(args[nr_args].value));
11611161
mlw_ref_update(ref, string);
11621162
}
11631163
break;
11641164

11651165
case mlw_x_arg_int:
11661166
/* Need to cast the pointer before dereferencing */
1167-
mlw_ref_update(ref, MLINT(*(int *)(&(args[nr_args].value))));
1167+
mlw_ref_update(ref, MLINT(*(int *)(args[nr_args].value)));
11681168
break;
11691169

11701170
case mlw_x_arg_short:
11711171
/* Need to cast the pointer before dereferencing */
1172-
mlw_ref_update(ref, MLINT(*(short *)(&(args[nr_args].value))));
1172+
mlw_ref_update(ref, MLINT(*(short *)(args[nr_args].value)));
11731173
break;
11741174

11751175
case mlw_x_arg_string:
@@ -1180,11 +1180,11 @@ static void args_to_pairs(Arg args[], mlval list)
11801180
break;
11811181

11821182
case mlw_x_arg_unboxed:
1183-
mlw_ref_update(ref, (mlval)args[nr_args].value);
1183+
mlw_ref_update(ref, (mlval)*((XtArgVal *)args[nr_args].value));
11841184
break;
11851185

11861186
default:
1187-
error("args_to_pairs: Illegal Argument constructor for resource `%s': 0x%X",
1187+
error("xt_args_to_pairs: Illegal Argument constructor for resource `%s': 0x%X",
11881188
CSTRING(FIELD(head, 0)), FIELD(argument, 0));
11891189
}
11901190

@@ -1885,24 +1885,16 @@ static mlval widget_values_set(mlval argument)
18851885
static mlval widget_values_get(mlval argument)
18861886
{
18871887
Arg args[MAX_NR_ARGS];
1888+
XtArgVal vals[MAX_NR_ARGS] = {0};
18881889
Cardinal nr_args, i;
18891890
mlval list = FIELD(argument, 1);
18901891

18911892
pairs_to_args(args, &nr_args, list);
18921893
for(i=0; i<nr_args; ++i) {
1893-
XtArgVal tmp = (XtArgVal)XtMalloc(sizeof (XtArgVal));
1894-
if (tmp == 0)
1895-
error("widget_values_get: malloc failed", 0, 0);
1896-
else
1897-
args[i].value = tmp;
1894+
args[i].value = (XtArgVal)&vals[i];
18981895
}
18991896
XtGetValues((Widget)FIELD(argument, 0), args, nr_args);
1900-
for(i=0; i<nr_args; ++i) {
1901-
XtArgVal *tmp = (XtArgVal*)args[i].value;
1902-
args[i].value = *tmp;
1903-
XtFree ((char*)tmp);
1904-
}
1905-
args_to_pairs(args, list);
1897+
xt_args_to_pairs(args, list);
19061898

19071899
return(MLUNIT);
19081900
}

0 commit comments

Comments
 (0)