<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">The left side is still determined by the current state of the patch, though -- it's only going to check objects that are still there, which any garbage on the right won't ever match (right?). If there is a match, it's going to be because the state on both sides of the == was updated when the object was created. We never really have to worry about false positives, so I'm not sure the random long is the same situation.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 1, 2015 at 9:54 PM, Jonathan Wilkes <span dir="ltr"><<a href="mailto:jancsika@yahoo.com" target="_blank">jancsika@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div>But if you trace error_object back, you'll see it gets created from an sscanf</div><div dir="ltr">of a c string.  And that string was stored in the tcl/tk "text" widget as state bound</div><div dir="ltr">to a <ctrl-click> proc (or in post-1980s version of Pd that I work on, a</div><div dir="ltr">"hyperlink").</div><div dir="ltr"><br></div><div dir="ltr">That state can persist well past the life of the object it referred to.  For example,</div><div dir="ltr">the error_object could have been deleted by the user.</div><div dir="ltr"><br></div><div dir="ltr">That's why I was generating a random long in my contrived example.  If we<br></div><div dir="ltr">cast garbage to void* and put it to the right of the equals sign, isn't libc</div><div dir="ltr">technically allowed to respond by serving Pd users a listicle of the top 10 C</div><div dir="ltr">programming references available from Amazon with free shipping?<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div dir="ltr"><br></div><div dir="ltr">-Jonathan<br></div></font></span><div><div class="h5"><div><span></span></div>  <br><div><br><br></div><div style="display:block"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"> <div dir="ltr"> <font face="Arial" size="2"> On Thursday, October 1, 2015 7:32 PM, Matt Barber <<a href="mailto:brbrofsvl@gmail.com" target="_blank">brbrofsvl@gmail.com</a>> wrote:<br> </font> </div>  <br><br> <div><div><div><div dir="ltr"><div style="font-family:verdana,sans-serif">As I understand it, you can compare void pointers because they just store addresses.</div><div style="font-family:verdana,sans-serif"><br clear="none"></div><div style="font-family:verdana,sans-serif">In g_editor.c:</div><div style="font-family:verdana,sans-serif"><br clear="none"></div><div><div><font face="verdana, sans-serif"><br clear="none"></font></div><div><font face="verdana, sans-serif">static int glist_dofinderror(t_glist *gl, void *error_object)</font></div><div><font face="verdana, sans-serif">{</font></div><div><font face="verdana, sans-serif">    t_gobj *g;</font></div><div><font face="verdana, sans-serif">    for (g = gl->gl_list; g; g = g->g_next)</font></div><div><font face="verdana, sans-serif">    {</font></div><div><font face="verdana, sans-serif">        if ((void *)g == error_object)</font></div><div><font face="verdana, sans-serif">        {</font></div><div><font face="verdana, sans-serif">            /* got it... now show it. */</font></div><div><font face="verdana, sans-serif">            glist_noselect(gl);</font></div><div><font face="verdana, sans-serif">            canvas_vis(glist_getcanvas(gl), 1);</font></div><div><font face="verdana, sans-serif">            canvas_editmode(glist_getcanvas(gl), 1.);</font></div><div><font face="verdana, sans-serif">            glist_select(gl, g);</font></div><div><font face="verdana, sans-serif">            return (1);</font></div><div><font face="verdana, sans-serif">        }</font></div><div><font face="verdana, sans-serif">        else if (g->g_pd == canvas_class)</font></div><div><font face="verdana, sans-serif">        {</font></div><div><font face="verdana, sans-serif">            if (glist_dofinderror((t_canvas *)g, error_object))</font></div><div><font face="verdana, sans-serif">                return (1);</font></div><div><font face="verdana, sans-serif">        }</font></div><div><font face="verdana, sans-serif">    }</font></div><div><font face="verdana, sans-serif">    return (0);</font></div><div><font face="verdana, sans-serif">}</font></div><div><font face="verdana, sans-serif"><br clear="none"></font></div><div><font face="verdana, sans-serif"><br clear="none"></font></div><div><font face="verdana, sans-serif">this function takes a pointer to void (storing the address of an object) as its second argument void *error_object. It can't know what the type of that object is, because it's being called from somewhere else, and it could be any kind of Pd object. That somewhere else knows what kind of object it is and (more importantly) where that object's address is, and just passes that address in. Then t_gobj *g; traverses the canvas, and since the address of each object is known, each of those can be compared to the object address passed in until there's a match. This is kind of a way of getting around the usual strong typing in c; as long as we know from both ends of the transaction that we can get valid addresses of what we're interested in, there's no problem just comparing those addresses to see if we've found the same object.</font></div><div><font face="verdana, sans-serif"><br clear="none"></font></div><div><font face="verdana, sans-serif"><br clear="none"></font></div></div></div><div><br clear="none"><div>On Thu, Oct 1, 2015 at 4:45 PM, Jonathan Wilkes via Pd-list <span dir="ltr"><<a rel="nofollow" shape="rect" href="mailto:pd-list@lists.iem.at" target="_blank">pd-list@lists.iem.at</a>></span> wrote:<br clear="none"><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div>Hi list,</div><div><br clear="none"></div><div>int compare_pointers(t_pd *foo)</div><div>{</div><div dir="ltr">     long bar = generate_random_long();</div><div dir="ltr">     return (((void *)foo) == ((void *)bar));</div><div dir="ltr">}</div><div dir="ltr"><br clear="none"></div><div dir="ltr">(I probably have unnecessary parens there...)</div><div dir="ltr"><br clear="none"></div><div dir="ltr">Is the check for equality a case of undefined behavior?</div><div dir="ltr"><br clear="none"></div><div dir="ltr">If so, doesn't glob_findinstance of s_print.c also lead to the same</div><div dir="ltr">undefined behavior?</div><span><font color="#888888"></font></span><div dir="ltr"><br clear="none"></div><div dir="ltr">-Jonathan</div><div dir="ltr"> </div></div></div></div><br clear="none">_______________________________________________<br clear="none">
<a rel="nofollow" shape="rect" href="mailto:Pd-list@lists.iem.at" target="_blank">Pd-list@lists.iem.at</a> mailing list<br clear="none">
UNSUBSCRIBE and account-management -> <a rel="nofollow" shape="rect" href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br clear="none">
<br clear="none"></blockquote></div><br clear="none"></div></div></div><br><br></div>  </div> </div>  </div></div></div></div></div></blockquote></div><br></div>