From nobody@FreeBSD.org  Wed Jul 21 01:19:29 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E71FD106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Jul 2010 01:19:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id BCA548FC18
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Jul 2010 01:19:29 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o6L1JSxg014477
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 21 Jul 2010 01:19:28 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o6L1JSH3014476;
	Wed, 21 Jul 2010 01:19:28 GMT
	(envelope-from nobody)
Message-Id: <201007210119.o6L1JSH3014476@www.freebsd.org>
Date: Wed, 21 Jul 2010 01:19:28 GMT
From: Tom Uffner <tom@uffner.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: graphics/gdal - Thread support broken
X-Send-Pr-Version: www-3.1
X-GNATS-Notify: sunpoet@sunpoet.net

>Number:         148804
>Category:       ports
>Synopsis:       graphics/gdal - Thread support broken
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 21 01:20:03 UTC 2010
>Closed-Date:    Wed Sep 15 09:18:34 UTC 2010
>Last-Modified:  Wed Sep 15 09:18:34 UTC 2010
>Originator:     Tom Uffner
>Release:        9-current
>Organization:
>Environment:
FreeBSD xiombarg.uffner.com 9.0-CURRENT FreeBSD 9.0-CURRENT #157: Tue Jun  8 03:26:06 EDT 2010     root@xiombarg.uffner.com:/usr/obj/usr/src/sys/XIOMBARG  i386
>Description:
The port makefile has a config knob for "Thread support". When this is enabled, the port fails to build:

cpl_multiproc.cpp:735:2: error: #error "Recursive mutexes apparently unsupported, configure --without-threads"
gmake[1]: *** [cpl_multiproc.o] Error 1
gmake[1]: Leaving directory `/usr/ports/graphics/gdal/work/gdal-1.6.0/port'
gmake: *** [port-target] Error 2
*** Error code 1

the problem appears to be a Linuxism in cpl_multiproc.cpp where it checks if recursive mutexes are supported. They are (and have been since 1998) but the test fails due to non-portable coding. In BSD derived PThreads implementations, since 1996, pthread mutex types are defined as an enum, not a C pre-processor macro (currently at line 128 of /usr/include/pthread.h). The comment immediatly above implies, though I haven't checked, that this syntax was standardized in SUSv2.

deleting or altering the "#if defined(PTHREAD_MUTEX_RECURSIVE)" test so that the #error is not triggered allows the package to build with thread support.
>How-To-Repeat:
% cd /usr/ports/graphics/gdal
% make config

check the "Thread support" box

% make all

build will fail as shown above
>Fix:
This really should be fixed upstream by the GDAL project since they claim to support BSD, but adding the attached patch to the FreeBSD port is a workaround.

Patch attached with submission follows:

--- port/cpl_multiproc.cpp.orig	2010-07-20 21:06:43.000000000 -0400
+++ port/cpl_multiproc.cpp	2010-07-20 21:07:47.000000000 -0400
@@ -721,19 +721,12 @@
 
     hMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
 
-#if defined(PTHREAD_MUTEX_RECURSIVE)
     {
         pthread_mutexattr_t  attr;
         pthread_mutexattr_init( &attr );
         pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE );
         pthread_mutex_init( hMutex, &attr );
     }
-#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
-    pthread_mutex_t tmp_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-    *hMutex = tmp_mutex;
-#else
-#error "Recursive mutexes apparently unsupported, configure --without-threads" 
-#endif
 
     // mutexes are implicitly acquired when created.
     CPLAcquireMutex( hMutex, 0.0 );


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Wed Jul 21 01:20:18 UTC 2010 
State-Changed-Why:  
Awaiting maintainers feedback (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148804 

From: Edwin Groothuis <edwin@FreeBSD.org>
To: sunpoet@sunpoet.net
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/148804: graphics/gdal - Thread support broken
Date: Wed, 21 Jul 2010 01:20:17 UT

 Maintainer of graphics/gdal,
 
 Please note that PR ports/148804 has just been submitted.
 
 If it contains a patch for an upgrade, an enhancement or a bug fix
 you agree on, reply to this email stating that you approve the patch
 and a committer will take care of it.
 
 The full text of the PR can be found at:
     http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/148804
 
 -- 
 Edwin Groothuis via the GNATS Auto Assign Tool
 edwin@FreeBSD.org
Responsible-Changed-From-To: freebsd-ports-bugs->glebius 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Sep 13 06:58:23 UTC 2010 
Responsible-Changed-Why:  
Over to new maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148804 

From: Gleb Smirnoff <glebius@FreeBSD.org>
To: Tom Uffner <tom@uffner.com>
Cc: sunpoet@sunpoet.net, freebsd-ports-bugs@FreeBSD.org
Subject: Re: ports/148804: graphics/gdal - Thread support broken
Date: Mon, 13 Sep 2010 12:45:51 +0400

   Hello, Tom!
 
   I remember a problem like this, that I've encountered some time
 ago, but now port builds fine.
 
   I suppose, that your 9-CURRENT from June 8 has some breakage
 in headers. Newer CURRENT is more compatible with this linuxism.
 
   Can you try to upgrade?
 
 -- 
 Totus tuus, Glebius.

From: Tom Uffner <tom@uffner.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/148804: graphics/gdal - Thread support broken
Date: Tue, 14 Sep 2010 16:53:19 -0400

 According to either SVN or CVS, the header file that this port fails to
 compile against (/usr/include/pthread.h) has not been changed since 
 2009-03-14. And, like i said in the original PR, the particular section
 of said header file that it fails on has not been modified in 11 years.
 
 I could update to today's -current and try to build it, but unless the
 port or the upstream source tarball has been changed it would be a futile
 and pointless exercise.
 
 Furthermore, I would strongly object to the FreeBSD project putting any
 effort into chasing Linux compatibility in long established code that is
 already standards compliant. As I stated, this bug is the fault of the
 GDAL project and should most properly be resolved there, I merely proposed
 a workaround until they update their codebase to reflect changes that
 occurred more than a decade ago.
 
 tom

From: Tom Uffner <tom@uffner.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/148804: graphics/gdal - Thread support broken
Date: Tue, 14 Sep 2010 17:15:55 -0400

 I just noticed that a few weeks after I submitted this PR, someone
 (possibly you), updated both the port and the GDAL source version and
 that one of those changes eliminated the problem with thread support.
 
 you may as well close this PR since it has now been rendered irrelevant.
 
 thanks,
 tom
State-Changed-From-To: feedback->closed 
State-Changed-By: glebius 
State-Changed-When: Wed Sep 15 09:18:07 UTC 2010 
State-Changed-Why:  
The bug is irrelevant for the recent version of GDAL. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148804 
>Unformatted:
