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 2009/12/04 02:07:13 UTC
svn commit: r887024 - in /lucene/lucy/trunk/core/Lucy:
Test/Object/TestByteBuf.c Test/Object/TestCharBuf.c Test/TestUtils.bp
Test/TestUtils.c Util/Freezer.bp Util/Freezer.c
Author: marvin
Date: Fri Dec 4 01:07:12 2009
New Revision: 887024
URL: http://svn.apache.org/viewvc?rev=887024&view=rev
Log:
Commit freezer.diff from LUCY-81, adding Lucy::Util::Freezer for serializing
and deserializing arbitrary objects.
Added:
lucene/lucy/trunk/core/Lucy/Util/Freezer.bp (with props)
lucene/lucy/trunk/core/Lucy/Util/Freezer.c (with props)
Modified:
lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c
lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c
lucene/lucy/trunk/core/Lucy/Test/TestUtils.bp
lucene/lucy/trunk/core/Lucy/Test/TestUtils.c
Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c?rev=887024&r1=887023&r2=887024&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestByteBuf.c Fri Dec 4 01:07:12 2009
@@ -121,10 +121,21 @@
DECREF(wanted);
}
+static void
+test_serialization(TestBatch *batch)
+{
+ ByteBuf *wanted = BB_new_bytes("foobar", 6);
+ ByteBuf *got = (ByteBuf*)TestUtils_freeze_thaw((Obj*)wanted);
+ ASSERT_TRUE(batch, got && BB_Equals(wanted, (Obj*)got),
+ "Serialization round trip");
+ DECREF(wanted);
+ DECREF(got);
+}
+
void
TestBB_run_tests()
{
- TestBatch *batch = Test_new_batch("TestByteBuf", 21, NULL);
+ TestBatch *batch = Test_new_batch("TestByteBuf", 22, NULL);
PLAN(batch);
test_Equals(batch);
@@ -133,6 +144,7 @@
test_compare(batch);
test_Mimic(batch);
test_Cat(batch);
+ test_serialization(batch);
batch->destroy(batch);
}
Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c?rev=887024&r1=887023&r2=887024&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestCharBuf.c Fri Dec 4 01:07:12 2009
@@ -5,6 +5,7 @@
#include <stdio.h>
#include "Lucy/Test.h"
+#include "Lucy/Test/TestUtils.h"
#include "Lucy/Test/Object/TestCharBuf.h"
static char smiley[] = { (char)0xE2, (char)0x98, (char)0xBA, 0 };
@@ -350,10 +351,21 @@
DECREF(got);
}
+static void
+test_serialization(TestBatch *batch)
+{
+ CharBuf *wanted = S_get_cb("foo");
+ CharBuf *got = (CharBuf*)TestUtils_freeze_thaw((Obj*)wanted);
+ ASSERT_TRUE(batch, got && CB_Equals(wanted, (Obj*)got),
+ "Round trip through FREEZE/THAW");
+ DECREF(got);
+ DECREF(wanted);
+}
+
void
TestCB_run_tests()
{
- TestBatch *batch = Test_new_batch("TestCharBuf", 47, NULL);
+ TestBatch *batch = Test_new_batch("TestCharBuf", 48, NULL);
PLAN(batch);
test_vcatf_s(batch);
@@ -377,6 +389,7 @@
test_Trim(batch);
test_To_F64(batch);
test_To_I64(batch);
+ test_serialization(batch);
batch->destroy(batch);
}
Modified: lucene/lucy/trunk/core/Lucy/Test/TestUtils.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/TestUtils.bp?rev=887024&r1=887023&r2=887024&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/TestUtils.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Test/TestUtils.bp Fri Dec 4 01:07:12 2009
@@ -44,6 +44,12 @@
*/
inert incremented VArray*
doc_set();
+
+ /** Return the result of round-tripping the object through FREEZE and
+ * THAW.
+ */
+ inert incremented Obj*
+ freeze_thaw(Obj *object);
}
/* Copyright 2009 The Apache Software Foundation
Modified: lucene/lucy/trunk/core/Lucy/Test/TestUtils.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/TestUtils.c?rev=887024&r1=887023&r2=887024&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/TestUtils.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/TestUtils.c Fri Dec 4 01:07:12 2009
@@ -4,6 +4,10 @@
#include <string.h>
#include "Lucy/Test/TestUtils.h"
+#include "Lucy/Store/InStream.h"
+#include "Lucy/Store/OutStream.h"
+#include "Lucy/Store/RAMFile.h"
+#include "Lucy/Util/Freezer.h"
u64_t
TestUtils_random_u64()
@@ -74,6 +78,28 @@
return CB_new_from_utf8(ptr, strlen(ptr));
}
+Obj*
+TestUtils_freeze_thaw(Obj *object)
+{
+ if (object) {
+ RAMFile *ram_file = RAMFile_new(NULL, false);
+ OutStream *outstream = OutStream_open((Obj*)ram_file);
+ FREEZE(object, outstream);
+ OutStream_Close(outstream);
+ DECREF(outstream);
+ {
+ InStream *instream = InStream_open((Obj*)ram_file);
+ Obj *retval = THAW(instream);
+ DECREF(instream);
+ DECREF(ram_file);
+ return retval;
+ }
+ }
+ else {
+ return NULL;
+ }
+}
+
/* Copyright 2009 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
Added: lucene/lucy/trunk/core/Lucy/Util/Freezer.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/Freezer.bp?rev=887024&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/Freezer.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Util/Freezer.bp Fri Dec 4 01:07:12 2009
@@ -0,0 +1,43 @@
+parcel Lucy;
+
+inert class Lucy::Util::Freezer {
+
+ /** Store an arbitrary object to the outstream.
+ */
+ inert void
+ freeze(Obj *obj, OutStream *outstream);
+
+ /** Retrieve an arbitrary object from the instream.
+ */
+ inert incremented Obj*
+ thaw(InStream *instream);
+}
+
+__C__
+#define LUCY_FREEZE(_obj, _outstream) \
+ lucy_Freezer_freeze((Obj*)(_obj), (outstream))
+
+#define LUCY_THAW(_instream) \
+ lucy_Freezer_thaw(instream)
+
+#ifdef LUCY_USE_SHORT_NAMES
+ #define FREEZE LUCY_FREEZE
+ #define THAW LUCY_THAW
+#endif
+__END_C__
+
+/* Copyright 2009 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/core/Lucy/Util/Freezer.bp
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Util/Freezer.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/Freezer.c?rev=887024&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/Freezer.c (added)
+++ lucene/lucy/trunk/core/Lucy/Util/Freezer.c Fri Dec 4 01:07:12 2009
@@ -0,0 +1,39 @@
+#define C_LUCY_FREEZER
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Util/Freezer.h"
+#include "Lucy/Store/InStream.h"
+#include "Lucy/Store/OutStream.h"
+
+void
+Freezer_freeze(Obj *obj, OutStream *outstream)
+{
+ CB_Serialize(Obj_Get_Class_Name(obj), outstream);
+ Obj_Serialize(obj, outstream);
+}
+
+Obj*
+Freezer_thaw(InStream *instream)
+{
+ CharBuf *class_name = CB_deserialize(NULL, instream);
+ VTable *vtable = VTable_singleton(class_name, NULL);
+ Obj *blank = VTable_Make_Obj(vtable);
+ DECREF(class_name);
+ return Obj_Deserialize(blank, instream);
+}
+
+/* Copyright 2009 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/core/Lucy/Util/Freezer.c
------------------------------------------------------------------------------
svn:eol-style = native