I am trying to send some data out of an outlet using a symbol pointer. I have tried using sprintf like martin suggested with little succes. I am sure I am the one doing something wrong. I am getting a pointer symbol but I am not able to convert the pointer back. In external#1 I have:
The out ---------------- IplImage *frame; char symstr[10]; t_symbol *sym; sprintf(symstr, "%p", frame); sym = gensym(symstr); outlet_symbol(x->m_outFrames, sym);
With this I get an address like: symbol 0x1159da0
...but on the conversion in external#2 I get the problem. The conversion looks like:
The in----------------------- IplImage *in_frame; x->in_frame = (IplImage *)atol(s->s_name); post("frame %s", x->in_frame); post("symbol %s",s->s_name);
...with this I get this: frame (null) symbol 0x1159da0
So I'm getting the symbol in, but its not converting into "in_fame." Does anyone know what I am doing wrong or a way to use Pd's A_POINTER. I have looked at Gem and pdp but I cant figure it out. Thanks, Alain
moin Alain,
I've never passed pointers around between externals myself, but...
On 2007-06-22 04:57:35, nosehair911@bellsouth.net appears to have written:
I am trying to send some data out of an outlet using a symbol pointer. I have tried using sprintf like martin suggested with little succes. I am sure I am the one doing something wrong. I am getting a pointer symbol but I am not able to convert the pointer back. In external#1 I have:
The out ---------------- IplImage *frame; char symstr[10]; t_symbol *sym; sprintf(symstr, "%p", frame); sym = gensym(symstr); outlet_symbol(x->m_outFrames, sym);
With this I get an address like: symbol 0x1159da0
... looks kosher to me ...
...but on the conversion in external#2 I get the problem. The conversion looks like:
The in----------------------- IplImage *in_frame; x->in_frame = (IplImage *)atol(s->s_name); post("frame %s", x->in_frame); post("symbol %s",s->s_name);
...with this I get this: frame (null) symbol 0x1159da0
first of all, you probably want to post("frame %p", x->in_frame), rather than "%s". Second, in the docs for my atol (here under linux|glibc), I see:
-- Function: long int atol (const char *STRING) This function is similar to the `strtol' function with a BASE argument of `10', except that it need not detect overflow errors. The `atol' function is provided mostly for compatibility with existing code; using `strtol' is more robust.
... so if your atol() is similar, then trying to convert a hex string to a pointer with atol() is an exercise in futility (since in general, 10!=16). strtol() ought to work better, auto-detetcting the hex-iness of the string by its '0x' prefix. You might also just want to roll out the big guns and use the "%x" format to scanf(), but strtol() is likely to be the better way to go.
marmosets, Bryan
nosehair911@bellsouth.net wrote:
I am trying to send some data out of an outlet using a symbol pointer. I have tried using sprintf like martin suggested with little succes. I am sure I am the one doing something wrong. I am getting a pointer symbol but I am not able to convert the pointer back. In external#1 I have:
The out ---------------- IplImage *frame; char symstr[10]; t_symbol *sym; sprintf(symstr, "%p", frame); sym = gensym(symstr); outlet_symbol(x->m_outFrames, sym);
With this I get an address like: symbol 0x1159da0
...but on the conversion in external#2 I get the problem. The conversion looks like:
The in----------------------- IplImage *in_frame; x->in_frame = (IplImage *)atol(s->s_name); post("frame %s", x->in_frame); post("symbol %s",s->s_name);
...with this I get this: frame (null) symbol 0x1159da0
So I'm getting the symbol in, but its not converting into "in_fame." Does anyone know what I am doing wrong or a way to use Pd's A_POINTER. I have looked at Gem and pdp but I cant figure it out.
Oh yes, atol only converts base 10 but the pointer is in base 16 format. Maybe try: x->in_frame = (IplImage *)sscanf(s->s_name, "%p"); or: x->in_frame = (IplImage *)sscanf(s->s_name, "%x");
OTOH if you did sprintf(symstr, "%lu", frame);
first, then atol would probably work OK.
Martin