I'm really glad you mentioned this .... I got to this point:<br><br><span id=":t" class="Ad"></span><br>(include "gl-header.scm") <br> <br>
(c-declare #<<c-declare-end <br>#include <GL/gl.h> <br>c-declare-end <br>
) <br> <br> <br>
(define u32-vector->uint* <br> (c-lambda (scheme-object) GLuint* "___result = ___CAST(GLuint*,&___FETCH_U32(___BODY(_\<br>__arg1),___INT(0)));")) <br>
<br><br>... and yeah, now I'm going to scratch it. Wasn't aware the gc moved stuff around. Thanks! I can only imagine how fun this bug would have been to debug.<br><br><div class="gmail_quote">On Thu, Apr 16, 2009 at 9:30 PM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5"><br>
On 17-Apr-09, at 12:19 AM, lowly coder wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi!<br>
<br>
This is a different question from my previous silly question.<br>
<br>
All though it's really cool that I can take a C function with signature:<br>
void foo(int *);<br>
and in scheme land create a (scheme-foo) so that I can do:<br>
<br>
(define bar (make-u....vector ...))<br>
(scheme-foo bar)<br>
<br>
There are a lot of C functions I need to use that take arguments int*, short*, ...<br>
<br>
I would prefer to not change all these C bindings, and somehow magically have a Scheme function that given:<br>
(uber-magic bar)<br>
returns me a int* corresponding to where the data is stored in u32-vector bar.<br>
</blockquote>
<br></div></div>
That would be problematic because objects in the Scheme heap, including vectors, can be moved by the garbage collector. So a C pointer to an element of a u32vector could become stale (dangling pointer) at any moment. The only way this could work is to allocate a "still" vector. But all of this is seriously asking for trouble (the pointer will be a dangling pointer when the still object is reclaimed).<br>
<font color="#888888">
<br>
Marc<br>
<br>
</font></blockquote></div><br>