[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-11-06 Thread redi at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



Jonathan Wakely redi at gcc dot gnu.org changed:



   What|Removed |Added



 Status|NEW |RESOLVED

 Resolution||FIXED



--- Comment #48 from Jonathan Wakely redi at gcc dot gnu.org 2012-11-06 
11:35:22 UTC ---

Fixed for 4.8


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-10 Thread redi at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



Jonathan Wakely redi at gcc dot gnu.org changed:



   What|Removed |Added



   Target Milestone|--- |4.8.0



--- Comment #47 from Jonathan Wakely redi at gcc dot gnu.org 2012-10-10 
23:19:56 UTC ---

should be fixed on trunk, by

http://gcc.gnu.org/ml/gcc-cvs/2012-10/msg00457.html


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread redi at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



Jonathan Wakely redi at gcc dot gnu.org changed:



   What|Removed |Added



 Status|UNCONFIRMED |NEW

   Last reconfirmed||2012-10-08

Summary|--enable-libstdcxx-time=yes |--enable-libstdcxx-time=yes

   |doesn't find the functional |doesn't find the function

   |nanosleep() on darwin   |nanosleep() on darwin

 Ever Confirmed|0   |1



--- Comment #37 from Jonathan Wakely redi at gcc dot gnu.org 2012-10-08 
16:47:46 UTC ---

(In reply to comment #36)

 (In reply to comment #33)

 

  So is _GLIBCXX_USE_SCHED_YIELD defined on darwin?

 

 Yes, passing --enable-libstdcxx-time=yes and allowing nanosleep() to be found 

 on darwin also results in...

 

 ./c++/4.8.0/x86_64-apple-darwin12.2.0/bits/c++config.h:#define

 _GLIBCXX_USE_SCHED_YIELD 1

 ./c++/4.8.0/x86_64-apple-darwin12.2.0/i386/bits/c++config.h:#define

 _GLIBCXX_USE_SCHED_YIELD 1



The check for sched_yield has nothing to do with nanosleep, that must have

always ben defined.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread howarth at nitro dot med.uc.edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #38 from Jack Howarth howarth at nitro dot med.uc.edu 2012-10-08 
17:03:39 UTC ---

I assume the option of using...



Index: libstdc++-v3/config/os/bsd/darwin/os_defines.h

===

--- libstdc++-v3/config/os/bsd/darwin/os_defines.h(revision 192213)

+++ libstdc++-v3/config/os/bsd/darwin/os_defines.h(working copy)

@@ -42,4 +42,8 @@

 // Static initializer macro is buggy in darwin, see libstdc++/51906

 #define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC



+// Use nanosleep and sched_yield in libc for C++11 standard.

+#define _GLIBCXX_USE_NANOSLEEP 1

+#define _GLIBCXX_USE_SCHED_YIELD 1

+

 #endif



...eliminates our ability to toggle this support off with

--disable-libstdcxx-time, right? This is my only concern with this approach

versus the patch in comment 32;


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread redi at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #39 from Jonathan Wakely redi at gcc dot gnu.org 2012-10-08 
17:16:13 UTC ---

Yes, but why do you want to disable it?



Why does that patch define _GLIBCXX_USE_SCHED_YIELD?

That is correctly detected anyway by configure, without any changes, as I said

in comment 30 and again in comment 37


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread jeremyhu at macports dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #40 from Jeremy Huddleston Sequoia jeremyhu at macports dot org 
2012-10-08 18:33:37 UTC ---

(In reply to comment #25)

 N.B. prior to POSIX 2008 nanosleep was part of the Timers option, if OS X

 supports that it should define _POSIX_TIMERS to 0, -1 or 200112L to indicate

 it's supported.  POSIX 2008 moves the Timers functionality to the Base spec,

 and requires that _POSIX_TIMERS is defined to 200809L. In eiher case, a POSIX

 system supporting nanosleep should define _POSIX_TIMERS.



It is defined to -1 because OS X does not support all that _POSIX_TIMERS

entails.



I still don't see why the _POSIX_TIMERS  0 check exists at all.  On systems

that don't have it, the tests will simply fail because timespec or nanosleep

are undefined.



 The configure checks are based on well-documented, publicly-available

 standards, please try to understand them instead of proposing patches based on

 the misunderstanding that adding struct makes any difference to anything.



I very much understand the standards, and I've provided a link to them.  The

standard itself does not require _POSIX_TIMERS to be defined for nanosleep to

be supported, and it specifically states 'struct timespec' in the function

prototype.



(In reply to comment #26)

  If Apple or anyone else wants it to work

 otherwise they need to do the work, as GCC maintainers have no reason to do

 support building parts of GCC without GCC!



Apple is fully committed to libc++.  If anyone wants libstdc++ to work on

Darwin, it is clear that it will need to be a community effort.



(In reply to comment #29)

 _POSIX_TIMERS=200112L would mean darwin provides a pre-2008 nanosleep, -1 
 means

 the Timers option is not supported.



Yes, it is not *fully* supported.



  Or are you going to demand that the use of pre-2008 POSIX nanosleep() be 
  only

  accepted on a target-specific basis?

 

 There are plenty of systems with a 2001 nanosleep that define _POSIX_TIMERS to

 20112L, but darwin seems to support nanosleep without the rest of the Timers

 option.  I don't want to remove the correct check for _POSIX_TIMERS just for

 one system's peculiarities.



It's not one system.  You are misreading the spec.  _POSIX_TIMERS  0 implies

that all the functionality is available.  That is the only thing you can deduce

from that check.  It is perfectly valid to have a conforming nanosleep with

_POSIX_TIMERS = -1.



Why are you even othering to put that code inside of a _POSIX_TIMERS  0 check.

 If _POSIX_TIMERS  0, you're guaranteed (by the standard) to have that

functionality, so there's no point in checking... if you want to support all

platforms, it's better to just check for nanosleep directly without the

_POSIX_TIMERS check.



(In reply to comment #39)

 Yes, but why do you want to disable it?

 

 Why does that patch define _GLIBCXX_USE_SCHED_YIELD?



I think his patch has no effect on _GLIBCXX_USE_SCHED_YIELD ... I think he

wasn't seeing _GLIBCXX_USE_SCHED_YIELD before because of a mistype he was

having with the configure option.



With Rob's patch, I see both _GLIBCXX_USE_SCHED_YIELD and

_GLIBCXX_USE_NANOSLEEP defined to 1.



 That is correctly detected anyway by configure, without any changes, as I said

 in comment 30 and again in comment 37



Yes, it is.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread redi at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #41 from Jonathan Wakely redi at gcc dot gnu.org 2012-10-08 
19:50:21 UTC ---

(In reply to comment #40)

 I still don't see why the _POSIX_TIMERS  0 check exists at all.  On systems

 that don't have it, the tests will simply fail because timespec or nanosleep

 are undefined.



The existence of a function called nanosleep doesn't mean it's the right one,

or that it will be found at link time, or available at run-time.



Checking _POSIX_TIMERS  0 means the functionality is actually usable, without

checking sysconf() at run-time as described by POSIX.1b-2001.



  The configure checks are based on well-documented, publicly-available

  standards, please try to understand them instead of proposing patches based 
  on

  the misunderstanding that adding struct makes any difference to anything.

 

 I very much understand the standards, and I've provided a link to them.



(That was a link to clock_nanosleep not nanosleep, which was a different

option, not Timers ;)

That comment wasn't aimed at you...



  The

 standard itself does not require _POSIX_TIMERS to be defined for nanosleep to

 be supported, and it specifically states 'struct timespec' in the function

 prototype.



... but you do still seem to doubt that the struct is unnecessary in C++. 

Maybe you've noticed how you don't need to say:



   class std::string str = a string;

   ^

to use C++ classes. It's the same for structs.



 (In reply to comment #26)

   If Apple or anyone else wants it to work

  otherwise they need to do the work, as GCC maintainers have no reason to do

  support building parts of GCC without GCC!

 

 Apple is fully committed to libc++.  If anyone wants libstdc++ to work on

 Darwin, it is clear that it will need to be a community effort.



Again, there's a difference between *working* (i.e. being usable) on darwin and

being able to build libstdc++ with a different compiler.  There is no

requirement to be able to configure libstdc++ with anything other than G++, but

in any case I assure you that clang++ doesn't require the 'struct' keyword

either.





 It's not one system.  You are misreading the spec.



No I'm not, my words you quoted carefully made the distinction of saying -1

means the Timers option is not supported, not that nanosleep is not supported:



  _POSIX_TIMERS=200112L would mean darwin provides a pre-2008 nanosleep, -1 
  means

  the Timers option is not supported.



(I was admittedly less careful in comment 25, sorry)



I'd be happy to improve the test to support other systems, but the patches

posted to this PR so far have been unacceptable due to failing to understand

the existing checks, failing to meet libstdc++'s configury conventions, or

adding support for a single system rather than for any systems which provide

nanosleep without the rest of the Timers option.  In the absence of a decent

patch I suggest defining the HAVE_NANOSLEEP macro in os_defines.h and moving

on.





 Why are you even othering to put that code inside of a _POSIX_TIMERS  0 
 check.

  If _POSIX_TIMERS  0, you're guaranteed (by the standard) to have that

 functionality, so there's no point in checking...



The existence of a preprocessor symbol doesn't tell you whether you need to

link to a particular library to use the function.



The check is AC_TRY_LINK which will ensure not only is the function declared

but the symbol is found, having added -lposix4 or -lrt to the link line if

earlier checks indicate they're needed.





 if you want to support all

 platforms, it's better to just check for nanosleep directly without the

 _POSIX_TIMERS check.



If _POSIX_TIMERS is defined to 0 the code might compile but not work at

run-time.  I didn't write those checks, but I'm not inclined to remove the

tests of the POSIX option macros just to fix this PR.





  That is correctly detected anyway by configure, without any changes, as I 
  said

  in comment 30 and again in comment 37

 

 Yes, it is.



Gread, thanks for confirming that.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread jeremyhu at macports dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #42 from Jeremy Huddleston Sequoia jeremyhu at macports dot org 
2012-10-08 20:10:26 UTC ---

(In reply to comment #41)

 (In reply to comment #40)

  I still don't see why the _POSIX_TIMERS  0 check exists at all.  On systems

  that don't have it, the tests will simply fail because timespec or nanosleep

  are undefined.

 

 The existence of a function called nanosleep doesn't mean it's the right one,

 or that it will be found at link time, or available at run-time.

 

 Checking _POSIX_TIMERS  0 means the functionality is actually usable, without

 checking sysconf() at run-time as described by POSIX.1b-2001.

 



Right, but as we see here, the converse is not true.  ie:



This is true:

(_POSIX_TIMERS  0) = (nanosleep is the one you want)



This is not true:

(nanosleep is the one you want) = (_POSIX_TIMERS  0)



You want to find an test such that:



(your test) = (nanosleep is the one you want)



 (That was a link to clock_nanosleep not nanosleep, which was a different

 option, not Timers ;)



Aww sorry.  I copy-linked the wrong one, but meh.



 ... but you do still seem to doubt that the struct is unnecessary in C++. 



No.  I don't doubt that.  I admitted in comment #20 that C++ is not a strength

of mine, so thanks for letting me know about this detail.



 Maybe you've noticed how you don't need to say:

 

class std::string str = a string;

^

 to use C++ classes. It's the same for structs.



Yeah, I knew about class, but I didn't know about that for structs.  I thought

it wasn't possible to drop 'struct' in C++ as it's not possible to drop it in C

(although most users will typedef).  Thanks for teaching me something new.



 Again, there's a difference between *working* (i.e. being usable) on darwin 
 and

 being able to build libstdc++ with a different compiler.  There is no

 requirement to be able to configure libstdc++ with anything other than G++, 
 but

 in any case I assure you that clang++ doesn't require the 'struct' keyword

 either.



I don't doubt it.  I was just trying to make the usage strictly match the POSIX

spec.



  It's not one system.  You are misreading the spec.

 

 No I'm not, my words you quoted carefully made the distinction of saying -1

 means the Timers option is not supported, not that nanosleep is not supported:



Ok.



 I'd be happy to improve the test to support other systems, but the patches

 posted to this PR so far have been unacceptable due to failing to understand

 the existing checks, failing to meet libstdc++'s configury conventions, or

 adding support for a single system rather than for any systems which provide

 nanosleep without the rest of the Timers option.  In the absence of a decent

 patch I suggest defining the HAVE_NANOSLEEP macro in os_defines.h and moving

 on.



  Why are you even othering to put that code inside of a _POSIX_TIMERS  0 
  check.

   If _POSIX_TIMERS  0, you're guaranteed (by the standard) to have that

  functionality, so there's no point in checking...

 

 The existence of a preprocessor symbol doesn't tell you whether you need to

 link to a particular library to use the function.



Ah, I forgot you were checking for library linkage as well.  That makes sense.



 The check is AC_TRY_LINK which will ensure not only is the function declared

 but the symbol is found, having added -lposix4 or -lrt to the link line if

 earlier checks indicate they're needed.



That makes sense.



  if you want to support all

  platforms, it's better to just check for nanosleep directly without the

  _POSIX_TIMERS check.

 

 If _POSIX_TIMERS is defined to 0 the code might compile but not work at

 run-time.  I didn't write those checks, but I'm not inclined to remove the

 tests of the POSIX option macros just to fix this PR.



Ok, what about just using _POSIX_TIMERS  0 || defined(__APPLE__)?  That may

miss some other OSs in the same boat, but they can always add similar checks.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread howarth at nitro dot med.uc.edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #43 from Jack Howarth howarth at nitro dot med.uc.edu 2012-10-08 
20:31:01 UTC ---

Both OpenBSD and FreeBSD seem to have nanosleep calls documented as...



The nanosleep() function conforms to IEEE Std 1003.1b-1993 (``POSIX'')



like Apple's. On the other hand, using a patch like...



Index: libstdc++-v3/config/os/bsd/darwin/os_defines.h

===

--- libstdc++-v3/config/os/bsd/darwin/os_defines.h(revision 19)

+++ libstdc++-v3/config/os/bsd/darwin/os_defines.h(working copy)

@@ -42,4 +42,9 @@

 // Static initializer macro is buggy in darwin, see libstdc++/51906

 #define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC



+// Use nanosleep and sched_yield in libc for time.clock and 

+// thread.thread.this in C++11 standard.

+#define _GLIBCXX_USE_NANOSLEEP 1

+#define _GLIBCXX_USE_SCHED_YIELD 1

+

 #endif



will effectively default darwin to --enable-libstdcxx-time=yes and eliminates a

configure option.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread redi at gcc dot gnu.org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #44 from Jonathan Wakely redi at gcc dot gnu.org 2012-10-08 
20:42:22 UTC ---

(In reply to comment #42)

 You want to find an test such that:

 

 (your test) = (nanosleep is the one you want)



That's why I was asking about other feature test macros that would allow us to

detect systems supporting the POSIX.1b-1993 Realtime Extensions, but not the

later Timers option, or the POSIX-2008 Base.





 Ok, what about just using _POSIX_TIMERS  0 || defined(__APPLE__)?  That may

 miss some other OSs in the same boat, but they can always add similar checks.



Because we generally try to avoid littering acinclude.m4 with such checks.  The

other OSs can add defines to their own os_defines.h files if needed.





(In reply to comment #43)

 will effectively default darwin to --enable-libstdcxx-time=yes and eliminates 
 a

 configure option.



That's a *good* thing. If the platform unconditionally supports the feature and

doesn't need a configure check why would you want to prevent using it?  All

that achieves is an incomplete libstdc++ with missing functionality.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread howarth at nitro dot med.uc.edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #45 from Jack Howarth howarth at nitro dot med.uc.edu 2012-10-08 
22:27:08 UTC ---

I can confirm the existence of sched_yield() back to Libc-166 in 1997 on

darwin.



http://opensource.apple.com/source/Libc/Libc-166/pthreads.subproj/sched.h



The nanosleep() call appears at least by Libc-262.2.12 in 2003 on darwin...



http://opensource.apple.com/source/Libc/Libc-262.2.12/include/time.h



and probably goes back further but the archived Libc don't show the time.h

header before then.


[Bug libstdc++/54847] --enable-libstdcxx-time=yes doesn't find the function nanosleep() on darwin

2012-10-08 Thread howarth at nitro dot med.uc.edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54847



--- Comment #46 from Jack Howarth howarth at nitro dot med.uc.edu 2012-10-09 
00:46:08 UTC ---

Revised patch posted to libstdc++ mailing list...



http://gcc.gnu.org/ml/libstdc++/2012-10/msg00047.html