fix wrong delete of user_data in gda 71/18971/2
Antoine ELIAS [Thu, 26 Jan 2017 14:50:29 +0000 (15:50 +0100)]
Change-Id: Ib9a150a48b5838c9b5cd9e25f6d1f2680084502f

scilab/modules/graphic_objects/src/cpp/createGraphicObject.cpp
scilab/modules/graphic_objects/tests/unit_tests/gda_userdata.tst [new file with mode: 0644]

index cd1f4c8..98fd49d 100644 (file)
@@ -118,7 +118,18 @@ int createNewFigureWithAxes()
     if (iUserDataSize != 0)
     {
         int* pUserData = NULL;
+
         getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+
+        if (sizeof(void*) == 4) //32 bits
+        {
+            increaseValRef(NULL, (int*)* (int*)pUserData);
+        }
+        else //64 bits
+        {
+            increaseValRef(NULL, (int*)* (long long*)pUserData);
+        }
+
         setGraphicObjectProperty(getCurrentSubWin(), __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
     }
 
diff --git a/scilab/modules/graphic_objects/tests/unit_tests/gda_userdata.tst b/scilab/modules/graphic_objects/tests/unit_tests/gda_userdata.tst
new file mode 100644 (file)
index 0000000..5413eb0
--- /dev/null
@@ -0,0 +1,31 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2017 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- NO CHECK REF -->
+
+// check gda user_data and resulting gca user_data
+
+d = gda();
+d.user_data = "test";
+assert_checkequal(d.user_data, "test");
+
+a1=gca();
+assert_checkequal(a1.user_data, "test");
+
+xdel(winsid());
+assert_checkequal(d.user_data, "test");
+
+a1 = gca();
+assert_checkequal(a1.user_data, "test");
+
+d.user_data = "test 2";
+assert_checkequal(d.user_data, "test 2");
+assert_checkequal(a1.user_data, "test");
+scf();
+a2 = gca();
+assert_checkequal(a2.user_data, "test 2");
+xdel(winsid());