@@ -69,7 +69,6 @@ bool xy_on_android = false;
6969
7070char * xy_os_devnull = NULL ;
7171
72- // #define NDEBUG
7372
7473#ifdef _WIN32
7574 #define XY_Build_On_Windows 1
@@ -90,14 +89,22 @@ char *xy_os_devnull = NULL;
9089 #define XY_Build_On_Unix 1
9190#endif
9291
92+
93+
94+ /**
95+ * assert() 会被 NDEBUG 关闭,但我们也没有必要强制开启它,还是留给用户定义
96+ */
97+ // #undef NDEBUG
98+ #define xy_noop () ((void)0)
99+
93100#define assert_str (a , b ) assert (xy_streql ((a), (b)))
94101
95- #define xy_unsupported ( ) assert(!"Unsuppoted" )
96- #define xy_unimplemented () assert(!"Unimplemented temporarily ")
97- #define xy_unreached () assert(!"This code shouldn't be reached ")
98- #define xy_noop () (void)0
99- #define xy_cant_be_null (p ) if(!p) assert(! "This pointer can't be null")
100- #define xy_developer_mistake ( reason ) assert(!reason)
102+ #define xy_panic ( reason ) assert(!reason )
103+ #define xy_unsupported () xy_panic("Unsuppoted ")
104+ #define xy_unimplemented () xy_panic("Unimplemented temporarily ")
105+ #define xy_unreached () xy_panic("This code shouldn't be reached")
106+ #define xy_cant_be_null (p ) if(!p) xy_panic( "This pointer can't be null")
107+
101108
102109
103110static void _xy_print_int (int n ) {printf ("%d" , n );}
@@ -130,7 +137,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);}
130137 bool: _xy_print_bool, \
131138 char *: _xy_print_str, \
132139 const char *: _xy_print_const_str, \
133- default: assert(! "Unsupported type for print()!") \
140+ default: xy_panic( "Unsupported type for print()!") \
134141)(x)
135142
136143/**
@@ -145,7 +152,7 @@ static void _xy_println_const_str (const char *str) {printf ("%s\n", str);}
145152 bool: _xy_println_bool, \
146153 char *: _xy_println_str, \
147154 const char *: _xy_println_const_str, \
148- default: assert(! "Unsupported type for println()/say()!") \
155+ default: xy_panic( "Unsupported type for println()/say()!") \
149156)(x)
150157/* @flavor Perl/Raku */
151158#define say println
@@ -1164,7 +1171,8 @@ xy_detect_os ()
11641171 xy_on_bsd = true;
11651172 }
11661173
1167- assert (xy_on_windows || xy_on_linux || xy_on_android || xy_on_macos || xy_on_bsd );
1174+ if (!(xy_on_windows || xy_on_linux || xy_on_android || xy_on_macos || xy_on_bsd ))
1175+ xy_panic ("Unknown operating system" );
11681176}
11691177
11701178
@@ -1271,7 +1279,7 @@ xy_seq_at (XySeq_t *seq, int n)
12711279{
12721280 xy_cant_be_null (seq );
12731281
1274- if (0 == n ) assert (! "The index must begin from 1, not 0" );
1282+ if (0 == n ) xy_panic ( "The index must begin from 1, not 0" );
12751283
12761284 if (1 == n ) return seq -> first_item ? seq -> first_item -> data : NULL ;
12771285
0 commit comments