> > managed to get something working on my machine, so it might help you. this > is the code:
You need to also add: ccall((:oauth_free_array,"liboauth"), Void, (Ptr{Cint}, Ptr{Ptr{Ptr{Cchar_t}}}), [result], a) (roughly - untested) On Mon, Sep 15, 2014 at 12:52 PM, David Gonzales <dvdgonzale...@gmail.com> wrote: > managed to get something working on my machine, so it might help you. this > is the code: > a = Array(Ptr{Ptr{Uint8}},1) > str = > "oauth_token=2a71d1c73d2771b00f13ca0acb9836a10477d3c56&oauth_token_secret=a1b5c00c1f3e23fb314a0aa22e990266" > result = > ccall((:oauth_split_url_parameters,"liboauth"),Cint,(Ptr{Uint8},Ptr{Ptr{Ptr{Uint8}}}),convert(Ptr{Uint8},str),a) > aa = unsafe_load(a[1]) > bb = unsafe_load(a[1],2) > bytestring(aa) > bytestring(bb) > > > cheers > > > On Monday, September 15, 2014 6:45:41 PM UTC+3, Randy Zwitch wrote: >> >> Thanks Ivar. When I get further along, I'd love for you to take a look at >> what I did. Right now, I'm blindly wrapping the functions as practice, but >> if you look in my code/tests, I can tell there are functions there that are >> either duplicative or don't make sense. And if my naive wrapping is leaking >> memory because the original function is leaking memory, I'd love to get >> that taken care of before adding to METADATA :) >> >> On Monday, September 15, 2014 11:37:15 AM UTC-4, Ivar Nesje wrote: >>> >>> That seems like a really tricky function to wrap. You need to do C style >>> memory handling in order for this to work, and C style memory handling >>> requires you to really look in the documentation (for the function) to see >>> how it works. Example code for how this function is used correctly from C >>> is almost mandatory. >>> >>> I found this example >>> <http://liboauth.sourceforge.net/tests_2oauthexample_8c-example.html>, >>> apparently from the OAuth site, where they demonstrate how to do a poor job >>> and leak memory. DON'T USE IT!!! >>> >>> I'll try to write a correct implemementation that uses oauth_free_array >>> <http://liboauth.sourceforge.net/oauth_8h.html#ada81dd39be59cadbc1bd77df78ffef52>(int* >>> c, char**arg) to clean up. >>> >>> Ivar >>> >>> >>> kl. 16:47:44 UTC+2 mandag 15. september 2014 skrev Randy Zwitch følgende: >>>> >>>> Continuing on my attempt to learn Julia ccall by wrapping liboauth...I >>>> have the following code that was mostly generated by Clang.jl: >>>> >>>> >>>> https://github.com/randyzwitch/OAuth.jl/blob/ >>>> master/src/OAuth.jl#L248-254 >>>> >>>> >>>> function oauth_split_url_parameters(url::String,argv::Ptr{Ptr{Ptr{ >>>> Uint8}}}) >>>> result = ccall((:oauth_split_url_parameters,LIBOAUTH),Cint,( >>>> Ptr{Uint8},Ptr{Ptr{Ptr{Uint8}}}),url,argv) >>>> if result == C_NULL >>>> error("oauth_split_url_parameters failed") >>>> end >>>> return result >>>> end >>>> >>>> I'm pretty sure I want to re-write this code to remove the second >>>> argument, since the second argument is just allocating space for an array. >>>> I don't want to return the Cint for success/fail, but rather the array that >>>> splits the 'url' argument. >>>> >>>> function oauth_split_url_parameters(url::String) >>>> argv = *Ptr{Ptr{Ptr{Uint8}}}* #What Julia code actually goes here >>>> to make this work? >>>> result = ccall((:oauth_split_url_parameters,LIBOAUTH),Cint,( >>>> Ptr{Uint8},Ptr{Ptr{Ptr{Uint8}}}),url,argv) >>>> if result == C_NULL >>>> error("oauth_split_url_parameters failed") >>>> end >>>> return argv >>>> end >>>> >>>> I've tried allocating an array() in place of Ptr{Ptr{Ptr{Uint8}}} , but >>>> that doesn't work. I think this is an array of pointers to string >>>> variables? How can I make this work? >>>> >>>> Thanks. >>>> >>>> >>>>