Merge pull request #307 from tree-sitter/pointer-sized-cancellation-flag

Make the cancellation flag a size_t, not a uint32_t
This commit is contained in:
Max Brunsfeld 2019-03-22 12:30:39 -07:00 committed by GitHub
commit 82358d3f2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 31 additions and 30 deletions

View file

@ -1,5 +1,6 @@
/* automatically generated by rust-bindgen */
pub type __darwin_size_t = ::std::os::raw::c_ulong;
pub type FILE = [u64; 19usize];
pub type TSSymbol = u16;
#[repr(C)]
@ -136,10 +137,10 @@ extern "C" {
) -> *mut TSTree;
}
extern "C" {
pub fn ts_parser_cancellation_flag(arg1: *const TSParser) -> *const u32;
pub fn ts_parser_cancellation_flag(arg1: *const TSParser) -> *const usize;
}
extern "C" {
pub fn ts_parser_set_cancellation_flag(arg1: *mut TSParser, arg2: *const u32);
pub fn ts_parser_set_cancellation_flag(arg1: *mut TSParser, arg2: *const usize);
}
extern "C" {
pub fn ts_parser_timeout_micros(arg1: *const TSParser) -> u64;

View file

@ -15,7 +15,7 @@ use std::collections::HashMap;
use std::ffi::CStr;
use std::marker::PhantomData;
use std::os::raw::{c_char, c_void};
use std::sync::atomic::AtomicU32;
use std::sync::atomic::AtomicUsize;
use std::{fmt, ptr, slice, str, u16};
pub const PARSER_HEADER: &'static str = include_str!("../include/tree_sitter/parser.h");
@ -336,13 +336,13 @@ impl Parser {
};
}
pub unsafe fn cancellation_flag(&self) -> Option<&AtomicU32> {
(ffi::ts_parser_cancellation_flag(self.0) as *const AtomicU32).as_ref()
pub unsafe fn cancellation_flag(&self) -> Option<&AtomicUsize> {
(ffi::ts_parser_cancellation_flag(self.0) as *const AtomicUsize).as_ref()
}
pub unsafe fn set_cancellation_flag(&self, flag: Option<&AtomicU32>) {
pub unsafe fn set_cancellation_flag(&self, flag: Option<&AtomicUsize>) {
if let Some(flag) = flag {
ffi::ts_parser_set_cancellation_flag(self.0, flag as *const AtomicU32 as *const u32);
ffi::ts_parser_set_cancellation_flag(self.0, flag as *const AtomicUsize as *const usize);
} else {
ffi::ts_parser_set_cancellation_flag(self.0, ptr::null());
}

View file

@ -88,8 +88,8 @@ void ts_parser_halt_on_error(TSParser *, bool);
TSTree *ts_parser_parse(TSParser *, const TSTree *, TSInput);
TSTree *ts_parser_parse_string(TSParser *, const TSTree *, const char *, uint32_t);
TSTree *ts_parser_parse_string_encoding(TSParser *, const TSTree *, const char *, uint32_t, TSInputEncoding);
const uint32_t *ts_parser_cancellation_flag(const TSParser *);
void ts_parser_set_cancellation_flag(TSParser *, const uint32_t *);
const size_t *ts_parser_cancellation_flag(const TSParser *);
void ts_parser_set_cancellation_flag(TSParser *, const size_t *);
uint64_t ts_parser_timeout_micros(const TSParser *);
void ts_parser_set_timeout_micros(TSParser *, uint64_t);
void ts_parser_reset(TSParser *);

View file

@ -7,7 +7,7 @@
#include <windows.h>
static inline uint32_t atomic_load(const volatile uint32_t *p) {
static inline size_t atomic_load(const volatile size_t *p) {
return *p;
}
@ -21,7 +21,7 @@ static inline uint32_t atomic_dec(volatile uint32_t *p) {
#else
static inline uint32_t atomic_load(const volatile uint32_t *p) {
static inline size_t atomic_load(const volatile size_t *p) {
return __atomic_load_n(p, __ATOMIC_RELAXED);
}

View file

@ -70,7 +70,7 @@ struct TSParser {
TSDuration timeout_duration;
unsigned accept_count;
unsigned operation_count;
const volatile uint32_t *cancellation_flag;
const volatile size_t *cancellation_flag;
bool halt_on_error;
Subtree old_tree;
TSRangeArray included_range_differences;
@ -1589,12 +1589,12 @@ void ts_parser_halt_on_error(TSParser *self, bool should_halt_on_error) {
self->halt_on_error = should_halt_on_error;
}
const uint32_t *ts_parser_cancellation_flag(const TSParser *self) {
return (const uint32_t *)self->cancellation_flag;
const size_t *ts_parser_cancellation_flag(const TSParser *self) {
return (const size_t *)self->cancellation_flag;
}
void ts_parser_set_cancellation_flag(TSParser *self, const uint32_t *flag) {
self->cancellation_flag = (const volatile uint32_t *)flag;
void ts_parser_set_cancellation_flag(TSParser *self, const size_t *flag) {
self->cancellation_flag = (const volatile size_t *)flag;
}
uint64_t ts_parser_timeout_micros(const TSParser *self) {