From jeroen.ooms at stat.ucla.edu  Wed May 25 13:23:34 2016
From: jeroen.ooms at stat.ucla.edu (Jeroen Ooms)
Date: Wed, 25 May 2016 13:23:34 +0200
Subject: [Rd] Suggestion: mkString(NULL) should be NA
In-Reply-To: <22341.32520.155909.439980@stat.math.ethz.ch>
References: <CABFfbXt7raZDRaGP+T=XWKeBZq8oh88FRh8+Xj7jFkf_VFspsA@mail.gmail.com>
	<CABFfbXu0LTrSy9Qq5mouq6fX=nN=NF9xshtM8Q9khYn3cWtEQw@mail.gmail.com>
	<CADwqtCP2O7zUSJ3BHvYbkD25EyJPyj9LhdazJf5UzELVW1_9-w@mail.gmail.com>
	<CABFfbXtUHYepH93PZrYktNbFfNX-Y8iF5Pk6DYOgUFk=MGK7pA@mail.gmail.com>
	<CADwqtCNLmskyk1v_syjGeH6H4tnLTAkihKh8c0gHuc7nHDqpDQ@mail.gmail.com>
	<22341.32520.155909.439980@stat.math.ethz.ch>
Message-ID: <CABFfbXtVi09hpKc-FbgWBbPkJrU1V2bNdsTHqBEdxFK2rfmpog@mail.gmail.com>

On Wed, May 25, 2016 at 12:31 PM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
> Better than segfaulting, yes, but really agree with Bill (and
> Gabe), also for Rf_mkChar(NULL):
> I think both functions should give an error in such a case
> rather than returning NA_character_
>
> It is an accident of some kind if they got NULL, no?

Not necessarily. A char* of NULL can be a string which is not
initiated or simply unavailable due to configuration.

The example from my original email was in curl package which exposes
the version string of libz that was used to build libcurl:

  mkString(data->libz_version)

This worked on all platforms that I tested. However a user found that
if libcurl was configured --without-libz (which is uncommon) the
libz_version string does not get set by libcurl and is always NULL. I
had not foreseen this and it would lead to a segfault.

I think making mkString() return NA for null strings lead to the most
robust behavior. Raising an exception seems a little harsh to me, as
there is no way the user would be able to recover from this, and there
might not be an actual problem at all.



[Rd] Suggestion: mkString(NULL) should be NA
Jeroen Ooms