Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60838df

Browse files
committed
Move pg_lzcompress.c to src/common.
Exposing compression and decompression APIs of pglz makes possible itsuse by extensions and contrib modules. pglz_decompress contained a callto elog to emit an error message in case of corrupted data. This functionis changed to return a status code to let its callers return an error instead.This commit is required for upcoming WAL compression feature so thatthe WAL reader facility can decompress the WAL data by using pglz_decompress.Michael Paquier
1 parent5b89473 commit60838df

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

‎src/backend/access/heap/tuptoaster.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include"catalog/catalog.h"
3838
#include"miscadmin.h"
3939
#include"utils/fmgroids.h"
40-
#include"utils/pg_lzcompress.h"
40+
#include"common/pg_lzcompress.h"
4141
#include"utils/rel.h"
4242
#include"utils/typcache.h"
4343
#include"utils/tqual.h"
@@ -142,7 +142,8 @@ heap_tuple_untoast_attr(struct varlena * attr)
142142

143143
attr= (structvarlena*)palloc(PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
144144
SET_VARSIZE(attr,PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
145-
pglz_decompress(tmp,VARDATA(attr));
145+
if (!pglz_decompress(tmp,VARDATA(attr)))
146+
elog(ERROR,"compressed data is corrupted");
146147
pfree(tmp);
147148
}
148149
}
@@ -167,7 +168,8 @@ heap_tuple_untoast_attr(struct varlena * attr)
167168

168169
attr= (structvarlena*)palloc(PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
169170
SET_VARSIZE(attr,PGLZ_RAW_SIZE(tmp)+VARHDRSZ);
170-
pglz_decompress(tmp,VARDATA(attr));
171+
if (!pglz_decompress(tmp,VARDATA(attr)))
172+
elog(ERROR,"compressed data is corrupted");
171173
}
172174
elseif (VARATT_IS_SHORT(attr))
173175
{
@@ -239,7 +241,8 @@ heap_tuple_untoast_attr_slice(struct varlena * attr,
239241

240242
preslice= (structvarlena*)palloc(size);
241243
SET_VARSIZE(preslice,size);
242-
pglz_decompress(tmp,VARDATA(preslice));
244+
if (!pglz_decompress(tmp,VARDATA(preslice)))
245+
elog(ERROR,"compressed data is corrupted");
243246

244247
if (tmp!= (PGLZ_Header*)attr)
245248
pfree(tmp);

‎src/backend/utils/adt/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ OBJS = acl.o arrayfuncs.o array_selfuncs.o array_typanalyze.o \
2525
jsonfuncs.o like.o lockfuncs.o mac.o misc.o nabstime.o name.o\
2626
network.o network_gist.o network_selfuncs.o\
2727
numeric.o numutils.o oid.o oracle_compat.o\
28-
orderedsetaggs.opg_lzcompress.opg_locale.opg_lsn.o\
29-
pgstatfuncs.opseudotypes.o quote.o rangetypes.o rangetypes_gist.o\
28+
orderedsetaggs.opg_locale.opg_lsn.opgstatfuncs.o\
29+
pseudotypes.o quote.o rangetypes.o rangetypes_gist.o\
3030
rangetypes_selfuncs.o rangetypes_spgist.o rangetypes_typanalyze.o\
3131
regexp.o regproc.o ri_triggers.o rowtypes.o ruleutils.o\
3232
selfuncs.o tid.o timestamp.o trigfuncs.o\

‎src/common/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ include $(top_builddir)/src/Makefile.global
2323
overrideCPPFLAGS := -DFRONTEND$(CPPFLAGS)
2424
LIBS +=$(PTHREAD_LIBS)
2525

26-
OBJS_COMMON = exec.o pgfnames.o psprintf.o relpath.o rmtree.o username.o wait_error.o
26+
OBJS_COMMON = exec.o pg_lzcompress.o pgfnames.o psprintf.o relpath.o\
27+
rmtree.o username.o wait_error.o
2728

2829
OBJS_FRONTEND =$(OBJS_COMMON) fe_memutils.o
2930

‎src/backend/utils/adt/pg_lzcompress.crenamed to‎src/common/pg_lzcompress.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*FALSE if not; in the latter case the contents of dest
2828
*are undefined.
2929
*
30-
*void
30+
*bool
3131
*pglz_decompress(const PGLZ_Header *source, char *dest)
3232
*
3333
*source is the compressed input.
@@ -40,6 +40,10 @@
4040
*The data is written to buff exactly as it was handed
4141
*to pglz_compress(). No terminating zero byte is added.
4242
*
43+
*The return value is TRUE if decompression succeeded,
44+
*FALSE if not; in the latter case the contents of dest
45+
*are undefined.
46+
*
4347
*The decompression algorithm and internal data format:
4448
*
4549
*PGLZ_Header is defined as
@@ -169,14 +173,14 @@
169173
*
170174
* Copyright (c) 1999-2014, PostgreSQL Global Development Group
171175
*
172-
* src/backend/utils/adt/pg_lzcompress.c
176+
* src/common/pg_lzcompress.c
173177
* ----------
174178
*/
175179
#include"postgres.h"
176180

177181
#include<limits.h>
178182

179-
#include"utils/pg_lzcompress.h"
183+
#include"common/pg_lzcompress.h"
180184

181185

182186
/* ----------
@@ -492,7 +496,8 @@ pglz_find_match(int16 *hstart, const char *input, const char *end,
492496
/* ----------
493497
* pglz_compress -
494498
*
495-
*Compresses source into dest using strategy.
499+
*Compresses source into dest using strategy. Returns false if a failure
500+
*occurred, true in case of success.
496501
* ----------
497502
*/
498503
bool
@@ -678,10 +683,11 @@ pglz_compress(const char *source, int32 slen, PGLZ_Header *dest,
678683
/* ----------
679684
* pglz_decompress -
680685
*
681-
*Decompresses source into dest.
686+
*Decompresses source into dest. Returns false if a failure
687+
*occurred, true in case of success.
682688
* ----------
683689
*/
684-
void
690+
bool
685691
pglz_decompress(constPGLZ_Header*source,char*dest)
686692
{
687693
constunsignedchar*sp;
@@ -771,9 +777,10 @@ pglz_decompress(const PGLZ_Header *source, char *dest)
771777
* Check we decompressed the right amount.
772778
*/
773779
if (dp!=destend||sp!=srcend)
774-
elog(ERROR,"compressed data is corrupt");
780+
return false;
775781

776782
/*
777783
* That's it.
778784
*/
785+
return true;
779786
}

‎src/include/utils/pg_lzcompress.hrenamed to‎src/include/common/pg_lzcompress.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
*Definitions for the builtin LZ compressor
55
*
6-
* src/include/utils/pg_lzcompress.h
6+
* src/include/common/pg_lzcompress.h
77
* ----------
88
*/
99

@@ -107,6 +107,6 @@ extern const PGLZ_Strategy *const PGLZ_strategy_always;
107107
*/
108108
externboolpglz_compress(constchar*source,int32slen,PGLZ_Header*dest,
109109
constPGLZ_Strategy*strategy);
110-
externvoidpglz_decompress(constPGLZ_Header*source,char*dest);
110+
externboolpglz_decompress(constPGLZ_Header*source,char*dest);
111111

112112
#endif/* _PG_LZCOMPRESS_H_ */

‎src/tools/msvc/Mkvcbuild.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ sub mkvcbuild
7676
push(@pgportfiles,'rint.c')if ($vsVersion <'12.00');
7777

7878
our@pgcommonallfiles =qw(
79-
exec.c pgfnames.c psprintf.c relpath.c rmtree.c username.c wait_error.c);
79+
exec.c pg_lzcompress.c pgfnames.c psprintf.c relpath.c rmtree.c
80+
username.c wait_error.c);
8081

8182
our@pgcommonfrontendfiles = (@pgcommonallfiles,qw(fe_memutils.c));
8283

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp