Skip to content

Commit 59367f8

Browse files
siyuan0322shirly121BingqingLyu
authored
Resolve a issue that JNA could not map bool correctly (#2376)
ref: https://stackoverflow.com/questions/55225896/jna-maps-java-boolean-to-1-integer Fix the bug of #1814 roots from the mapping of Boolean in Java to C. Probably [this PR](rust-lang/rust#89887) within rust version 1.61 trigger that, though I'm not sure. Co-authored-by: shirly121 <[email protected]> Co-authored-by: BingqingLyu <[email protected]>
1 parent 553b517 commit 59367f8

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed

.github/workflows/k8s-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ jobs:
419419
- name: Helm Test
420420
run: |
421421
cd charts
422-
helm template graphscope --set image.registry="",image.tag=${SHORT_SHA} \
422+
helm template graphscope --set image.registry="",image.tag="${SHORT_SHA}" \
423423
./graphscope
424-
helm install graphscope --set image.registry="",image.tag=${SHORT_SHA} \
424+
helm install graphscope --set image.registry="",image.tag="${SHORT_SHA}" \
425425
./graphscope
426426
helm test graphscope --timeout 5m0s
427427
export NODE_IP=$(kubectl get pod -lgraphscope.coordinator.name=coordinator-graphscope -ojsonpath="{.items[0].status.hostIP}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.alibaba.graphscope.common.jna;
2+
3+
import com.sun.jna.FromNativeContext;
4+
import com.sun.jna.ToNativeContext;
5+
import com.sun.jna.TypeConverter;
6+
7+
// to convert java boolean to i32 and define i32 as the native bool type
8+
public class BooleanConverter implements TypeConverter {
9+
@Override
10+
public Object toNative(Object value, ToNativeContext context) {
11+
return Integer.valueOf(Boolean.TRUE.equals(value) ? 1 : 0);
12+
}
13+
14+
@Override
15+
public Object fromNative(Object value, FromNativeContext context) {
16+
return ((Integer) value).intValue() != 0 ? Boolean.TRUE : Boolean.FALSE;
17+
}
18+
19+
@Override
20+
public Class<?> nativeType() {
21+
// BOOL is 32-bit int
22+
return Integer.class;
23+
}
24+
}

interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/jna/IrTypeMapper.java

+1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ public class IrTypeMapper extends DefaultTypeMapper {
2424
private IrTypeMapper() {
2525
super();
2626
addTypeConverter(IntEnum.class, new EnumConverter());
27+
addTypeConverter(Boolean.class, new BooleanConverter());
2728
}
2829
}

interactive_engine/executor/ir/core/rust-toolchain.toml

-5
This file was deleted.

interactive_engine/executor/ir/core/src/plan/ffi.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl TryFrom<FfiVariable> for common_pb::Variable {
371371
#[derive(Default)]
372372
pub struct FfiAlias {
373373
alias: FfiNameOrId,
374-
is_query_given: bool,
374+
is_query_given: i32,
375375
}
376376

377377
impl TryFrom<FfiAlias> for Option<common_pb::NameOrId> {
@@ -942,8 +942,11 @@ mod project {
942942
use super::*;
943943
/// To initialize a project operator.
944944
#[no_mangle]
945-
pub extern "C" fn init_project_operator(is_append: bool) -> *const c_void {
946-
let project = Box::new(pb::Project { mappings: vec![], is_append });
945+
pub extern "C" fn init_project_operator(is_append: i32) -> *const c_void {
946+
let project = Box::new(pb::Project {
947+
mappings: vec![],
948+
is_append: if is_append == 0 { false } else { true },
949+
});
947950
Box::into_raw(project) as *const c_void
948951
}
949952

interactive_engine/executor/rust-toolchain.toml

-5
This file was deleted.

0 commit comments

Comments
 (0)