Commits

Jason Perkins committed 8f583fc

Make deterministic UUID code friendly to non-C99 compilers; update change log

Comments (0)

Files changed (2)

 --------
-  4.5 (in progress)
+  5.0 (in progress)
 --------
 
 * Completely overhauled the platform support; too many changes to list
 * Added NoImplicitLink flag to force explicit linking from Visual Studio
 * Decoupled VS2010 smaller type checks (/RTCc) from extra warnings (/W4)
 * Added NoRuntimeChecks flag to disable Visual Studio default checks
+* Generated Visual Studio GUIDs are now deterministic
+* Added support for Visual Studio solution groups
 
 
 -------

src/host/os_uuid.c

 /**
  * \file   os_uuid.c
  * \brief  Create a new UUID.
- * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
+ * \author Copyright (c) 2002-2012 Jason Perkins and the Premake project
  */
 
 #include "premake.h"
-#include <stdint.h>
 
 #if PLATFORM_WINDOWS
 #include <Objbase.h>
 #endif
 
+
+/*
+ * Pull off the four lowest bytes of a value and add them to my array,
+ * without the help of the determinately sized C99 data types that
+ * are not yet universally supported.
+ */
+static void add(unsigned char* bytes, int offset, unsigned long value)
+{
+	int i;
+	for (i = 0; i < 4; ++i)
+	{
+		bytes[offset++] = value & 0xff;
+		value >>= 8;
+	}
+}
+
+
 int os_uuid(lua_State* L)
 {
 	char uuid[38];
-	uint32_t buffer[4];
-	uint8_t* bytes = (uint8_t*)buffer;
+	unsigned char bytes[16];
 	
 	/* If a name argument is supplied, build the UUID from that. For speed we
 	 * are using a simple DBJ2 hashing function; if this isn't sufficient we
 	const char* name = luaL_optstring(L, 1, NULL);
 	if (name != NULL)
 	{
-		buffer[0] = do_hash(name, 0);
-		buffer[1] = do_hash(name, 'L');
-		buffer[2] = do_hash(name, 'u');
-		buffer[3] = do_hash(name, 'a');
+		add(bytes, 0, do_hash(name, 0));
+		add(bytes, 4, do_hash(name, 'L'));
+		add(bytes, 8, do_hash(name, 'u'));
+		add(bytes, 12, do_hash(name, 'a'));
 	}
 
 	/* If no name is supplied, try to build one properly */	
 	else
 	{
 #if PLATFORM_WINDOWS
-		CoCreateGuid((GUID*)buffer);
+		CoCreateGuid((GUID*)bytes);
 #else
 		int result;
 
 		/* not sure how to get a UUID here, so I fake it */
 		FILE* rnd = fopen("/dev/urandom", "rb");
-		result = fread(buffer, 16, 1, rnd);
+		result = fread(bytes, 16, 1, rnd);
 		fclose(rnd);
 		if (!result)
 		{