apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stein <gst...@lyra.org>
Subject Re: cvs commit: apr/threadproc/win32 proc.c
Date Mon, 27 Nov 2000 21:08:43 GMT
On Mon, Nov 27, 2000 at 11:28:52AM -0800, rbb@covalent.net wrote:
> On 27 Nov 2000, Karl Fogel wrote:
> > I'm curious -- how does it cause warnings to have a const in the
> > prototype of a function you're calling with non-const data?  It seems
> > odd to me that this would cause a problem... Perhaps there's something
> > else going on here?
> > 
> > I mean, we're writing the functions, and we know we're not going to
> > change that data, right?  
> We are asking for data that is const char * const *, but passing in
> char * const * data.  This causes incompatible pointer type warnings when
> compiling Apache.

I tried to get all of those changed. Where did I miss?

> > (Or is the issue that when we pass some of the data through to
> > execve() or whatever, it's making less strict promises than our
> > wrapper does, so we'd have to, ick, cast?)
> APR is actually not complaining, but it does seem a bit odd to me that we
> are asking for stricter access than the underlying functions we are
> using.

Those are using the "char * const *data" for historical purposes. Before
"const" came along, they were just "char **data". POSIX was able to change
that to "char * const *data" in a revision because that is "pointer
compatible" with historical usage. If they put the extra const in there,
then old programs would get warnings.

> One of the arguments made for this commit was that we may actually
> get const data, so we had better be sure that we treat it as const.  I
> disagree.  If we are given const data, then we have a problem, because
> POSIX doesn't state that the C Run-Time won't change the data underneath
> us.

Are you talking about the stuff getting changed when we call execve()? Or
do you mean argc/argv?

For the former: it better not change it. I've seen plenty of uses like this:

    char *args[5];
    args[0] = "diff";
    args[1] = "-u";
    args[2] = file1;
    args[3] = file2;
    args[4] = NULL;

If the CRT tried to change any of the strings, then you'd get a segfault
because those strings are in a readonly segment.

If you're referring to argc/argv, then "volatile" is the proper qualifier.

> We NEED to match POSIX in this, and require char *const * data.

No. We should have the semantics that work. And the lack of const fails for
the above example.

If we need to cast going into execve(), fine. That is under the covers of
our function's declaration. There isn't going to be a platform out there
that modifies what we pass in.


Greg Stein, http://www.lyra.org/

View raw message