Assert for RTEST that Qnil and Qfalse differ just 1 bit
This commit is contained in:
parent
86096a91d5
commit
412e3c7a8d
Notes:
git
2022-10-19 13:56:02 +00:00
@ -136,6 +136,7 @@ static inline bool
|
|||||||
RB_TEST(VALUE obj)
|
RB_TEST(VALUE obj)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
* if USE_FLONUM
|
||||||
* Qfalse: ....0000 0000
|
* Qfalse: ....0000 0000
|
||||||
* Qnil: ....0000 1000
|
* Qnil: ....0000 1000
|
||||||
* ~Qnil: ....1111 0111
|
* ~Qnil: ....1111 0111
|
||||||
@ -143,6 +144,14 @@ RB_TEST(VALUE obj)
|
|||||||
* ----------------------------
|
* ----------------------------
|
||||||
* RTEST(v) ....xxxx 0xxx
|
* RTEST(v) ....xxxx 0xxx
|
||||||
*
|
*
|
||||||
|
* if ! USE_FLONUM
|
||||||
|
* Qfalse: ....0000 0000
|
||||||
|
* Qnil: ....0000 0100
|
||||||
|
* ~Qnil: ....1111 1011
|
||||||
|
* v ....xxxx xxxx
|
||||||
|
* ----------------------------
|
||||||
|
* RTEST(v) ....xxxx x0xx
|
||||||
|
*
|
||||||
* RTEST(v) can be 0 if and only if (v == Qfalse || v == Qnil).
|
* RTEST(v) can be 0 if and only if (v == Qfalse || v == Qnil).
|
||||||
*/
|
*/
|
||||||
return obj & ~RUBY_Qnil;
|
return obj & ~RUBY_Qnil;
|
||||||
|
3
ruby.c
3
ruby.c
@ -62,6 +62,9 @@
|
|||||||
#include "ruby/version.h"
|
#include "ruby/version.h"
|
||||||
#include "ruby/internal/error.h"
|
#include "ruby/internal/error.h"
|
||||||
|
|
||||||
|
#define singlebit_only_p(x) !((x) & ((x)-1))
|
||||||
|
STATIC_ASSERT(Qnil_1bit_from_Qfalse, singlebit_only_p(Qnil^Qfalse));
|
||||||
|
|
||||||
#ifndef MAXPATHLEN
|
#ifndef MAXPATHLEN
|
||||||
# define MAXPATHLEN 1024
|
# define MAXPATHLEN 1024
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user