From: "Justin Lenzo" <j-lenzo@northwestern.edu>
To: gsl-discuss@sourceware.org
Subject: Re: containers tentative design summary
Date: Fri, 20 Nov 2009 09:37:00 -0000 [thread overview]
Message-ID: <58694.129.105.199.222.1258660264.squirrel@129.105.199.222> (raw)
> At Thu, 29 Oct 2009 17:40:30 -0400,
> James Bergstra wrote:
> > If the purpose is to protect the user from accidentally messing around
> > with data then, as Gerard suggests, maybe we shouldn't bother. This
> > is not a battle that we can win in C. Good naming conventions for
> > functions, which indicate the arguments that will be modified, is the
> > most that a C library is expected to provide.
>
> The purpose is to make programs safer, rather than provide any hints
> for optimisation. The current system is type-safe and gives a
> "discarding const" compiler warning if people try to pass const
> objects to functions as non-const arguments - these seem like useful
> features. It's not clear to me what the actual benefit would be if we
> only had non-const vectors and matrices.
>
What if you went with a structure like the following:
typedef struct {
const double *data;
double *wdata;
...
} gsl_vector;
When a gsl_vector is allocated, the array is attached to 'wdata' and
aliased to 'data'. When a read-only vector view is made, it returns a
new instance of the gsl_vector datatype where the 'data' and other
members are copied over, but sets 'wdata' to NULL. Basically, you
would be allowing the same datatype to cover allocated vectors,
read-write views, and read-only views. It seems to me this achieves
the goal of protecting underlying read-only data, as long as your
willing to check for NULL pointers in the routines that write to a
vector. I don't know anything about the security implications, so
forgive me if this is a dangerous approach.
next reply other threads:[~2009-11-20 9:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-20 9:37 Justin Lenzo [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-11-03 19:44 Gerard Jungman
2009-11-09 20:41 ` Brian Gough
2009-11-09 23:06 ` Gerard Jungman
2009-11-14 15:25 ` Brian Gough
2009-11-15 9:13 ` Tuomo Keskitalo
2009-11-15 16:44 ` Jonathan Underwood
2009-11-15 18:41 ` Robert G. Brown
2009-11-16 11:56 ` Brian Gough
2009-10-05 10:12 Gerard Jungman
2009-10-05 14:50 ` James Bergstra
2009-10-05 23:00 ` Gerard Jungman
2009-10-05 23:45 ` James Bergstra
2009-10-06 19:59 ` Gerard Jungman
[not found] ` <645d17210910060537s762d6323pfd2bec8590ad28e9@mail.gmail.com>
2009-10-06 20:02 ` Gerard Jungman
2009-10-23 21:28 ` Brian Gough
2009-10-27 23:06 ` Gerard Jungman
[not found] ` <7f1eaee30910271628h70785125m68e47c7a7b5c25b7@mail.gmail.com>
2009-10-27 23:49 ` Gerard Jungman
2009-10-29 18:06 ` Brian Gough
2009-10-29 20:41 ` Gerard Jungman
2009-10-29 21:40 ` James Bergstra
2009-10-30 16:54 ` Brian Gough
2009-10-30 16:54 ` Brian Gough
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=58694.129.105.199.222.1258660264.squirrel@129.105.199.222 \
--to=j-lenzo@northwestern.edu \
--cc=gsl-discuss@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).