2727 https://github.com/HaxeFoundation/hashlink/wiki/
2828**/
2929
30- #define HL_VERSION 0x010A00
30+ #define HL_VERSION 0x010C00
3131
3232#if defined(_WIN32 )
3333# define HL_WIN
5353
5454#if defined(linux ) || defined(__linux__ )
5555# define HL_LINUX
56- #ifndef _GNU_SOURCE
5756# define _GNU_SOURCE
5857#endif
59- #endif
6058
6159#if defined(HL_IOS ) || defined(HL_ANDROID ) || defined(HL_TVOS )
6260# define HL_MOBILE
184182#else
185183# define C_FUNCTION_BEGIN
186184# define C_FUNCTION_END
187- # ifndef true
188- # define true 1
189- # define false 0
190- typedef unsigned char bool ;
191- # endif
192185#endif
193186
194187typedef intptr_t int_val ;
195188typedef long long int64 ;
196189typedef unsigned long long uint64 ;
197190
191+ #include <stdbool.h>
198192#include <stdlib.h>
199193#include <stdio.h>
200194#include <memory.h>
@@ -211,9 +205,9 @@ typedef unsigned long long uint64;
211205
212206#if defined(HL_WIN ) && !defined(HL_LLVM )
213207#if defined(HL_WIN_DESKTOP ) && !defined(HL_MINGW )
214- // # include <Windows.h>
208+ # include <Windows.h>
215209#elif defined(HL_WIN_DESKTOP ) && defined(HL_MINGW )
216- // # include<windows.h>
210+ # include <windows.h>
217211#else
218212# include <xdk.h>
219213#endif
@@ -226,8 +220,8 @@ typedef wchar_t uchar;
226220# define ustrlen wcslen
227221# define ustrdup _wcsdup
228222HL_API int uvszprintf ( uchar * out , int out_size , const uchar * fmt , va_list arglist );
229- # define utod (s ,end ) wcstod(s,end)
230- # define utoi (s ,end ) wcstol(s,end,10)
223+ # define _utod (s ,end ) wcstod(s,end)
224+ # define _utoi (s ,end ) wcstol(s,end,10)
231225# define ucmp (a ,b ) wcscmp(a,b)
232226# define utostr (out ,size ,str ) wcstombs(out,str,size)
233227#elif defined(HL_MAC )
@@ -239,39 +233,29 @@ typedef uint16_t uchar;
239233#if defined(HL_IOS ) || defined(HL_TVOS ) || defined(HL_MAC )
240234#include <stddef.h>
241235#include <stdint.h>
242- #ifdef HL_MAC
243236typedef uint16_t char16_t ;
244237typedef uint32_t char32_t ;
245- #endif
246- #elif defined(HL_NATIVE_UCHAR_FUN )
238+ #else
247239# include <uchar.h>
248- #elif __cplusplus <= 199711L
249- # include <stdint.h>
250- typedef uint16_t uchar16_t ;
251- typedef uint32_t uchar32_t ;
252- #ifndef EMSCRIPTEN
253- typedef int32_t char32_t ;
254- typedef int16_t char16_t ;
255- #endif
256240#endif
257241typedef char16_t uchar ;
258242# undef USTR
259243# define USTR (str ) u##str
260244#endif
261245
262- #ifndef HL_NATIVE_UCHAR_FUN
263246C_FUNCTION_BEGIN
264- HL_API int ustrlen ( const uchar * str );
265- HL_API uchar * ustrdup ( const uchar * str );
266247HL_API double utod ( const uchar * str , uchar * * end );
267248HL_API int utoi ( const uchar * str , uchar * * end );
249+ #ifndef HL_NATIVE_UCHAR_FUN
250+ HL_API int ustrlen ( const uchar * str );
251+ HL_API uchar * ustrdup ( const uchar * str );
268252HL_API int ucmp ( const uchar * a , const uchar * b );
269253HL_API int utostr ( char * out , int out_size , const uchar * str );
270254HL_API int usprintf ( uchar * out , int out_size , const uchar * fmt , ... );
271255HL_API int uvszprintf ( uchar * out , int out_size , const uchar * fmt , va_list arglist );
272256HL_API void uprintf ( const uchar * fmt , const uchar * str );
273- C_FUNCTION_END
274257#endif
258+ C_FUNCTION_END
275259
276260#if defined(HL_VCC )
277261# define hl_debug_break () if( IsDebuggerPresent() ) __debugbreak()
@@ -297,6 +281,11 @@ C_FUNCTION_END
297281 ".long 0b;" \
298282 ".popsection")
299283# endif
284+ #elif defined(HL_MAC )
285+ #include <signal.h>
286+ # define hl_debug_break () \
287+ if( hl_detect_debugger() ) \
288+ raise(SIGTRAP);//__builtin_trap();
300289#else
301290# define hl_debug_break ()
302291#endif
@@ -494,7 +483,7 @@ typedef struct _vclosure {
494483 void * fun ;
495484 int hasValue ;
496485# ifdef HL_64
497- int __pad ;
486+ int stackCount ;
498487# endif
499488 void * value ;
500489} vclosure ;
@@ -535,7 +524,9 @@ struct hl_runtime_obj {
535524 vdynamic * (* getFieldFun )( vdynamic * obj , int hfield );
536525 // relative
537526 int nlookup ;
527+ int ninterfaces ;
538528 hl_field_lookup * lookup ;
529+ int * interfaces ;
539530};
540531
541532typedef struct {
@@ -601,6 +592,7 @@ HL_API vdynamic *hl_alloc_strbytes( const uchar *msg, ... );
601592HL_API void hl_assert ( void );
602593HL_API HL_NO_RETURN ( void hl_throw ( vdynamic * v ) );
603594HL_API HL_NO_RETURN ( void hl_rethrow ( vdynamic * v ) );
595+ HL_API HL_NO_RETURN ( void hl_null_access ( void ) );
604596HL_API void hl_setup_longjump ( void * j );
605597HL_API void hl_setup_exception ( void * resolve_symbol , void * capture_stack );
606598HL_API void hl_dump_stack ( void );
@@ -661,7 +653,7 @@ HL_API vdynamic *hl_dyn_call_safe( vclosure *c, vdynamic **args, int nargs, bool
661653 so you are sure it's of the used typed. Otherwise use hl_dyn_call
662654*/
663655#define hl_call0 (ret ,cl ) \
664- (cl->hasValue ? ((ret(*)(vdynamic*))cl->fun)(cl->value) : ((ret(*)())cl->fun)())
656+ (cl->hasValue ? ((ret(*)(vdynamic*))cl->fun)(cl->value) : ((ret(*)())cl->fun)())
665657#define hl_call1 (ret ,cl ,t ,v ) \
666658 (cl->hasValue ? ((ret(*)(vdynamic*,t))cl->fun)(cl->value,v) : ((ret(*)(t))cl->fun)(v))
667659#define hl_call2 (ret ,cl ,t1 ,v1 ,t2 ,v2 ) \
@@ -675,9 +667,13 @@ HL_API vdynamic *hl_dyn_call_safe( vclosure *c, vdynamic **args, int nargs, bool
675667
676668struct _hl_thread ;
677669struct _hl_mutex ;
670+ struct _hl_semaphore ;
671+ struct _hl_condition ;
678672struct _hl_tls ;
679673typedef struct _hl_thread hl_thread ;
680674typedef struct _hl_mutex hl_mutex ;
675+ typedef struct _hl_semaphore hl_semaphore ;
676+ typedef struct _hl_condition hl_condition ;
681677typedef struct _hl_tls hl_tls ;
682678
683679HL_API hl_thread * hl_thread_start ( void * callback , void * param , bool withGC );
@@ -692,6 +688,22 @@ HL_API bool hl_mutex_try_acquire( hl_mutex *l );
692688HL_API void hl_mutex_release ( hl_mutex * l );
693689HL_API void hl_mutex_free ( hl_mutex * l );
694690
691+ HL_API hl_semaphore * hl_semaphore_alloc (int value );
692+ HL_API void hl_semaphore_acquire (hl_semaphore * sem );
693+ HL_API bool hl_semaphore_try_acquire (hl_semaphore * sem , vdynamic * timeout );
694+ HL_API void hl_semaphore_release (hl_semaphore * sem );
695+ HL_API void hl_semaphore_free (hl_semaphore * sem );
696+
697+ HL_API hl_condition * hl_condition_alloc ();
698+ HL_API void hl_condition_acquire (hl_condition * cond );
699+ HL_API bool hl_condition_try_acquire (hl_condition * cond );
700+ HL_API void hl_condition_release (hl_condition * cond );
701+ HL_API void hl_condition_wait (hl_condition * cond );
702+ HL_API bool hl_condition_timed_wait (hl_condition * cond , double timeout );
703+ HL_API void hl_condition_signal (hl_condition * cond );
704+ HL_API void hl_condition_broadcast (hl_condition * cond );
705+ HL_API void hl_condition_free (hl_condition * cond );
706+
695707HL_API hl_tls * hl_tls_alloc ( bool gc_value );
696708HL_API void hl_tls_set ( hl_tls * l , void * value );
697709HL_API void * hl_tls_get ( hl_tls * l );
@@ -754,7 +766,7 @@ HL_API void hl_throw_buffer( hl_buffer *b );
754766// ----------------------- FFI ------------------------------------------------------
755767
756768// match GNU C++ mangling
757- #define TYPE_STR "vcsilfdbBDPOATR??X?N"
769+ #define TYPE_STR "vcsilfdbBDPOATR??X?N?S "
758770
759771#undef _VOID
760772#define _NO_ARG
@@ -776,6 +788,7 @@ HL_API void hl_throw_buffer( hl_buffer *b );
776788#define _ABSTRACT (name ) "X" #name "_"
777789#undef _NULL
778790#define _NULL (t ) "N" t
791+ #define _STRUCT "S"
779792
780793#undef _STRING
781794#define _STRING _OBJ(_BYTES _I32)
@@ -786,7 +799,7 @@ typedef struct {
786799 int length ;
787800} vstring ;
788801
789- // #define DEFINE_PRIM(t,name,args) DEFINE_PRIM_WITH_NAME(t,name,args,name)
802+ // this macro has been renamed from DEFINE_PRIM to DEFINE_HL_PRIM, because DEFINE_PRIM is already used
790803#define DEFINE_HL_PRIM (t ,name ,args ) DEFINE_PRIM_WITH_NAME(t,name,args,name)
791804#define _DEFINE_PRIM_WITH_NAME (t ,name ,args ,realName ) C_FUNCTION_BEGIN EXPORT void *hlp_##realName( const char **sign ) { *sign = _FUN(t,args); return (void*)(&HL_NAME(name)); } C_FUNCTION_END
792805
@@ -838,6 +851,7 @@ HL_API void *hl_fatal_error( const char *msg, const char *file, int line );
838851HL_API void hl_fatal_fmt ( const char * file , int line , const char * fmt , ...);
839852HL_API void hl_sys_init (void * * args , int nargs , void * hlfile );
840853HL_API void hl_setup_callbacks (void * sc , void * gw );
854+ HL_API void hl_setup_callbacks2 (void * sc , void * gw , int flags );
841855HL_API void hl_setup_reload_check ( void * freload , void * param );
842856
843857#include <setjmp.h>
@@ -855,14 +869,17 @@ struct _hl_trap_ctx {
855869#define HL_EXC_CATCH_ALL 2
856870#define HL_EXC_IS_THROW 4
857871#define HL_THREAD_INVISIBLE 16
858- #define HL_TREAD_TRACK_SHIFT 5
872+ #define HL_THREAD_PROFILER_PAUSED 32
873+ #define HL_TREAD_TRACK_SHIFT 16
859874
860875#define HL_TRACK_ALLOC 1
861876#define HL_TRACK_CAST 2
862877#define HL_TRACK_DYNFIELD 4
863878#define HL_TRACK_DYNCALL 8
864879#define HL_TRACK_MASK (HL_TRACK_ALLOC | HL_TRACK_CAST | HL_TRACK_DYNFIELD | HL_TRACK_DYNCALL)
865880
881+ #define HL_MAX_EXTRA_STACK 64
882+
866883typedef struct {
867884 int thread_id ;
868885 // gc vars
@@ -879,6 +896,8 @@ typedef struct {
879896 // extra
880897 jmp_buf gc_regs ;
881898 void * exc_stack_trace [HL_EXC_MAX_STACK ];
899+ void * extra_stack_data [HL_MAX_EXTRA_STACK ];
900+ int extra_stack_size ;
882901} hl_thread_info ;
883902
884903HL_API hl_thread_info * hl_get_thread ();
@@ -898,7 +917,7 @@ typedef struct {
898917
899918HL_API hl_track_info hl_track ;
900919
901- #else
920+ #else
902921
903922#define hl_is_tracking (_ ) false
904923#define hl_track_call (a ,b )
0 commit comments