diff options
-rw-r--r-- | system/include/compat/math.h | 14 | ||||
-rw-r--r-- | system/include/compat/stdlib.h | 16 | ||||
-rw-r--r-- | system/include/compat/string.h | 17 | ||||
-rw-r--r-- | system/include/compat/sys/stat.h | 20 | ||||
-rw-r--r-- | system/include/compat/sys/timeb.h (renamed from system/include/libc/sys/timeb.h) | 0 | ||||
-rw-r--r-- | system/include/compat/unistd.h | 16 | ||||
-rw-r--r-- | system/include/compat/xlocale.h | 21 | ||||
-rw-r--r-- | system/include/libc/stdlib.h | 2 | ||||
-rw-r--r-- | system/include/libc/string.h | 2 | ||||
-rw-r--r-- | system/include/libc/sys/unistd.h | 1 | ||||
-rw-r--r-- | system/include/xlocale.h | 7 | ||||
-rwxr-xr-x | tests/runner.py | 12 | ||||
-rw-r--r-- | tests/sockets/test_sockets_echo_server.c | 8 | ||||
-rw-r--r-- | tests/sockets/test_sockets_partial_server.c | 24 | ||||
-rw-r--r-- | tests/test_core.py | 8 | ||||
-rw-r--r-- | tools/shared.py | 1 | ||||
-rwxr-xr-x | tools/source-maps/sourcemapper.js | 43 |
17 files changed, 178 insertions, 34 deletions
diff --git a/system/include/compat/math.h b/system/include/compat/math.h new file mode 100644 index 00000000..089cf66b --- /dev/null +++ b/system/include/compat/math.h @@ -0,0 +1,14 @@ +#ifndef _COMPAT_MATH_H_ +#define _COMPAT_MATH_H_ + +#ifndef isinff + #define isinff isinf +#endif + +#ifndef isnanf + #define isnanf isnan +#endif + +#include_next <math.h> + +#endif /* _COMPAT_MATH_H_ */ diff --git a/system/include/compat/stdlib.h b/system/include/compat/stdlib.h new file mode 100644 index 00000000..dc01947d --- /dev/null +++ b/system/include/compat/stdlib.h @@ -0,0 +1,16 @@ +#ifndef _COMPAT_STDLIB_H +#define _COMPAT_STDLIB_H + +#ifdef __cplusplus +extern "C" { +#endif + +int getloadavg(double loadavg[], int nelem); + +#ifdef __cplusplus +} +#endif + +#include_next <stdlib.h> + +#endif diff --git a/system/include/compat/string.h b/system/include/compat/string.h new file mode 100644 index 00000000..880089cc --- /dev/null +++ b/system/include/compat/string.h @@ -0,0 +1,17 @@ +#ifndef _COMPAT_STRING_H +#define _COMPAT_STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern char* strlwr(char *); +extern char* strupr(char *); + +#ifdef __cplusplus +} +#endif + +#include_next <string.h> + +#endif diff --git a/system/include/compat/sys/stat.h b/system/include/compat/sys/stat.h new file mode 100644 index 00000000..731502ea --- /dev/null +++ b/system/include/compat/sys/stat.h @@ -0,0 +1,20 @@ +#ifndef _COMPAT_STAT_H +#define _COMPAT_STAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include_next <sys/stat.h> + +#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO) +#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO) +#define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH) +#define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH) +#define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/system/include/libc/sys/timeb.h b/system/include/compat/sys/timeb.h index 0a2c3de8..0a2c3de8 100644 --- a/system/include/libc/sys/timeb.h +++ b/system/include/compat/sys/timeb.h diff --git a/system/include/compat/unistd.h b/system/include/compat/unistd.h new file mode 100644 index 00000000..07c3afde --- /dev/null +++ b/system/include/compat/unistd.h @@ -0,0 +1,16 @@ +#ifndef _COMPAT_UNISTD_H +#define _COMPAT_UNISTD_H + +#ifdef __cplusplus +extern "C" { +#endif + +char * getwd(char *__buf ); + +#ifdef __cplusplus +} +#endif + +#include_next <unistd.h> + +#endif diff --git a/system/include/compat/xlocale.h b/system/include/compat/xlocale.h new file mode 100644 index 00000000..4bafa27d --- /dev/null +++ b/system/include/compat/xlocale.h @@ -0,0 +1,21 @@ +#ifndef _COMPAT_XLOCALE_H_ +#define _COMPAT_XLOCALE_H_ + +#include <locale.h> + +#ifdef __cplusplus +extern "C" { +#endif + +long long strtoll_l(const char *start, char **end, int base, locale_t loc); +unsigned long long strtoull_l(const char *start, char **end, int base, locale_t loc); +double strtold_l(const char *start, char **end, locale_t loc); + +#ifdef __cplusplus +} +#endif + +#include_next <xlocale.h> + +#endif /* _COMPAT_XLOCALE_H_ */ + diff --git a/system/include/libc/stdlib.h b/system/include/libc/stdlib.h index 888b6041..6fdef40b 100644 --- a/system/include/libc/stdlib.h +++ b/system/include/libc/stdlib.h @@ -223,8 +223,6 @@ extern long double strtold (const char *, char **); extern long double wcstold (const wchar_t *, wchar_t **); #endif /* _LDBL_EQ_DBL */ -int getloadavg(double loadavg[], int nelem); /* XXX Emscripten */ - _END_STD_C #endif /* _STDLIB_H_ */ diff --git a/system/include/libc/string.h b/system/include/libc/string.h index 515c71a7..8fd9ea43 100644 --- a/system/include/libc/string.h +++ b/system/include/libc/string.h @@ -72,8 +72,6 @@ size_t _EXFUN(strlcpy,(char *, const char *, size_t)); int _EXFUN(strncasecmp,(const char *, const char *, size_t)); size_t _EXFUN(strnlen,(const char *, size_t)); char *_EXFUN(strsep,(char **, const char *)); -char *_EXFUN(strlwr,(char *)); -char *_EXFUN(strupr,(char *)); #if defined(__CYGWIN__) || defined(EMSCRIPTEN) #ifndef DEFS_H /* Kludge to work around problem compiling in gdb */ char *_EXFUN(strsignal, (int __signo)); diff --git a/system/include/libc/sys/unistd.h b/system/include/libc/sys/unistd.h index 1a414b3c..a4219d4d 100644 --- a/system/include/libc/sys/unistd.h +++ b/system/include/libc/sys/unistd.h @@ -102,7 +102,6 @@ uid_t _EXFUN(getuid, (void )); #endif #if defined(EMSCRIPTEN) || defined(__CYGWIN__) char * _EXFUN(getusershell, (void)); -char * _EXFUN(getwd, (char *__buf )); int _EXFUN(iruserok, (unsigned long raddr, int superuser, const char *ruser, const char *luser)); #endif int _EXFUN(isatty, (int __fildes )); diff --git a/system/include/xlocale.h b/system/include/xlocale.h index bb3b50e5..6867d25f 100644 --- a/system/include/xlocale.h +++ b/system/include/xlocale.h @@ -1,4 +1,3 @@ - #ifndef _XLOCALE_H_ #define _XLOCALE_H_ @@ -9,10 +8,6 @@ extern "C" { #endif -long long strtoll_l(const char *start, char **end, int base, locale_t loc); -unsigned long long strtoull_l(const char *start, char **end, int base, locale_t loc); -double strtold_l(const char *start, char **end, locale_t loc); - int strcoll_l(const char *s1, const char *s2, locale_t locale); int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t locale); @@ -43,5 +38,5 @@ size_t strftime_l(char *s, size_t maxsize, const char *format, const struct tm * } #endif -#endif /* _LOCALE_H_ */ +#endif /* _XLOCALE_H_ */ diff --git a/tests/runner.py b/tests/runner.py index bdbd2676..318946e6 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -275,6 +275,18 @@ process(sys.argv[1]) print "Output: " + output[0] return output[0] + # Tests that the given two paths are identical, modulo path delimiters. E.g. "C:/foo" is equal to "C:\foo". + def assertPathsIdentical(self, path1, path2): + path1 = path1.replace('\\', '/') + path2 = path2.replace('\\', '/') + return self.assertIdentical(path1, path2) + + # Tests that the given two multiline text content are identical, modulo line ending differences (\r\n on Windows, \n on Unix). + def assertTextDataIdentical(self, text1, text2): + text1 = text1.replace('\r\n', '\n') + text2 = text2.replace('\r\n', '\n') + return self.assertIdentical(text1, text2) + def assertIdentical(self, values, y): if type(values) not in [list, tuple]: values = [values] for x in values: diff --git a/tests/sockets/test_sockets_echo_server.c b/tests/sockets/test_sockets_echo_server.c index 8a48b878..38e27cac 100644 --- a/tests/sockets/test_sockets_echo_server.c +++ b/tests/sockets/test_sockets_echo_server.c @@ -37,6 +37,11 @@ typedef struct { server_t server; client_t client; +void cleanup() { + if (server.fd) close(server.fd); + if (client.fd) close(client.fd); +} + void main_loop(void *arg) { int res; fd_set fdr; @@ -105,6 +110,9 @@ int main() { struct sockaddr_in addr; int res; + atexit(cleanup); + signal(SIGTERM, cleanup); + memset(&server, 0, sizeof(server_t)); memset(&client, 0, sizeof(client_t)); diff --git a/tests/sockets/test_sockets_partial_server.c b/tests/sockets/test_sockets_partial_server.c index 57fae84b..dfe0e249 100644 --- a/tests/sockets/test_sockets_partial_server.c +++ b/tests/sockets/test_sockets_partial_server.c @@ -14,18 +14,13 @@ #include <emscripten.h> #endif -int serverfd = -1; -int clientfd = -1; - -// csock.send("\x09\x01\x02\x03\x04\x05\x06\x07\x08\x09") -// csock.send("\x08\x01\x02\x03\x04\x05\x06\x07\x08") -// csock.send("\x07\x01\x02\x03\x04\x05\x06\x07") -// csock.send("\x06\x01\x02\x03\x04\x05\x06") -// csock.send("\x05\x01\x02\x03\x04\x05") -// csock.send("\x04\x01\x02\x03\x04") -// csock.send("\x03\x01\x02\x03") -// csock.send("\x02\x01\x02") -// csock.send("\x01\x01") +int serverfd = 0; +int clientfd = 0; + +void cleanup() { + if (serverfd) close(serverfd); + if (clientfd) close(clientfd); +} void do_send(int sockfd) { static char* buffers[] = { @@ -69,7 +64,7 @@ void iter(void *arg) { FD_ZERO(&fdr); FD_ZERO(&fdw); FD_SET(serverfd, &fdr); - if (clientfd != -1) FD_SET(clientfd, &fdw); + if (clientfd) FD_SET(clientfd, &fdw); res = select(64, &fdr, &fdw, NULL, NULL); if (res == -1) { perror("select failed"); @@ -91,6 +86,9 @@ int main() { struct sockaddr_in addr; int res; + atexit(cleanup); + signal(SIGTERM, cleanup); + // create the socket serverfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (serverfd == -1) { diff --git a/tests/test_core.py b/tests/test_core.py index 31db6ca5..88f6674a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -9582,15 +9582,15 @@ def process(filename): self.assertIdentical(clean(no_maps_file), clean(out_file)) map_filename = out_filename + '.map' data = json.load(open(map_filename, 'r')) - self.assertIdentical(out_filename, data['file']) - self.assertIdentical(src_filename, data['sources'][0]) - self.assertIdentical(src, data['sourcesContent'][0]) + self.assertPathsIdentical(out_filename, data['file']) + self.assertPathsIdentical(src_filename, data['sources'][0]) + self.assertTextDataIdentical(src, data['sourcesContent'][0]) mappings = json.loads(jsrun.run_js( path_from_root('tools', 'source-maps', 'sourcemap2json.js'), tools.shared.NODE_JS, [map_filename])) seen_lines = set() for m in mappings: - self.assertIdentical(src_filename, m['source']) + self.assertPathsIdentical(src_filename, m['source']) seen_lines.add(m['originalLine']) # ensure that all the 'meaningful' lines in the original code get mapped assert seen_lines.issuperset([6, 7, 11, 12]) diff --git a/tools/shared.py b/tools/shared.py index 917f548e..0d0f20d4 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -550,6 +550,7 @@ if USE_EMSDK: # allows projects to override them) EMSDK_OPTS = ['-nostdinc', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', '-Xclang', '-isystem' + path_from_root('system', 'local', 'include'), + '-Xclang', '-isystem' + path_from_root('system', 'include', 'compat'), '-Xclang', '-isystem' + path_from_root('system', 'include', 'libcxx'), '-Xclang', '-isystem' + path_from_root('system', 'include'), '-Xclang', '-isystem' + path_from_root('system', 'include', 'emscripten'), diff --git a/tools/source-maps/sourcemapper.js b/tools/source-maps/sourcemapper.js index fa908900..06c9a227 100755 --- a/tools/source-maps/sourcemapper.js +++ b/tools/source-maps/sourcemapper.js @@ -16,6 +16,38 @@ function countLines(s) { return count; } +// For a minor optimization, only do win32->unix normalization if we are actually on Windows, +// which avoids redundantly scanning files if not needed. +var isWindows = (process.platform === 'win32'); + +var unixPathRe = new RegExp('\\\\', 'g'); +// Returns the given (possibly Windows) path p normalized to unix path separators '/'. +function toUnixPath(p) { + if (isWindows) { + return p.replace(unixPathRe, '/'); + } else { + return p; + } +} + +var unixLineEndRe = new RegExp('\r\n', 'g'); +// Returns the given (possibly Windows) text data t normalized to unix line endings '\n'. +function toUnixLineEnding(t) { + if (isWindows) { + return t.replace(unixLineEndRe, '\n'); + } else { + return t; + } +} + +// If path "p2" is a relative path, joins paths p1 and p2 to form "p1/p2". If p2 is an absolute path, "p2" is returned. +function joinPath(p1, p2) { + if (p2[0] == '/' || (p2.length >= 3 && p2[1] == ':' && (p2[2] == '/' || p2[2] == '\\'))) // Is p2 an absolute path? + return p2; + else + return toUnixPath(path.join(p1, p2)); +} + /* * Extracts the line (not block) comments from the generated function code and * invokes commentHandler with (comment content, line number of comment). This @@ -105,8 +137,7 @@ function generateMap(mappings, sourceRoot, mapFileBaseName, generatedLineOffset) // avoid doing it unnecessarily if (!(originalFileName in seenFiles)) { seenFiles[originalFileName] = true; - var rootedPath = originalFileName[0] === path.sep ? - originalFileName : path.join(sourceRoot, originalFileName); + var rootedPath = joinPath(sourceRoot, originalFileName); try { generator.setSourceContent(originalFileName, fs.readFileSync(rootedPath, 'utf-8')); } catch (e) { @@ -144,15 +175,15 @@ if (require.main === module) { } else { var opts = parseArgs(process.argv.slice(2)); var fileName = opts._[0]; - var sourceRoot = opts.sourceRoot ? opts.sourceRoot : "."; - var mapFileBaseName = opts.mapFileBaseName ? opts.mapFileBaseName : fileName; + var sourceRoot = opts.sourceRoot ? toUnixPath(opts.sourceRoot) : "."; + var mapFileBaseName = toUnixPath(opts.mapFileBaseName ? opts.mapFileBaseName : fileName); var generatedLineOffset = opts.offset ? parseInt(opts.offset, 10) : 0; - var generatedSource = fs.readFileSync(fileName, 'utf-8'); + var generatedSource = toUnixLineEnding(fs.readFileSync(fileName, 'utf-8')); var source = generatedSource; var mappings = getMappings(generatedSource); for (var i = 1, l = opts._.length; i < l; i ++) { - var optimizedSource = fs.readFileSync(opts._[i], 'utf-8') + var optimizedSource = toUnixLineEnding(fs.readFileSync(opts._[i], 'utf-8')) var optimizedMappings = getMappings(optimizedSource); var newMappings = {}; // uglify processes the code between EMSCRIPTEN_START_FUNCS and |