-
-
Notifications
You must be signed in to change notification settings - Fork 1
Use modern kernel api for create safe multifile model in super-safe language #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uselessgoddess
wants to merge
13
commits into
linksplatform:main
Choose a base branch
from
uselessgoddess:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2186e0f
Basic COCk example
uselessgoddess 30796a1
Optimize imports
uselessgoddess 06d9763
Small refactoring
uselessgoddess 4cda0da
CrUD example like C
uselessgoddess 6c97891
Rewrite C api to non-singleton style
uselessgoddess 35ef885
Full write basic api
uselessgoddess 014c333
Use linux build
uselessgoddess b55ed4a
Update CD
uselessgoddess bbe44a1
Update CD
uselessgoddess ae11706
Update CD
uselessgoddess b0d0c35
Update CD
uselessgoddess 755365a
Show output
uselessgoddess c805f49
We can reenable this section
uselessgoddess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "triplets" | ||
version = "0.1.0" | ||
authors = ["uselessgoddess"] | ||
edition = "2018" | ||
|
||
build = "build.rs" | ||
|
||
[dependencies] | ||
libc = "0.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
println!("cargo:rustc-link-search=native=dylibs"); | ||
println!("cargo:rustc-link-lib=static=Platform.Data.Triplets.Kernel"); | ||
} |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#[cfg(windows)] | ||
use std::os::windows::raw::HANDLE; | ||
use libc::c_void; | ||
use libc::int64_t; | ||
use libc::uint64_t; | ||
|
||
pub type SignedInteger = libc::int64_t; | ||
pub type UnsignedInteger = libc::uint64_t; | ||
pub type LinkIndex = UnsignedInteger; | ||
|
||
pub type Visitor = extern "C" fn(LinkIndex); | ||
pub type StoppableVisitor = extern "C" fn(LinkIndex) -> SignedInteger; | ||
|
||
pub const SUCCESS_RESULT: SignedInteger = 0; | ||
pub const ERROR_RESULT: SignedInteger = 1; | ||
|
||
#[repr(C)] | ||
pub struct Link | ||
{ | ||
pub SourceIndex: LinkIndex, | ||
pub TargetIndex: LinkIndex, | ||
pub LinkerIndex: LinkIndex, | ||
pub Timestamp: SignedInteger, | ||
pub BySourceRootIndex: LinkIndex, | ||
pub BySourceLeftIndex: LinkIndex, | ||
pub BySourceRightIndex: LinkIndex, | ||
pub BySourceCount: UnsignedInteger, | ||
pub ByTargetRootIndex: LinkIndex, | ||
pub ByTargetLeftIndex: LinkIndex, | ||
pub ByTargetRightIndex: LinkIndex, | ||
pub ByTargetCount: UnsignedInteger, | ||
pub ByLinkerRootIndex: LinkIndex, | ||
pub ByLinkerLeftIndex: LinkIndex, | ||
pub ByLinkerRightIndex: LinkIndex, | ||
pub ByLinkerCount: UnsignedInteger, | ||
} | ||
|
||
#[repr(C)] | ||
pub struct RawDB | ||
{ | ||
#[cfg(windows)] | ||
pub storageFileHandle: HANDLE, | ||
#[cfg(windows)] | ||
pub storageFileMappingHandle: HANDLE, | ||
#[cfg(unix)] | ||
storageFileHandle: int64_t, | ||
pub storageFileSizeInBytes: int64_t, | ||
pub pointerToMappedRegion: *mut c_void, | ||
|
||
pub currentMemoryPageSizeInBytes: int64_t, | ||
pub serviceBlockSizeInBytes: int64_t, | ||
pub baseLinksSizeInBytes: int64_t, | ||
pub baseBlockSizeInBytes: int64_t, | ||
pub storageFileMinSizeInBytes: int64_t, | ||
|
||
pub pointerToDataSeal: *mut int64_t, | ||
pub pointerToLinkIndexSize: *mut int64_t, | ||
pub pointerToMappingLinksMaxSize: *mut int64_t, | ||
pub lpointerToPointerToMappingLinks: *mut LinkIndex, | ||
pub lpointerToLinksMaxSize: *mut LinkIndex, | ||
pub lpointerToLinksSize: *mut LinkIndex, | ||
pub LpointerToLinks: *mut Link, | ||
|
||
pub pointerToUnusedMarker: *mut Link, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
//#![feature(try_trait)] | ||
#![feature(thread_local)] | ||
#![feature(in_band_lifetimes)] | ||
|
||
use common::{*}; | ||
use link_c::{*}; | ||
//use persistent_memory_manager::{*}; | ||
|
||
pub mod common; | ||
mod link_c; | ||
mod persistent_memory_manager_c; | ||
pub mod persistent_memory_manager; | ||
|
||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::common::{RawDB, LinkIndex}; | ||
use libc::malloc; | ||
use crate::link_c::{RawDB_new, CreateLink, UpdateLink, DeleteLink}; | ||
use crate::persistent_memory_manager_c::{OpenLinks, CloseLinks, GetLinksCount}; | ||
use std::ffi::CString; | ||
use crate::persistent_memory_manager::Links; | ||
|
||
#[test] | ||
fn it_works() { | ||
std::fs::remove_file("db.links"); | ||
{ | ||
let mem = Links::create("db.links"); | ||
println!("{:?}", mem); | ||
// close db file | ||
} | ||
|
||
let mem = Links::open("db.links").unwrap(); | ||
println!("{:?}", mem); | ||
mem.close().unwrap(); | ||
} | ||
|
||
#[test] | ||
fn c_like_CrUD() { | ||
std::fs::remove_file("юникод_data_base.links"); | ||
|
||
unsafe { | ||
let db = RawDB_new(); | ||
|
||
let name = CString::new("юникод_data_base.links").unwrap(); | ||
OpenLinks(db, name.as_ptr()); | ||
|
||
let itself = 0; | ||
|
||
let is_a = CreateLink(db, itself, itself, itself); | ||
let is_not_a = CreateLink(db, itself, itself, is_a); | ||
let link = CreateLink(db, itself, is_a, itself); | ||
let thing = CreateLink(db, itself, is_not_a, link); | ||
|
||
UpdateLink(db, is_a, is_a, is_a, link); | ||
|
||
DeleteLink(db, is_a); | ||
DeleteLink(db, thing); | ||
|
||
println!("Links count: {}", GetLinksCount(db)); | ||
|
||
CloseLinks(db); | ||
|
||
libc::free(db as *mut libc::c_void); | ||
}} | ||
|
||
#[test] | ||
fn CrUD() { | ||
std::fs::remove_file("db.links"); | ||
let mem = Links::create("db.links").unwrap(); | ||
|
||
let itself = 0 as LinkIndex /* optional */; | ||
|
||
let mut is_a = mem.create(itself, itself, itself); | ||
let is_not_a = mem.create(itself, itself, &is_a); | ||
let link = mem.create(itself, &is_a, itself); | ||
let thing = mem.create(itself, &is_not_a, &link); | ||
|
||
let clone = is_a.clone(); | ||
is_a.update(&clone, &clone, &link); | ||
// or | ||
// is_a.update(is_a.index(), is_a.index(), &link); | ||
|
||
is_a.delete(); // delete all | ||
thing.delete(); | ||
|
||
println!("Links count: {:?}", mem.count()); | ||
} | ||
|
||
#[test] | ||
fn multi_file() { | ||
std::fs::remove_file("1.links"); | ||
std::fs::remove_file("2.links"); | ||
|
||
let mem1 = Links::create("1.links").unwrap(); | ||
let mem2 = Links::create("2.links").unwrap(); | ||
|
||
mem1.create(1, 0, 2); | ||
mem2.create(2, 0, 3); | ||
|
||
println!("mem1: {:?}", mem1); | ||
println!("mem1 links count: {}", mem1.count()); | ||
println!("{:-<10}", '-'); | ||
println!("mem2: {:?}", mem2); | ||
println!("mem2 links count: {}", mem1.count()); | ||
println!("{:-<10}", '-'); | ||
println!("mem1 close result: {:?}", mem1.close()); | ||
println!("mem2 close result: {:?}", mem2.close()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
use crate::common::{*}; | ||
|
||
extern "C" { | ||
pub fn RawDB_new() -> *mut RawDB; | ||
|
||
pub fn GetSourceIndex( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn GetLinkerIndex( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn GetTargetIndex( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn GetTime( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> SignedInteger; | ||
|
||
pub fn CreateLink( | ||
db: *mut RawDB, | ||
source: LinkIndex, | ||
linker: LinkIndex, | ||
target: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn SearchLink( | ||
db: *mut RawDB, | ||
source: LinkIndex, | ||
linker: LinkIndex, | ||
target: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn ReplaceLink( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
replacement: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn UpdateLink( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
source: LinkIndex, | ||
linker: LinkIndex, | ||
target: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn DeleteLink( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
); | ||
|
||
pub fn GetFirstRefererBySourceIndex( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn GetFirstRefererByLinkerIndex( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn GetFirstRefererByTargetIndex( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> LinkIndex; | ||
|
||
pub fn GetLinkNumberOfReferersBySource( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> UnsignedInteger; | ||
|
||
pub fn GetLinkNumberOfReferersByLinker( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> UnsignedInteger; | ||
|
||
pub fn GetLinkNumberOfReferersByTarget( | ||
db: *mut RawDB, | ||
index: LinkIndex, | ||
) -> UnsignedInteger; | ||
|
||
pub fn WalkThroughAllReferersBySource( | ||
db: *mut RawDB, | ||
root: LinkIndex, | ||
visitor: Visitor, | ||
); | ||
|
||
pub fn WalkThroughReferersBySource( | ||
db: *mut RawDB, | ||
root: LinkIndex, | ||
visitor: StoppableVisitor, | ||
) -> SignedInteger; | ||
|
||
pub fn WalkThroughAllReferersByLinker( | ||
db: *mut RawDB, | ||
root: LinkIndex, | ||
visitor: Visitor, | ||
); | ||
|
||
pub fn WalkThroughReferersByLinker( | ||
db: *mut RawDB, | ||
root: LinkIndex, | ||
visitor: StoppableVisitor, | ||
) -> SignedInteger; | ||
|
||
pub fn WalkThroughAllReferersByTarget( | ||
db: *mut RawDB, | ||
root: LinkIndex, | ||
visitor: Visitor, | ||
); | ||
|
||
pub fn WalkThroughReferersByTarget( | ||
db: *mut RawDB, | ||
root: LinkIndex, | ||
visitor: StoppableVisitor, | ||
) -> SignedInteger; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.