aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-22 10:15:07 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-22 10:15:07 -0800
commit7af6ac4d14404cbc9bf49e7761ec745e6c3dd773 (patch)
treebd8a073145e6e894af308086c05b8361ee0a197e
parent08fd4f470e70b68d288370833524cfe49e9e369d (diff)
fix pthread_setspecific on values of null
-rw-r--r--src/library.js2
-rw-r--r--tests/pthread/specific.c8
-rw-r--r--tests/pthread/specific.c.txt2
3 files changed, 11 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index 8425a10f..3df61724 100644
--- a/src/library.js
+++ b/src/library.js
@@ -6963,7 +6963,7 @@ LibraryManager.library = {
pthread_setspecific__deps: ['$PTHREAD_SPECIFIC', '$ERRNO_CODES'],
pthread_setspecific: function(key, value) {
- if (value == 0) {
+ if (!(key in PTHREAD_SPECIFIC)) {
return ERRNO_CODES.EINVAL;
}
PTHREAD_SPECIFIC[key] = value;
diff --git a/tests/pthread/specific.c b/tests/pthread/specific.c
index 914884e7..631baf8c 100644
--- a/tests/pthread/specific.c
+++ b/tests/pthread/specific.c
@@ -33,6 +33,14 @@ int main(void)
printf("pthread_getspecific = %d\n", *data2);
assert(*data2 == 123);
+ rv = pthread_setspecific(key, NULL);
+ printf("valid pthread_setspecific for value NULL = %d\n", rv);
+ assert(rv == 0);
+
+ data2 = pthread_getspecific(key);
+ assert(data2 == NULL);
+ printf("pthread_getspecific = %p\n", data2);
+
rv = pthread_key_create(&key, &destr_function);
data2 = pthread_getspecific(key);
printf("pthread_getspecific after key recreate = %p\n", data2);
diff --git a/tests/pthread/specific.c.txt b/tests/pthread/specific.c.txt
index ad122b3d..ce7bef3d 100644
--- a/tests/pthread/specific.c.txt
+++ b/tests/pthread/specific.c.txt
@@ -1,6 +1,8 @@
pthread_key_create = 0
pthread_setspecific = 0
pthread_getspecific = 123
+valid pthread_setspecific for value NULL = 0
+pthread_getspecific = (nil)
pthread_getspecific after key recreate = (nil)
pthread_key_delete = 0
pthread_key_delete repeated = 22