|
50 | 50 | **
|
51 | 51 | ***********************************************************************/
|
52 | 52 |
|
53 |
| -#if defined(__cplusplus) && __cplusplus >= 201103L |
54 |
| -#include <type_traits> // used in CASTING MACROS |
55 |
| -#endif |
56 |
| - |
57 | 53 | #ifdef __OBJC__
|
58 | 54 | #define HAS_BOOL // don't redefine BOOL in objective-c code
|
59 | 55 | #endif
|
@@ -427,103 +423,15 @@ typedef void(*CFUNC)(void *);
|
427 | 423 | #define REB_NORETURN
|
428 | 424 | #endif
|
429 | 425 |
|
430 |
| -// |
431 |
| -// CASTING MACROS |
432 |
| -// |
433 |
| -// The following code and explanation is from "Casts for the Masses (in C)": |
434 |
| -// |
435 |
| -// http://blog.hostilefork.com/c-casts-for-the-masses/ |
436 |
| -// |
437 |
| -// But debug builds don't inline functions--not even no-op ones whose sole |
438 |
| -// purpose is static analysis. This means the cast macros add a headache when |
439 |
| -// stepping through the debugger, and also they consume a measurable amount |
440 |
| -// of runtime. Hence we sacrifice cast checking in the debug builds...and the |
441 |
| -// release C++ builds on Travis are relied upon to do the proper optimizations |
442 |
| -// as well as report any static analysis errors. |
443 |
| -// |
444 |
| - |
445 |
| -#if !defined(__cplusplus) || !defined(NDEBUG) |
446 |
| - /* These macros are easier-to-spot variants of the parentheses cast. |
447 |
| - * The 'm_cast' is when getting [M]utablity on a const is okay (RARELY!) |
448 |
| - * Plain 'cast' can do everything else (except remove volatile) |
449 |
| - * The 'c_cast' helper ensures you're ONLY adding [C]onst to a value |
450 |
| - */ |
451 |
| - #define m_cast(t,v) ((t)(v)) |
452 |
| - #define cast(t,v) ((t)(v)) |
453 |
| - #define c_cast(t,v) ((t)(v)) |
454 |
| - /* |
455 |
| - * Q: Why divide roles? A: Frequently, input to cast is const but you |
456 |
| - * "just forget" to include const in the result type, gaining mutable |
457 |
| - * access. Stray writes to that can cause even time-traveling bugs, with |
458 |
| - * effects *before* that write is made...due to "undefined behavior". |
459 |
| - */ |
460 |
| -#elif defined(__cplusplus) /* for gcc -Wundef */ && (__cplusplus < 201103L) |
461 |
| - /* Well-intentioned macros aside, C has no way to enforce that you can't |
462 |
| - * cast away a const without m_cast. C++98 builds can do that, at least: |
463 |
| - */ |
464 |
| - #define m_cast(t,v) const_cast<t>(v) |
465 |
| - #define cast(t,v) ((t)(v)) |
466 |
| - #define c_cast(t,v) const_cast<t>(v) |
467 |
| -#else |
468 |
| - /* __cplusplus >= 201103L has C++11's type_traits, where we get some |
469 |
| - * actual power. cast becomes a reinterpret_cast for pointers and a |
470 |
| - * static_cast otherwise. We ensure c_cast added a const and m_cast |
471 |
| - * removed one, and that neither affected volatility. |
472 |
| - */ |
473 |
| - template<typename T, typename V> |
474 |
| - T m_cast_helper(V v) { |
475 |
| - static_assert(!std::is_const<T>::value, |
476 |
| - "invalid m_cast() - requested a const type for output result"); |
477 |
| - static_assert(std::is_volatile<T>::value == std::is_volatile<V>::value, |
478 |
| - "invalid m_cast() - input and output have mismatched volatility"); |
479 |
| - return const_cast<T>(v); |
480 |
| - } |
481 |
| - /* reinterpret_cast for pointer to pointer casting (non-class source)*/ |
482 |
| - template<typename T, typename V, |
483 |
| - typename std::enable_if< |
484 |
| - !std::is_class<V>::value |
485 |
| - && (std::is_pointer<V>::value || std::is_pointer<T>::value) |
486 |
| - >::type* = nullptr> |
487 |
| - T cast_helper(V v) { return reinterpret_cast<T>(v); } |
488 |
| - /* static_cast for non-pointer to non-pointer casting (non-class source) */ |
489 |
| - template<typename T, typename V, |
490 |
| - typename std::enable_if< |
491 |
| - !std::is_class<V>::value |
492 |
| - && (!std::is_pointer<V>::value && !std::is_pointer<T>::value) |
493 |
| - >::type* = nullptr> |
494 |
| - T cast_helper(V v) { return static_cast<T>(v); } |
495 |
| - /* use static_cast on all classes, to go through their cast operators */ |
496 |
| - template<typename T, typename V, |
497 |
| - typename std::enable_if< |
498 |
| - std::is_class<V>::value |
499 |
| - >::type* = nullptr> |
500 |
| - T cast_helper(V v) { return static_cast<T>(v); } |
501 |
| - template<typename T, typename V> |
502 |
| - T c_cast_helper(V v) { |
503 |
| - static_assert(!std::is_const<T>::value, |
504 |
| - "invalid c_cast() - did not request const type for output result"); |
505 |
| - static_assert(std::is_volatile<T>::value == std::is_volatile<V>::value, |
506 |
| - "invalid c_cast() - input and output have mismatched volatility"); |
507 |
| - return const_cast<T>(v); |
508 |
| - } |
509 |
| - #define m_cast(t, v) m_cast_helper<t>(v) |
510 |
| - #define cast(t, v) cast_helper<t>(v) |
511 |
| - #define c_cast(t, v) c_cast_helper<t>(v) |
512 |
| -#endif |
513 |
| - |
| 426 | +/* These macros are easier-to-spot variants of the parentheses cast. |
| 427 | + * The 'm_cast' is when getting [M]utablity on a const is okay (RARELY!) |
| 428 | + * Plain 'cast' can do everything else (except remove volatile) |
| 429 | + * The 'c_cast' helper ensures you're ONLY adding [C]onst to a value |
| 430 | + */ |
| 431 | +#define m_cast(t,v) ((t)(v)) |
| 432 | +#define cast(t,v) ((t)(v)) |
| 433 | +#define c_cast(t,v) ((t)(v)) |
514 | 434 |
|
515 |
| -//=//// BYTE STRINGS VS UNENCODED CHARACTER STRINGS ///////////////////////=// |
516 |
| -// |
517 |
| -// Use these when you semantically are talking about unsigned characters as |
518 |
| -// bytes. For instance: if you want to count unencoded chars in 'char *' us |
519 |
| -// strlen(), and the reader will know that is a count of letters. If you have |
520 |
| -// something like UTF-8 with more than one byte per character, use LEN_BYTES. |
521 |
| -// The casting macros are derived from "Casts for the Masses (in C)": |
522 |
| -// |
523 |
| -// http://blog.hostilefork.com/c-casts-for-the-masses/ |
524 |
| -// |
525 |
| -// For APPEND_BYTES_LIMIT, m is the max-size allocated for d (dest) |
526 |
| -// |
527 | 435 | #include <string.h> // for strlen() etc, but also defines `size_t`
|
528 | 436 | #define strsize strlen
|
529 | 437 | #if defined(NDEBUG)
|
|
0 commit comments