Commit Graph

104 Commits

Author SHA1 Message Date
rillig e13d43880d make: unexport list memory management functions
They are only used in a single source file.

No functional change.
2023-12-29 20:43:58 +00:00
rillig 4f4e6f996b make: improve comments and a parameter name
No binary change.
2022-03-03 19:55:27 +00:00
rillig a53f37541a make: use consistent indentation for statements and continuations
No binary change, except for line numbers in assertions in suff.c.
2021-12-15 12:24:13 +00:00
rillig b310848a9c make: remove redundant comments for multiple-inclusion guards 2021-12-15 12:08:25 +00:00
rillig 7371a30a76 make: mark several functions whose result must be used
Suggested by sjg, to catch more bugs like the memory leak in cond.c
1.303 from 2021-12-13.

No binary change.
2021-12-15 09:53:41 +00:00
rillig 046937fa67 make: fix comments 2021-12-05 10:11:31 +00:00
rillig 244fd9f4c4 make: use C99 bool type instead of defining its own
No functional change.
2021-04-03 11:08:40 +00:00
rillig c175751478 make: indent inline functions for lists
No functional change.
2021-03-15 16:06:05 +00:00
rillig ef4f79b178 make: remove unused Lst_Destroy
The code in job.c that seemed to use it is inside an '#if 0' block.
2021-02-01 18:55:15 +00:00
rillig a5bfcb8bf5 make(1): remove anonymous union from struct ListNode
Anonymous structs and unions have been introduced in C11.  The code of
make is supposed to be compatible with C90 though.

The additional members were intended to be used during an interactive
debugging session only and were thus not relevant to running the actual
code.
2021-01-03 21:12:03 +00:00
rillig b754dcb0cc make(1): format multi-line comments 2020-12-30 10:03:16 +00:00
rillig ac4393a924 make(1): rename Vector.priv_cap to cap
There is no use case for accessing or even modifying the capacity of a
vector, therefore there is no need to hide it using the prefix "priv_".
This way, the member names are aligned between Buffer and Vector.
2020-12-13 20:57:17 +00:00
rillig 19fb9dcba2 make(1): inline Lst_Enqueue 2020-12-04 20:11:48 +00:00
rillig dfc53e1755 make(1): inline Vector_Done 2020-12-04 20:08:07 +00:00
rillig 12bd7715ad make(1): reduce memory allocation in Arch_ParseArchive 2020-11-28 23:13:28 +00:00
rillig aa3ed0e416 make(1): reduce pointer indirection for archives 2020-11-28 19:26:10 +00:00
rillig e93d02d95f make(1): remove pointer indirection from GNode.commands
Just to save a few memory allocations.  No noticeable effect on the
performance though.
2020-11-28 18:55:52 +00:00
rillig a41e5257d9 make(1): inline Lst_ForEachUntil in meta mode
This means no more unnecessary void pointers in function signatures and
no more abstraction level at checking a single element of a list.  In
most cases it is more appropriate to define a function that operates on
the list as a whole, thereby hiding implementation details like the
ListNode from the caller.
2020-11-27 08:07:26 +00:00
rillig 97e7e491d3 make(1): indent list functions with tabs instead of spaces 2020-11-24 19:46:29 +00:00
rillig a40fe9f746 make(1): use consistent definition for MAKE_INLINE 2020-11-10 00:32:12 +00:00
rillig 2f29849acc make(1): inline Vector_Get
It is simple enough that it neither bloats the code nor warrants the
extra function call.
2020-10-28 02:43:16 +00:00
rillig fe98ead323 make(1): remove obsolete comment from lst.h 2020-10-25 13:31:16 +00:00
rillig 57a6634b84 make(1): replace PtrVector with Vector, which can contain any type 2020-10-25 13:06:12 +00:00
rillig 10febc0902 make(1): rename type Vector to PtrVector
This allows the name Vector to be used for a more generic vector type,
which will be added soon.
2020-10-25 12:08:53 +00:00
rillig a0e49d6d3e make(1): inline Lst_Copy in Make_ExpandUse 2020-10-25 10:07:23 +00:00
rillig ff1ab01baf make(1): remove unused Lst_Find and Lst_FindFrom 2020-10-24 10:36:23 +00:00
rillig 76a498de62 make(1): remove Lst_ForEachUntilConcurrent
The remaining callers of that function don't modify the list
structurally and thus can use the simpler Lst_ForEachUntil instead.
2020-10-23 04:58:33 +00:00
rillig 1200b79007 make(1): add Lst_ForEachUntilConcurrent
Previously, Lst_ForEachUntil allowed the list to be modified while
iterating.  Almost none of the code needs this, and it's also confusing
for human readers.

None of the current unit tests makes use of this concurrent modification
right now, but that's not evidence enough.  Only 72% of the code are
covered by unit tests right now, and there are lots of edge cases
(whether intended or not) that are not covered by unit tests.

Therefore, all calls to Lst_ForEachUntil were changed to
Lst_ForEachUntilConcurrent and those that were obvious were changed
back.  The remaining calls probably don't need the concurrent
modification code, but that's not obvious from looking at the code.
2020-10-22 21:27:24 +00:00
rillig 2a4cb66e3c make(1): remove Lst_Open, Lst_Next, Lst_Close
These functions had made the Lst data type more complicated and hard to
understand than necessary.  This additional complexity was not needed in
the vast majority of the cases.
2020-10-22 20:18:20 +00:00
rillig 756d5a2e68 make(1): remove unused typedef LstActionProc 2020-10-21 07:14:22 +00:00
rillig 859199ba81 make(1): inline simple Lst getters
The function call variant takes more screen space than the direct field
access.  Having an abstract API is usually a good idea, in this case of
simple read-only member access it makes the code more difficult to read.

LstNode_Set has been kept as a function since it is not a read-only
accessor function.
2020-10-19 21:57:37 +00:00
rillig 6c8a1ff384 make(1): remove unused Lst_ForEach
All of its uses have been inlined since iterating through a linked list
is trivial.  This avoids the cumbersome callback functions with void
pointer parameters, allowing the compiler to perform better type checks.
2020-10-19 21:41:31 +00:00
rillig 2e62f9c853 make(1): add tags to enum types
This allows IDEs to offer better type information than "anonymous enum".
2020-10-18 17:19:54 +00:00
rillig 92688ee547 make(1): rename Lst_Init to Lst_New
For the other types such as HashTable and Buffer, the Init function does
not allocate the memory for the structure itself, it only fills it.
2020-10-18 13:02:10 +00:00
rillig 09fc919e11 make(1): rename Stack to Vector
Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
2020-10-18 08:58:29 +00:00
rillig 073f669ad5 make(1): inline and remove LstNode_Prev and LstNode_Next
These functions made the code larger than necessary.  The prev and next
fields are published intentionally since navigating in a doubly-linked
list is simple to do and there is no need to wrap this in a layer of
function calls, not even syntactically.  (On the execution level, the
function calls had been inlined anyway.)
2020-09-26 17:15:20 +00:00
rillig 009ae8030a make(1): add tags to some of the unnamed structs
The tags prevent the structs from accidentally becoming compatible
types.

While here, remove a few typedefs for structs that are single-purpose,
since there is no point in abstracting from the actual representation of
these types.
2020-09-25 15:54:50 +00:00
rillig 293320330f make(1): fix build on Debian 9
lst.h:92:5: error: unknown type name 'uint8_t'

It had been broken since the previous commit on 2020-09-24 08:23:29.
2020-09-25 04:18:11 +00:00
rillig ff01c24104 make(1): make the API of the List partially public
Accessing the fields List.first, List.last, ListNode.prev, ListNode.next
and ListNode.datum in read-only mode should be more efficient than a
whole function call.

All modifications to the lists or their nodes must still happen via
function calls.

This change reduces the code size, makes the code faster to execute and
allows Lst_ForEach to be written inline without the visual overhead of
function calls.
2020-09-24 08:23:29 +00:00
rillig 7a5c7eeb37 make(1): move documentation for MakeAddAllSrc to its correct place 2020-09-24 07:32:03 +00:00
rillig 4ec7405c5c make(1): rename Lst_ForEach to Lst_ForEachUntil
Since the callback function returns a terminating condition, this is not
really a foreach loop.

Many of the calls to Lst_ForEachUntil don't make use of the terminating
condition, and several don't modify the list structurally, which means
they don't need this complicated implementation.

In a follow-up commit, Lst_ForEach will be added back with a much
simpler implementation that iterates over the list naively, without a
terminating condition and without taking the iteration state from
Lst_Open/Lst_Next/Lst_Close into account.  The migration to this simpler
implementation will be done step by step since each callback function
needs to be examined closely.
2020-09-24 07:11:29 +00:00
rillig 8410b85440 make(1): refactor add_wait_dep to not use Lst_ForEachFrom anymore
It was the last remaining use of that function outside of lst.c.

While here, clean up the code of add_wait_dep by removing unreachable
code (the GNode lists never contain NULL, only the GNode.commands lists
do that).
2020-09-24 06:45:59 +00:00
rillig a2ec3df107 make(1): use fine-grained type names for lists and their nodes
This is only intended to help the human reader.  There is no additional
type safety yet.
2020-09-22 04:05:41 +00:00
rillig 9cc1256284 make(1): use a stack instead of a list for the nested include path
By using a Stack instead of a Lst, the available API is reduced to the
very few functions that are really needed for a stack.  This prevents
accidental misuse (such as confusing Lst_Append with Lst_Prepend) and
clearly communicates what the expected behavior is.

A stack also needs fewer calls to bmake_malloc than an equally-sized
list, and the memory is contiguous.  For the nested include path, all
this doesn't matter, but the type is so generic that it may be used in
other places as well.
2020-09-04 17:59:36 +00:00
rillig c62bab2173 make(1): improve grouping of the Lst functions
Lst_IsEmpty does not belong in the "create and destroy" group, but in
"query information without modifying anything".

The functions named LstNode_* all belong together.  They do not provide
much abstraction, but still they restrict the API and hide a few struct
fields that are only used internally by Lst_Open/Lst_Close and
Lst_ForEach.

Use consistent wording in the documentation of the functions (list,
node, datum).
2020-09-02 23:33:13 +00:00
rillig eb0c83b502 make(1): rename Lst_Datum to LstNode_Datum 2020-08-30 11:15:05 +00:00
rillig 2d4a05ee59 make(1): rename Lst_Memeber to Lst_FindDatum
The new name nicely aligns with Lst_Find and Lst_FindFrom.
2020-08-30 11:12:05 +00:00
rillig bb2ba6a0e5 make(1): rename LstNode functions to match their type 2020-08-29 10:41:12 +00:00
rillig f6a7d0bc31 make(1): rename Lst_FindB back to Lst_Find
The migration from "comparison function" to "match function" is done,
the "B" in the names is no longer needed.
2020-08-29 10:12:06 +00:00
rillig db2e5ed453 make(1): migrate remaining Lst_Find to Lst_FindB
While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.
2020-08-29 10:06:23 +00:00