Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/AST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum ASTType {
AST_TextDelimiters,
NUM_ASTTypes
};
const char* ASTType_str[NUM_ASTTypes] = {};
thread_local const char* ASTType_str[NUM_ASTTypes] = {};

struct ASTHelper;
struct ASTNode {
Expand All @@ -106,10 +106,10 @@ struct ASTNode {
{}
};

bool parse_ast = false;
ASTNode ast;
ASTNode* cur_ast = *
ASTHelper* cur_ast_help = nullptr;
thread_local bool parse_ast = false;
thread_local ASTNode ast;
thread_local ASTNode* cur_ast = *
thread_local ASTHelper* cur_ast_help = nullptr;

const UChar* xml_encode(const UChar* b, const UChar* e) {
static thread_local CG3::UString buf;
Expand Down
2 changes: 1 addition & 1 deletion src/Cohort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace CG3 {

extern pool<Cohort> pool_cohorts;
extern thread_local pool<Cohort> pool_cohorts;

Cohort* alloc_cohort(SingleWindow* p) {
Cohort* c = pool_cohorts.get();
Expand Down
6 changes: 3 additions & 3 deletions src/GrammarApplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
namespace CG3 {

// Order is important - we want SingleWindows to be destroyed first, then Cohorts, then Readings
pool<Reading> pool_readings;
pool<Cohort> pool_cohorts;
pool<SingleWindow> pool_swindows;
thread_local pool<Reading> pool_readings;
thread_local pool<Cohort> pool_cohorts;
thread_local pool<SingleWindow> pool_swindows;

GrammarApplicator::GrammarApplicator(std::ostream& ux_err)
: ux_stderr(&ux_err)
Expand Down
2 changes: 1 addition & 1 deletion src/GrammarApplicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class GrammarApplicator {
Reading* get_sub_reading(Reading* tr, int sub_reading);

void printDebugRule(const Rule& rule, bool target = true, bool cntx = true) {
static std::stringstream buf;
thread_local static std::stringstream buf;

bool ttrace = false;
swapper<bool> _st(true, trace, ttrace);
Expand Down
2 changes: 1 addition & 1 deletion src/Reading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace CG3 {

extern pool<Reading> pool_readings;
extern thread_local pool<Reading> pool_readings;

Reading* alloc_reading(Cohort* p) {
Reading* r = pool_readings.get();
Expand Down
2 changes: 1 addition & 1 deletion src/SingleWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace CG3 {

extern pool<SingleWindow> pool_swindows;
extern thread_local pool<SingleWindow> pool_swindows;

SingleWindow* alloc_swindow(Window* p) {
SingleWindow* s = pool_swindows.get();
Expand Down
2 changes: 2 additions & 0 deletions src/cg3.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ Valid signatures:
//*/
void cg3_applicator_setoption(cg3_applicator* applicator, cg3_option option, void* value);
void cg3_applicator_free(cg3_applicator* applicator);
void cg3_applicator_free_binary(cg3_applicator* applicator);

void cg3_run_grammar_on_text(cg3_applicator*, std_istream*, std_ostream*);
void cg3_run_grammar_on_text_fns(cg3_applicator*, const char* input, const char* output);
size_t cg3_run_grammar_on_buffer(cg3_applicator* applicator_, const char* input, size_t in_length, char* output, size_t out_length);
size_t cg3_run_grammar_on_buffer_binary(cg3_applicator* applicator_, const char* input, size_t in_length, char* output, size_t out_length);

cg3_mwesplitapplicator* cg3_mwesplitapplicator_create();
#define cg3_mwesplitapplicator_free cg3_applicator_free
Expand Down
2 changes: 1 addition & 1 deletion src/flat_unordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class flat_unordered_map {
return;
}

static container vals;
thread_local static container vals;
vals.resize(0);
vals.reserve(size_);
for (auto& elem : elements) {
Expand Down
20 changes: 20 additions & 0 deletions src/libcg3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ void cg3_applicator_free(cg3_applicator* applicator_) {
delete applicator;
}

void cg3_applicator_free_binary(cg3_applicator* applicator_) {
GrammarApplicator* applicator = static_cast<BinaryApplicator*>(applicator_);
delete applicator;
}

void cg3_run_grammar_on_text(cg3_applicator* applicator_, std_istream* is_, std_ostream* os_) {
GrammarApplicator* applicator = static_cast<GrammarApplicator*>(applicator_);
std::istream* is = static_cast<std::istream*>(is_);
Expand Down Expand Up @@ -312,6 +317,21 @@ size_t cg3_run_grammar_on_buffer(cg3_applicator* applicator_, const char* input,
return mx;
}

size_t cg3_run_grammar_on_buffer_binary(cg3_applicator* applicator_, const char* input, size_t in_length, char* output, size_t out_length) {
BinaryApplicator* applicator = static_cast<BinaryApplicator*>(applicator_);
std::string istr(input, in_length);
std::istringstream is(istr);
std::ostringstream os;
applicator->runGrammarOnText(is, os);
// Ideally we would write directly to output without copying,
// but I couldn't figure out how to do that, and this is good
// enough for my purposes. -DGS 2026-02-16
const auto& ostr = os.str();
auto mx = (ostr.size() > out_length ? out_length : ostr.size());
memcpy(output, ostr.data(), mx);
return mx;
}

cg3_sentence* cg3_sentence_new(cg3_applicator* applicator_) {
GrammarApplicator* applicator = static_cast<GrammarApplicator*>(applicator_);
SingleWindow* current = applicator->gWindow->allocSingleWindow();
Expand Down
Loading