Aaron Gray | 28 Apr 03:39

Re: idc for windows platform

On Mon, Apr 28, 2008 at 2:28 AM, Aaron Gray <aaronngray.lists-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
On Mon, Apr 28, 2008 at 2:18 AM, Krzysztof Kowalczyk <kkowalczyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>  "Krzysztof Kowalczyk" <kkowalczyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
>  > The other form works for both msvc and gcc (see
>  > http://codepad.org/VxF4pBHg for a proof (well, a proof that it
>  > compiles with gcc, or at least a version of gcc)) so the #ifdef isn't
>  > necessary, just use __VA_ARGS__ version. I verified that it compiles
>  > with msvc 2005.
>
>  Using __VA_ARGS__ is not quite correct with GCC.  You should be able
>  to call the _send (or _sendv) macro without supplying any arguments
>  after RCV.  The comma preceding __VA_ARGS__ causes a syntax error
>  under GCC when there are no other arguments, but if you use ##ARG it
>  deletes the comma and all is well.
>
>  Does MSVC compile properly without arguments?
>
>  i.e. does:
>
>  _send("abc", 123)
>
>  cause a syntax error?

Good point. MSVC handles that according to
http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx
and this test program, which compiles and works as expected with msvc
(and doesn't compile on gcc):

#include <stdio.h>
#define np(s, ...) \
       printf(s, __VA_ARGS__)

int main(int argc, char **argv)
{
 int d = 4;
 np("hello\n");
 np("s %d", d);
 return 0;
}

So #ifdef is needed after all. Alternatively, all places where
_send(a,b) is used, could be changed to _send0(a,b).

Here's another possible solution if we are using C99 and have inline functions :-
 
#include <stdarg.h>
 
inline oop _send( oop msg, oop rcv, ...)
{
  va_list ap;
  register oop _r = rcv;
  struct __closure *_c;
  oop ret;

  va_start( ap, rcv);
  _c = (struct __closure *) _libid->bind( msg, _r);
  ret = (_c->method)( (oop) _c, _r, _r, ap);
  va_end( ap);
  return ret;
}
You will probably need a "#define inline __inline" for MS VC.
 
This is untested but should work okay. I am not at a state where I can really test this yet, hopefully I will be able to catch up this week.
 
A hacked PoC :-
 
 
Aaron
 
 
 
<div>
<div class="gmail_quote">On Mon, Apr 28, 2008 at 2:28 AM, Aaron Gray &lt;<a href="mailto:aaronngray.lists@...">aaronngray.lists@...</a>&gt; wrote:<br><blockquote class="gmail_quote">
<div class="gmail_quote">
<div>
<div></div>
<div class="Wj3C7c">On Mon, Apr 28, 2008 at 2:18 AM, Krzysztof Kowalczyk &lt;<a href="mailto:kkowalczyk@..." target="_blank">kkowalczyk@...</a>&gt; wrote:<br><blockquote class="gmail_quote">
<div>&gt; &nbsp;"Krzysztof Kowalczyk" &lt;<a href="mailto:kkowalczyk@..." target="_blank">kkowalczyk@...</a>&gt; writes:<br>&gt;<br>&gt; &nbsp;&gt; The other form works for both msvc and gcc (see<br>&gt; &nbsp;&gt; <a href="http://codepad.org/VxF4pBHg" target="_blank">http://codepad.org/VxF4pBHg</a> for a proof (well, a proof that it<br>
&gt; &nbsp;&gt; compiles with gcc, or at least a version of gcc)) so the #ifdef isn't<br>&gt; &nbsp;&gt; necessary, just use __VA_ARGS__ version. I verified that it compiles<br>&gt; &nbsp;&gt; with msvc 2005.<br>&gt;<br>&gt; &nbsp;Using __VA_ARGS__ is not quite correct with GCC. &nbsp;You should be able<br>
&gt; &nbsp;to call the _send (or _sendv) macro without supplying any arguments<br>&gt; &nbsp;after RCV. &nbsp;The comma preceding __VA_ARGS__ causes a syntax error<br>&gt; &nbsp;under GCC when there are no other arguments, but if you use ##ARG it<br>
&gt; &nbsp;deletes the comma and all is well.<br>&gt;<br>&gt; &nbsp;Does MSVC compile properly without arguments?<br>&gt;<br>&gt; &nbsp;i.e. does:<br>&gt;<br>&gt; &nbsp;_send("abc", 123)<br>&gt;<br>&gt; &nbsp;cause a syntax error?<br><br>
</div>Good point. MSVC handles that according to<br><a href="http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/ms177415(VS.80).aspx</a><br>and this test program, which compiles and works as expected with msvc<br>
(and doesn't compile on gcc):<br><br>#include &lt;stdio.h&gt;<br>#define np(s, ...) \<br>&nbsp; &nbsp; &nbsp; &nbsp;printf(s, __VA_ARGS__)<br><br>int main(int argc, char **argv)<br>{<br>&nbsp;int d = 4;<br>&nbsp;np("hello\n");<br>&nbsp;np("s %d", d);<br>
&nbsp;return 0;<br>}<br><br>So #ifdef is needed after all. Alternatively, all places where<br>_send(a,b) is used, could be changed to _send0(a,b).<br><br>
</blockquote>
</div>
</div>
<div>Here's another possible solution if we are using C99 and have inline functions :-</div>
<div>&nbsp;</div>
<div>#include &lt;stdarg.h&gt;</div>
<div>&nbsp;</div>
<div>inline oop _send( oop msg, oop rcv, ...)<br>{<br>&nbsp; va_list ap;<br>&nbsp; register oop _r = rcv;<br>&nbsp; struct __closure *_c;<br>&nbsp; oop ret;</div>
<div>
<br>&nbsp; va_start( ap, rcv);<br>
</div>
<div>&nbsp; _c = (struct __closure *) _libid-&gt;bind( msg, _r);<br>&nbsp; ret = (_c-&gt;method)( (oop) _c, _r, _r, ap);<br>
</div>
<div>&nbsp; va_end( ap);<br>
</div>
<div>&nbsp; return ret;<br>}<br>
</div>
<div>You will probably need a "#define inline __inline" for MS VC.</div>
<div>&nbsp;</div>
<div>This is untested but should work okay. I am not at a state where I can really test this yet, hopefully I will be able to catch up this week.</div>
<div></div>&nbsp;</div>
</blockquote>
</div>
<div>A hacked PoC :-</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <a href="http://codepad.org/8tZyQphW">http://codepad.org/8tZyQphW</a>
</div>
<div>&nbsp;</div>
<div>Aaron</div>
<div>&nbsp;</div>
<blockquote class="gmail_quote">
<div class="gmail_quote">
<div>
<span></span>&nbsp;</div>
<blockquote class="gmail_quote">
<div class="gmail_quote">
<div>&nbsp;</div>
</div>
</blockquote>
</div>
</blockquote>
</div>

Gmane