unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] emacs-25 dynamic modules support not compiling on FreeBSD 10.x
@ 2015-12-15 14:59 Ashish SHUKLA
  2015-12-16  7:13 ` Paul Eggert
  0 siblings, 1 reply; 3+ messages in thread
From: Ashish SHUKLA @ 2015-12-15 14:59 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1867 bytes --]

Hi,

Due to C11 threads.h check in configure, we get HAVE_THREADS_H defined in
config.h, which results in thrd_current getting invoked in `module_init' as
shown below:

--8<---------------cut here---------------start------------->8---
1123 void
1124 module_init (void)
1125 {
1126   /* It is not guaranteed that dynamic initializers run in the main thread,
1127      therefore detect the main thread here.  */
1128 #ifdef HAVE_THREADS_H
1129   main_thread = thrd_current ();
1130 #elif defined HAVE_PTHREAD
1131   main_thread = pthread_self ();
1132 #elif defined WINDOWSNT
1133   /* The 'main' function already recorded the main thread's thread ID,
1134      so we need just to use it . */
1135   main_thread = dwMainThreadId;
1136 #endif
1137 }
--8<---------------cut here---------------end--------------->8---

thrd_current(3)[1] on FreeBSD 10.x requires -lstdthreads to be included in
libraries, or you'll get linker error about missing `thrd_current'.

Attached diff (w.r.t. 0ad27a5a) fixes this on FreeBSD 10.x, but needs to be
rewritten to be portable.

--8<---------------cut here---------------start------------->8---
--- configure.ac.orig
+++ configure.ac
@@ -2204,7 +2204,7 @@
     [emacs_cv_pthread_lib=no
      OLD_CPPFLAGS=$CPPFLAGS
      OLD_LIBS=$LIBS
-     for emacs_pthread_lib in 'none needed' -lpthread; do
+     for emacs_pthread_lib in 'none needed' '-lpthread -lstdthreads'; do
        case $emacs_pthread_lib in
 	 -*) LIBS="$OLD_LIBS $emacs_pthread_lib";;
        esac
--8<---------------cut here---------------end--------------->8---

References:
[1]  https://www.freebsd.org/cgi/man.cgi?query=thrd_current

HTH
-- 
Ashish SHUKLA

“If we live, we live; if we die, we die; if we suffer, we suffer; if we are
terrified, we are terrified. No problem.” (Alan Watts)

Sent from my Emacs

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs-25 dynamic modules support not compiling on FreeBSD 10.x
  2015-12-15 14:59 [PATCH] emacs-25 dynamic modules support not compiling on FreeBSD 10.x Ashish SHUKLA
@ 2015-12-16  7:13 ` Paul Eggert
  2015-12-16 11:12   ` Ashish SHUKLA
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Eggert @ 2015-12-16  7:13 UTC (permalink / raw)
  To: Ashish SHUKLA, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 676 bytes --]

Ashish SHUKLA wrote:
> thrd_current(3)[1] on FreeBSD 10.x requires -lstdthreads to be included in
> libraries, or you'll get linker error about missing `thrd_current'.

Thanks for reporting this. Although at some point we'll need to port Emacs to 
C11 threads, currently we should focus on fixing bugs and not new projects like 
that. (As far as I know, all current platforms that have C11 threads also have a 
thread mechanism that Emacs already uses, so the C11-thread-porting project is 
not urgent.) So, instead of worrying about configuring -lstdthreads I installed 
the attached patch so that -lstdthreads should not be necessary. Please give it 
a try on FreeBSD 10.x.

[-- Attachment #2: 0001-Remove-attempt-to-use-C11-threads.patch --]
[-- Type: text/x-diff, Size: 3196 bytes --]

From 202cde0498f737d5aa988a6bc74025ba972b7a7c Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 15 Dec 2015 23:10:12 -0800
Subject: [PATCH] Remove attempt to use C11 threads

C11 threads are not needed for Emacs now, and their use is causing
hassles on FreeBSD 10.x.  Problem reported by Ashish SHUKLA in:
http://lists.gnu.org/archive/html/emacs-devel/2015-12/msg00648.html
* configure.ac: Do not check for C11 threads. Remove unnecessary
fiddling with CPPFLAGS when configuring pthreads.
* src/emacs-module.c (main_thread, check_main_thread)
(module_init): Do not worry about C11 threads.
---
 configure.ac       |  7 +------
 src/emacs-module.c | 13 +++----------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac
index b2fa1ed..14a1428 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2192,9 +2192,6 @@ LIBS="$LIBS_SYSTEM $LIBS"
 dnl FIXME replace main with a function we actually want from this library.
 AC_CHECK_LIB(Xbsd, main, LD_SWITCH_X_SITE="$LD_SWITCH_X_SITE -lXbsd")
 
-dnl Check for C11 threads.
-AC_CHECK_HEADERS_ONCE(threads.h)
-
 dnl Check for the POSIX thread library.
 LIB_PTHREAD=
 AC_CHECK_HEADERS_ONCE(pthread.h)
@@ -2202,7 +2199,6 @@ if test "$ac_cv_header_pthread_h" && test "$opsys" != "mingw32"; then
   AC_CACHE_CHECK([for pthread library],
     [emacs_cv_pthread_lib],
     [emacs_cv_pthread_lib=no
-     OLD_CPPFLAGS=$CPPFLAGS
      OLD_LIBS=$LIBS
      for emacs_pthread_lib in 'none needed' -lpthread; do
        case $emacs_pthread_lib in
@@ -2231,8 +2227,7 @@ if test "$ac_cv_header_pthread_h" && test "$opsys" != "mingw32"; then
        if test "$emacs_cv_pthread_lib" != no; then
 	 break
        fi
-     done
-     CPPFLAGS=$OLD_CPPFLAGS])
+     done])
   if test "$emacs_cv_pthread_lib" != no; then
     AC_DEFINE([HAVE_PTHREAD], 1, [Define to 1 if you have POSIX threads.])
     case $emacs_cv_pthread_lib in
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 620df93..ee97644 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -44,10 +44,7 @@ enum { module_has_cleanup = false };
 
 /* Handle to the main thread.  Used to verify that modules call us in
    the right thread.  */
-#ifdef HAVE_THREADS_H
-# include <threads.h>
-static thrd_t main_thread;
-#elif defined HAVE_PTHREAD
+#ifdef HAVE_PTHREAD
 # include <pthread.h>
 static pthread_t main_thread;
 #elif defined WINDOWSNT
@@ -789,9 +786,7 @@ usage: (module-call ENVOBJ &rest ARGLIST)   */)
 static void
 check_main_thread (void)
 {
-#ifdef HAVE_THREADS_H
-  eassert (thrd_equal (thdr_current (), main_thread));
-#elif defined HAVE_PTHREAD
+#ifdef HAVE_PTHREAD
   eassert (pthread_equal (pthread_self (), main_thread));
 #elif defined WINDOWSNT
   eassert (GetCurrentThreadId () == main_thread);
@@ -1125,9 +1120,7 @@ module_init (void)
 {
   /* It is not guaranteed that dynamic initializers run in the main thread,
      therefore detect the main thread here.  */
-#ifdef HAVE_THREADS_H
-  main_thread = thrd_current ();
-#elif defined HAVE_PTHREAD
+#ifdef HAVE_PTHREAD
   main_thread = pthread_self ();
 #elif defined WINDOWSNT
   /* The 'main' function already recorded the main thread's thread ID,
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs-25 dynamic modules support not compiling on FreeBSD 10.x
  2015-12-16  7:13 ` Paul Eggert
@ 2015-12-16 11:12   ` Ashish SHUKLA
  0 siblings, 0 replies; 3+ messages in thread
From: Ashish SHUKLA @ 2015-12-16 11:12 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Ashish SHUKLA, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]

On Tue, 15 Dec 2015 23:13:42 -0800, Paul Eggert <eggert@cs.ucla.edu> said:
| Ashish SHUKLA wrote:
|| thrd_current(3)[1] on FreeBSD 10.x requires -lstdthreads to be included in
|| libraries, or you'll get linker error about missing `thrd_current'.

| Thanks for reporting this. Although at some point we'll need to port
| Emacs to C11 threads, currently we should focus on fixing bugs and not
| new projects like that. (As far as I know, all current platforms that
| have C11 threads also have a thread mechanism that Emacs already uses,
| so the C11-thread-porting project is not urgent.) So, instead of
| worrying about configuring -lstdthreads I installed the attached patch
| so that -lstdthreads should not be necessary. Please give it a try on
| FreeBSD 10.x.

Hi Paul,

The attached diff works fine, and seem better at this point.

Thanks!
-- 
Ashish SHUKLA

“Mohandas K. Gandhi often changed his mind publicly.  An aide once asked him
how he could so freely contradict this week what he had said just last
week. The great man replied that it was because this week he knew better.”

Sent from my Emacs

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-16 11:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-15 14:59 [PATCH] emacs-25 dynamic modules support not compiling on FreeBSD 10.x Ashish SHUKLA
2015-12-16  7:13 ` Paul Eggert
2015-12-16 11:12   ` Ashish SHUKLA

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).