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:
commit
82358d3f2f
12 changed files with 31 additions and 30 deletions
|
|
@ -5,8 +5,8 @@ install:
|
|||
|
||||
# Install rust
|
||||
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
||||
- IF "%PLATFORM%" == "x86" rustup-init -y --default-toolchain beta --default-host i686-pc-windows-msvc
|
||||
- IF "%PLATFORM%" == "x64" rustup-init -y --default-toolchain beta --default-host x86_64-pc-windows-msvc
|
||||
- IF "%PLATFORM%" == "x86" rustup-init -y --default-toolchain stable --default-host i686-pc-windows-msvc
|
||||
- IF "%PLATFORM%" == "x64" rustup-init -y --default-toolchain stable --default-host x86_64-pc-windows-msvc
|
||||
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
|
||||
- rustc -vV
|
||||
- cargo -vV
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
language: rust
|
||||
rust:
|
||||
- beta
|
||||
- stable
|
||||
|
||||
os:
|
||||
- linux
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use super::error::{Error, Result};
|
|||
use super::util;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::time::Instant;
|
||||
use std::{fs, thread};
|
||||
use tree_sitter::{Language, LogType, Parser};
|
||||
|
|
@ -27,7 +27,7 @@ pub fn parse_file_at_path(
|
|||
// If the `--cancel` flag was passed, then cancel the parse
|
||||
// when the user types a newline.
|
||||
if allow_cancellation {
|
||||
let flag = Box::new(AtomicU32::new(0));
|
||||
let flag = Box::new(AtomicUsize::new(0));
|
||||
unsafe { parser.set_cancellation_flag(Some(&flag)) };
|
||||
thread::spawn(move || {
|
||||
let mut line = String::new();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use super::helpers::edits::{perform_edit, Edit, ReadRecorder};
|
||||
use super::helpers::fixtures::{get_language, get_test_language};
|
||||
use crate::generate::generate_parser_for_grammar;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::{thread, time};
|
||||
use tree_sitter::{InputEdit, LogType, Parser, Point, Range};
|
||||
|
||||
|
|
@ -303,7 +303,7 @@ fn test_parsing_on_multiple_threads() {
|
|||
|
||||
#[test]
|
||||
fn test_parsing_cancelled_by_another_thread() {
|
||||
let cancellation_flag = Box::new(AtomicU32::new(0));
|
||||
let cancellation_flag = Box::new(AtomicUsize::new(0));
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(get_language("javascript")).unwrap();
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ int ts_highlighter_highlight(
|
|||
const char *source_code,
|
||||
uint32_t source_code_len,
|
||||
TSHighlightBuffer *output,
|
||||
const uint32_t *cancellation_flag
|
||||
const size_t *cancellation_flag
|
||||
);
|
||||
|
||||
// TSHighlightBuffer: This struct stores the HTML output of syntax
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::ffi::CStr;
|
|||
use std::io::Write;
|
||||
use std::os::raw::c_char;
|
||||
use std::process::abort;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::{fmt, slice};
|
||||
use tree_sitter::{Language, PropertySheet};
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ pub extern "C" fn ts_highlighter_highlight(
|
|||
source_code: *const c_char,
|
||||
source_code_len: u32,
|
||||
output: *mut TSHighlightBuffer,
|
||||
cancellation_flag: *const AtomicU32,
|
||||
cancellation_flag: *const AtomicUsize,
|
||||
) -> ErrorCode {
|
||||
let this = unwrap_ptr(this);
|
||||
let output = unwrap_mut_ptr(output);
|
||||
|
|
@ -154,7 +154,7 @@ impl TSHighlighter {
|
|||
source_code: &[u8],
|
||||
scope_name: &str,
|
||||
output: &mut TSHighlightBuffer,
|
||||
cancellation_flag: Option<&AtomicU32>,
|
||||
cancellation_flag: Option<&AtomicUsize>,
|
||||
) -> ErrorCode {
|
||||
let configuration = self.languages.get(scope_name);
|
||||
if configuration.is_none() {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|||
use serde_derive::*;
|
||||
use std::fmt::{self, Write};
|
||||
use std::mem::transmute;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::{cmp, str, usize};
|
||||
use tree_sitter::{Language, Node, Parser, Point, PropertySheet, Range, Tree, TreePropertyCursor};
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ where
|
|||
layers: Vec<Layer<'a>>,
|
||||
utf8_error_len: Option<usize>,
|
||||
operation_count: usize,
|
||||
cancellation_flag: Option<&'a AtomicU32>,
|
||||
cancellation_flag: Option<&'a AtomicUsize>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
|
@ -382,7 +382,7 @@ where
|
|||
language: Language,
|
||||
property_sheet: &'a PropertySheet<Properties>,
|
||||
injection_callback: F,
|
||||
cancellation_flag: Option<&'a AtomicU32>,
|
||||
cancellation_flag: Option<&'a AtomicUsize>,
|
||||
) -> Result<Self, String> {
|
||||
let mut parser = Parser::new();
|
||||
unsafe { parser.set_cancellation_flag(cancellation_flag.clone()) };
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 *);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue