Bug in sigslot when disconnecting a slot

Darren Hobbs <[email protected]> Fri, 27 Aug 2004 19:20:50 -0500
Newsgroups gmane.comp.windows.devel.netwindows
Message-ID <OF56947696.0587B034-ON85256EFE.0000B6F5-85256EFE.0001D586@thoughtworks.com>
This is a multipart message in MIME format.
--===============0730476066==
Content-Type: multipart/alternative;
	boundary="=_alternative 0001D58085256EFE_="

This is a multipart message in MIME format.
--=_alternative 0001D58085256EFE_=
Content-Type: text/plain; charset="US-ASCII"

The sigslot framework appears to have a bug in the rmSlot method where it 
doesn't remove the correct slot.  I've included a version that addresses 
the issue.  The reassignment of the slots array removes any 'holes'.  Not 
knowing enough about javascript's memory management, this step may not be 
needed - the code works fine without it, as it leaves empty array entries 
as 'undefined' which always fail the equality check.

Regards,

-Darren

this.rmSlot = function(pobj, pfp){
            if(__sig__.isSigFP(pfp)){
                  var tslot = __sig__.getSig(pfp);
                  var tsl = this.slots.length;
                  for(var x=(tsl-1); x>=0; x-=1){
                        if(this.slots[x]==tslot){
                              // Fix bug
                              delete this.slots[x];

                              // if only 2 arguments were passed, or the 
third isn't "true", return.
 if((arguments.length<3)||(arguments[2]!=true)){
                                                // changed 'return true' 
to break
                                    break;
                              }
                        }
                  }
                  // Reassign slots to remove empty entries
                  var newSlots = [];
                  var m = 0;
                  for (var n=0; n < this.slots.length; n++) {
                        if (this.slots[n] != undefined) {
                              newSlots[m++] = this.slots[n];
                        }
                  }
                  this.slots = newSlots;
                  // End of slot reassignment

                  return true;
            }else{
                  return false;
            }
      }

--=_alternative 0001D58085256EFE_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">The sigslot framework appears to have
a bug in the rmSlot method where it doesn't remove the correct slot. &nbsp;I've
included a version that addresses the issue. &nbsp;The reassignment of
the slots array removes any 'holes'. &nbsp;Not knowing enough about javascript's
memory management, this step may not be needed - the code works fine without
it, as it leaves empty array entries as 'undefined' which always fail the
equality check.</font>
<br>
<br><font size=2 face="sans-serif">Regards,</font>
<br>
<br><font size=2 face="sans-serif">-Darren</font>
<br>
<br><font size=2><tt>this.rmSlot = function(pobj, pfp){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(__sig__.isSigFP(pfp)){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var tslot
= __sig__.getSig(pfp);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var tsl
= this.slots.length;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(var
x=(tsl-1); x&gt;=0; x-=1){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;if(this.slots[x]==tslot){</tt></font>
<br><font size=2><tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Fix bug<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete this.slots[x];<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// if only 2 arguments were passed, or
the third isn't &quot;true&quot;, return.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if((arguments.length&lt;3)||(arguments[2]!=true)){</tt></font>
<br><font size=2><tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; // changed 'return true' to break<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</tt></font>
<br><font size=2><tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; // Reassign slots to remove empty entries<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var newSlots
= [];<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var m =
0;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (var
n=0; n &lt; this.slots.length; n++) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;if (this.slots[n] != undefined) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;newSlots[m++] = this.slots[n];<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.slots
= newSlots;</tt></font>
<br><font size=2><tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; // End of slot reassignment<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return true;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}else{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp;}<br>
</tt></font>
--=_alternative 0001D58085256EFE_=--


--===============0730476066==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
The netWindows developers list: [email protected]
http://netwindows.org/mailman/listinfo/devel_netwindows.org

--===============0730476066==--