1
0
mirror of https://github.com/Sebekerga/native_api_1c.git synced 2025-07-17 01:12:24 +02:00
This commit is contained in:
Maxim K
2024-08-16 22:34:24 +05:00
parent fe192f934b
commit c6f6d1717a
7 changed files with 85 additions and 36 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "native_api_1c"
version = "0.10.5"
version = "0.10.7"
edition = "2021"
repository = "https://github.com/Sebekerga/native_api_1c"
license = "MIT"

View File

@ -1,6 +1,6 @@
[package]
name = "native_api_1c_core"
version = "0.9.3"
version = "0.9.4"
edition = "2021"
repository = "https://github.com/Sebekerga/native_api_1c"
license = "MIT"

View File

@ -0,0 +1,62 @@
use std::ffi::c_long;
use super::{connection::Connection, memory_manager::MemoryManager, This};
use crate::interface::AddInWrapper;
#[repr(C)]
pub struct InitDoneBaseVTable<T: AddInWrapper> {
dtor: usize,
#[cfg(target_family = "unix")]
dtor2: usize,
init:
unsafe extern "system" fn(&mut This<0, T>, &'static Connection) -> bool,
set_mem_manager: unsafe extern "system" fn(
&mut This<0, T>,
&'static MemoryManager,
) -> bool,
get_info: unsafe extern "system" fn(&mut This<0, T>) -> c_long,
done: unsafe extern "system" fn(&mut This<0, T>),
}
unsafe extern "system" fn init<T: AddInWrapper>(
this: &mut This<0, T>,
interface: &'static Connection,
) -> bool {
let component = this.get_component();
component.addin.init(interface)
}
unsafe extern "system" fn set_mem_manager<T: AddInWrapper>(
this: &mut This<0, T>,
mem: &'static MemoryManager,
) -> bool {
let component = this.get_component();
component.memory = Some(mem);
true
}
unsafe extern "system" fn get_info<T: AddInWrapper>(
this: &mut This<0, T>,
) -> c_long {
let component = this.get_component();
component.addin.get_info() as c_long
}
unsafe extern "system" fn done<T: AddInWrapper>(this: &mut This<0, T>) {
let component = this.get_component();
component.addin.done()
}
impl<T: AddInWrapper> Default for InitDoneBaseVTable<T> {
fn default() -> Self {
Self {
dtor: 0,
#[cfg(target_family = "unix")]
dtor2: 0,
init,
set_mem_manager,
get_info,
done,
}
}
}

View File

@ -1,7 +1,4 @@
use super::{
get_str, memory_manager::MemoryManagerImpl, offset,
provided_types::TVariant,
};
use super::{get_str, offset, provided_types::TVariant};
use crate::interface::{AddInWrapper, ParamValue, ParamValues};
use std::{
ffi::c_long,

View File

@ -27,34 +27,17 @@ pub struct MemoryManager {
pub struct AllocationError;
pub trait MemoryManagerImpl {
impl MemoryManager {
/// Safe wrapper around `alloc_memory` method of the MemoryManager object
/// to allocate memory for byte array
/// # Arguments
/// * `size` - size of the memory block to allocate
/// # Returns
/// `Result<NonNull<u8>, AllocationError>` - pointer to the allocated memory block
fn alloc_blob(&self, size: usize) -> Result<NonNull<u8>, AllocationError>;
/// Safe wrapper around `alloc_memory` method of the MemoryManager object
/// to allocate memory for UTF-16 string
/// # Arguments
/// * `size` - size of the memory block to allocate
/// # Returns
/// `Result<NonNull<u16>, AllocationError>` - pointer to the allocated memory block
fn alloc_str(&self, size: usize) -> Result<NonNull<u16>, AllocationError>;
/// Safe wrapper around `free_memory` method of the MemoryManager object
/// to free memory block
/// # Arguments
/// * `ptr` - pointer to the memory block to free
/// # Returns
/// `Result<(), ()>` - empty result
fn free_memory(&self, ptr: &mut *mut c_void);
}
impl MemoryManagerImpl for MemoryManager {
fn alloc_blob(&self, size: usize) -> Result<NonNull<u8>, AllocationError> {
pub fn alloc_blob(
&self,
size: usize,
) -> Result<NonNull<u8>, AllocationError> {
let mut ptr = ptr::null_mut::<c_void>();
unsafe {
if (self.vptr.alloc_memory)(self, &mut ptr, size as c_ulong * 2) {
@ -68,7 +51,16 @@ impl MemoryManagerImpl for MemoryManager {
}
}
fn alloc_str(&self, size: usize) -> Result<NonNull<u16>, AllocationError> {
/// Safe wrapper around `alloc_memory` method of the MemoryManager object
/// to allocate memory for UTF-16 string
/// # Arguments
/// * `size` - size of the memory block to allocate
/// # Returns
/// `Result<NonNull<u16>, AllocationError>` - pointer to the allocated memory block
pub fn alloc_str(
&self,
size: usize,
) -> Result<NonNull<u16>, AllocationError> {
let mut ptr = ptr::null_mut::<c_void>();
unsafe {
if (self.vptr.alloc_memory)(self, &mut ptr, size as c_ulong * 2) {
@ -82,7 +74,7 @@ impl MemoryManagerImpl for MemoryManager {
}
}
fn free_memory(&self, ptr: &mut *mut c_void) {
pub fn free_memory(&self, ptr: &mut *mut c_void) {
unsafe {
(self.vptr.free_memory)(self, ptr);
}

View File

@ -8,9 +8,7 @@ use chrono::{Datelike, Timelike};
use crate::interface::ParamValue;
use super::memory_manager::{
AllocationError, MemoryManager, MemoryManagerImpl,
};
use super::memory_manager::{AllocationError, MemoryManager};
/// Type representing 1C date and time values
/// # Fields
@ -144,7 +142,7 @@ impl PartialEq for Tm {
/// `variant` - pointer to the TVariant object
/// `result` - pointer to the result of the operation
pub struct ReturnValue<'a> {
pub mem: &'a dyn MemoryManagerImpl,
pub mem: &'a MemoryManager,
pub variant: &'a mut TVariant,
pub result: &'a mut bool,
}
@ -153,7 +151,7 @@ pub struct ReturnValue<'a> {
impl<'a> ReturnValue<'a> {
/// Creates a new ReturnValue object
pub fn new(
mem: &'a dyn MemoryManagerImpl,
mem: &'a MemoryManager,
variant: &'a mut TVariant,
result: &'a mut bool,
) -> Self {

View File

@ -1,6 +1,6 @@
[package]
name = "native_api_1c_macro"
version = "0.10.4"
version = "0.10.5"
edition = "2021"
repository = "https://github.com/Sebekerga/native_api_1c"
license = "MIT"