Libtensorflow/TString.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 80 CC 2 SCAR 10.6
CC
2
Cov
0%
DESTROY
6.0
_CREATE
2.0
BEGIN
2.0
CRAP 2.9
1 package AI::TensorFlow::Libtensorflow::TString;
2 # ABSTRACT: A variable-capacity string type
3 $AI::TensorFlow::Libtensorflow::TString::VERSION = '0.0.7';
4 use strict;
5 use warnings;
6 use namespace::autoclean;
7 use AI::TensorFlow::Libtensorflow::Lib qw(arg);
8 use FFI::Platypus::Memory qw(malloc free);
9  
10 my $ffi = AI::TensorFlow::Libtensorflow::Lib->ffi;
11 $ffi->mangler(AI::TensorFlow::Libtensorflow::Lib->mangler_default);
12  
13 ### From <tensorflow/tsl/platform/ctstring_internal.h>
14 #// _Static_assert(sizeof(TF_TString) == 24);
15 use constant SIZEOF_TF_TString => 24;
16  
17  
18 ### From <tensorflow/tsl/platform/ctstring_internal.h>
19 # typedef enum TF_TString_Type { // NOLINT
20 # TF_TSTR_SMALL = 0x00,
21 # TF_TSTR_LARGE = 0x01,
22 # TF_TSTR_OFFSET = 0x02,
23 # TF_TSTR_VIEW = 0x03,
24 # TF_TSTR_TYPE_MASK = 0x03
25 # } TF_TString_Type;
26  
27 sub _CREATE {
28 my ($class) = @_;
29 my $pointer = malloc SIZEOF_TF_TString;
30 my $obj = bless { ptr => $pointer }, $class;
31 }
32  
33 $ffi->attach( [ 'StringInit' => 'Init' ] => [
34 arg 'TF_TString' => 'tstr'
35 ] => 'void' => sub {
36 my ($xs, $invoc) = @_;
37 my $obj = ref $invoc ? $invoc : $invoc->_CREATE();
38 $xs->($obj);
39 $obj;
40 });
41  
42 $ffi->attach( [ 'StringCopy' => 'Copy' ] => [
43 arg TF_TString => 'dst',
44 arg tf_text_buffer => [ qw( src size ) ],
45 ] => 'void' );
46  
47 $ffi->attach( [ 'StringAssignView' => 'AssignView' ] => [
48 arg TF_TString => 'dst',
49 arg tf_text_buffer => [ qw( src size ) ],
50 ] => 'void' );
51  
52 $ffi->attach( [ 'StringGetDataPointer' => 'GetDataPointer' ] => [
53 arg TF_TString => 'tstr',
54 ] => 'opaque' );
55  
56 $ffi->attach( [ 'StringGetType' => 'GetType' ] => [
57 arg TF_TString => 'str'
58 ] => 'int' );
59  
60 $ffi->attach( [ 'StringGetSize' => 'GetSize' ] => [
61 arg TF_TString => 'tstr'
62 ] => 'size_t' );
63  
64 $ffi->attach( [ 'StringGetCapacity' => 'GetCapacity' ] => [
65 arg TF_TString => 'str'
66 ] => 'size_t' );
67  
68 $ffi->attach( [ 'StringDealloc' => 'Dealloc' ] => [
69 arg TF_TString => 'tstr',
70 ] => 'void' );
71  
72 sub DESTROY {
73 if( ! $_[0]->{owner} ) {
74 $_[0]->Dealloc;
75 free $_[0]->{ptr};
76 }
77 }
78  
79 1;
80  
81 __END__