Skip to content

Commit 1ebbb2b

Browse files
committed
fixes to make multiprocessing compile and work (wip)
- remove _multiprocessing from blacklist - add patches to change way semaphores are used in queues - change test for HAVE_BROCKEN_SEM_GETVALUE - add flush() method to LogFile class - add patches to pyton recipe
1 parent 0cf6e14 commit 1ebbb2b

File tree

6 files changed

+136
-1
lines changed

6 files changed

+136
-1
lines changed

recipes/python/patches/disable-modules.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# This global variable is used to hold the list of modules to be disabled.
77
-disabled_module_list = []
8-
+disabled_module_list = ['spwd', '_ctypes','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt','_multiprocessing']
8+
+disabled_module_list = ['spwd', '_ctypes','bz2','ossaudiodev','_curses','_curses_panel','readline','_locale','_bsddb','gdbm','dbm','nis','linuxaudiodev','crypt']
99

1010
def add_dir_to_list(dirlist, dir):
1111
"""Add the directory 'dir' to the list 'dirlist' (at the front) if
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- Python-2.7.2/Modules/_multiprocessing/multiprocessing.c.orig 2011-06-11 17:46:27.000000000 +0200
2+
+++ Python-2.7.2/Modules/_multiprocessing/multiprocessing.c 2012-11-01 01:34:34.172297156 +0100
3+
@@ -122,7 +122,7 @@
4+
cmsg->cmsg_type = SCM_RIGHTS;
5+
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
6+
msg.msg_controllen = cmsg->cmsg_len;
7+
- *CMSG_DATA(cmsg) = fd;
8+
+ *(int*)CMSG_DATA(cmsg) = fd;
9+
10+
Py_BEGIN_ALLOW_THREADS
11+
res = sendmsg(conn, &msg, 0);
12+
@@ -165,7 +165,7 @@
13+
if (res < 0)
14+
return PyErr_SetFromErrno(PyExc_OSError);
15+
16+
- fd = *CMSG_DATA(cmsg);
17+
+ fd = *(int*)CMSG_DATA(cmsg);
18+
return Py_BuildValue("i", fd);
19+
}
20+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--- Python-2.7.2/configure.in.orig 2012-11-01 19:09:33.586433845 +0100
2+
+++ Python-2.7.2/configure.in 2012-11-01 19:10:26.390692009 +0100
3+
@@ -3611,15 +3611,13 @@
4+
#include <semaphore.h>
5+
#include <sys/stat.h>
6+
7+
-int main(void) {
8+
- sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
9+
- if (a == SEM_FAILED) {
10+
- perror("sem_open");
11+
- return 1;
12+
- }
13+
- sem_close(a);
14+
- sem_unlink("/autoconf");
15+
- return 0;
16+
+int main(void){
17+
+ sem_t a;
18+
+ sem_init(&a, PTHREAD_PROCESS_PRIVATE, 0);
19+
+ int count;
20+
+ int res;
21+
+ res = sem_getvalue(&a, &count);
22+
+ return res==-1 ? 1 : 0;
23+
}
24+
]])],
25+
[ac_cv_posix_semaphores_enabled=yes],
26+
@@ -3644,18 +3642,12 @@
27+
#include <sys/stat.h>
28+
29+
int main(void){
30+
- sem_t *a = sem_open("/autocftw", O_CREAT, S_IRUSR|S_IWUSR, 0);
31+
- int count;
32+
- int res;
33+
- if(a==SEM_FAILED){
34+
- perror("sem_open");
35+
- return 1;
36+
-
37+
- }
38+
- res = sem_getvalue(a, &count);
39+
- sem_close(a);
40+
- sem_unlink("/autocftw");
41+
- return res==-1 ? 1 : 0;
42+
+ sem_t a;
43+
+ sem_init(&a, PTHREAD_PROCESS_PRIVATE, 0);
44+
+ int count;
45+
+ int res;
46+
+ res = sem_getvalue(&a, &count);
47+
+ return res==-1 ? 1 : 0;
48+
}
49+
]])],
50+
[ac_cv_broken_sem_getvalue=no],
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--- Python-2.7.2/Modules/_multiprocessing/semaphore.c.orig 2012-11-01 21:52:08.729279756 +0100
2+
+++ Python-2.7.2/Modules/_multiprocessing/semaphore.c 2012-11-01 22:09:20.037257214 +0100
3+
@@ -35,7 +35,6 @@
4+
#define SEM_CREATE(name, val, max) CreateSemaphore(NULL, val, max, NULL)
5+
#define SEM_CLOSE(sem) (CloseHandle(sem) ? 0 : -1)
6+
#define SEM_GETVALUE(sem, pval) _GetSemaphoreValue(sem, pval)
7+
-#define SEM_UNLINK(name) 0
8+
9+
static int
10+
_GetSemaphoreValue(HANDLE handle, long *value)
11+
@@ -192,14 +191,32 @@
12+
13+
#define SEM_CLEAR_ERROR()
14+
#define SEM_GET_LAST_ERROR() 0
15+
-#define SEM_CREATE(name, val, max) sem_open(name, O_CREAT | O_EXCL, 0600, val)
16+
-#define SEM_CLOSE(sem) sem_close(sem)
17+
#define SEM_GETVALUE(sem, pval) sem_getvalue(sem, pval)
18+
-#define SEM_UNLINK(name) sem_unlink(name)
19+
20+
-#ifndef HAVE_SEM_UNLINK
21+
-# define sem_unlink(name) 0
22+
-#endif
23+
+static sem_t*
24+
+SEM_CREATE(const char *name, int val, int max)
25+
+{
26+
+ sem_t *sem = malloc(sizeof *sem);
27+
+
28+
+ if (sem == NULL)
29+
+ goto failure;
30+
+
31+
+ if (sem_init(sem, 0, val) == -1)
32+
+ goto failure;
33+
+
34+
+ return sem;
35+
+
36+
+failure:
37+
+ return SEM_FAILED;
38+
+}
39+
+
40+
+static int
41+
+SEM_CLOSE(sem_t *sem)
42+
+{
43+
+ int status = sem_destroy(sem);
44+
+ free(sem);
45+
+ return status;
46+
+}
47+
48+
#ifndef HAVE_SEM_TIMEDWAIT
49+
# define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save)
50+
@@ -441,9 +458,6 @@
51+
if (handle == SEM_FAILED || SEM_GET_LAST_ERROR() != 0)
52+
goto failure;
53+
54+
- if (SEM_UNLINK(buffer) < 0)
55+
- goto failure;
56+
-
57+
result = newsemlockobject(type, handle, kind, maxvalue);
58+
if (!result)
59+
goto failure;

recipes/python/recipe.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ function prebuild_python() {
3030
try patch -p1 < $RECIPE_python/patches/fix-remove-corefoundation.patch
3131
try patch -p1 < $RECIPE_python/patches/fix-dynamic-lookup.patch
3232

33+
try patch -p1 < $RECIPE_python/patches/fix-multiprocessing.patch
34+
try patch -p1 < $RECIPE_python/patches/fix-semaphore.patch
35+
try patch -p1 < $RECIPE_python/patches/fix-semaphore-test.patch
36+
3337
system=$(uname -s)
3438
if [ "X$system" == "XDarwin" ]; then
3539
try patch -p1 < $RECIPE_python/patches/fix-configure-darwin.patch

src/jni/application/python/start.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ int main(int argc, char **argv) {
8686
" for l in lines[:-1]:\n" \
8787
" androidembed.log(l)\n" \
8888
" self.buffer = lines[-1]\n" \
89+
" def flush(self):\n" \
90+
" return\n" \
8991
"sys.stdout = sys.stderr = LogFile()\n" \
9092
"import site; print site.getsitepackages()\n"\
9193
"print 'Android path', sys.path\n" \

0 commit comments

Comments
 (0)