Anarchos has quit [Quit: Vision[0.9.7-H-090423]: i've been blurred!]
rwmjones has quit [Read error: Operation timed out]
Drk-Sd has quit [Quit: night]
jknick has quit [Quit: Lost terminal]
threeve has joined #ocaml
_unK has quit [Remote host closed the connection]
<Alpounet>
yziquel, disable the GC ?
<yziquel>
yes. to see if it's causing my problems.
<Alpounet>
OCaml's runtime is based on it, afaik, so my guess is that it isn't that much of a good idea
cognizant-cog has joined #ocaml
<Alpounet>
you can get GC statistics etc
<Alpounet>
force GC'ing
<yziquel>
(segfaults with caml_copy_string)
<Alpounet>
it may help revealing your problem
<yziquel>
main program is C, calling OCaml code.
<Alpounet>
yziquel, any potential scope issues with ocaml<->native code ?
<Alpounet>
like a pointer already released but still manipulated from OCaml code
<Alpounet>
freed*
<yziquel>
that's what i'd like to know.
<yziquel>
disabling the GC, or at least heap compaction, would be useful here.
<Alpounet>
hmm
<Alpounet>
gdb isn't of help here ?
<yziquel>
nope.
<Alpounet>
just sit and watch your pointers in action
<yziquel>
it crashes as soon as the callback runs. first opcode.
<Alpounet>
and see if one goes into ocaml code while in an invalid state
<Alpounet>
watching what you pass to caml_copy_string gives you any information ?
<yziquel>
currently going through the asm of caml_copy_string to see what's going on.
<yziquel>
what I pass to caml_copy_string is a string.
<yziquel>
i want to check what i get out of it. not easy.
<Alpounet>
I guess caml_copy_string just accesses your pointer and copies cells from there
<Alpounet>
thus the address may be invalid
<Alpounet>
hmm yeah
<yziquel>
{ value s = Val_unit; Begin_roots1(s); value s = caml_copy_string(my_string); value x = caml_callback(*caml_named_value("value of string"), s); End_roots(); }
yakischloba has quit [Quit: Leaving.]
<yziquel>
Alpounet: the repnz scas %es:(%rdi),%al instruction, you mean?
<yziquel>
%rdi: first argument passed to caml_copy_string (amd64). a char *
<Alpounet>
I guess it's somewhere in there that you have an invalid address being accessed, or some similar undesired behavior
<Alpounet>
so there
<Alpounet>
it segfaults on value s = caml_copy_string(my_string);
<yziquel>
no
<yziquel>
it segfaults in the first opcode of the callback function. i.e. as soon as it enters ocaml code.
<yziquel>
i believe it tries to access the value, i.e. the ocaml string.
<Alpounet>
yziquel, are you including caml/alloc.h ?
<Alpounet>
including caml/alloc.h should fix your issue
<yziquel>
callq 0x40b39f <caml_alloc_string> is screwed?
<Alpounet>
it seems the return type is biased depending on whether you include alloc.h or not
<yziquel>
mkay... that's a pain.
<Alpounet>
yziquel, does it work now ?
<yziquel>
wait.
<Alpounet>
(if it's the issue, yeah, I agree, it's much of a pain)
<yziquel>
i'm pretty sure that it's this,
<yziquel>
i'm surprised that the bug report is closed.
<Alpounet>
yeah
<Alpounet>
going the following way "you must include caml/alloc.h, that's all, like if we were gonna do it for you"
<yziquel>
i mean: you want to call OCaml from C. you compile your .o, your .cmx. you ocamlopt the whole bunch. (the manual doc isn't overly clear on the topic btw). you fill in headers one by one. and then you cannot allocate on C side just because you're on amd64?
<yziquel>
at least there should be a more detailed doc on embedding OCaml in C code in the manual. with an alloc.h included.
<Alpounet>
well
<Alpounet>
memory.h SHOULD include alloc.h
<Alpounet>
or maybe I'm stupid ?
<Alpounet>
but hey
<Alpounet>
how do you handle memory without allocating ?
<Alpounet>
and, as we've just seen it, such a bug is quite tricky to find.
<yziquel>
it works now, with alloc.h
<Alpounet>
yeah, great !
<Alpounet>
now we'll both know it... in case
<yziquel>
yeah sure. but the idea of ocaml segfaulting... doesn't cut it...
<Alpounet>
heh
<Alpounet>
now, 4AM in France, I'm off
<Alpounet>
ttyl
pad has quit [Remote host closed the connection]
M|_ has joined #ocaml
Asmadeus_ has joined #ocaml
msteele_ has joined #ocaml
LionMade1fLions has joined #ocaml
bitbckt_ has joined #ocaml
fremo___ has joined #ocaml
bitbckt has quit [Write error: Broken pipe]
fremo_ has quit [Write error: Broken pipe]
dark has joined #ocaml
LionMadeOfLions has quit [Ping timeout: 265 seconds]
M| has quit [Ping timeout: 265 seconds]
Asmadeus has quit [Ping timeout: 265 seconds]
msteele has quit [Ping timeout: 265 seconds]
cognizant-cog has quit [Quit: ChatZilla 0.9.86 [Firefox 3.5.7/20100106054534]]
cognizant-cog has joined #ocaml
cognizant-cog has quit [Quit: ChatZilla 0.9.86 [Firefox 3.5.7/20100106054534]]
Associat0r has quit [Quit: Associat0r]
yakischloba has joined #ocaml
bzzbzz_ has joined #ocaml
caligula__ has joined #ocaml
cognizant-cog has joined #ocaml
bzzbzz has quit [Read error: Connection reset by peer]
caligula_ has quit [Remote host closed the connection]
sabren has joined #ocaml
sabren has quit []
threeve has quit [Quit: threeve]
ulfdoz has joined #ocaml
Gooffy has joined #ocaml
cognizant-cog has quit [Quit: ChatZilla 0.9.86 [Firefox 3.5.7/20100106054534]]
bzzbzz_ has quit [Quit: leaving]
ulfdoz has quit [Ping timeout: 265 seconds]
ttamttam has joined #ocaml
joewilliams is now known as joewilliams_away
Gooffy has quit [Read error: Connection reset by peer]
Gooffy has joined #ocaml
nop has joined #ocaml
yakischloba has quit [Quit: Leaving.]
nop has quit [Ping timeout: 248 seconds]
ikaros has joined #ocaml
nop has joined #ocaml
ikaros has quit [Quit: Leave the magic to Houdini]
cygnus_ has quit [Ping timeout: 248 seconds]
avsm has joined #ocaml
Yoric has joined #ocaml
slash_ has joined #ocaml
Yoric has quit [Quit: Yoric]
_zack has joined #ocaml
seafood has joined #ocaml
seafood has quit [Client Quit]
valross has quit [Quit: Ex-Chat]
sgnb`` has joined #ocaml
nop_ has joined #ocaml
rbancrof1 has joined #ocaml
maskd- has joined #ocaml
nop has quit [*.net *.split]
maskd has quit [*.net *.split]
bjorkintosh has quit [*.net *.split]
rbancroft has quit [*.net *.split]
gim has quit [*.net *.split]
sgnb` has quit [*.net *.split]
_unK has joined #ocaml
tmaedaZ is now known as tmaeda
maskd- is now known as maskd
yziquel has quit [Ping timeout: 252 seconds]
mrvn has joined #ocaml
<mrvn>
Hi.
<quelqun_dautre>
hi.
<mrvn>
I have a little design problem. I have a C function that takes a callback as argument and returns. Sometime later it then calls the callback either with a success or with an error. I would like to throw an exception but how do I throw that into the callback?
<mrvn>
Should I use 2 callbacks or use a variant type to pass either the succes or exception?
execve has joined #ocaml
<fraggle_>
show us the source :)
<mrvn>
The source that doesn't exist because I don't know how to best write it?
<mrvn>
val read : context -> Unix.file_descr -> int64 -> Buffer.t -> (XXX -> unit) -> unit
<mrvn>
If the read succeeds the callback should get the Buffer.t back. If it fails then the Unix.error
<fraggle_>
it looks like a monad
<mrvn>
Async IO
jao has quit [Ping timeout: 256 seconds]
<Alpounet>
mrvn, do you really really want an exception ? 'cause you may use a type like : type 'a computation_that_can_fail = Error of string | Success of 'a
<Alpounet>
and indeed it's quite much in the monad spirit
<mrvn>
Yes I would like an exception.
<mrvn>
Makes it if only for the sake of learning how to do that.
<Alpounet>
mrvn, then I'd go for a variant type
<mrvn>
and then match res with Success buf -> ... | Fail exn -> raise exn ?
<fraggle_>
should do the trick indeed
<mrvn>
ugly
<Alpounet>
mrvn, yeah but with appropriate chaining functions and all, your code would be quite elegant
<fraggle_>
you want async I/O on string ?
<mrvn>
fraggle_: Only on Aio.Buffer.t, which is a page aligned Bigarray
<mrvn>
Ocaml strings can be moved by the GC so no async IO with them.
<fraggle_>
yep, and you use Buffer module to store them
<mrvn>
type t = private (int, int8_unsigned_elt, c_layout) Array1.t
<mrvn>
external create : int -> t = "caml_aio_buffer_create"
Asmadeus_ is now known as Asmadeus
<mrvn>
Need a special Bigarray for the alignment and you can't pass it a normal one.
<mrvn>
I also do truely evil things like: let buf = ((Obj.magic buf) : (int, int16_unsigned_elt, c_layout) Array1.t) in Array1.unsafe_get buf off
<mrvn>
That is what I'm doing and I don't care about portability to non linux.
<fraggle_>
you just want to map a C function to a OCaml one ?
<mrvn>
No. I want to have a nice interface.
fomatt has quit [Ping timeout: 252 seconds]
<fraggle_>
I really suggest using camlidl as a starting point to do the fisrt mapping
<fraggle_>
then refine the API
<mrvn>
camlidl won't help one bit in designing the api.
<fraggle_>
sure, but it's just to have a first code snippet
<mrvn>
already have the bindings. Except for the callback type basically.
<fraggle_>
ok I look to your code
Gooffy has quit [Quit: Leaving.]
Yoric has joined #ocaml
<fraggle_>
as far as i understand, all your callback are in C
<mrvn>
Not really. C doesn't have callbacks in the interface. It gives me an event that contains a pointer into my table of callbacks.
<mrvn>
// Get callback and buffer
<mrvn>
ml_fn = Field(ml_ctx, slot);
<mrvn>
ml_buf = Field(ml_ctx, slot + 1);
<fraggle_>
quite honestly, Alpounet's solution is the simplest way to implement want you want
<fraggle_>
s/want/what/
<mrvn>
type result = Result of Buffer.t | Errno of int | Partial of Buffer.t * int
<mrvn>
val read : context -> Unix.file_descr -> int64 -> Buffer.t -> (result -> unit) -> unit
<mrvn>
That is what I have now.
<mrvn>
Errno of int is suposed to become the Unix.error
<mrvn>
How do I specify an int64 as hex? 0x123456789abcdefLL seems wrong
<mrvn>
nm, too many L
<mrvn>
*grummel* Reading an int, int32 or int64 from my Buffer segfaults.
<mrvn>
Can't Obj.magic an int8 Bigarray to int32/int64
_unK has quit [Remote host closed the connection]
<mrvn>
I wonder what is faster now. Reading bytes and shifting them into int32/int64 in ocaml or a call that does it directly.
<Camarade_Tux>
anyone with some experience with FRP? I'm trying to decide if it fits what I need (reading on it right now): I have a set of tabs which is stored as a list and two keyboard shortcuts: ^t to create a new tab and ^w to close one, unfortunately, callbacks in lablgtk return a boolean but I need to return the updated list
tmaeda is now known as tmaedaZ
<Camarade_Tux>
would frp fit this?
<_zack>
thelema: JFYI, the homepage of batteries still points to 1.0.0, whereas 1.0.1 is out
<Camarade_Tux>
mehdid: I saw it but it has last been modified 3 years ago
<Camarade_Tux>
mehdid: also, there is an ocamlrt2 (mentionned on lambda-ultimate) but the link is dead and the author said he has stopped working on it
<mehdid>
ok
<Camarade_Tux>
I think I'll write something myself, not sure when though
<mrvn>
Camarade_Tux: another Do-It-Yourself guy. :)
yakischloba has joined #ocaml
<Camarade_Tux>
mrvn: unfortunately, yes: gives me much more work ;-)
<avsm>
thelema: what are the things with github you dont like?
ido has quit [Remote host closed the connection]
dark has quit [Remote host closed the connection]
avsm has quit [Quit: Leaving.]
<Camarade_Tux>
now, I have no idea how I'm going to make react and lablgtk work together :-)
<derdon>
Camarade_Tux: are you familiar with menus in LablGTK?
<derdon>
Camarade_Tux: and when I add the image buttons omitting factory, it will work?
<Camarade_Tux>
no idea :-)
<thelema>
The Itemfactory is much easier to use, and to add new menus to, although writing a few wrapper functions to create menus using the manual method could go a long way towards usability. With the Itemfactory, it is not possible to add images or the character '/' to the menus.
<thelema>
<from the page Camarade_Tux linked to>
<Camarade_Tux>
bah, should have seen it
<Camarade_Tux>
on the other hand, I removed firefox and since my browser isn't ready, I'm stuck without a "search" function :P
<derdon>
thelema: ah, I see
<derdon>
yeah, it works now :)
<derdon>
I love you guys!
<thelema>
glad to help
<derdon>
glad to be helped :)
<thelema>
now can you pre-emptively pass it on by... improving the ocaml-tutorial docs?
<Camarade_Tux>
:-)
<derdon>
thelema: not yet. still not experienced enough.
<derdon>
thelema: In addition, I work on the German translation
<thelema>
I don't buy the "not experienced" argument, but I'll let it slide this time. :)
<derdon>
well, it works :)
<derdon>
what about the "too much homework" argument?
<Camarade_Tux>
not experienced enough to be confident ;-)
<thelema>
get off IRC if you have too much homework. :)
<derdon>
thelema: you're right. but OCaml is much more fun
<thelema>
yes it is.
LionMade1fLions has left #ocaml []
LionMade1fLions has joined #ocaml
ttamttam has joined #ocaml
bjorkintosh has joined #ocaml
Yoric has quit [Quit: Yoric]
ttamttam has quit [Quit: Leaving.]
Leonidas has joined #ocaml
ikaros has joined #ocaml
nop has joined #ocaml
_unK has quit [Remote host closed the connection]
tty56 has quit [Quit: tty56]
Submarine has joined #ocaml
Submarine has quit [Read error: Connection reset by peer]
ikaros has quit [Quit: Leave the magic to Houdini]
Submarine has joined #ocaml
itewsh has quit [Quit: There are only 10 kinds of people: those who understand binary and those who don't]
derdon has quit [Quit: derdon]
Submarine has quit [Read error: Connection reset by peer]
ulfdoz has joined #ocaml
execve has quit [Ping timeout: 276 seconds]
DaveS has joined #ocaml
yakischloba has quit [Quit: Leaving.]
Yoric has joined #ocaml
derdon has joined #ocaml
nop has quit [Ping timeout: 252 seconds]
ccasin has joined #ocaml
ccasin has quit [Remote host closed the connection]