Skip to content

Commit f3d254c

Browse files
authored
Unexpected Output from delete from array (#700)
Changed how the non-flat array gets copied from the CopySubarray function. The changes are done for non-flat type arrays and for flat type it's still the same. I have used what we have for elementType->CopyData so that a proper copy(deep copy) happens.
1 parent 265b8c9 commit f3d254c

File tree

4 files changed

+110
-12
lines changed

4 files changed

+110
-12
lines changed

source/core/Array.cpp

+28-12
Original file line numberDiff line numberDiff line change
@@ -1201,15 +1201,31 @@ VIREO_FUNCTION_SIGNATURET(ArrayMaxMinInternal, FindArrayMaxMinInstruction)
12011201
}
12021202
// NOLINT(runtime/references)
12031203
static void CopySubArray(AQBlock1* &sourcePtr, AQBlock1* &destinationPtr, // NOLINT(runtime/references)
1204-
const UInt32 elementSize, const size_t elementsToCopy)
1204+
const size_t elementsToCopy, TypedArrayCoreRef arraySource, TypedArrayCoreRef arrayDest)
12051205
{
1206-
if (elementsToCopy) {
1207-
size_t bytesToCopy = elementsToCopy * elementSize;
1208-
if (destinationPtr) {
1209-
memmove(destinationPtr, sourcePtr, bytesToCopy);
1210-
sourcePtr += bytesToCopy, destinationPtr += bytesToCopy;
1211-
} else {
1212-
sourcePtr += bytesToCopy;
1206+
NIError err = kNIError_Success;
1207+
TypeRef elementType = arraySource->ElementType();
1208+
if (elementType->IsFlat()) {
1209+
if (elementsToCopy) {
1210+
size_t bytesToCopy = elementsToCopy * elementType->TopAQSize();
1211+
if (destinationPtr) {
1212+
memmove(destinationPtr, sourcePtr, bytesToCopy);
1213+
sourcePtr += bytesToCopy, destinationPtr += bytesToCopy;
1214+
} else {
1215+
sourcePtr += bytesToCopy;
1216+
}
1217+
}
1218+
} else {
1219+
IntIndex stride = elementType->TopAQSize();
1220+
IntIndex count = elementsToCopy;
1221+
for (Int32 i = 0; i < count; i++) {
1222+
err = elementType->CopyData(sourcePtr, destinationPtr);
1223+
if (err != kNIError_Success) {
1224+
arrayDest->Resize1D(0);
1225+
break;
1226+
}
1227+
sourcePtr += stride;
1228+
destinationPtr += stride;
12131229
}
12141230
}
12151231
}
@@ -1316,11 +1332,11 @@ VIREO_FUNCTION_SIGNATURE7(ArrayDeleteND, TypedArrayCoreRef, StaticType, void,
13161332
size_t numberOfElementsToBeDeleted = deletedPortionLength * numberOfElementsInDeletedDimension;
13171333
size_t numberOfElementsAfterDeleted = (dimensionSize[dimensionToDelete]
13181334
- (startIndex + deletedPortionLength)) * numberOfElementsInDeletedDimension;
1319-
Int32 currentDimension;
1335+
Int32 currentDimension;
13201336
do {
1321-
CopySubArray(inputArrayPtr, outputArrayPtr, elementSize, numberOfElementsBeforeDeleted);
1322-
CopySubArray(inputArrayPtr, deletedArrayPtr, elementSize, numberOfElementsToBeDeleted);
1323-
CopySubArray(inputArrayPtr, outputArrayPtr, elementSize, numberOfElementsAfterDeleted);
1337+
CopySubArray(inputArrayPtr, outputArrayPtr, numberOfElementsBeforeDeleted, arrayIn, arrayOut);
1338+
CopySubArray(inputArrayPtr, deletedArrayPtr, numberOfElementsToBeDeleted, arrayIn, deletedArray);
1339+
CopySubArray(inputArrayPtr, outputArrayPtr, numberOfElementsAfterDeleted, arrayIn, arrayOut);
13241340
currentDimension = dimensionToDelete;
13251341
while (--currentDimension >= 0 && ++index[currentDimension] >= dimensionSize[currentDimension])
13261342
index[currentDimension] = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Loop no - 1
2+
Input 4D Array of String
3+
(((('a1' 'a2' 'a3' 'a4') ('b1' 'b2' 'b3' 'b4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
4+
Deleted Array
5+
((('b1' 'b2' 'b3' 'b4')))
6+
Output Array
7+
(((('a1' 'a2' 'a3' 'a4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
8+
Loop no - 2
9+
Input 4D Array of String
10+
(((('a1' 'a2' 'a3' 'a4') ('b1' 'b2' 'b3' 'b4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
11+
Deleted Array
12+
((('b1' 'b2' 'b3' 'b4')))
13+
Output Array
14+
(((('a1' 'a2' 'a3' 'a4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
15+
Loop no - 3
16+
Input 4D Array of String
17+
(((('a1' 'a2' 'a3' 'a4') ('b1' 'b2' 'b3' 'b4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
18+
Deleted Array
19+
((('b1' 'b2' 'b3' 'b4')))
20+
Output Array
21+
(((('a1' 'a2' 'a3' 'a4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
define (WebApp%3A%3Aindex%2Egviweb dv(.VirtualInstrument (
2+
Locals: c( // Data Space
3+
e(dv(.String 'WebApp::index.gviweb')local0)
4+
ce(dv(.Int32 3)c1)
5+
ce(dv(.Int32 0)c2)
6+
e(.Int32 local3)
7+
e(.Int32 local4)
8+
ce(dv(.Int32 10)c5)
9+
e(.UInt32 local6)
10+
ce(dv(.Int32 1)c7)
11+
ce(dv(a(.String * * * *) (((('a1' 'a2' 'a3' 'a4' )('b1' 'b2' 'b3' 'b4' )('c1' 'c2' 'c3' 'c4' )('d1' 'd2' 'd3' 'd4' )('e1' 'e2' 'e3' 'e4' )('f1' 'f2' 'f3' 'f4' )('g1' 'g2' 'g3' 'g4' )))))c8)
12+
e(a(.String * * * *) local9)
13+
e(a(.String * * *) local10)
14+
de(a(.String * * *) dataItem_DeletedPortion)
15+
e(a(.String * * *) local12)
16+
de(a(.String * * * *) dataItem_ArrayWithSubsetDeleted)
17+
e(a(.String * * * *) local14)
18+
e(.UInt32 local15)
19+
e(.Boolean local16)
20+
ce(dv(.Int32 0)c17)
21+
e(dv(.Int32 2)local18)
22+
)
23+
clump(1
24+
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#12##WebApp;}" c1)
25+
IsGE(c2 c1 local16)
26+
BranchIfTrue(1 local16)
27+
Branch(2)
28+
Perch(2)
29+
Copy(c17 local3)
30+
Copy(c1 local4)
31+
Perch(3)
32+
Convert(c5 local6)
33+
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#23d77726c0714674bcf64c1054667ee4##WebApp;}" c5 c7 c8)
34+
ArrayDelete(local9 local10 c8 * c7 local18 )
35+
Copy(local10 dataItem_DeletedPortion)
36+
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#110262b5adda4912928eedd243f5bf67##WebApp;}" local9 local10)
37+
Copy(local9 dataItem_ArrayWithSubsetDeleted)
38+
WaitMilliseconds(local6 * )
39+
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#58099fec38a94a8297cf980d7e70ae5a##WebApp;}" )
40+
Increment(local3 local3 )
41+
Printf("Loop no - ")
42+
Printf("%d\n" local3)
43+
Println("Input 4D Array of String")
44+
Println(c8)
45+
Println("Deleted Array")
46+
Println(dataItem_DeletedPortion)
47+
Println("Output Array")
48+
Println(dataItem_ArrayWithSubsetDeleted)
49+
BranchIfGE(4 local3 local4)
50+
Branch(3)
51+
Perch(4)
52+
Branch(0)
53+
Perch(1)
54+
Branch(0)
55+
Perch(0)
56+
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#e9c42849feb046fabc82ca61e2684d21##WebApp;}" )
57+
/* Clump Ended. */ )
58+
)))
59+
enqueue (WebApp%3A%3Aindex%2Egviweb)
60+
//Finished!! :D

test-it/testList.json

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"ArrayDelete.via",
111111
"ArrayDeleteFail.via",
112112
"ArrayDeleteFail2.via",
113+
"ArrayDeleteMultiDimensionString.via",
113114
"ArrayDemo.via",
114115
"ArrayFillNDV.via",
115116
"ArrayFillNDVFail.via",

0 commit comments

Comments
 (0)