From edd at debian.org  Thu May 11 13:29:50 2017
From: edd at debian.org (Dirk Eddelbuettel)
Date: Thu, 11 May 2017 06:29:50 -0500
Subject: [Rd] xrealloc namespace conflict
In-Reply-To: <59143A13.4090600@stern.nyu.edu>
References: <590DED69.30404@stern.nyu.edu>
	<59143A13.4090600@stern.nyu.edu>
Message-ID: <22804.19246.514394.430012@max.eddelbuettel.com>


On 11 May 2017 at 12:16, Patrick Perry wrote:
| I've done a bit more investigation into this issue. Here is my current 
| understanding of the situation:
| 
| 1. I have a package on CRAN (corpus-0.3.1) that passes tests on all 
| platforms except for Linux.
| 2. My package defines a C function, "xrealloc", for internal use.
| 3. The libreadline library that R links to defines a different version 
| of "xrealloc".
| 4. On Linux, when I load my package, references to "xrealloc" get linked 
| to the libreadline version of that function.
| 5. This causes one of my tests to fail, calling exit(2), because the 
| libreadline version of xrealloc does not allow calls of the form 
| "xrealloc(ptr, 0)".
| 
| I can work around this issue pretty easily, by either renaming my 
| version of xrealloc to something else, or by avoiding calls of the form 
| "xrealloc(ptr, 0)". So, this is not a major issue, but it's a little 
| unsettling to see this behavior when my package does not explicitly link 
| to or use anything from libreadline.
| 
| Is there a reason this behavior is only manifesting on Linux? Is there 
| something wrong with the way I'm compiling my package on that platform? 
| Is this just some quirk about the way R is loading dynamic libraries on 
| Linux? I'd appreciate any insight into the issue.

It may just be the flat namespace and linking order. AFAIK there is nothing
in C preventing so maybe you 'just got lucky' on the other platforms. See eg
http://stackoverflow.com/questions/7998770/

But then I don't use pure C that after anymore ... and in C++ you could just
wrap a namespace around your code, avoiding the issue.


Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



[Rd] xrealloc namespace conflict
Dirk Eddelbuettel