[Caml-list] Gtk text printing

2011-08-16 Thread 郭骁
I decided to use OCaml and GTK+ in my recent project. Everything seemed to be OK, but I found that seemingly there is no way of printing.The application should be able to print some text reports in win32 environment. So I use google to search possible solutions: http://www.google.com.hk/url?s

[Caml-list] Re: Interfacing with C: bad practice

2011-08-16 Thread Jeffrey Scofield
Gerd Stolpmann writes: > I don't know for SML, but OCaml also leaves the order unspecified in > which function arguments are evaluated (and ocamlc and ocamlopt behave > even differently in this respect). So I think the problem would > translate to OCaml in some form. This is a good point. A pro

Re: [Caml-list] Re: Interfacing with C: bad practice

2011-08-16 Thread Gerd Stolpmann
Am Dienstag, den 16.08.2011, 11:55 -0500 schrieb Jeffrey Scofield: > (One great thing about the ML family is that there > are exceptionally clear answers to questions like this. > Especially for Standard ML.) I don't know for SML, but OCaml also leaves the order unspecified in which function argum

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread rixed
-[ Tue, Aug 16, 2011 at 05:10:42PM +0100, Richard W.M. Jones ] > Nevertheless, the C compiler isn't allowed to just push 'list' blindly > onto the stack and assume it doesn't change across the call to > 'caml_copy_string'. For me, wrp_ml_cons(caml_copy_string(*s), list); with caml_copy

Re: [Caml-list] Re: Interfacing with C: bad practice

2011-08-16 Thread Will M. Farr
An aside: In case people want to crib the language, the Racket (formerly PLT Scheme) manual contains a warning about exactly this problem in the appended text (Section 3.1.2 of the "Inside: Racket C API" at http://docs.racket-lang.org/inside/im_memoryalloc.html#(part._im~3a3m~3astack) ). It sh

[Caml-list] Re: Interfacing with C: bad practice

2011-08-16 Thread Jeffrey Scofield
Török Edwin writes: > But isn't this 'f(g(), x)' issue the same as the classic example > of undefined behaviour with f(++i, ++i)? It's not quite the same, because a function call (g()) introduces a sequence point. In the f(++i, ++i) case, I think there's only a sequence point after the call to

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Richard W.M. Jones
On Tue, Aug 16, 2011 at 07:34:31PM +0300, Török Edwin wrote: > Undefined behaviour doesn't mean it must show different results with -O2, > it *might* if the compiler decides to do some optimization. > > But isn't this 'f(g(), x)' issue the same as the classic example of undefined > behaviour with

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Török Edwin
On 08/16/2011 07:27 PM, Richard W.M. Jones wrote: > Grrr now _my_ program has a bug. > > -- > #include > #include > > void f (int a, int b); > int g (void); > int *global = NULL; > > int > main (void) > { > int x = 1; > gl

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread malc
On Tue, 16 Aug 2011, Richard W.M. Jones wrote: > Grrr now _my_ program has a bug. > FWIW i have asked Richard Henderson to share his opinion and he found nothing wrong with memory.h and/or the OP's code, and believes it's a compiler bug. [..snip..] -- mailto:av1...@comtv.ru -- Caml-list mai

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Richard W.M. Jones
Grrr now _my_ program has a bug. -- #include #include void f (int a, int b); int g (void); int *global = NULL; int main (void) { int x = 1; global = &x; f (g (), x); exit (0); } void f (int a, int b) { printf ("a =

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Richard W.M. Jones
On Tue, Aug 16, 2011 at 08:18:48PM +0400, Dmitry Bely wrote: > On Tue, Aug 16, 2011 at 8:10 PM, Richard W.M. Jones wrote: > > > Well it would certainly help if we had a piece of runnable code to > > look at.  The code supplied in the original email contains an infinite > > loop. > > Yes, that wa

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
On Tue, Aug 16, 2011 at 8:10 PM, Richard W.M. Jones wrote: > Well it would certainly help if we had a piece of runnable code to > look at.  The code supplied in the original email contains an infinite > loop. Yes, that was my mistake that I corrected later. The loop should be for (; *s != NULL

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Richard W.M. Jones
On Tue, Aug 16, 2011 at 05:10:42PM +0100, Richard W.M. Jones wrote: > Well it would certainly help if we had a piece of runnable code to > look at. The code supplied in the original email contains an infinite > loop. I missed there was another email later that contains the fixed code (s++). I'm

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Wojciech Meyer
On Tue, Aug 16, 2011 at 5:06 PM, John Carr wrote: > > Richard W.M. Jones wrote: > > > On Tue, Aug 16, 2011 at 11:37:03AM +0400, Dmitry Bely wrote: > > > C compiler first puts "list" pointer on stack and then calls > > > caml_copy_string(*s), potentially invalidating "list". Of course, the > > >

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
On Tue, Aug 16, 2011 at 7:25 PM, Richard W.M. Jones wrote: > On Tue, Aug 16, 2011 at 11:37:03AM +0400, Dmitry Bely wrote: >> C compiler first puts "list" pointer on stack and then calls >> caml_copy_string(*s), potentially invalidating "list". Of course, the >> stack copy of "list" is not register

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Richard W.M. Jones
On Tue, Aug 16, 2011 at 05:51:38PM +0200, ri...@happyleptic.org wrote: > -[ Tue, Aug 16, 2011 at 04:25:50PM +0100, Richard W.M. Jones ] > > I think this must be a bug in your C compiler. The address of list is > > stashed in the roots struct, so the C compiler should know that list > > can be

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread John Carr
Richard W.M. Jones wrote: > On Tue, Aug 16, 2011 at 11:37:03AM +0400, Dmitry Bely wrote: > > C compiler first puts "list" pointer on stack and then calls > > caml_copy_string(*s), potentially invalidating "list". Of course, the > > stack copy of "list" is not registered as a global root so wrp_m

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Will M. Farr
Yes. The C compiler can see that the address of list has been passed to external functions in CAMLlocal, so has to assume the worst: that the address is stored in some global variable, and caml_copy_string or the functions it calls can access it and thereby change the value of list. If the com

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread rixed
-[ Tue, Aug 16, 2011 at 04:25:50PM +0100, Richard W.M. Jones ] > I think this must be a bug in your C compiler. The address of list is > stashed in the roots struct, so the C compiler should know that list > can be changed by the call to caml_copy_string. Are you certain that the C abstract m

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Richard W.M. Jones
On Tue, Aug 16, 2011 at 11:37:03AM +0400, Dmitry Bely wrote: > C compiler first puts "list" pointer on stack and then calls > caml_copy_string(*s), potentially invalidating "list". Of course, the > stack copy of "list" is not registered as a global root so wrp_ml_cons > gets an invalid value. I th

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread John Carr
Mauricio Fernandez wrote: > This has been in my mind for a while: why don't CAMLparamX declare the local > variables as volatile? That would not help. Passing the address of a local variable to an external function warns the compiler that the variable may change when another external function

[Caml-list] New release of the Caml Examples collection

2011-08-16 Thread pierre . weis
[Version française ci-dessous] The Caml Examples package is a large set of Caml example programs. Most of the programs are provided both in Objective Caml and in Caml Light. This new enhanced version of the Caml Examples package contains the complete set of examples from the book ``Le langage Cam

[Caml-list] Re: Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
On Tue, Aug 16, 2011 at 11:37 AM, Dmitry Bely wrote: (...) >    while (*s != NULL) { >        list = wrp_ml_cons(caml_copy_string(*s), list); /* bug! */ >    } Ah, s increment is missing. The loop should be written as for (; *s != NULL; s++) { list = wrp_ml_cons(caml_copy_string(*s),

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread rixed
-[ Tue, Aug 16, 2011 at 01:17:28PM +0300, Török Edwin ] > So a best practice would be to always use a temporary variable > registered with CAMLlocal* when you call a function that can potentially > invoke the GC? I would say the best practive would be to not call an allocating function from a

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Mauricio Fernandez
On Tue, Aug 16, 2011 at 01:21:02PM +0400, Dmitry Bely wrote: > On Tue, Aug 16, 2011 at 12:57 PM, Christophe TROESTLER > wrote: > > On Tue, 16 Aug 2011 11:37:03 +0400, Dmitry Bely wrote: > >> In the line > >> > >>         list = wrp_ml_cons(caml_copy_string(*s), list); /* bug! */ > >> > > Let me e

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Török Edwin
On 08/16/2011 12:53 PM, Dmitry Bely wrote: > On Tue, Aug 16, 2011 at 1:46 PM, wrote: >> -[ Tue, Aug 16, 2011 at 11:43:24AM +0300, Török Edwin ] >>> 'list' should be reachable via caml_local_roots, so if it really gets an >>> invalid value >>> it sounds like a bug to me. >> >> list may not be

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
On Tue, Aug 16, 2011 at 1:46 PM, wrote: > -[ Tue, Aug 16, 2011 at 11:43:24AM +0300, Török Edwin ] >> 'list' should be reachable via caml_local_roots, so if it really gets an >> invalid value >> it sounds like a bug to me. > > list may not be garbage collected (since it is indeed registered a

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread rixed
-[ Tue, Aug 16, 2011 at 11:43:24AM +0300, Török Edwin ] > 'list' should be reachable via caml_local_roots, so if it really gets an > invalid value > it sounds like a bug to me. list may not be garbage collected (since it is indeed registered as the root), but it may be moved arround (ie promo

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
On Tue, Aug 16, 2011 at 12:57 PM, Christophe TROESTLER wrote: > On Tue, 16 Aug 2011 11:37:03 +0400, Dmitry Bely wrote: >> >> I would like to share my experience of writing bad C bindings. The >> following code is wrong, although no "living in harmony with the >> garbage collector" rule seems to be

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Török Edwin
On 08/16/2011 11:25 AM, Dmitry Bely wrote: > 2011/8/16 Török Edwin : >> On 08/16/2011 10:37 AM, Dmitry Bely wrote: >>> I would like to share my experience of writing bad C bindings. The >>> following code is wrong, although no "living in harmony with the >>> garbage collector" rule seems to be viol

Re: [Caml-list] Questions about default instances

2011-08-16 Thread Sébastien Furic
Hello Jacques, Le 08/08/2011 09:14, Jacques Garrigue a écrit : On 2011/08/05, at 1:22, Sébastien Furic wrote: What is the usual way in OCaml to define mutually recursive classes that share default instances? There is no concept of "default instance" in OCaml, and as you discovered yoursel

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
2011/8/16 Török Edwin : > On 08/16/2011 10:37 AM, Dmitry Bely wrote: >> I would like to share my experience of writing bad C bindings. The >> following code is wrong, although no "living in harmony with the >> garbage collector" rule seems to be violated: >> >> value wrp_ml_cons (value v, value l)

Re: [Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Török Edwin
On 08/16/2011 10:37 AM, Dmitry Bely wrote: > I would like to share my experience of writing bad C bindings. The > following code is wrong, although no "living in harmony with the > garbage collector" rule seems to be violated: > > value wrp_ml_cons (value v, value l) > { > CAMLparam2(v, l); >

[Caml-list] Interfacing with C: bad practice

2011-08-16 Thread Dmitry Bely
I would like to share my experience of writing bad C bindings. The following code is wrong, although no "living in harmony with the garbage collector" rule seems to be violated: value wrp_ml_cons (value v, value l) { CAMLparam2(v, l); CAMLlocal1(cell); cell = caml_alloc_small(2, Tag_cons);

[Caml-list] [ANNOUNCE] llpp v7

2011-08-16 Thread malc
Hello, New version of llpp is now available (tagged v7) at http://repo.or.cz/w/llpp.git Blurb: llpp a graphical PDF viewer which aims to superficially resemble less(1) Changes (relative to v5): * Human readable/editable configuration file * Optional (default on) proportional display (for docum