caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Segfault using malloc within stubs
@ 2005-02-06 14:05 julius
  2005-02-08 17:51 ` Damien Doligez
  2005-02-08 18:42 ` art yerkes
  0 siblings, 2 replies; 4+ messages in thread
From: julius @ 2005-02-06 14:05 UTC (permalink / raw)
  To: caml-list

Actually, this is just un exemple that illustrates the real function I 
used. We can add some use of the test pointer and result value but it 
changes nothing: in this function you can't do anything that someway 
malloc the test pointer.
As you say it's very weird and much disapointing :)

Julius

PS: In my implementation, test is given to a function that use it to 
stock its result (after malloc it), and result is a caml value pointing 
to some calculus result. The end is same: segfault...

Remi Vanicat wrote:

> On Sun, 06 Feb 2005 08:38:06 +0100, julius <flute@noos.fr> wrote:
>  
>
>> Hello,
>>
>> I have this strange problem with my stubs, I wrote this function but it
>> leads to a segfault:
>>
>> CAMLprim value foo(value v)
>> {
>>    CAMLparam1(v);
>>    CAML(result);
>>    char** test;
>>
>>    test=(char**)malloc(4*sizeof(char*));
>>    CAMLreturn(result);
>> }
>>
>> After much tests, it seems that malloc is not allowed when using Caml
>> data types or when trying to register data to the ocaml garbage
>> collector... But I don't understand why as C heap and OCaml heap are
>> distinct :-/
>>   
>
>
> It seem weird. First of all, mallocs are explicitly allowed in the
> doc. So the problem must be somewhere else. I see that in this code,
> the test pointer is never used, but throw away, and this could lead to
> a memory leak. Also the result variable is never set, so this is
> probably the problem. Try to add a result=Val_unit; somewhere in your
> code to see if the problem goes away. I forget : I don't know what
> CAML(result) mean. Did you want to use CAML_local1(result) ? may be
> this is the problem.
>
>
>  
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Segfault using malloc within stubs
  2005-02-06 14:05 [Caml-list] Segfault using malloc within stubs julius
@ 2005-02-08 17:51 ` Damien Doligez
  2005-02-08 18:42 ` art yerkes
  1 sibling, 0 replies; 4+ messages in thread
From: Damien Doligez @ 2005-02-08 17:51 UTC (permalink / raw)
  To: caml users

On Feb 6, 2005, at 15:05, julius wrote:

> Actually, this is just un exemple that illustrates the real function I 
> used. We can add some use of the test pointer and result value but it 
> changes nothing: in this function you can't do anything that someway 
> malloc the test pointer.
> As you say it's very weird and much disapointing :)

Except for the "CAML" macro that doesn't exist and the uninitialized 
value
of the "result" variable, your code is correct.  The bug must be within
the part that you removed.

-- Damien


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Segfault using malloc within stubs
  2005-02-06 14:05 [Caml-list] Segfault using malloc within stubs julius
  2005-02-08 17:51 ` Damien Doligez
@ 2005-02-08 18:42 ` art yerkes
  1 sibling, 0 replies; 4+ messages in thread
From: art yerkes @ 2005-02-08 18:42 UTC (permalink / raw)
  To: julius; +Cc: caml-list

On Sun, 06 Feb 2005 15:05:29 +0100
julius <flute@noos.fr> wrote:

> Actually, this is just un exemple that illustrates the real function I 
> used. We can add some use of the test pointer and result value but it 
> changes nothing: in this function you can't do anything that someway 
> malloc the test pointer.
> As you say it's very weird and much disapointing :)
> 
> Julius
> 
> PS: In my implementation, test is given to a function that use it to 
> stock its result (after malloc it), and result is a caml value pointing 
> to some calculus result. The end is same: segfault...
> 

If you like, you can give SWIG a chance to create this interface for you.
try http://www.swig.org/
-- 
Here's a simple experiment. Stand on a train track between two locomotives
which are pushing on you with equal force in opposite directions. You will
exhibit no net motion. None the less, you may soon begin to notice that
something important is happening.
-- Robert Stirniman


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Segfault using malloc within stubs
@ 2005-02-25  0:36 Garry Belka
  0 siblings, 0 replies; 4+ messages in thread
From: Garry Belka @ 2005-02-25  0:36 UTC (permalink / raw)
  To: caml-list

In our case the problem was in an interaction of interface definition 
and run-time system, so to say.

The memory we were allocating within stub was described as an Ocaml 
string, and so Ocaml was trying to check its size at first access, and 
failing with segfault.
As soon as we defined access functions for the string based on 
unsafe_get instead of naively using x.(i) notation, we stopped seeing
Segfault. Other option it to compile code with -unsafe turned on.

Garry


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-02-25  0:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-06 14:05 [Caml-list] Segfault using malloc within stubs julius
2005-02-08 17:51 ` Damien Doligez
2005-02-08 18:42 ` art yerkes
2005-02-25  0:36 Garry Belka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).