[pypy-svn] pypy default: Fix the tests about PyThread_acquire_lock and PyThread_release_lock
amauryfa
commits-noreply at bitbucket.org
Mon Mar 21 23:21:21 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r42834:00f07d6abcc0
Date: 2011-03-21 23:13 +0100
http://bitbucket.org/pypy/pypy/changeset/00f07d6abcc0/
Log: Fix the tests about PyThread_acquire_lock and PyThread_release_lock
diff --git a/pypy/module/cpyext/include/pythread.h b/pypy/module/cpyext/include/pythread.h
--- a/pypy/module/cpyext/include/pythread.h
+++ b/pypy/module/cpyext/include/pythread.h
@@ -0,0 +1,8 @@
+#ifndef Py_PYTHREAD_H
+#define Py_PYTHREAD_H
+
+typedef void *PyThread_type_lock;
+#define WAIT_LOCK 1
+#define NOWAIT_LOCK 0
+
+#endif
diff --git a/pypy/module/cpyext/thread.py b/pypy/module/cpyext/thread.py
--- a/pypy/module/cpyext/thread.py
+++ b/pypy/module/cpyext/thread.py
@@ -1,13 +1,22 @@
from pypy.module.thread import ll_thread
from pypy.module.cpyext.api import CANNOT_FAIL, cpython_api
-from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import lltype, rffi
@cpython_api([], rffi.LONG, error=CANNOT_FAIL)
def PyThread_get_thread_ident(space):
return ll_thread.get_ident()
+LOCKP = rffi.COpaquePtr(typedef='PyThread_type_lock')
-# @cpython_api([ll_thread.TLOCKP, rffi.INT], rffi.INT, error=CANNOT_FAIL)
-# def PyThread_acquire_lock(space, lock, waitflag):
-# return ll_thread.Lock(lock).acquire(waitflag)
+ at cpython_api([LOCKP, rffi.INT], rffi.INT, error=CANNOT_FAIL)
+def PyThread_acquire_lock(space, lock, waitflag):
+ lock = rffi.cast(ll_thread.TLOCKP, lock)
+ return ll_thread.c_thread_acquirelock(lock, waitflag)
+
+ at cpython_api([LOCKP], lltype.Void)
+def PyThread_release_lock(space, lock):
+ lock = rffi.cast(ll_thread.TLOCKP, lock)
+ ll_thread.c_thread_releaselock(lock)
+
+
diff --git a/pypy/module/cpyext/include/Python.h b/pypy/module/cpyext/include/Python.h
--- a/pypy/module/cpyext/include/Python.h
+++ b/pypy/module/cpyext/include/Python.h
@@ -119,6 +119,7 @@
#include "pystate.h"
#include "fileobject.h"
#include "pysignals.h"
+#include "pythread.h"
// XXX This shouldn't be included here
#include "structmember.h"
diff --git a/pypy/module/cpyext/test/test_thread.py b/pypy/module/cpyext/test/test_thread.py
--- a/pypy/module/cpyext/test/test_thread.py
+++ b/pypy/module/cpyext/test/test_thread.py
@@ -24,17 +24,15 @@
assert results[0][0] != results[1][0]
- @py.test.mark.xfail
def test_acquire_lock(self, space, api):
assert hasattr(api, 'PyThread_acquire_lock')
lock = allocate_ll_lock()
- assert api.PyThread_acquire_lock(lock, space.w_int(0)) == 1
- assert api.PyThread_acquire_lock(lock, space.w_int(1)) == 0
+ assert api.PyThread_acquire_lock(lock, 1) == 1
+ assert api.PyThread_acquire_lock(lock, 0) == 0
- @py.test.mark.xfail
def test_release_lock(self, space, api):
assert hasattr(api, 'PyThread_acquire_lock')
lock = allocate_ll_lock()
- api.PyThread_acquire_lock(lock, space.w_int(0))
+ api.PyThread_acquire_lock(lock, 1)
api.PyThread_release_lock(lock)
- assert api.PyThread_acquire_lock(lock, space.w_int(0)) == 1
+ assert api.PyThread_acquire_lock(lock, 0) == 1
More information about the Pypy-commit
mailing list