aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-27 08:09:49 +0300
committermax99x <max99x@gmail.com>2011-08-27 08:09:49 +0300
commitc105c7232c06a47e8a801d1d122adcccb1a6e3f0 (patch)
tree79abc535798502dec5f9d1458feb3349e66e58ec
parent1ca0ab32d47326d0d83ae15165bf306cb9965658 (diff)
Simplified strdup(); added test for it in test_strings.
-rw-r--r--src/library.js7
-rw-r--r--tests/runner.py7
2 files changed, 7 insertions, 7 deletions
diff --git a/src/library.js b/src/library.js
index afecc253..03f23439 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3652,13 +3652,8 @@ LibraryManager.library = {
strdup: function(ptr) {
var len = String_len(ptr);
- var end = ptr + len;
var newStr = _malloc(len + 1);
- for (var src = ptr, dst = newStr; src < end; src++, dst++) {
- var srcVal = {{{ makeGetValue('src', 0, 'i8') }}};
- {{{ makeSetValue('dst', 0, 'srcVal', 'i8') }}}
- }
- {{{ makeSetValue('dst', 0, 0, 'i8') }}}
+ {{{ makeCopyValues('newStr', 'ptr', 'len + 1', 'null', ' || 0') }}};
return newStr;
},
diff --git a/tests/runner.py b/tests/runner.py
index 8fd090f0..9b7c8ec9 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -679,10 +679,15 @@ if 'benchmark' not in sys.argv:
printf("%s\\n", NULL); // Should print '(null)', not the string at address 0, which is a real address for us!
printf("/* a comment */\\n"); // Should not break the generated code!
printf("// another\\n"); // Should not break the generated code!
+
+ char* strdup_val = strdup("test");
+ printf("%s\\n", strdup_val);
+ free(strdup_val);
+
return 0;
}
'''
- self.do_test(src, '3:10,177,543\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another', ['wowie', 'too', '74'])
+ self.do_test(src, '3:10,177,543\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\n', ['wowie', 'too', '74'])
def test_error(self):
src = r'''