浏览代码

Fixed an issue with big endian processor. Added a string conversion sanity check.

Marco Bambini 8 年之前
父节点
当前提交
02dc0af07e
共有 3 个文件被更改,包括 12 次插入4 次删除
  1. 4 1
      src/compiler/gravity_lexer.c
  2. 6 1
      src/runtime/gravity_core.c
  3. 2 2
      src/shared/gravity_value.h

+ 4 - 1
src/compiler/gravity_lexer.c

@@ -174,7 +174,10 @@ static inline bool next_utf8(gravity_lexer_t *lexer, int *result) {
 	int c = NEXT;
 	INC_TOKLEN;
 
-	uint32_t len = utf8_charbytes((const char *)&c, 0);
+    // the following explicit conversion fixes an issue with big-endian processor (like Motorola 68000, PowerPC, Sun Sparc and IBM S/390)
+    // was uint32_t len = utf8_charbytes((const char *)&c, 0);
+    const char s = c;
+	uint32_t len = utf8_charbytes((const char *)&s, 0);
 	if (len == 0) return false;
 
 	switch(len) {

+ 6 - 1
src/runtime/gravity_core.c

@@ -421,7 +421,12 @@ inline gravity_value_t convert_value2string (gravity_vm *vm, gravity_value_t v)
     }
 
 	// execute closure and return its value
-	if (gravity_vm_runclosure(vm, closure, v, NULL, 0)) return gravity_vm_result(vm);
+    if (gravity_vm_runclosure(vm, closure, v, NULL, 0)) {
+        gravity_value_t result = gravity_vm_result(vm);
+        // sanity check closure return value because sometimes nil is returned by an objc instance (for example NSData String)
+        if (!VALUE_ISA_STRING(result)) return VALUE_FROM_CSTRING(vm, "null");
+        return result;
+    }
 
 	return VALUE_FROM_ERROR(NULL);
 }

+ 2 - 2
src/shared/gravity_value.h

@@ -66,8 +66,8 @@
 extern "C" {
 #endif
 
-#define GRAVITY_VERSION						"0.3.7"     // git tag 0.3.7
-#define GRAVITY_VERSION_NUMBER				0x000307    // git push --tags
+#define GRAVITY_VERSION						"0.3.8"     // git tag 0.3.8
+#define GRAVITY_VERSION_NUMBER				0x000308    // git push --tags
 #define GRAVITY_BUILD_DATE					__DATE__
 
 #ifndef GRAVITY_ENABLE_DOUBLE