[education/rkward] rkward: Overallocate a bit on device struct

Thomas Friedrichsmeier null at kde.org
Fri May 10 17:04:24 BST 2024


Git commit 0d5f0b2e3f6ae20ec83abe7e630433222e7aa762 by Thomas Friedrichsmeier.
Committed on 10/05/2024 at 14:54.
Pushed by tfry into branch 'master'.

Overallocate a bit on device struct

M  +9    -0    rkward/autotests/core_test.cpp
M  +2    -1    rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp

https://invent.kde.org/education/rkward/-/commit/0d5f0b2e3f6ae20ec83abe7e630433222e7aa762

diff --git a/rkward/autotests/core_test.cpp b/rkward/autotests/core_test.cpp
index 30a726216..1bcdf48c8 100644
--- a/rkward/autotests/core_test.cpp
+++ b/rkward/autotests/core_test.cpp
@@ -363,6 +363,15 @@ private Q_SLOTS:
 		waitForAllFinished();  // priority_command_done must remain in scope until done
 	}
 
+	void RKDeviceTest() {
+		// Well, this test is sort of lame but should at least catch major breakage in RK() device
+		runCommandAsync(new RCommand("demo(graphics)", RCommand::User), nullptr, [](RCommand *command) {
+			QVERIFY(!command->failed());
+		});
+		RInterface::issueCommand(new RCommand("dev.off()", RCommand::User));
+		waitForAllFinished();  // priority_command_done must remain in scope until done
+	}
+
 	void restartRBackend() {
 		auto restart_action = RKWardMainWindow::getMain()->actionCollection()->action("restart_r");
 		QVERIFY(restart_action != nullptr);
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
index 8be6be5a5..b55e578b7 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_setup.cpp
@@ -64,7 +64,8 @@ void RKStartGraphicsDevice (double width, double height, double pointsize, const
 	{
 		RKRSupport::InterruptSuspension susp;
 		/* Allocate and initialize the device driver data */
-		dev = (pDevDesc) RFn::R_chk_calloc(1, sizeof(DevDesc));
+		const size_t allocsize = sizeof(DevDesc) + 256; // deliberately overallocating, in case later version of R try to write something, here
+		dev = (pDevDesc) RFn::R_chk_calloc(1, allocsize);
 		// NOTE: The call to RKGraphicsDeviceBackendTransmitter::instance(), here is important beyond error checking. It might *create* the instance and connection, if this is the first use.
 		if (!(dev && RKGraphicsDeviceBackendTransmitter::instance () && desc->init (dev, pointsize, family, bg))) {
 			RFn::R_chk_free(dev);



More information about the rkward-tracker mailing list