git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Junio C Hamano <gitster@pobox.com>, Toon Claes <toon@iotcl.com>,
	Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v3 0/9] reftable: code style improvements
Date: Tue, 6 Feb 2024 07:35:19 +0100	[thread overview]
Message-ID: <cover.1707200355.git.ps@pks.im> (raw)
In-Reply-To: <cover.1706687982.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 7767 bytes --]

Hi,

this is the third version of my patch series that tries to align the
reftable library's coding style to be closer to Git's own code style.

The only change compared to v2 is that I've now also converted some
calls to `reftable_malloc()` to use `REFTABLE_ALLOC_ARRAY`.

Thanks!

Patrick

Patrick Steinhardt (9):
  reftable: introduce macros to grow arrays
  reftable: introduce macros to allocate arrays
  reftable/stack: fix parameter validation when compacting range
  reftable/stack: index segments with `size_t`
  reftable/stack: use `size_t` to track stack slices during compaction
  reftable/stack: use `size_t` to track stack length
  reftable/merged: refactor seeking of records
  reftable/merged: refactor initialization of iterators
  reftable/record: improve semantics when initializing records

 reftable/basics.c          |  15 ++--
 reftable/basics.h          |  17 ++++-
 reftable/block.c           |  35 ++++-----
 reftable/block_test.c      |   2 +-
 reftable/blocksource.c     |   4 +-
 reftable/iter.c            |   3 +-
 reftable/merged.c          | 100 +++++++++++-------------
 reftable/merged_test.c     |  52 ++++++-------
 reftable/pq.c              |   8 +-
 reftable/publicbasics.c    |   3 +-
 reftable/reader.c          |  12 ++-
 reftable/readwrite_test.c  |   8 +-
 reftable/record.c          |  57 +++++---------
 reftable/record.h          |  10 +--
 reftable/record_test.c     |   8 +-
 reftable/refname.c         |   4 +-
 reftable/reftable-merged.h |   2 +-
 reftable/stack.c           | 153 +++++++++++++++++--------------------
 reftable/stack.h           |   6 +-
 reftable/stack_test.c      |   7 +-
 reftable/tree.c            |   4 +-
 reftable/writer.c          |  21 ++---
 22 files changed, 236 insertions(+), 295 deletions(-)

Range-diff against v2:
 1:  12bd721ddf =  1:  12bd721ddf reftable: introduce macros to grow arrays
 2:  2dde581a02 !  2:  95689ca7ce reftable: introduce macros to allocate arrays
    @@ Commit message
         it means that we can now provide proper overflow checks when multiplying
         the array size with the member size.
     
    -    Convert callsites of `reftable_calloc()` to the new signature, using the
    -    new macros where possible.
    +    Convert callsites of `reftable_calloc()` to the new signature and start
    +    using the new macros where possible.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
    @@ reftable/basics.h: int names_length(char **names);
      #define REFTABLE_ALLOC_GROW(x, nr, alloc) \
      	do { \
     
    + ## reftable/block.c ##
    +@@ reftable/block.c: int block_writer_finish(struct block_writer *w)
    + 		int block_header_skip = 4 + w->header_off;
    + 		uLongf src_len = w->next - block_header_skip;
    + 		uLongf dest_cap = src_len * 1.001 + 12;
    ++		uint8_t *compressed;
    ++
    ++		REFTABLE_ALLOC_ARRAY(compressed, dest_cap);
    + 
    +-		uint8_t *compressed = reftable_malloc(dest_cap);
    + 		while (1) {
    + 			uLongf out_dest_len = dest_cap;
    + 			int zresult = compress2(compressed, &out_dest_len,
    +@@ reftable/block.c: int block_reader_init(struct block_reader *br, struct reftable_block *block,
    + 		uLongf dst_len = sz - block_header_skip; /* total size of dest
    + 							    buffer. */
    + 		uLongf src_len = block->len - block_header_skip;
    +-		/* Log blocks specify the *uncompressed* size in their header.
    +-		 */
    +-		uncompressed = reftable_malloc(sz);
    ++
    ++		/* Log blocks specify the *uncompressed* size in their header. */
    ++		REFTABLE_ALLOC_ARRAY(uncompressed, sz);
    + 
    + 		/* Copy over the block header verbatim. It's not compressed. */
    + 		memcpy(uncompressed, block->data, block_header_skip);
    +
      ## reftable/block_test.c ##
     @@ reftable/block_test.c: static void test_block_read_write(void)
      	int j = 0;
    @@ reftable/readwrite_test.c: static void test_table_read_write_seek_index(void)
      	uint8_t want_hash[GIT_SHA1_RAWSZ];
      
     
    + ## reftable/record.c ##
    +@@ reftable/record.c: static void reftable_obj_record_copy_from(void *rec, const void *src_rec,
    + 		(const struct reftable_obj_record *)src_rec;
    + 
    + 	reftable_obj_record_release(obj);
    +-	obj->hash_prefix = reftable_malloc(src->hash_prefix_len);
    ++
    ++	REFTABLE_ALLOC_ARRAY(obj->hash_prefix, src->hash_prefix_len);
    + 	obj->hash_prefix_len = src->hash_prefix_len;
    + 	if (src->hash_prefix_len)
    + 		memcpy(obj->hash_prefix, src->hash_prefix, obj->hash_prefix_len);
    + 
    +-	obj->offsets = reftable_malloc(src->offset_len * sizeof(uint64_t));
    ++	REFTABLE_ALLOC_ARRAY(obj->offsets, src->offset_len);
    + 	obj->offset_len = src->offset_len;
    + 	COPY_ARRAY(obj->offsets, src->offsets, src->offset_len);
    + }
    +@@ reftable/record.c: static int reftable_obj_record_decode(void *rec, struct strbuf key,
    + 	int n = 0;
    + 	uint64_t last;
    + 	int j;
    +-	r->hash_prefix = reftable_malloc(key.len);
    ++
    ++	REFTABLE_ALLOC_ARRAY(r->hash_prefix, key.len);
    + 	memcpy(r->hash_prefix, key.buf, key.len);
    + 	r->hash_prefix_len = key.len;
    + 
    +@@ reftable/record.c: static int reftable_obj_record_decode(void *rec, struct strbuf key,
    + 	if (count == 0)
    + 		return start.len - in.len;
    + 
    +-	r->offsets = reftable_malloc(count * sizeof(uint64_t));
    ++	REFTABLE_ALLOC_ARRAY(r->offsets, count);
    + 	r->offset_len = count;
    + 
    + 	n = get_var_int(&r->offsets[0], &in);
    +@@ reftable/record.c: static void reftable_log_record_copy_from(void *rec, const void *src_rec,
    + 		}
    + 
    + 		if (dst->value.update.new_hash) {
    +-			dst->value.update.new_hash = reftable_malloc(hash_size);
    ++			REFTABLE_ALLOC_ARRAY(dst->value.update.new_hash, hash_size);
    + 			memcpy(dst->value.update.new_hash,
    + 			       src->value.update.new_hash, hash_size);
    + 		}
    + 		if (dst->value.update.old_hash) {
    +-			dst->value.update.old_hash = reftable_malloc(hash_size);
    ++			REFTABLE_ALLOC_ARRAY(dst->value.update.old_hash, hash_size);
    + 			memcpy(dst->value.update.old_hash,
    + 			       src->value.update.old_hash, hash_size);
    + 		}
    +
      ## reftable/record_test.c ##
     @@ reftable/record_test.c: static void test_reftable_log_record_roundtrip(void)
      				.value_type = REFTABLE_LOG_UPDATE,
    @@ reftable/stack.c: static ssize_t reftable_fd_write(void *arg, const void *data,
      	struct strbuf list_file_name = STRBUF_INIT;
      	int err = 0;
      
    +@@ reftable/stack.c: static int fd_read_lines(int fd, char ***namesp)
    + 		goto done;
    + 	}
    + 
    +-	buf = reftable_malloc(size + 1);
    ++	REFTABLE_ALLOC_ARRAY(buf, size + 1);
    + 	if (read_in_full(fd, buf, size) != size) {
    + 		err = REFTABLE_IO_ERROR;
    + 		goto done;
     @@ reftable/stack.c: int read_lines(const char *filename, char ***namesp)
      	int err = 0;
      	if (fd < 0) {
 3:  f134702dc5 =  3:  f0e8f08884 reftable/stack: fix parameter validation when compacting range
 4:  50dac904e8 =  4:  7bcfe7b305 reftable/stack: index segments with `size_t`
 5:  a5ffbf09dd =  5:  a0867c0378 reftable/stack: use `size_t` to track stack slices during compaction
 6:  55605fb53b =  6:  29c5a54ae8 reftable/stack: use `size_t` to track stack length
 7:  80cf2fd272 =  7:  4605ad7247 reftable/merged: refactor seeking of records
 8:  8c1be2b159 =  8:  8c35968ce8 reftable/merged: refactor initialization of iterators
 9:  c39d7e30e7 =  9:  5bb2858c13 reftable/record: improve semantics when initializing records
-- 
2.43.GIT


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-02-06  6:35 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31  8:00 [PATCH 0/9] reftable: code style improvements Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 1/9] reftable: introduce macros to grow arrays Patrick Steinhardt
2024-01-31 17:44   ` Eric Sunshine
2024-01-31 20:35   ` Junio C Hamano
2024-02-01  7:29     ` Patrick Steinhardt
2024-02-01 16:30       ` Junio C Hamano
2024-01-31  8:01 ` [PATCH 2/9] reftable: introduce macros to allocate arrays Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 3/9] reftable/stack: fix parameter validation when compacting range Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 4/9] reftable/stack: index segments with `size_t` Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 5/9] reftable/stack: use `size_t` to track stack slices during compaction Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 6/9] reftable/stack: use `size_t` to track stack length Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 7/9] reftable/merged: refactor seeking of records Patrick Steinhardt
2024-01-31 17:55   ` Eric Sunshine
2024-01-31  8:01 ` [PATCH 8/9] reftable/merged: refactor initialization of iterators Patrick Steinhardt
2024-01-31  8:01 ` [PATCH 9/9] reftable/record: improve semantics when initializing records Patrick Steinhardt
2024-02-01  7:32 ` [PATCH v2 0/9] reftable: code style improvements Patrick Steinhardt
2024-02-01  7:32   ` [PATCH v2 1/9] reftable: introduce macros to grow arrays Patrick Steinhardt
2024-02-01  7:32   ` [PATCH v2 2/9] reftable: introduce macros to allocate arrays Patrick Steinhardt
2024-02-05 15:48     ` Karthik Nayak
2024-02-06  6:10       ` Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 3/9] reftable/stack: fix parameter validation when compacting range Patrick Steinhardt
2024-02-01 16:15     ` Toon Claes
2024-02-02  5:21       ` Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 4/9] reftable/stack: index segments with `size_t` Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 5/9] reftable/stack: use `size_t` to track stack slices during compaction Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 6/9] reftable/stack: use `size_t` to track stack length Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 7/9] reftable/merged: refactor seeking of records Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 8/9] reftable/merged: refactor initialization of iterators Patrick Steinhardt
2024-02-01  7:33   ` [PATCH v2 9/9] reftable/record: improve semantics when initializing records Patrick Steinhardt
2024-02-06  6:35 ` Patrick Steinhardt [this message]
2024-02-06  6:35   ` [PATCH v3 1/9] reftable: introduce macros to grow arrays Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 2/9] reftable: introduce macros to allocate arrays Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 3/9] reftable/stack: fix parameter validation when compacting range Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 4/9] reftable/stack: index segments with `size_t` Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 5/9] reftable/stack: use `size_t` to track stack slices during compaction Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 6/9] reftable/stack: use `size_t` to track stack length Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 7/9] reftable/merged: refactor seeking of records Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 8/9] reftable/merged: refactor initialization of iterators Patrick Steinhardt
2024-02-06  6:35   ` [PATCH v3 9/9] reftable/record: improve semantics when initializing records Patrick Steinhardt
2024-02-06  9:10   ` [PATCH v3 0/9] reftable: code style improvements Karthik Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1707200355.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=sunshine@sunshineco.com \
    --cc=toon@iotcl.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).