Skip to content

Commit

Permalink
fix offset and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
catornot committed Jan 20, 2024
1 parent caaa12d commit 3a31f4a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bindings/squirrelfunctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ offset_functions! {
sq_defconst = sq_defconstType where offset(0x12120);

sq_compilebuffer = sq_compilebufferType where offset(0x3110);
sq_pushroottable = sq_pushroottableType where offset(0x5840);
sq_pushroottable = sq_pushroottableType where offset(0x5860);
sq_call = sq_callType where offset(0x8650);
sq_compilefile = sq_compilefileType where offset(0xF950);

Expand Down
20 changes: 19 additions & 1 deletion src/high/northstar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@ impl PluginInfo {
dependency_name: &'static str,
context: PluginContext,
) -> Self {
assert!(log_name.len() == 9, "log name is used for logging and ideally should be 9 chars long and all upercase to look like every other log str");
assert!(
name.as_bytes()[name.len().saturating_sub(1)] == 0,
"name has to end with a null char to be a null terminated string"
);
assert!(
log_name.as_bytes()[log_name.len().saturating_sub(1)] == 0,
"log_name has to end with a null char to be a null terminated string"
);
assert!(
dependency_name.as_bytes()[dependency_name.len().saturating_sub(1)] == 0,
"dependency_name has to end with a null char to be a null terminated string"
);
assert!(name.len() > 1, "consider actually having a name");
assert!(log_name.len() > 1, "consider actually having a log_name");
assert!(
dependency_name.len() > 1,
"consider actually having a dependency_name"
);
assert!(log_name.len().saturating_sub(1) == 9, "log name is used for logging and ideally should be 9 chars long and all upercase to look like every other log str");
Self {
name,
log_name,
Expand Down
7 changes: 6 additions & 1 deletion src/interfaces/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ macro_rules! create_external_interface {
}

impl $crate::interfaces::external::SourceInterface for $interface_name {
#[inline]
fn get_vtable(&self) -> core::ptr::NonNull<fn()> {
self.vtable
}
Expand All @@ -44,7 +45,10 @@ macro_rules! create_external_interface {
$(
$func_vis unsafe fn $name( &self, $($arg_name: $arg,)* ) -> $output {
use $crate::interfaces::external::SourceInterface;
unsafe { (std::mem::transmute::<_,unsafe extern "C" fn($($arg),*) -> $output>(self.get_func($mod_name::Counter::$name as usize)))( $($arg_name),* ) }
use std::ffi::c_void;
unsafe { (std::mem::transmute::<_,unsafe extern "C" fn(*const c_void, $($arg),*) -> $output>(self.get_func($mod_name::Counter::$name as usize)))(
self as *const Self as *const c_void, $($arg_name),*
) }
}
)*
}
Expand All @@ -54,6 +58,7 @@ macro_rules! create_external_interface {
pub trait SourceInterface<Rtrn = Self> {
fn get_vtable(&self) -> NonNull<fn()>;

#[inline]
fn get_func(&self, index: usize) -> fn() {
unsafe { *self.get_vtable().as_ptr().add(index) }
}
Expand Down
4 changes: 2 additions & 2 deletions src/macros/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
///
/// impl Plugin for BasicPlugin {
/// const PLUGIN_INFO: PluginInfo =
/// PluginInfo::new("test", "Testttttt", "test", PluginContext::all());
/// PluginInfo::new("test\0", "Testttttt\0", "test\0", PluginContext::all());
///
/// fn new(reloaded: bool) -> Self {
/// Self {}
Expand Down Expand Up @@ -300,7 +300,7 @@ mod test_entry {

impl Plugin for Test {
const PLUGIN_INFO: PluginInfo =
PluginInfo::new("test", "Testttttt", "test", PluginContext::all());
PluginInfo::new("test\0", "Testttttt\0", "test\0", PluginContext::all());

fn new(_reloaded: bool) -> Self {
Self {}
Expand Down

0 comments on commit 3a31f4a

Please sign in to comment.