@zigc/lib 0.16.0-test.1 → 0.17.0-dev.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/c/fcntl.zig +6 -1
- package/c/inttypes.zig +0 -10
- package/c/math.zig +138 -114
- package/c/pthread.zig +57 -0
- package/c/search.zig +1 -27
- package/c/stdlib/drand48.zig +0 -57
- package/c/stdlib.zig +0 -100
- package/c/string.zig +20 -7
- package/c/strings.zig +0 -38
- package/c/stropts.zig +17 -0
- package/c/unistd.zig +27 -26
- package/c/wchar.zig +10 -0
- package/c.zig +3 -2
- package/compiler/aro/aro/Attribute/names.zig +604 -589
- package/compiler/aro/aro/Attribute.zig +202 -116
- package/compiler/aro/aro/Builtins/common.zig +874 -863
- package/compiler/aro/aro/Builtins/eval.zig +15 -7
- package/compiler/aro/aro/Builtins.zig +0 -1
- package/compiler/aro/aro/CodeGen.zig +8 -7
- package/compiler/aro/aro/Compilation.zig +137 -111
- package/compiler/aro/aro/Diagnostics.zig +21 -17
- package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
- package/compiler/aro/aro/Driver.zig +138 -63
- package/compiler/aro/aro/LangOpts.zig +12 -2
- package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
- package/compiler/aro/aro/Parser.zig +352 -153
- package/compiler/aro/aro/Pragma.zig +3 -2
- package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
- package/compiler/aro/aro/Preprocessor.zig +136 -62
- package/compiler/aro/aro/Target.zig +17 -12
- package/compiler/aro/aro/Tokenizer.zig +31 -14
- package/compiler/aro/aro/Toolchain.zig +4 -7
- package/compiler/aro/aro/Tree.zig +178 -148
- package/compiler/aro/aro/TypeStore.zig +82 -24
- package/compiler/aro/aro/Value.zig +13 -17
- package/compiler/aro/aro/features.zig +1 -0
- package/compiler/aro/aro/pragmas/message.zig +3 -2
- package/compiler/aro/aro/pragmas/once.zig +0 -1
- package/compiler/aro/aro/record_layout.zig +3 -3
- package/compiler/aro/aro/text_literal.zig +3 -2
- package/compiler/aro/assembly_backend/x86_64.zig +7 -8
- package/compiler/aro/backend/Assembly.zig +1 -2
- package/compiler/aro/backend/Interner.zig +2 -2
- package/compiler/aro/backend/Ir.zig +100 -92
- package/compiler/aro/include/ptrcheck.h +49 -0
- package/compiler/aro/main.zig +26 -10
- package/compiler/build_runner.zig +1 -2
- package/compiler/objdump.zig +93 -0
- package/compiler/reduce/Walk.zig +7 -7
- package/compiler/reduce.zig +5 -1
- package/compiler/resinator/compile.zig +2 -2
- package/compiler/resinator/main.zig +7 -1
- package/compiler/resinator/preprocess.zig +1 -3
- package/compiler/std-docs.zig +8 -1
- package/compiler/test_runner.zig +194 -62
- package/compiler/translate-c/MacroTranslator.zig +80 -11
- package/compiler/translate-c/PatternList.zig +1 -9
- package/compiler/translate-c/Scope.zig +43 -6
- package/compiler/translate-c/Translator.zig +369 -127
- package/compiler/translate-c/ast.zig +19 -11
- package/compiler/translate-c/main.zig +76 -17
- package/compiler_rt/cos.zig +140 -53
- package/compiler_rt/divmodei4.zig +40 -17
- package/compiler_rt/exp.zig +1 -6
- package/compiler_rt/exp2.zig +1 -6
- package/compiler_rt/exp_f128.zig +377 -0
- package/compiler_rt/fabs.zig +0 -2
- package/compiler_rt/fma.zig +0 -2
- package/compiler_rt/fmax.zig +0 -2
- package/compiler_rt/fmin.zig +0 -2
- package/compiler_rt/fmod.zig +0 -2
- package/compiler_rt/limb64.zig +1127 -0
- package/compiler_rt/log.zig +0 -2
- package/compiler_rt/log10.zig +0 -2
- package/compiler_rt/log2.zig +0 -2
- package/compiler_rt/long_double.zig +37 -0
- package/compiler_rt/mulXi3.zig +1 -1
- package/compiler_rt/mulo.zig +6 -1
- package/compiler_rt/rem_pio2l.zig +173 -0
- package/compiler_rt/round.zig +0 -2
- package/compiler_rt/sin.zig +139 -56
- package/compiler_rt/sincos.zig +277 -72
- package/compiler_rt/sqrt.zig +0 -2
- package/compiler_rt/ssp.zig +1 -1
- package/compiler_rt/tan.zig +117 -48
- package/compiler_rt/trig.zig +256 -6
- package/compiler_rt/trunc.zig +0 -2
- package/compiler_rt/udivmodei4.zig +28 -0
- package/compiler_rt.zig +2 -0
- package/fuzzer.zig +857 -307
- package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
- package/libc/musl/src/math/pow.c +343 -0
- package/package.json +1 -1
- package/std/Build/Cache.zig +6 -6
- package/std/Build/Fuzz.zig +6 -19
- package/std/Build/Module.zig +1 -1
- package/std/Build/Step/CheckObject.zig +3 -3
- package/std/Build/Step/Compile.zig +18 -1
- package/std/Build/Step/ConfigHeader.zig +49 -33
- package/std/Build/Step/InstallArtifact.zig +18 -0
- package/std/Build/Step/Run.zig +538 -89
- package/std/Build/Step/TranslateC.zig +0 -6
- package/std/Build/Step.zig +10 -19
- package/std/Build/WebServer.zig +31 -19
- package/std/Build/abi.zig +47 -11
- package/std/Build.zig +17 -17
- package/std/Io/Dir.zig +7 -2
- package/std/Io/Dispatch.zig +5 -13
- package/std/Io/File/Reader.zig +3 -1
- package/std/Io/File/Writer.zig +8 -6
- package/std/Io/File.zig +1 -0
- package/std/Io/Kqueue.zig +2 -2
- package/std/Io/Reader.zig +8 -9
- package/std/Io/Semaphore.zig +112 -17
- package/std/Io/Terminal.zig +1 -1
- package/std/Io/Threaded.zig +352 -180
- package/std/Io/Uring.zig +15 -16
- package/std/Io/Writer.zig +46 -42
- package/std/Io/net.zig +11 -11
- package/std/Io.zig +1052 -20
- package/std/SemanticVersion.zig +1 -1
- package/std/Target/Query.zig +2 -2
- package/std/Target.zig +53 -7
- package/std/Thread.zig +8 -3
- package/std/array_hash_map.zig +105 -573
- package/std/array_list.zig +22 -31
- package/std/bit_set.zig +22 -6
- package/std/builtin/assembly.zig +68 -0
- package/std/builtin.zig +4 -0
- package/std/c/haiku.zig +3 -0
- package/std/c/serenity.zig +1 -6
- package/std/c.zig +106 -24
- package/std/compress/flate/Compress.zig +3 -3
- package/std/compress/flate/Decompress.zig +2 -3
- package/std/compress/zstd/Decompress.zig +2 -4
- package/std/crypto/Certificate/Bundle.zig +15 -1
- package/std/crypto/Certificate.zig +13 -1
- package/std/crypto/ascon.zig +75 -33
- package/std/crypto/codecs/asn1/Oid.zig +12 -1
- package/std/crypto/codecs/asn1.zig +33 -18
- package/std/crypto/codecs/base64_hex_ct.zig +16 -8
- package/std/crypto/ml_kem.zig +2 -9
- package/std/crypto/tls/Client.zig +79 -4
- package/std/crypto/tls.zig +1 -1
- package/std/crypto.zig +1 -0
- package/std/debug/Dwarf.zig +29 -9
- package/std/debug/Info.zig +4 -0
- package/std/debug/MachOFile.zig +46 -8
- package/std/debug/Pdb.zig +540 -37
- package/std/debug/SelfInfo/Elf.zig +19 -18
- package/std/debug/SelfInfo/MachO.zig +18 -7
- package/std/debug/SelfInfo/Windows.zig +138 -36
- package/std/debug.zig +181 -66
- package/std/enums.zig +25 -19
- package/std/fmt.zig +8 -3
- package/std/fs/path.zig +6 -4
- package/std/heap/ArenaAllocator.zig +145 -154
- package/std/heap/BufferFirstAllocator.zig +165 -0
- package/std/heap/debug_allocator.zig +7 -7
- package/std/heap.zig +2 -126
- package/std/http/Client.zig +31 -30
- package/std/http.zig +14 -13
- package/std/json/Scanner.zig +2 -2
- package/std/json/Stringify.zig +3 -3
- package/std/json/dynamic.zig +4 -4
- package/std/math/big/int.zig +16 -17
- package/std/mem/Allocator.zig +4 -5
- package/std/mem.zig +48 -0
- package/std/os/emscripten.zig +2 -18
- package/std/os/linux/IoUring.zig +2 -0
- package/std/os/linux/aarch64.zig +41 -12
- package/std/os/linux/arc.zig +173 -0
- package/std/os/linux/arm.zig +41 -12
- package/std/os/linux/hexagon.zig +33 -11
- package/std/os/linux/loongarch32.zig +41 -13
- package/std/os/linux/loongarch64.zig +41 -12
- package/std/os/linux/m68k.zig +41 -13
- package/std/os/linux/mips.zig +67 -36
- package/std/os/linux/mips64.zig +60 -29
- package/std/os/linux/mipsn32.zig +60 -29
- package/std/os/linux/or1k.zig +41 -12
- package/std/os/linux/powerpc.zig +41 -12
- package/std/os/linux/powerpc64.zig +41 -12
- package/std/os/linux/riscv32.zig +41 -12
- package/std/os/linux/riscv64.zig +41 -12
- package/std/os/linux/s390x.zig +44 -7
- package/std/os/linux/sparc64.zig +83 -52
- package/std/os/linux/thumb.zig +52 -36
- package/std/os/linux/x32.zig +41 -12
- package/std/os/linux/x86.zig +42 -13
- package/std/os/linux/x86_64.zig +41 -12
- package/std/os/linux.zig +419 -438
- package/std/os/uefi/tables/boot_services.zig +9 -8
- package/std/os/windows.zig +2 -2
- package/std/os.zig +41 -0
- package/std/pdb.zig +143 -4
- package/std/posix.zig +6 -12
- package/std/priority_dequeue.zig +13 -12
- package/std/priority_queue.zig +5 -4
- package/std/process/Child.zig +1 -1
- package/std/process/Environ.zig +1 -1
- package/std/process.zig +1 -1
- package/std/sort.zig +3 -3
- package/std/start.zig +17 -4
- package/std/std.zig +19 -6
- package/std/testing/FailingAllocator.zig +4 -4
- package/std/testing/Smith.zig +37 -2
- package/std/zig/Ast/Render.zig +187 -459
- package/std/zig/Ast.zig +0 -4
- package/std/zig/AstGen.zig +86 -103
- package/std/zig/AstRlAnnotate.zig +0 -11
- package/std/zig/AstSmith.zig +2602 -0
- package/std/zig/BuiltinFn.zig +0 -32
- package/std/zig/Client.zig +8 -3
- package/std/zig/LibCInstallation.zig +4 -3
- package/std/zig/Parse.zig +90 -81
- package/std/zig/Server.zig +26 -0
- package/std/zig/WindowsSdk.zig +13 -13
- package/std/zig/Zir.zig +66 -62
- package/std/zig/ZonGen.zig +6 -5
- package/std/zig/c_translation/helpers.zig +14 -9
- package/std/zig/llvm/Builder.zig +119 -60
- package/std/zig/system.zig +20 -4
- package/std/zig/tokenizer.zig +2 -1
- package/std/zig.zig +7 -10
- package/std/zip.zig +5 -5
- package/zig.h +340 -1
- package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
- package/libc/mingw/complex/cabs.c +0 -48
- package/libc/mingw/complex/cabsf.c +0 -48
- package/libc/mingw/complex/cacos.c +0 -50
- package/libc/mingw/complex/cacosf.c +0 -50
- package/libc/mingw/complex/carg.c +0 -48
- package/libc/mingw/complex/cargf.c +0 -48
- package/libc/mingw/complex/casin.c +0 -50
- package/libc/mingw/complex/casinf.c +0 -50
- package/libc/mingw/complex/catan.c +0 -50
- package/libc/mingw/complex/catanf.c +0 -50
- package/libc/mingw/complex/ccos.c +0 -50
- package/libc/mingw/complex/ccosf.c +0 -50
- package/libc/mingw/complex/cexp.c +0 -48
- package/libc/mingw/complex/cexpf.c +0 -48
- package/libc/mingw/complex/cimag.c +0 -48
- package/libc/mingw/complex/cimagf.c +0 -48
- package/libc/mingw/complex/clog.c +0 -48
- package/libc/mingw/complex/clog10.c +0 -49
- package/libc/mingw/complex/clog10f.c +0 -49
- package/libc/mingw/complex/clogf.c +0 -48
- package/libc/mingw/complex/conj.c +0 -48
- package/libc/mingw/complex/conjf.c +0 -48
- package/libc/mingw/complex/cpow.c +0 -48
- package/libc/mingw/complex/cpowf.c +0 -48
- package/libc/mingw/complex/cproj.c +0 -48
- package/libc/mingw/complex/cprojf.c +0 -48
- package/libc/mingw/complex/creal.c +0 -48
- package/libc/mingw/complex/crealf.c +0 -48
- package/libc/mingw/complex/csin.c +0 -50
- package/libc/mingw/complex/csinf.c +0 -50
- package/libc/mingw/complex/csqrt.c +0 -48
- package/libc/mingw/complex/csqrtf.c +0 -48
- package/libc/mingw/complex/ctan.c +0 -50
- package/libc/mingw/complex/ctanf.c +0 -50
- package/libc/mingw/math/arm/s_rint.c +0 -86
- package/libc/mingw/math/arm/s_rintf.c +0 -51
- package/libc/mingw/math/arm/sincos.S +0 -30
- package/libc/mingw/math/arm-common/sincosl.c +0 -13
- package/libc/mingw/math/arm64/rint.c +0 -12
- package/libc/mingw/math/arm64/rintf.c +0 -12
- package/libc/mingw/math/arm64/sincos.S +0 -32
- package/libc/mingw/math/bsd_private_base.h +0 -148
- package/libc/mingw/math/fdiml.c +0 -24
- package/libc/mingw/math/frexpf.c +0 -13
- package/libc/mingw/math/frexpl.c +0 -71
- package/libc/mingw/math/x86/acosf.c +0 -29
- package/libc/mingw/math/x86/atanf.c +0 -23
- package/libc/mingw/math/x86/atanl.c +0 -18
- package/libc/mingw/math/x86/cos.def.h +0 -65
- package/libc/mingw/math/x86/cosl.c +0 -46
- package/libc/mingw/math/x86/cosl_internal.S +0 -55
- package/libc/mingw/math/x86/ldexp.c +0 -23
- package/libc/mingw/math/x86/scalbn.S +0 -41
- package/libc/mingw/math/x86/scalbnf.S +0 -40
- package/libc/mingw/math/x86/sin.def.h +0 -65
- package/libc/mingw/math/x86/sinl.c +0 -46
- package/libc/mingw/math/x86/sinl_internal.S +0 -58
- package/libc/mingw/math/x86/tanl.S +0 -62
- package/libc/mingw/misc/btowc.c +0 -28
- package/libc/mingw/misc/wcstof.c +0 -66
- package/libc/mingw/misc/wcstoimax.c +0 -132
- package/libc/mingw/misc/wcstoumax.c +0 -126
- package/libc/mingw/misc/wctob.c +0 -29
- package/libc/mingw/misc/winbs_uint64.c +0 -6
- package/libc/mingw/misc/winbs_ulong.c +0 -6
- package/libc/mingw/misc/winbs_ushort.c +0 -6
- package/libc/mingw/stdio/_Exit.c +0 -10
- package/libc/mingw/stdio/_findfirst64i32.c +0 -21
- package/libc/mingw/stdio/_findnext64i32.c +0 -21
- package/libc/mingw/stdio/_fstat64i32.c +0 -37
- package/libc/mingw/stdio/_stat64i32.c +0 -37
- package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
- package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
- package/libc/mingw/stdio/_wstat64i32.c +0 -37
- package/libc/mingw/winpthreads/spinlock.c +0 -82
- package/libc/musl/src/legacy/isastream.c +0 -7
- package/libc/musl/src/legacy/valloc.c +0 -8
- package/libc/musl/src/linux/tee.c +0 -8
- package/libc/musl/src/math/__cosl.c +0 -96
- package/libc/musl/src/math/__sinl.c +0 -78
- package/libc/musl/src/math/__tanl.c +0 -143
- package/libc/musl/src/math/aarch64/lrint.c +0 -10
- package/libc/musl/src/math/aarch64/lrintf.c +0 -10
- package/libc/musl/src/math/aarch64/rintf.c +0 -7
- package/libc/musl/src/math/cosl.c +0 -39
- package/libc/musl/src/math/fdim.c +0 -10
- package/libc/musl/src/math/fdimf.c +0 -10
- package/libc/musl/src/math/fdiml.c +0 -18
- package/libc/musl/src/math/finite.c +0 -7
- package/libc/musl/src/math/finitef.c +0 -7
- package/libc/musl/src/math/frexp.c +0 -23
- package/libc/musl/src/math/frexpf.c +0 -23
- package/libc/musl/src/math/frexpl.c +0 -29
- package/libc/musl/src/math/i386/lrint.c +0 -8
- package/libc/musl/src/math/i386/lrintf.c +0 -8
- package/libc/musl/src/math/i386/rintf.c +0 -7
- package/libc/musl/src/math/lrint.c +0 -72
- package/libc/musl/src/math/lrintf.c +0 -8
- package/libc/musl/src/math/powerpc64/lrint.c +0 -16
- package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
- package/libc/musl/src/math/rintf.c +0 -30
- package/libc/musl/src/math/s390x/rintf.c +0 -15
- package/libc/musl/src/math/sincosl.c +0 -60
- package/libc/musl/src/math/sinl.c +0 -41
- package/libc/musl/src/math/tanl.c +0 -29
- package/libc/musl/src/math/x32/lrint.s +0 -5
- package/libc/musl/src/math/x32/lrintf.s +0 -5
- package/libc/musl/src/math/x86_64/lrint.c +0 -8
- package/libc/musl/src/math/x86_64/lrintf.c +0 -8
- package/libc/musl/src/string/strdup.c +0 -10
- package/libc/musl/src/string/strndup.c +0 -12
- package/libc/musl/src/string/wcsdup.c +0 -10
- package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
- package/libc/musl/src/thread/pthread_spin_init.c +0 -6
- package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
- package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
- package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
- package/libc/musl/src/unistd/dup2.c +0 -20
- package/libc/musl/src/unistd/dup3.c +0 -26
- package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
- package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
- package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
- package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
package/std/heap.zig
CHANGED
|
@@ -12,6 +12,7 @@ const Alignment = std.mem.Alignment;
|
|
|
12
12
|
pub const ArenaAllocator = @import("heap/ArenaAllocator.zig");
|
|
13
13
|
pub const SmpAllocator = @import("heap/SmpAllocator.zig");
|
|
14
14
|
pub const FixedBufferAllocator = @import("heap/FixedBufferAllocator.zig");
|
|
15
|
+
pub const BufferFirstAllocator = @import("heap/BufferFirstAllocator.zig");
|
|
15
16
|
pub const PageAllocator = @import("heap/PageAllocator.zig");
|
|
16
17
|
pub const WasmAllocator = if (builtin.single_threaded) BrkAllocator else @compileError("unimplemented");
|
|
17
18
|
pub const BrkAllocator = @import("heap/BrkAllocator.zig");
|
|
@@ -367,113 +368,6 @@ pub const brk_allocator: Allocator = .{
|
|
|
367
368
|
.vtable = &BrkAllocator.vtable,
|
|
368
369
|
};
|
|
369
370
|
|
|
370
|
-
/// Returns a `StackFallbackAllocator` allocating using either a
|
|
371
|
-
/// `FixedBufferAllocator` on an array of size `size` and falling back to
|
|
372
|
-
/// `fallback_allocator` if that fails.
|
|
373
|
-
pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackFallbackAllocator(size) {
|
|
374
|
-
return StackFallbackAllocator(size){
|
|
375
|
-
.buffer = undefined,
|
|
376
|
-
.fallback_allocator = fallback_allocator,
|
|
377
|
-
.fixed_buffer_allocator = undefined,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/// An allocator that attempts to allocate using a
|
|
382
|
-
/// `FixedBufferAllocator` using an array of size `size`. If the
|
|
383
|
-
/// allocation fails, it will fall back to using
|
|
384
|
-
/// `fallback_allocator`. Easily created with `stackFallback`.
|
|
385
|
-
pub fn StackFallbackAllocator(comptime size: usize) type {
|
|
386
|
-
return struct {
|
|
387
|
-
const Self = @This();
|
|
388
|
-
|
|
389
|
-
buffer: [size]u8,
|
|
390
|
-
fallback_allocator: Allocator,
|
|
391
|
-
fixed_buffer_allocator: FixedBufferAllocator,
|
|
392
|
-
get_called: if (std.debug.runtime_safety) bool else void =
|
|
393
|
-
if (std.debug.runtime_safety) false else {},
|
|
394
|
-
|
|
395
|
-
/// This function both fetches a `Allocator` interface to this
|
|
396
|
-
/// allocator *and* resets the internal buffer allocator.
|
|
397
|
-
pub fn get(self: *Self) Allocator {
|
|
398
|
-
if (std.debug.runtime_safety) {
|
|
399
|
-
assert(!self.get_called); // `get` called multiple times; instead use `const allocator = stackFallback(N).get();`
|
|
400
|
-
self.get_called = true;
|
|
401
|
-
}
|
|
402
|
-
self.fixed_buffer_allocator = FixedBufferAllocator.init(self.buffer[0..]);
|
|
403
|
-
return .{
|
|
404
|
-
.ptr = self,
|
|
405
|
-
.vtable = &.{
|
|
406
|
-
.alloc = alloc,
|
|
407
|
-
.resize = resize,
|
|
408
|
-
.remap = remap,
|
|
409
|
-
.free = free,
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/// Unlike most std allocators `StackFallbackAllocator` modifies
|
|
415
|
-
/// its internal state before returning an implementation of
|
|
416
|
-
/// the`Allocator` interface and therefore also doesn't use
|
|
417
|
-
/// the usual `.allocator()` method.
|
|
418
|
-
pub const allocator = @compileError("use 'const allocator = stackFallback(N).get();' instead");
|
|
419
|
-
|
|
420
|
-
fn alloc(
|
|
421
|
-
ctx: *anyopaque,
|
|
422
|
-
len: usize,
|
|
423
|
-
alignment: Alignment,
|
|
424
|
-
ra: usize,
|
|
425
|
-
) ?[*]u8 {
|
|
426
|
-
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
427
|
-
return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, alignment, ra) orelse
|
|
428
|
-
return self.fallback_allocator.rawAlloc(len, alignment, ra);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
fn resize(
|
|
432
|
-
ctx: *anyopaque,
|
|
433
|
-
buf: []u8,
|
|
434
|
-
alignment: Alignment,
|
|
435
|
-
new_len: usize,
|
|
436
|
-
ra: usize,
|
|
437
|
-
) bool {
|
|
438
|
-
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
439
|
-
if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
|
|
440
|
-
return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, alignment, new_len, ra);
|
|
441
|
-
} else {
|
|
442
|
-
return self.fallback_allocator.rawResize(buf, alignment, new_len, ra);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
fn remap(
|
|
447
|
-
context: *anyopaque,
|
|
448
|
-
memory: []u8,
|
|
449
|
-
alignment: Alignment,
|
|
450
|
-
new_len: usize,
|
|
451
|
-
return_address: usize,
|
|
452
|
-
) ?[*]u8 {
|
|
453
|
-
const self: *Self = @ptrCast(@alignCast(context));
|
|
454
|
-
if (self.fixed_buffer_allocator.ownsPtr(memory.ptr)) {
|
|
455
|
-
return FixedBufferAllocator.remap(&self.fixed_buffer_allocator, memory, alignment, new_len, return_address);
|
|
456
|
-
} else {
|
|
457
|
-
return self.fallback_allocator.rawRemap(memory, alignment, new_len, return_address);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
fn free(
|
|
462
|
-
ctx: *anyopaque,
|
|
463
|
-
buf: []u8,
|
|
464
|
-
alignment: Alignment,
|
|
465
|
-
ra: usize,
|
|
466
|
-
) void {
|
|
467
|
-
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
468
|
-
if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
|
|
469
|
-
return FixedBufferAllocator.free(&self.fixed_buffer_allocator, buf, alignment, ra);
|
|
470
|
-
} else {
|
|
471
|
-
return self.fallback_allocator.rawFree(buf, alignment, ra);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
371
|
test c_allocator {
|
|
478
372
|
if (builtin.link_libc) {
|
|
479
373
|
try testAllocator(c_allocator);
|
|
@@ -524,25 +418,6 @@ test ArenaAllocator {
|
|
|
524
418
|
try testAllocatorAlignedShrink(allocator);
|
|
525
419
|
}
|
|
526
420
|
|
|
527
|
-
test "StackFallbackAllocator" {
|
|
528
|
-
{
|
|
529
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
530
|
-
try testAllocator(stack_allocator.get());
|
|
531
|
-
}
|
|
532
|
-
{
|
|
533
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
534
|
-
try testAllocatorAligned(stack_allocator.get());
|
|
535
|
-
}
|
|
536
|
-
{
|
|
537
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
538
|
-
try testAllocatorLargeAlignment(stack_allocator.get());
|
|
539
|
-
}
|
|
540
|
-
{
|
|
541
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
542
|
-
try testAllocatorAlignedShrink(stack_allocator.get());
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
421
|
/// This one should not try alignments that exceed what C malloc can handle.
|
|
547
422
|
pub fn testAllocator(base_allocator: mem.Allocator) !void {
|
|
548
423
|
var validationAllocator = mem.validationWrap(base_allocator);
|
|
@@ -1011,6 +886,7 @@ test {
|
|
|
1011
886
|
_ = ArenaAllocator;
|
|
1012
887
|
_ = DebugAllocator(.{});
|
|
1013
888
|
_ = FixedBufferAllocator;
|
|
889
|
+
_ = BufferFirstAllocator;
|
|
1014
890
|
if (builtin.single_threaded) {
|
|
1015
891
|
if (builtin.cpu.arch.isWasm() or (builtin.os.tag == .linux and !builtin.link_libc)) {
|
|
1016
892
|
_ = brk_allocator;
|
package/std/http/Client.zig
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
//!
|
|
5
5
|
//! TLS support may be disabled via `std.options.http_disable_tls`.
|
|
6
6
|
//!
|
|
7
|
-
//! TODO all the lockUncancelable in this file should be changed to regular lock and
|
|
8
|
-
//! `error.Canceled` added to more error sets.
|
|
9
7
|
const Client = @This();
|
|
10
8
|
|
|
11
9
|
const builtin = @import("builtin");
|
|
@@ -84,8 +82,8 @@ pub const ConnectionPool = struct {
|
|
|
84
82
|
/// If no connection is found, null is returned.
|
|
85
83
|
///
|
|
86
84
|
/// Threadsafe.
|
|
87
|
-
pub fn findConnection(pool: *ConnectionPool, io: Io, criteria: Criteria)
|
|
88
|
-
pool.mutex.
|
|
85
|
+
pub fn findConnection(pool: *ConnectionPool, io: Io, criteria: Criteria) Io.Cancelable!?*Connection {
|
|
86
|
+
try pool.mutex.lock(io);
|
|
89
87
|
defer pool.mutex.unlock(io);
|
|
90
88
|
|
|
91
89
|
var next = pool.free.last;
|
|
@@ -113,8 +111,8 @@ pub const ConnectionPool = struct {
|
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
/// Acquires an existing connection from the connection pool. This function is threadsafe.
|
|
116
|
-
pub fn acquire(pool: *ConnectionPool, io: Io, connection: *Connection) void {
|
|
117
|
-
pool.mutex.
|
|
114
|
+
pub fn acquire(pool: *ConnectionPool, io: Io, connection: *Connection) Io.Cancelable!void {
|
|
115
|
+
try pool.mutex.lock(io);
|
|
118
116
|
defer pool.mutex.unlock(io);
|
|
119
117
|
|
|
120
118
|
return pool.acquireUnsafe(connection);
|
|
@@ -150,8 +148,8 @@ pub const ConnectionPool = struct {
|
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
/// Adds a newly created node to the pool of used connections. This function is threadsafe.
|
|
153
|
-
pub fn addUsed(pool: *ConnectionPool, io: Io, connection: *Connection) void {
|
|
154
|
-
pool.mutex.
|
|
151
|
+
pub fn addUsed(pool: *ConnectionPool, io: Io, connection: *Connection) Io.Cancelable!void {
|
|
152
|
+
try pool.mutex.lock(io);
|
|
155
153
|
defer pool.mutex.unlock(io);
|
|
156
154
|
|
|
157
155
|
pool.used.append(&connection.pool_node);
|
|
@@ -162,18 +160,15 @@ pub const ConnectionPool = struct {
|
|
|
162
160
|
/// If the new size is smaller than the current size, then idle connections will be closed until the pool is the new size.
|
|
163
161
|
///
|
|
164
162
|
/// Threadsafe.
|
|
165
|
-
pub fn resize(pool: *ConnectionPool, io: Io,
|
|
166
|
-
pool.mutex.
|
|
163
|
+
pub fn resize(pool: *ConnectionPool, io: Io, new_size: usize) Io.Cancelable!void {
|
|
164
|
+
try pool.mutex.lock(io);
|
|
167
165
|
defer pool.mutex.unlock(io);
|
|
168
166
|
|
|
169
|
-
const next = pool.free.first;
|
|
170
|
-
_ = next;
|
|
171
167
|
while (pool.free_len > new_size) {
|
|
172
|
-
const popped = pool.free.popFirst()
|
|
168
|
+
const popped: *Connection = @alignCast(@fieldParentPtr("pool_node", pool.free.popFirst().?));
|
|
173
169
|
pool.free_len -= 1;
|
|
174
170
|
|
|
175
|
-
popped.
|
|
176
|
-
allocator.destroy(popped);
|
|
171
|
+
popped.destroy(io);
|
|
177
172
|
}
|
|
178
173
|
|
|
179
174
|
pool.free_size = new_size;
|
|
@@ -1133,7 +1128,16 @@ pub const Request = struct {
|
|
|
1133
1128
|
pub fn receiveHead(r: *Request, redirect_buffer: []u8) ReceiveHeadError!Response {
|
|
1134
1129
|
var aux_buf = redirect_buffer;
|
|
1135
1130
|
while (true) {
|
|
1136
|
-
|
|
1131
|
+
// This while loop is for handling redirects, which means the request's
|
|
1132
|
+
// connection may be different than the previous iteration. However, it
|
|
1133
|
+
// is still guaranteed to be non-null with each iteration of this loop.
|
|
1134
|
+
const connection = r.connection.?;
|
|
1135
|
+
|
|
1136
|
+
const head_buffer = r.reader.receiveHead() catch |err| {
|
|
1137
|
+
// Failure here means the connection can no longer be reused.
|
|
1138
|
+
connection.closing = true;
|
|
1139
|
+
return err;
|
|
1140
|
+
};
|
|
1137
1141
|
const response: Response = .{
|
|
1138
1142
|
.request = r,
|
|
1139
1143
|
.head = Response.Head.parse(head_buffer) catch return error.HttpHeadersInvalid,
|
|
@@ -1147,11 +1151,6 @@ pub const Request = struct {
|
|
|
1147
1151
|
return response; // we're not handling the 100-continue
|
|
1148
1152
|
}
|
|
1149
1153
|
|
|
1150
|
-
// This while loop is for handling redirects, which means the request's
|
|
1151
|
-
// connection may be different than the previous iteration. However, it
|
|
1152
|
-
// is still guaranteed to be non-null with each iteration of this loop.
|
|
1153
|
-
const connection = r.connection.?;
|
|
1154
|
-
|
|
1155
1154
|
if (r.method == .CONNECT and head.status.class() == .success) {
|
|
1156
1155
|
// This connection is no longer doing HTTP.
|
|
1157
1156
|
connection.closing = false;
|
|
@@ -1319,7 +1318,7 @@ pub fn initDefaultProxies(client: *Client, arena: Allocator, environ_map: *const
|
|
|
1319
1318
|
const io = client.io;
|
|
1320
1319
|
|
|
1321
1320
|
// Prevent any new connections from being created.
|
|
1322
|
-
client.connection_pool.mutex.
|
|
1321
|
+
try client.connection_pool.mutex.lock(io);
|
|
1323
1322
|
defer client.connection_pool.mutex.unlock(io);
|
|
1324
1323
|
|
|
1325
1324
|
assert(client.connection_pool.used.first == null); // There are active requests.
|
|
@@ -1414,7 +1413,7 @@ pub const basic_authorization = struct {
|
|
|
1414
1413
|
|
|
1415
1414
|
pub const ConnectTcpError = error{
|
|
1416
1415
|
TlsInitializationFailed,
|
|
1417
|
-
} || Allocator.Error || HostName.ConnectError;
|
|
1416
|
+
} || Allocator.Error || HostName.ConnectError || Io.Cancelable;
|
|
1418
1417
|
|
|
1419
1418
|
/// Reuses a `Connection` if one matching `host` and `port` is already open.
|
|
1420
1419
|
///
|
|
@@ -1447,7 +1446,7 @@ pub fn connectTcpOptions(client: *Client, options: ConnectTcpOptions) ConnectTcp
|
|
|
1447
1446
|
const proxied_host = options.proxied_host orelse host;
|
|
1448
1447
|
const proxied_port = options.proxied_port orelse port;
|
|
1449
1448
|
|
|
1450
|
-
if (client.connection_pool.findConnection(io, .{
|
|
1449
|
+
if (try client.connection_pool.findConnection(io, .{
|
|
1451
1450
|
.host = proxied_host,
|
|
1452
1451
|
.port = proxied_port,
|
|
1453
1452
|
.protocol = protocol,
|
|
@@ -1465,18 +1464,20 @@ pub fn connectTcpOptions(client: *Client, options: ConnectTcpOptions) ConnectTcp
|
|
|
1465
1464
|
error.Canceled => |e| return e,
|
|
1466
1465
|
else => return error.TlsInitializationFailed,
|
|
1467
1466
|
};
|
|
1468
|
-
|
|
1467
|
+
errdefer tc.destroy();
|
|
1468
|
+
try client.connection_pool.addUsed(io, &tc.connection);
|
|
1469
1469
|
return &tc.connection;
|
|
1470
1470
|
},
|
|
1471
1471
|
.plain => {
|
|
1472
1472
|
const pc = try Connection.Plain.create(client, proxied_host, proxied_port, stream);
|
|
1473
|
-
|
|
1473
|
+
errdefer pc.destroy();
|
|
1474
|
+
try client.connection_pool.addUsed(io, &pc.connection);
|
|
1474
1475
|
return &pc.connection;
|
|
1475
1476
|
},
|
|
1476
1477
|
}
|
|
1477
1478
|
}
|
|
1478
1479
|
|
|
1479
|
-
pub const ConnectUnixError = Allocator.Error || std.posix.SocketError || error{NameTooLong} || std.posix.ConnectError;
|
|
1480
|
+
pub const ConnectUnixError = Allocator.Error || std.posix.SocketError || error{NameTooLong} || std.posix.ConnectError || Io.Cancelable;
|
|
1480
1481
|
|
|
1481
1482
|
/// Connect to `path` as a unix domain socket. This will reuse a connection if one is already open.
|
|
1482
1483
|
///
|
|
@@ -1484,7 +1485,7 @@ pub const ConnectUnixError = Allocator.Error || std.posix.SocketError || error{N
|
|
|
1484
1485
|
pub fn connectUnix(client: *Client, path: []const u8) ConnectUnixError!*Connection {
|
|
1485
1486
|
const io = client.io;
|
|
1486
1487
|
|
|
1487
|
-
if (client.connection_pool.findConnection(io, .{
|
|
1488
|
+
if (try client.connection_pool.findConnection(io, .{
|
|
1488
1489
|
.host = path,
|
|
1489
1490
|
.port = 0,
|
|
1490
1491
|
.protocol = .plain,
|
|
@@ -1508,7 +1509,7 @@ pub fn connectUnix(client: *Client, path: []const u8) ConnectUnixError!*Connecti
|
|
|
1508
1509
|
};
|
|
1509
1510
|
errdefer client.allocator.free(conn.data.host);
|
|
1510
1511
|
|
|
1511
|
-
client.connection_pool.addUsed(conn);
|
|
1512
|
+
try client.connection_pool.addUsed(conn);
|
|
1512
1513
|
|
|
1513
1514
|
return &conn.data;
|
|
1514
1515
|
}
|
|
@@ -1526,7 +1527,7 @@ pub fn connectProxied(
|
|
|
1526
1527
|
const io = client.io;
|
|
1527
1528
|
if (!proxy.supports_connect) return error.TunnelNotSupported;
|
|
1528
1529
|
|
|
1529
|
-
if (client.connection_pool.findConnection(io, .{
|
|
1530
|
+
if (try client.connection_pool.findConnection(io, .{
|
|
1530
1531
|
.host = proxied_host,
|
|
1531
1532
|
.port = proxied_port,
|
|
1532
1533
|
.protocol = proxy.protocol,
|
package/std/http.zig
CHANGED
|
@@ -400,7 +400,7 @@ pub const Reader = struct {
|
|
|
400
400
|
0 => return error.HttpConnectionClosing,
|
|
401
401
|
else => return error.HttpRequestTruncated,
|
|
402
402
|
},
|
|
403
|
-
error.ReadFailed => return
|
|
403
|
+
error.ReadFailed => |e| return e,
|
|
404
404
|
};
|
|
405
405
|
continue;
|
|
406
406
|
}
|
|
@@ -443,7 +443,7 @@ pub const Reader = struct {
|
|
|
443
443
|
},
|
|
444
444
|
.none => {
|
|
445
445
|
if (content_length) |len| {
|
|
446
|
-
reader.state = .{ .body_remaining_content_length = len };
|
|
446
|
+
reader.state = if (len == 0) .ready else .{ .body_remaining_content_length = len };
|
|
447
447
|
reader.interface = .{
|
|
448
448
|
.buffer = transfer_buffer,
|
|
449
449
|
.seek = 0,
|
|
@@ -509,27 +509,29 @@ pub const Reader = struct {
|
|
|
509
509
|
limit: std.Io.Limit,
|
|
510
510
|
) std.Io.Reader.StreamError!usize {
|
|
511
511
|
const reader: *Reader = @alignCast(@fieldParentPtr("interface", io_r));
|
|
512
|
+
if (reader.state == .ready) return error.EndOfStream;
|
|
512
513
|
const remaining_content_length = &reader.state.body_remaining_content_length;
|
|
513
514
|
const remaining = remaining_content_length.*;
|
|
514
|
-
|
|
515
|
+
const n = try reader.in.stream(w, limit.min(.limited64(remaining)));
|
|
516
|
+
if (n == remaining) {
|
|
515
517
|
reader.state = .ready;
|
|
516
|
-
|
|
518
|
+
} else {
|
|
519
|
+
remaining_content_length.* = remaining - n;
|
|
517
520
|
}
|
|
518
|
-
const n = try reader.in.stream(w, limit.min(.limited64(remaining)));
|
|
519
|
-
remaining_content_length.* = remaining - n;
|
|
520
521
|
return n;
|
|
521
522
|
}
|
|
522
523
|
|
|
523
524
|
fn contentLengthDiscard(io_r: *std.Io.Reader, limit: std.Io.Limit) std.Io.Reader.Error!usize {
|
|
524
525
|
const reader: *Reader = @alignCast(@fieldParentPtr("interface", io_r));
|
|
526
|
+
if (reader.state == .ready) return error.EndOfStream;
|
|
525
527
|
const remaining_content_length = &reader.state.body_remaining_content_length;
|
|
526
528
|
const remaining = remaining_content_length.*;
|
|
527
|
-
|
|
529
|
+
const n = try reader.in.discard(limit.min(.limited64(remaining)));
|
|
530
|
+
if (n == remaining) {
|
|
528
531
|
reader.state = .ready;
|
|
529
|
-
|
|
532
|
+
} else {
|
|
533
|
+
remaining_content_length.* = remaining - n;
|
|
530
534
|
}
|
|
531
|
-
const n = try reader.in.discard(limit.min(.limited64(remaining)));
|
|
532
|
-
remaining_content_length.* = remaining - n;
|
|
533
535
|
return n;
|
|
534
536
|
}
|
|
535
537
|
|
|
@@ -541,8 +543,7 @@ pub const Reader = struct {
|
|
|
541
543
|
else => unreachable,
|
|
542
544
|
};
|
|
543
545
|
return chunkedReadEndless(reader, w, limit, chunk_len_ptr) catch |err| switch (err) {
|
|
544
|
-
error.ReadFailed => return
|
|
545
|
-
error.WriteFailed => return error.WriteFailed,
|
|
546
|
+
error.ReadFailed, error.WriteFailed => |e| return e,
|
|
546
547
|
error.EndOfStream => {
|
|
547
548
|
reader.body_err = error.HttpChunkTruncated;
|
|
548
549
|
return error.ReadFailed;
|
|
@@ -611,7 +612,7 @@ pub const Reader = struct {
|
|
|
611
612
|
else => unreachable,
|
|
612
613
|
};
|
|
613
614
|
return chunkedDiscardEndless(reader, limit, chunk_len_ptr) catch |err| switch (err) {
|
|
614
|
-
error.ReadFailed => return
|
|
615
|
+
error.ReadFailed => |e| return e,
|
|
615
616
|
error.EndOfStream => {
|
|
616
617
|
reader.body_err = error.HttpChunkTruncated;
|
|
617
618
|
return error.ReadFailed;
|
package/std/json/Scanner.zig
CHANGED
|
@@ -1401,7 +1401,7 @@ pub fn validate(allocator: Allocator, s: []const u8) Allocator.Error!bool {
|
|
|
1401
1401
|
while (true) {
|
|
1402
1402
|
const token = scanner.next() catch |err| switch (err) {
|
|
1403
1403
|
error.SyntaxError, error.UnexpectedEndOfInput => return false,
|
|
1404
|
-
error.OutOfMemory => return
|
|
1404
|
+
error.OutOfMemory => |e| return e,
|
|
1405
1405
|
error.BufferUnderrun => unreachable,
|
|
1406
1406
|
};
|
|
1407
1407
|
if (token == .end_of_document) break;
|
|
@@ -1734,7 +1734,7 @@ pub const Reader = struct {
|
|
|
1734
1734
|
|
|
1735
1735
|
fn refillBuffer(self: *@This()) std.Io.Reader.Error!void {
|
|
1736
1736
|
const input = self.reader.peekGreedy(1) catch |err| switch (err) {
|
|
1737
|
-
error.ReadFailed => return
|
|
1737
|
+
error.ReadFailed => |e| return e,
|
|
1738
1738
|
error.EndOfStream => return self.scanner.endInput(),
|
|
1739
1739
|
};
|
|
1740
1740
|
self.reader.toss(input.len);
|
package/std/json/Stringify.zig
CHANGED
|
@@ -770,9 +770,9 @@ fn testBasicWriteStream(w: *Stringify) !void {
|
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
fn getJsonObject(allocator: std.mem.Allocator) !std.json.Value {
|
|
773
|
-
var v: std.json.Value = .{ .object =
|
|
774
|
-
try v.object.put("one", std.json.Value{ .integer = @as(i64, @intCast(1)) });
|
|
775
|
-
try v.object.put("two", std.json.Value{ .float = 2.0 });
|
|
773
|
+
var v: std.json.Value = .{ .object = .empty };
|
|
774
|
+
try v.object.put(allocator, "one", std.json.Value{ .integer = @as(i64, @intCast(1)) });
|
|
775
|
+
try v.object.put(allocator, "two", std.json.Value{ .float = 2.0 });
|
|
776
776
|
return v;
|
|
777
777
|
}
|
|
778
778
|
|
package/std/json/dynamic.zig
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const debug = std.debug;
|
|
3
3
|
const ArenaAllocator = std.heap.ArenaAllocator;
|
|
4
|
-
const StringArrayHashMap = std.
|
|
4
|
+
const StringArrayHashMap = std.array_hash_map.String;
|
|
5
5
|
const Allocator = std.mem.Allocator;
|
|
6
6
|
const json = std.json;
|
|
7
7
|
|
|
@@ -103,10 +103,10 @@ pub const Value = union(enum) {
|
|
|
103
103
|
|
|
104
104
|
.object_begin => {
|
|
105
105
|
switch (try source.nextAllocMax(allocator, .alloc_always, options.max_value_len.?)) {
|
|
106
|
-
.object_end => return try handleCompleteValue(&stack, allocator, source, Value{ .object =
|
|
106
|
+
.object_end => return try handleCompleteValue(&stack, allocator, source, Value{ .object = .empty }, options) orelse continue,
|
|
107
107
|
.allocated_string => |key| {
|
|
108
108
|
try stack.appendSlice(&[_]Value{
|
|
109
|
-
Value{ .object =
|
|
109
|
+
Value{ .object = .empty },
|
|
110
110
|
Value{ .string = key },
|
|
111
111
|
});
|
|
112
112
|
},
|
|
@@ -145,7 +145,7 @@ fn handleCompleteValue(stack: *Array, allocator: Allocator, source: anytype, val
|
|
|
145
145
|
// stack: [..., .object]
|
|
146
146
|
var object = &stack.items[stack.items.len - 1].object;
|
|
147
147
|
|
|
148
|
-
const gop = try object.getOrPut(key);
|
|
148
|
+
const gop = try object.getOrPut(allocator, key);
|
|
149
149
|
if (gop.found_existing) {
|
|
150
150
|
switch (options.duplicate_field_behavior) {
|
|
151
151
|
.use_first => {},
|
package/std/math/big/int.zig
CHANGED
|
@@ -628,12 +628,12 @@ pub const Mutable = struct {
|
|
|
628
628
|
|
|
629
629
|
// Slice of the upper bits if they exist, these will be ignored and allows us to use addCarry to determine
|
|
630
630
|
// if an overflow occurred.
|
|
631
|
-
const x =
|
|
631
|
+
const x: Const = .{
|
|
632
632
|
.positive = a.positive,
|
|
633
633
|
.limbs = a.limbs[0..@min(req_limbs, a.limbs.len)],
|
|
634
634
|
};
|
|
635
635
|
|
|
636
|
-
const y =
|
|
636
|
+
const y: Const = .{
|
|
637
637
|
.positive = b.positive,
|
|
638
638
|
.limbs = b.limbs[0..@min(req_limbs, b.limbs.len)],
|
|
639
639
|
};
|
|
@@ -647,9 +647,8 @@ pub const Mutable = struct {
|
|
|
647
647
|
// Note: after this we still might need to wrap.
|
|
648
648
|
const msl = @max(a.limbs.len, b.limbs.len);
|
|
649
649
|
if (msl < req_limbs) {
|
|
650
|
+
r.len = msl + 1;
|
|
650
651
|
r.limbs[msl] = 1;
|
|
651
|
-
r.len = req_limbs;
|
|
652
|
-
@memset(r.limbs[msl + 1 .. req_limbs], 0);
|
|
653
652
|
} else {
|
|
654
653
|
carry_truncated = true;
|
|
655
654
|
}
|
|
@@ -673,12 +672,12 @@ pub const Mutable = struct {
|
|
|
673
672
|
|
|
674
673
|
// Slice of the upper bits if they exist, these will be ignored and allows us to use addCarry to determine
|
|
675
674
|
// if an overflow occurred.
|
|
676
|
-
const x =
|
|
675
|
+
const x: Const = .{
|
|
677
676
|
.positive = a.positive,
|
|
678
677
|
.limbs = a.limbs[0..@min(req_limbs, a.limbs.len)],
|
|
679
678
|
};
|
|
680
679
|
|
|
681
|
-
const y =
|
|
680
|
+
const y: Const = .{
|
|
682
681
|
.positive = b.positive,
|
|
683
682
|
.limbs = b.limbs[0..@min(req_limbs, b.limbs.len)],
|
|
684
683
|
};
|
|
@@ -690,12 +689,12 @@ pub const Mutable = struct {
|
|
|
690
689
|
// Note: In this case, might _also_ need to saturate.
|
|
691
690
|
const msl = @max(a.limbs.len, b.limbs.len);
|
|
692
691
|
if (msl < req_limbs) {
|
|
692
|
+
r.len = msl + 1;
|
|
693
693
|
r.limbs[msl] = 1;
|
|
694
|
-
r.len = req_limbs;
|
|
695
694
|
// Note: Saturation may still be required if msl == req_limbs - 1
|
|
696
695
|
} else {
|
|
697
696
|
// Overflowed req_limbs, definitely saturate.
|
|
698
|
-
r.setTwosCompIntLimit(if (r.positive) .max else .min, signedness, bit_count);
|
|
697
|
+
return r.setTwosCompIntLimit(if (r.positive) .max else .min, signedness, bit_count);
|
|
699
698
|
}
|
|
700
699
|
}
|
|
701
700
|
|
|
@@ -1374,7 +1373,7 @@ pub const Mutable = struct {
|
|
|
1374
1373
|
/// r is `calcTwosCompLimbCount(bit_count)`.
|
|
1375
1374
|
pub fn bitNotWrap(r: *Mutable, a: Const, signedness: Signedness, bit_count: usize) void {
|
|
1376
1375
|
r.copy(a.negate());
|
|
1377
|
-
const negative_one =
|
|
1376
|
+
const negative_one: Const = .{ .limbs = &.{1}, .positive = false };
|
|
1378
1377
|
_ = r.addWrap(r.toConst(), negative_one, signedness, bit_count);
|
|
1379
1378
|
}
|
|
1380
1379
|
|
|
@@ -1740,13 +1739,13 @@ pub const Mutable = struct {
|
|
|
1740
1739
|
r.positive = r_positive;
|
|
1741
1740
|
} else {
|
|
1742
1741
|
// Shrink x, y such that the trailing zero limbs shared between are removed.
|
|
1743
|
-
var x0 =
|
|
1742
|
+
var x0: Mutable = .{
|
|
1744
1743
|
.limbs = x.limbs[xy_trailing..],
|
|
1745
1744
|
.len = x.len - xy_trailing,
|
|
1746
1745
|
.positive = true,
|
|
1747
1746
|
};
|
|
1748
1747
|
|
|
1749
|
-
var y0 =
|
|
1748
|
+
var y0: Mutable = .{
|
|
1750
1749
|
.limbs = y.limbs[xy_trailing..],
|
|
1751
1750
|
.len = y.len - xy_trailing,
|
|
1752
1751
|
.positive = true,
|
|
@@ -1809,7 +1808,7 @@ pub const Mutable = struct {
|
|
|
1809
1808
|
// x >= y * b^(n - t) can be replaced by x/b^(n - t) >= y.
|
|
1810
1809
|
|
|
1811
1810
|
// 'divide' x by b^(n - t)
|
|
1812
|
-
var tmp =
|
|
1811
|
+
var tmp: Mutable = .{
|
|
1813
1812
|
.limbs = x.limbs[shift..],
|
|
1814
1813
|
.len = x.len - shift,
|
|
1815
1814
|
.positive = true,
|
|
@@ -2108,7 +2107,7 @@ pub const Const = struct {
|
|
|
2108
2107
|
pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {
|
|
2109
2108
|
const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
|
|
2110
2109
|
@memcpy(limbs[0..self.limbs.len], self.limbs);
|
|
2111
|
-
return
|
|
2110
|
+
return .{
|
|
2112
2111
|
.allocator = allocator,
|
|
2113
2112
|
.limbs = limbs,
|
|
2114
2113
|
.metadata = if (self.positive)
|
|
@@ -2802,7 +2801,7 @@ pub const Managed = struct {
|
|
|
2802
2801
|
/// default capacity will be used instead.
|
|
2803
2802
|
/// The integer value after initializing is `0`.
|
|
2804
2803
|
pub fn initCapacity(allocator: Allocator, capacity: usize) !Managed {
|
|
2805
|
-
return
|
|
2804
|
+
return .{
|
|
2806
2805
|
.allocator = allocator,
|
|
2807
2806
|
.metadata = 1,
|
|
2808
2807
|
.limbs = block: {
|
|
@@ -2868,7 +2867,7 @@ pub const Managed = struct {
|
|
|
2868
2867
|
}
|
|
2869
2868
|
|
|
2870
2869
|
pub fn cloneWithDifferentAllocator(other: Managed, allocator: Allocator) !Managed {
|
|
2871
|
-
return
|
|
2870
|
+
return .{
|
|
2872
2871
|
.allocator = allocator,
|
|
2873
2872
|
.metadata = other.metadata,
|
|
2874
2873
|
.limbs = block: {
|
|
@@ -3454,7 +3453,7 @@ pub const Managed = struct {
|
|
|
3454
3453
|
const tmp = try rma.allocator.alloc(Limb, a_len);
|
|
3455
3454
|
defer rma.allocator.free(tmp);
|
|
3456
3455
|
@memcpy(tmp[0..a_len], a.limbs[0..a_len]);
|
|
3457
|
-
const a_const =
|
|
3456
|
+
const a_const: Const = .{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
|
|
3458
3457
|
var rma_mut = rma.toMutable();
|
|
3459
3458
|
rma_mut.sqrNoAlias(a_const, rma.allocator);
|
|
3460
3459
|
rma.setMetadata(rma_mut.positive, rma_mut.len);
|
|
@@ -3479,7 +3478,7 @@ pub const Managed = struct {
|
|
|
3479
3478
|
const tmp = try rma.allocator.alloc(Limb, a_len);
|
|
3480
3479
|
defer rma.allocator.free(tmp);
|
|
3481
3480
|
@memcpy(tmp[0..a_len], a.limbs[0..a_len]);
|
|
3482
|
-
const a_const =
|
|
3481
|
+
const a_const: Const = .{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
|
|
3483
3482
|
var rma_mut = rma.toMutable();
|
|
3484
3483
|
rma_mut.pow(a_const, b, limbs_buffer);
|
|
3485
3484
|
rma.setMetadata(rma_mut.positive, rma_mut.len);
|
package/std/mem/Allocator.zig
CHANGED
|
@@ -322,7 +322,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool {
|
|
|
322
322
|
if (allocation.len == 0) {
|
|
323
323
|
return false;
|
|
324
324
|
}
|
|
325
|
-
const old_memory = mem.
|
|
325
|
+
const old_memory: []u8 = @ptrCast(@constCast(mem.absorbSentinel(allocation)));
|
|
326
326
|
// I would like to use saturating multiplication here, but LLVM cannot lower it
|
|
327
327
|
// on WebAssembly: https://github.com/ziglang/zig/issues/9660
|
|
328
328
|
//const new_len_bytes = new_len *| @sizeOf(T);
|
|
@@ -368,7 +368,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo
|
|
|
368
368
|
new_memory.len = new_len;
|
|
369
369
|
return new_memory;
|
|
370
370
|
}
|
|
371
|
-
const old_memory = mem.
|
|
371
|
+
const old_memory: []u8 = @ptrCast(@constCast(mem.absorbSentinel(allocation)));
|
|
372
372
|
// I would like to use saturating multiplication here, but LLVM cannot lower it
|
|
373
373
|
// on WebAssembly: https://github.com/ziglang/zig/issues/9660
|
|
374
374
|
//const new_len_bytes = new_len *| @sizeOf(T);
|
|
@@ -420,7 +420,7 @@ pub fn reallocAdvanced(
|
|
|
420
420
|
return ptr;
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
-
const old_byte_slice = mem.
|
|
423
|
+
const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem)));
|
|
424
424
|
const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory;
|
|
425
425
|
// Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
|
|
426
426
|
if (self.rawRemap(old_byte_slice, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), byte_count, return_address)) |p| {
|
|
@@ -443,8 +443,7 @@ pub fn reallocAdvanced(
|
|
|
443
443
|
pub fn free(self: Allocator, memory: anytype) void {
|
|
444
444
|
const slice_info = @typeInfo(@TypeOf(memory)).pointer;
|
|
445
445
|
comptime assert(slice_info.size == .slice);
|
|
446
|
-
const
|
|
447
|
-
const bytes: []u8 = @ptrCast(@constCast(mem_with_sent));
|
|
446
|
+
const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory)));
|
|
448
447
|
if (bytes.len == 0) return;
|
|
449
448
|
@memset(bytes, undefined);
|
|
450
449
|
self.rawFree(bytes, .fromByteUnits(slice_info.alignment orelse @alignOf(slice_info.child)), @returnAddress());
|