Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r82628:cca076442762
Date: 2016-03-01 10:35 +0100
http://bitbucket.org/pypy/pypy/changeset/cca076442762/

Log:    Fix import_cffi to also copy the .c and .h files. Re-run it to
        import cffi/5d4960993342.

diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_zintegration.py 
b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_zintegration.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_zintegration.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_zintegration.py
@@ -12,7 +12,7 @@
 def create_venv(name):
     tmpdir = udir.join(name)
     try:
-        subprocess.check_call(['virtualenv', '--distribute',
+        subprocess.check_call(['virtualenv', '--never-download',
                                '-p', os.path.abspath(sys.executable),
                                str(tmpdir)])
     except OSError as e:
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/add1-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/add1-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/add1-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/add1-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 
 extern int add1(int, int);
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/add2-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/add2-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/add2-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/add2-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 
 extern int add1(int, int);
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/embedding/add_recursive-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/add_recursive-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/add_recursive-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/add_recursive-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 
 #ifdef _MSC_VER
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/perf-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/perf-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/perf-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/perf-test.c
@@ -1,10 +1,12 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 #include <assert.h>
 #include <sys/time.h>
 #ifdef PTEST_USE_THREAD
 # include <pthread.h>
-# include <semaphore.h>
-static sem_t done;
+static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t cond1 = PTHREAD_COND_INITIALIZER;
+static int remaining;
 #endif
 
 
@@ -54,8 +56,11 @@
     printf("time per call: %.3g\n", t);
 
 #ifdef PTEST_USE_THREAD
-    int status = sem_post(&done);
-    assert(status == 0);
+    pthread_mutex_lock(&mutex1);
+    remaining -= 1;
+    if (!remaining)
+        pthread_cond_signal(&cond1);
+    pthread_mutex_unlock(&mutex1);
 #endif
 
     return arg;
@@ -68,19 +73,19 @@
     start_routine(0);
 #else
     pthread_t th;
-    int i, status = sem_init(&done, 0, 0);
-    assert(status == 0);
+    int i, status;
 
     add1(0, 0);   /* this is the main thread */
 
+    remaining = PTEST_USE_THREAD;
     for (i = 0; i < PTEST_USE_THREAD; i++) {
         status = pthread_create(&th, NULL, start_routine, NULL);
         assert(status == 0);
     }
-    for (i = 0; i < PTEST_USE_THREAD; i++) {
-        status = sem_wait(&done);
-        assert(status == 0);
-    }
+    pthread_mutex_lock(&mutex1);
+    while (remaining)
+        pthread_cond_wait(&cond1, &mutex1);
+    pthread_mutex_unlock(&mutex1);
 #endif
     return 0;
 }
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread-test.h 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread-test.h
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread-test.h
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread-test.h
@@ -1,10 +1,45 @@
+/* Generated by pypy/tool/import_cffi.py */
 /************************************************************/
 #ifndef _MSC_VER
 /************************************************************/
 
 
 #include <pthread.h>
-#include <semaphore.h>
+
+/* don't include <semaphore.h>, it is not available on OS/X */
+
+typedef struct {
+    pthread_mutex_t mutex1;
+    pthread_cond_t cond1;
+    unsigned int value;
+} sem_t;
+
+static int sem_init(sem_t *sem, int pshared, unsigned int value)
+{
+    assert(pshared == 0);
+    sem->value = value;
+    return (pthread_mutex_init(&sem->mutex1, NULL) ||
+            pthread_cond_init(&sem->cond1, NULL));
+}
+
+static int sem_post(sem_t *sem)
+{
+    pthread_mutex_lock(&sem->mutex1);
+    sem->value += 1;
+    pthread_cond_signal(&sem->cond1);
+    pthread_mutex_unlock(&sem->mutex1);
+    return 0;
+}
+
+static int sem_wait(sem_t *sem)
+{
+    pthread_mutex_lock(&sem->mutex1);
+    while (sem->value == 0)
+        pthread_cond_wait(&sem->cond1, &sem->mutex1);
+    sem->value -= 1;
+    pthread_mutex_unlock(&sem->mutex1);
+    return 0;
+}
 
 
 /************************************************************/
@@ -22,7 +57,7 @@
 typedef HANDLE sem_t;
 typedef HANDLE pthread_t;
 
-int sem_init(sem_t *sem, int pshared, unsigned int value)
+static int sem_init(sem_t *sem, int pshared, unsigned int value)
 {
     assert(pshared == 0);
     assert(value == 0);
@@ -30,26 +65,26 @@
     return *sem ? 0 : -1;
 }
 
-int sem_post(sem_t *sem)
+static int sem_post(sem_t *sem)
 {
     return ReleaseSemaphore(*sem, 1, NULL) ? 0 : -1;
 }
 
-int sem_wait(sem_t *sem)
+static int sem_wait(sem_t *sem)
 {
     WaitForSingleObject(*sem, INFINITE);
     return 0;
 }
 
-DWORD WINAPI myThreadProc(LPVOID lpParameter)
+static DWORD WINAPI myThreadProc(LPVOID lpParameter)
 {
     void *(* start_routine)(void *) = (void *(*)(void *))lpParameter;
     start_routine(NULL);
     return 0;
 }
 
-int pthread_create(pthread_t *thread, void *attr,
-                   void *start_routine(void *), void *arg)
+static int pthread_create(pthread_t *thread, void *attr,
+                          void *start_routine(void *), void *arg)
 {
     assert(arg == NULL);
     *thread = CreateThread(NULL, 0, myThreadProc, start_routine, 0, NULL);
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread1-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread1-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread1-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread1-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 #include <assert.h>
 #include "thread-test.h"
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread2-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread2-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread2-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread2-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 #include <assert.h>
 #include "thread-test.h"
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread3-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread3-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/thread3-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/thread3-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 #include <assert.h>
 #include "thread-test.h"
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/tlocal-test.c 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/tlocal-test.c
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/tlocal-test.c
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/tlocal-test.c
@@ -1,3 +1,4 @@
+/* Generated by pypy/tool/import_cffi.py */
 #include <stdio.h>
 #include <assert.h>
 #include "thread-test.h"
diff --git a/pypy/tool/import_cffi.py b/pypy/tool/import_cffi.py
--- a/pypy/tool/import_cffi.py
+++ b/pypy/tool/import_cffi.py
@@ -7,11 +7,18 @@
 
 import sys, py
 
-def mangle(lines):
-    yield "# Generated by pypy/tool/import_cffi.py\n"
-    for line in lines:
-        line = line.replace('from testing', 'from 
pypy.module.test_lib_pypy.cffi_tests')
-        yield line
+def mangle(lines, ext):
+    if ext == '.py':
+        yield "# Generated by pypy/tool/import_cffi.py\n"
+        for line in lines:
+            line = line.replace('from testing', 'from 
pypy.module.test_lib_pypy.cffi_tests')
+            yield line
+    elif ext in ('.c', '.h'):
+        yield "/* Generated by pypy/tool/import_cffi.py */\n"
+        for line in lines:
+            yield line
+    else:
+        raise AssertionError(ext)
 
 def main(cffi_dir):
     cffi_dir = py.path.local(cffi_dir)
@@ -23,10 +30,12 @@
     for p in (list(cffi_dir.join('cffi').visit(fil='*.py')) +
               list(cffi_dir.join('cffi').visit(fil='*.h'))):
         cffi_dest.join('..', p.relto(cffi_dir)).write(p.read())
-    for p in cffi_dir.join('testing').visit(fil='*.py'):
+    for p in (list(cffi_dir.join('testing').visit(fil='*.py')) +
+              list(cffi_dir.join('testing').visit(fil='*.h')) +
+              list(cffi_dir.join('testing').visit(fil='*.c'))):
         path = test_dest.join(p.relto(cffi_dir.join('testing')))
         path.join('..').ensure(dir=1)
-        path.write(''.join(mangle(p.readlines())))
+        path.write(''.join(mangle(p.readlines(), p.ext)))
 
 if __name__ == '__main__':
     if len(sys.argv) != 2:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to