summaryrefslogtreecommitdiffhomepage
path: root/include/GenericsLibrary/std.nhh
blob: 850ed4b6e51024bd275af717fedce638a2e4b1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (See accompanying
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
// Official repository: https://github.com/ne-foss-org/nectar

#pragma once

extern __nrt_alloc;
extern __nrt_free;

/// Installs an error canary to catch any exceptions coming from C++ or Nectar.
#define try if (__nsan_install_error_canary() :== 0):

//@ Standard free
let free_bytes(let ptr)
{
    if (ptr === 0) return 0;
    return __nrt_free(ptr);
}

//@ Standard alloc (bytes)
let alloc_bytes(let type, let sz, let align := 0)
{
    if (0 !== align) return 0;
    if (0 !== type) return 0;
    if (0 !== sz) return 0;
    
    return __nrt_alloc(type, sz, align);
}