@ebowwa/bun-native-page 0.2.0 → 0.2.2
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/dist/allocator.ts +1 -1
- package/dist/ffi.js +5 -1
- package/dist/ffi.ts +5 -1
- package/dist/index.ts +9 -9
- package/package.json +1 -1
package/dist/allocator.ts
CHANGED
|
@@ -264,7 +264,7 @@ export class BufferPool {
|
|
|
264
264
|
acquire(): AllocatedBuffer {
|
|
265
265
|
this._checkDestroyed();
|
|
266
266
|
|
|
267
|
-
let buffer: AllocatedBuffer | undefined;
|
|
267
|
+
let buffer: AllocatedBuffer | null | undefined;
|
|
268
268
|
|
|
269
269
|
if (this._available.length > 0) {
|
|
270
270
|
buffer = this._available.pop();
|
package/dist/ffi.js
CHANGED
|
@@ -23,7 +23,11 @@ function getNativePath() {
|
|
|
23
23
|
if (!platformDir) {
|
|
24
24
|
throw new Error(`Unsupported platform: ${key}`);
|
|
25
25
|
}
|
|
26
|
-
const libName = platform === 'win32'
|
|
26
|
+
const libName = platform === 'win32'
|
|
27
|
+
? 'page_native.dll'
|
|
28
|
+
: platform === 'linux'
|
|
29
|
+
? 'libpage_native.so'
|
|
30
|
+
: 'libpage_native.dylib';
|
|
27
31
|
return import.meta.dir + `/../native/${platformDir}/${libName}`;
|
|
28
32
|
}
|
|
29
33
|
// FFI symbol definitions
|
package/dist/ffi.ts
CHANGED
|
@@ -29,7 +29,11 @@ function getNativePath(): string {
|
|
|
29
29
|
throw new Error(`Unsupported platform: ${key}`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const libName = platform === 'win32'
|
|
32
|
+
const libName = platform === 'win32'
|
|
33
|
+
? 'page_native.dll'
|
|
34
|
+
: platform === 'linux'
|
|
35
|
+
? 'libpage_native.so'
|
|
36
|
+
: 'libpage_native.dylib';
|
|
33
37
|
return import.meta.dir + `/../native/${platformDir}/${libName}`;
|
|
34
38
|
}
|
|
35
39
|
|
package/dist/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ export * from './allocator.js';
|
|
|
10
10
|
|
|
11
11
|
import { ffi, ptr, toArrayBuffer } from './ffi.js';
|
|
12
12
|
import { PageSizeError, MapError, ProtectionError, LockError } from './errors.js';
|
|
13
|
-
import { handleOOM, OOMOptions } from './oom.js';
|
|
13
|
+
import { handleOOM, type OOMOptions } from './oom.js';
|
|
14
14
|
|
|
15
15
|
// ============================================================================
|
|
16
16
|
// Types
|
|
@@ -208,14 +208,14 @@ export function allocPageAligned(
|
|
|
208
208
|
|
|
209
209
|
const allocHandle = ffi.alloc(BigInt(size));
|
|
210
210
|
|
|
211
|
-
if (allocHandle === null || allocHandle ===
|
|
211
|
+
if (allocHandle === null || Number(allocHandle as unknown as bigint) === 0) {
|
|
212
212
|
return handleOOM(size, options) as never;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
const actualPtr = ffi.allocPtr(allocHandle);
|
|
216
216
|
const actualSize = Number(ffi.allocSize(allocHandle));
|
|
217
217
|
|
|
218
|
-
if (actualPtr === null || actualPtr ===
|
|
218
|
+
if (actualPtr === null || Number(actualPtr as unknown as bigint) === 0) {
|
|
219
219
|
ffi.free(allocHandle);
|
|
220
220
|
return handleOOM(size, options) as never;
|
|
221
221
|
}
|
|
@@ -259,14 +259,14 @@ export function mmapAnonymous(
|
|
|
259
259
|
const protValue = PROTECTION_MAP[prot];
|
|
260
260
|
const regionHandle = ffi.mmapAnonymous(BigInt(size), protValue);
|
|
261
261
|
|
|
262
|
-
if (regionHandle === null || regionHandle ===
|
|
262
|
+
if (regionHandle === null || Number(regionHandle as unknown as bigint) === 0) {
|
|
263
263
|
throw new MapError(size, 'mmap failed');
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
const actualPtr = ffi.mmapPtr(regionHandle);
|
|
267
267
|
const actualSize = Number(ffi.mmapSize(regionHandle));
|
|
268
268
|
|
|
269
|
-
if (actualPtr === null || actualPtr ===
|
|
269
|
+
if (actualPtr === null || Number(actualPtr as unknown as bigint) === 0) {
|
|
270
270
|
throw new MapError(size, 'mmap returned null pointer');
|
|
271
271
|
}
|
|
272
272
|
|
|
@@ -332,14 +332,14 @@ export function mmapFile(
|
|
|
332
332
|
const protValue = PROTECTION_MAP[prot];
|
|
333
333
|
const regionHandle = ffi.mmapFile(fd, BigInt(size), BigInt(offset), protValue);
|
|
334
334
|
|
|
335
|
-
if (regionHandle === null || regionHandle ===
|
|
335
|
+
if (regionHandle === null || Number(regionHandle as unknown as bigint) === 0) {
|
|
336
336
|
throw new MapError(size, 'mmap file failed');
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
const actualPtr = ffi.mmapPtr(regionHandle);
|
|
340
340
|
const actualSize = Number(ffi.mmapSize(regionHandle));
|
|
341
341
|
|
|
342
|
-
if (actualPtr === null || actualPtr ===
|
|
342
|
+
if (actualPtr === null || Number(actualPtr as unknown as bigint) === 0) {
|
|
343
343
|
throw new MapError(size, 'mmap file returned null pointer');
|
|
344
344
|
}
|
|
345
345
|
|
|
@@ -387,14 +387,14 @@ export function mmapHuge(size: number): MappedRegion | null {
|
|
|
387
387
|
|
|
388
388
|
const regionHandle = ffi.mmapHuge(BigInt(size));
|
|
389
389
|
|
|
390
|
-
if (regionHandle === null || regionHandle ===
|
|
390
|
+
if (regionHandle === null || Number(regionHandle as unknown as bigint) === 0) {
|
|
391
391
|
return null;
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
const actualPtr = ffi.mmapPtr(regionHandle);
|
|
395
395
|
const actualSize = Number(ffi.mmapSize(regionHandle));
|
|
396
396
|
|
|
397
|
-
if (actualPtr === null || actualPtr ===
|
|
397
|
+
if (actualPtr === null || Number(actualPtr as unknown as bigint) === 0) {
|
|
398
398
|
return null;
|
|
399
399
|
}
|
|
400
400
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebowwa/bun-native-page",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Cross-platform page-size aware memory operations for Bun - BufferPool, PageArena, mmap/munmap, mlock, mprotect, Windows file mapping",
|
|
5
5
|
"main": "dist/index.ts",
|
|
6
6
|
"exports": {
|