On Sun, May 12, 2013 at 3:23 AM, Florian Weimer <f...@deneb.enyo.de> wrote:
> * Skirmantas Kligys:
>
>> I am trying to write a native wrapper for
>>
>> https://github.com/pascalj/rust-expat
>>
>> (BTW, if there is a native Rust XML parser, I am interested to hear
>> about it, did not find it).  I have trouble calling back into Rust
>> from C code:
>
> It's probably better to avoid calling back into Rust, storing events
> in a buffer in C callbacks.

Florian,

Any reasons why?  Stack overflows?

I now have two working approaches:

1. Store Rust callbacks in a struct, pass it through expat as
user_data: *c_void, cast it back into a struct in a C callback, call
the Rust callback.

2. Create a port/chan pair, pass the chan through expat as user_data:
*c_void, cast it back into chan in a C callback, use it to send
XmlEvent enum variants; a child task listens on the port and does the
processing.

The second approach seems more "rusty" and probably will load two
cores unlike the first.

Both approaches pass data around as *c_void, which makes me a bit
nervous, but I just don't see any other way to pass typed pointers
into a C callback.  Let me know if I am missing something.

Thanks.
Skirmantas Kligys
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to