Hi;

the C symbol is lacking introspection annotations:

/**
 * poppler_document_new_from_data:
 * @data: the pdf data contained in a char array
 * @length: the length of #data
 * @password: (allow-none): password to unlock the file with, or %NULL
 * @error: (allow-none): Return location for an error, or %NULL
 ...

The @data argument should be marked as an array, with length stored in
the @length argument, i.e.:

 @data: (array length=length): the pdf data contained in a char array

This will allow the introspection bindings to know that you're passing
an array with a specified length, instead of just a pointer.

Additionally, the (allow-none) for @password should be `(nullable)`,
as it's the new name for in arguments that allow NULL. You don't need
the (allow-none) annotation for the GError argument: the introspection
scanner already knows that those are nullable.

Ciao,
 Emmanuele.


On 10 April 2016 at 19:48, Jeremy Volkening <j...@base2bio.com> wrote:
> Hello,
>
> A few months ago I updated the Poppler module to use
> Glib::Object::Introspection to generate the bindings. I just realized
> yesterday that this broke the "new_from_data()" constructor. I realized
> this as I was wrapping librsvg 2.0 in a similar fashion
> (https://github.com/jvolkening/p5-Image-Rsvg) and came across the
> problem of passing in a Perl scalar when the underlying library wanted
> a char array pointer. I borrowed the "_unpack_unless_array_ref()"
> function from Gtk3 in that instance and it solved the problem. However,
> it doesn't seem to be working in the same way for the Poppler bindings.
> I get a "PDF document is damaged" error from the underlying libs
> regardless of what I try. For now I hacked it to use an intermediate
> file on disk but I'd like to get it working properly.
>
> I thought I'd ask for advice here first as I figured this group would
> have the most experience dealing with G::O::I-based bindings. The
> previous bindings written directly in XS (not by me) worked without
> doing anything fancy that I can see:
>
>     hPopplerDocument*
>     new_from_data( class , data , length )
>             char * class;
>             char * data;
>             int * length;
>     PREINIT:
>             PopplerDocument *document;
>     CODE:
>             g_type_init();
>             Newz(0, RETVAL, 1, hPopplerDocument );
>             document = poppler_document_new_from_data( data, length,
>                  NULL, NULL ); if( document == NULL )
>             { croak("poppler_document_new_from_data failed"); }
>             RETVAL->handle = document;
>     OUTPUT:
>             RETVAL
>
> Below is the override I added to the module with the
> non-working part commented out and the hack below it. I didn't
> include the "_unpack_unless_array_ref()" code below but it was taken
> verbatim from Gtk3. The C method expects a char array pointer, the data
> length, and an optional password (ignored for now) as parameters. If
> anyone has any advice or suggestions they would be greatly appreciated.
>
> Regards,
> Jeremy
>
>
>     sub Poppler::Document::new_from_data {
>
>         my ($class, $data) = @_;
>
>         #-----------------------------
>         # this is how it should be done, but can't get it to work yet
>         #-----------------------------
>
>         #$data = _unpack_unless_array_ref( $data );
>         #my $len = scalar(@$data);
>
>         #return Glib::Object::Introspection->invoke (
>             #$_POPPLER_BASENAME, 'Document', 'new_from_data',
>             #$class, $data, $len
>         #);
>
>         #-----------------------------
>         # this is an ugly hack to make things work
>         #-----------------------------
>
>         use File::Temp;
>         my $tmp = File::Temp->new( UNLINK => 1 );
>         print {$tmp} $data;
>         close $tmp;
>         return Poppler::Document->new_from_file("$tmp", $pwd);
>
>     }
> _______________________________________________
> gtk-perl-list mailing list
> gtk-perl-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-perl-list



-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to