[m-rev.] diff: replace workarounds in the POSIX binding

Julien Fischer jfischer at opturion.com
Fri Mar 22 21:10:26 AEDT 2019


Replace workarounds in the POSIX binding.

Delete the workarounds for FD_{ZERO,SET,ISSET,CLR} in the POSIX binding.  The
stated reason for their existence was that the Linux headers defined them using
inline assembler that conflicted with our use of global register variables.

Since the runtime (now) defines a wrapper for FD_ZERO, use the runtime's
version instead of having the binding define its own.  We've been using
FD_{SET,ISSET} in the runtime without issues for many years.  (On my system,
they and FD_CLR are not defined using inline assembler anyway.)

extras/posix/posix_workarounds.{ch}:
     Delete this files.

extras/posix/posix.select.m:
     Use MR_fd_zero in place of ME_fd_zero.

     Use FD_{SET,ISSET,CLR} directly.

extras/posix/Makefile:
extras/posix/Mercury.options:
extras/posix/Mmakefile:
     Conform to the above changes.

Julien.

diff --git a/extras/posix/Makefile b/extras/posix/Makefile
index 7eebef0..26c92e0 100644
--- a/extras/posix/Makefile
+++ b/extras/posix/Makefile
@@ -12,15 +12,13 @@ TARGET = posix
  MMC = mmc

  .PHONY: build
-build: posix_workarounds.o
+build:
  	$(MMC) --make lib$(TARGET)

  .PHONY: install
  install: posix_workarounds.o
  	$(MMC) --make lib$(TARGET).install

-posix_workarounds.o: posix_workarounds.c
-
  .PHONY: realclean
  realclean:
  	cd samples && $(MAKE) realclean
diff --git a/extras/posix/Mercury.options b/extras/posix/Mercury.options
index 47a332e..3fecca1 100644
--- a/extras/posix/Mercury.options
+++ b/extras/posix/Mercury.options
@@ -1,6 +1,4 @@
  MCFLAGS = \
  	--libgrades-exclude java \
  	--libgrades-exclude csharp \
-	--libgrades-exclude erlang \
-	--link-object posix_workarounds.o \
-	--extra-library-header posix_workarounds.h
+	--libgrades-exclude erlang
diff --git a/extras/posix/Mmakefile b/extras/posix/Mmakefile
index a130522..921078f 100644
--- a/extras/posix/Mmakefile
+++ b/extras/posix/Mmakefile
@@ -13,14 +13,10 @@

  MAIN_TARGET=build

-# XXX invoking the Makefile from here won't build posix_workarounds.o
-# so we need to specify it here too.
  .PHONY: build
-build: posix_workarounds.o
+build:
  	$(MAKE) build

-posix_workarounds.o: posix_workarounds.c
-
  # The depend target does nothing, mmc --make will handle dependencies
  # automatically.
  #
diff --git a/extras/posix/posix.select.m b/extras/posix/posix.select.m
index 9b413f4..72423ea 100644
--- a/extras/posix/posix.select.m
+++ b/extras/posix/posix.select.m
@@ -43,7 +43,7 @@
      #include <sys/types.h>
      #include <unistd.h>

-    #include ""posix_workarounds.h""
+    #include ""mercury_reg_workarounds.h""
  ").

  :- pragma foreign_type("C", fdset_ptr, "fd_set *", [can_pass_as_mercury_type]).
@@ -87,7 +87,7 @@ select(Fd, R, W, E, Timeout, Result, !IO) :-

      MR_incr_hp(Fds0, 1+sizeof(fd_set)/sizeof(MR_Word));
      Fds = (fd_set *) Fds0;
-    ME_fd_zero(Fds);
+    MR_fd_zero(Fds);
      IO = IO0;
  ").

@@ -97,7 +97,7 @@ select(Fd, R, W, E, Timeout, Result, !IO) :-
      fd_clr(Fd::in, Fds::in, IO0::di, IO::uo),
      [promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
  "
-    ME_fd_clr(Fd, Fds);
+    FD_CLR(Fd, Fds);
      IO = IO0;
  ").

@@ -107,7 +107,7 @@ select(Fd, R, W, E, Timeout, Result, !IO) :-
      fd_zero(Fds::in, IO0::di, IO::uo),
      [promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
  "
-    ME_fd_zero(Fds);
+    MR_fd_zero(Fds);
      IO = IO0;
  ").

@@ -117,7 +117,7 @@ select(Fd, R, W, E, Timeout, Result, !IO) :-
      fd_isset(Fd::in, Fds::in, Res::out, IO0::di, IO::uo),
      [promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
  "
-    Res = (ME_fd_isset(Fd, Fds) ? MR_YES : MR_NO );
+    Res = (FD_ISSET(Fd, Fds) ? MR_YES : MR_NO );
      IO = IO0;
  ").

@@ -127,7 +127,7 @@ select(Fd, R, W, E, Timeout, Result, !IO) :-
      fd_set(Fd::in, Fds::in, IO0::di, IO::uo),
      [promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
  "
-    ME_fd_set(Fd, Fds);
+    FD_SET(Fd, Fds);
      IO = IO0;
  ").

diff --git a/extras/posix/posix_workarounds.c b/extras/posix/posix_workarounds.c
deleted file mode 100644
index d809b58..0000000
--- a/extras/posix/posix_workarounds.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (C) 1999 The University of Melbourne.  			      */
-/* Copyright (C) 2018 The Mercury team.                                       */
-/* This file is distributed under the terms specified in COPYING.LIB.         */
-/*----------------------------------------------------------------------------*/
-/*									      */
-/* This file contains a bunch of functions for working on fd_set objects.     */
-/* The reason that these are necessary is that gcc generates inline assembler */
-/* for these which conflicts with our use of global registers.		      */
-/*									      */
-/*----------------------------------------------------------------------------*/
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <unistd.h>
-
-#include "posix_workarounds.h"
-
-void ME_fd_zero(fd_set *fds)
-{
-	FD_ZERO(fds);
-}
-
-void ME_fd_clr(int fd, fd_set *fds)
-{
-	FD_CLR(fd, fds);
-}
-
-void ME_fd_set(int fd, fd_set *fds)
-{
-	FD_SET(fd, fds);
-}
-
-int ME_fd_isset(int fd, fd_set *fds)
-{
-	return FD_ISSET(fd, fds);
-}
-
diff --git a/extras/posix/posix_workarounds.h b/extras/posix/posix_workarounds.h
deleted file mode 100644
index 2186990..0000000
--- a/extras/posix/posix_workarounds.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*----------------------------------------------------------------------------*/
-/* Copyright (C) 1999 The University of Melbourne.  			      */
-/* This file may only be copied under the terms of the GNU Library General    */
-/* Public License - see the file COPYING.LIB in the Mercury distribution.     */
-/*----------------------------------------------------------------------------*/
-
-#ifndef ME_POSIX_WORKAROUNDS_H
-#define ME_POSIX_WORKAROUNDS_H
-
-void ME_fd_zero(fd_set *fds);
-
-void ME_fd_clr(int fd, fd_set *fds);
-
-void ME_fd_set(int fd, fd_set *fds);
-
-int ME_fd_isset(int fd, fd_set *fds);
-
-#endif


More information about the reviews mailing list