Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "David McClain" <dmcclain1@mindspring.com>
To: "caml" <caml-list@inria.fr>
Subject: [Caml-list] OCaml 3.08 and Bus Errors
Date: Mon, 2 Aug 2004 00:43:01 -0700	[thread overview]
Message-ID: <009b01c47864$5a3e46b0$0201a8c0@dylan> (raw)

... in going back over my sources from 5 years ago, it appears that at one
time I was trying (perhaps too hard) to outsmart the internals of OCaml. I
regret having to do this, but bear with me one moment...

I was avoiding declaring CAMLparamN() of input arguments in many cases
because I was attempting to gain a unified access to both of OCaml native
Arrays of double, and my own FastArray implementation which predates the
BigArray stuff. The only time it appeared necessary to declare an input
parameter is when some OCaml allocation could occur, and where we need to
track the possible relocation of those parameters as a result of a triggered
GC cycle.

But if I were completely finished accessing these parameters by the time an
OCaml allocation occurred, then I could care less where these parameters had
possibly been relocated. The caller of my C routines still have live
pointers to these parameters and so they form valid memory roots for GC.
Hence, GC does not need my CAMLparam's to find the system roots, it merely
offers through these macros to allow me to find them again should I need to
after some GC may have relocated them.

In my case with my FastArrays I dare not put them in these CAMLparam macros
because the arena pointer to the FastArray doubles array is not a valid
OCaml structure address, and so I don't want GC pounding on them. These
addresses are external to the OCaml heap, and so I guess OCaml would ignore
them anyway. I was playing fast and loose on purpose here because native
OCaml arrays of doubles do pass the address of their own arena. My C
routines have uniform access to the arena of both kinds of arrays.

I realized there is risk involved in using raw external pointers, especially
as the OCaml heap grows and eventually occupies the same region these
pointers once did. But that can't happen until these pointers are
invalidated and reclaimed anyway.

In looking at BigArray as a possible alternative to my FastArrays, I see
that the address passed for such arguments is much like a Custom block and
reaching the arena requires a special offsetting access from the passed
argument address. Hence these cannot be used interchangeably with normal
arrays of double.

I like the idea of moving back away from taking advantage of special
internal knowledge, since that ensures a greater lifetime to my code.
However, it still appears problematic to do so at this time...

In retrospect, it appears that the bus errors may have been caused by a
failed call to my Berkeley DBMS wrappers while the filename string was still
alive and perhaps still in use. Not sure just yet. This is one case where I
should have, and did, put CAMLparam wrappers on that filename string
argument and the Bus Errors subsequently went away.

But wholesale wrapping of all arguments to C glue routines is really not
warranted, and requires careful consideration of when these parameters will
be accessed in the code, and when OCaml heap allocations will occur. Only
those pointers that are both valid, and still live at the time of allocation
need protection by these CAMLparam wrappers.

Do I understand the situation correctly? Or has something more fundamental
changed in 3.08?

David McClain
Senior Corporate Scientist
Avisere, Inc.

+1.520.390.7738 (USA)
david.mcclain@avisere.com



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2004-08-02  7:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-02  7:43 David McClain [this message]
2004-08-06 12:09 ` Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='009b01c47864$5a3e46b0$0201a8c0@dylan' \
    --to=dmcclain1@mindspring.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox