Skip to content

Commit b231414

Browse files
authored
Merge branch 'metacall:develop' into mac_py
2 parents 9a5b710 + f88d470 commit b231414

29 files changed

Lines changed: 2070 additions & 2026 deletions

.github/workflows/linux-test.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,30 @@ jobs:
6767
METACALL_BUILD_TYPE: debug
6868
METACALL_BASE_IMAGE: ${{ matrix.image }}
6969

70+
linux-memcheck-test:
71+
name: Linux Valgrind Memcheck Test
72+
runs-on: ubuntu-latest
73+
74+
strategy:
75+
fail-fast: false
76+
matrix:
77+
image: ["debian:trixie-slim", "ubuntu:noble"]
78+
79+
steps:
80+
- name: Check out the repository
81+
uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 0
84+
85+
- name: Install, build and run Valgrind memcheck tests
86+
run: ./docker-compose.sh test-memcheck
87+
env:
88+
METACALL_BUILD_TYPE: debug
89+
METACALL_BASE_IMAGE: ${{ matrix.image }}
90+
7091
linux-distributable:
7192
name: Linux Distributable Dispatch
72-
needs: [linux-test, linux-sanitizer-test]
93+
needs: [linux-test, linux-sanitizer-test] # TODO: linux-memcheck-test
7394
runs-on: ubuntu-latest
7495
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master'
7596
steps:

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ This section describes all programming languages that **METACALL** allows to loa
128128
| [Go](https://golang.org/) | Go Runtime | go |
129129
| [Haskell](https://www.haskell.org/) | [Haskell FFI](https://wiki.haskell.org/GHC/Using_the_FFI) | hs |
130130
| [Crystal](https://crystal-lang.org/) | [Crystal Compiler Internals](https://github.com/crystal-lang/crystal/wiki/Compiler-internals) | cr |
131-
| [JavaScript](https://developer.mozilla.org/bm/docs/Web/JavaScript) | [SpiderMonkey](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference) | jsm |
131+
| [JavaScript](https://developer.mozilla.org/bm/docs/Web/JavaScript) | [SpiderMonkey](https://spidermonkey.dev/) | jsm |
132132
| [Dart](https://dart.dev/) | [Dart VM](https://dart.dev/tools/dart-vm) | dart |
133133
| [LuaJIT](https://luajit.org/) | [LuaJIT2](https://github.com/openresty/luajit2) | lua |
134134
| [LLVM IR](https://www.llvm.org/devmtg/2017-06/1-Davis-Chisnall-LLVM-2017.pdf) | [LLVM](https://llvm.org/) | llvm |

source/loaders/rs_loader/rust/compiler/src/api/class.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ extern "C" fn class_singleton_static_invoke(
9292
.expect("Unable to get method name");
9393
let ret = class.call(name, args);
9494
std::mem::forget(class);
95-
std::mem::forget(name);
9695
ret
9796
};
9897
if let Ok(ret) = ret {
99-
return ret;
98+
ret
10099
} else {
101-
return 0 as OpaqueType;
100+
0 as OpaqueType
102101
}
103102
}
104103

@@ -116,12 +115,10 @@ extern "C" fn class_singleton_static_await(
116115

117116
#[no_mangle]
118117
extern "C" fn class_singleton_destroy(_klass: OpaqueType, class_impl: OpaqueType) {
119-
if !rs_loader_destroyed() {
120-
if !class_impl.is_null() {
121-
unsafe {
122-
let class = Box::from_raw(class_impl as *mut class::Class);
123-
drop(class);
124-
}
118+
if !rs_loader_destroyed() && !class_impl.is_null() {
119+
unsafe {
120+
let class = Box::from_raw(class_impl as *mut class::Class);
121+
drop(class);
125122
}
126123
}
127124
}
@@ -239,10 +236,8 @@ pub fn register_class(class_registration: ClassRegistration) {
239236
loader_impl_type(class_registration.loader_impl, ret.as_ptr()),
240237
);
241238
};
242-
}
243-
else {
244-
let ret = CString::new("Null")
245-
.expect("Failed to convert return type to C string");
239+
} else {
240+
let ret = CString::new("Null").expect("Failed to convert return type to C string");
246241

247242
unsafe {
248243
signature_set_return(
@@ -294,10 +289,8 @@ pub fn register_class(class_registration: ClassRegistration) {
294289
loader_impl_type(class_registration.loader_impl, ret.as_ptr()),
295290
);
296291
};
297-
}
298-
else {
299-
let ret = CString::new("Null")
300-
.expect("Failed to convert return type to C string");
292+
} else {
293+
let ret = CString::new("Null").expect("Failed to convert return type to C string");
301294

302295
unsafe {
303296
signature_set_return(

source/loaders/rs_loader/rust/compiler/src/api/function.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ extern "C" fn function_singleton_await(
5454
0 as OpaqueType
5555
}
5656

57-
5857
#[no_mangle]
5958
extern "C" fn function_singleton_destroy(_func: OpaqueType, func_impl: OpaqueType) {
60-
if !rs_loader_destroyed() {
61-
if !func_impl.is_null() {
62-
unsafe {
63-
let func_ptr = Box::from_raw(func_impl as *mut class::Function);
64-
drop(func_ptr);
65-
}
59+
if !rs_loader_destroyed() && !func_impl.is_null() {
60+
unsafe {
61+
let func_ptr = Box::from_raw(func_impl as *mut class::Function);
62+
drop(func_ptr);
6663
}
6764
}
6865
}

source/loaders/rs_loader/rust/compiler/src/api/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ extern "C" {
121121
}
122122

123123
pub fn get_loader_lifecycle_state(loader_impl: OpaqueType) -> *mut LoaderLifecycleState {
124-
let loader_lifecycle_state =
125-
unsafe { loader_impl_get(loader_impl) } as *mut LoaderLifecycleState;
126-
127-
loader_lifecycle_state
124+
(unsafe { loader_impl_get(loader_impl) }) as *mut LoaderLifecycleState
128125
}
129126

130127
static mut RS_LOADER_PTR: *mut c_void = std::ptr::null_mut();
@@ -142,7 +139,9 @@ pub fn loader_lifecycle_register(loader_impl: OpaqueType) {
142139
}
143140

144141
pub fn loader_lifecycle_unload_children(loader_impl: OpaqueType) {
145-
unsafe { loader_unload_children(loader_impl); }
142+
unsafe {
143+
loader_unload_children(loader_impl);
144+
}
146145
}
147146

148147
pub enum PrimitiveMetacallProtocolTypes {
@@ -182,7 +181,5 @@ pub fn define_type(
182181
}
183182

184183
pub fn rs_loader_destroyed() -> bool {
185-
unsafe {
186-
loader_is_destroyed(RS_LOADER_PTR) == 0
187-
}
184+
unsafe { loader_is_destroyed(RS_LOADER_PTR) == 0 }
188185
}

0 commit comments

Comments
 (0)