Commit e28778ae authored by Stefan Behnel's avatar Stefan Behnel

Repair and extend TSS API test.

parent 8fdb0fbe
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from cpython.pythread cimport * from cpython.pythread cimport *
def tss_create_delete(): def tss_create_delete():
""" """
>>> tss_create_delete() >>> tss_create_delete()
...@@ -9,29 +10,48 @@ def tss_create_delete(): ...@@ -9,29 +10,48 @@ def tss_create_delete():
""" """
cdef Py_tss_t tss_key = Py_tss_NEEDS_INIT cdef Py_tss_t tss_key = Py_tss_NEEDS_INIT
cdef bint after_create, after_delete cdef bint after_create, after_delete
if PyThread_tss_create(&tss_key) > 0: if PyThread_tss_create(&tss_key) != 0:
# handle key creation failure raise MemoryError()
pass
after_create = PyThread_tss_is_created(&tss_key) != 0 after_create = PyThread_tss_is_created(&tss_key) != 0
PyThread_tss_delete(&tss_key) PyThread_tss_delete(&tss_key)
after_delete = PyThread_tss_is_created(&tss_key) != 0 after_delete = PyThread_tss_is_created(&tss_key) != 0
return (after_create, after_delete) return (after_create, after_delete)
def tss_alloc_free(): def tss_alloc_free():
""" """
>>> tss_alloc_free() >>> tss_alloc_free()
(True, False) False
"""
cdef Py_tss_t *ptr_key
cdef bint after_alloc, after_free
ptr_key = PyThread_tss_alloc()
if ptr_key == NULL:
raise MemoryError()
after_alloc = PyThread_tss_is_created(ptr_key) != 0
PyThread_tss_free(ptr_key)
return after_alloc
def tss_alloc_create_delete_free():
"""
>>> tss_alloc_create_delete_free()
(False, True, False)
""" """
cdef Py_tss_t *ptr_key cdef Py_tss_t *ptr_key
cdef bint after_alloc, after_free cdef bint after_alloc, after_free
ptr_key = PyThread_tss_alloc() ptr_key = PyThread_tss_alloc()
if ptr_key == NULL: if ptr_key == NULL:
# handle key allocation failure raise MemoryError()
pass
after_alloc = PyThread_tss_is_created(ptr_key) != 0 after_alloc = PyThread_tss_is_created(ptr_key) != 0
if PyThread_tss_create(ptr_key) != 0:
raise MemoryError()
after_create = PyThread_tss_is_created(ptr_key) != 0
PyThread_tss_delete(ptr_key)
after_delete = PyThread_tss_is_created(ptr_key) != 0
PyThread_tss_free(ptr_key) PyThread_tss_free(ptr_key)
after_free = PyThread_tss_is_created(ptr_key) != 0 return (after_alloc, after_create, after_delete)
return (after_alloc, after_free)
def tss_set_get(): def tss_set_get():
""" """
...@@ -41,9 +61,8 @@ def tss_set_get(): ...@@ -41,9 +61,8 @@ def tss_set_get():
cdef Py_tss_t tss_key = Py_tss_NEEDS_INIT cdef Py_tss_t tss_key = Py_tss_NEEDS_INIT
cdef int the_value = 1 cdef int the_value = 1
cdef int ret_value cdef int ret_value
if PyThread_tss_create(&tss_key) > 0: if PyThread_tss_create(&tss_key) != 0:
# handle key creation failure raise MemoryError()
pass
if PyThread_tss_get(&tss_key) == NULL: if PyThread_tss_get(&tss_key) == NULL:
PyThread_tss_set(&tss_key, <void *>&the_value) PyThread_tss_set(&tss_key, <void *>&the_value)
ret_value = (<int *>PyThread_tss_get(&tss_key))[0] ret_value = (<int *>PyThread_tss_get(&tss_key))[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment