Skip to content

Parsing Gtk2 XS files gives "not a function declaration" #1

@wsdookadr

Description

@wsdookadr

Hi,

I played a bit with Devel::ParseXS, I like it a lot.
I tested it on Gtk2 version 1.249 (here on CPAN ).

I used the latest version of Devel::ParseXS, this one.

I wrote the following small script and named it test.pl. This script uses Devel::ParseXS to parse an XS file which it takes from ARGV. After it's parsed, a traversal of the AST is made. I was interested in nodes with func_name, I wanted to see what kind of attributes the nodes have.

#!/usr/bin/env perl
use strict;
use warnings;
use lib './local/lib/perl5';
use Devel::XS::AST::Boot;
use Devel::ParseXS;
use Scalar::Util qw/blessed/;
use Data::Dumper;
my $parser = Devel::ParseXS->new();
#$parser->parse_file( "/tmp/Gtk2-1.249/xs/GtkCombo.xs" );
$parser->parse_file( $ARGV[0] );
my $ast = $parser->tree;

sub traverse {
    print ref($_[0])."\n";
    my $blacklist = {
        "ARRAY" => 1,
        "HASH"  => 1,
    };
    ###################################
    # Go over all keys of the current node(the one that was
    # passed as a parameter to travers )
    # and print the attributes
    ###################################
    for my $k (%{$_[0]}) {
        next if !defined($k);
        next if !defined($_[0]->{$k});
        next if $blacklist->{ref($_[0]->{$k})};
        next if blessed($_[0]->{$k});
        print "     [ $k  ; $_[0]->{$k} ]\n";
    };
    ###################################
    # Recurse
    ###################################
    for my $c (@{$_[0]->{contents}}) {
        next if !blessed($c);
        traverse($c);
    };
};

traverse($ast);

exit 0;

Then I ran a oneliner to find out how many of the XS files in Gtk2 it parsed without throwing an error:

ls -d ../Gtk2-1.249/xs/* | xargs -I% /bin/bash -c 'source /home/user/.bashrc; perl  test.pl % >/dev/null 2>/dev/null; echo $? ; exit 0;' | sort | uniq -c

And the result was this(first column is count, second column is exit value):

84 0
101 25
27 255

So 84 out of 212. So in 39% of the XS files in Gtk2, test.pl was succesful in parsing(exit value was zero), it's pretty good considering how hard XS is to parse since it's a mix of C and custom-stuff.

In the oneliner above I redirected both stdout and stderr to /dev/null. If I redirect just stdout to /dev/null, I can find what the errors were when parsing some of the XS files. I've put those here. All of the errors were thrown in parse_file on line 11 of test.pl.

I will have a closer look at it soon. But I like the module a lot and I'll play more with it soon.

Thanks a lot for writing this module 👍

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions