<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">​So, if you deleted [float] and created [clip], isn't it going to bash whatever c string was associated with [float] and associate it with [clip]? Moreover, that kind of error has to occur in an object that exists in the current state (I think?), so the old [float] (once it's gone) could never be part of an error in the first place.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">For 2) I think it depends on what you're going to do with the void pointer(s). Your compare_pointers() function could actually be read as the meat of a "guess my address!" roulette game. If you decided to write to *bar in case it matched, it might be a "guess my address!" Russian roulette game. I'm not sure what the compiler would say about that since I think you'd have to cast *bar back to something you could write.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 1, 2015 at 11:57 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="color:rgb(0,0,0);font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;font-size:16px;background-color:rgb(255,255,255)"><div>Well, two questions I guess:</div><div dir="ltr">1) false positives-- if I deleted [float] and create [clip], can't malloc use the addy</div><div dir="ltr">that belonged to [float]?  In that case [clip] could get associated with an error</div><div dir="ltr">it had nothing to do with.</div><div dir="ltr">2) Is it undefined behavior to check void* garbage for equality?<br></div><div dir="ltr">And just for the heck of it...</div><div dir="ltr">3) is there a way to create something like [readpd~] which would take indices</div><div dir="ltr">as input and output the corresponding bytes of the running Pd instance? :)</div><span class=""><font color="#888888"><div dir="ltr"><br></div><div dir="ltr">-Jonathan<br></div></font></span><div><div class="h5"><div dir="ltr"><br></div><div dir="ltr"><br><span></span></div><div dir="ltr"><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 11:22 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">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><div><br clear="none"><div>On Thu, Oct 1, 2015 at 9:54 PM, Jonathan Wilkes <span dir="ltr"><<a rel="nofollow" shape="rect" href="mailto:jancsika@yahoo.com" target="_blank">jancsika@yahoo.com</a>></span> wrote:<br clear="none"><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div style="color:rgb(0,0,0);font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;font-size:16px;background-color:rgb(255,255,255)"><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 clear="none"></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 clear="none"></div><div dir="ltr">That's why I was generating a random long in my contrived example.  If we<br clear="none"></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><font color="#888888"><br clear="none"></font></span></div><span><font color="#888888"></font></span><div dir="ltr"><br clear="none"></div><div dir="ltr">-Jonathan<br clear="none"></div><div><div><div><span></span></div>  <br clear="none"><div><br clear="none"><br clear="none"></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 rel="nofollow" shape="rect" href="mailto:brbrofsvl@gmail.com" target="_blank">brbrofsvl@gmail.com</a>> wrote:<br clear="none"> </font> </div>  <br clear="none"><br clear="none"> <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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div style="color:rgb(0,0,0);font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif;font-size:16px;background-color:rgb(255,255,255)"><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 clear="none"><br clear="none"></div>  </div> </div>  </div></div></div></div></div></blockquote></div><br clear="none"></div></div></div></div><br><br></div>  </div> </div>  </div></div></div></div></div></blockquote></div><br></div></div>