| 1 |
package FFI::Platypus::Record::Meta; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use 5.008004; |
| 6 |
|
| 7 |
# ABSTRACT: FFI support for structured records data |
| 8 |
our $VERSION = '2.12'; # VERSION |
| 9 |
|
| 10 |
|
| 11 |
{ |
| 12 |
require FFI::Platypus; |
| 13 |
my $ffi = FFI::Platypus->new( |
| 14 |
api => 2, |
| 15 |
); |
| 16 |
$ffi->bundle; |
| 17 |
$ffi->mangler(sub { |
| 18 |
my($name) = @_; |
| 19 |
$name =~ s/^/ffi_platypus_record_meta__/; |
| 20 |
$name; |
| 21 |
}); |
| 22 |
|
| 23 |
$ffi->type('opaque' => 'ffi_type'); |
| 24 |
|
| 25 |
$ffi->custom_type('meta_t' => { |
| 26 |
native_type => 'opaque', |
| 27 |
perl_to_native => sub { |
| 28 |
${ $_[0] }; |
| 29 |
}, |
| 30 |
}); |
| 31 |
|
| 32 |
$ffi->attach( _find_symbol => ['string'] => 'ffi_type'); |
| 33 |
|
| 34 |
$ffi->attach( new => ['ffi_type[]','int'] => 'meta_t', sub { |
| 35 |
my($xsub, $class, $elements, $closure_safe) = @_; |
| 36 |
|
| 37 |
if(ref($elements) ne 'ARRAY') |
| 38 |
{ |
| 39 |
require Carp; |
| 40 |
Carp::croak("passed something other than a array ref to @{[ __PACKAGE__ ]}"); |
| 41 |
} |
| 42 |
|
| 43 |
my @element_type_pointers; |
| 44 |
foreach my $element_type (@$elements) |
| 45 |
{ |
| 46 |
my $ptr = _find_symbol($element_type); |
| 47 |
if($ptr) |
| 48 |
{ |
| 49 |
push @element_type_pointers, $ptr; |
| 50 |
} |
| 51 |
else |
| 52 |
{ |
| 53 |
require Carp; |
| 54 |
Carp::croak("unknown type: $element_type"); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
push @element_type_pointers, undef; |
| 59 |
|
| 60 |
my $ptr = $xsub->(\@element_type_pointers, $closure_safe); |
| 61 |
bless \$ptr, $class; |
| 62 |
}); |
| 63 |
|
| 64 |
$ffi->attach( ffi_type => ['meta_t'] => 'ffi_type' ); |
| 65 |
$ffi->attach( size => ['meta_t'] => 'size_t' ); |
| 66 |
$ffi->attach( alignment => ['meta_t'] => 'ushort' ); |
| 67 |
$ffi->attach( element_pointers => ['meta_t'] => 'ffi_type[]' ); |
| 68 |
|
| 69 |
$ffi->attach( DESTROY => ['meta_t'] => 'void' ); |
| 70 |
} |
| 71 |
|
| 72 |
sub ptr { ${ shift() } } |
| 73 |
|
| 74 |
1; |
| 75 |
|
| 76 |
__END__ |
| 77 |
|
| 78 |
=pod |
| 79 |
|
| 80 |
=encoding UTF-8 |
| 81 |
|
| 82 |
=head1 NAME |
| 83 |
|
| 84 |
FFI::Platypus::Record::Meta - FFI support for structured records data |
| 85 |
|
| 86 |
=head1 VERSION |
| 87 |
|
| 88 |
version 2.12 |
| 89 |
|
| 90 |
=head1 DESCRIPTION |
| 91 |
|
| 92 |
This class is private to FFI::Platypus. See L<FFI::Platypus::Record> for |
| 93 |
the public interface to Platypus records. |
| 94 |
|
| 95 |
=head1 AUTHOR |
| 96 |
|
| 97 |
Author: Graham Ollis E<lt>[email protected]<gt> |
| 98 |
|
| 99 |
Contributors: |
| 100 |
|
| 101 |
Bakkiaraj Murugesan (bakkiaraj) |
| 102 |
|
| 103 |
Dylan Cali (calid) |
| 104 |
|
| 105 |
pipcet |
| 106 |
|
| 107 |
Zaki Mughal (zmughal) |
| 108 |
|
| 109 |
Fitz Elliott (felliott) |
| 110 |
|
| 111 |
Vickenty Fesunov (vyf) |
| 112 |
|
| 113 |
Gregor Herrmann (gregoa) |
| 114 |
|
| 115 |
Shlomi Fish (shlomif) |
| 116 |
|
| 117 |
Damyan Ivanov |
| 118 |
|
| 119 |
Ilya Pavlov (Ilya33) |
| 120 |
|
| 121 |
Petr Písař (ppisar) |
| 122 |
|
| 123 |
Mohammad S Anwar (MANWAR) |
| 124 |
|
| 125 |
Håkon Hægland (hakonhagland, HAKONH) |
| 126 |
|
| 127 |
Meredith (merrilymeredith, MHOWARD) |
| 128 |
|
| 129 |
Diab Jerius (DJERIUS) |
| 130 |
|
| 131 |
Eric Brine (IKEGAMI) |
| 132 |
|
| 133 |
szTheory |
| 134 |
|
| 135 |
José Joaquín Atria (JJATRIA) |
| 136 |
|
| 137 |
Pete Houston (openstrike, HOUSTON) |
| 138 |
|
| 139 |
Lukas Mai (MAUKE) |
| 140 |
|
| 141 |
=head1 COPYRIGHT AND LICENSE |
| 142 |
|
| 143 |
This software is copyright (c) 2015-2022 by Graham Ollis. |
| 144 |
|
| 145 |
This is free software; you can redistribute it and/or modify it under |
| 146 |
the same terms as the Perl 5 programming language system itself. |
| 147 |
|
| 148 |
=cut |