Fix crash in c_copy_struct R testcase

Workaround initialises additional members in the A struct when created
using new(A) as opposed to created with A().
Probably the typemaps for int etc should be fixed to not crash if the
input is not initialised though.
This commit is contained in:
William S Fulton 2025-04-19 16:20:17 +01:00
parent 5c4007267a
commit b16a7c958a
1 changed files with 5 additions and 0 deletions

View File

@ -46,6 +46,11 @@ la <- new("A");
la@ui <- as.integer(5)
# Removing the next line makes this fail in R 2.4
la@str <- ""
# The next two need initialising from R 4.5 onwards to avoid a segfault in
# R_swig_A_i_set/R_swig_A_d_set when copyToC() is called.
# TODO: how to check they are not initialised in C? - Rf_isInteger seems to succeed.
la@i <- as.integer(-6)
la@d <- as.double(1.2)
other = A()
foo <- copyToC(la, other)