line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::Platypus::Legacy::Raw::MemPtr; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
53
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
252
|
|
4
|
7
|
|
|
7
|
|
39
|
use warnings; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
235
|
|
5
|
7
|
|
|
7
|
|
42
|
use Carp qw( croak ); |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
347
|
|
6
|
7
|
|
|
7
|
|
60
|
use FFI::Platypus::Legacy::Raw::Platypus; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
434
|
|
7
|
7
|
|
|
7
|
|
56
|
use FFI::Platypus::Memory qw( malloc free memcpy ); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
425
|
|
8
|
7
|
|
|
7
|
|
3325
|
use FFI::Platypus::Buffer qw( scalar_to_buffer buffer_to_scalar ); |
|
7
|
|
|
|
|
3903
|
|
|
7
|
|
|
|
|
3359
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: FFI::Platypus::Legacy::Raw memory pointer type |
11
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw( FFI::Platypus::Legacy::Raw::Ptr ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
17
|
|
|
|
|
|
|
{ |
18
|
3
|
|
|
3
|
1
|
3480
|
my($class, $size) = @_; |
19
|
3
|
|
|
|
|
15
|
my $ptr = malloc $size; |
20
|
3
|
50
|
|
|
|
10
|
die "malloc failed" unless defined $ptr; |
21
|
3
|
|
|
|
|
10
|
bless \$ptr, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub DESTROY |
25
|
|
|
|
|
|
|
{ |
26
|
9
|
|
|
9
|
|
2477
|
my($self) = @_; |
27
|
9
|
|
|
|
|
51
|
free $$self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new_from_buf |
32
|
|
|
|
|
|
|
{ |
33
|
4
|
|
|
4
|
1
|
9595
|
my($class, undef, $size) = @_; |
34
|
4
|
|
|
|
|
22
|
my $dst = malloc $size; |
35
|
4
|
|
|
|
|
50
|
my($src, undef) = scalar_to_buffer $_[1]; |
36
|
4
|
|
|
|
|
55
|
memcpy $dst, $src, $size; |
37
|
4
|
|
|
|
|
17
|
bless \$dst, $class; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
_ffi_package |
42
|
|
|
|
|
|
|
->attach( |
43
|
|
|
|
|
|
|
['ffi__platypus__legacy__raw__memptr__new_from_ptr' => |
44
|
|
|
|
|
|
|
'_new_from_ptr'] |
45
|
|
|
|
|
|
|
=> ['opaque'] => 'opaque' |
46
|
|
|
|
|
|
|
) |
47
|
|
|
|
|
|
|
; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new_from_ptr |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
1
|
14
|
my($class, $src) = @_; |
52
|
2
|
100
|
|
|
|
8
|
if(ref $src) |
53
|
|
|
|
|
|
|
{ |
54
|
1
|
50
|
|
|
|
2
|
if(eval { $src->isa('FFI::Platypus::Legacy::Raw::Ptr') }) |
|
1
|
|
|
|
|
6
|
|
55
|
|
|
|
|
|
|
{ |
56
|
1
|
|
|
|
|
41
|
$src = $$src; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
24
|
my $dst = _new_from_ptr($src); |
60
|
2
|
|
|
|
|
7
|
bless \$dst, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
_ffi_package->attach_cast('_opaque_to_string', 'opaque' => 'string'); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
## NOTE: prototype for a method is kind of dumb but we are including it for |
67
|
|
|
|
|
|
|
## full compatability with FFI::Raw |
68
|
|
|
|
|
|
|
sub to_perl_str ($;$) |
69
|
|
|
|
|
|
|
{ |
70
|
4
|
|
|
4
|
1
|
1267
|
my($self, $size) = @_; |
71
|
4
|
100
|
|
|
|
17
|
if(@_ == 1) |
|
|
50
|
|
|
|
|
|
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
|
|
12
|
return _opaque_to_string($$self); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif(@_ == 2) |
76
|
|
|
|
|
|
|
{ |
77
|
3
|
|
|
|
|
12
|
return buffer_to_scalar($$self, $size); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
|
croak "Wrong number of arguments"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub tostr { |
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
return $self->to_perl_str(@_) |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |