Commit Graph
100 Commits
Author SHA1 Message Date
Feoramund a0efdf26a6 mem: Clarify Buddy_Allocator requirements 2025-07-22 10:52:55 -04:00
Feoramund 58f32cd690 Fix Linux-specific optimized test failure
The stack was not aligned as expected for `buddy_allocator_init` when
`-o:speed` was enabled, making this a test failure that only appeared
with optimizations enabled.

The data is now aligned specifically, as it should be.
2025-07-22 10:40:16 -04:00
Feoramund c87655525d testing: Make test state changes its own feature
This patch takes the former debug message output of a test changing its
state and makes it its own feature, toggleable with the
`ODIN_TEST_LOG_STATE_CHANGES` configurable. The output will be at the
info level and is disabled by default.
2025-06-26 12:46:03 -04:00
Feoramund 92005ba1a6 raylib: Refer to Odin-style enum over original C enum
Fixes #4865
2025-06-23 09:20:09 -04:00
Feoramund 3608297e0b Forbid nested declaration of instrumentation procedures
Fixes #3774
2025-06-23 09:11:16 -04:00
Feoramund d343f54d6d Fix spurious failure to compile procedures marked @instrumentation_enter
The type `Source_Code_Location` may not be available yet, which causes
the compiler to not recognize the procedure type correctly.
2025-06-23 09:03:50 -04:00
Feoramund 5b1113acb4 Ensure volatile status for all atomic operations
Fixes #2410
2025-06-20 19:43:41 -04:00
Feoramund 378e72b211 Push context onto stack before evaluating procedure parameters
Fixes #4711
2025-06-20 16:11:08 -04:00
Feoramund b82753227d sys/posix: Correct reference to core:text/regex 2025-06-20 10:46:40 -04:00
Feoramund 09690691b6 text/regex: Remove old docmentation and unneeded flag
`Unsupported_Flag` was used back when the iterator did not handle
`.Multiline`.
2025-06-20 10:45:48 -04:00
Feoramund 4d4356e806 mem: Guard against Buddy_Allocator overwriting metadata 2025-06-20 06:44:44 -04:00
Feoramund bfa0e1110a mem: Don't print Buddy_Allocator.tail
This is always a pointer past the end of the buffer given to
`buddy_allocator_init`, which could be an invalid address. Printing may
result in a segmentation violation.
2025-06-20 06:41:42 -04:00
Feoramund d307e44948 Add *.a to .gitignore 2025-06-19 20:03:45 -04:00
Feoramund 2c40a198fe Make check_all.sh executable, fix two typos 2025-06-19 20:03:37 -04:00
Feoramund 7022ad8378 Add test for issue #3435 2025-06-19 19:54:12 -04:00
Feoramund c2f3d074e3 mem: Forbid construction of Buddy_Allocator with insufficient space
This takes into account eventual alignment.
2025-06-19 19:41:39 -04:00
Feoramund 57e2d8f1dd mem: Fix Buddy_Allocator size calculation to truly include alignment
This didn't take into account the size of the header plus the size of
the allocation itself by virtue of `align_forward_uint`; this could
result in no change if `size` was equal to `b.alignment` because the
number is aligned, and if `actual_size` and `size` ended up being equal,
no additional space would be requested.

This meant that a block would end up being allocated on top of its
buddy's head.

Fixes #3435
2025-06-19 19:41:38 -04:00
Feoramund 4e9f15965a mem: Fix inverted condition in buddy_allocator_alloc_bytes_non_zeroed
This was causing the procedure to find a block, then find one again,
or to not find a block and not try again.
2025-06-19 19:33:51 -04:00
Feoramund 36762ce081 Add tests for new test failure expectation API 2025-06-16 11:25:32 -04:00
Feoramund 71c6b0c8f0 testing: Add API to expect signals and assertion failures 2025-06-16 11:25:32 -04:00
Feoramund 7526549e51 Disable usage of AddressSanitizer (pt. 2) 2025-06-15 15:34:18 -04:00
Feoramund 5e929b596d Merge branch 'master' into fix-2694 2025-06-15 15:30:26 -04:00
Feoramund efba9a1fb7 Disable usage of AddressSanitizer pending a per-allocator review
It has been discovered that AddressSanitizer does not keep a 1:1 mapping
of which bytes are poisoned and which are not. This can cause issues for
allocations less than 8 bytes and where addresses straddle 8-byte
boundaries.

See the following link for more information:

https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm#mapping
2025-06-15 15:06:28 -04:00
Feoramund 0b2cf9a4ca Add a tiny sanity test for core:mem allocators 2025-06-15 14:29:30 -04:00
Feoramund 134c39b58b mem: Standardize panic messages 2025-06-15 12:34:16 -04:00
Feoramund e4258b151e mem: Review all documentation comments 2025-06-15 12:34:16 -04:00
Feoramund 7524762620 mem: Poison memory for Buddy_Allocator 2025-06-15 12:34:16 -04:00
Feoramund 7e77bd425f mem: Guard against size 0 in dynamic_arena_resize_* 2025-06-15 12:34:16 -04:00
Feoramund 78a10b462f mem: Poison memory for Dynamic_Arena 2025-06-15 12:34:16 -04:00
Feoramund de3c322899 mem: Make dynamic_arena_alloc not private
None of the other `*_alloc` procs are private, and this proc is even
referenced in public documentation comments.
2025-06-15 12:34:16 -04:00
Feoramund 652c0c997d mem: Remove bogus comments
There is no `dynamic_arena_free`; the mode is not implemented
2025-06-15 12:34:15 -04:00
Feoramund c1e3171178 mem: Remove comment about calling panic
The behavior is codified in the comment as returning `Invalid_Pointer`.
2025-06-15 12:34:15 -04:00
Feoramund aaeae8bc7d mem: Remove trailing whitespace 2025-06-15 12:34:15 -04:00
Feoramund 47a54dd11a mem: Panic when passing invalid pointers to small stack free/resize
This is consistent with `Stack_Allocator`.
2025-06-15 12:34:15 -04:00
Feoramund d7e98ba82a Add test for issue #2694 2025-06-15 12:34:15 -04:00
Feoramund 3261896790 mem: Correct wrong error message 2025-06-15 12:34:15 -04:00
Feoramund aa41a77fc4 mem: Check if alignment matches on Small_Stack resize 2025-06-15 12:34:15 -04:00
Feoramund 3a02918efc mem: Make small_stack_resize* free if size is 0 2025-06-15 12:34:15 -04:00
Feoramund a4771ce1b5 mem: Clarify what happens when you free out-of-order in a Small_Stack 2025-06-15 12:34:15 -04:00
Feoramund 21a17c1ae6 mem: Replace auto_cast 2025-06-15 12:34:15 -04:00
Feoramund 8f68c46467 mem: Don't unpoison the header of a Small_Stack allocation 2025-06-15 12:34:15 -04:00
Feoramund 5798151a0e mem: Poison unused memory more thoroughly 2025-06-14 13:21:15 -04:00
Feoramund ae96b276c1 mem: Check if alignment matches on Stack_Allocator resize 2025-06-14 13:21:15 -04:00
Feoramund 837d8cf72c mem: Actually resize when resizing for Stack_Allocator
Changed the check from `bytes` to `err` for safety's sake, too.

This will prevent the potential bug of allocating non-zero memory, then
doing a zeroed resize, which will result in having garbage data in the
initial half.
2025-06-14 13:21:14 -04:00
Feoramund f701aeffd5 mem: Correct wrong error message 2025-06-14 13:21:14 -04:00
Feoramund 7580dc2dd0 mem: Remove pointless check in Scratch_Allocator
The backup allocator is set at `init` which happens even if `Scratch` is
nil at the head of `scratch_alloc_bytes_non_zeroed`.
2025-06-14 13:21:14 -04:00
Feoramund c4f6e973d9 mem: Don't change Scratch_Allocator's backup allocator
The backup allocator is set at `init` and must stay the same for the
lifetime of the Scratch allocator, as this allocator is used to free all
`leaked_allocations`. Changing it could lead to a situation where the
wrong allocator is used to free a leaked allocation.
2025-06-14 13:21:14 -04:00
Feoramund 62b0f71768 mem: Fix comment typo 2025-06-14 13:21:14 -04:00
Feoramund 890245c229 mem: Don't unpoison the header of a Stack allocation 2025-06-14 13:21:14 -04:00
Feoramund 79e5ddaa26 mem: Make stack_resize* free if size is 0
This will cause an error if the memory being resized was not the last
allocation, as should be expected according to the description that this
"acts just like stack_free."
2025-06-14 13:21:14 -04:00
Feoramund 179a8559f6 mem: Add guards against buggy allocators overlapping allocations 2025-06-14 13:21:14 -04:00
Feoramund f627b55cf5 mem: Fix several issues in Scratch_Allocator
1. The size was being adjusted for the alignment which does not make any
   sense without the context of the base pointer. Now we just add the
   `alignment - 1` to the size if needed then adjust the pointer.

2. The root pointer of the last allocation is now stored in order to
   make the free operation more useful (and to cover the right memory
   region for ASan).

3. Resizing now only works on the last allocation instead of any address
   in a valid range, which resulted in overwriting allocations that had
   just been made.

4. `old_memory` is now re-poisoned entirely before the resized range is
   returned with the new range unpoisoned. This will guarantee that
   there are no unpoisoned gaps.

Fixes #2694
2025-06-14 12:35:16 -04:00
Feoramund 61f9fb7232 runtime: Remove unneeded max(0, ...)
`len` never returns negative numbers, so this was an overcautious
expression.
2025-06-13 12:09:10 -04:00
Feoramund 23c1ce8722 container/queue: Remove trailing whitespace 2025-06-11 11:57:38 -04:00
Feoramund 66b2acbf24 container/queue: Add tests 2025-06-11 11:55:30 -04:00
Feoramund 638a1529a3 container/queue: Add shrink 2025-06-11 11:55:30 -04:00
Feoramund 040d79e1b9 container/queue: Let queues be re-initialized with different allocators 2025-06-11 11:55:30 -04:00
Feoramund 81f5763482 container/queue: Add common aliases enqueue and dequeue 2025-06-11 11:55:30 -04:00
Feoramund 6cb84e467b container/queue: Document the package 2025-06-11 11:55:30 -04:00
Feoramund 862442511a container/queue: Reorganize 2025-06-11 11:55:29 -04:00
Feoramund 58bda1209a container/queue: Deprecate peek_*
The `*_ptr` and `peek_*` procedures did the same thing, except `peek_*`
was over-cautiously putting the index through a modulo when all
assignments to `q.offset` are already wrapped.
2025-06-11 11:54:52 -04:00
Feoramund 27cd508571 container/queue: Fix and add more bounds checking 2025-06-11 11:54:47 -04:00
Feoramund 1fc390146f Let -no-entry-point work for Windows DLLs
Fixes #4660
2025-06-10 08:54:28 -04:00
Feoramund 4236b043e2 Move negation in internal_rat_to_float to end of procedure
This should cause a compiler error, due to the assignment to a named
return value in a deferred block.

Fixes #4565
2025-06-10 08:34:07 -04:00
Feoramund 5ed2735658 Guard against invalid proc types in parameter list
Fixes #4362
2025-06-10 06:13:14 -04:00
Feoramund 6dee422700 flags: Rename varg to overflow, let it be renamed with config 2025-06-09 13:02:05 -04:00
Feoramund 2e199c669f flags: Forbid combination of pos and manifold 2025-06-09 11:39:10 -04:00
Feoramund cae43b801f Add more core:flags tests to codify behavior 2025-06-09 11:39:10 -04:00
Feoramund 7c5700996f flags: Mention varg in the documentation 2025-06-09 11:39:10 -04:00
Feoramund e20db8df89 flags: Rename variadic to manifold (breaking change) 2025-06-09 11:27:27 -04:00
Feoramund 0747032e4a Use idiomatic rawptr(nil) 2025-06-08 17:48:06 -04:00
Feoramund 54f018ffc7 Guard against untyped nil in type cycle and type info sections
Fixes #5299
2025-06-08 17:48:01 -04:00
Feoramund 1cd1f9fec4 Add nullptr check in add_type_info_type_internal
Fixes #5215
2025-06-06 09:23:06 -04:00
Feoramund 2760f43ce7 Add deprecation warnings for strconv.append_* 2025-06-05 17:34:14 -04:00
Feoramund 153f7af594 Rename fixed.append to fixed.write too, for good measure 2025-06-05 16:56:29 -04:00
Feoramund 0049c62b26 Remove trailing whitespace 2025-06-05 16:56:01 -04:00
Feoramund b7de15caa3 Clarify strconv.append_* to strconv.write_* 2025-06-05 16:56:00 -04:00
Feoramund f8228a91d1 Mark some uninitialized memory as safe
Syscalls (but not C functions) are opaque to MemorySanitizer, thus some
memory addresses need to be manually marked as safe to access.
2025-06-05 16:06:44 -04:00
Feoramund 9c5640886d Add @(no_sanitize_memory) proc attribute with MSan additions to base:sanitizer 2025-06-05 16:06:40 -04:00
Feoramund 36b41ce163 Let compound literal array be broadcast to a struct field of arrays
Fixes #4364

Patch courtesy of @cribalik
2025-06-05 07:48:10 -04:00
Feoramund d046214f67 Be strict with type switch case column alignment too
This copies the same block used for regular switch cases.

Fixes #4673
2025-06-04 14:00:33 -04:00
Feoramund b0d050dd90 Print timings to stderr instead of stdout
This is in line with other diagnostic messages.

Fixes #4642
2025-06-04 13:59:31 -04:00
Feoramund 91111937a7 Guard against negative index in inject_at
Fixes #4595
2025-06-04 13:58:06 -04:00
Feoramund 68ed631582 Forbid multiple uses of -sanitize
`clang` does not allow this.

Fixes #4354
2025-06-03 21:23:24 -04:00
Feoramund 09ddf121e3 Fix typo 2025-06-03 21:15:20 -04:00
Feoramund 8cde9dce47 Rewrite Atomic_RW_Mutex
This patch simplifies the implementation and fixes #5254.

Previously, the mutex was set up as if there could be multiple writers,
and there seemed to be some confusion as to which `Writer` bits to
check, as not all were checked or set at the same time.

This could also result in the mutex being left in a non-zero state even
after unlocking all locks.

All unneeded state has been removed and extra checks have been put in
place.
2025-06-03 09:07:38 -04:00
Feoramund 16b8da6a79 Let -test-all-packages work with -build-mode:test
Fixes #3930
2025-06-02 07:47:19 -04:00
Feoramund 7996f89410 Show quaternion arguments in wxyz order, instead of xyzw, in mismatched type error
This is in accordance with the other error and makes sense with how
quaternions are printed with `real`/`w` coming first, then the
imaginaries, which are the `ijk`/`xyz` parts.
2025-06-01 14:36:38 -04:00
Feoramund b70d2b156a Make quaternion untyped values convert to first typed value found
This fixes an issue (#2079) where a typed argument could cause the
construction to fail on the basis of failed untyped -> typed conversion.
2025-06-01 14:35:53 -04:00
Feoramund 705ae3f343 Fix quaternion construction causing compiler crash
Previously, a construction of `quaternion(real=0, real=1, real=2,
real=3)` could crash the compiler.
2025-06-01 13:35:22 -04:00
Feoramund 57019f199c Add suggestions for quaternionN or complexN conversions
Quaternions and complex numbers are constructed with `quaternion` and
`complex`, but their types are of the `*N` form.

These suggestions should point the user in the right direction.
2025-05-31 07:09:29 -04:00
Feoramund 598c1a1f19 Allow overriding object extension in -build-mode:obj 2025-05-30 08:01:23 -04:00
Feoramund 73866b6b3d Remove trailing whitespace 2025-05-30 07:31:03 -04:00
Feoramund ee8234c792 Don't double-append module name when building separate objects
`m->module_name` will already have the `BuildPath_Output` name
prepended.
2025-05-30 07:15:34 -04:00
Feoramund 3c1201fb2c Error on unterminated multi-line comment 2025-05-29 18:28:54 -04:00
Feoramund 45219f240e Rename SIMD_IS_EMULATED to capability-affirmative HAS_HARDWARE_SIMD 2025-05-29 17:17:51 -04:00
Feoramund edbd247972 Use time.Stopwatch in core:bytes benchmark
This should result in a clearer idea of how fast the procedures are
running, as the loop can run without going back and forth to the system
for the time.
2025-05-29 16:35:26 -04:00
Feoramund 4e49fb4f82 Add benchmarks for runtime.memory_* comparison procedures 2025-05-29 16:35:26 -04:00
Feoramund b15a665898 Add tests for runtime.memory_* comparison procedures 2025-05-29 16:34:07 -04:00
Feoramund 34698288b8 Vectorize runtime.memory_* comparison procedures 2025-05-29 16:29:13 -04:00