Skip to content

Commit b764061

Browse files
Added NSTDWindowsHeapHandle.
1 parent c2f2208 commit b764061

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
- The overflow behavior for the "release" profile has been set to panic.
44
- The panic behavior for the "release" profile has been set to abort.
55
### `nstd.core`
6-
- `str[_mut]_to_*` functions now return `Optional`.
6+
- `str[_mut]_to_*` functions now return `NSTDOptional`.
77
- Added `cstr[_mut]_[first|last][_const]`.
88
- Added `ops`.
99
- Added `cty_is_unicode`.
1010
- Renamed `str[_mut]_get_char` to `str[_mut]_get`.
11-
- Added `Optional`.
12-
- Added `Result`.
11+
- Added `NSTDOptional`.
12+
- Added `NSTDResult`.
1313
- Added `panic`.
1414
- Made `math_[clamp|div_ceil|div_floor]_*` safe.
1515
### `nstd.cstring`
@@ -18,6 +18,7 @@
1818
### `nstd.fs`
1919
- Added `NSTDFileResult`.
2020
### `nstd.os`
21+
- Added `NSTDWindowsHeapHandle`.
2122
- Added `NSTDWindowsSharedLibHandle`.
2223
- Added `unix.alloc`.
2324
- Added `[unix|windows].shared_lib`.

include/nstd/os/windows/alloc/heap.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#include "../../../nstd.h"
55
#include "alloc.h"
66

7+
/// A raw handle to a heap.
8+
typedef NSTDInt NSTDWindowsHeapHandle;
9+
710
/// A handle to a process heap.
811
typedef struct {
912
/// The private handle.
10-
NSTDInt handle;
13+
NSTDWindowsHeapHandle handle;
1114
} NSTDWindowsHeap;
1215

1316
/// A result type that holds an `NSTDWindowsHeap` as the success variant.
@@ -40,6 +43,17 @@ NSTDAPI NSTDWindowsHeapResult nstd_os_windows_alloc_heap_default();
4043
/// See <https://docs.microsoft.com/en-us/windows/win32/api/heapapi/nf-heapapi-heapcreate>.
4144
NSTDAPI NSTDWindowsHeapResult nstd_os_windows_alloc_heap_new(NSTDUInt size);
4245

46+
/// Returns a raw handle to a heap.
47+
///
48+
/// # Parameters:
49+
///
50+
/// - `const NSTDWindowsHeap *heap` - The heap.
51+
///
52+
/// # Returns
53+
///
54+
/// `NSTDWindowsHeapHandle handle` - A native handle to the heap.
55+
NSTDAPI NSTDWindowsHeapHandle nstd_os_windows_alloc_heap_handle(const NSTDWindowsHeap *heap);
56+
4357
/// Returns the size of a memory block previously allocated by an `NSTDWindowsHeap`.
4458
///
4559
/// # Parameters:

src/os/windows/alloc/heap.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ use windows_sys::Win32::System::Memory::{
88
HeapValidate, HEAP_ZERO_MEMORY,
99
};
1010

11+
/// A raw handle to a heap.
12+
pub type NSTDWindowsHeapHandle = NSTDInt;
13+
1114
/// A handle to a process heap.
1215
#[repr(C)]
1316
pub struct NSTDWindowsHeap {
1417
/// The private handle.
15-
handle: NSTDInt,
18+
handle: NSTDWindowsHeapHandle,
1619
}
1720
impl Drop for NSTDWindowsHeap {
1821
/// [NSTDWindowsHeap] destructor.
@@ -121,6 +124,39 @@ pub unsafe extern "C" fn nstd_os_windows_alloc_heap_new(size: NSTDUInt) -> NSTDW
121124
}
122125
}
123126

127+
/// Returns a raw handle to a heap.
128+
///
129+
/// # Parameters:
130+
///
131+
/// - `const NSTDWindowsHeap *heap` - The heap.
132+
///
133+
/// # Returns
134+
///
135+
/// `NSTDWindowsHeapHandle handle` - A native handle to the heap.
136+
///
137+
/// # Example
138+
///
139+
/// ```
140+
/// use nstd_sys::{
141+
/// core::result::NSTDResult,
142+
/// os::windows::alloc::heap::{
143+
/// nstd_os_windows_alloc_heap_default, nstd_os_windows_alloc_heap_handle,
144+
/// },
145+
/// };
146+
///
147+
/// if let NSTDResult::Ok(heap) = unsafe { nstd_os_windows_alloc_heap_default() } {
148+
/// let handle = nstd_os_windows_alloc_heap_handle(&heap);
149+
/// assert!(handle != 0);
150+
/// }
151+
/// ```
152+
#[inline]
153+
#[cfg_attr(feature = "clib", no_mangle)]
154+
pub extern "C" fn nstd_os_windows_alloc_heap_handle(
155+
heap: &NSTDWindowsHeap,
156+
) -> NSTDWindowsHeapHandle {
157+
heap.handle
158+
}
159+
124160
/// Returns the size of a memory block previously allocated by an `NSTDWindowsHeap`.
125161
///
126162
/// # Parameters:

0 commit comments

Comments
 (0)