Skip to content

Commit

Permalink
Remove GameHandle wrapper type
Browse files Browse the repository at this point in the history
It's no longer necessary to appease cbindgen.
  • Loading branch information
Ortham committed Nov 24, 2019
1 parent 2af77de commit 4589ffd
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions ffi/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::error::Error;
use std::panic::catch_unwind;
use std::path::Path;
use std::ptr;
use std::sync::{LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::sync::RwLock;

use libc::{c_char, c_uint, size_t};
use loadorder::GameId;
Expand All @@ -37,21 +37,8 @@ use helpers::{error, handle_error, to_c_string_array, to_str};
///
/// Used to keep each game's data independent. Abstracts the definition of libloadorder's internal
/// state while still providing type safety across the library.
// NOTE: The outer Box is to appease cbindgen, but it probably just needs support for RwLock added.
#[allow(non_camel_case_types)]
pub type lo_game_handle = *mut GameHandle;

pub struct GameHandle(RwLock<Box<dyn WritableLoadOrder>>);

impl GameHandle {
pub fn read(&self) -> LockResult<RwLockReadGuard<Box<dyn WritableLoadOrder>>> {
self.0.read()
}

pub fn write(&self) -> LockResult<RwLockWriteGuard<Box<dyn WritableLoadOrder>>> {
self.0.write()
}
}
pub type lo_game_handle = *mut RwLock<Box<dyn WritableLoadOrder>>;

fn map_game_id(game_id: u32) -> Result<GameId, u32> {
match game_id {
Expand Down Expand Up @@ -153,7 +140,7 @@ pub unsafe extern "C" fn lo_create_handle(

let is_self_consistent = load_order.is_self_consistent();

*handle = Box::into_raw(Box::new(GameHandle(RwLock::new(load_order))));
*handle = Box::into_raw(Box::new(RwLock::new(load_order)));

match is_self_consistent {
Ok(true) => LIBLO_OK,
Expand Down

0 comments on commit 4589ffd

Please sign in to comment.