Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,50 @@
package FFI::Raw::Callback;
$FFI::Raw::Callback::VERSION = '0.32';
use strict;
use warnings;
=head1 NAME
FFI::Raw::Callback - FFI::Raw function pointer type
=head1 VERSION
version 0.32
=head1 DESCRIPTION
A B<FFI::Raw::Callback> represents a function pointer to a Perl routine. It can
be passed to functions taking a C<FFI::Raw::ptr> type.
=head1 METHODS
=head2 new( $coderef, $ret_type [, $arg_type ...] )
Create a C<FFI::Raw::Callback> using the code reference C<$coderef> as body. The
signature (return and arguments types) must also be passed.
=head1 CAVEATS
For callbacks with a C<FFI::Raw::str> return type, the string value will be copied
to a private field on the callback object. The memory for this value will be
freed the next time the callback is called, or when the callback itself is freed.
For more exact control over when the return value is freed, you can instead
use C<FFI::Raw::ptr> type and return a L<FFI::Raw::MemPtr> object.
=head1 AUTHOR
Alessandro Ghedini <alexbio@cpan.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2013 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of FFI::Raw::Callback

View File

@@ -0,0 +1,91 @@
package FFI::Raw::MemPtr;
$FFI::Raw::MemPtr::VERSION = '0.32';
use strict;
use warnings;
=head1 NAME
FFI::Raw::MemPtr - FFI::Raw memory pointer type
=head1 VERSION
version 0.32
=head1 DESCRIPTION
A B<FFI::Raw::MemPtr> represents a memory pointer which can be passed to
functions taking a C<FFI::Raw::ptr> argument.
The allocated memory is automatically deallocated once the object is not in use
anymore.
=head1 METHODS
=head2 new( $length )
Allocate a new C<FFI::Raw::MemPtr> of size C<$length> bytes.
=head2 new_from_buf( $buffer, $length )
Allocate a new C<FFI::Raw::MemPtr> of size C<$length> bytes and copy C<$buffer>
into it. This can be used, for example, to pass a pointer to a function that
takes a C struct pointer, by using C<pack()> or the L<Convert::Binary::C> module
to create the actual struct content.
For example, consider the following C code
struct some_struct {
int some_int;
char some_str[];
};
extern void take_one_struct(struct some_struct *arg) {
if (arg -> some_int == 42)
puts(arg -> some_str);
}
It can be called using FFI::Raw as follows:
use FFI::Raw;
my $packed = pack('ix![p]p', 42, 'hello');
my $arg = FFI::Raw::MemPtr -> new_from_buf($packed, length $packed);
my $take_one_struct = FFI::Raw -> new(
$shared, 'take_one_struct',
FFI::Raw::void, FFI::Raw::ptr
);
$take_one_struct -> ($arg);
Which would print C<hello>.
=head2 new_from_ptr( $ptr )
Allocate a new C<FFI::Raw::MemPtr> pointing to the C<$ptr>, which can be either
a C<FFI::Raw::MemPtr> or a pointer returned by another function.
This is the C<FFI::Raw> equivalent of a pointer to a pointer.
=head2 tostr( [$length] )
Convert a C<FFI::Raw::MemPtr> to a Perl string. If C<$length> is not provided,
the length of the string will be computed using C<strlen()>.
=head1 AUTHOR
Alessandro Ghedini <alexbio@cpan.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2013 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of FFI::Raw::MemPtr

98
database/perl/vendor/lib/FFI/Raw/Ptr.pm vendored Normal file
View File

@@ -0,0 +1,98 @@
package FFI::Raw::Ptr;
$FFI::Raw::Ptr::VERSION = '0.32';
use strict;
use warnings;
=head1 NAME
FFI::Raw::Ptr - Base FFI::Raw pointer type
=head1 VERSION
version 0.32
=head1 SYNOPSIS
package Foo;
use FFI::Raw;
use base qw(FFI::Raw::Ptr);
*_foo_new = FFI::Raw -> new(
$shared, 'foo_new',
FFI::Raw::ptr
) -> coderef;
sub new {
bless shift -> SUPER::new(_foo_new());
}
*get_bar = FFI::Raw -> new(
$shared, 'foo_get_bar',
FFI::Raw::int,
FFI::Raw::ptr
) -> coderef;
*set_bar = FFI::Raw -> new(
$shared, 'foo_set_bar',
FFI::Raw::void,
FFI::Raw::ptr,
FFI::Raw::int
) -> coderef;
*DESTROY = FFI::Raw -> new(
$shared, 'foo_free',
FFI::Raw::void,
FFI::Raw::ptr
) -> coderef;
1;
package main;
my $foo = Foo -> new;
$foo -> set_bar(42);
=head1 DESCRIPTION
A B<FFI::Raw::Ptr> represents a pointer to memory which can be passed to
functions taking a C<FFI::Raw::ptr> argument.
Note that differently from L<FFI::Raw::MemPtr>, C<FFI::Raw::Ptr> pointers are
not automatically deallocated once not in use anymore.
=head1 METHODS
=head2 new( $ptr )
Create a new C<FFI::Raw::Ptr> pointing to C<$ptr>, which can be either a
C<FFI::Raw::MemPtr> or a pointer returned by a C function.
=cut
sub new {
my($class, $ptr) = @_;
bless \$ptr, $class;
}
=head1 AUTHOR
Graham Ollis <plicease@cpan.org>
Alessandro Ghedini <alexbio@cpan.org>
=head1 LICENSE AND COPYRIGHT
Copyright 2014 Alessandro Ghedini.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1; # End of FFI::Raw::Ptr