git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/9] reftable: code style improvements

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 6, 2024, 06:35 UTC
Message-ID
<cover.1707200355.git.ps@pks.im>
In-Reply-To
<cover.1706687982.git.ps@pks.im>
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
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 30 of 40 in “reftable: code style improvements”
  1. 0/9 reftable: code style improvementsPatrick Steinhardt, Jan 31, 2024
  2. 1/9 reftable: introduce macros to grow arraysPatrick Steinhardt, Jan 31, 2024
  3. Eric SunshineJan 31, 2024
  4. Junio C HamanoJan 31, 2024
  5. Patrick SteinhardtFeb 1, 2024
  6. Junio C HamanoFeb 1, 2024
  7. 2/9 reftable: introduce macros to allocate arraysPatrick Steinhardt, Jan 31, 2024
  8. 3/9 reftable/stack: fix parameter validation when compacting rangePatrick Steinhardt, Jan 31, 2024
  9. 4/9 reftable/stack: index segments with `size_t`Patrick Steinhardt, Jan 31, 2024
  10. 5/9 reftable/stack: use `size_t` to track stack slices during compactionPatrick Steinhardt, Jan 31, 2024
  11. 6/9 reftable/stack: use `size_t` to track stack lengthPatrick Steinhardt, Jan 31, 2024
  12. 7/9 reftable/merged: refactor seeking of recordsPatrick Steinhardt, Jan 31, 2024
  13. Eric SunshineJan 31, 2024
  14. 8/9 reftable/merged: refactor initialization of iteratorsPatrick Steinhardt, Jan 31, 2024
  15. 9/9 reftable/record: improve semantics when initializing recordsPatrick Steinhardt, Jan 31, 2024
  16. 0/9 reftable: code style improvementsPatrick Steinhardt, Feb 1, 2024
  17. 1/9 reftable: introduce macros to grow arraysPatrick Steinhardt, Feb 1, 2024
  18. 2/9 reftable: introduce macros to allocate arraysPatrick Steinhardt, Feb 1, 2024
  19. Karthik NayakFeb 5, 2024
  20. Patrick SteinhardtFeb 6, 2024
  21. 3/9 reftable/stack: fix parameter validation when compacting rangePatrick Steinhardt, Feb 1, 2024
  22. Toon ClaesFeb 1, 2024
  23. Patrick SteinhardtFeb 2, 2024
  24. 4/9 reftable/stack: index segments with `size_t`Patrick Steinhardt, Feb 1, 2024
  25. 5/9 reftable/stack: use `size_t` to track stack slices during compactionPatrick Steinhardt, Feb 1, 2024
  26. 6/9 reftable/stack: use `size_t` to track stack lengthPatrick Steinhardt, Feb 1, 2024
  27. 7/9 reftable/merged: refactor seeking of recordsPatrick Steinhardt, Feb 1, 2024
  28. 8/9 reftable/merged: refactor initialization of iteratorsPatrick Steinhardt, Feb 1, 2024
  29. 9/9 reftable/record: improve semantics when initializing recordsPatrick Steinhardt, Feb 1, 2024
  30. 0/9 reftable: code style improvementsPatrick Steinhardt, Feb 6, 2024
  31. 1/9 reftable: introduce macros to grow arraysPatrick Steinhardt, Feb 6, 2024
  32. 2/9 reftable: introduce macros to allocate arraysPatrick Steinhardt, Feb 6, 2024
  33. 3/9 reftable/stack: fix parameter validation when compacting rangePatrick Steinhardt, Feb 6, 2024
  34. 4/9 reftable/stack: index segments with `size_t`Patrick Steinhardt, Feb 6, 2024
  35. 5/9 reftable/stack: use `size_t` to track stack slices during compactionPatrick Steinhardt, Feb 6, 2024
  36. 6/9 reftable/stack: use `size_t` to track stack lengthPatrick Steinhardt, Feb 6, 2024
  37. 7/9 reftable/merged: refactor seeking of recordsPatrick Steinhardt, Feb 6, 2024
  38. 8/9 reftable/merged: refactor initialization of iteratorsPatrick Steinhardt, Feb 6, 2024
  39. 9/9 reftable/record: improve semantics when initializing recordsPatrick Steinhardt, Feb 6, 2024
  40. Karthik NayakFeb 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.