From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 77145BBAF for ; Fri, 11 Jul 2008 12:21:51 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsACAGnRdkiBXvIYgWdsb2JhbACEUY1eAQEQIFGcfw X-IronPort-AV: E=Sophos;i="4.30,344,1212357600"; d="scan'208";a="27232639" Received: from note.orchestra.cse.unsw.edu.au ([129.94.242.24]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Jul 2008 12:21:49 +0200 Received: From [IPv6???1] ([129.94.242.130] == pill00.orchestra.cse.unsw.EDU.AU) (ident-user sseefried) (cse-authentic-sender sseefried) By note With Smtp ; Fri, 11 Jul 2008 20:21:46 +1000 From: Sean Seefried To: Richard Jones Date: Fri, 11 Jul 2008 20:21:45 +1000 Cc: caml-list@yquem.inria.fr Message-Id: In-Reply-To: <20080711094050.GB24400@annexia.org> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v924) Subject: Re: [Caml-list] Heaps size problems with "caml_alloc_small" in foreign function interfaces References: <20080711094050.GB24400@annexia.org> X-Mailer: Apple Mail (2.924) X-Spam: no; 0.00; alloc:01 alloc:01 allocations:01 wosize:01 camlidl:01 verbose:01 initialized:01 segfault:01 bug:01 malloc:01 bug:01 ocaml:01 garbage:01 garbage:01 wrote:01 On 11/07/2008, at 7:40 PM, Richard Jones wrote: > On Fri, Jul 11, 2008 at 06:21:51PM +1000, Sean Seefried wrote: >> I'm having a problem where sometimes a call to "caml_alloc_small" >> from >> C results in a segmentation fault. If I increase the size of the >> stack >> using OCAMLRUNPARAM=s=1000k then I don't get the crash anymore. It >> seems strange that I have to increase the size of the heap manually >> like this. Is this because I'm calling this function from C? > > Seems like you have confusion over heap & stack. > > First of all, caml_alloc_small is limited to small allocations, so > number of words allocated must be <= Max_young_wosize. You don't post > any example code so we can't see whether that is true in your code. > caml_alloc_small(32,0); is what seemed to cause the problem. I'm shying away from posting more code since it is auto-generated from CamlIDL and is very verbose. I didn't write it myself. > Secondly (and much more likely to be the problem), the caml_alloc* > functions allocate uninitialised memory. If the garbage collector What do you mean by "uninitialised memory"? > gets to run before you've properly initialized all the fields then the > GC will hit an uninitialised field and a segfault could be the result. > > eg: This is a fail: > > v = caml_alloc (2, 0); > vv = caml_alloc (3, 0); /* GC could run here */ > Store_field (v, 0, vv); > What do you do about this? Is there a way to stop the GC from running for a period of time? > Changing the _stack_ size (or other tunables) probably just changes > something about when the garbage collector runs, and thus moves the > bug around. > >> If I want to increase the size of the heap in C how do I do this? >> Could I write a "safe" caml_alloc_small which first checks to see if >> there is enough memory and then increases the heap size if not? > > The "size of the heap in C" is (for most operating systems) extended > automatically by malloc. What you're saying here isn't necessary - > you must have some other bug. > I wasn't very clear but I meant changing the OCaml heap size using C functions. Sean