Skip to content

Commit aa677b8

Browse files
Merge pull request #109 from sfleischman105/Beta-Branch
Update `pleco` to 0.4.1 and `pleco_engine` to 0.1.2
2 parents 0f324d5 + ce19f92 commit aa677b8

File tree

10 files changed

+33
-32
lines changed

10 files changed

+33
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ UCI (Universal Chess Interface) compatible engine.
1313
The overall goal for this project is to utilize the efficiency of Rust to create a Chess AI matching the speed of modern chess engines.
1414
For the engine, the majority of the code is a direct port of Stockfish's C++ code. See [their website](https://stockfishchess.org/) for
1515
more information about the engine. As such, the credit for all of the advanced algorithms used for searching, evaluation,
16-
and many others, go directly to the maintainers and authors of Stockfish. This project is simply for speed comparisons
16+
and many others, go directly to the maintainers and authors of Stockfish. This project is for speed comparisons
1717
between the two languages, as well as for educational purposes.
1818

1919
- [Documentation](https://docs.rs/pleco), [crates.io](https://crates.io/crates/pleco) for library functionality

pleco/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pleco"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Stephen Fleischman <[email protected]>"]
55
description = "A blazingly-fast chess library."
66
homepage = "https://github.com/sfleischman105/Pleco"

pleco/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#![feature(pointer_methods)]
7979
#![feature(cfg_target_feature, target_feature)]
8080
#![feature(stdsimd)]
81+
#![feature(nonnull_cast)]
8182

8283
#![allow(dead_code)]
8384

pleco/src/tools/tt.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
3636
use std::ptr::NonNull;
3737
use std::mem;
38-
use std::heap::{Alloc, Layout, Heap};
38+
use std::heap::{Alloc, Layout, Global};
3939
use std::cmp::min;
4040
use std::cell::UnsafeCell;
4141

@@ -423,8 +423,7 @@ impl TranspositionTable {
423423

424424
/// De-allocates the current heap.
425425
unsafe fn de_alloc(&self) {
426-
Heap.dealloc((*self.clusters.get()).as_ptr() as *mut _,
427-
Layout::array::<Cluster>(*self.cap.get()).unwrap());
426+
Global.dealloc((*self.clusters.get()).as_opaque(), Layout::array::<Cluster>(*self.cap.get()).unwrap());
428427
}
429428

430429
/// Returns the % of the hash table that is full.
@@ -481,13 +480,13 @@ unsafe fn cluster_first_entry(cluster: *mut Cluster) -> *mut Entry {
481480
#[inline]
482481
fn alloc_room(size: usize) -> NonNull<Cluster> {
483482
unsafe {
484-
let ptr = Heap.alloc_zeroed(Layout::array::<Cluster>(size).unwrap());
483+
let ptr = Global.alloc_zeroed(Layout::array::<Cluster>(size).unwrap());
485484

486485
let new_ptr = match ptr {
487-
Ok(ptr) => ptr,
488-
Err(err) => Heap.oom(err),
486+
Ok(ptr) => ptr.cast(),
487+
Err(_err) => Global.oom(),
489488
};
490-
NonNull::new(new_ptr as *mut Cluster).unwrap()
489+
new_ptr
491490
}
492491

493492
}

pleco_engine/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pleco_engine"
3-
version = "0.1.1" # Reminder to change in ./engine.rs
3+
version = "0.1.2" # Reminder to change in ./engine.rs
44
authors = ["Stephen Fleischman <[email protected]>"]
55
description = "A blazingly-fast Chess AI."
66
homepage = "https://github.com/sfleischman105/Pleco"
@@ -67,7 +67,7 @@ path = "src/lib.rs"
6767
doctest = true
6868

6969
[dependencies]
70-
pleco = { path = "../pleco", version = "0.4.0" }
70+
pleco = { path = "../pleco", version = "0.4.1" }
7171
clippy = {version = "0.0.191", optional = true}
7272
chrono = "0.4.1"
7373
rand = "0.4.2"

pleco_engine/src/consts.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Constant values and static structures.
2-
use std::heap::{Alloc, Layout, Heap};
2+
use std::heap::{Alloc, Layout, Global};
33

44
use std::ptr::{NonNull, self};
55
use std::sync::atomic::AtomicBool;
@@ -52,10 +52,10 @@ pub fn init_globals() {
5252
fn init_tt() {
5353
unsafe {
5454
let layout = Layout::new::<TranspositionTable>();
55-
let result = Heap.alloc_zeroed(layout);
55+
let result = Global.alloc_zeroed(layout);
5656
let new_ptr: *mut TranspositionTable = match result {
57-
Ok(ptr) => ptr as *mut TranspositionTable,
58-
Err(err) => Heap.oom(err),
57+
Ok(ptr) => ptr.cast().as_ptr() as *mut TranspositionTable,
58+
Err(_err) => Global.oom(),
5959
};
6060
ptr::write(new_ptr, TranspositionTable::new(DEFAULT_TT_SIZE));
6161
TT_TABLE = NonNull::new_unchecked(new_ptr);
@@ -65,10 +65,10 @@ fn init_tt() {
6565
fn init_timer() {
6666
unsafe {
6767
let layout = Layout::new::<TimeManager>();
68-
let result = Heap.alloc_zeroed(layout);
68+
let result = Global.alloc_zeroed(layout);
6969
let new_ptr: *mut TimeManager = match result {
70-
Ok(ptr) => ptr as *mut TimeManager,
71-
Err(err) => Heap.oom(err),
70+
Ok(ptr) => ptr.cast().as_ptr() as *mut TimeManager,
71+
Err(_err) => Global.oom(),
7272
};
7373
ptr::write(new_ptr, TimeManager::uninitialized());
7474
TIMER = NonNull::new_unchecked(new_ptr);

pleco_engine/src/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use num_cpus;
2020

2121
pub static ID_NAME: &str = "Pleco";
2222
pub static ID_AUTHORS: &str = "Stephen Fleischman";
23-
pub static VERSION: &str = "0.1.1";
23+
pub static VERSION: &str = "0.1.2";
2424

2525
#[derive(PartialEq)]
2626
enum SearchType {

pleco_engine/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![feature(fused)]
3030
#![feature(const_fn)]
3131
#![feature(box_into_raw_non_null)]
32+
#![feature(nonnull_cast)]
3233

3334
//#![crate_type = "staticlib"]
3435

pleco_engine/src/tables/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod capture_piece_history;
77
pub mod butterfly;
88

99
use std::ptr::NonNull;
10-
use std::heap::{Alloc, Layout, Heap};
10+
use std::heap::{Alloc, Layout, Global};
1111
use std::mem;
1212
use std::ptr;
1313
use std::ops::*;
@@ -138,17 +138,17 @@ impl<T: Sized + TableBaseConst> TableBase<T> {
138138

139139
// allocates space.
140140
unsafe fn alloc() -> NonNull<T> {
141-
let ptr = Heap.alloc_zeroed(Layout::array::<T>(T::ENTRY_COUNT).unwrap());
141+
let ptr = Global.alloc_zeroed(Layout::array::<T>(T::ENTRY_COUNT).unwrap());
142142
let new_ptr = match ptr {
143-
Ok(ptr) => ptr,
144-
Err(err) => Heap.oom(err),
143+
Ok(ptr) => ptr.cast().as_ptr(),
144+
Err(_err) => Global.oom(),
145145
};
146146
NonNull::new(new_ptr as *mut T).unwrap()
147147
}
148148

149149
/// de-allocates the current table.
150150
unsafe fn de_alloc(&mut self) {
151-
Heap.dealloc(self.table.as_ptr() as *mut _,
151+
Global.dealloc(self.table.as_opaque(),
152152
Layout::array::<T>(T::ENTRY_COUNT).unwrap());
153153
}
154154
}

pleco_engine/src/threadpool/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Contains the ThreadPool and the individual Threads.
22
3-
use std::heap::{Alloc, Layout, Heap};
3+
use std::heap::{Alloc, Layout, Global};
44
use std::sync::atomic::{AtomicBool,Ordering};
55
use std::thread::{JoinHandle,self};
66
use std::sync::{Once, ONCE_INIT};
@@ -39,10 +39,10 @@ pub fn init_threadpool() {
3939
.stack_size(THREAD_STACK_SIZE);
4040
let handle = scoped::builder_spawn_unsafe(builder, move || {
4141
let layout = Layout::new::<ThreadPool>();
42-
let result = Heap.alloc_zeroed(layout);
42+
let result = Global.alloc_zeroed(layout);
4343
let new_ptr: *mut ThreadPool = match result {
44-
Ok(ptr) => ptr as *mut ThreadPool,
45-
Err(err) => Heap.oom(err),
44+
Ok(ptr) => ptr.cast().as_ptr() as *mut ThreadPool,
45+
Err(_err) => Global.oom(),
4646
};
4747
ptr::write(new_ptr, ThreadPool::new());
4848
THREADPOOL = NonNull::new_unchecked(new_ptr);
@@ -138,10 +138,10 @@ impl ThreadPool {
138138
let layout = Layout::new::<Searcher>();
139139
let cond = if len == 0 {self.main_cond.clone()} else {self.thread_cond.clone()};
140140
unsafe {
141-
let result = Heap.alloc_zeroed(layout);
141+
let result = Global.alloc_zeroed(layout);
142142
let new_ptr: *mut Searcher = match result {
143-
Ok(ptr) => ptr as *mut Searcher,
144-
Err(err) => Heap.oom(err),
143+
Ok(ptr) => ptr.cast().as_ptr() as *mut Searcher,
144+
Err(_err) => Global.oom(),
145145
};
146146
ptr::write(new_ptr, Searcher::new(len, cond));
147147
self.threads.push(UnsafeCell::new(new_ptr));
@@ -217,7 +217,7 @@ impl ThreadPool {
217217
while let Some(unc) = self.threads.pop() {
218218
let th: *mut Searcher = *unc.get();
219219
let layout = Layout::new::<Searcher>();
220-
Heap.dealloc(th as *mut _, layout);
220+
Global.dealloc(NonNull::new_unchecked(th).as_opaque(), layout);
221221
}
222222
}
223223

0 commit comments

Comments
 (0)