Unnamed Fossil Project

Check-in [c84f04fc57]
Login

Check-in [c84f04fc57]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:updated
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c84f04fc575b27feb51499f959d882c2300c4a77
User & Date: alexey@sudachen.name 2012-03-25 21:39:41.000
Context
2012-04-04
10:37
'updated' check-in: 922d82ae97 user: alexey@sudachen.name tags: trunk
2012-03-25
21:39
updated check-in: c84f04fc57 user: alexey@sudachen.name tags: trunk
2012-03-20
03:31
updated check-in: 039942ee9d user: alexey@sudachen.name tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to yoyo.hc.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
in this Software without prior written authorization of the copyright holder.

*/

/*

  If using GNU bintools:
    
    Don't foget to use -rdynamic to see symbols in backtrace!

*/

#ifndef C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define YOYO_CORE_VERSION 1000







|







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
in this Software without prior written authorization of the copyright holder.

*/

/*

  If using GNU bintools:

    Don't foget to use -rdynamic to see symbols in backtrace!

*/

#ifndef C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C
#define YOYO_CORE_VERSION 1000
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#define __Acquire /* a function acquires the ownership of argument */

#if defined _MSC_VER
#define __No_Return __declspec(noreturn)
#elif defined __GNUC__
#define __No_Return __attribute__((noreturn))
#else
#define __No_Return 
#endif

#ifndef __yoTa
# define __yoTa(Text,NumId) Text
#endif

#define __FOUR_CHARS(C1,C2,C3,C4) ((uint_t)(C4)<<24)|((uint_t)(C3)<<16)|((uint_t)(C2)<<8)|((uint_t)(C1))







|







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#define __Acquire /* a function acquires the ownership of argument */

#if defined _MSC_VER
#define __No_Return __declspec(noreturn)
#elif defined __GNUC__
#define __No_Return __attribute__((noreturn))
#else
#define __No_Return
#endif

#ifndef __yoTa
# define __yoTa(Text,NumId) Text
#endif

#define __FOUR_CHARS(C1,C2,C3,C4) ((uint_t)(C4)<<24)|((uint_t)(C3)<<16)|((uint_t)(C2)<<8)|((uint_t)(C1))
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#  if !defined _X86_ && defined __i386
#   define _X86_ 1
#  endif
# endif
# if !defined WINVER
#  define WINVER 0x500
# endif

# include <windef.h>
# include <winsock2.h>
# include <winbase.h>
# include <excpt.h>
# include <objbase.h>
# include <io.h>
# include <process.h>
# include <malloc.h> /* alloca */
#else
# include <sys/time.h>
# include <unistd.h>
# include <dlfcn.h>
# ifdef _THREADS
#   include <pthreads.h>
# endif
# if defined __APPLE__
#   include <malloc/malloc.h> /* malloc_size */
# elif defined __NetBSD__
#   ifndef _NBSDMUTE
#     warning {! NetBSD has malloc_usable_size commented !}
#   endif
#   define malloc_size(Ptr) (0)
# else 
#   define malloc_size(Ptr) malloc_usable_size(Ptr)
# endif
#endif

#if defined __APPLE__ || defined __linux__
# include <execinfo.h> /* backtrace */
#elif defined __windoze







>

<




















|







127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#  if !defined _X86_ && defined __i386
#   define _X86_ 1
#  endif
# endif
# if !defined WINVER
#  define WINVER 0x500
# endif
# define WIN32_LEAN_AND_MEAN
# include <windef.h>

# include <winbase.h>
# include <excpt.h>
# include <objbase.h>
# include <io.h>
# include <process.h>
# include <malloc.h> /* alloca */
#else
# include <sys/time.h>
# include <unistd.h>
# include <dlfcn.h>
# ifdef _THREADS
#   include <pthreads.h>
# endif
# if defined __APPLE__
#   include <malloc/malloc.h> /* malloc_size */
# elif defined __NetBSD__
#   ifndef _NBSDMUTE
#     warning {! NetBSD has malloc_usable_size commented !}
#   endif
#   define malloc_size(Ptr) (0)
# else
#   define malloc_size(Ptr) malloc_usable_size(Ptr)
# endif
#endif

#if defined __APPLE__ || defined __linux__
# include <execinfo.h> /* backtrace */
#elif defined __windoze
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  typedef uint_t   halflong_t;  /* windows has 32-bit long always */
#else
  typedef ushort_t halflong_t;
#endif

/* maxint_t is max integer value supporting natively by CPU, depends on platform */
#ifdef __x86_64
  typedef uquad_t   umaxint_t; 
  typedef uint_t    halfumi_t; 
  typedef quad_t    maxint_t; 
  typedef int       halfmi_t; 
#else
  typedef ulong_t   umaxint_t; 
  typedef ushort_t  halfumi_t;
  typedef int       maxint_t;
  typedef short     halfmi_t;
#endif

/* longptr_t is unsigned integer value enough to store pointer value */
#ifdef __x86_64







|
|
|
|

|







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  typedef uint_t   halflong_t;  /* windows has 32-bit long always */
#else
  typedef ushort_t halflong_t;
#endif

/* maxint_t is max integer value supporting natively by CPU, depends on platform */
#ifdef __x86_64
  typedef uquad_t   umaxint_t;
  typedef uint_t    halfumi_t;
  typedef quad_t    maxint_t;
  typedef int       halfmi_t;
#else
  typedef ulong_t   umaxint_t;
  typedef ushort_t  halfumi_t;
  typedef int       maxint_t;
  typedef short     halfmi_t;
#endif

/* longptr_t is unsigned integer value enough to store pointer value */
#ifdef __x86_64
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#define YOYO_COMPOSE2(a,b) a##b
#define YOYO_COMPOSE3(a,b,c) a##b##_##c
#define YOYO_ID(Name,Line) YOYO_COMPOSE3(_YoYo_Label_,Name,Line)
#define YOYO_LOCAL_ID(Name) YOYO_ID(Name,__LINE__)

#ifdef _YOYO_CORE_BUILTIN
# define _YOYO_CORE_BUILTIN_CODE(Code) Code
# define _YOYO_CORE_EXTERN 
#else
# define _YOYO_CORE_BUILTIN_CODE(Code)
# define _YOYO_CORE_EXTERN extern 
#endif

#define Yo_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define Yo_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define Yo_ABS(a) ( (a) > 0 ? (a) : -(a) ) /* a > 0  does not produce warning on unsigned types */
#define Yo_ALIGNU(a,n) ( ((a) + ((n) - 1))&~((n) - 1) )








|


|







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#define YOYO_COMPOSE2(a,b) a##b
#define YOYO_COMPOSE3(a,b,c) a##b##_##c
#define YOYO_ID(Name,Line) YOYO_COMPOSE3(_YoYo_Label_,Name,Line)
#define YOYO_LOCAL_ID(Name) YOYO_ID(Name,__LINE__)

#ifdef _YOYO_CORE_BUILTIN
# define _YOYO_CORE_BUILTIN_CODE(Code) Code
# define _YOYO_CORE_EXTERN
#else
# define _YOYO_CORE_BUILTIN_CODE(Code)
# define _YOYO_CORE_EXTERN extern
#endif

#define Yo_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define Yo_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define Yo_ABS(a) ( (a) > 0 ? (a) : -(a) ) /* a > 0  does not produce warning on unsigned types */
#define Yo_ALIGNU(a,n) ( ((a) + ((n) - 1))&~((n) - 1) )

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    YOYO_RUNTIME_ERROR_GROUP        = 0x00080000,
    YOYO_SELFCHECK_ERROR_GROUP      = 0x00100000,
    YOYO_ENCODING_ERROR_GROUP       = 0x00200000,
    YOYO_ILLFORMED_ERROR_GROUP      = 0x00400000,
    YOYO_RANGE_ERROR_GROUP          = 0x00800000,
    YOYO_CORRUPTED_ERROR_GROUP      = 0x01000000,
    YOYO_STORAGE_ERROR_GROUP        = 0x02000000,
    
    YOYO_XXXX_ERROR_GROUP           = 0x7fff0000,
    YO_RERAISE_CURRENT_ERROR        = 0x7fff7fff,
    
    YOYO_TRACED_ERROR_GROUP     = YOYO_FATAL_ERROR_GROUP
                                |YOYO_RANGE_ERROR_GROUP
                                |YOYO_SELFCHECK_ERROR_GROUP,
    
    YOYO_ERROR_BASE             = 0x00008000,
    YOYO_ERROR_USER             = YOYO_USER_ERROR_GROUP|0,
    
    YOYO_ERROR_OUT_OF_MEMORY    = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+1),
    YOYO_FATAL_ERROR            = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+2),
    YOYO_ERROR_DYNCO_CORRUPTED  = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+3),
    YOYO_ERROR_METHOD_NOT_FOUND = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+4),
    YOYO_ERROR_REQUIRE_FAILED   = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+5),
    YOYO_ERROR_ILLFORMED        = YOYO_ILLFORMED_ERROR_GROUP|(YOYO_ERROR_BASE+6),
    YOYO_ERROR_OUT_OF_POOL      = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+7),







|


|



|


|







324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
    YOYO_RUNTIME_ERROR_GROUP        = 0x00080000,
    YOYO_SELFCHECK_ERROR_GROUP      = 0x00100000,
    YOYO_ENCODING_ERROR_GROUP       = 0x00200000,
    YOYO_ILLFORMED_ERROR_GROUP      = 0x00400000,
    YOYO_RANGE_ERROR_GROUP          = 0x00800000,
    YOYO_CORRUPTED_ERROR_GROUP      = 0x01000000,
    YOYO_STORAGE_ERROR_GROUP        = 0x02000000,

    YOYO_XXXX_ERROR_GROUP           = 0x7fff0000,
    YO_RERAISE_CURRENT_ERROR        = 0x7fff7fff,

    YOYO_TRACED_ERROR_GROUP     = YOYO_FATAL_ERROR_GROUP
                                |YOYO_RANGE_ERROR_GROUP
                                |YOYO_SELFCHECK_ERROR_GROUP,

    YOYO_ERROR_BASE             = 0x00008000,
    YOYO_ERROR_USER             = YOYO_USER_ERROR_GROUP|0,

    YOYO_ERROR_OUT_OF_MEMORY    = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+1),
    YOYO_FATAL_ERROR            = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+2),
    YOYO_ERROR_DYNCO_CORRUPTED  = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+3),
    YOYO_ERROR_METHOD_NOT_FOUND = YOYO_RUNTIME_ERROR_GROUP|(YOYO_ERROR_BASE+4),
    YOYO_ERROR_REQUIRE_FAILED   = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+5),
    YOYO_ERROR_ILLFORMED        = YOYO_ILLFORMED_ERROR_GROUP|(YOYO_ERROR_BASE+6),
    YOYO_ERROR_OUT_OF_POOL      = YOYO_FATAL_ERROR_GROUP|(YOYO_ERROR_BASE+7),
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# define Yo_Tls_Get(Name)     (Name)

# define YO_MULTITHREADED(Expr)

# define __Xchg_Interlock if (0) {;} else
# define __Xchg_Sync(Lx)  if (0) {;} else
# define Yo_Wait_Xchg_Lock(Ptr)
# define Yo_Xchg_Unlock(Ptr)  

# define __Mtx_Sync(Mtx)  if (0) {;} else

#else /* -D _THREADS */

#ifdef __windoze
#else







|







398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# define Yo_Tls_Get(Name)     (Name)

# define YO_MULTITHREADED(Expr)

# define __Xchg_Interlock if (0) {;} else
# define __Xchg_Sync(Lx)  if (0) {;} else
# define Yo_Wait_Xchg_Lock(Ptr)
# define Yo_Xchg_Unlock(Ptr)

# define __Mtx_Sync(Mtx)  if (0) {;} else

#else /* -D _THREADS */

#ifdef __windoze
#else
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466

#if defined __i386 || defined __x86_64
#define Eight_To_Quad(Eight)  (*(quad_t*)(Eight))
#else
quad_t Eight_To_Quad(void *b)
#ifdef _YOYO_CORE_BUILTIN
  {
    uint_t q0,q1;    
    q0 =   (unsigned int)((unsigned char*)b)[0]
              | ((unsigned int)((unsigned char*)b)[1] << 8)
              | ((unsigned int)((unsigned char*)b)[2] << 16)
              | ((unsigned int)((unsigned char*)b)[3] << 24);
    b = (char*b)+4;
    q1 =   (unsigned int)((unsigned char*)b)[0]
              | ((unsigned int)((unsigned char*)b)[1] << 8)







|







452
453
454
455
456
457
458
459
460
461
462
463
464
465
466

#if defined __i386 || defined __x86_64
#define Eight_To_Quad(Eight)  (*(quad_t*)(Eight))
#else
quad_t Eight_To_Quad(void *b)
#ifdef _YOYO_CORE_BUILTIN
  {
    uint_t q0,q1;
    q0 =   (unsigned int)((unsigned char*)b)[0]
              | ((unsigned int)((unsigned char*)b)[1] << 8)
              | ((unsigned int)((unsigned char*)b)[2] << 16)
              | ((unsigned int)((unsigned char*)b)[3] << 24);
    b = (char*b)+4;
    q1 =   (unsigned int)((unsigned char*)b)[0]
              | ((unsigned int)((unsigned char*)b)[1] << 8)
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619

_YOYO_CORE_EXTERN byte_t Bitcount_8_Q[]
#ifdef _YOYO_CORE_BUILTIN
= {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
   6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
   6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
#endif
 ;

#define Bitcount_8(q) (Bitcount_8_Q[(q)&0x0ff])  
uint_t Bitcount_Of( uint_t u )
#ifdef _YOYO_CORE_BUILTIN
    {
      int i;
      uint_t q;
      if ( u )
        for ( i = sizeof(u)*8-8; i >= 0; i-=8 )
          if ( !!(q = Bitcount_8(u>>i)) )
            return q+i;
      return 0;
    }
#endif
  ;

uint_t Min_Pow2(uint_t a)
#ifdef _YOYO_CORE_BUILTIN
  {
    if ( a ) --a; 
    return 1<<Bitcount_Of(a);
  }
#endif
  ;

int Yo_Mini(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
int Yo_Maxi(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });







|

|



|



|




|

















|







572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619

_YOYO_CORE_EXTERN byte_t Bitcount_8_Q[]
#ifdef _YOYO_CORE_BUILTIN
= {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
   5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
   6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
   6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
   8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
#endif
 ;

#define Bitcount_8(q) (Bitcount_8_Q[(q)&0x0ff])
uint_t Bitcount_Of( uint_t u )
#ifdef _YOYO_CORE_BUILTIN
    {
      int i;
      uint_t q;
      if ( u )
        for ( i = sizeof(u)*8-8; i >= 0; i-=8 )
          if ( !!(q = Bitcount_8(u>>i)) )
            return q+i;
      return 0;
    }
#endif
  ;

uint_t Min_Pow2(uint_t a)
#ifdef _YOYO_CORE_BUILTIN
  {
    if ( a ) --a;
    return 1<<Bitcount_Of(a);
  }
#endif
  ;

int Yo_Mini(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MIN(a,b); });
int Yo_Maxi(int a, int b) _YOYO_CORE_BUILTIN_CODE({ return Yo_MAX(a,b); });
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
  {
    void *p = Yo_Malloc_Npl(size);
    memset(p,0,size);
    return p;
  }
#endif
  ;
  
void *Yo_Resize_Npl(void *p,int size,int granularity)
#ifdef _YOYO_CORE_BUILTIN
  {
    int capacity = p?malloc_size(p):0;
    STRICT_REQUIRE(size >= 0);
    if ( !p || capacity < size )
      {







|







666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
  {
    void *p = Yo_Malloc_Npl(size);
    memset(p,0,size);
    return p;
  }
#endif
  ;

void *Yo_Resize_Npl(void *p,int size,int granularity)
#ifdef _YOYO_CORE_BUILTIN
  {
    int capacity = p?malloc_size(p):0;
    STRICT_REQUIRE(size >= 0);
    if ( !p || capacity < size )
      {
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
#endif
  ;

YOYO_C_SUPPORT_INFO *Yo_Extend_Csup_JmpBuf()
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    nfo = Yo_Realloc_Npl(nfo,sizeof(YOYO_C_SUPPORT_INFO) 
              + (nfo->jb_count - YOYO_INI_JB_COUNT + YOYO_EXT_JB_COUNT)*sizeof(YOYO_JMPBUF));
    nfo->jb_count += YOYO_EXT_JB_COUNT;
    Yo_Tls_Set(Yo_Csup_Nfo_Tls,nfo);
    return nfo;
  }
#endif
  ;

void Yo_Extend_Csup_Autopool()
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    uint_t ncount = nfo->auto_count + YOYO_EXT_POOL_COUNT; 
    nfo->auto_pool = Yo_Realloc_Npl(nfo->auto_pool,sizeof(*nfo->auto_pool)*ncount);
    nfo->auto_count = ncount;
    //nfo->auto_top = ncount;
  }
#endif
  ;

void Yo_Pool_Marker_Tag(void *o) _YOYO_CORE_BUILTIN_CODE({});


YOYO_AUTORELEASE *Yo_Find_Ptr_In_Pool(YOYO_C_SUPPORT_INFO *nfo, void *p)
#ifdef _YOYO_CORE_BUILTIN  
  {
    int n = nfo->auto_top;
    while ( n >= 0 )
      {
        if ( nfo->auto_pool[n].ptr == p )
          return &nfo->auto_pool[n];
        --n;
      }
    return 0;
  }
#endif
  ;
  
#define Yo_Push_Scope() Yo_Pool_Ptr(0,Yo_Pool_Marker_Tag)
#define Yo_Pool(Ptr) Yo_Pool_Ptr(Ptr,0)

void *Yo_Unrefe(void *p);
void *Yo_Pool_Ptr(void *ptr,void *cleanup)
#ifdef _YOYO_CORE_BUILTIN
  {
    if ( ptr || cleanup == Yo_Pool_Marker_Tag )
      {
        YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
        if ( !nfo ) nfo = Yo_Acquire_Csup_Nfo();
        STRICT_REQUIRE( (cleanup == Yo_Pool_Marker_Tag)
                      ||(cleanup == Yo_Unrefe) 
                      ||!Yo_Find_Ptr_In_Pool(nfo,ptr) );

        ++nfo->auto_top;
        STRICT_REQUIRE(nfo->auto_top <= nfo->auto_count);
        
        if ( nfo->auto_top == nfo->auto_count )
          Yo_Extend_Csup_Autopool();
        nfo->auto_pool[nfo->auto_top].ptr = ptr;
        nfo->auto_pool[nfo->auto_top].cleanup = cleanup?cleanup:free; 
      }
    return ptr;
  }
#endif
  ;
  
#define Yo_Release(Pooled) ((void)Yo_Unpool((Pooled),1))
#define Yo_Retain(Pooled) Yo_Unpool((Pooled),0)

void *Yo_Unpool(void *pooled,int do_cleanup)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && pooled )
      {
        int n = nfo->auto_top;
        while ( n >= 0 )
          {
            if ( nfo->auto_pool[n].ptr == pooled )
              {
                YOYO_AUTORELEASE *q = &nfo->auto_pool[n];
                if ( do_cleanup && q->ptr ) q->cleanup(q->ptr);
                
                if ( nfo->jb_top < 0 || nfo->jb[nfo->jb_top].auto_top < n )
                  {
                    if ( nfo->auto_top != n )
                        memmove(nfo->auto_pool+n,nfo->auto_pool+n+1,(nfo->auto_top-n)*sizeof(*q));
                    --nfo->auto_top;
                  }
                else
                  {
                    q->ptr = 0;
                    q->cleanup = 0;
                  }
                
                break; // while
              }
            --n;
          }
      }
    return pooled;
  }







|












|











|












|












|




|



|





|
















|











|







797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
#endif
  ;

YOYO_C_SUPPORT_INFO *Yo_Extend_Csup_JmpBuf()
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    nfo = Yo_Realloc_Npl(nfo,sizeof(YOYO_C_SUPPORT_INFO)
              + (nfo->jb_count - YOYO_INI_JB_COUNT + YOYO_EXT_JB_COUNT)*sizeof(YOYO_JMPBUF));
    nfo->jb_count += YOYO_EXT_JB_COUNT;
    Yo_Tls_Set(Yo_Csup_Nfo_Tls,nfo);
    return nfo;
  }
#endif
  ;

void Yo_Extend_Csup_Autopool()
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    uint_t ncount = nfo->auto_count + YOYO_EXT_POOL_COUNT;
    nfo->auto_pool = Yo_Realloc_Npl(nfo->auto_pool,sizeof(*nfo->auto_pool)*ncount);
    nfo->auto_count = ncount;
    //nfo->auto_top = ncount;
  }
#endif
  ;

void Yo_Pool_Marker_Tag(void *o) _YOYO_CORE_BUILTIN_CODE({});


YOYO_AUTORELEASE *Yo_Find_Ptr_In_Pool(YOYO_C_SUPPORT_INFO *nfo, void *p)
#ifdef _YOYO_CORE_BUILTIN
  {
    int n = nfo->auto_top;
    while ( n >= 0 )
      {
        if ( nfo->auto_pool[n].ptr == p )
          return &nfo->auto_pool[n];
        --n;
      }
    return 0;
  }
#endif
  ;

#define Yo_Push_Scope() Yo_Pool_Ptr(0,Yo_Pool_Marker_Tag)
#define Yo_Pool(Ptr) Yo_Pool_Ptr(Ptr,0)

void *Yo_Unrefe(void *p);
void *Yo_Pool_Ptr(void *ptr,void *cleanup)
#ifdef _YOYO_CORE_BUILTIN
  {
    if ( ptr || cleanup == Yo_Pool_Marker_Tag )
      {
        YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
        if ( !nfo ) nfo = Yo_Acquire_Csup_Nfo();
        STRICT_REQUIRE( (cleanup == Yo_Pool_Marker_Tag)
                      ||(cleanup == Yo_Unrefe)
                      ||!Yo_Find_Ptr_In_Pool(nfo,ptr) );

        ++nfo->auto_top;
        STRICT_REQUIRE(nfo->auto_top <= nfo->auto_count);

        if ( nfo->auto_top == nfo->auto_count )
          Yo_Extend_Csup_Autopool();
        nfo->auto_pool[nfo->auto_top].ptr = ptr;
        nfo->auto_pool[nfo->auto_top].cleanup = cleanup?cleanup:free;
      }
    return ptr;
  }
#endif
  ;

#define Yo_Release(Pooled) ((void)Yo_Unpool((Pooled),1))
#define Yo_Retain(Pooled) Yo_Unpool((Pooled),0)

void *Yo_Unpool(void *pooled,int do_cleanup)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && pooled )
      {
        int n = nfo->auto_top;
        while ( n >= 0 )
          {
            if ( nfo->auto_pool[n].ptr == pooled )
              {
                YOYO_AUTORELEASE *q = &nfo->auto_pool[n];
                if ( do_cleanup && q->ptr ) q->cleanup(q->ptr);

                if ( nfo->jb_top < 0 || nfo->jb[nfo->jb_top].auto_top < n )
                  {
                    if ( nfo->auto_top != n )
                        memmove(nfo->auto_pool+n,nfo->auto_pool+n+1,(nfo->auto_top-n)*sizeof(*q));
                    --nfo->auto_top;
                  }
                else
                  {
                    q->ptr = 0;
                    q->cleanup = 0;
                  }

                break; // while
              }
            --n;
          }
      }
    return pooled;
  }
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
          {
            YOYO_AUTORELEASE *q = &nfo->auto_pool[nfo->auto_top];
            STRICT_REQUIRE(nfo->auto_top <= nfo->auto_count);
            //printf("ptr: %p, cleanup: %p ?= pooled: %p, mark: %p\n", q->ptr, q->cleanup, pooled, mark);
            if ( q->ptr && (q->cleanup != Yo_Pool_Marker_Tag) )
              {
                if ( !pooled || q->ptr != pooled )
                  { 
                    q->cleanup(q->ptr);
                    //++counter;
                  }
                else
                  q_p = q;
              }
            --nfo->auto_top;







|







921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
          {
            YOYO_AUTORELEASE *q = &nfo->auto_pool[nfo->auto_top];
            STRICT_REQUIRE(nfo->auto_top <= nfo->auto_count);
            //printf("ptr: %p, cleanup: %p ?= pooled: %p, mark: %p\n", q->ptr, q->cleanup, pooled, mark);
            if ( q->ptr && (q->cleanup != Yo_Pool_Marker_Tag) )
              {
                if ( !pooled || q->ptr != pooled )
                  {
                    q->cleanup(q->ptr);
                    //++counter;
                  }
                else
                  q_p = q;
              }
            --nfo->auto_top;
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
        nfo->stats.unwinding = 0;
      }
    //printf("unwind: released %d ptrs, still pooled %d ptrs\n",counter,nfo->auto_top+1);
    return pooled;
  }
#endif
  ;
  
#define Yo_Refresh(Old,New) Yo_Refresh_Ptr(Old,New,0)
void *Yo_Refresh_Ptr(void *old,void *new,void *cleaner)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo;
    REQUIRE( new != 0 );
    if ( old && !!(nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls)) )







|







945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
        nfo->stats.unwinding = 0;
      }
    //printf("unwind: released %d ptrs, still pooled %d ptrs\n",counter,nfo->auto_top+1);
    return pooled;
  }
#endif
  ;

#define Yo_Refresh(Old,New) Yo_Refresh_Ptr(Old,New,0)
void *Yo_Refresh_Ptr(void *old,void *new,void *cleaner)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo;
    REQUIRE( new != 0 );
    if ( old && !!(nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls)) )
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
      Yo_Refresh(p,q);
    else if ( !p )
      Yo_Pool(q);
    return q;
  }
#endif
  ;
  
#if defined _YOYO_CORE_BUILTIN && defined __windoze && defined __VSCPRINTF
int _vscprintf(char *fmt,va_list va)
  {
    static char simulate[4096*4] = {0};
    return vsprintf(simulate,fmt,va);
  }
#endif
  
  
int Yo_Detect_Required_Buffer_Size(char *fmt,va_list va)
#ifdef _YOYO_CORE_BUILTIN
  {
  #ifdef __windoze
    return _vscprintf(fmt,va)+1;
  #else
    va_list qva;







|







|
|







1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
      Yo_Refresh(p,q);
    else if ( !p )
      Yo_Pool(q);
    return q;
  }
#endif
  ;

#if defined _YOYO_CORE_BUILTIN && defined __windoze && defined __VSCPRINTF
int _vscprintf(char *fmt,va_list va)
  {
    static char simulate[4096*4] = {0};
    return vsprintf(simulate,fmt,va);
  }
#endif


int Yo_Detect_Required_Buffer_Size(char *fmt,va_list va)
#ifdef _YOYO_CORE_BUILTIN
  {
  #ifdef __windoze
    return _vscprintf(fmt,va)+1;
  #else
    va_list qva;
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
    return b;
  }
#endif
  ;

char *Yo_Format_Npl(char *fmt,...)
  _YOYO_CORE_BUILTIN_CODE({va_list va;char *t; va_start(va,fmt); t = Yo_Format_(fmt,va);va_end(va); return t;});
  
char *Yo_Format(char *fmt,...) 
  _YOYO_CORE_BUILTIN_CODE({va_list va;char *t; va_start(va,fmt); t = Yo_Pool(Yo_Format_(fmt,va));va_end(va); return t;});
  
void Yo_Print_FILE(FILE *st, char *text, unsigned flags)
#ifdef _YOYO_CORE_BUILTIN
  {
    __Xchg_Interlock
      {
        fputs(text,st);
        if ( flags & YO_PRINT_NEWLINE ) fputc('\n',st);







|
|

|







1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
    return b;
  }
#endif
  ;

char *Yo_Format_Npl(char *fmt,...)
  _YOYO_CORE_BUILTIN_CODE({va_list va;char *t; va_start(va,fmt); t = Yo_Format_(fmt,va);va_end(va); return t;});

char *Yo_Format(char *fmt,...)
  _YOYO_CORE_BUILTIN_CODE({va_list va;char *t; va_start(va,fmt); t = Yo_Pool(Yo_Format_(fmt,va));va_end(va); return t;});

void Yo_Print_FILE(FILE *st, char *text, unsigned flags)
#ifdef _YOYO_CORE_BUILTIN
  {
    __Xchg_Interlock
      {
        fputs(text,st);
        if ( flags & YO_PRINT_NEWLINE ) fputc('\n',st);
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
void *Yo_Object_Extend( void *o, char *func_name, void *func )
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_OBJECT *T = YOYO_BASE(o);
    YOYO_FUNCTABLE *f;
    if ( !T )
      Yo_Raise(YOYO_ERROR_NULL_PTR,__yoTa("failed to extend nullptr",0),__Yo_FILE__,__LINE__);
    
    if ( T->dynamic )
      {
        if ( (T->dynamic->contsig >> 8) == YOYO_DYNCO_ATS )
          T->dynamic = Yo_Clone_Dynamic(T->dynamic,1);
        else
          T->dynamic = Yo_Extend_Dynamic(T->dynamic,1);
      }
    else
      {
        T->dynamic = Yo_Malloc_Npl(sizeof(YOYO_DYNAMIC));
        T->dynamic->contsig = YOYO_DYNCO_NYD<<8;
      }
      
    T->dynamic->typeid = Yo_Atomic_Increment(&Yo_Typeid_Counter);
    f = T->dynamic->funcs+(T->dynamic->contsig&0x0ff);
    ++T->dynamic->contsig;
    f->name = func_name;
    f->func = func;
    
    return o;
  }
#endif
  ;

enum { YOYO_OBJECT_SIGNATURE =  0x4f594f59 /*'YOYO'*/  }; 

void *Yo_Object_Clone(int size, void *orign)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_OBJECT *o;
    YOYO_OBJECT *T = YOYO_BASE(orign);
    if ( !T )
      Yo_Raise(YOYO_ERROR_NULL_PTR,__yoTa("failed to clone nullptr",0),__Yo_FILE__,__LINE__);
    
    o = Yo_Malloc_Npl(sizeof(YOYO_OBJECT)+size);
    o->signature = YOYO_OBJECT_SIGNATURE;
    o->rc = 1;
    memcpy(o+1,orign,size);
    
    if ( T->dynamic )
      {
        if ( (T->dynamic->contsig>>8) == YOYO_DYNCO_ATS )
          o->dynamic = T->dynamic;
        else
          {
            STRICT_REQUIRE( (T->dynamic->contsig>>8) == YOYO_DYNCO_NYD );
            o->dynamic = Yo_Clone_Dynamic(T->dynamic,0);
          }
      }
    else
      o->dynamic = 0;
    
    return Yo_Pool_Ptr(o+1,Yo_Unrefe);
  }
#endif
  ;

void *Yo_Object(int size,YOYO_FUNCTABLE *tbl)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_OBJECT *o = Yo_Zero_Malloc_Npl(sizeof(YOYO_OBJECT)+size);
    o->signature = YOYO_OBJECT_SIGNATURE;
    o->rc = 1;
    o->dynamic = (YOYO_DYNAMIC*)tbl;
    
    if ( tbl )
      {__Xchg_Interlock
        {
          YOYO_DYNAMIC *dynco = (YOYO_DYNAMIC*)tbl;
          if ( !dynco->contsig )
            {
              int count;







|












|





|





|








|




|












|












|







1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
void *Yo_Object_Extend( void *o, char *func_name, void *func )
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_OBJECT *T = YOYO_BASE(o);
    YOYO_FUNCTABLE *f;
    if ( !T )
      Yo_Raise(YOYO_ERROR_NULL_PTR,__yoTa("failed to extend nullptr",0),__Yo_FILE__,__LINE__);

    if ( T->dynamic )
      {
        if ( (T->dynamic->contsig >> 8) == YOYO_DYNCO_ATS )
          T->dynamic = Yo_Clone_Dynamic(T->dynamic,1);
        else
          T->dynamic = Yo_Extend_Dynamic(T->dynamic,1);
      }
    else
      {
        T->dynamic = Yo_Malloc_Npl(sizeof(YOYO_DYNAMIC));
        T->dynamic->contsig = YOYO_DYNCO_NYD<<8;
      }

    T->dynamic->typeid = Yo_Atomic_Increment(&Yo_Typeid_Counter);
    f = T->dynamic->funcs+(T->dynamic->contsig&0x0ff);
    ++T->dynamic->contsig;
    f->name = func_name;
    f->func = func;

    return o;
  }
#endif
  ;

enum { YOYO_OBJECT_SIGNATURE =  0x4f594f59 /*'YOYO'*/  };

void *Yo_Object_Clone(int size, void *orign)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_OBJECT *o;
    YOYO_OBJECT *T = YOYO_BASE(orign);
    if ( !T )
      Yo_Raise(YOYO_ERROR_NULL_PTR,__yoTa("failed to clone nullptr",0),__Yo_FILE__,__LINE__);

    o = Yo_Malloc_Npl(sizeof(YOYO_OBJECT)+size);
    o->signature = YOYO_OBJECT_SIGNATURE;
    o->rc = 1;
    memcpy(o+1,orign,size);

    if ( T->dynamic )
      {
        if ( (T->dynamic->contsig>>8) == YOYO_DYNCO_ATS )
          o->dynamic = T->dynamic;
        else
          {
            STRICT_REQUIRE( (T->dynamic->contsig>>8) == YOYO_DYNCO_NYD );
            o->dynamic = Yo_Clone_Dynamic(T->dynamic,0);
          }
      }
    else
      o->dynamic = 0;

    return Yo_Pool_Ptr(o+1,Yo_Unrefe);
  }
#endif
  ;

void *Yo_Object(int size,YOYO_FUNCTABLE *tbl)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_OBJECT *o = Yo_Zero_Malloc_Npl(sizeof(YOYO_OBJECT)+size);
    o->signature = YOYO_OBJECT_SIGNATURE;
    o->rc = 1;
    o->dynamic = (YOYO_DYNAMIC*)tbl;

    if ( tbl )
      {__Xchg_Interlock
        {
          YOYO_DYNAMIC *dynco = (YOYO_DYNAMIC*)tbl;
          if ( !dynco->contsig )
            {
              int count;
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
    return (val + 7)&~7;
  }
#endif
  ;

void *Yo_Object_Dtor(int size,void *dtor)
#ifdef _YOYO_CORE_BUILTIN
  {  
    int Sz = Yo_Align(sizeof(YOYO_OBJECT)+size);
    YOYO_OBJECT *o = Yo_Malloc_Npl(Sz+sizeof(YOYO_DYNAMIC));
    memset(o,0,Sz+sizeof(YOYO_DYNAMIC));
    o->signature = YOYO_OBJECT_SIGNATURE;
    o->rc = 1;
    o->dynamic = (YOYO_DYNAMIC*)((char*)o + Sz);
    o->dynamic->contsig = (YOYO_DYNCO_ATS<<8)|1;







|







1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
    return (val + 7)&~7;
  }
#endif
  ;

void *Yo_Object_Dtor(int size,void *dtor)
#ifdef _YOYO_CORE_BUILTIN
  {
    int Sz = Yo_Align(sizeof(YOYO_OBJECT)+size);
    YOYO_OBJECT *o = Yo_Malloc_Npl(Sz+sizeof(YOYO_DYNAMIC));
    memset(o,0,Sz+sizeof(YOYO_DYNAMIC));
    o->signature = YOYO_OBJECT_SIGNATURE;
    o->rc = 1;
    o->dynamic = (YOYO_DYNAMIC*)((char*)o + Sz);
    o->dynamic->contsig = (YOYO_DYNCO_ATS<<8)|1;
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
                if ( !f && (flags & YO_RAISE_ERROR) )
                  Yo_Raise(YOYO_ERROR_METHOD_NOT_FOUND,name,__Yo_FILE__,__LINE__);
                return f;
              }
            else
              Yo_Fatal(YOYO_ERROR_DYNCO_CORRUPTED,o,__Yo_FILE__,__LINE__);
          }
        else if (flags & YO_RAISE_ERROR) 
          Yo_Raise(YOYO_ERROR_METHOD_NOT_FOUND,name,__Yo_FILE__,__LINE__);
      }
    else if (flags & YO_RAISE_ERROR)
      Yo_Raise(YOYO_ERROR_METHOD_NOT_FOUND,name,__Yo_FILE__,__LINE__);
    return 0;
  }
#endif
  ;
  
void *Yo_Refe(void *p)
#ifdef _YOYO_CORE_BUILTIN
  {
    if ( p && STRICT_CHECK(YOYO_SIGNAT_IS_OK(p)) )
      Yo_Atomic_Increment(&YOYO_RC(p));
    return p;
  }
#endif
  ;

#ifdef _YOYO_CORE_BUILTIN
void *Yo_Unrefe(void *p)
  {
    if ( p && STRICT_CHECK(YOYO_SIGNAT_IS_OK(p)) 
           && !(Yo_Atomic_Decrement(&YOYO_RC(p))&0x7fffff) )
      {
        void (*destruct)(void *) = Yo_Find_Method_Of(&p,Oj_Destruct_OjMID,0);
        if ( !destruct )
          Yo_Object_Destruct(p);
        else
          destruct(p);







|








|













|







1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
                if ( !f && (flags & YO_RAISE_ERROR) )
                  Yo_Raise(YOYO_ERROR_METHOD_NOT_FOUND,name,__Yo_FILE__,__LINE__);
                return f;
              }
            else
              Yo_Fatal(YOYO_ERROR_DYNCO_CORRUPTED,o,__Yo_FILE__,__LINE__);
          }
        else if (flags & YO_RAISE_ERROR)
          Yo_Raise(YOYO_ERROR_METHOD_NOT_FOUND,name,__Yo_FILE__,__LINE__);
      }
    else if (flags & YO_RAISE_ERROR)
      Yo_Raise(YOYO_ERROR_METHOD_NOT_FOUND,name,__Yo_FILE__,__LINE__);
    return 0;
  }
#endif
  ;

void *Yo_Refe(void *p)
#ifdef _YOYO_CORE_BUILTIN
  {
    if ( p && STRICT_CHECK(YOYO_SIGNAT_IS_OK(p)) )
      Yo_Atomic_Increment(&YOYO_RC(p));
    return p;
  }
#endif
  ;

#ifdef _YOYO_CORE_BUILTIN
void *Yo_Unrefe(void *p)
  {
    if ( p && STRICT_CHECK(YOYO_SIGNAT_IS_OK(p))
           && !(Yo_Atomic_Decrement(&YOYO_RC(p))&0x7fffff) )
      {
        void (*destruct)(void *) = Yo_Find_Method_Of(&p,Oj_Destruct_OjMID,0);
        if ( !destruct )
          Yo_Object_Destruct(p);
        else
          destruct(p);
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
      case (Code):

#define __Except /* using with __Try_Except */ \
    else /* else branch of guards if */ \
      default:

YOYO_ERROR_INFO *Error_Info()
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && nfo->err.code )
      return &nfo->err;
    else
      return 0;
  }
#endif
  ;
  
char *Error_Message(void) 
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info && info->msg )
      return info->msg;
    return "";
  }
#endif
  ;

int Error_Code(void) 
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info )
      return info->code;
    return 0;
  }
#endif
  ;

char *Error_File(void) 
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info && info->filename )
      return info->filename;
    return __yoTa("<file>",0);
  }
#endif
  ;

int Error_Line(void) 
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info )
      return info->lineno;
    return 0;
  }
#endif
  ;

char *Error_Print_N_Exit(char *prefix, int code) 
#ifdef _YOYO_CORE_BUILTIN  
  {
    StdErr_Print_Nl(Yo_Format(__yoTa("%s: %s",0),prefix,Error_Message()));
    exit(code);
  }
#endif
  ;

#define Yo_Pop_JmpBuf() \
   (--((YOYO_C_SUPPORT_INFO *)Yo_Tls_Get(Yo_Csup_Nfo_Tls))->jb_top)

YOYO_JMPBUF *Yo_Push_JmpBuf(void)
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_C_Support_Nfo();
    YOYO_JMPBUF *jb;
    
    STRICT_REQUIRE(nfo->jb_top < nfo->jb_count);
    STRICT_REQUIRE(nfo->jb_top >= -1);
    
    if ( nfo->jb_top == nfo->jb_count-1 ) 
      nfo = Yo_Extend_Csup_JmpBuf();
    ++nfo->jb_top;

    jb = &nfo->jb[nfo->jb_top];
    memset(jb->locks,0,sizeof(jb->locks));
    jb->auto_top = nfo->auto_top+1;
    
    return jb;
  }
#endif
  ;

void Yo_JmpBuf_Push_Cs(void *cs,Yo_JMPBUF_Unlock unlock)
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    STRICT_REQUIRE ( cs );
    if ( nfo && cs )
      {
        STRICT_REQUIRE(nfo->jb_top < nfo->jb_count);
        STRICT_REQUIRE(nfo->jb_top >= -1);
        if ( nfo->jb_top > -1 && !nfo->stats.unwinding )
          {
            int i;
            YOYO_JMPBUF_LOCK *locks = nfo->jb[nfo->jb_top].locks;
            for ( i = YOYO_MAX_CS_COUNT-1; i >= 0; --i ) 
              if ( !locks[i].cs )
                {
                  locks[i].cs = cs;
                  locks[i].unlock = unlock;
                  return;
                }
            Yo_Fatal(YOYO_FATAL_ERROR,__yoTa("no enough lock space",0),__Yo_FILE__,__LINE__);
          }
      }
  }
#endif
  ;

  
void Yo_JmpBuf_Pop_Cs(void *cs)
#ifdef _YOYO_CORE_BUILTIN  
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && cs )
      {
        STRICT_REQUIRE(nfo->jb_top < nfo->jb_count);
        STRICT_REQUIRE(nfo->jb_top >= -1);
        if ( nfo->jb_top > -1 && !nfo->stats.unwinding )
          { 
            int i;
            YOYO_JMPBUF_LOCK *locks = nfo->jb[nfo->jb_top].locks;
            for ( i = YOYO_MAX_CS_COUNT-1; i >= 0; --i ) 
              if ( locks[i].cs == cs )
                {
                  memset(&locks[i],0,sizeof(locks[i]));
                  return;
                }
            Yo_Fatal(YOYO_FATAL_ERROR,__yoTa("trying to pop unexistent lock",0),__Yo_FILE__,__LINE__);
          }
      }
  }
#endif
  ;
  
char *Yo_Btrace(void);

#ifdef _YOYO_CORE_BUILTIN
__No_Return void _Yo_Raise(int err,char *msg,char *filename,int lineno)
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    STRICT_REQUIRE( !nfo || nfo->jb_top < nfo->jb_count );
    
    printf(__yoTa("err: %d, msg: %s, filename: %s, lineno: %d\n",0),err,msg,filename,lineno);
    
    if ( err == YO_RERAISE_CURRENT_ERROR && (!nfo || !nfo->err.code) )
      Yo_Fatal(YOYO_ERROR_UNEXPECTED,__yoTa("no errors occured yet",0),filename,lineno);
    
    if ( nfo && nfo->jb_top >= 0 && !nfo->stats.unwinding )
      {
        int i; 
        char *old_msg = nfo->err.msg;
        YOYO_JMPBUF_LOCK *locks = nfo->jb[nfo->jb_top].locks;
        
        if ( err != YO_RERAISE_CURRENT_ERROR )
          {
            nfo->err.msg = msg ? strdup(msg) : 0;
            nfo->err.code = err?err:-1;
            nfo->err.filename = filename;
            nfo->err.lineno = lineno;
            nfo->err.bt_count = backtrace(nfo->err.bt_cbk,YOYO_MAX_ERROR_BTRACE);
            free( old_msg );
          }
          
        for ( i = YOYO_MAX_CS_COUNT-1; i >= 0; --i ) 
          if (  locks[i].cs ) 
            locks[i].unlock(locks[i].cs);
        
        Yo_Unwind_Scope(0,nfo->jb[nfo->jb_top].auto_top,0);
        
        --nfo->jb_top;
        STRICT_REQUIRE(nfo->jb_top >= -1);
        
      #ifdef _TRACEXPT
        StdErr_Print_Nl(Yo_Btrace());
      #endif  
        longjmp(nfo->jb[nfo->jb_top+1].b,err?err:-1);
      }
    else
      {
        if ( err != YO_RERAISE_CURRENT_ERROR )
          Yo_Fatal(err,msg,filename,lineno);
        else







|









|
|
|









|
|









|
|









|
|









|
|











|



|


|
|






|






|











|













|

|







|


|











|







|

|


|


|


|









|
|
|

|

|


|


|







1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
      case (Code):

#define __Except /* using with __Try_Except */ \
    else /* else branch of guards if */ \
      default:

YOYO_ERROR_INFO *Error_Info()
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && nfo->err.code )
      return &nfo->err;
    else
      return 0;
  }
#endif
  ;

char *Error_Message(void)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info && info->msg )
      return info->msg;
    return "";
  }
#endif
  ;

int Error_Code(void)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info )
      return info->code;
    return 0;
  }
#endif
  ;

char *Error_File(void)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info && info->filename )
      return info->filename;
    return __yoTa("<file>",0);
  }
#endif
  ;

int Error_Line(void)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_ERROR_INFO *info = Error_Info();
    if ( info )
      return info->lineno;
    return 0;
  }
#endif
  ;

char *Error_Print_N_Exit(char *prefix, int code)
#ifdef _YOYO_CORE_BUILTIN
  {
    StdErr_Print_Nl(Yo_Format(__yoTa("%s: %s",0),prefix,Error_Message()));
    exit(code);
  }
#endif
  ;

#define Yo_Pop_JmpBuf() \
   (--((YOYO_C_SUPPORT_INFO *)Yo_Tls_Get(Yo_Csup_Nfo_Tls))->jb_top)

YOYO_JMPBUF *Yo_Push_JmpBuf(void)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_C_Support_Nfo();
    YOYO_JMPBUF *jb;

    STRICT_REQUIRE(nfo->jb_top < nfo->jb_count);
    STRICT_REQUIRE(nfo->jb_top >= -1);

    if ( nfo->jb_top == nfo->jb_count-1 )
      nfo = Yo_Extend_Csup_JmpBuf();
    ++nfo->jb_top;

    jb = &nfo->jb[nfo->jb_top];
    memset(jb->locks,0,sizeof(jb->locks));
    jb->auto_top = nfo->auto_top+1;

    return jb;
  }
#endif
  ;

void Yo_JmpBuf_Push_Cs(void *cs,Yo_JMPBUF_Unlock unlock)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    STRICT_REQUIRE ( cs );
    if ( nfo && cs )
      {
        STRICT_REQUIRE(nfo->jb_top < nfo->jb_count);
        STRICT_REQUIRE(nfo->jb_top >= -1);
        if ( nfo->jb_top > -1 && !nfo->stats.unwinding )
          {
            int i;
            YOYO_JMPBUF_LOCK *locks = nfo->jb[nfo->jb_top].locks;
            for ( i = YOYO_MAX_CS_COUNT-1; i >= 0; --i )
              if ( !locks[i].cs )
                {
                  locks[i].cs = cs;
                  locks[i].unlock = unlock;
                  return;
                }
            Yo_Fatal(YOYO_FATAL_ERROR,__yoTa("no enough lock space",0),__Yo_FILE__,__LINE__);
          }
      }
  }
#endif
  ;


void Yo_JmpBuf_Pop_Cs(void *cs)
#ifdef _YOYO_CORE_BUILTIN
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    if ( nfo && cs )
      {
        STRICT_REQUIRE(nfo->jb_top < nfo->jb_count);
        STRICT_REQUIRE(nfo->jb_top >= -1);
        if ( nfo->jb_top > -1 && !nfo->stats.unwinding )
          {
            int i;
            YOYO_JMPBUF_LOCK *locks = nfo->jb[nfo->jb_top].locks;
            for ( i = YOYO_MAX_CS_COUNT-1; i >= 0; --i )
              if ( locks[i].cs == cs )
                {
                  memset(&locks[i],0,sizeof(locks[i]));
                  return;
                }
            Yo_Fatal(YOYO_FATAL_ERROR,__yoTa("trying to pop unexistent lock",0),__Yo_FILE__,__LINE__);
          }
      }
  }
#endif
  ;

char *Yo_Btrace(void);

#ifdef _YOYO_CORE_BUILTIN
__No_Return void _Yo_Raise(int err,char *msg,char *filename,int lineno)
  {
    YOYO_C_SUPPORT_INFO *nfo = Yo_Tls_Get(Yo_Csup_Nfo_Tls);
    STRICT_REQUIRE( !nfo || nfo->jb_top < nfo->jb_count );

    printf(__yoTa("err: %d, msg: %s, filename: %s, lineno: %d\n",0),err,msg,filename,lineno);

    if ( err == YO_RERAISE_CURRENT_ERROR && (!nfo || !nfo->err.code) )
      Yo_Fatal(YOYO_ERROR_UNEXPECTED,__yoTa("no errors occured yet",0),filename,lineno);

    if ( nfo && nfo->jb_top >= 0 && !nfo->stats.unwinding )
      {
        int i;
        char *old_msg = nfo->err.msg;
        YOYO_JMPBUF_LOCK *locks = nfo->jb[nfo->jb_top].locks;

        if ( err != YO_RERAISE_CURRENT_ERROR )
          {
            nfo->err.msg = msg ? strdup(msg) : 0;
            nfo->err.code = err?err:-1;
            nfo->err.filename = filename;
            nfo->err.lineno = lineno;
            nfo->err.bt_count = backtrace(nfo->err.bt_cbk,YOYO_MAX_ERROR_BTRACE);
            free( old_msg );
          }

        for ( i = YOYO_MAX_CS_COUNT-1; i >= 0; --i )
          if (  locks[i].cs )
            locks[i].unlock(locks[i].cs);

        Yo_Unwind_Scope(0,nfo->jb[nfo->jb_top].auto_top,0);

        --nfo->jb_top;
        STRICT_REQUIRE(nfo->jb_top >= -1);

      #ifdef _TRACEXPT
        StdErr_Print_Nl(Yo_Btrace());
      #endif
        longjmp(nfo->jb[nfo->jb_top+1].b,err?err:-1);
      }
    else
      {
        if ( err != YO_RERAISE_CURRENT_ERROR )
          Yo_Fatal(err,msg,filename,lineno);
        else
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
char *Yo_Btrace_Format(int frames, void **cbk)
#ifdef _YOYO_CORE_BUILTIN
  {
    int  max_bt = 4096;
    char *bt = Yo_Malloc(max_bt);
    char *bt_p = bt;
    int i;
    
    i = snprintf(bt_p,max_bt,__yoTa("--backtrace--",0));
    bt_p+=i;
    max_bt-=i;
    memset(bt_p,0,max_bt--);
    
    for ( i = 0; i < frames; ++i )
      {
      #ifdef __windoze
        int dif = 0;
        char c = '+';
        int l = snprintf(bt_p,max_bt,__yoTa("\n %-2d=> %s %c%x (%p at %s)",0),
           i,
           "", 
           c, 
           dif>0?dif:-dif,
           cbk[i],
           Yo__basename("basename"));

        if ( l > 0 )
          {
            max_bt -= l;
            bt_p += l;
          }

      #else
        Dl_info dlinfo = {0};
        if ( dladdr(cbk[i], &dlinfo) )
          {
            int dif = (char*)cbk[i]-(char*)dlinfo.dli_saddr;
            char c = dif > 0?'+':'-'; 
            int l = snprintf(bt_p,max_bt,__yoTa("\n %-2d=> %s %c%x (%p at %s)",0),
               i,
               dlinfo.dli_sname, 
               c, 
               dif>0?dif:-dif,
               cbk[i],
               Yo__basename((char*)dlinfo.dli_fname));
            if ( l > 0 )
              {
                max_bt -= l;
                bt_p += l;
              }
          }
      #endif
      }
    
    return bt;
  }
#endif
  ;

char *Yo_Btrace(void)
#ifdef _YOYO_CORE_BUILTIN







|




|







|
|















|


|
|











|







1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
char *Yo_Btrace_Format(int frames, void **cbk)
#ifdef _YOYO_CORE_BUILTIN
  {
    int  max_bt = 4096;
    char *bt = Yo_Malloc(max_bt);
    char *bt_p = bt;
    int i;

    i = snprintf(bt_p,max_bt,__yoTa("--backtrace--",0));
    bt_p+=i;
    max_bt-=i;
    memset(bt_p,0,max_bt--);

    for ( i = 0; i < frames; ++i )
      {
      #ifdef __windoze
        int dif = 0;
        char c = '+';
        int l = snprintf(bt_p,max_bt,__yoTa("\n %-2d=> %s %c%x (%p at %s)",0),
           i,
           "",
           c,
           dif>0?dif:-dif,
           cbk[i],
           Yo__basename("basename"));

        if ( l > 0 )
          {
            max_bt -= l;
            bt_p += l;
          }

      #else
        Dl_info dlinfo = {0};
        if ( dladdr(cbk[i], &dlinfo) )
          {
            int dif = (char*)cbk[i]-(char*)dlinfo.dli_saddr;
            char c = dif > 0?'+':'-';
            int l = snprintf(bt_p,max_bt,__yoTa("\n %-2d=> %s %c%x (%p at %s)",0),
               i,
               dlinfo.dli_sname,
               c,
               dif>0?dif:-dif,
               cbk[i],
               Yo__basename((char*)dlinfo.dli_fname));
            if ( l > 0 )
              {
                max_bt -= l;
                bt_p += l;
              }
          }
      #endif
      }

    return bt;
  }
#endif
  ;

char *Yo_Btrace(void)
#ifdef _YOYO_CORE_BUILTIN
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725

#if defined __windoze  && defined _YOYO_CORE_BUILTIN

int backtrace( void **cbk, int count )
  {
    return 0;
  }
  
#elif defined __GNUC__ && defined _YOYO_CORE_BUILTIN \
    && !(defined __APPLE__ || defined __linux__) 

typedef struct _YOYO_BACKTRACE
  {
    void **cbk;
    int count;
  } YOYO_BACKTRACE;
  
_Unwind_Reason_Code backtrace_Helper(struct _Unwind_Context* ctx, YOYO_BACKTRACE *bt)
  {
    if ( bt->count ) 
      {
        void *eip = (void*)_Unwind_GetIP(ctx);
        if ( eip ) 
          {
            *bt->cbk++ = eip;
            --bt->count;
            return _URC_NO_REASON;
          }
      }
    return _URC_NORMAL_STOP;
  }
  
int backtrace( void **cbk, int count )
  {
    YOYO_BACKTRACE T = { cbk, count };
    _Unwind_Backtrace((_Unwind_Trace_Fn)&backtrace_Helper, &T);
    return count-T.count;
  }








|

|






|


|


|








|







1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725

#if defined __windoze  && defined _YOYO_CORE_BUILTIN

int backtrace( void **cbk, int count )
  {
    return 0;
  }

#elif defined __GNUC__ && defined _YOYO_CORE_BUILTIN \
    && !(defined __APPLE__ || defined __linux__)

typedef struct _YOYO_BACKTRACE
  {
    void **cbk;
    int count;
  } YOYO_BACKTRACE;

_Unwind_Reason_Code backtrace_Helper(struct _Unwind_Context* ctx, YOYO_BACKTRACE *bt)
  {
    if ( bt->count )
      {
        void *eip = (void*)_Unwind_GetIP(ctx);
        if ( eip )
          {
            *bt->cbk++ = eip;
            --bt->count;
            return _URC_NO_REASON;
          }
      }
    return _URC_NORMAL_STOP;
  }

int backtrace( void **cbk, int count )
  {
    YOYO_BACKTRACE T = { cbk, count };
    _Unwind_Backtrace((_Unwind_Trace_Fn)&backtrace_Helper, &T);
    return count-T.count;
  }

1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
          Yo_Btrace_N_Abort(__yoTa("fatal",0),ctx,filename,lineno);
        case YOYO_ERROR_DYNCO_CORRUPTED:
          Yo_Btrace_N_Abort(__yoTa("fatal",0),
            Yo_Format_Npl(__yoTa("corrupted dynco (%p)",0),ctx),filename,lineno);
        default:
          {
            char err_pfx[60];
            sprintf(err_pfx,__yoTa("unexpected(%08x)",0),err); 
            Yo_Btrace_N_Abort(err_pfx,ctx,filename,lineno);
          }
      }
  }
#endif
  ;








|







1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
          Yo_Btrace_N_Abort(__yoTa("fatal",0),ctx,filename,lineno);
        case YOYO_ERROR_DYNCO_CORRUPTED:
          Yo_Btrace_N_Abort(__yoTa("fatal",0),
            Yo_Format_Npl(__yoTa("corrupted dynco (%p)",0),ctx),filename,lineno);
        default:
          {
            char err_pfx[60];
            sprintf(err_pfx,__yoTa("unexpected(%08x)",0),err);
            Yo_Btrace_N_Abort(err_pfx,ctx,filename,lineno);
          }
      }
  }
#endif
  ;

1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
    if ( YOYO_ERROR_IS_USER_ERROR(code) )
      return Yo_Format(__yoTa("error(%d): %s",0),code,msg);
    else
      return Yo_Format(__yoTa("error(%08x): %s",0),code,msg);
  }
#endif
  ;
  
__No_Return void Error_Exit(char *pfx)
#ifdef _YOYO_CORE_BUILTIN
  {
    int code = Error_Code();
    char *msg = Error_Message();
    
  #ifndef _BACKTRACE
    if ( (code & YOYO_TRACED_ERROR_GROUP) || !Error_Info()->msg )
  #endif
      StdErr_Print_Nl(Yo_Error_Format_Btrace());
        
    if ( code == YOYO_ERROR_USER )
      StdErr_Print_Nl(Yo_Format(__yoTa("\n%s: %s",0),(pfx?pfx:__yoTa("error",0)),msg));
    else if ( YOYO_ERROR_IS_USER_ERROR(code) )
      StdErr_Print_Nl(Yo_Format(__yoTa("\n%s(%d): %s",0),(pfx?pfx:__yoTa("error",0)),code,msg));
    else
      StdErr_Print_Nl(Yo_Format(__yoTa("\n%s(%08x): %s",0),(pfx?pfx:__yoTa("error",0)),code,msg));
    if ( code & YOYO_FATAL_ERROR_GROUP )







|





|




|







1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
    if ( YOYO_ERROR_IS_USER_ERROR(code) )
      return Yo_Format(__yoTa("error(%d): %s",0),code,msg);
    else
      return Yo_Format(__yoTa("error(%08x): %s",0),code,msg);
  }
#endif
  ;

__No_Return void Error_Exit(char *pfx)
#ifdef _YOYO_CORE_BUILTIN
  {
    int code = Error_Code();
    char *msg = Error_Message();

  #ifndef _BACKTRACE
    if ( (code & YOYO_TRACED_ERROR_GROUP) || !Error_Info()->msg )
  #endif
      StdErr_Print_Nl(Yo_Error_Format_Btrace());

    if ( code == YOYO_ERROR_USER )
      StdErr_Print_Nl(Yo_Format(__yoTa("\n%s: %s",0),(pfx?pfx:__yoTa("error",0)),msg));
    else if ( YOYO_ERROR_IS_USER_ERROR(code) )
      StdErr_Print_Nl(Yo_Format(__yoTa("\n%s(%d): %s",0),(pfx?pfx:__yoTa("error",0)),code,msg));
    else
      StdErr_Print_Nl(Yo_Format(__yoTa("\n%s(%08x): %s",0),(pfx?pfx:__yoTa("error",0)),code,msg));
    if ( code & YOYO_FATAL_ERROR_GROUP )
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036

#define __Elm_Resize_Npl(MemPptr,L,Width,CpsPtr) Yo_Elm_Resize_Npl((void**)MemPptr,L,Width,CpsPtr)
void Yo_Elm_Resize_Npl(void **inout, int L, int type_width, int *capacity_ptr)
#ifdef _YOYO_CORE_BUILTIN
  {
    int requires = 0;
    int capacity = capacity_ptr?*capacity_ptr:0;
    
    if ( L )
      {
        requires = (L+1)*type_width;
        
        if ( *inout )
          {
            if ( !capacity )
              capacity = malloc_size(*inout);
            if ( capacity < requires )
              {
                capacity = Min_Pow2(requires);
                *inout = Yo_Realloc_Npl(*inout,capacity);
              }
          }
        else
          {
            if ( capacity < requires )
              capacity = Min_Pow2(requires);
              
            *inout = Yo_Malloc_Npl(capacity);
          }
      }

    if ( capacity_ptr ) *capacity_ptr = capacity;
  }
#endif
  ;
  
#define __Elm_Insert_Npl(MemPptr,Pos,Count,S,L,Width,CpsPtr) Yo_Elm_Insert_Npl((void**)MemPptr,Pos,Count,S,L,Width,CpsPtr)
int Yo_Elm_Insert_Npl(void **inout, int pos, int count, void *S, int L, int type_width, int *capacity_ptr)
#ifdef _YOYO_CORE_BUILTIN
  {
    STRICT_REQUIRE(pos <= count);
    
    if ( L < 0 ) /* inserting Z-string */
      switch ( type_width )
        {
          case sizeof(wchar_t): L = wcslen(S); break;
          case 1: L = strlen(S); break;
          default: PANICA(__yoTa("invalid size of string element",0));
        }

    if ( L )
      {
        Yo_Elm_Resize_Npl(inout,count+L,type_width,capacity_ptr);
        
        if ( pos < count ) 
          memmove((byte_t*)*inout+(pos+L)*type_width,(byte_t*)*inout+pos*type_width,(count-pos)*type_width);
        memcpy((byte_t*)*inout+pos*type_width, S, L*type_width);
        count += L;
        memset((byte_t*)*inout+count*type_width, 0, type_width);
      }

    return L;
  }
#endif
  ;

#define __Elm_Insert(MemPptr,Pos,Count,S,L,Width,CpsPtr) Yo_Elm_Insert((void**)MemPptr,Pos,Count,S,L,Width,CpsPtr)
int Yo_Elm_Insert(void **inout, int pos, int count, void *S, int L, int type_width, int *capacity_ptr)
#ifdef _YOYO_CORE_BUILTIN
  {
    void *old = *inout;
    int r = Yo_Elm_Insert_Npl(inout,pos,count,S,L,type_width,capacity_ptr);
    if ( *inout != old )
      {
        if ( old ) 
          Yo_Refresh_Ptr(old,*inout,0);
        else
          Yo_Pool_Ptr(*inout,0);
      }
    return r;
  }
#endif
  ;

#define Yo_Elm_Append(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Insert(Mem,Count,Count,S,L,Width,CpsPtr)
#define Yo_Elm_Append_Npl(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Insert_Npl(Mem,Count,Count,S,L,Width,CpsPtr)
#define __Vector_Append(Mem,Count,Capacity,S,L) (void)(*Count += Yo_Elm_Append((void**)Mem,*Count,S,L,1,Capacity))
#define __Elm_Append(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Append((void**)Mem,Count,S,L,Width,CpsPtr)
#define __Elm_Append_Npl(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Append_Npl((void**)Mem,Count,S,L,Width,CpsPtr)

#endif /* C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C */








|



|














|








|





|











|
|



















|
















<
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035


#define __Elm_Resize_Npl(MemPptr,L,Width,CpsPtr) Yo_Elm_Resize_Npl((void**)MemPptr,L,Width,CpsPtr)
void Yo_Elm_Resize_Npl(void **inout, int L, int type_width, int *capacity_ptr)
#ifdef _YOYO_CORE_BUILTIN
  {
    int requires = 0;
    int capacity = capacity_ptr?*capacity_ptr:0;

    if ( L )
      {
        requires = (L+1)*type_width;

        if ( *inout )
          {
            if ( !capacity )
              capacity = malloc_size(*inout);
            if ( capacity < requires )
              {
                capacity = Min_Pow2(requires);
                *inout = Yo_Realloc_Npl(*inout,capacity);
              }
          }
        else
          {
            if ( capacity < requires )
              capacity = Min_Pow2(requires);

            *inout = Yo_Malloc_Npl(capacity);
          }
      }

    if ( capacity_ptr ) *capacity_ptr = capacity;
  }
#endif
  ;

#define __Elm_Insert_Npl(MemPptr,Pos,Count,S,L,Width,CpsPtr) Yo_Elm_Insert_Npl((void**)MemPptr,Pos,Count,S,L,Width,CpsPtr)
int Yo_Elm_Insert_Npl(void **inout, int pos, int count, void *S, int L, int type_width, int *capacity_ptr)
#ifdef _YOYO_CORE_BUILTIN
  {
    STRICT_REQUIRE(pos <= count);

    if ( L < 0 ) /* inserting Z-string */
      switch ( type_width )
        {
          case sizeof(wchar_t): L = wcslen(S); break;
          case 1: L = strlen(S); break;
          default: PANICA(__yoTa("invalid size of string element",0));
        }

    if ( L )
      {
        Yo_Elm_Resize_Npl(inout,count+L,type_width,capacity_ptr);

        if ( pos < count )
          memmove((byte_t*)*inout+(pos+L)*type_width,(byte_t*)*inout+pos*type_width,(count-pos)*type_width);
        memcpy((byte_t*)*inout+pos*type_width, S, L*type_width);
        count += L;
        memset((byte_t*)*inout+count*type_width, 0, type_width);
      }

    return L;
  }
#endif
  ;

#define __Elm_Insert(MemPptr,Pos,Count,S,L,Width,CpsPtr) Yo_Elm_Insert((void**)MemPptr,Pos,Count,S,L,Width,CpsPtr)
int Yo_Elm_Insert(void **inout, int pos, int count, void *S, int L, int type_width, int *capacity_ptr)
#ifdef _YOYO_CORE_BUILTIN
  {
    void *old = *inout;
    int r = Yo_Elm_Insert_Npl(inout,pos,count,S,L,type_width,capacity_ptr);
    if ( *inout != old )
      {
        if ( old )
          Yo_Refresh_Ptr(old,*inout,0);
        else
          Yo_Pool_Ptr(*inout,0);
      }
    return r;
  }
#endif
  ;

#define Yo_Elm_Append(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Insert(Mem,Count,Count,S,L,Width,CpsPtr)
#define Yo_Elm_Append_Npl(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Insert_Npl(Mem,Count,Count,S,L,Width,CpsPtr)
#define __Vector_Append(Mem,Count,Capacity,S,L) (void)(*Count += Yo_Elm_Append((void**)Mem,*Count,S,L,1,Capacity))
#define __Elm_Append(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Append((void**)Mem,Count,S,L,Width,CpsPtr)
#define __Elm_Append_Npl(Mem,Count,S,L,Width,CpsPtr) Yo_Elm_Append_Npl((void**)Mem,Count,S,L,Width,CpsPtr)

#endif /* C_once_6973F3BA_26FA_434D_9ED9_FF5389CE421C */