<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Hi Folks,<br>
    <br>
    As Hernán pointed out, doing #become: sometimes is dangerous. For
    instance, if you do `self become: xxx` in the middle of a method,
    like in this case, the rest of the method will continue, but with
    'self' now being the new object. But the method on execution belongs
    to the old class! Any possible instance variable access will result
    in undefined behavior or a hard crash.<br>
    <br>
    The system has no way to validate that the method in execution is
    appropriate for the new instance. And the same would happen for any
    method where the becomed object is the receiver in the call stack,
    as soon execution will return there, and the same will happen.<br>
    <br>
    There are two ways out of this:<br>
    <br>
    1- #become: objects by 'remote control'. Ensure that the object to
    be becomed is not in the call stack and have some other object
    handle this.<br>
    <br>
    2- Take full responsibility for what you are doing, because you know
    that no invalid ivar accesses will happen. Implement your own
    version of #become:, maybe calling it #uncheckedBecome: or such.<br>
    <br>
    BTW, David, please read the exception description again and try to
    make sense of it. It it doesn't seem to make sense, please help us
    improve the text to something easier to understand in your view.<br>
    <br>
    Thanks,<br>
    <br>
    On 2/26/2024 9:04 AM, Hernán Wilkinson via Cuis-dev wrote:
    <blockquote
cite="mid:CAGgF3GwyToj5-ewe0D=G1+jpbLfz8cPU0pqVn3FX5Ljn29RZSw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi David,<br>
        <div> The exception that is signaled
          is MethodInCallStackToBecomeInvalid.</div>
        <div> It means that there is a method context in the stack that
          has a reference to the object you want to "become", in this
          case it is self.</div>
        <div> Doing a become in such a condition can produce problems (I
          do not remember the exact details of them, but something
          related to the method being jitted or something like that) and
          that is why the check and signaling the exception, but the
          exception is resumable as you saw. I have never had any
          problem resuming that exception under this circumstance. </div>
        <div><br>
        </div>
        <div>Cheers</div>
        <div>Hernan.</div>
        <div><br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Mon, Feb 26, 2024 at
          6:09 AM David Faitelson via Cuis-dev <<a
            moz-do-not-send="true" href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin: 0px 0px 0px
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div class="msg319760941679385087">
            <div style="" lang="EN-US">
              <div class="m_319760941679385087WordSection1">
                <p class="MsoNormal">Hi dear all,</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">I want to use become: to lazily
                  load objects from a database. Something along the
                  lines of:</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">Stub >> doesNotUnderstand:
                  aMessage</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">                | actual |</p>
                <p class="MsoNormal">                </p>
                <p class="MsoNormal">                actual := “fetch
                  from db”.</p>
                <p class="MsoNormal">                </p>
                <p class="MsoNormal">                self become:
                  actual.</p>
                <p class="MsoNormal">                </p>
                <p class="MsoNormal">                aMessage sendTo:
                  self.</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">When I run this code I get an
                  exception, but if I continue despite the signal, the
                  operations succeeds and the stub is correctly replaced
                  by the actual object.</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">Is this specific use of become:
                  safe despite the warning? Or does it work by luck and
                  I should seek a different solution? Or perhaps I can
                  use become: in some other way to achieve this effect?</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">Thanks,</p>
                <p class="MsoNormal">David</p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal"> </p>
                <p class="MsoNormal">                </p>
                <p class="MsoNormal"> </p>
                <div>
                  <div>
                    <p class="MsoNormal"><span style="font-size: 12pt;
                        font-family: "Times New Roman",serif;
                        color: black;">  </span><span style="font-size:
                        12pt; font-family: Calibri,sans-serif;"></span></p>
                  </div>
                </div>
                <p class="MsoNormal"> </p>
              </div>
            </div>
            -- <br>
            Cuis-dev mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
            <a moz-do-not-send="true"
              href="https://lists.cuis.st/mailman/listinfo/cuis-dev"
              rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
          </div>
        </blockquote>
      </div>
      <br clear="all">
      <div><br>
      </div>
      <span class="gmail_signature_prefix">-- </span><br>
      <div dir="ltr" class="gmail_signature">
        <div dir="ltr">
          <div>
            <div dir="ltr">
              <div style="font-size: small;">
                <div dir="ltr">
                  <div dir="ltr">
                    <div style="font-size: 12.8px;"><span
                        style="font-family: tahoma,sans-serif;
                        font-size: xx-small; border-collapse: collapse;"><strong><span
                            style="font-size: 8pt;"><span
                              style="font-size: small;"><font size="2"><span
                                  style="font-weight: normal;"><span
                                    style="font-weight: bold;">Hernán
                                    Wilkinson</span><br>
                                  Agile Software Development, Teaching
                                  & Coaching</span></font></span></span></strong></span></div>
                    <div style="font-size: 12.8px;"><span
                        style="font-family: tahoma,sans-serif;
                        font-size: xx-small; border-collapse: collapse;"><strong><span
                            style="font-size: 8pt;"><span
                              style="font-size: small;"><font size="2"><span
                                  style="font-weight: normal;">Phone:
                                  +54-011</span></font></span></span></strong></span><font
                        size="2" face="tahoma, sans-serif">-4893-2057</font></div>
                    <div style="font-size: 12.8px;"><strong
                        style="font-family: tahoma,sans-serif;
                        font-size: xx-small;"><span style="font-size:
                          8pt;"><span style="font-size: small;"><font
                              size="2"><span style="font-weight:
                                normal;">Twitter: @HernanWilkinson</span></font></span></span></strong></div>
                    <div style="font-size: 12.8px;"><span
                        style="font-family: tahoma,sans-serif;
                        font-size: xx-small; border-collapse: collapse;"><strong><span
                            style="font-size: 8pt;"><span
                              style="font-size: small;"><font size="2"><span
                                  style="font-weight: normal;">site: <a
                                    moz-do-not-send="true"
                                    href="http://www.10pines.com/"
                                    style="color: rgb(17, 65, 112);"
                                    target="_blank">http://www.10Pines.com</a></span></font></span></span></strong></span></div>
                    <div style="font-size: 12.8px;"><font face="tahoma,
                        sans-serif"><span style="border-collapse:
                          collapse;">Address: Alem 896</span></font>,
                      Floor 6, Buenos Aires, Argentina</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich</pre>
  </body>
</html>