Skip to content

Commit

Permalink
refs #3179 std::string COW issue workaround (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnich authored and sejvlond committed Dec 13, 2018
1 parent d4cd289 commit 43697b3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doxygen/lang/900_release_notes.dox.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
- Command line utils display source line code when interrupted

@subsection qore_09_bug_fixes Bug Fixes in Qore
- worked around a potential COW bug in \c std::string in GNU libdstdc++ 6+
(<a href="https://github.com/qorelanguage/qore/issues/3179">issue 3179</a>)
- fixed a bug with simple additional and subtraction with mixed @ref timeout_type "timeout" and
@ref date_type "date" values; updated docs that arithmetic operations with timeout values are not recommended
and can return unexpected values in some situations
Expand Down
18 changes: 18 additions & 0 deletions examples/test/qore/misc/issue3179/issue3179.qm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%new-style
%require-types
%strict-args
%enable-all-warnings

module issue3179 {
version = "1.0";
desc = "issue 3179 test";
author = "Qore Technologies, s.r.o.";
url = "https://qore.org";
license = "MIT";
}

public class Disappear {
static string get() {
return "str";
}
}
40 changes: 40 additions & 0 deletions examples/test/qore/misc/issue3179/issue3179.qtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env qore

%new-style
%require-types
%strict-args
%enable-all-warnings

%requires ../../../../../qlib/Util.qm
%requires ../../../../../qlib/QUnit.qm
%requires ./issue3179.qm

%requires reflection

%exec-class Issue3179Test

class Issue3179Test inherits QUnit::Test {
constructor() : QUnit::Test("Issue3179Test", "1.0") {
addTestCase("issue 3179", \issue3179());

set_return_value(main());
}

issue3179() {
for (int i = 0; i < 3; ++i) {
doTest();
}
}

private doTest() {
Program p(PO_NO_INHERIT_USER_CLASSES);
p.importClass("Disappear");
p.parse("string sub get() { return Disappear::get(); }", "");
assertEq("str", p.callFunction("get"));
assertEq("str", Disappear::get());

Class cls = Class::forName("Disappear");
AbstractMethod m = cls.findMethod("get").method;
assertEq("Disappear", m.getClass().getName());
}
}
3 changes: 2 additions & 1 deletion lib/QoreClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ qore_class_private::qore_class_private(QoreClass* n_cls, std::string&& nme, int6

// only called while the parse lock for the QoreProgram owning "old" is held
qore_class_private::qore_class_private(const qore_class_private& old, qore_ns_private* ns, QoreProgram* spgm, const char* new_name, bool inject, const qore_class_private* injectedClass)
: name(new_name ? new_name : old.name),
// issue #3179: we force a deep copy of "name" to work around COW issues with std::string with GNU libstdc++ 6+
: name(new_name ? new_name : old.name.c_str()),
ns(ns),
ahm(old.ahm),
constlist(old.constlist, 0, this), // committed constants
Expand Down

0 comments on commit 43697b3

Please sign in to comment.