… | |
… | |
81 | |
81 | |
82 | // in range excluding end |
82 | // in range excluding end |
83 | #define IN_RANGE_EXC(val,beg,end) \ |
83 | #define IN_RANGE_EXC(val,beg,end) \ |
84 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
84 | ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) |
85 | |
85 | |
86 | void cleanup (const char *cause, bool make_core = false); |
86 | ecb_cold void cleanup (const char *cause, bool make_core = false); |
87 | void fork_abort (const char *msg); |
87 | ecb_cold void fork_abort (const char *msg); |
88 | |
88 | |
89 | // rationale for using (U) not (T) is to reduce signed/unsigned issues, |
89 | // rationale for using (U) not (T) is to reduce signed/unsigned issues, |
90 | // as a is often a constant while b is the variable. it is still a bug, though. |
90 | // as a is often a constant while b is the variable. it is still a bug, though. |
91 | template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } |
91 | template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } |
92 | template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } |
92 | template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } |
… | |
… | |
283 | absdir (int d) |
283 | absdir (int d) |
284 | { |
284 | { |
285 | return ((d - 1) & 7) + 1; |
285 | return ((d - 1) & 7) + 1; |
286 | } |
286 | } |
287 | |
287 | |
288 | // avoid ctz name because netbsd or freebsd spams it's namespace with it |
|
|
289 | #if GCC_VERSION(3,4) |
|
|
290 | static inline int least_significant_bit (uint32_t x) |
|
|
291 | { |
|
|
292 | return __builtin_ctz (x); |
|
|
293 | } |
|
|
294 | #else |
|
|
295 | int least_significant_bit (uint32_t x); |
|
|
296 | #endif |
|
|
297 | |
|
|
298 | #define for_all_bits_sparse_32(mask, idxvar) \ |
288 | #define for_all_bits_sparse_32(mask, idxvar) \ |
299 | for (uint32_t idxvar, mask_ = mask; \ |
289 | for (uint32_t idxvar, mask_ = mask; \ |
300 | mask_ && ((idxvar = least_significant_bit (mask_)), mask_ &= ~(1 << idxvar), 1);) |
290 | mask_ && ((idxvar = ecb_ctz32 (mask_)), mask_ &= ~(1 << idxvar), 1);) |
301 | |
291 | |
302 | extern ssize_t slice_alloc; // statistics |
292 | extern ssize_t slice_alloc; // statistics |
303 | |
293 | |
304 | void *salloc_ (int n); |
294 | void *salloc_ (int n); |
305 | void *salloc_ (int n, void *src); |
295 | void *salloc_ (int n, void *src); |
… | |
… | |
536 | // p if not null |
526 | // p if not null |
537 | refcnt_base::refcnt_t *refcnt_ref () { return p ? &p->refcnt : &refcnt_dummy; } |
527 | refcnt_base::refcnt_t *refcnt_ref () { return p ? &p->refcnt : &refcnt_dummy; } |
538 | |
528 | |
539 | void refcnt_dec () |
529 | void refcnt_dec () |
540 | { |
530 | { |
541 | if (!is_constant (p)) |
531 | if (!ecb_is_constant (p)) |
542 | --*refcnt_ref (); |
532 | --*refcnt_ref (); |
543 | else if (p) |
533 | else if (p) |
544 | --p->refcnt; |
534 | --p->refcnt; |
545 | } |
535 | } |
546 | |
536 | |
547 | void refcnt_inc () |
537 | void refcnt_inc () |
548 | { |
538 | { |
549 | if (!is_constant (p)) |
539 | if (!ecb_is_constant (p)) |
550 | ++*refcnt_ref (); |
540 | ++*refcnt_ref (); |
551 | else if (p) |
541 | else if (p) |
552 | ++p->refcnt; |
542 | ++p->refcnt; |
553 | } |
543 | } |
554 | |
544 | |
… | |
… | |
814 | |
804 | |
815 | int similar_direction (int a, int b); |
805 | int similar_direction (int a, int b); |
816 | |
806 | |
817 | // like v?sprintf, but returns a "static" buffer |
807 | // like v?sprintf, but returns a "static" buffer |
818 | char *vformat (const char *format, va_list ap); |
808 | char *vformat (const char *format, va_list ap); |
819 | char *format (const char *format, ...) attribute ((format (printf, 1, 2))); |
809 | char *format (const char *format, ...) ecb_attribute ((format (printf, 1, 2))); |
820 | |
810 | |
821 | // safety-check player input which will become object->msg |
811 | // safety-check player input which will become object->msg |
822 | bool msg_is_safe (const char *msg); |
812 | bool msg_is_safe (const char *msg); |
823 | |
813 | |
824 | ///////////////////////////////////////////////////////////////////////////// |
814 | ///////////////////////////////////////////////////////////////////////////// |