Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit e80f2a5

Browse files
author
Reini Urban
committed
embed: add UNUSED for PERL_UNUSED_DECL
create optimized C calls via __attribute__((unused)) for unused args. declare them with UNUSED in embed.fnc
1 parent 9cf936f commit e80f2a5

File tree

6 files changed

+53
-51
lines changed

6 files changed

+53
-51
lines changed

.git-rr-cache

doio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ S_ingroup(pTHX_ Gid_t testgid, bool effective)
21862186
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
21872187

21882188
I32
2189-
Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp)
2189+
Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp PERL_UNUSED_DECL)
21902190
{
21912191
const key_t key = (key_t)SvNVx(*++mark);
21922192
SV *nsv = optype == OP_MSGGET ? NULL : *++mark;
@@ -2220,7 +2220,7 @@ Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp)
22202220
}
22212221

22222222
I32
2223-
Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp)
2223+
Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp PERL_UNUSED_DECL)
22242224
{
22252225
char *a;
22262226
I32 ret = -1;
@@ -2353,7 +2353,7 @@ Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp)
23532353
}
23542354

23552355
I32
2356-
Perl_do_msgsnd(pTHX_ SV **mark, SV **sp)
2356+
Perl_do_msgsnd(pTHX_ SV **mark, SV **sp PERL_UNUSED_DECL)
23572357
{
23582358
#ifdef HAS_MSG
23592359
STRLEN len;
@@ -2385,7 +2385,7 @@ Perl_do_msgsnd(pTHX_ SV **mark, SV **sp)
23852385
}
23862386

23872387
I32
2388-
Perl_do_msgrcv(pTHX_ SV **mark, SV **sp)
2388+
Perl_do_msgrcv(pTHX_ SV **mark, SV **sp PERL_UNUSED_DECL)
23892389
{
23902390
#ifdef HAS_MSG
23912391
char *mbuf;
@@ -2430,7 +2430,7 @@ Perl_do_msgrcv(pTHX_ SV **mark, SV **sp)
24302430
}
24312431

24322432
I32
2433-
Perl_do_semop(pTHX_ SV **mark, SV **sp)
2433+
Perl_do_semop(pTHX_ SV **mark, SV **sp PERL_UNUSED_DECL)
24342434
{
24352435
#ifdef HAS_SEM
24362436
STRLEN opsize;
@@ -2475,7 +2475,7 @@ Perl_do_semop(pTHX_ SV **mark, SV **sp)
24752475
}
24762476

24772477
I32
2478-
Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
2478+
Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp PERL_UNUSED_DECL)
24792479
{
24802480
#ifdef HAS_SHM
24812481
char *shm;

embed.fnc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
: no effect on output yet. It's a notation for the maintainers to know "I have
144144
: defined whether NULL is OK or not" rather than having neither NULL or NULLOK,
145145
: which is ambiguous.
146+
: UNUSED parameters get the PERL_UNUSED_DECL, ie. the optional __attribute__((unused))
146147
:
147148
: Individual flags may be separated by whitespace.
148149

@@ -384,17 +385,17 @@ s |void |exec_failed |NN const char *cmd|int fd|int do_report
384385
#endif
385386
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
386387
: Defined in doio.c, used only in pp_sys.c
387-
p |I32 |do_ipcctl |I32 optype|NN SV** mark|NN SV** sp
388+
p |I32 |do_ipcctl |I32 optype|NN SV** mark|UNUSED NULLOK SV** sp
388389
: Defined in doio.c, used only in pp_sys.c
389-
p |I32 |do_ipcget |I32 optype|NN SV** mark|NN SV** sp
390+
p |I32 |do_ipcget |I32 optype|NN SV** mark|UNUSED NULLOK SV** sp
390391
: Defined in doio.c, used only in pp_sys.c
391-
p |I32 |do_msgrcv |NN SV** mark|NN SV** sp
392+
p |I32 |do_msgrcv |NN SV** mark|UNUSED NULLOK SV** sp
392393
: Defined in doio.c, used only in pp_sys.c
393-
p |I32 |do_msgsnd |NN SV** mark|NN SV** sp
394+
p |I32 |do_msgsnd |NN SV** mark|UNUSED NULLOK SV** sp
394395
: Defined in doio.c, used only in pp_sys.c
395-
p |I32 |do_semop |NN SV** mark|NN SV** sp
396+
p |I32 |do_semop |NN SV** mark|UNUSED NULLOK SV** sp
396397
: Defined in doio.c, used only in pp_sys.c
397-
p |I32 |do_shmio |I32 optype|NN SV** mark|NN SV** sp
398+
p |I32 |do_shmio |I32 optype|NN SV** mark|UNUSED NULLOK SV** sp
398399
#endif
399400
Ap |void |do_join |NN SV *sv|NN SV *delim|NN SV **mark|NN SV **sp
400401
: Used in pp.c and pp_hot.c, prototype generated by regen/opcode.pl
@@ -982,7 +983,8 @@ Apda |OP* |newFOROP |I32 flags|NULLOK OP* sv|NN OP* expr|NULLOK OP* block|NULLOK
982983
Apda |OP* |newGIVENOP |NN OP* cond|NN OP* block|PADOFFSET defsv_off
983984
Apda |OP* |newLOGOP |I32 optype|I32 flags|NN OP *first|NN OP *other
984985
Apda |OP* |newLOOPEX |I32 type|NN OP* label
985-
Apda |OP* |newLOOPOP |I32 flags|I32 debuggable|NULLOK OP* expr|NULLOK OP* block
986+
Apda |OP* |newLOOPOP |I32 flags|UNUSED I32 debuggable \
987+
|NULLOK OP* expr|NULLOK OP* block
986988
Apda |OP* |newNULLLIST
987989
Apda |OP* |newOP |I32 optype|I32 flags
988990
Ap |void |newPROG |NN OP* o
@@ -1048,7 +1050,7 @@ Apda |OP* |newUNOP |I32 type|I32 flags|NULLOK OP* first
10481050
Apda |OP* |newUNOP_AUX |I32 type|I32 flags|NULLOK OP* first \
10491051
|NULLOK UNOP_AUX_item *aux
10501052
Apda |OP* |newWHENOP |NULLOK OP* cond|NN OP* block
1051-
Apda |OP* |newWHILEOP |I32 flags|I32 debuggable|NULLOK LOOP* loop \
1053+
Apda |OP* |newWHILEOP |I32 flags|UNUSED I32 debuggable|NULLOK LOOP* loop \
10521054
|NULLOK OP* expr|NULLOK OP* block|NULLOK OP* cont \
10531055
|I32 has_my
10541056
Apda |OP* |newMETHOP |I32 type|I32 flags|NN OP* dynamic_meth
@@ -1339,7 +1341,7 @@ Ap |HEK* |share_hek |NN const char* str|I32 len|U32 hash
13391341
#if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
13401342
: Used in perl.c
13411343
np |Signal_t |sighandler |int sig|NULLOK siginfo_t *info|NULLOK void *uap
1342-
Anp |Signal_t |csighandler |int sig|NULLOK siginfo_t *info|NULLOK void *uap
1344+
Anp |Signal_t |csighandler |int sig|UNUSED NULLOK siginfo_t *info|UNUSED NULLOK void *uap
13431345
#else
13441346
np |Signal_t |sighandler |int sig
13451347
Anp |Signal_t |csighandler |int sig

op.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7587,7 +7587,8 @@ unused and should always be 1.
75877587
*/
75887588

75897589
OP *
7590-
Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
7590+
Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable PERL_UNUSED_DECL,
7591+
OP *expr, OP *block)
75917592
{
75927593
OP* listop;
75937594
OP* o;
@@ -7692,7 +7693,7 @@ loop body to be enclosed in its own scope.
76927693
*/
76937694

76947695
OP *
7695-
Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop,
7696+
Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable PERL_UNUSED_DECL, LOOP *loop,
76967697
OP *expr, OP *block, OP *cont, I32 has_my)
76977698
{
76987699
dVAR;

proto.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,7 @@ PERL_CALLCONV OP* Perl_newLOOPEX(pTHX_ I32 type, OP* label)
29862986
#define PERL_ARGS_ASSERT_NEWLOOPEX \
29872987
assert(label)
29882988

2989-
PERL_CALLCONV OP* Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP* expr, OP* block)
2989+
PERL_CALLCONV OP* Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable PERL_UNUSED_DECL, OP* expr, OP* block)
29902990
__attribute__malloc__
29912991
__attribute__warn_unused_result__;
29922992

@@ -3181,7 +3181,7 @@ PERL_CALLCONV OP* Perl_newWHENOP(pTHX_ OP* cond, OP* block)
31813181
#define PERL_ARGS_ASSERT_NEWWHENOP \
31823182
assert(block)
31833183

3184-
PERL_CALLCONV OP* Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP* loop, OP* expr, OP* block, OP* cont, I32 has_my)
3184+
PERL_CALLCONV OP* Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable PERL_UNUSED_DECL, LOOP* loop, OP* expr, OP* block, OP* cont, I32 has_my)
31853185
__attribute__malloc__
31863186
__attribute__warn_unused_result__;
31873187

@@ -5836,45 +5836,39 @@ PERL_CALLCONV void Perl_dump_sv_child(pTHX_ SV *sv)
58365836

58375837
#endif
58385838
#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
5839-
PERL_CALLCONV I32 Perl_do_ipcctl(pTHX_ I32 optype, SV** mark, SV** sp)
5840-
__attribute__nonnull__(pTHX_2)
5841-
__attribute__nonnull__(pTHX_3);
5839+
PERL_CALLCONV I32 Perl_do_ipcctl(pTHX_ I32 optype, SV** mark, SV** sp PERL_UNUSED_DECL)
5840+
__attribute__nonnull__(pTHX_2);
58425841
#define PERL_ARGS_ASSERT_DO_IPCCTL \
5843-
assert(mark); assert(sp)
5842+
assert(mark)
58445843

5845-
PERL_CALLCONV I32 Perl_do_ipcget(pTHX_ I32 optype, SV** mark, SV** sp)
5846-
__attribute__nonnull__(pTHX_2)
5847-
__attribute__nonnull__(pTHX_3);
5844+
PERL_CALLCONV I32 Perl_do_ipcget(pTHX_ I32 optype, SV** mark, SV** sp PERL_UNUSED_DECL)
5845+
__attribute__nonnull__(pTHX_2);
58485846
#define PERL_ARGS_ASSERT_DO_IPCGET \
5849-
assert(mark); assert(sp)
5847+
assert(mark)
58505848

5851-
PERL_CALLCONV I32 Perl_do_msgrcv(pTHX_ SV** mark, SV** sp)
5852-
__attribute__nonnull__(pTHX_1)
5853-
__attribute__nonnull__(pTHX_2);
5849+
PERL_CALLCONV I32 Perl_do_msgrcv(pTHX_ SV** mark, SV** sp PERL_UNUSED_DECL)
5850+
__attribute__nonnull__(pTHX_1);
58545851
#define PERL_ARGS_ASSERT_DO_MSGRCV \
5855-
assert(mark); assert(sp)
5852+
assert(mark)
58565853

5857-
PERL_CALLCONV I32 Perl_do_msgsnd(pTHX_ SV** mark, SV** sp)
5858-
__attribute__nonnull__(pTHX_1)
5859-
__attribute__nonnull__(pTHX_2);
5854+
PERL_CALLCONV I32 Perl_do_msgsnd(pTHX_ SV** mark, SV** sp PERL_UNUSED_DECL)
5855+
__attribute__nonnull__(pTHX_1);
58605856
#define PERL_ARGS_ASSERT_DO_MSGSND \
5861-
assert(mark); assert(sp)
5857+
assert(mark)
58625858

5863-
PERL_CALLCONV I32 Perl_do_semop(pTHX_ SV** mark, SV** sp)
5864-
__attribute__nonnull__(pTHX_1)
5865-
__attribute__nonnull__(pTHX_2);
5859+
PERL_CALLCONV I32 Perl_do_semop(pTHX_ SV** mark, SV** sp PERL_UNUSED_DECL)
5860+
__attribute__nonnull__(pTHX_1);
58665861
#define PERL_ARGS_ASSERT_DO_SEMOP \
5867-
assert(mark); assert(sp)
5862+
assert(mark)
58685863

5869-
PERL_CALLCONV I32 Perl_do_shmio(pTHX_ I32 optype, SV** mark, SV** sp)
5870-
__attribute__nonnull__(pTHX_2)
5871-
__attribute__nonnull__(pTHX_3);
5864+
PERL_CALLCONV I32 Perl_do_shmio(pTHX_ I32 optype, SV** mark, SV** sp PERL_UNUSED_DECL)
5865+
__attribute__nonnull__(pTHX_2);
58725866
#define PERL_ARGS_ASSERT_DO_SHMIO \
5873-
assert(mark); assert(sp)
5867+
assert(mark)
58745868

58755869
#endif
58765870
#if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
5877-
PERL_CALLCONV Signal_t Perl_csighandler(int sig, siginfo_t *info, void *uap);
5871+
PERL_CALLCONV Signal_t Perl_csighandler(int sig, siginfo_t *info PERL_UNUSED_DECL, void *uap PERL_UNUSED_DECL);
58785872
PERL_CALLCONV Signal_t Perl_sighandler(int sig, siginfo_t *info, void *uap);
58795873
#endif
58805874
#if defined(HAVE_INTERP_INTERN)

regen/embed.pl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ sub open_print_header {
7575
}
7676

7777
my ($flags,$retval,$plain_func,@args) = @$_;
78-
my @nonnull;
78+
my (@nonnull, @unused, @names_of_nn, $func);
7979
my $has_context = ( $flags !~ /n/ );
8080
my $never_returns = ( $flags =~ /r/ );
8181
my $commented_out = ( $flags =~ /m/ );
8282
my $binarycompat = ( $flags =~ /b/ );
8383
my $is_malloc = ( $flags =~ /a/ );
8484
my $can_ignore = ( $flags !~ /R/ ) && !$is_malloc;
85-
my @names_of_nn;
86-
my $func;
8785

8886
if (! $can_ignore && $retval eq 'void') {
8987
warn "It is nonsensical to require the return value of a void function ($plain_func) to be checked";
@@ -134,6 +132,12 @@ sub open_print_header {
134132
warn "$func: $arg needs NN or NULLOK\n";
135133
++$unflagged_pointers;
136134
}
135+
my $unused = ($arg =~ s/\s*(\bUNUSED\b)\s+// );
136+
if ($unused) {
137+
$arg .= ' PERL_UNUSED_DECL';
138+
push( @unused, $n );
139+
}
140+
137141
my $nn = ( $arg =~ s/\s*\bNN\b\s+// );
138142
push( @nonnull, $n ) if $nn;
139143

@@ -145,14 +149,15 @@ sub open_print_header {
145149
$temp_arg =~ s/\*//g;
146150
$temp_arg =~ s/\s*\bstruct\b\s*/ /g;
147151
if ( ($temp_arg ne "...")
148-
&& ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/) ) {
152+
&& ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/)
153+
&& ($temp_arg !~ / PERL_UNUSED_DECL/) ) {
149154
warn "$func: $arg ($n) doesn't have a name\n";
150155
}
151156
if ( $SPLINT && $nullok && !$commented_out ) {
152157
$arg = '/*@null@*/ ' . $arg;
153158
}
154159
if (defined $1 && $nn && !($commented_out && !$binarycompat)) {
155-
push @names_of_nn, $1;
160+
push @names_of_nn, $1 if $1 ne 'PERL_UNUSED_DECL';
156161
}
157162
}
158163
$ret .= join ", ", @args;
@@ -191,7 +196,7 @@ sub open_print_header {
191196
$args = 0;
192197
my @fmts = grep $args[$_] =~ /\b(f|pat|fmt)$/, 0..$#args;
193198
if (@fmts != 1) {
194-
die "embed.pl: '$plain_func': can't determine pattern arg\n";
199+
die "embed.pl: '$plain_func': can't determine pattern arg @fmts @args\n";
195200
}
196201
$pat = $fmts[0] + 1;
197202
}

0 commit comments

Comments
 (0)