Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5c02a00

Browse files
committed
Move CRC tables to libpgport, and provide them in a separate include file.
This makes it much more convenient to build tools for Postgres that are separately compiled and require a matching CRC implementation. To prevent multiple copies of the CRC polynomial tables being introduced into the postgres binaries, they are now included in the static library libpgport that is mainly meant for replacement system functions. That seems like a bit of a kludge, but there's no better place. This cleans up building of the tools pg_controldata and pg_resetxlog, which previously had to build their own copies of pg_crc.o. In the future, external programs that need access to the CRC tables can include the tables directly from the new header file pg_crc_tables.h. Daniel Farina, reviewed by Abhijit Menon-Sen and Tom Lane
1 parent 0140a11 commit 5c02a00

File tree

9 files changed

+41
-28
lines changed

9 files changed

+41
-28
lines changed

src/backend/utils/hash/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ subdir = src/backend/utils/hash
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = dynahash.o hashfn.o pg_crc.o
15+
OBJS = dynahash.o hashfn.o
1616

1717
include $(top_srcdir)/src/backend/common.mk

src/bin/pg_controldata/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
/pg_crc.c
2-
31
/pg_controldata

src/bin/pg_controldata/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ subdir = src/bin/pg_controldata
1515
top_builddir = ../../..
1616
include $(top_builddir)/src/Makefile.global
1717

18-
OBJS= pg_controldata.o pg_crc.o $(WIN32RES)
18+
OBJS= pg_controldata.o $(WIN32RES)
1919

2020
all: pg_controldata
2121

2222
pg_controldata: $(OBJS) | submake-libpgport
2323
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
2424

25-
pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
26-
rm -f $@ && $(LN_S) $< .
27-
2825
install: all installdirs
2926
$(INSTALL_PROGRAM) pg_controldata$(X) '$(DESTDIR)$(bindir)/pg_controldata$(X)'
3027

@@ -35,4 +32,4 @@ uninstall:
3532
rm -f '$(DESTDIR)$(bindir)/pg_controldata$(X)'
3633

3734
clean distclean maintainer-clean:
38-
rm -f pg_controldata$(X) $(OBJS) pg_crc.c
35+
rm -f pg_controldata$(X) $(OBJS)

src/bin/pg_resetxlog/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
/pg_crc.c
2-
31
/pg_resetxlog

src/bin/pg_resetxlog/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ subdir = src/bin/pg_resetxlog
1515
top_builddir = ../../..
1616
include $(top_builddir)/src/Makefile.global
1717

18-
OBJS= pg_resetxlog.o pg_crc.o $(WIN32RES)
18+
OBJS= pg_resetxlog.o $(WIN32RES)
1919

2020
all: pg_resetxlog
2121

2222
pg_resetxlog: $(OBJS) | submake-libpgport
2323
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
2424

25-
pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
26-
rm -f $@ && $(LN_S) $< .
27-
2825
install: all installdirs
2926
$(INSTALL_PROGRAM) pg_resetxlog$(X) '$(DESTDIR)$(bindir)/pg_resetxlog$(X)'
3027

@@ -35,4 +32,4 @@ uninstall:
3532
rm -f '$(DESTDIR)$(bindir)/pg_resetxlog$(X)'
3633

3734
clean distclean maintainer-clean:
38-
rm -f pg_resetxlog$(X) $(OBJS) pg_crc.c
35+
rm -f pg_resetxlog$(X) $(OBJS)

src/backend/utils/hash/pg_crc.c renamed to src/include/utils/pg_crc_tables.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* pg_crc.c
4-
* PostgreSQL CRC support
3+
* pg_crc_tables.h
4+
* Polynomial lookup tables for CRC macros
5+
*
6+
* We make these tables available as a .h file so that programs not linked
7+
* with libpgport can still use the macros in pg_crc.h. They just need
8+
* to #include this header as well.
59
*
610
* See Ross Williams' excellent introduction
711
* A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS, available from
@@ -17,16 +21,12 @@
1721
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
1822
* Portions Copyright (c) 1994, Regents of the University of California
1923
*
20-
*
21-
* IDENTIFICATION
22-
* src/backend/utils/hash/pg_crc.c
24+
* src/include/utils/pg_crc_tables.h
2325
*
2426
*-------------------------------------------------------------------------
2527
*/
26-
27-
/* Use c.h so that this file can be built in either frontend or backend */
28-
#include "c.h"
29-
28+
#ifndef PG_CRC_TABLES_H
29+
#define PG_CRC_TABLES_H
3030

3131
/*
3232
* This table is based on the polynomial
@@ -513,3 +513,5 @@ const uint64 pg_crc64_table[256] = {
513513
#endif /* SIZEOF_VOID_P < 8 */
514514

515515
#endif /* PROVIDE_64BIT_CRC */
516+
517+
#endif /* PG_CRC_TABLES_H */

src/port/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ override CPPFLAGS := -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
3131
LIBS += $(PTHREAD_LIBS)
3232

3333
OBJS = $(LIBOBJS) chklocale.o dirmod.o erand48.o exec.o fls.o inet_net_ntop.o \
34-
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o pgstrcasecmp.o \
35-
qsort.o qsort_arg.o sprompt.o thread.o
34+
noblock.o path.o pgcheckdir.o pg_crc.o pgmkdirp.o pgsleep.o \
35+
pgstrcasecmp.o qsort.o qsort_arg.o sprompt.o thread.o
3636

3737
# foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
3838
OBJS_SRV = $(OBJS:%.o=%_srv.o)

src/port/pg_crc.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pg_crc.c
4+
* PostgreSQL CRC support
5+
*
6+
* This file simply #includes the CRC table definitions so that they are
7+
* available to programs linked with libpgport.
8+
*
9+
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
10+
* Portions Copyright (c) 1994, Regents of the University of California
11+
*
12+
*
13+
* IDENTIFICATION
14+
* src/port/pg_crc.c
15+
*
16+
*-------------------------------------------------------------------------
17+
*/
18+
19+
#include "c.h"
20+
21+
#include "utils/pg_crc_tables.h"

src/tools/msvc/Project.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ sub AddDir
261261
$mf =~ s{OBJS[^=]*=\s*(.*)$}{}m;
262262
}
263263

264-
# Match rules that pull in source files from different directories
265-
# example: pg_crc.c: $(top_srcdir)/src/backend/utils/hash/pg_crc.c
264+
# Match rules that pull in source files from different directories, eg
265+
# pgstrcasecmp.c rint.c snprintf.c: % : $(top_srcdir)/src/port/%
266266
my $replace_re = qr{^([^:\n\$]+\.c)\s*:\s*(?:%\s*: )?\$(\([^\)]+\))\/(.*)\/[^\/]+$}m;
267267
while ($mf =~ m{$replace_re}m)
268268
{

0 commit comments

Comments
 (0)