Simplified strdup(); added test for it in test_strings.
This commit is contained in:
Родитель
1ca0ab32d4
Коммит
c105c7232c
|
@ -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;
|
||||
},
|
||||
|
||||
|
|
|
@ -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'''
|
||||
|
|
Загрузка…
Ссылка в новой задаче