const mem = @import("std").mem;
const builtin = @import("std").builtin;
const std = @import("std");
const mimalloc = @import("./allocators/mimalloc.zig");
const FeatureFlags = @import("./feature_flags.zig");
const Environment = @import("./env.zig");
fn mimalloc_free(
_: *anyopaque,
buf: []u8,
buf_align: u8,
_: usize,
) void {
// mi_free_size internally just asserts the size
// so it's faster if we don't pass that value through
// but its good to have that assertion
if (comptime Environment.allow_assert) {
assert(mimalloc.mi_is_in_heap_region(buf.ptr));
if (mimalloc.canUseAlignedAlloc(buf.len, buf_align))
mimalloc.mi_free_size_aligned(buf.ptr, buf.len, buf_align)
else
mimalloc.mi_free_size(buf.ptr, buf.len);
} else {
mimalloc.mi_free(buf.ptr);
}
}
const c = struct {
pub const malloc_size = mimalloc.mi_malloc_size;
pub const malloc_usable_size = mimalloc.mi_malloc_usable_size;
pub const malloc = struct {
pub inline fn malloc_wrapped(size: usize) ?*anyopaque {
if (comptime FeatureFlags.log_allocations) std.debug.print("Malloc: {d}\n", .{size});
return mimalloc.mi_malloc(size);
}
}.malloc_wrapped;
pub inline fn free(ptr: anytype) void {
if (comptime Environment.allow_assert) {
assert(mimalloc.mi_is_in_heap_region(ptr));
}
mimalloc.mi_free(ptr);
}
pub const posix_memalign = struct {
pub inline fn mi_posix_memalign(p: [*c]?*anyopaque, alignment: usize, size: usize) c_int {
if (comptime FeatureFlags.log_allocations) std.debug.print("Posix_memalign: {d}\n", .{std.mem.alignForward(size, alignment)});
return mimalloc.mi_posix_memalign(p, alignment, size);
}
}.mi_posix_memalign;
};
const Allocator = mem.Allocator;
const assert = std.debug.assert;
const CAllocator = struct {
const malloc_size = c.malloc_size;
pub const supports_posix_memalign = true;
fn alignedAlloc(len: usize, alignment: usize) ?[*]u8 {
if (comptime FeatureFlags.log_allocations) std.debug.print("Malloc: {d}\n", .{len});
var ptr: ?*anyopaque = if (mimalloc.canUseAlignedAlloc(len, alignment))
mimalloc.mi_malloc_aligned(len, alignment)
else
mimalloc.mi_malloc(len);
if (comptime Environment.allow_assert) {
const usable = mimalloc.mi_malloc_usable_size(ptr);
if (usable < len) {
std.debug.panic("mimalloc: allocated size is too small: {d} < {d}", .{ usable, len });
}
}
return @ptrCast(?[*]u8, ptr);
}
fn alignedAllocSize(ptr: [*]u8) usize {
return CAllocator.malloc_size(ptr);
}
fn alloc(_: *anyopaque, len: usize, ptr_align: u8, _: usize) ?[*]u8 {
return alignedAlloc(len, ptr_align);
}
fn resize(_: *anyopaque, buf: []u8, _: u8, new_len: usize, _: usize) bool {
if (new_len <= buf.len) {
return true;
}
const full_len = alignedAllocSize(buf.ptr);
if (new_len <= full_len) {
return true;
}
return false;
}
const free = mimalloc_free;
};
pub const c_allocator = Allocator{
.ptr = undefined,
.vtable = &c_allocator_vtable,
};
const c_allocator_vtable = Allocator.VTable{
.alloc = &CAllocator.alloc,
.resize = &CAllocator.resize,
.free = &CAllocator.free,
};
const ZAllocator = struct {
const malloc_size = c.malloc_size;
pub const supports_posix_memalign = true;
fn alignedAlloc(len: usize, alignment: usize) ?[*]u8 {
if (comptime FeatureFlags.log_allocations) std.debug.print("Malloc: {d}\n", .{len});
var ptr = if (mimalloc.canUseAlignedAlloc(len, alignment))
mimalloc.mi_zalloc_aligned(len, alignment)
else
mimalloc.mi_zalloc(len);
if (comptime Environment.allow_assert) {
const usable = mimalloc.mi_malloc_usable_size(ptr);
if (usable < len) {
std.debug.panic("mimalloc: allocated size is too small: {d} < {d}", .{ usable, len });
}
}
return @ptrCast(?[*]u8, ptr);
}
fn alignedAllocSize(ptr: [*]u8) usize {
return CAllocator.malloc_size(ptr);
}
fn alloc(_: *anyopaque, len: usize, ptr_align: u8, _: usize) ?[*]u8 {
return alignedAlloc(len, ptr_align);
}
fn resize(_: *anyopaque, buf: []u8, _: u8, new_len: usize, _: usize) bool {
if (new_len <= buf.len) {
return true;
}
const full_len = alignedAllocSize(buf.ptr);
if (new_len <= full_len) {
return true;
}
return false;
}
const free = mimalloc_free;
};
pub const z_allocator = Allocator{
.ptr = undefined,
.vtable = &z_allocator_vtable,
};
const z_allocator_vtable = Allocator.VTable{
.alloc = &ZAllocator.alloc,
.resize = &ZAllocator.resize,
.free = &ZAllocator.free,
};
const HugeAllocator = struct {
fn alloc(
_: *anyopaque,
len: usize,
alignment: u29,
len_align: u29,
return_address: usize,
) error{OutOfMemory}![]u8 {
_ = return_address;
assert(len > 0);
assert(std.math.isPowerOfTwo(alignment));
var slice = std.os.mmap(
null,
len,
std.os.PROT.READ | std.os.PROT.WRITE,
std.os.MAP.ANONYMOUS | std.os.MAP.PRIVATE,
-1,
0,
) catch
return error.OutOfMemory;
_ = len_align;
return slice;
}
fn resize(
_: *anyopaque,
_: []u8,
_: u29,
_: usize,
_: u29,
_: usize,
) ?usize {
return null;
}
fn free(
_: *anyopaque,
buf: []u8,
_: u29,
_: usize,
) void {
std.os.munmap(@alignCast(std.meta.alignment([]align(std.mem.page_size) u8), buf));
}
};
pub const huge_allocator = Allocator{
.ptr = undefined,
.vtable = &huge_allocator_vtable,
};
const huge_allocator_vtable = Allocator.VTable{
.alloc = HugeAllocator.alloc,
.resize = HugeAllocator.resize,
.free = HugeAllocator.free,
};
pub const huge_threshold = 1024 * 256;
const AutoSizeAllocator = struct {
fn alloc(
_: *anyopaque,
len: usize,
alignment: u29,
len_align: u29,
return_address: usize,
) error{OutOfMemory}![]u8 {
_ = len_align;
if (len >= huge_threshold) {
return huge_allocator.rawAlloc(
len,
alignment,
return_address,
) orelse return error.OutOfMemory;
}
return c_allocator.rawAlloc(
len,
alignment,
return_address,
) orelse return error.OutOfMemory;
}
fn resize(
_: *anyopaque,
_: []u8,
_: u29,
_: usize,
_: u29,
_: usize,
) ?usize {
return null;
}
fn free(
_: *anyopaque,
buf: []u8,
a: u29,
b: usize,
) void {
if (buf.len >= huge_threshold) {
return huge_allocator.rawFree(
buf,
a,
b,
);
}
return c_allocator.rawFree(
buf,
a,
b,
);
}
};
pub const auto_allocator = Allocator{
.ptr = undefined,
.vtable = &auto_allocator_vtable,
};
const auto_allocator_vtable = Allocator.VTable{
.alloc = AutoSizeAllocator.alloc,
.resize = AutoSizeAllocator.resize,
.free = AutoSizeAllocator.free,
};
alue='feat/fonts-retrieve-data'>feat/fonts-retrieve-data
feat/foreign-key-migrations
feat/foreign-keys
feat/html-pages
feat/image-placeholders
feat/improve-custom-element-detection
feat/incremental-build
feat/indexes
feat/integration-kit
feat/jsx-transform
feat/legacy-markdown-flag
feat/markdoc-embeds
feat/markdown-components
feat/mdx-js-injection
feat/mdx-plugin-export
feat/minify-html
feat/next-get-env
feat/og
feat/ooo-streaming
feat/pragma
feat/preview
feat/react-19
feat/react-19-actions
feat/redirect-on-html-backup
feat/references
feat/remote-flag
feat/remove-astro-image-backup
feat/remove-studio
feat/render-with-queue
feat/reroute-ssr
feat/resolve-entrypoint
feat/router
feat/router-ii
feat/seo-components
feat/skip-sync-flag
feat/spa
feat/spa-ii
feat/squoosh
feat/standard-schema
feat/storage-studio
feat/streaming-rendering
feat/style-obj
feat/test-utils
feat/xray-improvements
fetch-astro-pages-mvp
fix-408
fix-all-pages-key
fix-beta-ref
fix-create-ref
fix-netlify-edge
fix-next-basics
fix-nullish-slot-name
fix-s-island-fallback
fix-vite-asset
fix/actions-cookies
fix/actions-pending-timeout
fix/assets-types
fix/astro-config-refresh
fix/astro-html-escape-bug
fix/build-subpaths
fix/client-only-component-css
fix/client-scripts-windows
fix/config-migration-defaults
fix/container-directives
fix/dates
fix/db-integration-with-missing-config
fix/devtoolbar-data-unset
fix/empty-slots
fix/filepath-layer
fix/frontmatter-file-url
fix/head-propagation
fix/hmr-css-deps
fix/import-ts-errors
fix/main-build-failure
fix/map-file-404-logs
fix/mdx-named-slots
fix/middleware-import
fix/multi-images
fix/nested-get-collection-call
fix/preact-package-build-failure
fix/primary-key-optional
fix/regex-flags
fix/server-headers
fix/stable-renderer-order
fix/transaction-type
fix/vue-nested
fix/webapi-dev
fork/markdoc-poc-with-md-support
fork/markdoc-poc-with-parser
format-imports-run
formatting
forward-button
framework-agnostic-astro-components
fryuni/db-pluggable-backend
fryuni/test-route-setup-hook
fryuni/tracing-hooks
hippotastic/legitimate-bat
hoisted-script-ts
host-ssr-example-2
hostfornode
image-non-node
improve-base-handling
inline-hoisted-scripts-now
jn.convert-assertions-to-query-params
latest
live-loaders
main
mandar1jn/ci-repo-check
markdoc-embed-prototyping
markdown
markdown-poc
mdx-path
mk/render-slot-template-backup
move-default-md-code-component
mt/lit-DSD
mt/lit-regen
mt/parse-DSD
mt/router_refactoring
nate/new-blog-template
netlify-1
netlify-preview
new-adapter-api
next
next-render
no-more-vite-postprocess
no-more-vite-postprocess2
old-build
plt-1006/unified-and-mdx
plt-1768-trailing-slash-object
preact-shared-signals
process-env-override
progress-log
re-export-drivers
react-fast-refresh
redirects-priority2
redirects-ssg-object
refactor-how-client-directives-work
refactor/image-internals
refactor/markdoc-renderer
refactor/rendere-queue
refactor/sitemap
refactor/ssr-size
release/0.17
release/0.18
remote-cdn-link
remove-fs-abstraction
remove-start
restart-on-lock
revert-13008-renovate/all-minor-patch
revert-lockfile
route-manifest-adapter
sarah11918-image-errors
sarah11918-patch-2
sb-tests2
seroval
server-islands-children
session-docs
single-file-build-2
slash-404-hint
slot-bug-1
solid-ecosystem-pkg
spike/app-setup
spike/autonav
spike/codehike
spike/context
spike/csr
spike/default-content
spike/incremental
spike/incremental-ii
spike/markdown-wasm
spike/render
spike/streaming
spike/svg
sqlite-test
squeal
ssr-redirect
stream-buffer
streaming
telemetry-audit-1
test/new-integrations-demo
test/new-ssr-demo
top-level-exports-integrations
ts-in-hoisted-script
ts-no-err
upd-vite-vendored
upgrade-deps
v1-beta
vercel-test
vite-fork
vscode-astro-global
vt-follow-redirects
warn-exp-flag
win
windows-tests-beta
wip-assets
wip-component-api-2
wip-docs-components
wip-docs-reference-gen
wip-fetch-cache
wip-fun-flags
wip-icons
wip-logging
wip-logging-saved
wip-mdc
wip-mdx-to-astro-js
wip-preview-command-integrations
wip-setup-content
wip-smoke
wip-speed-up-markdown
wip-stage
wip/react-19-test
Unnamed repository; edit this file 'description' to name the repository.
Age Commit message (Collapse ) Author Files Lines
* fix: avoid error on collectionType === 'unknown'
* fix: ignore underscores in file globs
* chore: clarify [!_]
* fix: mismatch error not throwing
* fix: bad collectionType var
* test: no error for empty collection
* chore: changeset
* refactor: remove entry prop from `getRenderModule()`
* refactor: remove `$entry` from markdoc
* test: update entry-prop -> variables test
* refactor: unify `getEntryConfigByExt`
* chore: clean up shared content / data get logic
* docs: update `$entry` recommendation
* chore: rename entry-prop -> variables
* chore: changeset
* chore: missed a spot
* docs: all-new nodes documentation
* edit: `.astro` ONLY
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* edit: `.` outside links, line break
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* edit: such as, not like
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* edit: more Astro less probs
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* edit: reviewers React to
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* edit: tagz
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* chore: add `default: 'article'` for document
* edit: reword client-side instructions
* edit: prism stylesheet got lost
* fix: heading -> blockquote
---------
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* test: add unit tests
* fix: prioritize prerendered routes
* chore: fix test
* add comment
* test: try avoiding race condition
* chore: changeset
* try avoiding race conditions attempt #2
* try avoiding race conditions (attempt 3)
* final fix hopefuly
* tet: add more tests
* sort conflicting dynamic routes aplhabetically
* test: fix test
* fix miss a head when the templaterender has a promise
* fix
* add some test
* test files move to md directory
* fix add
* delect file
---------
Co-authored-by: wuls <linsheng.wu@beantechs.com>