A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Perl/perl5/commit/6d59e610a3f269be73ffea56a90d1cd7dc8bf2fd below:

define and use STATIC_ASSERT_STMT for compile-time invariants · Perl/perl5@6d59e61 · GitHub

File tree Expand file treeCollapse file tree 7 files changed

+36

-12

lines changed

Filter options

Expand file treeCollapse file tree 7 files changed

+36

-12

lines changed Original file line number Diff line number Diff line change

@@ -9627,7 +9627,7 @@ Perl_ck_rvconst(pTHX_ OP *o)

9627 9627

SvREFCNT_dec(kid->op_sv);

9628 9628

#ifdef USE_ITHREADS

9629 9629

/* XXX hack: dependence on sizeof(PADOP) <= sizeof(SVOP) */

9630 -

assert (sizeof(PADOP) <= sizeof(SVOP));

9630 +

STATIC_ASSERT_STMT(sizeof(PADOP) <= sizeof(SVOP));

9631 9631

kPADOP->op_padix = pad_alloc(OP_GV, SVf_READONLY);

9632 9632

SvREFCNT_dec(PAD_SVl(kPADOP->op_padix));

9633 9633

PAD_SETSV(kPADOP->op_padix, MUTABLE_SV(SvREFCNT_inc_simple_NN(gv)));

Original file line number Diff line number Diff line change

@@ -3467,7 +3467,10 @@ typedef pthread_key_t perl_key;

3467 3467

# define __attribute__warn_unused_result__

3468 3468

#endif

3469 3469 3470 -

#if defined(DEBUGGING) && defined(I_ASSERT)

3470 +

#ifdef I_ASSERT

3471 +

# if !defined(DEBUGGING) && !defined(NDEBUG)

3472 +

# define NDEBUG 1

3473 +

# endif

3471 3474

# include <assert.h>

3472 3475

#endif

3473 3476

@@ -3498,6 +3501,27 @@ typedef pthread_key_t perl_key;

3498 3501

/* placeholder */

3499 3502

#endif

3500 3503 3504 +

#if defined(static_assert) || (defined(__cplusplus) && __cplusplus >= 201103L)

3505 +

/* static_assert is a macro defined in <assert.h> in C11 or a compiler

3506 +

builtin in C++11.

3507 +

*/

3508 +

# define STATIC_ASSERT_GLOBAL(COND) static_assert(COND, #COND)

3509 +

#else

3510 +

/* We use a bit-field instead of an array because gcc accepts

3511 +

'typedef char x[n]' where n is not a compile-time constant.

3512 +

We want to enforce constantness.

3513 +

*/

3514 +

# define STATIC_ASSERT_2(COND, SUFFIX) \

3515 +

typedef struct { \

3516 +

unsigned int _static_assertion_failed_##SUFFIX : (COND) ? 1 : -1; \

3517 +

} _static_assertion_failed_##SUFFIX PERL_UNUSED_DECL

3518 +

# define STATIC_ASSERT_1(COND, SUFFIX) STATIC_ASSERT_2(COND, SUFFIX)

3519 +

# define STATIC_ASSERT_GLOBAL(COND) STATIC_ASSERT_1(COND, __LINE__)

3520 +

#endif

3521 +

/* We need this wrapper even in C11 because 'case X: static_assert(...);' is an

3522 +

error (static_assert is a declaration, and only statements can have labels).

3523 +

*/

3524 +

#define STATIC_ASSERT_STMT(COND) do { STATIC_ASSERT_GLOBAL(COND); } while (0)

3501 3525 3502 3526

#ifndef __has_builtin

3503 3527

# define __has_builtin(x) 0 /* not a clang style compiler */

Original file line number Diff line number Diff line change

@@ -2956,7 +2956,7 @@ PP(pp_length)

2956 2956

/* simplest case shortcut */

2957 2957

/* turn off SVf_UTF8 in tmp flags if HINT_BYTES on*/

2958 2958

U32 svflags = (SvFLAGS(sv) ^ (in_bytes << 26)) & (SVf_POK|SVs_GMG|SVf_UTF8);

2959 -

assert(HINT_BYTES == 0x00000008 && SVf_UTF8 == 0x20000000 && (SVf_UTF8 == HINT_BYTES << 26));

2959 +

STATIC_ASSERT_STMT(HINT_BYTES == 0x00000008 && SVf_UTF8 == 0x20000000 && (SVf_UTF8 == HINT_BYTES << 26));

2960 2960

SETs(TARG);

2961 2961 2962 2962

if(LIKELY(svflags == SVf_POK))

Original file line number Diff line number Diff line change

@@ -386,7 +386,7 @@ PP(pp_padrange)

386 386

(base << (OPpPADRANGE_COUNTSHIFT + SAVE_TIGHT_SHIFT))

387 387

| (count << SAVE_TIGHT_SHIFT)

388 388

| SAVEt_CLEARPADRANGE);

389 -

assert(OPpPADRANGE_COUNTMASK + 1 == (1 <<OPpPADRANGE_COUNTSHIFT));

389 +

STATIC_ASSERT_STMT(OPpPADRANGE_COUNTMASK + 1 == (1 << OPpPADRANGE_COUNTSHIFT));

390 390

assert((payload >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT)) == base);

391 391

{

392 392

dSS_ADD;

Original file line number Diff line number Diff line change

@@ -534,9 +534,9 @@ Perl_tied_method(pTHX_ SV *methname, SV **sp, SV *const sv,

534 534

PERL_ARGS_ASSERT_TIED_METHOD;

535 535 536 536

/* Ensure that our flag bits do not overlap. */

537 -

assert((TIED_METHOD_MORTALIZE_NOT_NEEDED & G_WANT) == 0);

538 -

assert((TIED_METHOD_ARGUMENTS_ON_STACK & G_WANT) == 0);

539 -

assert((TIED_METHOD_SAY & G_WANT) == 0);

537 +

STATIC_ASSERT_STMT((TIED_METHOD_MORTALIZE_NOT_NEEDED & G_WANT) == 0);

538 +

STATIC_ASSERT_STMT((TIED_METHOD_ARGUMENTS_ON_STACK & G_WANT) == 0);

539 +

STATIC_ASSERT_STMT((TIED_METHOD_SAY & G_WANT) == 0);

540 540 541 541

PUTBACK; /* sp is at *foot* of args, so this pops args from old stack */

542 542

PUSHSTACKi(PERLSI_MAGIC);

Original file line number Diff line number Diff line change

@@ -1320,8 +1320,8 @@ Perl_sv_upgrade(pTHX_ SV *const sv, svtype new_type)

1320 1320

break;

1321 1321

case SVt_PV:

1322 1322

assert(new_type > SVt_PV);

1323 -

assert(SVt_IV < SVt_PV);

1324 -

assert(SVt_NV < SVt_PV);

1323 +

STATIC_ASSERT_STMT(SVt_IV < SVt_PV);

1324 +

STATIC_ASSERT_STMT(SVt_NV < SVt_PV);

1325 1325

break;

1326 1326

case SVt_PVIV:

1327 1327

break;

@@ -4311,7 +4311,7 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, SV* sstr, const I32 flags)

4311 4311

/* We're starting from SVt_NULL, so provided that's

4312 4312

* actual 0, we don't have to unset any SV type flags

4313 4313

* to promote to SVt_IV. */

4314 -

assert(SVt_NULL == 0);

4314 +

STATIC_ASSERT_STMT(SVt_NULL == 0);

4315 4315

SET_SVANY_FOR_BODYLESS_IV(dstr);

4316 4316

SvFLAGS(dstr) |= SVt_IV;

4317 4317

break;

@@ -9366,7 +9366,7 @@ Perl_newSViv(pTHX_ const IV i)

9366 9366

/* We're starting from SVt_FIRST, so provided that's

9367 9367

* actual 0, we don't have to unset any SV type flags

9368 9368

* to promote to SVt_IV. */

9369 -

assert(SVt_FIRST == 0);

9369 +

STATIC_ASSERT_STMT(SVt_FIRST == 0);

9370 9370 9371 9371

SET_SVANY_FOR_BODYLESS_IV(sv);

9372 9372

SvFLAGS(sv) |= SVt_IV;

Original file line number Diff line number Diff line change

@@ -730,7 +730,7 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)

730 730

parser->bufend = parser->bufptr + SvCUR(parser->linestr);

731 731

parser->last_lop = parser->last_uni = NULL;

732 732 733 -

assert(FITS_IN_8_BITS(LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES

733 +

STATIC_ASSERT_STMT(FITS_IN_8_BITS(LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES

734 734

|LEX_DONT_CLOSE_RSFP));

735 735

parser->lex_flags = (U8) (flags & (LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES

736 736

|LEX_DONT_CLOSE_RSFP));

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4