[Scummvm-git-logs] scummvm master -> 786aac568b966c0c68940e2ba2b065b318a56795

sev- sev at scummvm.org
Sat Oct 3 13:51:22 UTC 2020


This automated email contains information about 6 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
27030c7029 CONFIGURE: Add cxx11 feature
3180891045 PETKA: Add cxx11 as a dependency
f1ed89e5a3 CONFIGURE: Define USE_CXX11 when c++11 is enabled
a275522f89 COMMON: Add list initialization and move semantics to Array
2eccd9aa8c DEVTOOLS: Add cxx11 feature to create_project
786aac568b COMMON: Add c++11 initializer list replacement when not available in std lib


Commit: 27030c70296c678c40cf04982f6f2a409ec600fe
    https://github.com/scummvm/scummvm/commit/27030c70296c678c40cf04982f6f2a409ec600fe
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-10-03T15:51:14+02:00

Commit Message:
CONFIGURE: Add cxx11 feature

The idea is that engines that want to use c++11 can specify it as
a dependency in their configure.engine file so that the engine
is automatically disabled when c++11 is not available.

Changed paths:
    configure


diff --git a/configure b/configure
index 08c0d79bb2..d5316f0cd8 100755
--- a/configure
+++ b/configure
@@ -267,6 +267,7 @@ add_feature vorbis "Vorbis file support" "_vorbis _tremor"
 add_feature zlib "zlib" "_zlib"
 add_feature lua "lua" "_lua"
 add_feature fribidi "FriBidi" "_fribidi"
+add_feature cxx11 "c++11" "_use_cxx11"
 add_feature test_cxx11 "Test C++11" "_test_cxx11"
 
 # Directories for installing ScummVM.


Commit: 31808910456b649e3471a515b3d155488e310550
    https://github.com/scummvm/scummvm/commit/31808910456b649e3471a515b3d155488e310550
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-10-03T15:51:14+02:00

Commit Message:
PETKA: Add cxx11 as a dependency

Changed paths:
    engines/petka/configure.engine


diff --git a/engines/petka/configure.engine b/engines/petka/configure.engine
index 312f6b8df6..b2b3e06032 100644
--- a/engines/petka/configure.engine
+++ b/engines/petka/configure.engine
@@ -1,3 +1,3 @@
 # This file is included from the main "configure" script
 # add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps]
-add_engine petka "Red Comrades" no "" "" "highres 16bit freetype2"
+add_engine petka "Red Comrades" no "" "" "highres 16bit freetype2 cxx11"


Commit: f1ed89e5a39be22d6f54010fd2083e08d9ec5b22
    https://github.com/scummvm/scummvm/commit/f1ed89e5a39be22d6f54010fd2083e08d9ec5b22
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-10-03T15:51:14+02:00

Commit Message:
CONFIGURE: Define USE_CXX11 when c++11 is enabled

Changed paths:
    configure


diff --git a/configure b/configure
index d5316f0cd8..352cd3cdc0 100755
--- a/configure
+++ b/configure
@@ -2299,6 +2299,7 @@ if test "$_use_cxx11" = "yes" ; then
 	append_var CXXFLAGS "-std=c++11"
 fi
 echo $_use_cxx11
+define_in_config_if_yes "$_use_cxx11" 'USE_CXX11'
 
 #
 # Determine extra build flags for debug and/or release builds


Commit: a275522f89f716f7eda62ff732cd6d808e81d803
    https://github.com/scummvm/scummvm/commit/a275522f89f716f7eda62ff732cd6d808e81d803
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-10-03T15:51:14+02:00

Commit Message:
COMMON: Add list initialization and move semantics to Array

Changed paths:
    common/array.h
    test/common/array.h


diff --git a/common/array.h b/common/array.h
index c57d0a109d..96e79a90cc 100644
--- a/common/array.h
+++ b/common/array.h
@@ -28,6 +28,10 @@
 #include "common/textconsole.h" // For error()
 #include "common/memory.h"
 
+#ifdef USE_CXX11
+#include <initializer_list>
+#endif
+
 namespace Common {
 
 /**
@@ -84,6 +88,26 @@ public:
 		}
 	}
 
+#ifdef USE_CXX11
+	/**
+	 * Constructs an array as a copy of the given array using the c++11 move semantic.
+	 */
+	Array(Array<T> &&old) : _capacity(old._capacity), _size(old._size), _storage(old._storage) {
+		old._storage = nullptr;
+		old._capacity = 0;
+		old._size = 0;
+	}
+
+	/**
+	 * Constructs an array using list initialization.
+	 */
+	Array(std::initializer_list<T> list) : _size(list.size()) {
+		allocCapacity(list.size());
+		if (_storage)
+			Common::uninitialized_copy(list.begin(), list.end(), _storage);
+	}
+#endif
+
 	/**
 	 * Construct an array by copying data from a regular array.
 	 */
@@ -210,6 +234,24 @@ public:
 		return *this;
 	}
 
+#ifdef USE_CXX11
+	Array &operator=(Array<T> &&old) {
+		if (this == &old)
+			return *this;
+
+		freeStorage(_storage, _size);
+		_capacity = old._capacity;
+		_size = old._size;
+		_storage = old._storage;
+
+		old._storage = nullptr;
+		old._capacity = 0;
+		old._size = 0;
+
+		return *this;
+	}
+#endif
+
 	size_type size() const {
 		return _size;
 	}
diff --git a/test/common/array.h b/test/common/array.h
index bf0ff55639..f86d291ab2 100644
--- a/test/common/array.h
+++ b/test/common/array.h
@@ -322,6 +322,16 @@ class ArrayTestSuite : public CxxTest::TestSuite
 		Common::Array<Common::NonCopyable> nonCopyable(1);
 	}
 
+	void test_array_constructor_list() {
+#ifdef USE_CXX11
+		Common::Array<int> array = {1, 42, 255};
+		TS_ASSERT_EQUALS(array.size(), 3U);
+		TS_ASSERT_EQUALS(array[0], 1);
+		TS_ASSERT_EQUALS(array[1], 42);
+		TS_ASSERT_EQUALS(array[2], 255);
+#endif
+	}
+
 	void test_array_constructor_count_copy_value() {
 		Common::Array<int> trivial(5, 1);
 		TS_ASSERT_EQUALS(trivial.size(), 5U);


Commit: 2eccd9aa8cc7a00cc9b8364b42bb568683cc19d4
    https://github.com/scummvm/scummvm/commit/2eccd9aa8cc7a00cc9b8364b42bb568683cc19d4
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-10-03T15:51:14+02:00

Commit Message:
DEVTOOLS: Add cxx11 feature to create_project

Changed paths:
    devtools/create_project/create_project.cpp


diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp
index e0e26675ce..79d5197b38 100644
--- a/devtools/create_project/create_project.cpp
+++ b/devtools/create_project/create_project.cpp
@@ -1066,6 +1066,7 @@ const Feature s_features[] = {
 	{              "tts",                       "USE_TTS", false, true,  "Text to speech support"},
 	{"builtin-resources",             "BUILTIN_RESOURCES", false, true,  "include resources (e.g. engine data, fonts) into the binary"},
 	{"detection-static", "USE_DETECTION_FEATURES_STATIC",  "", true,  "Static linking of detection objects for engines."}
+	{            "cxx11",                     "USE_CXX11", false, true,  "Compile with c++11 support"}
 };
 
 const Tool s_tools[] = {


Commit: 786aac568b966c0c68940e2ba2b065b318a56795
    https://github.com/scummvm/scummvm/commit/786aac568b966c0c68940e2ba2b065b318a56795
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2020-10-03T15:51:14+02:00

Commit Message:
COMMON: Add c++11 initializer list replacement when not available in std lib

The c++11 standard includes some features that do not only depend on the
compiler supporting it, but also the c++ standard library having support
for it. This is the case for the initializer list feature. So when we
compile with a modern compiler but using an old std lib we need a
replacement for it.

Changed paths:
  A common/initializer_list.h
    common/array.h
    configure


diff --git a/common/array.h b/common/array.h
index 96e79a90cc..96e1ca270b 100644
--- a/common/array.h
+++ b/common/array.h
@@ -29,7 +29,7 @@
 #include "common/memory.h"
 
 #ifdef USE_CXX11
-#include <initializer_list>
+#include "common/initializer_list.h"
 #endif
 
 namespace Common {
diff --git a/common/initializer_list.h b/common/initializer_list.h
new file mode 100644
index 0000000000..8babe2730f
--- /dev/null
+++ b/common/initializer_list.h
@@ -0,0 +1,44 @@
+// Some compiler only have partial support for C++11 and we provide replacements for reatures not available.
+#ifdef USE_CXX11
+
+#ifdef NO_CXX11_INITIALIZER_LIST
+namespace std {
+	template<class T> class initializer_list {
+	public:
+		typedef T value_type;
+		typedef const T& reference;
+		typedef const T& const_reference;
+		typedef size_t size_type;
+		typedef const T* iterator;
+		typedef const T* const_iterator;
+
+		constexpr initializer_list() noexcept = default;
+		constexpr size_t size() const noexcept { return m_size; };
+		constexpr const T* begin() const noexcept { return m_begin; };
+		constexpr const T* end() const noexcept { return m_begin + m_size; }
+
+	private:
+		// Note: begin has to be first or the compiler gets very upset
+		const T* m_begin = { nullptr };
+		size_t m_size = { 0 };
+
+		// The compiler is allowed to call this constructor
+		constexpr initializer_list(const T* t, size_t s) noexcept : m_begin(t) , m_size(s) {}
+	};
+
+	template<class T> constexpr const T* begin(initializer_list<T> il) noexcept {
+		return il.begin();
+	}
+
+	template<class T> constexpr const T* end(initializer_list<T> il) noexcept {
+		return il.end();
+	}
+}
+
+#else
+
+#include <initializer_list>
+
+#endif // NO_CXX11_INITIALIZER_LIST
+
+#endif // USE_CXX11
diff --git a/configure b/configure
index 352cd3cdc0..71a8926e95 100755
--- a/configure
+++ b/configure
@@ -2301,6 +2301,30 @@ fi
 echo $_use_cxx11
 define_in_config_if_yes "$_use_cxx11" 'USE_CXX11'
 
+#
+# Additional tests for C++11 features that may not be present
+#
+if test "$_use_cxx11" = "yes" ; then
+	# Check if initializer list is available
+	echo_n "Checking if C++11 initializer list is available... "
+	cat > $TMPC << EOF
+#include <initializer_list>
+class FOO {
+public:
+	FOO(std::initializer_list<int> list) : _size(list.size()) {}
+	size_t _size;
+};
+int main(int argc, char *argv[]) { return 0; }
+EOF
+	cc_check
+	if test "$TMPR" -eq 0; then
+		echo yes
+	else
+		echo no
+		define_in_config_if_yes yes 'NO_CXX11_INITIALIZER_LIST'
+	fi
+fi
+
 #
 # Determine extra build flags for debug and/or release builds
 #




More information about the Scummvm-git-logs mailing list