<html><body bgcolor="#FFFFFF"><div>Not good: don't return structs by value. Pass a pointer to where you want the result. <br><br> - Jay (briefly/pocket-sized-computer-aka-phone)</div><div><br>On Mar 21, 2012, at 5:25 AM, Dragiša Durić <<a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><div><* EXTERNAL evbuffer_search *></div><div>PROCEDURE search(buf: t; what: char_star; len: size_t; start: UNTRACED REF ptr): ptr;</div><div><br></div><div><* EXTERNAL evbuffer_search_range *></div><div>PROCEDURE search_range(buf: t; what: char_star; len: size_t; start, end: void_star): ptr;</div><div><br></div><div>Tried both void_star and UNTRACED REF…</div><div><br></div><div><div>On Mar 21, 2012, at 12:59 PM, Antony Hosking wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div bgcolor="#FFFFFF"><div>Can you show your M3 interface declarations for these?<br><br>Sent from my iPad</div><div><br>On Mar 21, 2012, at 6:22 AM, Dragiša Durić <<a href="mailto:dragisha@m3w.org"><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a></a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><div>Here are procedures I am binding. No nonsense, no #define hell. Clear and pure, and I don't see how I would write better and clearer :).</div><div><br></div><div>=====</div><div>struct evbuffer_ptr</div><div>evbuffer_search(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start)</div><div>{</div><div> return evbuffer_search_range(buffer, what, len, start, NULL);</div><div>}</div><div><br></div><div>struct evbuffer_ptr</div><div>evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start, const struct evbuffer_ptr *end)</div><div>{</div><div> </div><div><div>On Mar 21, 2012, at 5:35 AM, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="hmmessage" style="font-size: 10pt; font-family: Tahoma; "><div dir="ltr">That is a bit wierd.<br>Lots of things seem wierd at first..and wierd even at second,<br>but often there are reasons things are how they are,<br>and often there are barriers to change.<br><br> <br>I would expect Ctypes.char = CHAR.<br> <br><br>But I don't know why it isn't.<br> <br> <br>I realize that CHAR ideally is some idealized abstract thing that can hold a unicode character.<br>But it isn't. It is 8 bits and will never be larger.<br> <br> <br>You are really best not to interface directly to C that you didn't write<br>and the C that you write that you interface to, you are best restricting<br>to a subset of C.<br> <br><br>And use m3-libs/m3core/src/unix for working examples.<br> <br><br>I remember when I added "BITS FOR" in Ctypes, it broke stuff.<br>I either didn't commit that or later removed it, leaving things as they<br>have been historically.<br> <br> <br> - Jay<br><br><div><div id="SkyDrivePlaceholder"></div>> To:<span class="Apple-converted-space"> </span><a href="mailto:dabenavidesd@yahoo.es"><a href="mailto:dabenavidesd@yahoo.es">dabenavidesd@yahoo.es</a></a><br>> Date: Tue, 20 Mar 2012 15:06:59 -0700<br>> From:<span class="Apple-converted-space"> </span><a href="mailto:mika@async.caltech.edu"><a href="mailto:mika@async.caltech.edu">mika@async.caltech.edu</a></a><br>> CC:<span class="Apple-converted-space"> </span><a href="mailto:m3devel@elegosoft.com"><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a></a><br>> Subject: Re: [M3devel] Problem interfacing C lib<br>><span class="Apple-converted-space"> </span><br>> char_star is, at least in my installation<br>><span class="Apple-converted-space"> </span><br>> UNTRACED REF [-16_7f-1 .. 16_7f]<br>><span class="Apple-converted-space"> </span><br>> But it's a good point that it's not actually an UNTRACED REF ARRAY OF CHAR<br>><span class="Apple-converted-space"> </span><br>> However<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> ADR(chars[0])<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> ought to be more or less precisely of the type char_star<br>><span class="Apple-converted-space"> </span><br>> ... so I doubt that is the problem.<br>><span class="Apple-converted-space"> </span><br>> I'm curious about whether the assembly code for the call changes without<br>> the <*EXTERNAL*> pragma... it shouldn't should it? In which case, where<br>> is chars passed, in pure Modula-3 code? I don't know enough about the<br>> standard ABI of amd64 to know what the code should look like I'm afraid.<br>><span class="Apple-converted-space"> </span><br>> Mika<br>><span class="Apple-converted-space"> </span><br>> "Daniel Alejandro Benavides D." writes:<br>> >Hi all:<br>> >I think the unchecked error lays down to:<br>> >Unsafe Operations section 2.7 (cf. Green Book SPWM3, p- 61):<br>> >it's allowed to have " ... a value of type ADDRESS to be assigned to a vari=<br>> >able of type UNTRACED REF T. It is an unchecked runtime error if the value =<br>> >does not address a variable of type T."<br>> ><br>> >which could be reads conversely as:<br>> ><br>> >a value of type UNTRACED REF T to be assigned to a variable of type ADDRESS=<br>> >. It is a checked runtime error if the variable does not address a var=<br>> >iable of type .T=20<br>> >=20<br>> >And because because char_star is a subrange [-128 .. 127] OF INTEGER (and n=<br>> >ot ADDRESS) and chars is UNTRACED REF ARRAY OF CHAR erro is cf. the specif=<br>> >ication.<br>> >So maybe you need to change your char_star<br>> ><br>> >Thanks in advance<br>> ><br>> ><br>> >--- El mar, 20/3/12, Dragi=C5=A1a Duri=C4=87 <<a href="mailto:dragisha@m3w.org"><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a></a>> escribi=C3=<br>> >=B3:<br>> ><br>> >> De: Dragi=C5=A1a Duri=C4=87 <<a href="mailto:dragisha@m3w.org"><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a></a>><br>> >> Asunto: Re: [M3devel] Problem interfacing C lib<br>> >> Para: "Mika Nystrom" <<a href="mailto:mika@async.caltech.edu"><a href="mailto:mika@async.caltech.edu">mika@async.caltech.edu</a></a>><br>> >> CC: <a href="mailto:m3devel@elegosoft.com"><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a></a><br>> >> Fecha: martes, 20 de marzo, 2012 01:04<br>> >> Errorr is SIGSEGV.<br>> >>=20<br>> >> chars is UNTRACED REF ARRAY OF CHAR but it is lesser<br>> >> problem, I think. It looks like formal 'what' is not<br>> >> sent at all!? It's place is taken by next argument - INTEGER<br>> >> len (equal 0x7 in this example).<br>> >>=20<br>> >> One common problem I meet often (as I bind C often :) is<br>> >> this - address of open array argument is ot what it looks<br>> >> like. To be sure you are getting address of various UNTRACED<br>> >> REF..ARRAY.. and open array procedure arguments - use=20<br>> >>=20<br>> >> ADR(chars[0])<br>> >>=20<br>> >> and do not use:<br>> >>=20<br>> >> LOOPHOLE(chars, ADDRESS)<br>> >>=20<br>> >> Of course, I tried ADR(chars[0]) :) - Same thing happened.<br>> >> Right now II downgraded my code to use strstr(3), but this<br>> >> argument passing still bugs me.<br>> >>=20<br>> >> dd<br>> >>=20<br>> >>=20<br>> >> On Mar 20, 2012, at 1:26 AM, Mika Nystrom wrote:<br>> >>=20<br>> >> > What are the declarations of all the variables involved<br>> >> in the call?<br>> >> >=20<br>> >> > And what is the actual error? Is it a SIGBUS,<br>> >> SIGSEGV?<br>> >> >=20<br>> >> > =3D?utf-8?Q?Dragi=3DC5=3DA1a_Duri=3DC4=3D87?=3D writes:<br>> >> >> I had some error before I LOOPHOLEd it.<br>> >> >>=20<br>> >> >> On Mar 19, 2012, at 7:27 PM, Daniel Alejandro<br>> >> Benavides D. wrote:<br>> >> >>=20<br>> >> >>> Hi all:<br>> >> >>> if chars is ADDRESS type why are you<br>> >> LOOPHOLE'ing it?=3D20<br>> >> >>> Thanks in advance<br>> >> >>> =3D20<br>> >> >>> --- El lun, 19/3/12, Dragi=3DC5=3DA1a Duri=3DC4=3D87<br>> >> <<a href="mailto:dragisha@m3w.org"><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a></a>><br>> >> =3D<br>> >> >> escribi=3DC3=3DB3:<br>> >> >>> =3D20<br>> >> >>>> De: Dragi=3DC5=3DA1a Duri=3DC4=3D87 <<a href="mailto:dragisha@m3w.org"><a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a></a>><br>> >> >>>> Asunto: [M3devel] Problem interfacing C<br>> >> lib<br>> >> >>>> Para: "m3devel" <<a href="mailto:m3devel@elegosoft.com"><a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a></a>><br>> >> >>>> Fecha: lunes, 19 de marzo, 2012 12:13<br>> >> >>>> #1 0x00000035bd8172a0 in<br>> >> >>>> evbuffer_search_range (buffer=3D3D0x694090,<br>> >> what=3D3D0x7 <Address<br>> >> >>>> 0x7 out of bounds>, len=3D3D0,<br>> >> start=3D3D0x0,<br>> >> >>>> end=3D3D0x7fffffffdbb0)<br>> >> >>>> at buffer.c:2441<br>> >> >>>> #2 0x0000000000404a0c in<br>> >> Buffer__Search (t=3D3D<error<br>> >> >>>> reading variable>, pattern=3D3D<error<br>> >> reading<br>> >> >>>> variable>, from=3D3D<error reading<br>> >> variable>,=3D20<br>> >> >>>> to=3D3D<error reading<br>> >> variable>) at<br>> >> >>>> ../src/Buffer.m3:150<br>> >> >>>> =3D20<br>> >> >>>> Buffer.m3:150<br>> >> >>>> pos :=3D3D<br>> >> >>>> evbuffer.search_range(t.b, LOOPHOLE(chars,<br>> >> ADDRESS), len,<br>> >> >>>> NIL, NIL);<br>> >> >>>> =3D20<br>> >> >>>> t.b is a pointer, so is chars=3DE2=3D80=3DA6 len<br>> >> is Utypes.size_t and<br>> >> >>>> it's value is 7.<br>> >> >>>> =3D20<br>> >> >>>> <* EXTERNAL evbuffer_search_range *><br>> >> >>>> PROCEDURE search_range(buf: t; what:<br>> >> char_star; len: size_t;<br>> >> >>>> start, end: UNTRACED REF ptr): ptr;<br>> >> >>>> =3D20<br>> >> >>>> t is an ADDRESS, and so on=3DE2=3D80=3DA6<br>> >> >>>> =3D20<br>> >> >>>> Critical Mass Modula-3 version d5.9.0<br>> >> >>>> last updated: 2010-07-21<br>> >> >>>> compiled: 2010-10-04 07:24:16<br>> >> >>>> configuration: /etc/cm3.cfg<br>> >> >>>> host: AMD64_LINUX<br>> >> >>>> target: AMD64_LINUX<br>> >> >>>> =3D20<br>> >> >>>> =3D20<br>> >> >>>> Any ideas? TIA,<br>> >> >>>> dd<br>> >> >>>> =3D20<br>> >> >>>> =3D20<br>> >>=20<br>> >></div></div></div></blockquote></div><br></div></blockquote></div></blockquote></div><br></div></blockquote></body></html>