--- parser3/src/main/pa_globals.C 2019/12/25 22:33:13 1.206 +++ parser3/src/main/pa_globals.C 2025/08/01 17:10:14 1.218 @@ -1,8 +1,8 @@ /** @file Parser: globals. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #include "pa_config_includes.h" @@ -19,7 +19,6 @@ extern "C" { #include "pa_globals.h" #include "pa_socks.h" #include "pa_sapi.h" -#include "pa_threads.h" #include "pa_xml_io.h" #include "pa_common.h" #include "pa_symbols.h" @@ -27,9 +26,9 @@ extern "C" { #include "pa_cache_managers.h" #include "ltdl.h" -#include "pcre.h" +#include "pa_vregex.h" -volatile const char * IDENT_PA_GLOBALS_C="$Id: pa_globals.C,v 1.206 2019/12/25 22:33:13 moko Exp $" IDENT_PA_GLOBALS_H IDENT_PA_SAPI_H; +volatile const char * IDENT_PA_GLOBALS_C="$Id: pa_globals.C,v 1.218 2025/08/01 17:10:14 moko Exp $" IDENT_PA_GLOBALS_H IDENT_PA_SAPI_H; // defines @@ -47,13 +46,16 @@ short hex_value[0x100] = { 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -THREAD_LOCAL Request* thread_request=NULL; +THREAD_LOCAL Request* thread_request=NULL; // every TLS should be referenced elsewhere, or GC will collect it void pa_register_thread_request(Request& r) { thread_request=&r; } + /// retrives request set by pa_set_request function, useful in contextless places [slow] Request& pa_thread_request() { + if(!thread_request) + throw Exception(0, 0, "request is not initialized"); return *thread_request; } @@ -175,10 +177,30 @@ static void pa_gc_free_maybeignore(void* #endif // XML +#ifdef HAVE_PCRE2 +pcre2_general_context* VRegex::fgen_ctxt; + +static void* pa_pcre_malloc(size_t size, void *){ + return pa_malloc(size); +} + +static void pa_pcre_free(void *ptr, void *){ + pa_free(ptr); +} +#endif + + void pa_CORD_oom_fn(void) { pa_fail_alloc("expand string", 0); } +#ifndef PA_DEBUG_DISABLE_GC +extern "C" void *pa_fail_alloc(const char*); +extern "C" void pa_GC_abort_func(const char *msg) { + pa_fail_alloc(msg); +} +#endif + /** @todo gc: libltdl: substitute lt_dlmalloc & co */ @@ -205,8 +227,12 @@ static void gc_substitute_memory_managem #endif // pcre +#ifdef HAVE_PCRE2 + VRegex::fgen_ctxt=pcre2_general_context_create(pa_pcre_malloc, pa_pcre_free, NULL); +#else pcre_malloc=pa_malloc; pcre_free=pa_free; +#endif // cord CORD_oom_fn=pa_CORD_oom_fn; @@ -218,12 +244,13 @@ static void gc_substitute_memory_managem void pa_globals_init() { #ifndef PA_DEBUG_DISABLE_GC - GC_java_finalization=0; // Dont collect unless explicitly requested. This is quicker (~30% ), // but less memory-efficient(~8%), so deciding for speed. - GC_dont_gc=1; + GC_disable(); // as we log allocation errors, we don't need default gc warnings (without timestamp and URI) GC_set_warn_proc(GC_ignore_warn_proc); + // to prevent "mmap(PROT_NONE) failed + Aborted" under Linux + GC_set_abort_func(pa_GC_abort_func); #endif // init socks @@ -284,6 +311,9 @@ void pa_globals_init() { pa_xml_io_init(); #endif + + // init *_class variables + methoded_array(); } static bool is_dlinited=false; @@ -355,7 +385,6 @@ void pa_dlinit() { // defines for VS2015 to link with gc/xml libs compiled in the previous VS versions #if _MSC_VER >= 1900 #pragma comment(lib,"legacy_stdio_definitions.lib") -extern "C" { FILE _iob[3] = { *stdin, *stdout, *stderr }; } #endif #endif // _MSC_VER