You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2010/02/19 18:33:38 UTC
svn commit: r911870 [1/2] - in /lucene/lucy/trunk: charmonizer/
charmonizer/src/Charmonizer/Probe/ clownfish/lib/Clownfish/Binding/
clownfish/lib/Clownfish/Binding/Perl/ core/Lucy/Index/ core/Lucy/Object/
core/Lucy/Store/ core/Lucy/Test/Index/ core/Luc...
Author: marvin
Date: Fri Feb 19 17:33:37 2010
New Revision: 911870
URL: http://svn.apache.org/viewvc?rev=911870&view=rev
Log:
Deploy alloca(). Add the Charmonizer Memory module. Change meaning of
ZCB_BLANK, remove ZCB_make and add ZCB_WRAP. Hide struct definition of
ZombieCharBuf almost everywhere. Simplify the autogenerated Perl bindings
since we no longer need an intermediate automatic ZombieCharBuf for wrapping a
string (since we can pass raw memory from alloca() instead). (alloca.diff
from LUCY-100)
Added:
lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.c (with props)
lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.h (with props)
Modified:
lucene/lucy/trunk/charmonizer/charmonize.c
lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl.pm
lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm
lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm
lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm
lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm
lucene/lucy/trunk/core/Lucy/Index/Segment.c
lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp
lucene/lucy/trunk/core/Lucy/Object/CharBuf.c
lucene/lucy/trunk/core/Lucy/Object/Hash.c
lucene/lucy/trunk/core/Lucy/Object/VTable.c
lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c
lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c
lucene/lucy/trunk/core/Lucy/Store/FSFolder.c
lucene/lucy/trunk/core/Lucy/Store/Folder.c
lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c
lucene/lucy/trunk/core/Lucy/Test/Index/TestSegment.c
lucene/lucy/trunk/core/Lucy/Test/Object/TestHash.c
lucene/lucy/trunk/core/Lucy/Test/Object/TestObj.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestCompoundFileReader.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestFSDirHandle.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFileHandle.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestFileHandle.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestInStream.c
lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c
lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c
lucene/lucy/trunk/core/Lucy/Test/Util/TestJson.c
lucene/lucy/trunk/core/Lucy/Util/IndexFileNames.c
lucene/lucy/trunk/core/Lucy/Util/ToolSet.h
lucene/lucy/trunk/perl/lib/Lucy/Object/Hash.pm
lucene/lucy/trunk/perl/lib/Lucy/Object/Obj.pm
lucene/lucy/trunk/perl/lib/Lucy/Util/IndexFileNames.pm
lucene/lucy/trunk/perl/xs/XSBind.c
lucene/lucy/trunk/perl/xs/XSBind.h
Modified: lucene/lucy/trunk/charmonizer/charmonize.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/charmonize.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/charmonize.c (original)
+++ lucene/lucy/trunk/charmonizer/charmonize.c Fri Feb 19 17:33:37 2010
@@ -12,6 +12,7 @@
#include "Charmonizer/Probe/Headers.h"
#include "Charmonizer/Probe/Integers.h"
#include "Charmonizer/Probe/LargeFiles.h"
+#include "Charmonizer/Probe/Memory.h"
#include "Charmonizer/Probe/UnusedVars.h"
#include "Charmonizer/Probe/VariadicMacros.h"
#include "Charmonizer/Core/HeaderChecker.h"
@@ -43,6 +44,7 @@
chaz_Integers_run();
chaz_Floats_run();
chaz_LargeFiles_run();
+ chaz_Memory_run();
chaz_UnusedVars_run();
chaz_VariadicMacros_run();
@@ -50,6 +52,13 @@
if (chaz_HeadCheck_check_header("sys/mman.h")) {
chaz_ConfWriter_append_conf("#define CHY_HAS_SYS_MMAN_H\n\n");
}
+ chaz_ConfWriter_append_conf(
+ "#ifdef CHY_HAS_ALLOCA_H\n"
+ " #include <alloca.h>\n"
+ "#elif defined(CHY_HAS_MALLOC_H)\n"
+ " #include <malloc.h>\n"
+ "#endif\n\n"
+ );
/* Clean up. */
chaz_Probe_clean_up();
@@ -58,7 +67,7 @@
}
/**
- * Copyright 2006-2009 The Apache Software Foundation
+ * Copyright 2006-2010 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.c?rev=911870&view=auto
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.c (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.c Fri Feb 19 17:33:37 2010
@@ -0,0 +1,90 @@
+#define CHAZ_USE_SHORT_NAMES
+
+#include "Charmonizer/Probe/Memory.h"
+#include "Charmonizer/Core/Compiler.h"
+#include "Charmonizer/Core/HeaderChecker.h"
+#include "Charmonizer/Core/ConfWriter.h"
+#include "Charmonizer/Core/Util.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char alloca_code[] =
+ "#include <%s>\n"
+ QUOTE( int main() { )
+ QUOTE( void *foo = %s(1); )
+ QUOTE( return 0; )
+ QUOTE( } );
+
+void
+Memory_run(void)
+{
+ chaz_bool_t has_alloca_h = false;
+ chaz_bool_t has_malloc_h = false;
+ chaz_bool_t has_alloca = false;
+ chaz_bool_t has_underscore_alloca = false;
+ char code_buf[sizeof(alloca_code) + 100];
+
+ ConfWriter_start_module("Memory");
+
+ /* Unixen. */
+ sprintf(code_buf, alloca_code, "alloca.h", "alloca");
+ if (CC_test_compile(code_buf, strlen(code_buf))) {
+ has_alloca_h = true;
+ has_alloca = true;
+ ConfWriter_append_conf("#define CHY_HAS_ALLOCA_H\n");
+ ConfWriter_append_conf("#define chy_alloca alloca\n");
+ }
+
+ /* Windows. */
+ if (!has_alloca) {
+ sprintf(code_buf, alloca_code, "malloc.h", "alloca");
+ if (CC_test_compile(code_buf, strlen(code_buf))) {
+ has_malloc_h = true;
+ has_alloca = true;
+ ConfWriter_append_conf("#define CHY_HAS_MALLOC_H\n");
+ ConfWriter_append_conf("#define chy_alloca alloca\n");
+ }
+ }
+ if (!has_alloca) {
+ sprintf(code_buf, alloca_code, "malloc.h", "_alloca");
+ if (CC_test_compile(code_buf, strlen(code_buf))) {
+ has_malloc_h = true;
+ has_underscore_alloca = true;
+ ConfWriter_append_conf("#define CHY_HAS_MALLOC_H\n");
+ ConfWriter_append_conf("#define chy_alloca _alloca\n");
+ }
+ }
+
+ /* Shorten */
+ ConfWriter_start_short_names();
+ if (has_alloca_h) {
+ ConfWriter_shorten_macro("HAS_ALLOCA_H");
+ }
+ if (has_malloc_h) {
+ ConfWriter_shorten_macro("HAS_MALLOC_H");
+ if (!has_alloca && has_underscore_alloca) {
+ ConfWriter_shorten_function("alloca");
+ }
+ }
+ ConfWriter_end_short_names();
+
+ ConfWriter_end_module();
+}
+
+/**
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
Propchange: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.h?rev=911870&view=auto
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.h (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.h Fri Feb 19 17:33:37 2010
@@ -0,0 +1,50 @@
+/* Charmonizer/Probe/Memory.h
+ */
+
+#ifndef H_CHAZ_MEMORY
+#define H_CHAZ_MEMORY
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The Memory module attempts to detect these symbols or alias them to
+ * synonyms:
+ *
+ * alloca
+ *
+ * These following symbols will be defined if the associated headers are
+ * available:
+ *
+ * HAS_ALLOCA_H <alloca.h>
+ * HAS_MALLOC_H <malloc.h>
+ */
+void chaz_Memory_run(void);
+
+#ifdef CHAZ_USE_SHORT_NAMES
+ #define Memory_run chaz_Memory_run
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CHAZ_MEMORY */
+
+
+/**
+ * Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
Propchange: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe/Memory.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl.pm?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl.pm Fri Feb 19 17:33:37 2010
@@ -159,7 +159,6 @@
sub _xs_file_contents {
my ( $self, $generated_xs, $xs_init, $hand_rolled_xs ) = @_;
return <<END_STUFF;
-#define C_LUCY_ZOMBIECHARBUF
#include "xs/XSBind.h"
#include "boil.h"
#include "$self->{boot_h_file}"
Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Constructor.pm Fri Feb 19 17:33:37 2010
@@ -60,7 +60,6 @@
my $val = $arg_inits->[$i];
my $name = $var->micro_sym;
my $sv_name = $name . "_sv";
- my $stack_name = $name . "_zcb";
my $type = $var->get_type;
my $len = length $name;
@@ -68,7 +67,7 @@
$allot_params .= qq| &$sv_name, "$name", $len,\n|;
# Create code for determining and validating value.
- my $statement = from_perl( $type, $name, $sv_name, $stack_name );
+ my $statement = from_perl( $type, $name, $sv_name );
if ( defined $val ) {
my $assignment = qq|if ($sv_name && XSBind_sv_defined($sv_name)) {
$statement
Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Method.pm Fri Feb 19 17:33:37 2010
@@ -125,7 +125,6 @@
my $var = $arg_vars->[$i];
my $val = $arg_inits->[$i];
my $var_name = $var->micro_sym;
- my $stack_name = $var_name . '_zcb';
my $var_type = $var->get_type;
my $statement;
if ( $i == 0 ) { # $self
@@ -133,8 +132,7 @@
= _self_assign_statement( $var_type, $method->micro_sym );
}
else {
- $statement
- = from_perl( $var_type, $var_name, "ST($i)", $stack_name );
+ $statement = from_perl( $var_type, $var_name, "ST($i)" );
}
if ( defined $val ) {
$statement
@@ -206,7 +204,6 @@
my $val = $arg_inits->[$i];
my $name = $var->micro_sym;
my $sv_name = $name . "_sv";
- my $stack_name = $name . "_zcb";
my $type = $var->get_type;
my $len = length $name;
@@ -214,7 +211,7 @@
$allot_params .= qq| &$sv_name, "$name", $len,\n|;
# Code for determining and validating value.
- my $statement = from_perl( $type, $name, $sv_name, $stack_name );
+ my $statement = from_perl( $type, $name, $sv_name );
if ( defined $val ) {
my $assignment
= qq|if ( $sv_name && XSBind_sv_defined($sv_name) ) {
Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Subroutine.pm Fri Feb 19 17:33:37 2010
@@ -86,19 +86,7 @@
sub var_declarations {
my $self = shift;
my $arg_vars = $self->{param_list}->get_variables;
- my @var_declarations;
- for my $i ( 0 .. $#$arg_vars ) {
- my $arg_var = $arg_vars->[$i];
- push @var_declarations, $arg_var->local_declaration;
- next if $i == 0; # no ZombieCharBuf for $self.
- next
- unless $arg_var->get_type->get_specifier
- =~ /^lucy_(Obj|CharBuf)$/;
- push @var_declarations,
- 'lucy_ZombieCharBuf '
- . $arg_var->micro_sym
- . '_zcb = LUCY_ZCB_BLANK;';
- }
+ my @var_declarations = map { $_->local_declaration } @$arg_vars;
if ( !$self->{retval_type}->is_void ) {
my $return_type = $self->{retval_type}->to_c;
push @var_declarations, "$return_type retval;";
Modified: lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm (original)
+++ lucene/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/TypeMap.pm Fri Feb 19 17:33:37 2010
@@ -90,21 +90,20 @@
# Extract a Clownfish object from a Perl SV.
sub _sv_to_bp_obj {
- my ( $type, $bp_var, $xs_var, $stack_var ) = @_;
+ my ( $type, $bp_var, $xs_var ) = @_;
my $struct_sym = $type->get_specifier;
my $vtable = uc($struct_sym);
- my $third_arg;
if ( $struct_sym =~ /^[a-z_]*(Obj|CharBuf)$/ ) {
# Share buffers rather than copy between Perl scalars and BP string
# types. Assume that the appropriate ZombieCharBuf has been declared
# on the stack.
- $third_arg = "&$stack_var";
+ return "$bp_var = ($struct_sym*)XSBind_sv_to_lucy_obj($xs_var, "
+ . "$vtable, alloca(lucy_ZCB_size()));"
}
else {
- $third_arg = 'NULL';
+ return "$bp_var = ($struct_sym*)XSBind_sv_to_lucy_obj($xs_var, "
+ . "$vtable, NULL);";
}
- return "$bp_var = ($struct_sym*)XSBind_sv_to_lucy_obj($xs_var, "
- . "$vtable, $third_arg);";
}
sub _void_star_to_lucy {
@@ -120,12 +119,12 @@
}
sub from_perl {
- my ( $type, $bp_var, $xs_var, $stack_var ) = @_;
+ my ( $type, $bp_var, $xs_var ) = @_;
confess("Not a Clownfish::Type")
unless blessed($type) && $type->isa('Clownfish::Type');
if ( $type->is_object ) {
- return _sv_to_bp_obj( $type, $bp_var, $xs_var, $stack_var );
+ return _sv_to_bp_obj( $type, $bp_var, $xs_var );
}
elsif ( $type->is_primitive ) {
if ( my $sub = $primitives_from_perl{ $type->to_c } ) {
@@ -216,7 +215,7 @@
chy_u32_t\tCHY_UNSIGNED_INT
chy_u64_t\tCHY_BIG_UNSIGNED_INT
-lucy_ZombieCharBuf\tZOMBIECHARBUF_NOT_POINTER
+const lucy_CharBuf*\tCONST_CHARBUF
END_STUFF
return $content;
@@ -251,8 +250,8 @@
CHY_BIG_UNSIGNED_INT
$big_unsigned_convert
-ZOMBIECHARBUF_NOT_POINTER
- \$var = lucy_ZCB_make_str(SvPVutf8_nolen(\$arg), SvCUR(\$arg));
+CONST_CHARBUF
+ \$var = (const lucy_CharBuf*)LUCY_ZCB_WRAP_STR(SvPVutf8_nolen(\$arg), SvCUR(\$arg));
END_STUFF
}
@@ -310,7 +309,7 @@
=head2 from_perl
- my $c_code = from_perl( $type, $bp_var, $xs_var, $stack_var );
+ my $c_code = from_perl( $type, $bp_var, $xs_var );
Return C code which converts from a Perl scalar to a variable of type $type.
@@ -327,14 +326,6 @@
=item * B<xs_var> - The C name of the Perl scalar from which we are extracting
a value.
-=item * B<stack_var> - Only required needed when C<type> is
-Clownfish::Object indicating that C<bp_var> is an either an Obj or a
-CharBuf. When passing strings or other simple types to Clownfish functions
-from Perl, we allow the user to supply simple scalars rather than forcing them
-to create Clownfish objects. We do this by creating a ZombieCharBuf on the
-stack and assigning the string from the Perl scalar to it. C<stack_var> is
-the name of that ZombieCharBuf wrapper.
-
=back
=head2 to_perl
Modified: lucene/lucy/trunk/core/Lucy/Index/Segment.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Index/Segment.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Index/Segment.c (original)
+++ lucene/lucy/trunk/core/Lucy/Index/Segment.c Fri Feb 19 17:33:37 2010
@@ -174,8 +174,8 @@
Seg_store_metadata_str(Segment *self, const char *key, size_t key_len,
Obj *value)
{
- ZombieCharBuf k = ZCB_make_str((char*)key, key_len);
- Seg_Store_Metadata(self, (CharBuf*)&k, value);
+ ZombieCharBuf *k = ZCB_WRAP_STR((char*)key, key_len);
+ Seg_Store_Metadata(self, (CharBuf*)k, value);
}
Obj*
Modified: lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/CharBuf.bp Fri Feb 19 17:33:37 2010
@@ -330,6 +330,31 @@
class Lucy::Object::ZombieCharBuf cnick ZCB
extends Lucy::Object::ViewCharBuf {
+ /** Return a ZombieCharBuf with a blank string.
+ */
+ inert incremented ZombieCharBuf*
+ new(void *allocation);
+
+ /**
+ * @param allocation A single block of memory which will be used for both
+ * the ZombieCharBuf object and its buffer.
+ * @param alloc_size The size of the allocation.
+ * @param pattern A format pattern.
+ */
+ inert incremented ZombieCharBuf*
+ newf(void *allocation, size_t alloc_size, const char *pattern, ...);
+
+ inert incremented ZombieCharBuf*
+ wrap(void *allocation, const CharBuf *source);
+
+ inert incremented ZombieCharBuf*
+ wrap_str(void *allocation, const char *ptr, size_t size);
+
+ /** Return the size for a ZombieCharBuf struct.
+ */
+ inert size_t
+ size();
+
/** Throws an error.
*/
public void
@@ -338,29 +363,25 @@
__C__
-#define LUCY_ZCB_BLANK \
- { LUCY_ZOMBIECHARBUF, {1}, "", 0, 0 }
+#define LUCY_ZCB_BLANK() lucy_ZCB_new(alloca(lucy_ZCB_size()))
+
#define LUCY_ZCB_LITERAL(string) \
{ LUCY_ZOMBIECHARBUF, {1}, string "", sizeof(string) -1, sizeof(string) }
-extern lucy_ZombieCharBuf LUCY_ZCB_EMPTY;
-
-#ifdef C_LUCY_ZOMBIECHARBUF
-/* Simple functions which allows assignment idiom for ZombieCharBuf values.
- */
-lucy_ZombieCharBuf
-lucy_ZCB_make_str(const char *ptr, size_t size);
+#define LUCY_ZCB_WRAP(source) \
+ lucy_ZCB_wrap(alloca(lucy_ZCB_size()), source)
+
+#define LUCY_ZCB_WRAP_STR(ptr, size) \
+ lucy_ZCB_wrap_str(alloca(lucy_ZCB_size()), ptr, size)
-lucy_ZombieCharBuf
-lucy_ZCB_make(const lucy_CharBuf *source);
-#endif /* C_LUCY_ZOMBIECHARBUF */
+extern lucy_ZombieCharBuf LUCY_ZCB_EMPTY;
#ifdef LUCY_USE_SHORT_NAMES
#define ZCB_BLANK LUCY_ZCB_BLANK
#define ZCB_LITERAL(_string) LUCY_ZCB_LITERAL(_string)
#define EMPTY LUCY_ZCB_EMPTY
- #define ZCB_make lucy_ZCB_make
- #define ZCB_make_str lucy_ZCB_make_str
+ #define ZCB_WRAP LUCY_ZCB_WRAP
+ #define ZCB_WRAP_STR LUCY_ZCB_WRAP_STR
#endif
__END_C__
Modified: lucene/lucy/trunk/core/Lucy/Object/CharBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/CharBuf.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/CharBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/CharBuf.c Fri Feb 19 17:33:37 2010
@@ -37,7 +37,7 @@
static void
S_die_invalid_pattern(const char *pattern);
-ZombieCharBuf EMPTY = ZCB_BLANK;
+ZombieCharBuf EMPTY = { ZOMBIECHARBUF, {1}, "", 0, 0 };
CharBuf*
CB_new(size_t size)
@@ -127,13 +127,13 @@
CB_hash_code(CharBuf *self)
{
u32_t hashvalue = 5381;
- ZombieCharBuf iterator = ZCB_make(self);
+ ZombieCharBuf *iterator = ZCB_WRAP(self);
{
const CB_nip_one_t nip_one
- = (CB_nip_one_t)METHOD(iterator.vtable, CB, Nip_One);
- while (iterator.size) {
- u32_t code_point = (u32_t)nip_one((CharBuf*)&iterator);
+ = (CB_nip_one_t)METHOD(iterator->vtable, CB, Nip_One);
+ while (iterator->size) {
+ u32_t code_point = (u32_t)nip_one((CharBuf*)iterator);
hashvalue = ((hashvalue << 5) + hashvalue) ^ code_point;
}
}
@@ -145,15 +145,17 @@
S_grow(CharBuf *self, size_t size)
{
if (size >= self->cap) {
- self->cap = size + 1;
- self->ptr = (char*)REALLOCATE(self->ptr, self->cap);
+ CB_Grow(self, size);
}
}
char*
CB_grow(CharBuf *self, size_t size)
{
- if (size >= self->cap) { S_grow(self, size); }
+ if (size >= self->cap) {
+ self->cap = size + 1;
+ self->ptr = (char*)REALLOCATE(self->ptr, self->cap);
+ }
return self->ptr;
}
@@ -394,19 +396,19 @@
i64_t
CB_basex_to_i64(CharBuf *self, u32_t base)
{
- ZombieCharBuf iterator = ZCB_make(self);
+ ZombieCharBuf *iterator = ZCB_WRAP(self);
i64_t retval = 0;
bool_t is_negative = false;
/* Advance past minus sign. */
- if (ZCB_Code_Point_At(&iterator, 0) == '-') {
- ZCB_Nip_One(&iterator);
+ if (ZCB_Code_Point_At(iterator, 0) == '-') {
+ ZCB_Nip_One(iterator);
is_negative = true;
}
/* Accumulate. */
- while (iterator.size) {
- i32_t code_point = ZCB_Nip_One(&iterator);
+ while (iterator->size) {
+ i32_t code_point = ZCB_Nip_One(iterator);
if (isalnum(code_point)) {
i32_t addend = isdigit(code_point)
? code_point - '0'
@@ -696,9 +698,9 @@
CB_truncate(CharBuf *self, size_t count)
{
u32_t num_code_points;
- ZombieCharBuf iterator = ZCB_make(self);
- num_code_points = ZCB_Nip(&iterator, count);
- self->size -= iterator.size;
+ ZombieCharBuf *iterator = ZCB_WRAP(self);
+ num_code_points = ZCB_Nip(iterator, count);
+ self->size -= iterator->size;
return num_code_points;
}
@@ -733,14 +735,14 @@
CharBuf*
CB_substring(CharBuf *self, size_t offset, size_t len)
{
- ZombieCharBuf iterator = ZCB_make(self);
+ ZombieCharBuf *iterator = ZCB_WRAP(self);
char *sub_start;
size_t byte_len;
- ZCB_Nip(&iterator, offset);
- sub_start = iterator.ptr;
- ZCB_Nip(&iterator, len);
- byte_len = iterator.ptr - sub_start;
+ ZCB_Nip(iterator, offset);
+ sub_start = iterator->ptr;
+ ZCB_Nip(iterator, len);
+ byte_len = iterator->ptr - sub_start;
return CB_new_from_trusted_utf8(sub_start, byte_len);
}
@@ -750,16 +752,16 @@
{
const CharBuf *a = *(const CharBuf**)va;
const CharBuf *b = *(const CharBuf**)vb;
- ZombieCharBuf iterator_a = ZCB_make(a);
- ZombieCharBuf iterator_b = ZCB_make(b);
- while (iterator_a.size && iterator_b.size) {
- i32_t code_point_a = ZCB_Nip_One(&iterator_a);
- i32_t code_point_b = ZCB_Nip_One(&iterator_b);
+ ZombieCharBuf *iterator_a = ZCB_WRAP(a);
+ ZombieCharBuf *iterator_b = ZCB_WRAP(b);
+ while (iterator_a->size && iterator_b->size) {
+ i32_t code_point_a = ZCB_Nip_One(iterator_a);
+ i32_t code_point_b = ZCB_Nip_One(iterator_b);
const i32_t comparison = code_point_a - code_point_b;
if (comparison != 0) return comparison;
}
- if (iterator_a.size != iterator_b.size) {
- return iterator_a.size < iterator_b.size ? -1 : 1;
+ if (iterator_a->size != iterator_b->size) {
+ return iterator_a->size < iterator_b->size ? -1 : 1;
}
return 0;
}
@@ -891,22 +893,60 @@
/*****************************************************************/
-ZombieCharBuf
-ZCB_make_str(const char *ptr, size_t size)
+ZombieCharBuf*
+ZCB_new(void *allocation)
{
- ZombieCharBuf retval;
- retval.ref.count = 1;
- retval.vtable = ZOMBIECHARBUF;
- retval.cap = 0;
- retval.size = size;
- retval.ptr = (char*)ptr;
- return retval;
+ static char empty_string[] = "";
+ ZombieCharBuf *self = (ZombieCharBuf*)allocation;
+ self->ref.count = 1;
+ self->vtable = ZOMBIECHARBUF;
+ self->cap = 0;
+ self->size = 0;
+ self->ptr = empty_string;
+ return self;
}
-ZombieCharBuf
-ZCB_make(const CharBuf *source)
+ZombieCharBuf*
+ZCB_newf(void *allocation, size_t alloc_size, const char *pattern, ...)
+{
+ ZombieCharBuf *self = (ZombieCharBuf*)allocation;
+
+ self->ref.count = 1;
+ self->vtable = ZOMBIECHARBUF;
+ self->cap = alloc_size - sizeof(ZombieCharBuf);
+ self->size = 0;
+ self->ptr = ((char*)allocation) + sizeof(ZombieCharBuf);
+
+ va_list args;
+ va_start(args, pattern);
+ ZCB_VCatF(self, pattern, args);
+ va_end(args);
+
+ return self;
+}
+
+ZombieCharBuf*
+ZCB_wrap_str(void *allocation, const char *ptr, size_t size)
+{
+ ZombieCharBuf *self = (ZombieCharBuf*)allocation;
+ self->ref.count = 1;
+ self->vtable = ZOMBIECHARBUF;
+ self->cap = 0;
+ self->size = size;
+ self->ptr = (char*)ptr;
+ return self;
+}
+
+ZombieCharBuf*
+ZCB_wrap(void *allocation, const CharBuf *source)
+{
+ return ZCB_wrap_str(allocation, source->ptr, source->size);
+}
+
+size_t
+ZCB_size()
{
- return ZCB_make_str(source->ptr, source->size);
+ return sizeof(ZombieCharBuf);
}
void
Modified: lucene/lucy/trunk/core/Lucy/Object/Hash.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Hash.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Hash.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Hash.c Fri Feb 19 17:33:37 2010
@@ -1,5 +1,4 @@
#define C_LUCY_HASH
-#define C_LUCY_ZOMBIECHARBUF
#define LUCY_USE_SHORT_NAMES
#define CHY_USE_SHORT_NAMES
@@ -292,9 +291,9 @@
void
Hash_store_str(Hash *self, const char *key, size_t key_len, Obj *value)
{
- ZombieCharBuf key_buf = ZCB_make_str((char*)key, key_len);
- lucy_Hash_do_store(self, (Obj*)&key_buf, value,
- ZCB_Hash_Code(&key_buf), false);
+ ZombieCharBuf *key_buf = ZCB_WRAP_STR((char*)key, key_len);
+ lucy_Hash_do_store(self, (Obj*)key_buf, value,
+ ZCB_Hash_Code(key_buf), false);
}
Obj*
@@ -308,8 +307,8 @@
Obj*
Hash_fetch_str(Hash *self, const char *key, size_t key_len)
{
- ZombieCharBuf key_buf = ZCB_make_str(key, key_len);
- return Hash_fetch(self, (Obj*)&key_buf);
+ ZombieCharBuf *key_buf = ZCB_WRAP_STR(key, key_len);
+ return Hash_fetch(self, (Obj*)key_buf);
}
static INLINE HashEntry*
@@ -364,8 +363,8 @@
Obj*
Hash_delete_str(Hash *self, const char *key, size_t key_len)
{
- ZombieCharBuf key_buf = ZCB_make_str(key, key_len);
- return Hash_delete(self, (Obj*)&key_buf);
+ ZombieCharBuf *key_buf = ZCB_WRAP_STR(key, key_len);
+ return Hash_delete(self, (Obj*)key_buf);
}
u32_t
Modified: lucene/lucy/trunk/core/Lucy/Object/VTable.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/VTable.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/VTable.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/VTable.c Fri Feb 19 17:33:37 2010
@@ -1,6 +1,5 @@
#define C_LUCY_VTABLE
#define C_LUCY_OBJ
-#define C_LUCY_ZOMBIECHARBUF
#define LUCY_USE_SHORT_NAMES
#define CHY_USE_SHORT_NAMES
@@ -140,7 +139,7 @@
Hash *meths = Hash_new(num_novel);
u32_t i;
CharBuf *scrunched = CB_new(0);
- ZombieCharBuf callback_name = ZCB_BLANK;
+ ZombieCharBuf *callback_name = ZCB_BLANK();
for (i = 0; i < num_novel; i++) {
CharBuf *meth = (CharBuf*)VA_fetch(novel_host_methods, i);
S_scrunch_charbuf(meth, scrunched);
@@ -148,9 +147,9 @@
}
for (i = 0; singleton->callbacks[i] != NULL; i++) {
lucy_Callback *const callback = singleton->callbacks[i];
- ZCB_Assign_Str(&callback_name, callback->name,
+ ZCB_Assign_Str(callback_name, callback->name,
callback->name_len);
- S_scrunch_charbuf((CharBuf*)&callback_name, scrunched);
+ S_scrunch_charbuf((CharBuf*)callback_name, scrunched);
if (Hash_Fetch(meths, (Obj*)scrunched)) {
VTable_Override(singleton, callback->func,
callback->offset);
@@ -201,10 +200,10 @@
static void
S_scrunch_charbuf(CharBuf *source, CharBuf *target)
{
- ZombieCharBuf iterator = ZCB_make(source);
+ ZombieCharBuf *iterator = ZCB_WRAP(source);
CB_Set_Size(target, 0);
- while (ZCB_Get_Size(&iterator)) {
- u32_t code_point = ZCB_Nip_One(&iterator);
+ while (ZCB_Get_Size(iterator)) {
+ u32_t code_point = ZCB_Nip_One(iterator);
if (code_point > 127) {
THROW(ERR, "Can't fold case for %o", source);
}
Modified: lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/CompoundFileReader.c Fri Feb 19 17:33:37 2010
@@ -10,9 +10,6 @@
#include "Lucy/Util/Json.h"
#include "Lucy/Util/StringHelper.h"
-static ZombieCharBuf cf_file = ZCB_LITERAL("cf.dat");
-static ZombieCharBuf cfmeta_file = ZCB_LITERAL("cfmeta.json");
-
CompoundFileReader*
CFReader_open(Folder *folder)
{
@@ -24,15 +21,15 @@
CompoundFileReader*
CFReader_do_open(CompoundFileReader *self, Folder *folder)
{
- Hash *metadata = (Hash*)Json_slurp_json((Folder*)folder,
- (CharBuf*)&cfmeta_file);
+ CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
+ Hash *metadata = (Hash*)Json_slurp_json((Folder*)folder, cfmeta_file);
Err *error = NULL;
Folder_init((Folder*)self, Folder_Get_Path(folder));
/* Parse metadata file. */
if (!metadata || !Hash_Is_A(metadata, HASH)) {
- error = Err_new(CB_newf("Can't read '%o' in '%o'", &cfmeta_file,
+ error = Err_new(CB_newf("Can't read '%o' in '%o'", cfmeta_file,
Folder_Get_Path(folder)));
}
else {
@@ -42,7 +39,7 @@
if (self->format < 1) {
error = Err_new(CB_newf(
"Corrupt %o file: Missing or invalid 'format'",
- &cfmeta_file));
+ cfmeta_file));
}
else if (self->format > CFWriter_current_file_format) {
error = Err_new(CB_newf("Unsupported compound file format: %i32 "
@@ -51,7 +48,7 @@
}
else if (!self->records) {
error = Err_new(CB_newf("Corrupt %o file: missing 'files' key",
- &cfmeta_file));
+ cfmeta_file));
}
}
DECREF(metadata);
@@ -62,7 +59,8 @@
}
/* Open an instream which we'll clone over and over. */
- self->instream = Folder_Open_In(folder, (CharBuf*)&cf_file);
+ CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
+ self->instream = Folder_Open_In(folder, cf_file);
if(!self->instream) {
ERR_ADD_FRAME(Err_get_error());
DECREF(self);
@@ -75,18 +73,18 @@
/* Strip directory name from filepaths for old format. */
if (self->format == 1) {
VArray *files = Hash_Keys(self->records);
- ZombieCharBuf filename = ZCB_BLANK;
- ZombieCharBuf folder_name = ZCB_BLANK;
- IxFileNames_local_part(Folder_Get_Path(folder), &folder_name);
- size_t folder_name_len = ZCB_Length(&folder_name);
+ ZombieCharBuf *filename = ZCB_BLANK();
+ ZombieCharBuf *folder_name
+ = IxFileNames_local_part(Folder_Get_Path(folder), ZCB_BLANK());
+ size_t folder_name_len = ZCB_Length(folder_name);
for (uint32_t i = 0, max = VA_Get_Size(files); i < max; i++) {
CharBuf *orig = (CharBuf*)VA_Fetch(files, i);
- if (CB_Starts_With(orig, (CharBuf*)&folder_name)) {
+ if (CB_Starts_With(orig, (CharBuf*)folder_name)) {
Obj *record = Hash_Delete(self->records, (Obj*)orig);
- ZCB_Assign(&filename, orig);
- ZCB_Nip(&filename, folder_name_len + sizeof(DIR_SEP) - 1);
- Hash_Store(self->records, (Obj*)&filename, (Obj*)record);
+ ZCB_Assign(filename, orig);
+ ZCB_Nip(filename, folder_name_len + sizeof(DIR_SEP) - 1);
+ Hash_Store(self->records, (Obj*)filename, (Obj*)record);
}
}
@@ -150,10 +148,12 @@
/* Once the number of virtual files falls to 0, remove the compound
* files. */
if (Hash_Get_Size(self->records) == 0) {
- if (!Folder_Delete(self->real_folder, (CharBuf*)&cf_file)) {
+ CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
+ if (!Folder_Delete(self->real_folder, cf_file)) {
return false;
}
- if (!Folder_Delete(self->real_folder, (CharBuf*)&cfmeta_file)) {
+ CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
+ if (!Folder_Delete(self->real_folder, cfmeta_file)) {
return false;
}
@@ -183,10 +183,12 @@
return NULL;
}
else if (CB_Get_Size(self->path)) {
- CharBuf *fullpath = CB_newf("%o/%o", self->path, name);
- InStream *instream = InStream_Reopen(self->instream, fullpath,
- Obj_To_I64(offset), Obj_To_I64(len));
- DECREF(fullpath);
+ size_t size = ZCB_size() + CB_Get_Size(self->path)
+ + CB_Get_Size(name) + 10;
+ CharBuf *fullpath = (CharBuf*)ZCB_newf(alloca(size), size,
+ "%o/%o", self->path, name);
+ InStream *instream = InStream_Reopen(self->instream,
+ fullpath, Obj_To_I64(offset), Obj_To_I64(len));
return instream;
}
else {
Modified: lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/CompoundFileWriter.c Fri Feb 19 17:33:37 2010
@@ -10,10 +10,6 @@
i32_t CFWriter_current_file_format = 1;
-static ZombieCharBuf cfmeta_file = ZCB_LITERAL("cfmeta.json");
-static ZombieCharBuf cfmeta_temp = ZCB_LITERAL("cfmeta.json.temp");
-static ZombieCharBuf cf_file = ZCB_LITERAL("cf.dat");
-
/* Helper which does the heavy lifting for CFWriter_consolidate. */
static void
S_do_consolidate(CompoundFileWriter *self);
@@ -47,7 +43,8 @@
void
CFWriter_consolidate(CompoundFileWriter *self)
{
- if (Folder_Exists(self->folder, (CharBuf*)&cfmeta_file)) {
+ CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
+ if (Folder_Exists(self->folder, cfmeta_file)) {
THROW(ERR, "Merge already performed for %o",
Folder_Get_Path(self->folder));
}
@@ -60,16 +57,18 @@
static void
S_clean_up_old_temp_files(CompoundFileWriter *self)
{
- Folder *folder = self->folder;
-
- if (Folder_Exists(folder, (CharBuf*)&cf_file)) {
- if (!Folder_Delete(folder, (CharBuf*)&cf_file)) {
- THROW(ERR, "Can't delete '%o'", &cf_file);
+ Folder *folder = self->folder;
+ CharBuf *cfmeta_temp = (CharBuf*)ZCB_WRAP_STR("cfmeta.json.temp", 16);
+ CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
+
+ if (Folder_Exists(folder, cf_file)) {
+ if (!Folder_Delete(folder, cf_file)) {
+ THROW(ERR, "Can't delete '%o'", cf_file);
}
}
- if (Folder_Exists(folder, (CharBuf*)&cfmeta_temp)) {
- if (!Folder_Delete(folder, (CharBuf*)&cfmeta_temp)) {
- THROW(ERR, "Can't delete '%o'", &cfmeta_temp);
+ if (Folder_Exists(folder, cfmeta_temp)) {
+ if (!Folder_Delete(folder, cfmeta_temp)) {
+ THROW(ERR, "Can't delete '%o'", cfmeta_temp);
}
}
}
@@ -82,7 +81,8 @@
Hash *sub_files = Hash_new(0);
VArray *files = Folder_List(folder, NULL);
VArray *merged = VA_new(VA_Get_Size(files));
- OutStream *outstream = Folder_Open_Out(folder, (CharBuf*)&cf_file);
+ CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
+ OutStream *outstream = Folder_Open_Out(folder, (CharBuf*)cf_file);
u32_t i, max;
bool_t rename_success;
@@ -97,10 +97,10 @@
* earlier releases. */
CharBuf *infilepath = CB_new(30);
bool_t base_len = 0;
- ZombieCharBuf seg_name = ZCB_BLANK;
- IxFileNames_local_part(Folder_Get_Path(folder), &seg_name);
- if (ZCB_Starts_With_Str(&seg_name, "seg_", 4)) {
- CB_setf(infilepath, "%o/", &seg_name);
+ ZombieCharBuf *seg_name
+ = IxFileNames_local_part(Folder_Get_Path(folder), ZCB_BLANK());
+ if (ZCB_Starts_With_Str(seg_name, "seg_", 4)) {
+ CB_setf(infilepath, "%o/", seg_name);
base_len = CB_Get_Size(infilepath);
}
@@ -141,10 +141,10 @@
DECREF(infilepath);
/* Write metadata to cfmeta file. */
- Json_spew_json((Obj*)metadata, (Folder*)self->folder,
- (CharBuf*)&cfmeta_temp);
- rename_success = Folder_Rename(self->folder, (CharBuf*)&cfmeta_temp,
- (CharBuf*)&cfmeta_file);
+ CharBuf *cfmeta_temp = (CharBuf*)ZCB_WRAP_STR("cfmeta.json.temp", 16);
+ CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
+ Json_spew_json((Obj*)metadata, (Folder*)self->folder, cfmeta_temp);
+ rename_success = Folder_Rename(self->folder, cfmeta_temp, cfmeta_file);
if (!rename_success) { RETHROW(INCREF(Err_get_error())); }
/* Clean up. */
Modified: lucene/lucy/trunk/core/Lucy/Store/FSFolder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/FSFolder.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/FSFolder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/FSFolder.c Fri Feb 19 17:33:37 2010
@@ -35,9 +35,15 @@
#include "Lucy/Store/OutStream.h"
#include "Lucy/Util/IndexFileNames.h"
-/* Return a new CharBuf containing a platform-specific absolute filepath. */
+/* Return a ZombieCharBuf (cast to CharBuf) containing a platform-specific
+ * absolute filepath. */
static CharBuf*
-S_fullpath(FSFolder *self, const CharBuf *path);
+S_fullpath(FSFolder *self, const CharBuf *path, void *allocation,
+ size_t alloc_size);
+#define FULLPATH(self, _path) \
+ S_fullpath(self, _path, alloca( \
+ ZCB_size() + CB_Get_Size(self->path) + CB_Get_Size(_path) + 10), \
+ ZCB_size() + CB_Get_Size(self->path) + CB_Get_Size(_path) + 10)
/* Return true if the supplied path is a directory. */
static bool_t
@@ -86,21 +92,19 @@
FileHandle*
FSFolder_local_open_filehandle(FSFolder *self, const CharBuf *name, u32_t flags)
{
- CharBuf *fullpath = S_fullpath(self, name);
+ CharBuf *fullpath = FULLPATH(self, name);
FSFileHandle *fh = FSFH_open(fullpath, flags);
if (!fh) {
ERR_ADD_FRAME(Err_get_error());
}
- DECREF(fullpath);
return (FileHandle*)fh;
}
bool_t
FSFolder_local_mkdir(FSFolder *self, const CharBuf *name)
{
- CharBuf *dir = S_fullpath(self, name);
+ CharBuf *dir = FULLPATH(self, name);
bool_t result = S_create_dir(dir);
- DECREF(dir);
if (!result) {
ERR_ADD_FRAME(Err_get_error());
}
@@ -126,11 +130,10 @@
}
else {
struct stat stat_buf;
- CharBuf *fullpath = S_fullpath(self, name);
+ CharBuf *fullpath = FULLPATH(self, name);
bool_t retval = false;
if (stat((char*)CB_Get_Ptr8(fullpath), &stat_buf) != -1)
retval = true;
- DECREF(fullpath);
return retval;
}
}
@@ -144,9 +147,8 @@
return true;
}
else {
- CharBuf *fullpath = S_fullpath(self, name);
+ CharBuf *fullpath = FULLPATH(self, name);
bool_t result = S_dir_ok(fullpath);
- DECREF(fullpath);
return result;
}
}
@@ -154,16 +156,14 @@
bool_t
FSFolder_rename(FSFolder *self, const CharBuf* from, const CharBuf *to)
{
- CharBuf *from_path = S_fullpath(self, from);
- CharBuf *to_path = S_fullpath(self, to);
+ CharBuf *from_path = FULLPATH(self, from);
+ CharBuf *to_path = FULLPATH(self, to);
bool_t retval = !rename((char*)CB_Get_Ptr8(from_path),
(char*)CB_Get_Ptr8(to_path));
if (!retval) {
Err_set_error(Err_new(CB_newf("rename from '%o' to '%o' failed: %s",
from_path, to_path, strerror(errno))));
}
- DECREF(to_path);
- DECREF(from_path);
return retval;
}
@@ -171,8 +171,8 @@
FSFolder_hard_link(FSFolder *self, const CharBuf *from,
const CharBuf *to)
{
- CharBuf *from_path = S_fullpath(self, from);
- CharBuf *to_path = S_fullpath(self, to);
+ CharBuf *from_path = FULLPATH(self, from);
+ CharBuf *to_path = FULLPATH(self, to);
char *from8 = (char*)CB_Get_Ptr8(from_path);
char *to8 = (char*)CB_Get_Ptr8(to_path);
#ifdef CHY_HAS_UNISTD_H
@@ -196,22 +196,19 @@
FREEMEM(win_error);
}
#endif
- DECREF(to_path);
- DECREF(from_path);
return retval;
}
bool_t
FSFolder_local_delete(FSFolder *self, const CharBuf *name)
{
- CharBuf *fullpath = S_fullpath(self, name);
+ CharBuf *fullpath = FULLPATH(self, name);
char *path_ptr = (char*)CB_Get_Ptr8(fullpath);
#ifdef CHY_REMOVE_ZAPS_DIRS
bool_t result = !remove(path_ptr);
#else
bool_t result = !rmdir(path_ptr) || !remove(path_ptr);
#endif
- DECREF(fullpath);
DECREF(Hash_Delete(self->entries, (Obj*)name));
return result;
}
@@ -243,8 +240,7 @@
}
{
- CharBuf *fullpath = S_fullpath(self, name);
- static ZombieCharBuf cfmeta_file = ZCB_LITERAL("cfmeta.json");
+ CharBuf *fullpath = FULLPATH(self, name);
if (S_dir_ok(fullpath)) {
subfolder = (Folder*)FSFolder_new(fullpath);
if (!subfolder) {
@@ -252,7 +248,8 @@
}
/* Try to open a CompoundFileReader. On failure, just use the
* existing folder. */
- if (Folder_Local_Exists(subfolder, (CharBuf*)&cfmeta_file)) {
+ CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
+ if (Folder_Local_Exists(subfolder, cfmeta_file)) {
CompoundFileReader *cf_reader = CFReader_open(subfolder);
if (cf_reader) {
DECREF(subfolder);
@@ -260,24 +257,19 @@
}
}
Hash_Store(self->entries, (Obj*)name, (Obj*)subfolder);
- DECREF(fullpath);
return subfolder;
}
- else {
- DECREF(fullpath);
- }
}
return NULL;
}
static CharBuf*
-S_fullpath(FSFolder *self, const CharBuf *path)
+S_fullpath(FSFolder *self, const CharBuf *path, void *allocation,
+ size_t alloc_size)
{
- CharBuf *fullpath = CB_new(200);
- CB_Cat(fullpath, self->path);
- CB_Cat_Trusted_Str(fullpath, DIR_SEP, sizeof(DIR_SEP) - 1);
- CB_Cat(fullpath, path);
+ CharBuf *fullpath = (CharBuf*)ZCB_newf(allocation, alloc_size, "%o%s%o",
+ self->path, DIR_SEP, path);
if (DIR_SEP[0] != '/') {
CB_Swap_Chars(fullpath, '/', DIR_SEP[0]);
}
@@ -308,9 +300,9 @@
bool_t
S_is_local_entry(const CharBuf *path)
{
- ZombieCharBuf scratch = ZCB_make(path);
+ ZombieCharBuf *scratch = ZCB_WRAP(path);
u32_t code_point;
- while (0 != (code_point = ZCB_Nip_One(&scratch))) {
+ while (0 != (code_point = ZCB_Nip_One(scratch))) {
if (code_point == '/') { return false; }
}
return true;
Modified: lucene/lucy/trunk/core/Lucy/Store/Folder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/Folder.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/Folder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/Folder.c Fri Feb 19 17:33:37 2010
@@ -53,8 +53,7 @@
InStream *instream = NULL;
if (enclosing_folder) {
- ZombieCharBuf name_zcb = ZCB_BLANK;
- ZombieCharBuf *name = IxFileNames_local_part(path, &name_zcb);
+ ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
instream = Folder_Local_Open_In(enclosing_folder, (CharBuf*)name);
if (!instream) {
ERR_ADD_FRAME(Err_get_error());
@@ -114,8 +113,7 @@
FileHandle *fh = NULL;
if (enclosing_folder) {
- ZombieCharBuf name_zcb = ZCB_BLANK;
- ZombieCharBuf *name = IxFileNames_local_part(path, &name_zcb);
+ ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
fh = Folder_Local_Open_FileHandle(enclosing_folder,
(CharBuf*)name, flags);
if (!fh) {
@@ -134,8 +132,7 @@
{
Folder *enclosing_folder = Folder_Enclosing_Folder(self, path);
if (enclosing_folder) {
- ZombieCharBuf name_zcb = ZCB_BLANK;
- ZombieCharBuf *name = IxFileNames_local_part(path, &name_zcb);
+ ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
bool_t result = Folder_Local_Delete(enclosing_folder, (CharBuf*)name);
return result;
}
@@ -153,8 +150,7 @@
if (!path || !CB_Get_Size(path)) { return false; }
if (enclosing_folder) {
- ZombieCharBuf entry_zcb = ZCB_BLANK;
- ZombieCharBuf *local = IxFileNames_local_part(path, &entry_zcb);
+ ZombieCharBuf *local = IxFileNames_local_part(path, ZCB_BLANK());
if (Folder_Local_Is_Directory(enclosing_folder, (CharBuf*)local)) {
Folder *inner_folder
= Folder_Local_Find_Folder(enclosing_folder, (CharBuf*)local);
@@ -273,8 +269,7 @@
"Can't recursively create dir %o", path)));
}
else {
- ZombieCharBuf name_zcb = ZCB_BLANK;
- ZombieCharBuf *name = IxFileNames_local_part(path, &name_zcb);
+ ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
result = Folder_Local_MkDir(enclosing_folder, (CharBuf*)name);
if (!result) {
ERR_ADD_FRAME(Err_get_error());
@@ -290,8 +285,7 @@
Folder *enclosing_folder = Folder_Enclosing_Folder(self, path);
bool_t retval = false;
if (enclosing_folder) {
- ZombieCharBuf name_zcb = ZCB_BLANK;
- ZombieCharBuf *name = IxFileNames_local_part(path, &name_zcb);
+ ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
if (Folder_Local_Exists(enclosing_folder, (CharBuf*)name)) {
retval = true;
}
@@ -386,8 +380,7 @@
CFWriter_Consolidate(cf_writer);
DECREF(cf_writer);
if (CB_Get_Size(path)) {
- ZombieCharBuf name_zcb = ZCB_BLANK;
- ZombieCharBuf *name = IxFileNames_local_part(path, &name_zcb);
+ ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
CompoundFileReader *cf_reader = CFReader_open(folder);
if (!cf_reader) { RETHROW(INCREF(Err_get_error())); }
Hash_Store(enclosing_folder->entries, (Obj*)name,
@@ -399,8 +392,6 @@
static Folder*
S_enclosing_folder(Folder *self, ZombieCharBuf *path)
{
- ZombieCharBuf scratch;
- ZombieCharBuf path_component;
size_t path_component_len = 0;
u32_t code_point;
@@ -408,11 +399,11 @@
if (ZCB_Code_Point_From(path, 0) == '/') { ZCB_Chop(path, 1); }
/* Find first component of the file path. */
- scratch = ZCB_make((CharBuf*)path);
- path_component = ZCB_make((CharBuf*)path);
- while (0 != (code_point = ZCB_Nip_One(&scratch))) {
+ ZombieCharBuf *scratch = ZCB_WRAP((CharBuf*)path);
+ ZombieCharBuf *path_component = ZCB_WRAP((CharBuf*)path);
+ while (0 != (code_point = ZCB_Nip_One(scratch))) {
if (code_point == '/') {
- ZCB_Truncate(&path_component, path_component_len);
+ ZCB_Truncate(path_component, path_component_len);
ZCB_Nip(path, path_component_len + 1);
break;
}
@@ -420,11 +411,11 @@
}
/** If we've eaten up the entire filepath, self is enclosing folder. */
- if (ZCB_Get_Size(&scratch) == 0) { return self; }
+ if (ZCB_Get_Size(scratch) == 0) { return self; }
{
Folder *local_folder
- = Folder_Local_Find_Folder(self, (CharBuf*)&path_component);
+ = Folder_Local_Find_Folder(self, (CharBuf*)path_component);
if (!local_folder) {
/* This element of the filepath doesn't exist, or it's not a
* directory. However, there are filepath characters left over,
@@ -441,8 +432,8 @@
Folder*
Folder_enclosing_folder(Folder *self, const CharBuf *path)
{
- ZombieCharBuf scratch = ZCB_make(path);
- return S_enclosing_folder(self, &scratch);
+ ZombieCharBuf *scratch = ZCB_WRAP(path);
+ return S_enclosing_folder(self, scratch);
}
Folder*
@@ -452,14 +443,14 @@
return self;
}
else {
- ZombieCharBuf scratch = ZCB_make(path);
- Folder *enclosing_folder = S_enclosing_folder(self, &scratch);
+ ZombieCharBuf *scratch = ZCB_WRAP(path);
+ Folder *enclosing_folder = S_enclosing_folder(self, scratch);
if (!enclosing_folder) {
return NULL;
}
else {
return Folder_Local_Find_Folder(enclosing_folder,
- (CharBuf*)&scratch);
+ (CharBuf*)scratch);
}
}
}
Modified: lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/RAMFolder.c Fri Feb 19 17:33:37 2010
@@ -262,10 +262,8 @@
{
Folder *from_folder = RAMFolder_Enclosing_Folder(self, from);
Folder *to_folder = RAMFolder_Enclosing_Folder(self, to);
- ZombieCharBuf from_zbc = ZCB_BLANK;
- ZombieCharBuf to_zbc = ZCB_BLANK;
- ZombieCharBuf *from_name = IxFileNames_local_part(from, &from_zbc);
- ZombieCharBuf *to_name = IxFileNames_local_part(to, &to_zbc);
+ ZombieCharBuf *from_name = IxFileNames_local_part(from, ZCB_BLANK());
+ ZombieCharBuf *to_name = IxFileNames_local_part(to, ZCB_BLANK());
bool_t result = S_rename_or_hard_link(self, from, to,
from_folder, to_folder, from_name, to_name, OP_RENAME);
if (!result) { ERR_ADD_FRAME(Err_get_error()); }
@@ -277,10 +275,8 @@
{
Folder *from_folder = RAMFolder_Enclosing_Folder(self, from);
Folder *to_folder = RAMFolder_Enclosing_Folder(self, to);
- ZombieCharBuf from_zbc = ZCB_BLANK;
- ZombieCharBuf to_zbc = ZCB_BLANK;
- ZombieCharBuf *from_name = IxFileNames_local_part(from, &from_zbc);
- ZombieCharBuf *to_name = IxFileNames_local_part(to, &to_zbc);
+ ZombieCharBuf *from_name = IxFileNames_local_part(from, ZCB_BLANK());
+ ZombieCharBuf *to_name = IxFileNames_local_part(to, ZCB_BLANK());
bool_t result = S_rename_or_hard_link(self, from, to,
from_folder, to_folder, from_name, to_name, OP_HARD_LINK);
if (!result) { ERR_ADD_FRAME(Err_get_error()); }
Modified: lucene/lucy/trunk/core/Lucy/Test/Index/TestSegment.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Index/TestSegment.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Index/TestSegment.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Index/TestSegment.c Fri Feb 19 17:33:37 2010
@@ -10,27 +10,27 @@
test_fields(TestBatch *batch)
{
Segment *segment = Seg_new(1);
- ZombieCharBuf foo = ZCB_LITERAL("foo");
- ZombieCharBuf bar = ZCB_LITERAL("bar");
- ZombieCharBuf baz = ZCB_LITERAL("baz");
+ ZombieCharBuf *foo = ZCB_WRAP_STR("foo",3 );
+ ZombieCharBuf *bar = ZCB_WRAP_STR("bar", 3);
+ ZombieCharBuf *baz = ZCB_WRAP_STR("baz", 3);
i32_t field_num;
- field_num = Seg_Add_Field(segment, (CharBuf*)&foo);
+ field_num = Seg_Add_Field(segment, (CharBuf*)foo);
ASSERT_TRUE(batch, field_num == 1,
"Add_Field returns field number, and field numbers start at 1");
- field_num = Seg_Add_Field(segment, (CharBuf*)&bar);
+ field_num = Seg_Add_Field(segment, (CharBuf*)bar);
ASSERT_TRUE(batch, field_num == 2, "add a second field");
- field_num = Seg_Add_Field(segment, (CharBuf*)&foo);
+ field_num = Seg_Add_Field(segment, (CharBuf*)foo);
ASSERT_TRUE(batch, field_num == 1,
"Add_Field returns existing field number if field is already known");
- ASSERT_TRUE(batch, ZCB_Equals(&bar, (Obj*)Seg_Field_Name(segment, 2)),
+ ASSERT_TRUE(batch, ZCB_Equals(bar, (Obj*)Seg_Field_Name(segment, 2)),
"Field_Name");
ASSERT_TRUE(batch, Seg_Field_Name(segment, 3) == NULL,
"Field_Name returns NULL for unknown field number");
- ASSERT_TRUE(batch, Seg_Field_Num(segment, (CharBuf*)&bar) == 2,
+ ASSERT_TRUE(batch, Seg_Field_Num(segment, (CharBuf*)bar) == 2,
"Field_Num");
- ASSERT_TRUE(batch, Seg_Field_Num(segment, (CharBuf*)&baz) == 0,
+ ASSERT_TRUE(batch, Seg_Field_Num(segment, (CharBuf*)baz) == 0,
"Field_Num returns 0 for unknown field name");
DECREF(segment);
@@ -108,13 +108,13 @@
Segment *segment = Seg_new(100);
Segment *got = Seg_new(100);
CharBuf *meta;
- ZombieCharBuf flotsam = ZCB_LITERAL("flotsam");
- ZombieCharBuf jetsam = ZCB_LITERAL("jetsam");
+ CharBuf *flotsam = (CharBuf*)ZCB_WRAP_STR("flotsam", 7);
+ CharBuf *jetsam = (CharBuf*)ZCB_WRAP_STR("jetsam", 6);
Seg_Set_Count(segment, 111);
Seg_Store_Metadata_Str(segment, "foo", 3, (Obj*)CB_newf("bar"));
- Seg_Add_Field(segment, (CharBuf*)&flotsam);
- Seg_Add_Field(segment, (CharBuf*)&jetsam);
+ Seg_Add_Field(segment, flotsam);
+ Seg_Add_Field(segment, jetsam);
RAMFolder_MkDir(folder, Seg_Get_Name(segment));
Seg_Write_File(segment, (Folder*)folder);
@@ -123,8 +123,7 @@
ASSERT_TRUE(batch, Seg_Get_Count(got) == Seg_Get_Count(segment),
"Round-trip count through file");
ASSERT_TRUE(batch,
- Seg_Field_Num(got, (CharBuf*)&jetsam)
- == Seg_Field_Num(segment, (CharBuf*)&jetsam),
+ Seg_Field_Num(got, jetsam) == Seg_Field_Num(segment, jetsam),
"Round trip field names through file");
meta = (CharBuf*)Seg_Fetch_Metadata_Str(got, "foo", 3);
ASSERT_TRUE(batch, meta && CB_Is_A(meta, CHARBUF)
Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestHash.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestHash.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestHash.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestHash.c Fri Feb 19 17:33:37 2010
@@ -67,9 +67,9 @@
const u32_t starting_cap = Hash_Get_Capacity(hash);
VArray *expected = VA_new(100);
VArray *got = VA_new(100);
- ZombieCharBuf twenty = ZCB_make_str("20", 2);
- ZombieCharBuf forty = ZCB_make_str("40", 2);
- ZombieCharBuf foo = ZCB_make_str("foo", 3);
+ ZombieCharBuf *twenty = ZCB_WRAP_STR("20", 2);
+ ZombieCharBuf *forty = ZCB_WRAP_STR("40", 2);
+ ZombieCharBuf *foo = ZCB_WRAP_STR("foo", 3);
i32_t i;
for (i = 0; i < 100; i++) {
@@ -94,31 +94,31 @@
ASSERT_INT_EQ(batch, Hash_Get_Size(hash), 100,
"size incremented properly by Hash_Store");
- ASSERT_TRUE(batch, Hash_Fetch(hash, (Obj*)&foo) == NULL,
+ ASSERT_TRUE(batch, Hash_Fetch(hash, (Obj*)foo) == NULL,
"Fetch against non-existent key returns NULL");
- Hash_Store(hash, (Obj*)&forty, INCREF(&foo));
- ASSERT_TRUE(batch, ZCB_Equals(&foo, Hash_Fetch(hash, (Obj*)&forty)),
+ Hash_Store(hash, (Obj*)forty, INCREF(foo));
+ ASSERT_TRUE(batch, ZCB_Equals(foo, Hash_Fetch(hash, (Obj*)forty)),
"Hash_Store replaces existing value");
ASSERT_FALSE(batch, Hash_Equals(hash, (Obj*)dupe),
"replacement value spoils equals");
ASSERT_INT_EQ(batch, Hash_Get_Size(hash), 100,
"size unaffected after value replaced");
- ASSERT_TRUE(batch, Hash_Delete(hash, (Obj*)&forty) == (Obj*)&foo,
+ ASSERT_TRUE(batch, Hash_Delete(hash, (Obj*)forty) == (Obj*)foo,
"Delete returns value");
- DECREF(&foo);
+ DECREF(foo);
ASSERT_INT_EQ(batch, Hash_Get_Size(hash), 99,
"size decremented by successful Delete");
- ASSERT_TRUE(batch, Hash_Delete(hash, (Obj*)&forty) == NULL,
+ ASSERT_TRUE(batch, Hash_Delete(hash, (Obj*)forty) == NULL,
"Delete returns NULL when key not found");
ASSERT_INT_EQ(batch, Hash_Get_Size(hash), 99,
"size not decremented by unsuccessful Delete");
- DECREF(Hash_Delete(dupe, (Obj*)&forty));
+ DECREF(Hash_Delete(dupe, (Obj*)forty));
ASSERT_TRUE(batch, VA_Equals(got, (Obj*)expected), "Equals after Delete");
Hash_Clear(hash);
- ASSERT_TRUE(batch, Hash_Fetch(hash, (Obj*)&twenty) == NULL, "Clear");
+ ASSERT_TRUE(batch, Hash_Fetch(hash, (Obj*)twenty) == NULL, "Clear");
ASSERT_TRUE(batch, Hash_Get_Size(hash) == 0, "size is 0 after Clear");
DECREF(hash);
@@ -169,11 +169,11 @@
ASSERT_TRUE(batch, VA_Equals(values, (Obj*)expected), "Values from Iter");
{
- ZombieCharBuf forty = ZCB_make_str("40", 2);
- ZombieCharBuf nope = ZCB_make_str("nope", 4);
- Obj *key = Hash_Find_Key(hash, (Obj*)&forty, ZCB_Hash_Code(&forty));
- ASSERT_TRUE(batch, Obj_Equals(key, (Obj*)&forty), "Find_Key");
- key = Hash_Find_Key(hash, (Obj*)&nope, ZCB_Hash_Code(&nope)),
+ ZombieCharBuf *forty = ZCB_WRAP_STR("40", 2);
+ ZombieCharBuf *nope = ZCB_WRAP_STR("nope", 4);
+ Obj *key = Hash_Find_Key(hash, (Obj*)forty, ZCB_Hash_Code(forty));
+ ASSERT_TRUE(batch, Obj_Equals(key, (Obj*)forty), "Find_Key");
+ key = Hash_Find_Key(hash, (Obj*)nope, ZCB_Hash_Code(nope)),
ASSERT_TRUE(batch, key == NULL,
"Find_Key returns NULL for non-existent key");
}
Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestObj.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestObj.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestObj.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestObj.c Fri Feb 19 17:33:37 2010
@@ -7,11 +7,11 @@
static Obj*
S_new_testobj()
{
- static ZombieCharBuf klass = ZCB_LITERAL("TestObj");
+ ZombieCharBuf *klass = ZCB_WRAP_STR("TestObj", 7);
Obj *obj;
- VTable *vtable = VTable_fetch_vtable((CharBuf*)&klass);
+ VTable *vtable = VTable_fetch_vtable((CharBuf*)klass);
if (!vtable) {
- vtable = VTable_singleton((CharBuf*)&klass, OBJ);
+ vtable = VTable_singleton((CharBuf*)klass, OBJ);
}
obj = VTable_Make_Obj(vtable);
return Obj_init(obj);
@@ -39,12 +39,12 @@
{
Obj *testobj = S_new_testobj();
CharBuf *string = Obj_To_String(testobj);
- ZombieCharBuf temp = ZCB_make(string);
- while(ZCB_Get_Size(&temp)) {
- if (ZCB_Starts_With_Str(&temp, "TestObj", 7)) { break; }
- ZCB_Nip_One(&temp);
+ ZombieCharBuf *temp = ZCB_WRAP(string);
+ while(ZCB_Get_Size(temp)) {
+ if (ZCB_Starts_With_Str(temp, "TestObj", 7)) { break; }
+ ZCB_Nip_One(temp);
}
- ASSERT_TRUE(batch, ZCB_Starts_With_Str(&temp, "TestObj", 7), "To_String");
+ ASSERT_TRUE(batch, ZCB_Starts_With_Str(temp, "TestObj", 7), "To_String");
DECREF(string);
DECREF(testobj);
}
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestCompoundFileReader.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestCompoundFileReader.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestCompoundFileReader.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestCompoundFileReader.c Fri Feb 19 17:33:37 2010
@@ -1,3 +1,4 @@
+#define C_LUCY_ZOMBIECHARBUF
#define C_LUCY_RAMFOLDER
#include "Lucy/Util/ToolSet.h"
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestFSDirHandle.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestFSDirHandle.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestFSDirHandle.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestFSDirHandle.c Fri Feb 19 17:33:37 2010
@@ -1,4 +1,3 @@
-#define C_LUCY_CHARBUF
#include "Lucy/Util/ToolSet.h"
/* rmdir */
@@ -17,41 +16,37 @@
#include "Lucy/Store/FSFolder.h"
#include "Lucy/Store/OutStream.h"
-static CharBuf foo = ZCB_LITERAL("foo");
-static CharBuf boffo = ZCB_LITERAL("boffo");
-static CharBuf foo_boffo = ZCB_LITERAL("foo/boffo");
-static CharBuf test_dir = ZCB_LITERAL("_fsdir_test");
-
static void
test_all(TestBatch *batch)
{
- FSFolder *folder = FSFolder_new(&test_dir);
- OutStream *outstream;
- FSDirHandle *dh;
- CharBuf *entry;
- bool_t saw_foo = false;
- bool_t saw_boffo = false;
- bool_t foo_was_dir = false;
- bool_t boffo_was_dir = false;
- int count = 0;
+ CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
+ CharBuf *boffo = (CharBuf*)ZCB_WRAP_STR("boffo", 5);
+ CharBuf *foo_boffo = (CharBuf*)ZCB_WRAP_STR("foo/boffo", 9);
+ CharBuf *test_dir = (CharBuf*)ZCB_WRAP_STR("_fsdir_test", 11);
+ FSFolder *folder = FSFolder_new(test_dir);
+ bool_t saw_foo = false;
+ bool_t saw_boffo = false;
+ bool_t foo_was_dir = false;
+ bool_t boffo_was_dir = false;
+ int count = 0;
rmdir("_fsdir_test");
FSFolder_Initialize(folder);
- FSFolder_MkDir(folder, &foo);
- outstream = FSFolder_Open_Out(folder, &boffo);
+ FSFolder_MkDir(folder, foo);
+ OutStream *outstream = FSFolder_Open_Out(folder, boffo);
DECREF(outstream);
- outstream = FSFolder_Open_Out(folder, &foo_boffo);
+ outstream = FSFolder_Open_Out(folder, foo_boffo);
DECREF(outstream);
- dh = FSDH_open(&test_dir);
- entry = FSDH_Get_Entry(dh);
+ FSDirHandle *dh = FSDH_open(test_dir);
+ CharBuf *entry = FSDH_Get_Entry(dh);
while (FSDH_Next(dh)) {
count++;
- if (CB_Equals(entry, (Obj*)&foo)) {
+ if (CB_Equals(entry, (Obj*)foo)) {
saw_foo = true;
foo_was_dir = FSDH_Entry_Is_Dir(dh);
}
- else if (CB_Equals(entry, (Obj*)&boffo)) {
+ else if (CB_Equals(entry, (Obj*)boffo)) {
saw_boffo = true;
boffo_was_dir = FSDH_Entry_Is_Dir(dh);
}
@@ -65,9 +60,9 @@
"File correctly identified by Entry_Is_Dir");
DECREF(dh);
- FSFolder_Delete(folder, &foo_boffo);
- FSFolder_Delete(folder, &foo);
- FSFolder_Delete(folder, &boffo);
+ FSFolder_Delete(folder, foo_boffo);
+ FSFolder_Delete(folder, foo);
+ FSFolder_Delete(folder, boffo);
DECREF(folder);
rmdir("_fsdir_test");
}
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFileHandle.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFileHandle.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFileHandle.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFileHandle.c Fri Feb 19 17:33:37 2010
@@ -16,38 +16,38 @@
#include "Lucy/Store/FSFileHandle.h"
#include "Lucy/Store/FileWindow.h"
-static CharBuf test_filename = ZCB_LITERAL("_fsfh_test_file");
-
static void
test_open(TestBatch *batch)
{
+
FSFileHandle *fh;
+ CharBuf *test_filename = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
- remove((char*)CB_Get_Ptr8(&test_filename));
+ remove((char*)CB_Get_Ptr8(test_filename));
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_READ_ONLY);
+ fh = FSFH_open(test_filename, FH_READ_ONLY);
ASSERT_TRUE(batch, fh == NULL,
"open() with FH_READ_ONLY on non-existent file returns NULL");
ASSERT_TRUE(batch, Err_get_error() != NULL,
"open() with FH_READ_ONLY on non-existent file sets error");
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_WRITE_ONLY);
+ fh = FSFH_open(test_filename, FH_WRITE_ONLY);
ASSERT_TRUE(batch, fh == NULL,
"open() without FH_CREATE returns NULL");
ASSERT_TRUE(batch, Err_get_error() != NULL,
"open() without FH_CREATE sets error");
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_CREATE);
+ fh = FSFH_open(test_filename, FH_CREATE);
ASSERT_TRUE(batch, fh == NULL,
"open() without FH_WRITE_ONLY returns NULL");
ASSERT_TRUE(batch, Err_get_error() != NULL,
"open() without FH_WRITE_ONLY sets error");
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
+ fh = FSFH_open(test_filename, FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
ASSERT_TRUE(batch, fh && FSFH_Is_A(fh, FSFILEHANDLE), "open() succeeds");
ASSERT_TRUE(batch, Err_get_error() == NULL, "open() no errors");
FSFH_Write(fh, "foo", 3);
@@ -55,13 +55,13 @@
DECREF(fh);
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
+ fh = FSFH_open(test_filename, FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
ASSERT_TRUE(batch, fh == NULL, "FH_EXCLUSIVE blocks open()");
ASSERT_TRUE(batch, Err_get_error() != NULL,
"FH_EXCLUSIVE blocks open(), sets error");
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_CREATE | FH_WRITE_ONLY);
+ fh = FSFH_open(test_filename, FH_CREATE | FH_WRITE_ONLY);
ASSERT_TRUE(batch, fh && FSFH_Is_A(fh, FSFILEHANDLE),
"open() for append");
ASSERT_TRUE(batch, Err_get_error() == NULL,
@@ -71,13 +71,13 @@
DECREF(fh);
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_READ_ONLY);
+ fh = FSFH_open(test_filename, FH_READ_ONLY);
ASSERT_TRUE(batch, fh && FSFH_Is_A(fh, FSFILEHANDLE), "open() read only");
ASSERT_TRUE(batch, Err_get_error() == NULL,
"open() read only -- no errors");
DECREF(fh);
- remove((char*)CB_Get_Ptr8(&test_filename));
+ remove((char*)CB_Get_Ptr8(test_filename));
}
static void
@@ -88,9 +88,10 @@
const char *bar = "bar";
char buffer[12];
char *buf = buffer;
+ CharBuf *test_filename = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
- remove((char*)CB_Get_Ptr8(&test_filename));
- fh = FSFH_open(&test_filename,
+ remove((char*)CB_Get_Ptr8(test_filename));
+ fh = FSFH_open(test_filename,
FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
ASSERT_TRUE(batch, FSFH_Length(fh) == I64_C(0), "Length initially 0");
@@ -109,7 +110,7 @@
/* Reopen for reading. */
Err_set_error(NULL);
- fh = FSFH_open(&test_filename, FH_READ_ONLY);
+ fh = FSFH_open(test_filename, FH_READ_ONLY);
ASSERT_TRUE(batch, FSFH_Length(fh) == I64_C(6), "Length on Read");
ASSERT_TRUE(batch, FSFH_Read(fh, buf, 0, 6), "Read returns success");
@@ -136,25 +137,26 @@
"Writing to a read-only handle sets error");
DECREF(fh);
- remove((char*)CB_Get_Ptr8(&test_filename));
+ remove((char*)CB_Get_Ptr8(test_filename));
}
static void
test_Close(TestBatch *batch)
{
+ CharBuf *test_filename = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
FSFileHandle *fh;
- bool_t result;
+ bool_t result;
- remove((char*)CB_Get_Ptr8(&test_filename));
- fh = FSFH_open(&test_filename,
+ remove((char*)CB_Get_Ptr8(test_filename));
+ fh = FSFH_open(test_filename,
FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
ASSERT_TRUE(batch, FSFH_Close(fh), "Close returns true for write-only");
DECREF(fh);
/* Simulate an OS error when closing the file descriptor. This
* approximates what would happen if, say, we run out of disk space. */
- remove((char*)CB_Get_Ptr8(&test_filename));
- fh = FSFH_open(&test_filename,
+ remove((char*)CB_Get_Ptr8(test_filename));
+ fh = FSFH_open(test_filename,
FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
close(fh->fd);
fh->fd = -1;
@@ -165,22 +167,23 @@
"Failed Close() sets Err_error");
DECREF(fh);
- fh = FSFH_open(&test_filename, FH_READ_ONLY);
+ fh = FSFH_open(test_filename, FH_READ_ONLY);
ASSERT_TRUE(batch, FSFH_Close(fh), "Close returns true for read-only");
DECREF(fh);
- remove((char*)CB_Get_Ptr8(&test_filename));
+ remove((char*)CB_Get_Ptr8(test_filename));
}
static void
test_Window(TestBatch *batch)
{
+ CharBuf *test_filename = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
FSFileHandle *fh;
FileWindow *window = FileWindow_new();
u32_t i;
- remove((char*)CB_Get_Ptr8(&test_filename));
- fh = FSFH_open(&test_filename,
+ remove((char*)CB_Get_Ptr8(test_filename));
+ fh = FSFH_open(test_filename,
FH_CREATE | FH_WRITE_ONLY | FH_EXCLUSIVE);
for (i = 0; i < 1024; i++) {
FSFH_Write(fh, "foo ", 4);
@@ -189,7 +192,7 @@
/* Reopen for reading. */
DECREF(fh);
- fh = FSFH_open(&test_filename, FH_READ_ONLY);
+ fh = FSFH_open(test_filename, FH_READ_ONLY);
if (!fh) { RETHROW(INCREF(Err_get_error())); }
Err_set_error(NULL);
@@ -218,7 +221,7 @@
DECREF(window);
DECREF(fh);
- remove((char*)CB_Get_Ptr8(&test_filename));
+ remove((char*)CB_Get_Ptr8(test_filename));
}
void
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c Fri Feb 19 17:33:37 2010
@@ -1,4 +1,3 @@
-#define C_LUCY_CHARBUF
#include "Lucy/Util/ToolSet.h"
/* mkdir, rmdir */
@@ -22,16 +21,12 @@
#include "Lucy/Store/FSFolder.h"
#include "Lucy/Store/OutStream.h"
-static CharBuf test_dir_name = ZCB_LITERAL("_fsfolder_test");
-static CharBuf foo = ZCB_LITERAL("foo");
-static CharBuf bar = ZCB_LITERAL("bar");
-static CharBuf foo_boffo = ZCB_LITERAL("foo/boffo");
-
static Folder*
S_set_up()
{
- FSFolder *folder = FSFolder_new(&test_dir_name);
- rmdir("_fsfolder_test");
+ rmdir("_fstest");
+ CharBuf *test_dir = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
+ FSFolder *folder = FSFolder_new(test_dir);
FSFolder_Initialize(folder);
if (!FSFolder_Check(folder)) {
RETHROW(INCREF(Err_get_error()));
@@ -43,17 +38,18 @@
S_tear_down()
{
struct stat stat_buf;
- rmdir("_fsfolder_test");
- if (stat("_fsfolder_test", &stat_buf) != -1) {
- THROW(ERR, "Can't clean up directory _fsfolder_test");
+ rmdir("_fstest");
+ if (stat("_fstest", &stat_buf) != -1) {
+ THROW(ERR, "Can't clean up directory _fstest");
}
}
static void
test_Initialize_and_Check(TestBatch *batch)
{
- FSFolder *folder = FSFolder_new(&test_dir_name);
- rmdir("_fsfolder_test");
+ rmdir("_fstest");
+ CharBuf *test_dir = (CharBuf*)ZCB_WRAP_STR("_fstest", 7);
+ FSFolder *folder = FSFolder_new(test_dir);
ASSERT_FALSE(batch, FSFolder_Check(folder),
"Check() returns false when folder dir doesn't exist");
FSFolder_Initialize(folder);
@@ -68,29 +64,32 @@
test_protect_symlinks(TestBatch *batch)
{
#ifdef CHY_HAS_UNISTD_H
- FSFolder *folder = (FSFolder*)S_set_up();
+ FSFolder *folder = (FSFolder*)S_set_up();
+ CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
+ CharBuf *bar = (CharBuf*)ZCB_WRAP_STR("bar", 3);
+ CharBuf *foo_boffo = (CharBuf*)ZCB_WRAP_STR("foo/boffo", 9);
- FSFolder_MkDir(folder, &foo);
- FSFolder_MkDir(folder, &bar);
- OutStream *outstream = FSFolder_Open_Out(folder, &foo_boffo);
+ FSFolder_MkDir(folder, foo);
+ FSFolder_MkDir(folder, bar);
+ OutStream *outstream = FSFolder_Open_Out(folder, foo_boffo);
DECREF(outstream);
- if (symlink("_fsfolder_test/foo/boffo", "_fsfolder_test/bar/banana")) {
+ if (symlink("_fstest/foo/boffo", "_fstest/bar/banana")) {
FAIL(batch, "symlink() failed");
FAIL(batch, "symlink() failed");
FAIL(batch, "symlink() failed");
FAIL(batch, "symlink() failed");
}
else {
- ASSERT_TRUE(batch, FSFolder_Delete_Tree(folder, &bar),
+ ASSERT_TRUE(batch, FSFolder_Delete_Tree(folder, bar),
"Delete_Tree() returns true"),
- ASSERT_FALSE(batch, FSFolder_Exists(folder, &bar),
+ ASSERT_FALSE(batch, FSFolder_Exists(folder, bar),
"Tree is really gone");
- ASSERT_TRUE(batch, FSFolder_Exists(folder, &foo),
+ ASSERT_TRUE(batch, FSFolder_Exists(folder, foo),
"Original folder sill there");
- ASSERT_TRUE(batch, FSFolder_Exists(folder, &foo_boffo),
+ ASSERT_TRUE(batch, FSFolder_Exists(folder, foo_boffo),
"Delete_Tree() did not follow directory symlink");
- FSFolder_Delete_Tree(folder, &foo);
+ FSFolder_Delete_Tree(folder, foo);
}
DECREF(folder);
S_tear_down();
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestFileHandle.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestFileHandle.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestFileHandle.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestFileHandle.c Fri Feb 19 17:33:37 2010
@@ -17,11 +17,11 @@
static FileHandle*
S_new_filehandle()
{
- static ZombieCharBuf klass = ZCB_LITERAL("TestFileHandle");
+ ZombieCharBuf *klass = ZCB_WRAP_STR("TestFileHandle", 14);
FileHandle *fh;
- VTable *vtable = VTable_fetch_vtable((CharBuf*)&klass);
+ VTable *vtable = VTable_fetch_vtable((CharBuf*)klass);
if (!vtable) {
- vtable = VTable_singleton((CharBuf*)&klass, FILEHANDLE);
+ vtable = VTable_singleton((CharBuf*)klass, FILEHANDLE);
}
VTable_Override(vtable, S_no_op_method, Lucy_FH_Close_OFFSET);
fh = (FileHandle*)VTable_Make_Obj(vtable);
@@ -33,13 +33,13 @@
{
TestBatch *batch = TestBatch_new(2);
FileHandle *fh = S_new_filehandle();
- ZombieCharBuf foo = ZCB_LITERAL("foo");
+ ZombieCharBuf *foo = ZCB_WRAP_STR("foo", 3);
TestBatch_Plan(batch);
ASSERT_TRUE(batch, CB_Equals_Str(FH_Get_Path(fh), "", 0), "Get_Path");
- FH_Set_Path(fh, (CharBuf*)&foo);
- ASSERT_TRUE(batch, CB_Equals(FH_Get_Path(fh), (Obj*)&foo), "Set_Path");
+ FH_Set_Path(fh, (CharBuf*)foo);
+ ASSERT_TRUE(batch, CB_Equals(FH_Get_Path(fh), (Obj*)foo), "Set_Path");
DECREF(fh);
DECREF(batch);
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestInStream.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestInStream.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestInStream.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestInStream.c Fri Feb 19 17:33:37 2010
@@ -70,8 +70,8 @@
static void
test_Clone_and_Reopen(TestBatch *batch)
{
- ZombieCharBuf foo = ZCB_LITERAL("foo");
- ZombieCharBuf bar = ZCB_LITERAL("bar");
+ ZombieCharBuf *foo = ZCB_WRAP_STR("foo", 3);
+ ZombieCharBuf *bar = ZCB_WRAP_STR("bar", 3);
RAMFile *file = RAMFile_new(NULL, false);
OutStream *outstream = OutStream_open((Obj*)file);
RAMFileHandle *fh;
@@ -85,22 +85,22 @@
}
OutStream_Close(outstream);
- fh = RAMFH_open((CharBuf*)&foo, FH_READ_ONLY, file);
+ fh = RAMFH_open((CharBuf*)foo, FH_READ_ONLY, file);
instream = InStream_open((Obj*)fh);
InStream_Seek(instream, 1);
- ASSERT_TRUE(batch, CB_Equals(InStream_Get_Filename(instream), (Obj*)&foo),
+ ASSERT_TRUE(batch, CB_Equals(InStream_Get_Filename(instream), (Obj*)foo),
"Get_Filename");
clone = InStream_Clone(instream);
- ASSERT_TRUE(batch, CB_Equals(InStream_Get_Filename(clone), (Obj*)&foo),
+ ASSERT_TRUE(batch, CB_Equals(InStream_Get_Filename(clone), (Obj*)foo),
"Clones have same filename");
ASSERT_TRUE(batch, InStream_Length(instream) == InStream_Length(clone),
"Clones have same length");
ASSERT_TRUE(batch, InStream_Read_U8(instream) == InStream_Read_U8(clone),
"Clones start at same file position");
- reopened = InStream_Reopen(instream, (CharBuf*)&bar, 25, 1);
- ASSERT_TRUE(batch, CB_Equals(InStream_Get_Filename(reopened), (Obj*)&bar),
+ reopened = InStream_Reopen(instream, (CharBuf*)bar, 25, 1);
+ ASSERT_TRUE(batch, CB_Equals(InStream_Get_Filename(reopened), (Obj*)bar),
"Reopened InStreams take new filename");
ASSERT_TRUE(batch, InStream_Read_U8(reopened) == 'z',
"Reopened stream starts at supplied offset");
Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestRAMDirHandle.c Fri Feb 19 17:33:37 2010
@@ -1,5 +1,4 @@
#define C_LUCY_RAMFOLDER
-#define C_LUCY_CHARBUF
#include "Lucy/Util/ToolSet.h"
#include "Lucy/Test.h"
@@ -8,39 +7,37 @@
#include "Lucy/Store/RAMFolder.h"
#include "Lucy/Store/RAMDirHandle.h"
-static CharBuf foo = ZCB_LITERAL("foo");
-static CharBuf boffo = ZCB_LITERAL("boffo");
-static CharBuf foo_boffo = ZCB_LITERAL("foo/boffo");
-
static void
test_all(TestBatch *batch)
{
- RAMFolder *folder = RAMFolder_new(NULL);
- FileHandle *fh;
- RAMDirHandle *dh;
- CharBuf *entry;
- bool_t saw_foo = false;
- bool_t saw_boffo = false;
- bool_t foo_was_dir = false;
- bool_t boffo_was_dir = false;
- int count = 0;
-
- RAMFolder_MkDir(folder, &foo);
- fh = RAMFolder_Open_FileHandle(folder, &boffo, FH_CREATE | FH_WRITE_ONLY);
+ RAMFolder *folder = RAMFolder_new(NULL);
+ CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
+ CharBuf *boffo = (CharBuf*)ZCB_WRAP_STR("boffo", 5);
+ CharBuf *foo_boffo = (CharBuf*)ZCB_WRAP_STR("foo/boffo", 9);
+ bool_t saw_foo = false;
+ bool_t saw_boffo = false;
+ bool_t foo_was_dir = false;
+ bool_t boffo_was_dir = false;
+ int count = 0;
+
+ /* Set up folder contents. */
+ RAMFolder_MkDir(folder, foo);
+ FileHandle *fh = RAMFolder_Open_FileHandle(folder, boffo,
+ FH_CREATE | FH_WRITE_ONLY);
DECREF(fh);
- fh = RAMFolder_Open_FileHandle(folder, &foo_boffo,
+ fh = RAMFolder_Open_FileHandle(folder, foo_boffo,
FH_CREATE | FH_WRITE_ONLY );
DECREF(fh);
- dh = RAMDH_new(folder);
- entry = RAMDH_Get_Entry(dh);
+ RAMDirHandle *dh = RAMDH_new(folder);
+ CharBuf *entry = RAMDH_Get_Entry(dh);
while (RAMDH_Next(dh)) {
count++;
- if (CB_Equals(entry, (Obj*)&foo)) {
+ if (CB_Equals(entry, (Obj*)foo)) {
saw_foo = true;
foo_was_dir = RAMDH_Entry_Is_Dir(dh);
}
- else if (CB_Equals(entry, (Obj*)&boffo)) {
+ else if (CB_Equals(entry, (Obj*)boffo)) {
saw_boffo = true;
boffo_was_dir = RAMDH_Entry_Is_Dir(dh);
}
Modified: lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c?rev=911870&r1=911869&r2=911870&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c Fri Feb 19 17:33:37 2010
@@ -7,54 +7,53 @@
static void
test_local_part(TestBatch *batch)
{
- ZombieCharBuf source = ZCB_BLANK;
- ZombieCharBuf target = ZCB_BLANK;
- ZombieCharBuf *got = ⌖
+ ZombieCharBuf *source = ZCB_BLANK();
+ ZombieCharBuf *got = ZCB_BLANK();
- got = IxFileNames_local_part((CharBuf*)&source, got);
- ASSERT_TRUE(batch, ZCB_Equals(got, (Obj*)&source), "simple name");
+ got = IxFileNames_local_part((CharBuf*)source, got);
+ ASSERT_TRUE(batch, ZCB_Equals(got, (Obj*)source), "simple name");
- ZCB_Assign_Str(&source, "foo.txt", 7);
- got = IxFileNames_local_part((CharBuf*)&source, got);
- ASSERT_TRUE(batch, ZCB_Equals(got, (Obj*)&source), "name with extension");
+ ZCB_Assign_Str(source, "foo.txt", 7);
+ got = IxFileNames_local_part((CharBuf*)source, got);
+ ASSERT_TRUE(batch, ZCB_Equals(got, (Obj*)source), "name with extension");
- ZCB_Assign_Str(&source, "/foo", 4);
- got = IxFileNames_local_part((CharBuf*)&source, got);
+ ZCB_Assign_Str(source, "/foo", 4);
+ got = IxFileNames_local_part((CharBuf*)source, got);
ASSERT_TRUE(batch, ZCB_Equals_Str(got, "foo", 3), "strip leading slash");
- ZCB_Assign_Str(&source, "/foo/", 5);
- got = IxFileNames_local_part((CharBuf*)&source, got);
+ ZCB_Assign_Str(source, "/foo/", 5);
+ got = IxFileNames_local_part((CharBuf*)source, got);
ASSERT_TRUE(batch, ZCB_Equals_Str(got, "foo", 3), "strip trailing slash");
- ZCB_Assign_Str(&source, "foo/bar\\ ", 9);
- got = IxFileNames_local_part((CharBuf*)&source, got);
+ ZCB_Assign_Str(source, "foo/bar\\ ", 9);
+ got = IxFileNames_local_part((CharBuf*)source, got);
ASSERT_TRUE(batch, ZCB_Equals_Str(got, "bar\\ ", 5),
"Include garbage like backslashes and spaces");
- ZCB_Assign_Str(&source, "foo/bar/baz.txt", 15);
- got = IxFileNames_local_part((CharBuf*)&source, got);
+ ZCB_Assign_Str(source, "foo/bar/baz.txt", 15);
+ got = IxFileNames_local_part((CharBuf*)source, got);
ASSERT_TRUE(batch, ZCB_Equals_Str(got, "baz.txt", 7), "find last component");
}
static void
test_extract_gen(TestBatch *batch)
{
- ZombieCharBuf source = ZCB_BLANK;
+ ZombieCharBuf *source = ZCB_WRAP_STR("", 0);
- source = ZCB_make_str("seg_9", 5);
- ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)&source) == 9,
+ ZCB_Assign_Str(source, "seg_9", 5);
+ ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
"extract_gen");
- source = ZCB_make_str("seg_9/", 6);
- ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)&source) == 9,
+ ZCB_Assign_Str(source, "seg_9/", 6);
+ ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
"deal with trailing slash");
- source = ZCB_make_str("seg_9_8", 7);
- ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)&source) == 9,
+ ZCB_Assign_Str(source, "seg_9_8", 7);
+ ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
"Only go past first underscore");
- source = ZCB_make_str("snapshot_5.json", 15);
- ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)&source) == 5,
+ ZCB_Assign_Str(source, "snapshot_5.json", 15);
+ ASSERT_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 5,
"Deal with file suffix");
}