Re: [Rd] "warning: assignment discards qualifiers from pointer target type"

From: oliver <oliver_at_first.in-berlin.de>
Date: Thu, 09 Jun 2011 02:17:31 +0200

On Wed, Jun 08, 2011 at 02:23:29PM -0400, Simon Urbanek wrote:
>
> On Jun 8, 2011, at 12:08 PM, oliver wrote:
>
> > On Wed, Jun 08, 2011 at 12:22:10PM +0100, Prof Brian Ripley wrote:
> >> On Tue, 7 Jun 2011, Duncan Murdoch wrote:
> >>
> >>> On 07/06/2011 9:08 AM, oliver wrote:
> >>>> Hello,
> >>>>
> >>>> following an advice here from the list I looked into sources of other
> >>>> packages (xts) and found the TYPEOF() macro/function, which really is
> >>>> helpful.
> >>
> >> It is documented, of course, but actually better alternatives are
> >> described in 'Writing R Extensions'.
> >>
> >> We would urge you to study the R sources rather than copy bad habits
> >> from randomly chosen package sources.
> > [...]
> >
> > Hmhh, it was not randomly chosen, it was, what I got as a hint here on the list.
> >
>
> It was not provided to you to look at how it checks arguments. For basic
> usage it's better to look at the R code. The coding styles vary a lot in
> packages (and so does the quality of packages) - some of them are really bad,
> but you have to remember that most people write packages in their free time and
> are not programmers...

OK, I see.

[...]
> >> and there is no
> >> check in that code that LENGTH(filename_sexp) > 0 (or == 1). In the
> >> R sources you will often see things like
> >>
> >> if(!isString(sfile) || LENGTH(sfile) < 1)
> >> error("invalid '%s' argument", "description");
> > [...]
> >
> > If it's a vector, I can just pic the first element.
>
> Yes, but only if it's not a vector of length zero - hence the necessary check.
>
>
> > Or does LENGTH(sfile) give the length of the string itself
> > (like strlen(3))?
> >
>
> No.
[...]

OK, I looked at this now.

LENGTH() checks the length of the vector.

Good to know this.

So the problem of a vector of length 0 can be with any arguments of type SEXP, hence I will need to check ANY arg on it's length.

This is vital to stability under any situation.

Thanks for this valuable hint!

I will add checks for all my SEXP-args.

Ciao,

   Oliver



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 09 Jun 2011 - 00:20:43 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 09 Jun 2011 - 07:20:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive