| 1 |
/* ---------------------------------------------------------------------- */ |
| 2 |
|
| 3 |
#define ns__aproc0 "::aproc" |
| 4 |
|
| 5 |
#ifndef CRITCL_variadic_int |
| 6 |
#define CRITCL_variadic_int |
| 7 |
|
| 8 |
/* NOTE: Array 'v' is allocated on the heap. The argument |
| 9 |
// release code is used to free it after the worker |
| 10 |
// function returned. Depending on type and what is done |
| 11 |
// by the worker it may have to make copies of the data. |
| 12 |
*/ |
| 13 |
|
| 14 |
typedef struct critcl_variadic_int { |
| 15 |
Tcl_Obj** o; /* Original object array */ |
| 16 |
int c; /* Element count */ |
| 17 |
int* v; /* Allocated array of the elements */ |
| 18 |
} critcl_variadic_int; |
| 19 |
|
| 20 |
static int |
| 21 |
_critcl_variadic_int_item (Tcl_Interp* interp, Tcl_Obj* src, int* dst) { |
| 22 |
{ |
| 23 |
if (Tcl_GetIntFromObj(interp, src, dst) != TCL_OK) return TCL_ERROR; } |
| 24 |
return TCL_OK; |
| 25 |
} |
| 26 |
|
| 27 |
#endif /* CRITCL_variadic_int _________ */ |
| 28 |
|
| 29 |
static void c__aproc0(critcl_variadic_int args) |
| 30 |
{ |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
static int |
| 35 |
tcl__aproc0(ClientData cd, Tcl_Interp *interp, Tcl_Size oc, Tcl_Obj *CONST ov[]) |
| 36 |
{ |
| 37 |
critcl_variadic_int _args; |
| 38 |
/* (int args, ...) - - -- --- ----- -------- */ |
| 39 |
{ |
| 40 |
int src, dst, leftovers = (oc-1); |
| 41 |
_args.c = leftovers; |
| 42 |
_args.v = (int*) ((!leftovers) ? 0 : ckalloc (leftovers * sizeof (int))); |
| 43 |
_args.o = (Tcl_Obj**) &ov[1]; |
| 44 |
for (src = 1, dst = 0; leftovers > 0; dst++, src++, leftovers--) { |
| 45 |
if (_critcl_variadic_int_item (interp, ov[src], &(_args.v[dst])) != TCL_OK) { |
| 46 |
ckfree ((char*) _args.v); /* Cleanup partial work */ |
| 47 |
return TCL_ERROR; |
| 48 |
} |
| 49 |
} } |
| 50 |
|
| 51 |
/* Call - - -- --- ----- -------- */ |
| 52 |
c__aproc0(_args); |
| 53 |
|
| 54 |
/* (Release: int args, ...) - - -- --- ----- -------- */ |
| 55 |
if (_args.c) { ckfree ((char*) _args.v); } |
| 56 |
|
| 57 |
/* (void return) - - -- --- ----- -------- */ |
| 58 |
return TCL_OK; |
| 59 |
} |