Re: pgwin32_safestat weirdness - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: pgwin32_safestat weirdness
Date
Msg-id 4805EFAA.6050705@dunslane.net
Whole thread Raw
In response to Re: pgwin32_safestat weirdness  (Magnus Hagander <magnus@hagander.net>)
Responses Re: pgwin32_safestat weirdness  (Magnus Hagander <magnus@hagander.net>)
List pgsql-hackers

Magnus Hagander wrote:
> Tom Lane wrote:
>
>> Magnus Hagander <magnus@hagander.net> writes:
>>
>>> Shouldn't be too hard to do, but I keep thinking it'd be cleaner to
>>> just not do the redefine when building libpq. It means we'd add a
>>> define like BUILDING_LIBPQ or something to the libpq Makefile, and
>>> exclude the redefine if set.
>>>
>> +1 for that general approach, but let's call the macro something
>> like UNSAFE_STAT_OKAY.  If the day ever comes that we need safestat
>> inside libpq, or more likely that we want to exclude it from some
>> other piece of code, it'll be clearer what to do.
>>
>
> Hmm. I thought BUILDING_LIBPQ would be the more generic one, since we
> might want to control other stuff from it. I recall wanting that define
> at some point in the past, but I can't recall why... :-)
>
> But - I'll do it with UNSAFE_STAT_OK if that's what ppl want. And then
> a simple ifeq() section in libpq Makefile, right?
>
> Or we could have libpq define the BUILDING_LIBPQ, and have a header say
> #ifdef BUILDING_LIBPQ / #define UNSAFE_STAT_OK / #endif.... That would
> certainly be the most flexible, but maybe not the prettiest solution
> until such time as we actually need it.
>
>
>

I think a simple approach is all we need for now - not even sure we need
an ifeq() section in the makefile.

Here's a patch, which I'll apply unless there's an objection.

cheers

andrew
Index: src/include/port.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/port.h,v
retrieving revision 1.120
diff -c -r1.120 port.h
*** src/include/port.h    11 Apr 2008 23:53:00 -0000    1.120
--- src/include/port.h    16 Apr 2008 12:16:01 -0000
***************
*** 287,294 ****
   *
   * We must pull in sys/stat.h here so the system header definition
   * goes in first, and we redefine that, and not the other way around.
   */
! #if defined(WIN32) && !defined(__CYGWIN__)
  #include <sys/stat.h>
  extern int    pgwin32_safestat(const char *path, struct stat *buf);
  #define stat(a,b) pgwin32_safestat(a,b)
--- 287,297 ----
   *
   * We must pull in sys/stat.h here so the system header definition
   * goes in first, and we redefine that, and not the other way around.
+  *
+  * Some frontends don't need the size from stat, so if UNSAFE_STAT_OK
+  * is defined we don't bother with this.
   */
! #if defined(WIN32) && !defined(__CYGWIN__) && !defined(UNSAFE_STAT_OK)
  #include <sys/stat.h>
  extern int    pgwin32_safestat(const char *path, struct stat *buf);
  #define stat(a,b) pgwin32_safestat(a,b)
Index: src/interfaces/libpq/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v
retrieving revision 1.165
diff -c -r1.165 Makefile
*** src/interfaces/libpq/Makefile    7 Apr 2008 14:15:58 -0000    1.165
--- src/interfaces/libpq/Makefile    16 Apr 2008 12:16:01 -0000
***************
*** 19,25 ****
  SO_MAJOR_VERSION= 5
  SO_MINOR_VERSION= 2

! override CPPFLAGS :=  -DFRONTEND -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
  ifneq ($(PORTNAME), win32)
  override CFLAGS += $(PTHREAD_CFLAGS)
  endif
--- 19,25 ----
  SO_MAJOR_VERSION= 5
  SO_MINOR_VERSION= 2

! override CPPFLAGS :=  -DFRONTEND -DUNSAFE_STAT_OK -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
  ifneq ($(PORTNAME), win32)
  override CFLAGS += $(PTHREAD_CFLAGS)
  endif

pgsql-hackers by date:

Previous
From: Gregory Stark
Date:
Subject: Re: pg_terminate_backend() issues
Next
From: Radek Strnad
Date:
Subject: Collation at database level