From: Justin Pryzby Date: Sat, 14 Jan 2023 10:45:02 -0600 Subject: [PATCH 6/7] f! --- src/bin/pg_dump/compress_lz4.c | 34 ++++++++++++++++---------------- src/bin/pg_dump/compress_lz4.h | 4 ++-- src/bin/pg_dump/t/002_pg_dump.pl | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/bin/pg_dump/compress_lz4.c b/src/bin/pg_dump/compress_lz4.c index c97e16187a0..0e259a6251a 100644 --- a/src/bin/pg_dump/compress_lz4.c +++ b/src/bin/pg_dump/compress_lz4.c @@ -117,13 +117,13 @@ EndCompressorLZ4(ArchiveHandle *AH, CompressorState *cs) /* Public routines that support LZ4 compressed data I/O */ void -InitCompressorLZ4(CompressorState *cs, const pg_compress_specification compression_spec) +InitCompressorLZ4(CompressorState *cs, const pg_compress_specification *compression_spec) { cs->readData = ReadDataFromArchiveLZ4; cs->writeData = WriteDataToArchiveLZ4; cs->end = EndCompressorLZ4; - cs->compression_spec = compression_spec; + cs->compression_spec = *compression_spec; /* Will be lazy init'd */ cs->private_data = pg_malloc0(sizeof(LZ4CompressorState)); @@ -189,7 +189,7 @@ LZ4File_get_error(CompressFileHandle *CFH) /* * Prepare an already alloc'ed LZ4File struct for subsequent calls. * - * It creates the nessary contexts for the operations. When compressing, + * It creates the necessary contexts for the operations. When compressing, * it additionally writes the LZ4 header in the output stream. */ static int @@ -228,7 +228,7 @@ LZ4File_init(LZ4File * fs, int size, bool compressing) if (fwrite(fs->buffer, 1, status, fs->fp) != status) { - errno = errno ? : ENOSPC; + errno = errno ? errno : ENOSPC; return 1; } } @@ -255,7 +255,7 @@ LZ4File_init(LZ4File * fs, int size, bool compressing) /* * Read already decompressed content from the overflow buffer into 'ptr' up to * 'size' bytes, if available. If the eol_flag is set, then stop at the first - * occurance of the new line char prior to 'size' bytes. + * occurrence of the new line char prior to 'size' bytes. * * Any unread content in the overflow buffer, is moved to the beginning. */ @@ -309,10 +309,10 @@ LZ4File_read_internal(LZ4File * fs, void *ptr, int ptrsize, bool eol_flag) void *readbuf; /* Lazy init */ - if (!fs->inited && LZ4File_init(fs, size, false /* decompressing */ )) + if (LZ4File_init(fs, size, false /* decompressing */ )) return -1; - /* Verfiy that there is enough space in the outbuf */ + /* Verify that there is enough space in the outbuf */ if (size > fs->buflen) { fs->buflen = size; @@ -363,10 +363,10 @@ LZ4File_read_internal(LZ4File * fs, void *ptr, int ptrsize, bool eol_flag) if (outlen > 0 && dsize < size && eol_found == false) { char *p; - size_t lib = (eol_flag == 0) ? size - dsize : size - 1 - dsize; + size_t lib = eol_flag ? size - 1 - dsize : size - dsize ; size_t len = outlen < lib ? outlen : lib; - if (eol_flag == true && + if (eol_flag && (p = memchr(fs->buffer, '\n', outlen)) && (size_t) (p - fs->buffer + 1) <= len) { @@ -377,7 +377,7 @@ LZ4File_read_internal(LZ4File * fs, void *ptr, int ptrsize, bool eol_flag) memcpy((char *) ptr + dsize, fs->buffer, len); dsize += len; - /* move what did not fit, if any, at the begining of the buf */ + /* move what did not fit, if any, at the beginning of the buf */ if (len < outlen) memmove(fs->buffer, fs->buffer + len, outlen - len); outlen -= len; @@ -414,7 +414,7 @@ LZ4File_write(const void *ptr, size_t size, CompressFileHandle *CFH) size_t status; int remaining = size; - if (!fs->inited && LZ4File_init(fs, size, true)) + if (LZ4File_init(fs, size, true)) return -1; while (remaining > 0) @@ -433,7 +433,7 @@ LZ4File_write(const void *ptr, size_t size, CompressFileHandle *CFH) if (fwrite(fs->buffer, 1, status, fs->fp) != status) { - errno = errno ? : ENOSPC; + errno = errno ? errno : ENOSPC; return 1; } } @@ -520,7 +520,7 @@ LZ4File_close(CompressFileHandle *CFH) LZ4F_getErrorName(status)); else if ((ret = fwrite(fs->buffer, 1, status, fs->fp)) != status) { - errno = errno ? : ENOSPC; + errno = errno ? errno : ENOSPC; WRITE_ERROR_EXIT; } @@ -582,7 +582,7 @@ LZ4File_open_write(const char *path, const char *mode, CompressFileHandle *CFH) } void -InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification compression_spec) +InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification *compression_spec) { LZ4File *lz4fp; @@ -596,7 +596,7 @@ InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification compres CFH->close_func = LZ4File_close; CFH->get_error_func = LZ4File_get_error; - CFH->compression_spec = compression_spec; + CFH->compression_spec = *compression_spec; lz4fp = pg_malloc0(sizeof(*lz4fp)); if (CFH->compression_spec.level >= 0) lz4fp->prefs.compressionLevel = CFH->compression_spec.level; @@ -605,13 +605,13 @@ InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification compres } #else /* USE_LZ4 */ void -InitCompressorLZ4(CompressorState *cs, const pg_compress_specification compression_spec) +InitCompressorLZ4(CompressorState *cs, const pg_compress_specification *compression_spec) { pg_fatal("this build does not support compression with %s", "LZ4"); } void -InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification compression_spec) +InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification *compression_spec) { pg_fatal("this build does not support compression with %s", "LZ4"); } diff --git a/src/bin/pg_dump/compress_lz4.h b/src/bin/pg_dump/compress_lz4.h index 74595db1b98..69a3d9c171f 100644 --- a/src/bin/pg_dump/compress_lz4.h +++ b/src/bin/pg_dump/compress_lz4.h @@ -16,7 +16,7 @@ #include "compress_io.h" -extern void InitCompressorLZ4(CompressorState *cs, const pg_compress_specification compression_spec); -extern void InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification compression_spec); +extern void InitCompressorLZ4(CompressorState *cs, const pg_compress_specification *compression_spec); +extern void InitCompressLZ4(CompressFileHandle *CFH, const pg_compress_specification *compression_spec); #endif /* _COMPRESS_LZ4_H_ */ diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index f497ec60407..263995a2b7a 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -183,7 +183,7 @@ my %pgdump_runs = ( "$tempdir/compression_lz4_dir/blobs.toc.lz4", ], }, - # Verify that data files where compressed + # Verify that data files were compressed glob_patterns => [ "$tempdir/compression_lz4_dir/toc.dat", "$tempdir/compression_lz4_dir/*.dat.lz4", -- 2.25.1 --e7jIye1Ygp5H0AIi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0007-TMP-pg_dump-use-lz4-by-default-for-CI-only.patch"