buildlib/Lucy/Build/Binding/Util.pm

filter: Statementstmt 100% 33 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 6 totaltotal 87.2% 41 / 47 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
bind_all
1.0
CRAP 1.0
« autogen/include/cfish_parcel.h ↑ Summary buildlib/LucyX/Build/Binding/Search.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 package Lucy::Build::Binding::Util;
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '0.008000';
20 1 $VERSION = eval $VERSION;
21  
22 1 ▶sub bind_all {
Subroutine bind_all: called CC=1 SCAR=0.0
Pod undocumented
23 1 my $class = shift;
24 1 $class->bind_debug;
25 1 $class->bind_freezer;
26 1 $class->bind_indexfilenames;
27 1 $class->bind_sortexternal;
28 1 $class->bind_stringhelper;
29 }
30  
31 1 ▶sub bind_debug {
Subroutine bind_debug: called CC=1 SCAR=0.0
Pod undocumented
32 1 my $xs_code = <<'END_XS_CODE';
33 MODULE = Lucy PACKAGE = Lucy::Util::Debug
34  
35 #include "Lucy/Util/Debug.h"
36  
37 void
38 DEBUG_PRINT(message)
39 char *message;
40 PPCODE:
41 CFISH_UNUSED_VAR(message);
42 LUCY_DEBUG_PRINT("%s", message);
43  
44 void
45 DEBUG(message)
46 char *message;
47 PPCODE:
48 CFISH_UNUSED_VAR(message);
49 LUCY_DEBUG("%s", message);
50  
51 bool
52 DEBUG_ENABLED()
53 CODE:
54 RETVAL = LUCY_DEBUG_ENABLED;
55 OUTPUT: RETVAL
56  
57 =for comment
58  
59 Keep track of any Lucy objects that have been assigned to global Perl
60 variables. This is useful when accounting how many objects should have been
61 destroyed and diagnosing memory leaks.
62  
63 =cut
64  
65 void
66 track_globals(...)
67 PPCODE:
68 {
69 CFISH_UNUSED_VAR(items);
70 LUCY_IFDEF_DEBUG(lucy_Debug_num_globals++;);
71 }
72  
73 void
74 set_env_cache(str)
75 char *str;
76 PPCODE:
77 lucy_Debug_set_env_cache(str);
78  
79 void
80 ASSERT(maybe)
81 int maybe;
82 PPCODE:
83 CFISH_UNUSED_VAR(maybe);
84 LUCY_ASSERT(maybe, "XS ASSERT binding test");
85  
86 IV
87 num_allocated()
88 CODE:
89 RETVAL = lucy_Debug_num_allocated;
90 OUTPUT: RETVAL
91  
92 IV
93 num_freed()
94 CODE:
95 RETVAL = lucy_Debug_num_freed;
96 OUTPUT: RETVAL
97  
98 IV
99 num_globals()
100 CODE:
101 RETVAL = lucy_Debug_num_globals;
102 OUTPUT: RETVAL
103 END_XS_CODE
104  
105 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
106 parcel => "Lucy",
107 class_name => "Lucy::Util::Debug",
108 );
109 1 $binding->append_xs($xs_code);
110  
111 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
112 }
113  
114 1 ▶sub bind_freezer {
Subroutine bind_freezer: called CC=1 SCAR=0.0
Pod undocumented
115 1 my $xs_code = <<'END_XS_CODE';
116 MODULE = Lucy PACKAGE = Lucy::Util::Freezer
117  
118 void
119 freeze(obj, outstream)
120 cfish_Obj *obj;
121 lucy_OutStream *outstream;
122 PPCODE:
123 lucy_Freezer_serialize(obj, outstream);
124  
125 SV*
126 thaw(instream)
127 lucy_InStream *instream;
128 CODE:
129 cfish_Obj *obj = lucy_Freezer_thaw(instream);
130 RETVAL = CFISH_OBJ_TO_SV_NOINC(obj);
131 OUTPUT: RETVAL
132  
133 END_XS_CODE
134  
135 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
136 parcel => "Lucy",
137 class_name => "Lucy::Util::Freezer",
138 );
139 1 $binding->append_xs($xs_code);
140  
141 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
142 }
143  
144 1 ▶sub bind_indexfilenames {
Subroutine bind_indexfilenames: called CC=1 SCAR=0.0
Pod undocumented
145 1 my $xs_code = <<'END_XS_CODE';
146 MODULE = Lucy PACKAGE = Lucy::Util::IndexFileNames
147  
148 uint64_t
149 extract_gen(name)
150 cfish_String *name;
151 CODE:
152 RETVAL = lucy_IxFileNames_extract_gen(name);
153 OUTPUT: RETVAL
154  
155 SV*
156 latest_snapshot(folder)
157 lucy_Folder *folder;
158 CODE:
159 {
160 cfish_String *latest = lucy_IxFileNames_latest_snapshot(folder);
161 RETVAL = (SV*)CFISH_Str_To_Host(latest, NULL);
162 CFISH_DECREF(latest);
163 }
164 OUTPUT: RETVAL
165 END_XS_CODE
166  
167 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
168 parcel => "Lucy",
169 class_name => "Lucy::Util::IndexFileNames",
170 );
171 1 $binding->append_xs($xs_code);
172  
173 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
174 }
175  
176 1 ▶sub bind_sortexternal {
Subroutine bind_sortexternal: called CC=1 SCAR=0.0
Pod undocumented
177 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
178 parcel => "Lucy",
179 class_name => "Lucy::Util::SortExternal",
180 );
181 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
182 }
183  
184 1 ▶sub bind_stringhelper {
Subroutine bind_stringhelper: called CC=1 SCAR=0.0
Pod undocumented
185 1 my $xs_code = <<'END_XS_CODE';
186 MODULE = Lucy PACKAGE = Lucy::Util::StringHelper
187  
188 =for comment
189  
190 Turn an SV's UTF8 flag on. Equivalent to Encode::_utf8_on, but we don't have
191 to load Encode.
192  
193 =cut
194  
195 void
196 utf8_flag_on(sv)
197 SV *sv;
198 PPCODE:
199 SvUTF8_on(sv);
200  
201 =for comment
202  
203 Turn an SV's UTF8 flag off.
204  
205 =cut
206  
207 void
208 utf8_flag_off(sv)
209 SV *sv;
210 PPCODE:
211 SvUTF8_off(sv);
212  
213 SV*
214 to_base36(num)
215 uint64_t num;
216 CODE:
217 {
218 char base36[lucy_StrHelp_MAX_BASE36_BYTES];
219 size_t size = lucy_StrHelp_to_base36(num, &base36);
220 RETVAL = newSVpvn(base36, size);
221 }
222 OUTPUT: RETVAL
223  
224 =for comment
225  
226 Upgrade a SV to UTF8, converting Latin1 if necessary. Equivalent to
227 utf::upgrade().
228  
229 =cut
230  
231 void
232 utf8ify(sv)
233 SV *sv;
234 PPCODE:
235 sv_utf8_upgrade(sv);
236  
237 bool
238 utf8_valid(sv)
239 SV *sv;
240 CODE:
241 {
242 STRLEN len;
243 char *ptr = SvPV(sv, len);
244 RETVAL = cfish_Str_utf8_valid(ptr, len);
245 }
246 OUTPUT: RETVAL
247  
248 =for comment
249  
250 Concatenate one scalar onto the end of the other, ignoring UTF-8 status of the
251 second scalar. This is necessary because $not_utf8 . $utf8 results in a
252 scalar which has been infected by the UTF-8 flag of the second argument.
253  
254 =cut
255  
256 void
257 cat_bytes(sv, catted)
258 SV *sv;
259 SV *catted;
260 PPCODE:
261 {
262 STRLEN len;
263 char *ptr = SvPV(catted, len);
264 if (SvUTF8(sv)) { CFISH_THROW(CFISH_ERR, "Can't cat_bytes onto a UTF-8 SV"); }
265 sv_catpvn(sv, ptr, len);
266 }
267 END_XS_CODE
268  
269 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
270 class_name => "Lucy::Util::StringHelper",
271 );
272 1 $binding->append_xs($xs_code);
273  
274 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
275 }
276  
277 1 1;
« autogen/include/cfish_parcel.h ↑ Summary buildlib/LucyX/Build/Binding/Search.pm »