[education/rkward] rkward: Remove some obsoleted workarounds

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


Git commit a1af8b7907c43c492484dbf9646b55475c48ac89 by Thomas Friedrichsmeier.
Committed on 10/05/2024 at 13:49.
Pushed by tfry into branch 'master'.

Remove some obsoleted workarounds

M  +5    -5    rkward/core/renvironmentobject.cpp
M  +1    -1    rkward/core/renvironmentobject.h
M  +3    -3    rkward/core/rkpseudoobjects.cpp
M  +3    -3    rkward/core/rkpseudoobjects.h
M  +2    -3    rkward/core/robject.cpp
M  +2    -2    rkward/core/robject.h
M  +1    -1    rkward/core/robjectlist.cpp
M  +1    -1    rkward/core/robjectlist.h
M  +0    -1    rkward/rbackend/rkrapi.h
M  +3    -19   rkward/rbackend/rkrbackend.cpp
M  +1    -3    rkward/rbackend/rkrbackendprotocol_backend.cpp
M  +1    -9    rkward/rbackend/rkstructuregetter.cpp

https://invent.kde.org/education/rkward/-/commit/a1af8b7907c43c492484dbf9646b55475c48ac89

diff --git a/rkward/core/renvironmentobject.cpp b/rkward/core/renvironmentobject.cpp
index cc620cf80..9a415476c 100644
--- a/rkward/core/renvironmentobject.cpp
+++ b/rkward/core/renvironmentobject.cpp
@@ -55,10 +55,10 @@ QString REnvironmentObject::getFullName (int options) const {
 
 	if (type & GlobalEnv) return name;	// .GlobalEnv
 	if ((type & ToplevelEnv) && (options & IncludeEnvirIfNotGlobalEnv)) return ("as.environment (" + rQuote (name) + ')');
-	return parent->makeChildName (name, type & Misplaced, options);
+	return parent->makeChildName(name, options);
 }
 
-QString REnvironmentObject::makeChildName (const QString &short_child_name, bool misplaced, int options) const {
+QString REnvironmentObject::makeChildName (const QString &short_child_name, int options) const {
 	RK_TRACE (OBJECTS);
 
 	QString safe_name;
@@ -77,8 +77,8 @@ QString REnvironmentObject::makeChildName (const QString &short_child_name, bool
 /* Some items are placed outside of their native namespace. E.g. in package:boot item "motor". It can be retrieved using as.environment ("package:boot")$motor. This is extremely ugly. We need to give them (and only them) this special treatment. */
 // TODO: hopefully one day operator "::" will work even in those cases. So check back later, and remove after a sufficient amount of backwards compatibility time
 // NOTE: This appears to have been fixed in R 2.14.0, when all packages were forced to have namespaces. Currently backend has a version check to set "misplaced", appropriately.
-		if ((type & PackageEnv) && (!misplaced)) return (packageName () + "::" + safe_name);
-		return (getFullName (options) + '$' + safe_name);
+		if (type & PackageEnv) return (packageName() + "::" + safe_name);
+		return (getFullName(options) + '$' + safe_name);
 	}
 	return (getFullName (options) + '$' + safe_name);
 }
@@ -168,7 +168,7 @@ void REnvironmentObject::updateNamespace (RData* new_data) {
 QString REnvironmentObject::renameChildCommand (RObject *object, const QString &new_name) const {
 	RK_TRACE (OBJECTS);
 
-	return (makeChildName (new_name, false, IncludeEnvirIfNotGlobalEnv) + " <- " + object->getFullName () + '\n' + removeChildCommand (object));
+	return (makeChildName(new_name, IncludeEnvirIfNotGlobalEnv) + " <- " + object->getFullName() + '\n' + removeChildCommand(object));
 }
 
 QString REnvironmentObject::removeChildCommand (RObject *object) const {
diff --git a/rkward/core/renvironmentobject.h b/rkward/core/renvironmentobject.h
index decb9d812..3981db18d 100644
--- a/rkward/core/renvironmentobject.h
+++ b/rkward/core/renvironmentobject.h
@@ -27,7 +27,7 @@ public:
 	virtual void updateFromR (RCommandChain *chain, const QStringList &added_symbols, const QStringList &removed_symbols);
 
 	QString getFullName (int) const override;
-	QString makeChildName (const QString &short_child_name, bool misplaced, int options) const override;
+	QString makeChildName(const QString &short_child_name, int options) const override;
 /** reimplemented from RContainerObject: If this is an environment var, call RContainerObject::writeMetaData (). Else, do nothing. An environment has no meta data. */
 	void writeMetaData (RCommandChain *chain) override;
 	QString packageName () const;
diff --git a/rkward/core/rkpseudoobjects.cpp b/rkward/core/rkpseudoobjects.cpp
index 8629e63fb..de5bcdc3a 100644
--- a/rkward/core/rkpseudoobjects.cpp
+++ b/rkward/core/rkpseudoobjects.cpp
@@ -28,7 +28,7 @@ QString RSlotsPseudoObject::getFullName (int options) const {
 	return (".rk.get.slots (" + parent->getFullName (options) + ')');
 }
 
-QString RSlotsPseudoObject::makeChildName (const QString &short_child_name, bool, int options) const {
+QString RSlotsPseudoObject::makeChildName(const QString &short_child_name, int options) const {
 	RK_TRACE (OBJECTS);
 
 	if (options & ExplicitSlotsExpansion) {
@@ -57,7 +57,7 @@ QString RKNamespaceObject::getFullName (int) const {
 	return ("asNamespace (" + rQuote (namespace_name) + ')');
 }
 
-QString RKNamespaceObject::makeChildName (const QString& short_child_name, bool, int) const {
+QString RKNamespaceObject::makeChildName(const QString& short_child_name, int) const {
 	RK_TRACE (OBJECTS);
 	QString safe_name = short_child_name;
 	if (irregularShortName (safe_name)) safe_name = rQuote (short_child_name);
@@ -84,7 +84,7 @@ QString RKOrphanNamespacesObject::getFullName (int) const {
 	return ("loadedNamespaces ()");
 }
 
-QString RKOrphanNamespacesObject::makeChildName (const QString& short_child_name, bool, int) const {
+QString RKOrphanNamespacesObject::makeChildName(const QString& short_child_name, int) const {
 	RK_TRACE (OBJECTS);
 	return ("asNamespace (" + rQuote (short_child_name) + ')');
 }
diff --git a/rkward/core/rkpseudoobjects.h b/rkward/core/rkpseudoobjects.h
index 01c75917a..4ab2392f9 100644
--- a/rkward/core/rkpseudoobjects.h
+++ b/rkward/core/rkpseudoobjects.h
@@ -26,7 +26,7 @@ public:
 	~RSlotsPseudoObject ();
 
 	QString getFullName (int) const override;
-	QString makeChildName (const QString &short_child_name, bool misplaced, int) const override;
+	QString makeChildName(const QString &short_child_name, int) const override;
 };
 
 /**
@@ -42,7 +42,7 @@ public:
 	~RKNamespaceObject ();
 
 	QString getFullName (int) const override;
-	QString makeChildName (const QString &short_child_name, bool misplaced, int) const override;
+	QString makeChildName(const QString &short_child_name, int) const override;
 	QString namespaceName () const { return namespace_name; };
 private:
 	QString namespace_name;
@@ -65,7 +65,7 @@ public:
 	~RKOrphanNamespacesObject ();
 
 	QString getFullName (int options) const override;
-	QString makeChildName (const QString &short_child_name, bool misplaced, int options) const override;
+	QString makeChildName(const QString &short_child_name, int options) const override;
 	QString getObjectDescription () const override;
 
 	RKNamespaceObject *findOrphanNamespace (const QString &name) const;
diff --git a/rkward/core/robject.cpp b/rkward/core/robject.cpp
index 186cf3d4c..21487e58a 100644
--- a/rkward/core/robject.cpp
+++ b/rkward/core/robject.cpp
@@ -121,7 +121,7 @@ bool RObject::irregularShortName (const QString &name) {
 
 QString RObject::getFullName (int options) const {
 	RK_TRACE (OBJECTS);
-	return parent->makeChildName (RObject::name, type & Misplaced, options);
+	return parent->makeChildName(RObject::name, options);
 }
 
 QString RObject::getLabel () const {
@@ -229,7 +229,7 @@ bool RObject::inherits (const QString &class_name) const {
 	return (classnames.contains (class_name));
 }
 
-QString RObject::makeChildName (const QString &short_child_name, bool, int options) const {
+QString RObject::makeChildName(const QString &short_child_name, int options) const {
 	RK_TRACE (OBJECTS);
 	if (options & DollarExpansion) {
 		if (irregularShortName (short_child_name)) return (getFullName (options) + '$' + rQuote (short_child_name));
@@ -437,7 +437,6 @@ bool RObject::updateType (RData *new_data) {
 	bool changed = false;
 	int new_type = new_data->intVector ().at (0);
 	if (type & PseudoObject) new_type |= PseudoObject;
-	if (type & Misplaced) new_type |= Misplaced;
 	if (type & Pending) new_type |= Pending;	// NOTE: why don't we just clear the pending flag, here? Well, we don't want to generate a change notification for this. TODO: rethink the logic, and maybe use an appropriate mask
 	if (type & NeedDataUpdate) new_type |= NeedDataUpdate;
 	if (type != new_type) {
diff --git a/rkward/core/robject.h b/rkward/core/robject.h
index 085318f4f..491e1bd81 100644
--- a/rkward/core/robject.h
+++ b/rkward/core/robject.h
@@ -49,7 +49,7 @@ public:
 		GlobalEnv=1 << 9,
 		ToplevelEnv=1 << 10,
 		PackageEnv=1 << 11,
-		Misplaced=1 << 12,		/** < the object is not in the namespace where it would be expected */
+//		Misplaced=1 << 12,		/** < the object is not in the namespace where it would be expected */
 		S4Object=1 << 13,
 		Numeric=1 << 14,
 		Factor=2 << 14,
@@ -228,7 +228,7 @@ public:
 	};
 
 /** generates a (full) name for a child of this object with the given name. */
-	virtual QString makeChildName (const QString &short_child_name, bool misplaced=false, int object_name_options=DefaultObjectNameOptions) const;
+	virtual QString makeChildName (const QString &short_child_name, int object_name_options=DefaultObjectNameOptions) const;
 protected:
 // why do I need those to compile? I thought they were derived classes!
 	friend class RContainerObject;
diff --git a/rkward/core/robjectlist.cpp b/rkward/core/robjectlist.cpp
index 5941b4f66..0d37ee4ee 100644
--- a/rkward/core/robjectlist.cpp
+++ b/rkward/core/robjectlist.cpp
@@ -314,7 +314,7 @@ bool RObjectList::updateStructure (RData *) {
 QString RObjectList::renameChildCommand (RObject *object, const QString &new_name) const {
 	RK_TRACE (OBJECTS);
 
-	return (makeChildName (new_name, false, IncludeEnvirIfNotGlobalEnv) + " <- " + object->getFullName () + '\n' + removeChildCommand (object));
+	return (makeChildName(new_name, IncludeEnvirIfNotGlobalEnv) + " <- " + object->getFullName() + '\n' + removeChildCommand(object));
 }
 
 QString RObjectList::removeChildCommand (RObject *object) const {
diff --git a/rkward/core/robjectlist.h b/rkward/core/robjectlist.h
index 5c6d68c10..e92eb142a 100644
--- a/rkward/core/robjectlist.h
+++ b/rkward/core/robjectlist.h
@@ -42,7 +42,7 @@ public:
 	void updateFromR (RCommandChain *chain, const QStringList &current_searchpath, const QStringList &current_namespaces);
 	
 	QString getFullName (int) const override { return QString (); };
-	QString makeChildName (const QString &short_child_name, bool, int) const override { return short_child_name; };
+	QString makeChildName(const QString &short_child_name, int) const override { return short_child_name; };
 	/** reimplemented from RContainerObject: do nothing. The object-list has no meta data. */
 	void writeMetaData (RCommandChain *) override {};
 
diff --git a/rkward/rbackend/rkrapi.h b/rkward/rbackend/rkrapi.h
index b768ad94d..ede2cb0e1 100644
--- a/rkward/rbackend/rkrapi.h
+++ b/rkward/rbackend/rkrapi.h
@@ -211,7 +211,6 @@ IMPORT_R_API(R_chk_free);
 IMPORT_R_API(R_dot_Last);
 IMPORT_R_API(R_getEmbeddingDllInfo);
 IMPORT_R_API(R_lsInternal3);
-IMPORT_R_API(Rprintf); // currently unused
 IMPORT_R_API(R_registerRoutines);
 IMPORT_R_API(R_removeVarFromFrame);
 IMPORT_R_API(R_tryEval);
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index 372bcc450..f34ec9502 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -1263,20 +1263,6 @@ SEXP runCommandInternalBase (SEXP pr, RKRBackend::RKWardRError *error) {
 		*error = RKRBackend::NoError;
 	}
 
-// actually, the code inside this #if worked up to R 2.15.x.
-// see the corresponding #if in runCommand
-#if R_VERSION < R_Version(2,13,0)
-	// for safety, let's protect exp for the two print calls below.
-	// TODO: this is not good. It causes an additional RFn::Rf_protect and URFn::Rf_protect. Need to (re-)move printing
-	RFn::Rf_protect (exp);
-	/* Do NOT ask me why, but the line below is needed for warnings to be printed, while otherwise they would not be shown.
-	Apparently we need to print at least something in order to achieve this. Whatever really happens in Rprintf () to have such an effect, I did not bother to find out. */
-	RFn::Rprintf((char *) "");
-
-	RFn::Rf_PrintWarnings();
-
-	RFn::Rf_unprotect (1);		// exp; We unprotect this, as most of the time the caller is not really interested in the result
-#endif
 	return exp;
 }
 
@@ -1336,14 +1322,12 @@ void RKRBackend::runCommand (RCommandProxy *command) {
 		if (error == NoError) {
 			RFn::Rf_protect (parsed);
 			SEXP exp;
-#if R_VERSION >= R_Version(2,13,0)
-			int warn_level = RKRSupport::SEXPToInt (RFn::Rf_GetOption1(RFn::Rf_install("warn")), 0);
+			// Make sure any warning arising during the command actually get assuciated with it (rather than getting printed, after the next user command)
+			int warn_level = RKRSupport::SEXPToInt(RFn::Rf_GetOption1(RFn::Rf_install("warn")), 0);
 			if (warn_level != 1) setWarnOption (1);
-#endif
 			RFn::Rf_protect (exp = runCommandInternalBase (parsed, &error));
-#if R_VERSION >= R_Version(2,13,0)
 			if (warn_level != 1) setWarnOption (warn_level);
-#endif
+
 			if (error == NoError) {
 				if (ctype & RCommand::GetStringVector) {
 					command->setData (RKRSupport::SEXPToStringList (exp));
diff --git a/rkward/rbackend/rkrbackendprotocol_backend.cpp b/rkward/rbackend/rkrbackendprotocol_backend.cpp
index b34888fd8..6b14ad58f 100644
--- a/rkward/rbackend/rkrbackendprotocol_backend.cpp
+++ b/rkward/rbackend/rkrbackendprotocol_backend.cpp
@@ -120,14 +120,12 @@ SPDX-License-Identifier: GPL-2.0-or-later
 		// this token is sent both via stdout and the local socket connection. The frontend simply compares both values.
 		QString token = QUuid::createUuid ().toString ();
 
-		// TODO: Should rather take the libname from CMake
-		// maybe we also want to accept an absolute path specified on command line from the frontend
 #ifdef RK_DLOPEN_LIBRSO
 		RFn::init(libr_dll_handle, dlsym_fun);
 #endif
 
 		RKRBackendTransmitter transmitter (servername, token);
-		RKRBackendProtocolBackend::p_transmitter = &transmitter; // cppcheck-suppress danlingReference ; -> valid for the lifetime of the backend
+		RKRBackendProtocolBackend::p_transmitter = &transmitter; // cppcheck-suppress danglingReference ; -> valid for the lifetime of the backend
 		RKRBackendProtocolBackend backend (data_dir, rkd_server_name);
 		transmitter.start ();
 		RKRBackend::this_pointer->run (locale_dir);
diff --git a/rkward/rbackend/rkstructuregetter.cpp b/rkward/rbackend/rkstructuregetter.cpp
index 22fa717a2..8a107bdc1 100644
--- a/rkward/rbackend/rkstructuregetter.cpp
+++ b/rkward/rbackend/rkstructuregetter.cpp
@@ -378,15 +378,7 @@ void RKStructureGetter::getStructureWorker (SEXP val, const QString &name, int a
 				SEXP child = RFn::Rf_findVar (current_childname, value);
 				RFn::Rf_protect (child);
 
-				bool child_misplaced = false;
-				if (at_toplevel && with_namespace && (!RKRBackend::this_pointer->RRuntimeIsVersion (2, 14, 0))) {
-					if (!RFn::Rf_isNull (namespace_envir)) {
-						SEXP dummy = RFn::Rf_findVarInFrame(namespace_envir, current_childname);
-						if (RFn::Rf_isNull (dummy) || (dummy == ROb(R_UnboundValue))) child_misplaced = true;
-					}
-				}
-
-				getStructureSafe (child, childnames[i], child_misplaced ? RObject::Misplaced : 0, children[i], nesting_depth + 1);
+				getStructureSafe (child, childnames[i], 0, children[i], nesting_depth + 1);
 				RFn::Rf_unprotect (2); /* current_childname, child */
 			}
 		} else if (do_cont) {



More information about the rkward-tracker mailing list