Skip to content

Commit 16dbf4a

Browse files
authored
feat(ext/ffi): Support bool FFI type (#15754)
1 parent 08a6af3 commit 16dbf4a

File tree

10 files changed

+227
-66
lines changed

10 files changed

+227
-66
lines changed

cli/dts/lib.deno.unstable.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ declare namespace Deno {
393393
| "usize"
394394
| "isize";
395395

396+
type NativeBooleanType = "bool";
397+
396398
type NativePointerType = "pointer";
397399

398400
type NativeBufferType = "buffer";
@@ -408,6 +410,7 @@ declare namespace Deno {
408410
export type NativeType =
409411
| NativeNumberType
410412
| NativeBigIntType
413+
| NativeBooleanType
411414
| NativePointerType
412415
| NativeBufferType
413416
| NativeFunctionType;
@@ -419,6 +422,7 @@ declare namespace Deno {
419422
type ToNativeTypeMap =
420423
& Record<NativeNumberType, number>
421424
& Record<NativeBigIntType, PointerValue>
425+
& Record<NativeBooleanType, boolean>
422426
& Record<NativePointerType, PointerValue | null>
423427
& Record<NativeFunctionType, PointerValue | null>
424428
& Record<NativeBufferType, TypedArray | null>;
@@ -455,6 +459,7 @@ declare namespace Deno {
455459
type FromNativeTypeMap =
456460
& Record<NativeNumberType, number>
457461
& Record<NativeBigIntType, PointerValue>
462+
& Record<NativeBooleanType, boolean>
458463
& Record<NativePointerType, PointerValue>
459464
& Record<NativeBufferType, PointerValue>
460465
& Record<NativeFunctionType, PointerValue>;
@@ -610,6 +615,8 @@ declare namespace Deno {
610615

611616
pointer: bigint;
612617

618+
/** Gets a boolean at the specified byte offset from the pointer. */
619+
getBool(offset?: number): boolean;
613620
/** Gets an unsigned 8-bit integer at the specified byte offset from the pointer. */
614621
getUint8(offset?: number): number;
615622
/** Gets a signed 8-bit integer at the specified byte offset from the pointer. */

ext/ffi/00_ffi.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
this.pointer = pointer;
4646
}
4747

48+
getBool(offset = 0) {
49+
return ops.op_ffi_read_bool(
50+
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,
51+
);
52+
}
53+
4854
getUint8(offset = 0) {
4955
return ops.op_ffi_read_u8(
5056
offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer,

ext/ffi/jit_trampoline.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ macro_rules! cstr {
2323

2424
fn native_arg_to_c(ty: &NativeType) -> &'static str {
2525
match ty {
26+
NativeType::Bool => "bool",
2627
NativeType::U8 | NativeType::U16 | NativeType::U32 => "uint32_t",
2728
NativeType::I8 | NativeType::I16 | NativeType::I32 => "int32_t",
2829
NativeType::Void => "void",
@@ -39,6 +40,7 @@ fn native_arg_to_c(ty: &NativeType) -> &'static str {
3940

4041
fn native_to_c(ty: &NativeType) -> &'static str {
4142
match ty {
43+
NativeType::Bool => "bool",
4244
NativeType::U8 => "uint8_t",
4345
NativeType::U16 => "uint16_t",
4446
NativeType::U32 => "uint32_t",

0 commit comments

Comments
 (0)