Skip to content

Commit c85d5a6

Browse files
committed
ExtUtils::ParseXS: rename most object fields
This big commit renames around 60 of the 75-or-so fields within an ExtUtils::ParseXS hash object. This is because many of the current names are confusing and follow no particular pattern. I've used the following rules of thumb: - Generally make the names longer. For example there are three fields which indicate whether the RETVAL value has been seen within a particular XSUB section, and it's not at all obvious that (for example) gotRETVAL specifically indicates having seen that var in the *OUTPUT* section. - Prefix most things with a category, e.g. xsub_ for per-XSUB values, config_ for config values etc. I've generally left miscellaneous global state un-prefixed. - Hashes (and the occasional array) are generally named as map_X_to_Y where X and Y describe the keys and values. - Booleans indicating that something in particular has been detected in the XS source file are prefixed with seen_. - Fields directly related to an XS keyword use that keyword in upper-case, e.g. xsub_seen_ALIAS. A few fields were left as-is because it would be too much effort to rename them, e.g. line and line_no should really have become in_lines and in_line_nums. A couple of fields were left as-is because they are going to be removed soon. This commit includes some minor changes to code comments and a bunch of white-space changes, e.g. wrapping code lines which have become too long. But there are no other functional changes. It could in theory break code which access the object's fields directly. WAS NOW InitFileCode bootcode_early errors error_count Overloaded map_overloaded_package_to_C_package Fallback map_package_to_fallback_string Module_cname MODULE_cname Packprefix PACKAGE_class Packid PACKAGE_C_name Package PACKAGE_name Prefix PREFIX_pattern ProtoUsed proto_behaviour_specified WantPrototypes PROTOTYPES_value interfaces seen_INTERFACE_or_MACRO typemap typemaps_object WantVersionChk VERSIONCHECK_value XSStack XS_parse_stack argtypes config_allow_argtypes except config_allow_exceptions inout config_allow_inout author_warnings config_author_warnings optimize config_optimize RetainCplusplusHierarchicalTypes config_RetainCplusplusHierarchicalTypes strip_c_func_prefix config_strip_c_func_prefix WantLineNumbers config_WantLineNumbers FH in_fh filename in_filename filepathname in_pathname XsubAliasValueClashHinted xsub_alias_clash_hinted Attributes xsub_attributes cond xsub_CASE_condition condnum xsub_CASE_condition_count func_args xsub_C_auto_function_signature deferred xsub_deferred_code_lines Full_func_name xsub_func_full_C_name pname xsub_func_full_perl_name func_name xsub_func_name XsubAliases xsub_map_alias_name_to_value XsubAliasValues xsub_map_alias_value_to_name_seen_hash proto_arg xsub_map_arg_idx_to_proto defaults xsub_map_argname_to_default args_match xsub_map_argname_to_idx in_out xsub_map_argname_to_in_out lengthof xsub_map_argname_to_islength argtype_seen xsub_map_argname_to_seen_type var_types xsub_map_argname_to_type Interfaces xsub_map_interface_name_short_to_original OverloadsThisXSUB xsub_map_overload_name_to_seen arg_list xsub_map_varname_to_seen_in_INPUT outargs xsub_map_varname_to_seen_in_OUTPUT ProtoThisXSUB xsub_prototype ret_type xsub_return_type RETVAL_code xsub_RETVAL_typemap_code ScopeThisXSUB xsub_SCOPE_enabled ALIAS xsub_seen_ALIAS interface xsub_seen_INTERFACE_or_MACRO have_OUTPUT xsub_seen_OUTPUT proto_in_this_xsub xsub_seen_PROTOTYPE have_CODE_with_RETVAL xsub_seen_RETVAL_in_CODE retvaldone xsub_seen_RETVAL_in_INPUT gotRETVAL xsub_seen_RETVAL_in_OUTPUT scope_in_this_xsub xsub_seen_SCOPE thisdone xsub_seen_THIS_in_INPUT DoSetMagic xsub_SETMAGIC_state
1 parent c1ba994 commit c85d5a6

File tree

6 files changed

+635
-539
lines changed

6 files changed

+635
-539
lines changed

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

Lines changed: 587 additions & 493 deletions
Large diffs are not rendered by default.

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Eval.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ sub eval_output_typemap_code {
4141
my ($_pxs, $_code, $_other) = @_;
4242

4343
my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
44-
= @{$_pxs}{qw(Package ALIAS func_name Full_func_name pname)};
44+
= @{$_pxs}{qw(PACKAGE_name xsub_seen_ALIAS xsub_func_name
45+
xsub_func_full_C_name xsub_func_full_perl_name)};
4546

4647
my ($var, $type, $ntype, $subtype, $arg)
4748
= @{$_other}{qw(var type ntype subtype arg)};
@@ -75,7 +76,8 @@ sub eval_input_typemap_code {
7576
my ($_pxs, $_code, $_other) = @_;
7677

7778
my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
78-
= @{$_pxs}{qw(Package ALIAS func_name Full_func_name pname)};
79+
= @{$_pxs}{qw(PACKAGE_name xsub_seen_ALIAS xsub_func_name
80+
xsub_func_full_C_name xsub_func_full_perl_name)};
7981

8082
my ($var, $type, $num, $init, $printed_name, $arg, $ntype, $argoff, $subtype)
8183
= @{$_other}{qw(var type num init printed_name arg ntype argoff subtype)};

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Utilities.pm

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ sub assign_func_args {
528528
shift @func_args if defined($class);
529529

530530
for my $arg (@func_args) {
531-
$arg =~ s/^/&/ if $self->{in_out}->{$arg};
531+
$arg =~ s/^/&/ if $self->{xsub_map_argname_to_in_out}->{$arg};
532532
}
533533
return join(", ", @func_args);
534534
}
@@ -541,7 +541,7 @@ sub assign_func_args {
541541
=item * Purpose
542542
543543
Process a CPP conditional line (C<#if> etc), to keep track of conditional
544-
nesting. In particular, it updates C<< @{$self->{XSStack}} >> which
544+
nesting. In particular, it updates C<< @{$self->{XS_parse_stack}} >> which
545545
contains the current list of nested conditions. So an C<#if> pushes, an
546546
C<#endif> pops, an C<#else> modifies etc. Each element is a hash of the
547547
form:
@@ -586,40 +586,40 @@ sub analyze_preprocessor_statements {
586586

587587
if ($statement eq 'if') {
588588
# #if or #ifdef
589-
$XSS_work_idx = @{ $self->{XSStack} };
590-
push(@{ $self->{XSStack} }, {type => 'if'});
589+
$XSS_work_idx = @{ $self->{XS_parse_stack} };
590+
push(@{ $self->{XS_parse_stack} }, {type => 'if'});
591591
}
592592
else {
593593
# An #else/#elsif/#endif.
594594

595595
$self->death("Error: '$statement' with no matching 'if'")
596-
if $self->{XSStack}->[-1]{type} ne 'if';
596+
if $self->{XS_parse_stack}->[-1]{type} ne 'if';
597597

598-
if ($self->{XSStack}->[-1]{varname}) {
598+
if ($self->{XS_parse_stack}->[-1]{varname}) {
599599
# close any '#ifdef XSubPPtmpAAAA' inserted earlier into boot code.
600-
push(@{ $self->{InitFileCode} }, "#endif\n");
600+
push(@{ $self->{bootcode_early} }, "#endif\n");
601601
push(@{ $BootCode_ref }, "#endif");
602602
}
603603

604-
my(@fns) = keys %{$self->{XSStack}->[-1]{functions}};
604+
my(@fns) = keys %{$self->{XS_parse_stack}->[-1]{functions}};
605605

606606
if ($statement ne 'endif') {
607607
# Add current functions to the hash of functions seen in previous
608608
# branch limbs, then reset for this next limb of the branch.
609-
@{$self->{XSStack}->[-1]{other_functions}}{@fns} = (1) x @fns;
610-
@{$self->{XSStack}->[-1]}{qw(varname functions)} = ('', {});
609+
@{$self->{XS_parse_stack}->[-1]{other_functions}}{@fns} = (1) x @fns;
610+
@{$self->{XS_parse_stack}->[-1]}{qw(varname functions)} = ('', {});
611611
}
612612
else {
613613
# #endif - pop stack and update new top entry
614-
my($tmp) = pop(@{ $self->{XSStack} });
614+
my($tmp) = pop(@{ $self->{XS_parse_stack} });
615615
0 while (--$XSS_work_idx
616-
&& $self->{XSStack}->[$XSS_work_idx]{type} ne 'if');
616+
&& $self->{XS_parse_stack}->[$XSS_work_idx]{type} ne 'if');
617617

618618
# For all functions declared within any limb of the just-popped
619619
# if/endif, mark them as having appeared within this limb of the
620620
# outer nested branch.
621621
push(@fns, keys %{$tmp->{other_functions}});
622-
@{$self->{XSStack}->[$XSS_work_idx]{functions}}{@fns} = (1) x @fns;
622+
@{$self->{XS_parse_stack}->[$XSS_work_idx]{functions}}{@fns} = (1) x @fns;
623623
}
624624
}
625625

@@ -771,7 +771,7 @@ sub _MsgHint {
771771
my ExtUtils::ParseXS $self = shift;
772772
my $hint = pop;
773773
my $warn_line_number = $self->current_line_number();
774-
my $ret = join("",@_) . " in $self->{filename}, line $warn_line_number\n";
774+
my $ret = join("",@_) . " in $self->{in_filename}, line $warn_line_number\n";
775775
if ($hint) {
776776
$ret .= " ($_)\n" for split /\n/, $hint;
777777
}
@@ -784,7 +784,7 @@ sub _MsgHint {
784784
sub blurt {
785785
my ExtUtils::ParseXS $self = shift;
786786
$self->Warn(@_);
787-
$self->{errors}++
787+
$self->{error_count}++
788788
}
789789

790790

@@ -793,7 +793,7 @@ sub blurt {
793793
sub death {
794794
my ExtUtils::ParseXS $self = $_[0];
795795
my $message = _MsgHint(@_,"");
796-
if ($self->{die_on_error}) {
796+
if ($self->{config_die_on_error}) {
797797
die $message;
798798
} else {
799799
warn $message;
@@ -835,7 +835,7 @@ sub check_conditional_preprocessor_statements {
835835
elsif (!$cpplevel) {
836836
$self->Warn("Warning: #else/elif/endif without #if in this function");
837837
print STDERR " (precede it with a blank line if the matching #if is outside the function)\n"
838-
if $self->{XSStack}->[-1]{type} eq 'if';
838+
if $self->{XS_parse_stack}->[-1]{type} eq 'if';
839839
return;
840840
}
841841
elsif ($cpp =~ /^\#\s*endif/) {

dist/ExtUtils-ParseXS/t/110-assign_func_args.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ my ($self, @args, $class);
1414
my ($func_args, $expected);
1515

1616
@args = qw( alpha beta gamma );
17-
$self->{in_out}->{alpha} = 'OUT';
17+
$self->{xsub_map_argname_to_in_out}->{alpha} = 'OUT';
1818
$expected = q|&alpha, beta, gamma|;
1919
$func_args = assign_func_args($self, \@args, $class);
2020
is( $func_args, $expected,
2121
"Got expected func_args: in_out true; class undefined" );
2222

2323
@args = ( 'My::Class', qw( beta gamma ) );
24-
$self->{in_out}->{beta} = 'OUT';
24+
$self->{xsub_map_argname_to_in_out}->{beta} = 'OUT';
2525
$class = 'My::Class';
2626
$expected = q|&beta, gamma|;
2727
$func_args = assign_func_args($self, \@args, $class);
2828
is( $func_args, $expected,
2929
"Got expected func_args: in_out true; class defined" );
3030

3131
@args = ( 'My::Class', qw( beta gamma ) );
32-
$self->{in_out}->{beta} = '';
32+
$self->{xsub_map_argname_to_in_out}->{beta} = '';
3333
$class = 'My::Class';
3434
$expected = q|beta, gamma|;
3535
$func_args = assign_func_args($self, \@args, $class);
3636
is( $func_args, $expected,
3737
"Got expected func_args: in_out false; class defined" );
3838

3939
@args = qw( alpha beta gamma );
40-
$self->{in_out}->{alpha} = '';
40+
$self->{xsub_map_argname_to_in_out}->{alpha} = '';
4141
$class = undef;
4242
$expected = q|alpha, beta, gamma|;
4343
$func_args = assign_func_args($self, \@args, $class);

dist/ExtUtils-ParseXS/t/113-check_cond_preproc_statements.t

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use PrimitiveCapture;
1212

1313
my $self = bless({} => 'ExtUtils::ParseXS');
1414
$self->{line} = [];
15-
$self->{XSStack} = [];
16-
$self->{XSStack}->[0] = {};
15+
$self->{XS_parse_stack} = [];
16+
$self->{XS_parse_stack}->[0] = {};
1717

1818
{
1919
$self->{line} = [
@@ -26,8 +26,8 @@ $self->{XSStack}->[0] = {};
2626
"#endif this_is_an_endif_statement",
2727
];
2828
$self->{line_no} = [ 17 .. 23 ];
29-
$self->{XSStack}->[-1]{type} = 'if';
30-
$self->{filename} = 'myfile1';
29+
$self->{XS_parse_stack}->[-1]{type} = 'if';
30+
$self->{in_filename} = 'myfile1';
3131

3232
my $rv;
3333
my $stderr = PrimitiveCapture::capture_stderr(sub {
@@ -49,8 +49,8 @@ $self->{XSStack}->[0] = {};
4949
"#endif this_is_an_endif_statement",
5050
];
5151
$self->{line_no} = [ 17 .. 23 ];
52-
$self->{XSStack}->[-1]{type} = 'if';
53-
$self->{filename} = 'myfile1';
52+
$self->{XS_parse_stack}->[-1]{type} = 'if';
53+
$self->{in_filename} = 'myfile1';
5454

5555
my $rv;
5656
my $stderr = PrimitiveCapture::capture_stderr(sub {
@@ -70,8 +70,8 @@ $self->{XSStack}->[0] = {};
7070
"#endif this_is_an_endif_statement",
7171
];
7272
$self->{line_no} = [ 17 .. 22 ];
73-
$self->{XSStack}->[-1]{type} = 'if';
74-
$self->{filename} = 'myfile1';
73+
$self->{XS_parse_stack}->[-1]{type} = 'if';
74+
$self->{in_filename} = 'myfile1';
7575

7676
my $rv;
7777
my $stderr = PrimitiveCapture::capture_stderr(sub {
@@ -99,8 +99,8 @@ $self->{XSStack}->[0] = {};
9999
"#endif this_is_an_endif_statement",
100100
];
101101
$self->{line_no} = [ 17 .. 22 ];
102-
$self->{XSStack}->[-1]{type} = 'file';
103-
$self->{filename} = 'myfile1';
102+
$self->{XS_parse_stack}->[-1]{type} = 'file';
103+
$self->{in_filename} = 'myfile1';
104104

105105
my $rv;
106106
my $stderr = PrimitiveCapture::capture_stderr(sub {
@@ -128,8 +128,8 @@ $self->{XSStack}->[0] = {};
128128
"Gamma this is not an if/elif/elsif/endif",
129129
];
130130
$self->{line_no} = [ 17 .. 22 ];
131-
$self->{XSStack}->[-1]{type} = 'if';
132-
$self->{filename} = 'myfile1';
131+
$self->{XS_parse_stack}->[-1]{type} = 'if';
132+
$self->{in_filename} = 'myfile1';
133133

134134
my $rv;
135135
my $stderr = PrimitiveCapture::capture_stderr(sub {

dist/ExtUtils-ParseXS/t/114-blurt_death_Warn.t

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ $self->{line_no} = [];
2525
'Delta',
2626
];
2727
$self->{line_no} = [ 17 .. 20 ];
28-
$self->{filename} = 'myfile1';
28+
$self->{in_filename} = 'myfile1';
2929

3030
my $message = 'Warning: Ignoring duplicate alias';
3131

3232
my $stderr = PrimitiveCapture::capture_stderr(sub {
3333
Warn( $self, $message);
3434
});
3535
like( $stderr,
36-
qr/$message in $self->{filename}, line 20/,
36+
qr/$message in $self->{in_filename}, line 20/,
3737
"Got expected Warn output",
3838
);
3939
}
@@ -47,14 +47,14 @@ $self->{line_no} = [];
4747
'Epsilon',
4848
];
4949
$self->{line_no} = [ 17 .. 20 ];
50-
$self->{filename} = 'myfile2';
50+
$self->{in_filename} = 'myfile2';
5151

5252
my $message = 'Warning: Ignoring duplicate alias';
5353
my $stderr = PrimitiveCapture::capture_stderr(sub {
5454
Warn( $self, $message);
5555
});
5656
like( $stderr,
57-
qr/$message in $self->{filename}, line 19/,
57+
qr/$message in $self->{in_filename}, line 19/,
5858
"Got expected Warn output",
5959
);
6060
}
@@ -67,14 +67,14 @@ $self->{line_no} = [];
6767
'Delta',
6868
];
6969
$self->{line_no} = [ 17 .. 21 ];
70-
$self->{filename} = 'myfile1';
70+
$self->{in_filename} = 'myfile1';
7171

7272
my $message = 'Warning: Ignoring duplicate alias';
7373
my $stderr = PrimitiveCapture::capture_stderr(sub {
7474
Warn( $self, $message);
7575
});
7676
like( $stderr,
77-
qr/$message in $self->{filename}, line 17/,
77+
qr/$message in $self->{in_filename}, line 17/,
7878
"Got expected Warn output",
7979
);
8080
}
@@ -87,16 +87,16 @@ $self->{line_no} = [];
8787
'Delta',
8888
];
8989
$self->{line_no} = [ 17 .. 20 ];
90-
$self->{filename} = 'myfile1';
91-
$self->{errors} = 0;
90+
$self->{in_filename} = 'myfile1';
91+
$self->{error_count} = 0;
9292

9393

9494
my $message = 'Error: Cannot parse function definition';
9595
my $stderr = PrimitiveCapture::capture_stderr(sub {
9696
blurt( $self, $message);
9797
});
9898
like( $stderr,
99-
qr/$message in $self->{filename}, line 20/,
99+
qr/$message in $self->{in_filename}, line 20/,
100100
"Got expected blurt output",
101101
);
102102
is( $self->report_error_count, 1, "Error count incremented correctly" );
@@ -112,15 +112,15 @@ SKIP: {
112112
'Delta',
113113
];
114114
$self->{line_no} = [ 17 .. 20 ];
115-
$self->{filename} = 'myfile1';
115+
$self->{in_filename} = 'myfile1';
116116

117117
my $message = "Code is not inside a function";
118118
eval {
119119
my $stderr = PrimitiveCapture::capture_stderr(sub {
120120
death( $self, $message);
121121
});
122122
like( $stderr,
123-
qr/$message in $self->{filename}, line 20/,
123+
qr/$message in $self->{in_filename}, line 20/,
124124
"Got expected death output",
125125
);
126126
};

0 commit comments

Comments
 (0)