[Csnd-dev] Shared memory for scalar optional arguments to opcodes
Eduardo Moguillansky <[email protected]>
| Newsgroups | gmane.comp.audio.csound.devel |
|---|---|
| Message-ID | <CAHFFssKw3-Yoe_Xb0RY8Fpvpb98YjQMZRSs3YYWYD=pKcZp3Gw@mail.gmail.com> |
I hope I am understanding something fundamentally wrong about how optional
arguments work . I am seeing surprising (for me) behaviour in csound
(tested 6.18, 6.19 and develop branch) when an opcode declares optional
arguments. All optional arguments which are not passed seem to share the
same memory space, which means that they cannot be initialized and should
be treated as read-only. Is this the intended behaviour? This holds true
for any both i, k types, as long as they are optional: o/O, p/P, j/J, etc.
Here is some minimal code to prove the point. When this opcode is called in
the form
aout testargs ain ;; optional args left unfilled
The result is
Adresses in0: 1771221120, in1: 1770975480, in2: 1770975480
Values in0: 0.000000, in1: 1.000000, in2: 1.000000
Notice how the k arguments (in1 and in2) share the same memory address.
typedef struct {
OPDS h;
MYFLT *out;
MYFLT *in0;
MYFLT *in1;
MYFLT *in2;
} TESTARGS;
static int32_t testargs_init(CSOUND *csound, TESTARGS *p) {
printf("Addresses in0: %d, in1: %d, in2: %d\n", p->in0, p->in1, p->in2);
printf("Values in0: %f, in1: %f, in2: %f\n", *p->in0, *p->in1, *p->in2);
return OK;
}
// for csound 6
static OENTRY localops[] = {
{"testargs", S(TESTARGS), 0, 1, "a", "aPP", (SUBR)testargs_init}
}
// for csound 7
static OENTRY localops[] = {
{"testargs", S(TESTARGS), 0, "a", "aPP", (SUBR)testargs_init}
}