From tom@@@k@||ber@ @end|ng |rom gm@||@com  Thu Apr  7 09:32:03 2022
From: tom@@@k@||ber@ @end|ng |rom gm@||@com (Tomas Kalibera)
Date: Thu, 7 Apr 2022 09:32:03 +0200
Subject: [Rd] calloc() vs. R_Calloc()
In-Reply-To: <CAJ=0CtBMDXf4R0DR40whvXS5i8=KUrPRqbZWC-TWWeU2DfzQjw@mail.gmail.com>
References: <CAJ=0CtBMDXf4R0DR40whvXS5i8=KUrPRqbZWC-TWWeU2DfzQjw@mail.gmail.com>
Message-ID: <f57301d8-c736-34af-29b1-c59d9458b180@gmail.com>


On 4/7/22 08:59, Adrian Du?a wrote:
> Dear R devs,
>
> I ran into a C level problem that hopefully is a quick fix to a trained eye.
>
> Not sure if I am able to produce a minimal reproducible example, but
> suppose a (test) package passes all the local tests, passes the R CMD check
> and also passes the tests on both rhub and https://win-builder.r-project.org
>
> The test GitHub repo is here:
> https://github.com/dusadrian/QCAtest
>
> As per the latest CRAN recommendation, I need to replace calloc() and
> free() with R's Calloc() and Free(). In the above repo, the latest commit
> does not pass the tests any longer, and the absolute single difference is
> using the recommended commands in the file:
> https://github.com/dusadrian/QCAtest/blob/main/src/CCubes.c
>
> The previous initial commit of this file (which has no problems) is here:
> https://github.com/dusadrian/QCAtest/blob/5fb13f44457a2071b322ad42ab579f3547d1c551/src/CCubes.c
>
> There must be something obvious I'm doing wrong, perhaps a header missing
> or not in the right place, but it just escapes me.
> I've tried both Calloc() and R_Calloc(), both versions result in the same
> errors.

And what are the errors you run into? On which platforms, under what 
circumstances, etc? It would be much easier to give advice knowing that.

In principle, one issue you may run into when switching allocators is 
that you accidentally end up freeing by a different allocator from the 
one used to allocate it. It is common on Windows but can in principle 
happen elsewhere as well.

Also by a slightly different heap layout or different allocator 
implementation you may wake up bugs in the program not seen previously 
(use after free, invalid memory accesses, etc)

Tomas

>
> Many thanks in advance for any hint,
> Adrian
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] calloc() vs. R_Calloc()
Tomas Kalibera