From owner-freebsd-python@FreeBSD.ORG  Thu Mar 12 11:07:29 2009
Return-Path: <owner-freebsd-python@FreeBSD.ORG>
Delivered-To: python@FreeBSD.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 1322B106566B;
	Thu, 12 Mar 2009 11:07:29 +0000 (UTC)
	(envelope-from bms@incunabulum.net)
Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com
	[66.111.4.25]) by mx1.freebsd.org (Postfix) with ESMTP id D92DA8FC08;
	Thu, 12 Mar 2009 11:07:28 +0000 (UTC)
	(envelope-from bms@incunabulum.net)
Received: from compute1.internal (compute1.internal [10.202.2.41])
	by out1.messagingengine.com (Postfix) with ESMTP id 7F9EB2ED999;
	Thu, 12 Mar 2009 07:07:28 -0400 (EDT)
Received: from heartbeat1.messagingengine.com ([10.202.2.160])
	by compute1.internal (MEProxy); Thu, 12 Mar 2009 07:07:28 -0400
X-Sasl-enc: hO0gsfl/uI64YE0XwgwC1JLpIB7xkEwt26w4lPHFzhow 1236856048
Received: from anglepoise.lon.incunabulum.net
	(82-35-112-254.cable.ubr07.dals.blueyonder.co.uk [82.35.112.254])
	by mail.messagingengine.com (Postfix) with ESMTPSA id D05833D0D;
	Thu, 12 Mar 2009 07:07:27 -0400 (EDT)
Message-ID: <49B8ECEE.801@incunabulum.net>
Date: Thu, 12 Mar 2009 11:07:26 +0000
From: Bruce Simpson <bms@incunabulum.net>
User-Agent: Thunderbird 2.0.0.19 (X11/20090125)
MIME-Version: 1.0
To: python@FreeBSD.org
References: <49B8E7D8.3010606@incunabulum.net>
In-Reply-To: <49B8E7D8.3010606@incunabulum.net>
Content-Type: multipart/mixed; boundary="------------010909040601040402010606"
Cc: John Baldwin <jhb@freebsd.org>
Subject: Re: Regarding HAVE_BROKEN_POSIX_SEMAPHORES
X-BeenThere: freebsd-python@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: FreeBSD-specific Python issues <freebsd-python.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-python>, 
	<mailto:freebsd-python-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-python>
List-Post: <mailto:freebsd-python@freebsd.org>
List-Help: <mailto:freebsd-python-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-python>,
	<mailto:freebsd-python-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 12 Mar 2009 11:07:29 -0000

This is a multi-part message in MIME format.
--------------010909040601040402010606
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Bruce Simpson wrote:
> Hi,
>
> If any of you can find the time, could you try applying rev 189736 of 
> uipc_sem.c and patching Python to be built *without* defining 
> HAVE_BROKEN_POSIX_SEMAPHORES in ${WRKSRC}/Python/thread_pthread.h ?
...

Here is a patch for some of the issues in the Python 2.6 port I have 
been working through.

With this patch you should be able to run test_threading.py successfully 
on FreeBSD 7-STABLE,
although the fork-from-thread problem still exists.

This ran OK for me, I imagine it could benefit from your expert examination!

It appears there may be a resource leak in uipc_sem.c not cleaning up 
after signal termination,
I'm Cc'ing jhb@ as he may know more about this than I do.

cheers,
BMS

--------------010909040601040402010606
Content-Type: text/plain;
 name="python-semaphores.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="python-semaphores.patch"

? .swp
? work
? files/__orig__patch-Python_thread__pthread.h
Index: Makefile
===================================================================
RCS file: /home/pcvs/ports/lang/python26/Makefile,v
retrieving revision 1.156
diff -u -p -r1.156 Makefile
--- Makefile	27 Feb 2009 01:25:31 -0000	1.156
+++ Makefile	12 Mar 2009 11:04:20 -0000
@@ -57,6 +57,10 @@ OPTIONS=	THREADS "Enable thread support"
 
 .include <bsd.port.pre.mk>
 
+.if ${OSVERSION} >= 700000
+EXTRA_PATCHES+=	${PATCHDIR}/extra-patch-setup.py
+.endif
+
 .if ${PYTHON_VERSION} == ${PYTHON_DEFAULT_VERSION}
 MLINKS=		${PYTHON_VERSION}.1 python.1
 PLIST_SUB+=	IF_DEFAULT=""
Index: files/extra-patch-setup.py
===================================================================
RCS file: files/extra-patch-setup.py
diff -N files/extra-patch-setup.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ files/extra-patch-setup.py	12 Mar 2009 11:04:20 -0000
@@ -0,0 +1,26 @@
+--- setup.py.1	2009-03-12 04:07:36.000000000 +0000
++++ setup.py	2009-03-12 04:08:36.000000000 +0000
+@@ -1265,13 +1265,21 @@
+                 )
+             libraries = []
+ 
+-        elif platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
++        elif platform in ('freebsd4', 'freebsd5', 'freebsd6'):
+             # FreeBSD's P1003.1b semaphore support is very experimental
+             # and has many known problems. (as of June 2008)
+-            macros = dict(                  # FreeBSD
++            macros = dict(                  # FreeBSD 4-6
+                 HAVE_SEM_OPEN=0,
+                 HAVE_SEM_TIMEDWAIT=0,
+                 HAVE_FD_TRANSFER=1,
++                )
++            libraries = []
++
++        elif platform in ('freebsd7', 'freebsd8'):
++            macros = dict(                  # FreeBSD 7+
++                HAVE_SEM_OPEN=1,
++                HAVE_SEM_TIMEDWAIT=1,
++                HAVE_FD_TRANSFER=1,
+                 )
+             libraries = []
+ 
Index: files/patch-Lib_test_test_threading.py
===================================================================
RCS file: files/patch-Lib_test_test_threading.py
diff -N files/patch-Lib_test_test_threading.py
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ files/patch-Lib_test_test_threading.py	12 Mar 2009 11:04:20 -0000
@@ -0,0 +1,11 @@
+--- Lib/test/test_threading.py.bak	2009-03-12 07:59:17.000000000 +0000
++++ Lib/test/test_threading.py	2009-03-12 10:48:04.000000000 +0000
+@@ -382,7 +382,7 @@
+             return
+         # Skip platforms with known problems forking from a worker thread.
+         # See http://bugs.python.org/issue3863.
+-        if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'):
++        if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8', 'os2emx'):
+             print >>sys.stderr, ('Skipping test_3_join_in_forked_from_thread'
+                                  ' due to known OS bugs on'), sys.platform
+             return
Index: files/patch-Python_thread__pthread.h
===================================================================
RCS file: /home/pcvs/ports/lang/python26/files/patch-Python_thread__pthread.h,v
retrieving revision 1.1
diff -u -p -r1.1 patch-Python_thread__pthread.h
--- files/patch-Python_thread__pthread.h	27 Feb 2009 01:25:32 -0000	1.1
+++ files/patch-Python_thread__pthread.h	12 Mar 2009 11:04:20 -0000
@@ -1,9 +1,34 @@
-
-$FreeBSD: ports/lang/python26/files/patch-Python_thread__pthread.h,v 1.1 2009/02/27 01:25:32 sobomax Exp $
-
---- Python/thread_pthread.h
-+++ Python/thread_pthread.h
-@@ -149,6 +149,7 @@
+--- Python/thread_pthread.h.orig	2006-06-13 16:04:24.000000000 +0100
++++ Python/thread_pthread.h	2009-03-12 10:55:49.000000000 +0000
+@@ -26,13 +26,18 @@
+ #endif
+ #endif
+ 
++#ifdef __FreeBSD__
++#include <osreldate.h>
++#endif
++
+ /* The POSIX spec says that implementations supporting the sem_*
+    family of functions must indicate this by defining
+    _POSIX_SEMAPHORES. */   
+ #ifdef _POSIX_SEMAPHORES
+ /* On FreeBSD 4.x, _POSIX_SEMAPHORES is defined empty, so 
+    we need to add 0 to make it work there as well. */
+-#if (_POSIX_SEMAPHORES+0) == -1
++#if defined(__FreeBSD__) && __FreeBSD_version < 701104 && \
++    (_POSIX_SEMAPHORES+0) == -1
+ #define HAVE_BROKEN_POSIX_SEMAPHORES
+ #else
+ #include <semaphore.h>
+@@ -44,7 +49,6 @@
+    in default setting.  So the process scope is preferred to get
+    enough number of threads to work. */
+ #ifdef __FreeBSD__
+-#include <osreldate.h>
+ #if __FreeBSD_version >= 500000 && __FreeBSD_version < 504101
+ #undef PTHREAD_SYSTEM_SCHED_SUPPORTED
+ #endif
+@@ -149,6 +153,7 @@
  {
  	pthread_t th;
  	int status;
@@ -11,7 +36,7 @@ $FreeBSD: ports/lang/python26/files/patc
  #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
  	pthread_attr_t attrs;
  #endif
-@@ -177,6 +178,8 @@
+@@ -177,6 +182,8 @@
  #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
          pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
  #endif
@@ -20,7 +45,7 @@ $FreeBSD: ports/lang/python26/files/patc
  
  	status = pthread_create(&th, 
  #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
-@@ -188,6 +191,7 @@
+@@ -188,6 +195,7 @@
  				 (void *)arg
  				 );
  

--------------010909040601040402010606--