1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00
Commit Graph

632 Commits

Author SHA1 Message Date
obarthel
115099698a Added an assertion to verify that the first free chunk on the slab's list is really always available. 2023-09-09 12:55:01 +02:00
obarthel
4f3d0c981c If the memory debug option is active, realloc() can no longer damage the trailing guard area. 2023-09-09 12:54:16 +02:00
obarthel
96af3a1165 Reformatted, so that it might be a bit more readable. 2023-09-08 17:20:51 +02:00
obarthel
6cabff4bbb Added the missing semicolon; 2023-09-08 17:20:16 +02:00
obarthel
71708e84ce The memory debugging code now places the the damage detection areas which bracket the allocation area so that the originally requested allocation size is used, not the rounded-up size. Debug output in memory node checking no longer counts the non-breaking space character as unprintable. 2023-09-08 16:11:01 +02:00
obarthel
3d70b18c23 Simplified how the slab allocator, the memory pool or AllocMem() are being used. Added robust integer overflow detection. Allocation sizes are now padded to a multiple of MEM_BLOCKSIZE. Repaired how the plain AllocMem() allocations are managed. alloca() cleanup is disabled during the stdlib_memory_exit destructor's work. The stdlib_memory_init constructor is more robust and now insists that exec.library V39+ uses memory pools. 2023-09-08 16:08:45 +02:00
obarthel
842acf2eaa Updated to properly use the MemoryNode changes. 2023-09-08 16:05:29 +02:00
obarthel
b9463f442b Added notes on calloc() being safe to use under certain circumstances if the number of elements or the element size happens to be 0. In effect, malloc() will decide what is going to happen. 2023-09-08 16:04:53 +02:00
obarthel
7ceeb4f8ed If alloca() would end up returning a NULL pointer, it now invokes the default alloca trap function, which calls abort(). You can override this, if you need to. 2023-09-08 16:03:47 +02:00
obarthel
fc8051f724 Modifed the MemoryNode so that its size will always be a multiple of MEM_BLOCKSIZE. The SlabSingleAllocation is now always a multiple of MEM_BLOCKSIZE, too. Tracking whether a MemoryNode is not supposed to be freed is now accomplished through dedicated flag instead of repurposing the allocation size field. 2023-09-08 16:02:37 +02:00
obarthel
64ba9b5389 Added the __addition_overflows() function prototype, which is used by code which checks for unsigned 32 bit integer sums exceeding the range of an unsigned 32 bit integer. 2023-09-08 16:00:38 +02:00
obarthel
1286b86f07 Added more robust integer overflow detection. Slab memory is now allocated so that its address starts on a MEM_BLOCKSIZE boundary. 2023-09-08 15:59:19 +02:00
obarthel
8101b43fc5 Tpyo correction 2023-09-08 15:52:06 +02:00
obarthel
efaffd9182 Typo corection 2023-09-08 15:51:13 +02:00
Olaf Barthel
6197531c90 Added integer overflow checking for the element_size and count parameters. 2023-09-06 13:28:48 +02:00
Olaf Barthel
b94937ff38 Fixed the bug which broke both fgets() and gets(): copying data from the FILE buffer failed to bump the destination string pointer. Also added an abort check in order to avoid turning the memcpy() operation into an uninterruptable sequence. 2023-09-06 13:27:45 +02:00
Olaf Barthel
2cb54d48a9 Added the common function which both fputs() and puts() share now. 2023-09-06 13:24:45 +02:00
Olaf Barthel
a7389454bb fputs() and puts() now share the same common code. Added abort checks in order to avoid turning the memcpy() operations into an uninterruptable sequence. 2023-09-06 13:24:15 +02:00
Olaf Barthel
45d118101a Added assertion test for the buffer alignment padding size. 2023-09-06 13:22:07 +02:00
Olaf Barthel
e4a703000a Reactivated memory debugging features. Added more robust integer overflow checking. 2023-09-06 13:21:13 +02:00
Olaf Barthel
8a4a75e721 Optionally, the slab allocator can be built to deliver 64-bit aligned allocations by default. Also, the slab allocator is no longer enabled at build time. 2023-09-06 13:20:10 +02:00
obarthel
4cb621d24d Added documentation on side-effects caused by using MEMF_CLEAR 2022-03-30 09:33:25 +02:00
obarthel
ff5826c54e Small changes to the code documentation
The memory pools store puddles near head of the allocation list and the large allocations near the tail of the list.

Some hints added to point to side-effects which might apply to memory allocation operations.
2021-12-23 13:08:08 +01:00
obarthel
b7ce13cbf8 Changed the internal data structures for slab allocations to yield 64-bit-aligned memory allocations. This can be tuned with the __MEM_ALLOCATIONS_64_BIT_ALIGNED preprocessor symbol. 2021-09-27 11:03:08 +02:00
obarthel
e71249a15b Removed the profile_profile.o file from the library to be be built. Added a comment explaining why this was necessary. 2021-09-27 11:00:54 +02:00
obarthel
19323ec218 The aggressive loop optimization option can be disabled/enabled as needed through a variable. 2021-09-27 11:00:20 +02:00
obarthel
cc8b81e7cc Added a 'C' implementation for the memory pools functions
Data structures and behaviour should follow the original (well, "original and bug-fixed") implementation.
2021-06-22 15:15:29 +02:00
obarthel
a7efdabefc Rewritten to handle date ranges better which lie outside the expected time of day, day of month and month.
The 'struct tm' is now properly updated to reflect the time and date information which comes out of the number of seconds calculated.

A bug reported by Andreas Falkenhahn is resolved which had the effect of distorting the number of seconds calculated.
2020-07-06 12:01:35 +02:00
Olaf Barthel
57774795af Typo correction. 2020-02-27 12:15:30 +01:00
Olaf Barthel
9d99542299 Fix for indentation error. 2020-02-27 12:15:17 +01:00
obarthel
e02089e28a Better handling of unbuffered mode for interactive streams
If the stream is unbuffered and turns out to be an interactive stream (e.g. stderr) then output will be made to follow the rules of line buffering to yield better readability of the output. Similar code exists with fputs(), for example.
2019-08-24 14:05:09 +02:00
obarthel
2bcfec3e60 Optimizations for better write performance.
fwrite() now tries to fill the write buffer as far is possible and will only resort to using the __putc() macros when necessary. This should improve write performance by quite a bit.

If the write buffer happens to be empty and the number of bytes to write is at least as large as the write buffer, then fwrite() will directly call write(). This should improve write performance, too.

If the file is in unbuffered mode, fwrite() now always calls write(), bypassing the write buffer altogether.
2019-08-24 14:03:34 +02:00
obarthel
4a01746be2 Optimizations for better write performance.
fputs() now works almost exactly like fwrite(), except that it's dealing with a NUL-terminated string.
2019-08-24 14:00:03 +02:00
obarthel
914ef57844 Changed how size=0 plays out
Setting the buffer size to 0 had the effect of switching the buffering mode. This is a bad idea since it wasn't actually called for: this is what the 'bufmode' parameter is intended for. What happens now is that the default buffer size is used (BUFSIZ), which sort of follows what the BSD libc did: a zero buffer size delayed the allocation of a buffer until the first read/write access occured.
2019-08-24 13:58:04 +02:00
obarthel
089ae11181 Improvements for better read performance.
gets() now tries to copy as much data from the read buffer as possible, and will fall back onto using the __getc() macro only if necessary. This should improve performance on long lines, or crash faster if the read buffer happens to be too short. This is probably wasted on gets(), but you never know...
2019-08-24 13:55:31 +02:00
obarthel
ae13cd77fc Optimizations for better read performance.
If the buffer mode is set to "no buffering" then fread() will always bypass the buffer and call read() instead.

If there is enough data waiting to be read from the buffer, fread() will now copy it directly, refilling the buffer as needed.

If the read buffer happens to be empty, buffering is enabled for the stream, and the number of bytes to read is at least as large as the buffer size,  then fread() will directly call read(), which should improve performance significantly.
2019-08-24 13:53:48 +02:00
obarthel
3f21e90fca Optimizations for better read performance
fgets() now copies as much data from the read buffer as possible, falling back onto the __getc() macro only as a last resort. This should help greatly when reading long lines since the overhead of calling __getc() goes away.
2019-08-24 13:50:41 +02:00
Olaf Barthel
5f14118d73 Fix for translation bug, which would make "a/../b" into "a./b". Contributed by Thomas Frieden - thank you very much! 2018-12-05 13:31:43 +01:00
Sebastian Bauer
b874ff71de Add wcscoll() dummy. 2018-04-22 11:21:24 +02:00
Sebastian Bauer
397013922c Use IsMinListEmpty() for MinList rather than IsListEmpty().
This removes the warnings about breaking the strict-aliasing rules.
2018-04-10 23:20:20 +02:00
Sebastian Bauer
85c36839d5 Create the proper directoy for MAKELIB. 2018-04-10 23:19:13 +02:00
Sebastian Bauer
196d37b28a Compile with -nostdlib, rather than -mcrt=clib2.
We are actually building the clib2 here.
2018-04-10 23:18:30 +02:00
Sebastian Bauer
e8086be768 Disable -Wunused-label.
There are a lot of unused lables, depending on the actual
compiling mode.
2018-04-10 23:17:08 +02:00
Sebastian Bauer
82dd474e3b Disable -Wbad-function-cast. It produces a lot of useless warnings. 2018-04-09 23:24:56 +02:00
Sebastian Bauer
58f36203b1 Fix cast to function pointer. 2018-04-09 23:24:07 +02:00
Sebastian Bauer
425f899302 Merge pull request #7 from sba1/wchar-fixes
Wchar fixes
2018-03-31 09:37:50 +02:00
Sebastian Bauer
febe89c61b Update changelog. 2018-03-30 22:17:41 +02:00
Sebastian Bauer
3e50be491b Include stdint.h for WCHAR_MAX to avoid redundant definitions. 2018-03-30 21:42:12 +02:00
Sebastian Bauer
dfc7f310d6 Don't define wchar_t in C++ as it is a bultin-type there. 2018-03-30 21:35:06 +02:00
Sebastian Bauer
a6a9352a00 Compile wchar_wscoll.c. 2018-03-30 21:21:31 +02:00