Skip to content

Commit b69fc3b

Browse files
author
Pavel Marek
committed
RStringVecNativeData accesses its data via NativeDataAccess
(cherry picked from commit 2d89c39)
1 parent 3307480 commit b69fc3b

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/NativeDataAccess.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,34 +1121,8 @@ static int getDataLength(RStringVector vector, Object[] data) {
11211121
}
11221122
}
11231123

1124-
static String getData(RStringVector vector, Object data, int index) {
1125-
if (noStringNative.isValid() || data != null) {
1126-
Object localData = data;
1127-
if (localData instanceof String[]) {
1128-
return ((String[]) localData)[index];
1129-
}
1130-
assert data instanceof CharSXPWrapper[] : localData;
1131-
assert ((CharSXPWrapper[]) localData)[index] != null;
1132-
return ((CharSXPWrapper[]) localData)[index].getContents();
1133-
} else {
1134-
return getStringNativeMirrorData(vector.getNativeMirror(), index).getContents();
1135-
}
1136-
}
1137-
1138-
static void setData(RStringVector vector, Object data, int index, String value) {
1139-
assert data != null;
1140-
if (data instanceof String[]) {
1141-
assert !vector.isNativized();
1142-
((String[]) data)[index] = value;
1143-
} else {
1144-
assert data instanceof CharSXPWrapper[] : data;
1145-
CharSXPWrapper elem = CharSXPWrapper.create(value);
1146-
((CharSXPWrapper[]) data)[index] = elem;
1147-
1148-
if (!noStringNative.isValid() && vector.isNativized()) {
1149-
NativeDataAccess.setNativeMirrorStringData(vector.getNativeMirror(), index, elem);
1150-
}
1151-
}
1124+
static CharSXPWrapper getData(RStringVector vector, int index) {
1125+
return getStringNativeMirrorData(vector.getNativeMirror(), index);
11521126
}
11531127

11541128
static void setData(RStringVector vector, CharSXPWrapper[] data, int index, CharSXPWrapper value) {

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RStringVecNativeData.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public class RStringVecNativeData implements TruffleObject, ShareableVectorData
4646

4747
/**
4848
* After nativized, the data array degenerates to a reference holder, which prevents the objects
49-
* from being GC'ed. If the native code copies data of one string vector to another without
49+
* from being GC'ed. This means that if someone changes the order of the CHARSXP elements on the native
50+
* side, this modification is not reflected in this reference holder array.
51+
*
52+
* If the native code copies data of one string vector to another without
5053
* using the proper API, we are doomed.
5154
*/
5255
private final CharSXPWrapper[] data;
@@ -140,32 +143,32 @@ public RandomAccessIterator randomAccessIterator() {
140143

141144
@ExportMessage
142145
public String getStringAt(int index) {
143-
return NativeDataAccess.getData(vec, null, index);
146+
return NativeDataAccess.getData(vec, index).getContents();
144147
}
145148

146149
@ExportMessage
147150
public String getNextString(SeqIterator it) {
148-
return NativeDataAccess.getData(vec, null, it.getIndex());
151+
return NativeDataAccess.getData(vec, it.getIndex()).getContents();
149152
}
150153

151154
@ExportMessage
152155
public String getString(@SuppressWarnings("unused") RandomAccessIterator it, int index) {
153-
return NativeDataAccess.getData(vec, null, index);
156+
return NativeDataAccess.getData(vec, index).getContents();
154157
}
155158

156159
@ExportMessage
157160
public CharSXPWrapper getCharSXPAt(int index) {
158-
return data[index];
161+
return NativeDataAccess.getData(vec, index);
159162
}
160163

161164
@ExportMessage
162165
public CharSXPWrapper getNextCharSXP(SeqIterator it) {
163-
return data[it.getIndex()];
166+
return NativeDataAccess.getData(vec, it.getIndex());
164167
}
165168

166169
@ExportMessage
167170
public CharSXPWrapper getCharSXP(@SuppressWarnings("unused") RandomAccessIterator it, int index) {
168-
return data[index];
171+
return NativeDataAccess.getData(vec, index);
169172
}
170173

171174
// Write access to the elements:
@@ -197,16 +200,16 @@ public void setString(@SuppressWarnings("unused") RandomAccessWriteIterator it,
197200

198201
@ExportMessage
199202
public void setCharSXPAt(int index, CharSXPWrapper value) {
200-
data[index] = value;
203+
NativeDataAccess.setData(vec, data, index, value);
201204
}
202205

203206
@ExportMessage
204207
public void setNextCharSXP(SeqWriteIterator it, CharSXPWrapper value) {
205-
data[it.getIndex()] = value;
208+
NativeDataAccess.setData(vec, data, it.getIndex(), value);
206209
}
207210

208211
@ExportMessage
209212
public void setCharSXP(@SuppressWarnings("unused") RandomAccessWriteIterator it, int index, CharSXPWrapper value) {
210-
data[index] = value;
213+
NativeDataAccess.setData(vec, data, index, value);
211214
}
212215
}

0 commit comments

Comments
 (0)