瀏覽代碼

Fix compilation on windows

Daniele Bartolini 10 年之前
父節點
當前提交
47efab7e69

+ 1 - 1
src/console_server.cpp

@@ -47,7 +47,7 @@ void ConsoleServer::shutdown()
 
 void ConsoleServer::send(TCPSocket client, const char* json)
 {
-	uint32_t len = strlen(json);
+	uint32_t len = strlen32(json);
 	client.write((const char*)&len, 4);
 	client.write(json, len);
 }

+ 2 - 2
src/core/command_line.h

@@ -23,8 +23,8 @@ struct CommandLine
 	{
 		for (int i = 0; i < _argc; i++)
 		{
-			if ((shortopt != '\0' && strlen(_argv[i]) > 1 && _argv[i][0] == '-' && _argv[i][1] == shortopt) ||
-				(strlen(_argv[i]) > 2 && _argv[i][0] == '-' && _argv[i][1] == '-' && strcmp(&_argv[i][2], longopt) == 0))
+			if ((shortopt != '\0' && strlen32(_argv[i]) > 1 && _argv[i][0] == '-' && _argv[i][1] == shortopt) ||
+				(strlen32(_argv[i]) > 2 && _argv[i][0] == '-' && _argv[i][1] == '-' && strcmp(&_argv[i][2], longopt) == 0))
 			{
 				return i;
 			}

+ 1 - 1
src/core/error/stacktrace_linux.cpp

@@ -26,7 +26,7 @@ const char* addr2line(const char* addr, char* line, int len)
 	if (f)
 	{
 		fgets(line, len, f);
-		line[strlen(line) - 1] = '\0';
+		line[strlen32(line) - 1] = '\0';
 		pclose(f);
 		return line;
 	}

+ 1 - 1
src/core/filesystem/reader_writer.h

@@ -71,7 +71,7 @@ public:
 	/// The final null character is not copied to the file.
 	void write_string(const char* string)
 	{
-		_file.write(string, strlen(string));
+		_file.write(string, strlen32(string));
 	}
 
 private:

+ 3 - 3
src/core/os.h

@@ -112,7 +112,7 @@ namespace os
 		CE_ASSERT(err != 0, "GetFileTime: GetLastError = %d", GetLastError());
 		CE_UNUSED(err);
 		CloseHandle(hfile);
-		return (uint64_t)((ftwrite.dwHighDateTime << 32) | ftwrite.dwLowDateTime);
+		return (uint64_t)((uint64_t(ftwrite.dwHighDateTime) << 32) | ftwrite.dwLowDateTime);
 #endif
 	}
 
@@ -223,7 +223,7 @@ namespace os
 
 			TempAllocator512 ta;
 			DynamicString filename(fname, ta);
-			vector::push_back(files, fname);
+			vector::push_back(files, filename);
 		}
 		while (FindNextFile(file, &ffd) != 0);
 
@@ -335,7 +335,7 @@ namespace os
 		PROCESS_INFORMATION process;
 		memset(&process, 0, sizeof(process));
 
-		int err = CreateProcess(path, args, NULL, NULL, TRUE, 0, NULL, NULL, &info, &process);
+		int err = CreateProcess(path, (LPSTR)args, NULL, NULL, TRUE, 0, NULL, NULL, &info, &process);
 		CE_ASSERT(err != 0, "CreateProcess: GetLastError = %d", GetLastError());
 		CE_UNUSED(err);
 

+ 2 - 2
src/core/string_id.cpp

@@ -12,7 +12,7 @@ namespace crown
 {
 
 StringId32::StringId32(const char* str)
-	: _id(murmur32(str, strlen(str)))
+	: _id(murmur32(str, strlen32(str)))
 {
 }
 
@@ -28,7 +28,7 @@ const char* StringId32::to_string(char* buf)
 }
 
 StringId64::StringId64(const char* str)
-	: _id(murmur64(str, strlen(str)))
+	: _id(murmur64(str, strlen32(str)))
 {
 }
 

+ 14 - 13
src/core/strings/dynamic_string.h

@@ -9,6 +9,7 @@
 #include "memory.h"
 #include "array.h"
 #include "string_id.h"
+#include "string_utils.h"
 #include <string.h> // memmove
 
 namespace crown
@@ -78,7 +79,7 @@ inline DynamicString::DynamicString(const char* s, Allocator& a)
 	: _data(a)
 {
 	CE_ASSERT_NOT_NULL(s);
-	array::push(_data, s, (uint32_t)strlen(s));
+	array::push(_data, s, strlen32(s));
 }
 
 inline DynamicString& DynamicString::operator+=(const DynamicString& s)
@@ -89,7 +90,7 @@ inline DynamicString& DynamicString::operator+=(const DynamicString& s)
 inline DynamicString& DynamicString::operator+=(const char* s)
 {
 	CE_ASSERT_NOT_NULL(s);
-	array::push(_data, s, (uint32_t)strlen(s));
+	array::push(_data, s, strlen32(s));
 	return *this;
 }
 
@@ -109,7 +110,7 @@ inline DynamicString& DynamicString::operator=(const char* s)
 {
 	CE_ASSERT_NOT_NULL(s);
 	array::clear(_data);
-	array::push(_data, s, (uint32_t)strlen(s));
+	array::push(_data, s, strlen32(s));
 	return *this;
 }
 
@@ -143,7 +144,7 @@ inline void DynamicString::reserve(uint32_t n)
 
 inline uint32_t DynamicString::length() const
 {
-	return (uint32_t)strlen(this->c_str());
+	return strlen32(this->c_str());
 }
 
 inline void DynamicString::strip_leading(const char* s)
@@ -151,11 +152,11 @@ inline void DynamicString::strip_leading(const char* s)
 	CE_ASSERT_NOT_NULL(s);
 	CE_ASSERT(starts_with(s), "String does not start with %s", s);
 
-	const size_t my_len = strlen(c_str());
-	const size_t s_len = strlen(s);
+	const uint32_t my_len = strlen32(c_str());
+	const uint32_t s_len = strlen32(s);
 
 	memmove(array::begin(_data), array::begin(_data) + s_len, (my_len - s_len));
-	array::resize(_data, uint32_t(my_len - s_len));
+	array::resize(_data, my_len - s_len);
 }
 
 inline void DynamicString::strip_trailing(const char* s)
@@ -163,23 +164,23 @@ inline void DynamicString::strip_trailing(const char* s)
 	CE_ASSERT_NOT_NULL(s);
 	CE_ASSERT(ends_with(s), "String does not end with %s", s);
 
-	const size_t my_len = strlen(c_str());
-	const size_t s_len = strlen(s);
-	array::resize(_data, uint32_t(my_len - s_len));
+	const uint32_t my_len = strlen32(c_str());
+	const uint32_t s_len = strlen32(s);
+	array::resize(_data, my_len - s_len);
 }
 
 inline bool DynamicString::starts_with(const char* s) const
 {
 	CE_ASSERT_NOT_NULL(s);
-	return strncmp(c_str(), s, strlen(s)) == 0;
+	return strncmp(c_str(), s, strlen32(s)) == 0;
 }
 
 inline bool DynamicString::ends_with(const char* s) const
 {
 	CE_ASSERT_NOT_NULL(s);
 
-	const size_t my_len = strlen(c_str());
-	const size_t s_len = strlen(s);
+	const uint32_t my_len = strlen32(c_str());
+	const uint32_t s_len = strlen32(s);
 
 	if (my_len >= s_len)
 	{

+ 3 - 3
src/core/strings/fixed_string.h

@@ -22,7 +22,7 @@ public:
 	}
 
 	FixedString(const char* str)
-		: _length(strlen(str))
+		: _length(strlen32(str))
 		, _data(str)
 	{
 	}
@@ -41,14 +41,14 @@ public:
 
 	FixedString& operator=(const char* str)
 	{
-		_length = strlen(str);
+		_length = strlen32(str);
 		_data = str;
 		return *this;
 	}
 
 	bool operator==(const char* str) const
 	{
-		const uint32_t len = strlen(str);
+		const uint32_t len = strlen32(str);
 		return _length == len && !strncmp(_data, str, len);
 	}
 

+ 6 - 6
src/core/strings/path.cpp

@@ -15,9 +15,9 @@ namespace path
 	{
 		CE_ASSERT(path != NULL, "Path must be != NULL");
 #if CROWN_PLATFORM_POSIX
-		return strlen(path) > 0 && path[0] == SEPARATOR;
+		return strlen32(path) > 0 && path[0] == SEPARATOR;
 #elif CROWN_PLATFORM_WINDOWS
-		return strlen(path) > 2 && isalpha(path[0]) && path[1] == ':' && path[2] == SEPARATOR;
+		return strlen32(path) > 2 && isalpha(path[0]) && path[1] == ':' && path[2] == SEPARATOR;
 #endif
 	}
 
@@ -25,16 +25,16 @@ namespace path
 	{
 		CE_ASSERT(path != NULL, "Path must be != NULL");
 #if CROWN_PLATFORM_POSIX
-		return is_absolute_path(path) && strlen(path) == 1;
+		return is_absolute_path(path) && strlen32(path) == 1;
 #elif CROWN_PLATFORM_WINDOWS
-		return is_absolute_path(path) && strlen(path) == 3;
+		return is_absolute_path(path) && strlen32(path) == 3;
 #endif
 	}
 
 	void join(const char* a, const char* b, DynamicString& path)
 	{
-		const uint32_t la = strlen(a);
-		const uint32_t lb = strlen(b);
+		const uint32_t la = strlen32(a);
+		const uint32_t lb = strlen32(b);
 		path.reserve(la + lb + 1);
 		path += a;
 		path += SEPARATOR;

+ 2 - 2
src/core/strings/string_stream.h

@@ -86,9 +86,9 @@ namespace string_stream
 		return stream_printf(s, "%g", val);
 	}
 
-	inline StringStream& operator<<(StringStream& s, const char* string)
+	inline StringStream& operator<<(StringStream& s, const char* str)
 	{
-		array::push(s, string, (uint32_t)strlen(string));
+		array::push(s, str, strlen32(str));
 		return s;
 	}
 

+ 5 - 0
src/core/strings/string_utils.h

@@ -36,6 +36,11 @@ inline int32_t snprintf(char* str, size_t n, const char* format, ...)
 	return len;
 }
 
+inline uint32_t strlen32(const char* str)
+{
+	return (uint32_t)strlen(str);
+}
+
 inline const char* skip_spaces(const char* str)
 {
 	while (isspace(*str)) ++str;

+ 4 - 3
src/device.h

@@ -20,6 +20,7 @@
 #include "allocator.h"
 #include "log.h"
 #include "proxy_allocator.h"
+#include "string_utils.h"
 #include <bx/allocator.h>
 #include <bgfx/bgfx.h>
 
@@ -159,7 +160,7 @@ private:
 		{
 			char buf[2048];
 			strncpy(buf, _format, sizeof(buf));
-			buf[strlen(buf)-1] = '\0'; // Remove trailing newline
+			buf[strlen32(buf)-1] = '\0'; // Remove trailing newline
 			CE_LOGDV(buf, _argList);
 		}
 
@@ -204,7 +205,7 @@ private:
 		virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* /*_file*/, uint32_t /*_line*/)
 		{
 			if (!_ptr)
-				return _allocator.allocate((uint32_t)_size, (uint32_t)_align == 0 ? 1 : _align);
+				return _allocator.allocate((uint32_t)_size, (uint32_t)_align == 0 ? 1 : (uint32_t)_align);
 
 			if (_size == 0)
 			{
@@ -213,7 +214,7 @@ private:
 			}
 
 			// Realloc
-			void* p = _allocator.allocate((uint32_t)_size, (uint32_t)_align == 0 ? 1 : _align);
+			void* p = _allocator.allocate((uint32_t)_size, (uint32_t)_align == 0 ? 1 : (uint32_t)_align);
 			_allocator.deallocate(_ptr);
 			return p;
 		}

+ 3 - 2
src/input/input_device.cpp

@@ -6,7 +6,8 @@
 #include "input_device.h"
 #include "error.h"
 #include "allocator.h"
-#include <string.h> // strlen, strcpy, memset
+#include "string_utils.h"
+#include <string.h> // strcpy, memset
 
 namespace crown
 {
@@ -88,7 +89,7 @@ InputDevice* InputDevice::create(Allocator& a, const char* name, uint8_t num_but
 		+ sizeof(InputDevice)
 		+ sizeof(uint8_t)*num_buttons*2
 		+ sizeof(Vector3)*num_axes
-		+ strlen(name) + 1;
+		+ strlen32(name) + 1;
 
 	InputDevice* id = (InputDevice*)a.allocate(size);
 

+ 1 - 1
src/input/input_device.h

@@ -62,7 +62,7 @@ public:
 	uint8_t* _last_state;    // num_buttons
 	uint8_t* _current_state; // num_buttons
 	Vector3* _axis;          // num_axes
-	char* _name;             // strlen(name) + 1
+	char* _name;             // strlen32(name) + 1
 
 public:
 

+ 1 - 1
src/renderers/gui.cpp

@@ -210,7 +210,7 @@ void Gui::draw_text(const char* str, const char* font, uint32_t font_size, const
 	// Vector2 m_pen;
 
 	// const float scale = ((float)font_size / (float)resource->font_size());
-	// const uint32_t str_len = strlen(str);
+	// const uint32_t str_len = strlen32(str);
 
 	// TransientVertexBuffer vb;
 	// TransientIndexBuffer ib;

+ 1 - 1
src/renderers/shader.cpp

@@ -52,7 +52,7 @@ namespace shader_resource
 #if CROWN_PLATFORM_LINUX
 		args <<	"120";
 #elif CROWN_PLATFORM_WINDOWS
-		args << (strcmp(type, "vertex") == 0) ? "vs_3_0" : "ps_3_0";
+		args << ((strcmp(type, "vertex") == 0) ? "vs_3_0" : "ps_3_0");
 #endif
 
 		return os::execute_process(SHADERC_PATH, c_str(args), output);