Skip to content

Commit 0b8f647

Browse files
author
luke
committed
Add DATAPTR_RW for use in ALTREP Dataptr methods.
git-svn-id: https://svn.r-project.org/R/trunk@89022 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 0d41de4 commit 0b8f647

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

doc/manual/R-exts.texi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14969,14 +14969,15 @@ iteration strategy.
1496914969
Some functions useful in implementing new alternate representation
1497014970
classes, beyond those defined in @file{R_ext/Altrep.h}, include
1497114971
@code{ALTREP}, @code{ALTREP_CLASS}, @code{R_altrep_data1},
14972-
@code{R_set_altrep_data1}, @code{R_altrep_data2}, and
14973-
@code{R_set_altrep_data2}.
14972+
@code{R_set_altrep_data1}, @code{R_altrep_data2},
14973+
@code{R_set_altrep_data2}, and @code{DATAPTR_RW}.
1497414974
@eapifun ALTREP
1497514975
@eapifun ALTREP_CLASS
1497614976
@eapifun R_altrep_data1
1497714977
@eapifun R_set_altrep_data1
1497814978
@eapifun R_set_altrep_data2
1497914979
@eapifun R_altrep_data2
14980+
@eapifun DATAPTR_RW
1498014981
@eapihdr R_ext/Altrep.h
1498114982

1498214983
For some objects it may be possible to very efficiently determine
@@ -17497,8 +17498,11 @@ functions that should be used instead:
1749717498
@itemx DATAPTR
1749817499
@itemx STDVEC_DATAPTR
1749917500
Use @code{STRING_PTR_RO} and @code{DATAPTR_RO}. Obtaining
17500-
writable pointers to these data can violate the memory manager's
17501-
integrity assumptions and is not supported.
17501+
writable pointers to these data can violate the memory manager's
17502+
integrity assumptions and is not supported.
17503+
One exception is that a writable pointer may need to be returned
17504+
by an @code{ALTREP} @code{Dataptr} method. The function
17505+
@code{DATAPTR_RW} can use for this purpose.
1750217506
@item isFrame
1750317507
Use @code{Rf_isDataFrame}, added in @R{} 4.5.0.
1750417508
@item BODY
@@ -17742,6 +17746,10 @@ void CLEAR_ATTRIB(SEXP x)
1774217746
UNSET_S4_OBJECT(x);
1774317747
@}
1774417748
#endif
17749+
17750+
#if R_VERSION < R_Version(4, 6, 0)
17751+
# define DATAPTR_RW(x) DATAPTR(x)
17752+
#endif
1774517753
@end example
1774617754

1774717755

src/include/R_ext/Altrep.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ DECLARE_METHOD_SETTER(altstring, No_NA)
172172
DECLARE_METHOD_SETTER(altlist, Elt)
173173
DECLARE_METHOD_SETTER(altlist, Set_elt)
174174

175+
/* DATAPTR_RW is declared here since it should only be used to
176+
implement Dataptr methods. */
177+
void *DATAPTR_RW(SEXP);
178+
175179
#ifdef __cplusplus
176180
}
177181
#endif

src/main/altclasses.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ static void *compact_intseq_Dataptr(SEXP x, Rboolean writeable)
183183
SET_COMPACT_SEQ_EXPANDED(x, val);
184184
UNPROTECT(1);
185185
}
186-
return DATAPTR(COMPACT_SEQ_EXPANDED(x));
186+
return DATAPTR_RW(COMPACT_SEQ_EXPANDED(x));
187187
}
188188

189189
static const void *compact_intseq_Dataptr_or_null(SEXP x)
190190
{
191191
SEXP val = COMPACT_SEQ_EXPANDED(x);
192-
return val == R_NilValue ? NULL : DATAPTR(val);
192+
return val == R_NilValue ? NULL : DATAPTR_RO(val);
193193
}
194194

195195
static int compact_intseq_Elt(SEXP x, R_xlen_t i)
@@ -428,13 +428,13 @@ static void *compact_realseq_Dataptr(SEXP x, Rboolean writeable)
428428
SET_COMPACT_SEQ_EXPANDED(x, val);
429429
UNPROTECT(1);
430430
}
431-
return DATAPTR(COMPACT_SEQ_EXPANDED(x));
431+
return DATAPTR_RW(COMPACT_SEQ_EXPANDED(x));
432432
}
433433

434434
static const void *compact_realseq_Dataptr_or_null(SEXP x)
435435
{
436436
SEXP val = COMPACT_SEQ_EXPANDED(x);
437-
return val == R_NilValue ? NULL : DATAPTR(val);
437+
return val == R_NilValue ? NULL : DATAPTR_RO(val);
438438
}
439439

440440
static double compact_realseq_Elt(SEXP x, R_xlen_t i)
@@ -759,13 +759,13 @@ static R_INLINE void expand_deferred_string(SEXP x)
759759
static void *deferred_string_Dataptr(SEXP x, Rboolean writeable)
760760
{
761761
expand_deferred_string(x);
762-
return DATAPTR(DEFERRED_STRING_EXPANDED(x));
762+
return DATAPTR_RW(DEFERRED_STRING_EXPANDED(x));
763763
}
764764

765765
static const void *deferred_string_Dataptr_or_null(SEXP x)
766766
{
767767
SEXP state = DEFERRED_STRING_STATE(x);
768-
return state != R_NilValue ? NULL : DATAPTR(DEFERRED_STRING_EXPANDED(x));
768+
return state != R_NilValue ? NULL : DATAPTR_RO(DEFERRED_STRING_EXPANDED(x));
769769
}
770770

771771
static SEXP deferred_string_Elt(SEXP x, R_xlen_t i)
@@ -1528,7 +1528,7 @@ static R_xlen_t wrapper_Length(SEXP x)
15281528
static void *wrapper_Dataptr(SEXP x, Rboolean writeable)
15291529
{
15301530
if (writeable)
1531-
return DATAPTR(WRAPPER_WRAPPED_RW(x));
1531+
return DATAPTR_RW(WRAPPER_WRAPPED_RW(x));
15321532
else
15331533
/**** could avoid the cast by having separate methods */
15341534
return (void *) DATAPTR_RO(WRAPPER_WRAPPED(x));

src/main/memory.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,6 +4160,9 @@ void *(STDVEC_DATAPTR)(SEXP x)
41604160
return STDVEC_DATAPTR(x);
41614161
}
41624162

4163+
/* nedded for implementing Dataptr ALTREP methods */
4164+
void *DATAPTR_RW(SEXP x) { return DATAPTR(x); }
4165+
41634166
int *(LOGICAL)(SEXP x) {
41644167
if(TYPEOF(x) != LGLSXP)
41654168
error("%s() can only be applied to a '%s', not a '%s'",

0 commit comments

Comments
 (0)