[Rd] "warning: assignment discards qualifiers from pointer target type"
oliver at first.in-berlin.de
Thu Jun 9 02:17:31 CEST 2011
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))?
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.
More information about the R-devel