32 #ifndef _QORE_QORELIBINTERN_H
34 #define _QORE_QORELIBINTERN_H
36 #include "qore/intern/config.h"
40 #include <sys/types.h>
42 #ifdef HAVE_SYS_STATVFS_H
43 #define Q_HAVE_STATVFS
44 #include <sys/statvfs.h>
48 #ifdef HAVE_EXECINFO_H
51 #ifdef HAVE_ARPA_INET_H
52 #include <arpa/inet.h>
54 #ifdef HAVE_SYS_SOCKET_H
55 #include <sys/socket.h>
60 #ifdef HAVE_NETINET_IN_H
61 #include <netinet/in.h>
63 #ifdef HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
66 #ifdef HAVE_SYS_SOCKET_H
67 #include <sys/socket.h>
72 #ifdef HAVE_ARPA_INET_H
73 #include <arpa/inet.h>
75 #ifdef HAVE_WINSOCK2_H
78 #ifdef HAVE_WS2TCPIP_H
84 #ifdef HAVE_NETINET_TCP_H
85 #include <netinet/tcp.h>
91 #ifdef HAVE_INTTYPES_H
95 #ifndef HAVE_STRCASESTR
96 extern char* strcasestr(
const char* s1,
const char* s2);
100 #define MPFR_USE_INTMAX_T 1
106 #if TARGET_BITS == 64
121 #define NT_SOFTINT -4
122 #define NT_SOFTFLOAT -5
123 #define NT_SOFTNUMBER -6
124 #define NT_SOFTBOOLEAN -7
125 #define NT_SOFTSTRING -8
126 #define NT_SOFTDATE -9
127 #define NT_SOFTLIST -10
128 #define NT_TIMEOUT -11
129 #define NT_INTORFLOAT -12
130 #define NT_INTFLOATORNUMBER -13
131 #define NT_FLOATORNUMBER -14
132 #define NT_SOFTBINARY -15
134 #define NT_SOMETHING -101 // i.e. "not NOTHING"
135 #define NT_DATA -102 // either QoreStringNode or BinaryNode
137 typedef std::set<QoreObject*> obj_set_t;
140 DLLLOCAL
extern int qore_ssl_data_index;
143 enum q_setpub_t :
unsigned char {
149 DLLLOCAL
void parse_init_value(
QoreValue& val, LocalVar* oflag,
int pflag,
int& lvids,
const QoreTypeInfo*& typeInfo);
156 DLLLOCAL
bool needs_scan(
const QoreValue& v);
162 hashdecl ParseWarnOptions {
166 DLLLOCAL ParseWarnOptions() : parse_options(0), warn_mask(0) {
169 DLLLOCAL ParseWarnOptions(
int64 n_parse_options,
int n_warn_mask = 0) : parse_options(n_parse_options), warn_mask(n_warn_mask) {
172 DLLLOCAL
void operator=(
const ParseWarnOptions& pwo) {
173 parse_options = pwo.parse_options;
174 warn_mask = pwo.warn_mask;
177 DLLLOCAL
bool operator==(
const ParseWarnOptions& pwo)
const {
178 return parse_options == pwo.parse_options && warn_mask == pwo.warn_mask;
182 hashdecl QoreProgramLineLocation {
183 int16_t start_line = -1,
187 DLLLOCAL QoreProgramLineLocation(
int sline,
int eline) : start_line(sline ? sline : (eline ? 1 : 0)), end_line(eline) {
188 assert(sline <= 0xffff);
189 assert(eline <= 0xffff);
192 DLLLOCAL QoreProgramLineLocation() {
195 DLLLOCAL QoreProgramLineLocation(
const QoreProgramLineLocation& old) =
default;
197 DLLLOCAL QoreProgramLineLocation(QoreProgramLineLocation&& old) =
default;
200 hashdecl QoreProgramLocation :
public QoreProgramLineLocation {
203 DLLLOCAL QoreProgramLocation() {
206 DLLLOCAL
explicit QoreProgramLocation(
const char* f,
int sline,
int eline,
const char* source,
int offset,
207 const char* lang =
"Qore") :
208 QoreProgramLineLocation(sline, eline), file(f), source(source), lang(lang), offset(offset) {
209 assert(offset <= 0xffff);
212 DLLLOCAL
explicit QoreProgramLocation(
const char* f,
int sline = 0,
int eline = 0) :
213 QoreProgramLineLocation(sline, eline), file(f) {
217 DLLLOCAL QoreProgramLocation(
int sline,
int eline);
219 DLLLOCAL QoreProgramLocation(
const QoreProgramLocation& old) =
default;
221 DLLLOCAL QoreProgramLocation(QoreProgramLocation&& old) =
default;
223 DLLLOCAL
void clear() {
224 start_line = end_line = -1;
230 DLLLOCAL
void toString(
QoreString& str)
const;
232 DLLLOCAL
const char* getFile()
const {
236 DLLLOCAL
const char* getFileValue()
const {
237 return file ? file :
"";
240 DLLLOCAL
const char* getSource()
const {
244 DLLLOCAL
const char* getSourceValue()
const {
245 return source ? source :
"";
248 DLLLOCAL
const char* getLanguage()
const {
252 DLLLOCAL
const char* getLanguageValue()
const {
253 return lang ? lang :
"";
256 DLLLOCAL
void setFile(
const char* f) {
260 DLLLOCAL
void setSource(
const char* s) {
264 DLLLOCAL
void setLanguage(
const char* l) {
268 DLLLOCAL
bool operator<(
const QoreProgramLocation& loc)
const {
269 return start_line < loc.start_line
270 || end_line < loc.end_line
272 || source < loc.source
273 || offset < loc.offset
277 DLLLOCAL
bool operator==(
const QoreProgramLocation& loc)
const {
278 return start_line == loc.start_line
279 && end_line == loc.end_line
281 && source == loc.source
282 && offset == loc.offset
286 DLLLOCAL
bool operator!=(
const QoreProgramLocation& loc)
const {
287 return !(*
this == loc);
291 const char* file =
nullptr;
292 const char* source =
nullptr;
293 const char* lang =
"Qore";
299 DLLLOCAL
extern const QoreProgramLocation loc_builtin;
301 hashdecl QoreCommandLineLocation :
public QoreProgramLocation {
302 DLLLOCAL QoreCommandLineLocation() : QoreProgramLocation(
"<command-line>", 1, 1) {
307 DLLLOCAL
extern QoreCommandLineLocation qoreCommandLineLocation;
310 DLLLOCAL
void parse_error(
const QoreProgramLocation& loc,
const char* fmt, ...);
311 DLLLOCAL
void parseException(
const QoreProgramLocation& loc,
const char* err,
const char* fmt, ...);
312 DLLLOCAL
void parseException(
const QoreProgramLocation& loc,
const char* err,
QoreStringNode* desc);
314 DLLLOCAL
QoreString* findFileInPath(
const char* file,
const char* path);
315 DLLLOCAL
QoreString* findFileInEnvPath(
const char* file,
const char* varname);
316 DLLLOCAL
int qore_find_file_in_path(
QoreString& str,
const char* file,
const char* path);
318 DLLLOCAL
const QoreTypeInfo* getBuiltinUserTypeInfo(
const char* str);
319 DLLLOCAL
const QoreTypeInfo* getBuiltinUserOrNothingTypeInfo(
const char* str);
321 DLLLOCAL
const char* getBuiltinTypeName(
qore_type_t type);
332 #ifdef HAVE_STRTOIMAX
333 static inline long long atoll(
const char* str) {
334 return strtoimax(str, 0, 10);
337 static inline long long atoll(
const char* str) {
339 sscanf(str,
"%lld", &i);
345 #if !defined(HAVE_STRTOLL) && defined(HAVE_STRTOIMAX)
347 #define strtoll strtoimax
355 #ifdef HAVE_OPENSSL_CONST
356 #define OPENSSL_CONST const
358 #define OPENSSL_CONST
361 #ifdef HAVE_X509_GET0_SIGNATURE_CONST
362 #define OPENSSL_X509_GET0_SIGNATURE_CONST const
364 #define OPENSSL_X509_GET0_SIGNATURE_CONST
367 typedef std::set<const AbstractQoreNode*> const_node_set_t;
368 typedef std::set<LocalVar*> lvar_set_t;
370 class LVarSet :
public lvar_set_t {
377 DLLLOCAL LVarSet() : needs_scan(false) {
381 DLLLOCAL
void add(LocalVar* var);
384 DLLLOCAL
bool needsScan()
const {
389 enum obe_type_e { OBE_Unconditional, OBE_Success, OBE_Error };
391 class StatementBlock;
392 typedef std::pair<enum obe_type_e, StatementBlock*> qore_conditional_block_exit_statement_t;
394 typedef std::list<qore_conditional_block_exit_statement_t> block_list_t;
397 typedef std::map<QoreCondition*, int> cond_map_t;
399 #if defined(HAVE_CHECK_STACK_POS)
400 #define QORE_MANAGE_STACK
404 #define DAH_NOCHANGE 0 // acquire lock temporarily
405 #define DAH_ACQUIRE 1 // acquire lock and hold
406 #define DAH_RELEASE 2 // release lock at end of action
407 #define DAH_NOCONN 3 // acquire lock temporarily and do not make a connection
409 #define DAH_TEXT(d) (d == DAH_RELEASE ? "RELEASE" : (d == DAH_ACQUIRE ? "ACQUIRE" : "NOCHANGE"))
411 DLLLOCAL
int check_lvalue(
QoreValue n,
bool assign =
true);
413 DLLLOCAL
int check_lvalue_int(
const QoreProgramLocation* loc,
const QoreTypeInfo*& typeInfo,
const char* name);
414 DLLLOCAL
int check_lvalue_float(
const QoreProgramLocation* loc,
const QoreTypeInfo*& typeInfo,
const char* name);
415 DLLLOCAL
int check_lvalue_int_float_number(
const QoreProgramLocation* loc,
const QoreTypeInfo*& typeInfo,
const char* name);
416 DLLLOCAL
int check_lvalue_number(
const QoreProgramLocation* loc,
const QoreTypeInfo*& typeInfo,
const char* name);
418 DLLLOCAL
extern QoreClass* QC_PSEUDOVALUE;
419 DLLLOCAL
extern QoreClass* QC_PSEUDONOTHING;
428 #define Q_SVF_BSIZE 4096
429 #define Q_HAVE_STATVFS
431 unsigned long f_bsize;
432 unsigned long f_frsize;
433 unsigned int f_blocks;
434 unsigned int f_bfree;
435 unsigned int f_bavail;
436 unsigned int f_files;
437 unsigned int f_ffree;
438 unsigned int f_favail;
439 unsigned long f_fsid;
440 unsigned long f_flag;
441 unsigned long f_namemax;
444 f_frsize = f_bsize = Q_SVF_BSIZE;
445 f_blocks = total / Q_SVF_BSIZE;
446 f_bfree = free / Q_SVF_BSIZE;
447 f_bavail = avail / Q_SVF_BSIZE;
449 f_files = f_blocks / 8;
450 f_ffree = f_bfree / 8;
451 f_favail = f_bavail / 8;
457 DLLLOCAL
int statvfs(
const char* path,
struct statvfs* buf);
458 DLLLOCAL
int q_fstatvfs(
const char* filepath,
struct statvfs* buf);
470 for (
auto& i : *value_list) {
491 value_list->push_back(v);
499 class QoreParseListNode;
501 #include "qore/intern/NamedScope.h"
502 #include "qore/intern/QoreTypeInfo.h"
503 #include "qore/intern/ParseNode.h"
504 #include "qore/intern/QoreThreadList.h"
505 #include "qore/intern/lvalue_ref.h"
506 #include "qore/intern/qore_thread_intern.h"
507 #include "qore/intern/Function.h"
508 #include "qore/intern/CallReferenceCallNode.h"
509 #include "qore/intern/CallReferenceNode.h"
510 #include "qore/intern/BuiltinFunction.h"
511 #include "qore/intern/AbstractStatement.h"
512 #include "qore/intern/Variable.h"
513 #include "qore/intern/LocalVar.h"
514 #include "qore/intern/ScopedObjectCallNode.h"
515 #include "qore/intern/NewComplexTypeNode.h"
516 #include "qore/intern/ScopedRefNode.h"
517 #include "qore/intern/ClassRefNode.h"
518 #include "qore/intern/Context.h"
519 #include "qore/intern/BarewordNode.h"
520 #include "qore/intern/SelfVarrefNode.h"
521 #include "qore/intern/StaticClassVarRefNode.h"
522 #include "qore/intern/BackquoteNode.h"
523 #include "qore/intern/ContextrefNode.h"
524 #include "qore/intern/ContextRowNode.h"
525 #include "qore/intern/ComplexContextrefNode.h"
526 #include "qore/intern/FindNode.h"
527 #include "qore/intern/VRMutex.h"
528 #include "qore/intern/VLock.h"
529 #include "qore/intern/QoreException.h"
530 #include "qore/intern/StatementBlock.h"
531 #include "qore/intern/VarRefNode.h"
532 #include "qore/intern/QoreRegexSubst.h"
533 #include "qore/intern/QoreRegex.h"
534 #include "qore/intern/QoreTransliteration.h"
535 #include "qore/intern/ObjectMethodReferenceNode.h"
536 #include "qore/intern/QoreClosureParseNode.h"
537 #include "qore/intern/QoreClosureNode.h"
538 #include "qore/intern/QoreImplicitArgumentNode.h"
539 #include "qore/intern/QoreImplicitElementNode.h"
540 #include "qore/intern/QoreOperatorNode.h"
541 #include "qore/intern/QoreTimeZoneManager.h"
542 #include "qore/intern/ContextStatement.h"
543 #include "qore/intern/SwitchStatement.h"
544 #include "qore/intern/QorePseudoMethods.h"
545 #include "qore/intern/ParseReferenceNode.h"
546 #include "qore/intern/WeakReferenceNode.h"
548 DLLLOCAL
extern std::atomic<bool> qore_initialized;
549 DLLLOCAL
extern std::atomic<bool> qore_shutdown;
550 DLLLOCAL
extern std::atomic<bool> qore_exiting;
552 DLLLOCAL
extern int qore_library_options;
554 #ifndef HAVE_GETHOSTBYADDR_R
561 #define NET_BUFSIZE 1024
564 #ifndef HOSTNAMEBUFSIZE
565 #define HOSTNAMEBUFSIZE 512
568 #ifndef HAVE_LOCALTIME_R
572 #ifndef HAVE_GMTIME_R
576 DLLLOCAL
extern char table64[64];
579 DLLLOCAL
BinaryNode*
parseHex(
const QoreProgramLocation* loc,
const char* buf,
int len);
580 DLLLOCAL
void print_node(FILE* fp,
const QoreValue qv);
581 DLLLOCAL
void delete_global_variables();
582 DLLLOCAL
void init_lib_intern(
char* env[]);
583 DLLLOCAL QoreParseListNode* make_args(
const QoreProgramLocation* loc,
QoreValue arg);
587 DLLLOCAL
void init_qore_types();
588 DLLLOCAL
void delete_qore_types();
590 DLLLOCAL
QoreListNode* stat_to_list(
const struct stat& sbuf);
592 DLLLOCAL
QoreHashNode* statvfs_to_hash(
const struct statvfs& statvfs);
602 DLLLOCAL StaticSystemNamespace();
604 DLLLOCAL ~StaticSystemNamespace();
608 DLLLOCAL
extern StaticSystemNamespace* staticSystemNamespace;
610 class QoreParseListNodeParseInitHelper {
612 QoreParseListNode* l;
619 DLLLOCAL QoreParseListNodeParseInitHelper(QoreParseListNode* n_l, LocalVar* n_oflag,
int n_pflag,
int& n_lvids) :
620 l(n_l), oflag(n_oflag), pflag(n_pflag), lvids(n_lvids) {
623 DLLLOCAL
QoreValue parseInit(
const QoreTypeInfo*& typeInfo) {
628 parse_init_value(n, oflag, pflag, lvids, typeInfo);
632 DLLLOCAL
bool next() {
634 if (pos == (
int)l->size()) {
641 DLLLOCAL
int index() {
646 class QorePossibleListNodeParseInitHelper {
654 const QoreTypeInfo* singleTypeInfo =
nullptr;
657 DLLLOCAL QorePossibleListNodeParseInitHelper(
QoreValue& n, LocalVar* n_oflag,
int n_pflag,
int& n_lvids) :
666 parse_init_value(n, oflag, pflag, lvids, singleTypeInfo);
670 if (QoreTypeInfo::parseAccepts(listTypeInfo, singleTypeInfo))
675 DLLLOCAL
bool noArgument()
const {
679 DLLLOCAL
bool next() {
685 if (pos == l->
size()) {
692 DLLLOCAL
void parseInit(
const QoreTypeInfo*& typeInfo);
695 DLLLOCAL
void raise_nonexistent_method_call_warning(
const QoreProgramLocation* loc,
const QoreClass* qc,
const char* method);
705 class qore_hash_private;
706 class qore_object_private;
709 class hash_assignment_priv {
711 qore_hash_private& h;
713 qore_object_private* o =
nullptr;
715 DLLLOCAL hash_assignment_priv(qore_hash_private& n_h, HashMember* n_om) : h(n_h), om(n_om) {
718 DLLLOCAL hash_assignment_priv(qore_hash_private& n_h,
const char* key,
bool must_already_exist =
false, qore_object_private* obj =
nullptr);
720 DLLLOCAL hash_assignment_priv(
QoreHashNode& n_h,
const char* key,
bool must_already_exist =
false);
722 DLLLOCAL hash_assignment_priv(
QoreHashNode& n_h,
const std::string &key,
bool must_already_exist =
false);
728 DLLLOCAL
void reassign(
const char* key,
bool must_already_exist =
false);
738 DLLLOCAL
bool exists()
const {
755 DLLLOCAL
void qore_machine_backtrace();
757 #ifndef QORE_THREAD_STACK_BLOCK
758 #define QORE_THREAD_STACK_BLOCK 64
761 template <
typename T,
int S1 = QORE_THREAD_STACK_BLOCK>
764 DLLLOCAL ThreadBlock(
const ThreadBlock&);
769 ThreadBlock<T, S1>* prev, * next =
nullptr;
771 DLLLOCAL ThreadBlock(ThreadBlock* prev =
nullptr) : prev(prev) { }
772 DLLLOCAL ~ThreadBlock() { }
773 DLLLOCAL T& get(
int p) {
777 DLLLOCAL
bool frameBoundary(
int p);
780 template <
typename T,
int S1 = QORE_THREAD_STACK_BLOCK>
781 class ThreadLocalDataIterator {
782 typedef ThreadLocalDataIterator<T, S1> self_t;
785 typedef ThreadBlock<T, S1> Block;
788 Block* orig =
nullptr, * curr =
nullptr;
792 DLLLOCAL ThreadLocalDataIterator(Block* n_orig)
793 : orig(n_orig && n_orig->pos ? n_orig : nullptr) {
796 DLLLOCAL ThreadLocalDataIterator() {
799 DLLLOCAL
bool next() {
821 }
while (curr->frameBoundary(pos));
828 return curr->get(pos);
832 template <
typename T,
int S1 = QORE_THREAD_STACK_BLOCK>
833 class ThreadLocalData {
835 typedef ThreadBlock<T, S1> Block;
836 typedef ThreadLocalDataIterator<T, S1> iterator;
840 DLLLOCAL ThreadLocalData() {
845 DLLLOCAL ~ThreadLocalData() {
857 DLLLOCAL
bool empty()
const {
858 return (!curr->pos && !curr->prev);
862 DLLLOCAL
int getFrameCount()
const {
867 int frame_count = -1;
870 DLLLOCAL ThreadLocalData(
const ThreadLocalData&);
874 DLLLOCAL
int q_get_af(
int type);
876 DLLLOCAL
int q_get_raf(
int type);
878 DLLLOCAL
int q_get_sock_type(
int t);
880 class OptHashRefHelper {
890 DLLLOCAL ~OptHashRefHelper() {
911 class VariableBlockHelper {
913 DLLLOCAL VariableBlockHelper();
914 DLLLOCAL ~VariableBlockHelper();
917 class ParseOptionMaps {
919 DLLLOCAL
void doMap(
int64 code,
const char* desc,
const char* dom =
nullptr);
922 typedef std::map<int64, const char*> pomap_t;
923 typedef std::map<const char*, int64, ltstr> pormap_t;
925 pomap_t pomap, dommap;
926 pormap_t pormap, domrmap;
928 DLLLOCAL ParseOptionMaps();
937 DLLLOCAL
extern ParseOptionMaps pomaps;
941 DLLLOCAL
extern bool q_disable_gc;
943 DLLLOCAL
QoreValue qore_parse_get_define_value(
const QoreProgramLocation* loc,
const char* str,
QoreString& arg,
bool& ok);
945 #ifndef HAVE_INET_NTOP
946 DLLLOCAL
const char* inet_ntop(
int af,
const void* src,
char* dst,
size_t size);
948 #ifndef HAVE_INET_PTON
949 DLLLOCAL
int inet_pton(
int af,
const char* src,
void* dst);
957 DLLLOCAL
void check_self_assignment(
const QoreProgramLocation* loc,
QoreValue n, LocalVar* selfid);
959 DLLLOCAL
void ignore_return_value(QoreSimpleValue& n);
961 DLLLOCAL
void qore_string_init();
966 const QoreString* quote,
bool trim_unquoted, AbstractIteratorHelper* h =
nullptr,
973 DLLLOCAL
void init_charmaps();
979 DLLLOCAL
int64 q_clock_getmillis();
980 DLLLOCAL
int64 q_clock_getmicros();
981 DLLLOCAL
int64 q_clock_getnanos();
983 DLLLOCAL
void qore_init_random_salt();
984 DLLLOCAL
int qore_get_ptr_hash(
QoreString& str,
const void* ptr);
987 DLLLOCAL
const char* q_find_first_path_sep(
const char* path);
989 DLLLOCAL
const char* q_find_last_path_sep(
const char* path);
992 DLLLOCAL
int q_get_mode(
const QoreString& path);
1010 DLLLOCAL
void* qore_get_in_addr(
struct sockaddr *sa);
1012 DLLLOCAL
size_t qore_get_in_len(
struct sockaddr *sa);
1014 DLLLOCAL
QoreHashNode* get_source_location(
const QoreProgramLocation* loc);
1016 DLLLOCAL
void qore_delete_module_options();
1018 DLLLOCAL
const QoreTypeInfo* qore_get_type_from_string_intern(
const char* str);