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 2011/08/05 03:51:18 UTC
[lucy-commits] svn commit: r1154069 - in /incubator/lucy/trunk: clownfish/src/
core/Lucy/Object/ core/Lucy/Plan/ core/Lucy/Search/ perl/xs/
Author: marvin
Date: Fri Aug 5 01:51:17 2011
New Revision: 1154069
URL: http://svn.apache.org/viewvc?rev=1154069&view=rev
Log:
Use BoolNum singletons CFISH_TRUE and CFISH_FALSE instead of string hacks, in
many places but particularly Dump/Load routines, eventually yielding JSON with
values encoded as 'true' and 'false' rather than '"1"' and '"0"'.
Modified:
incubator/lucy/trunk/clownfish/src/CFCBindAliases.c
incubator/lucy/trunk/clownfish/src/CFCDumpable.c
incubator/lucy/trunk/core/Lucy/Object/Num.c
incubator/lucy/trunk/core/Lucy/Object/Num.cfh
incubator/lucy/trunk/core/Lucy/Object/Obj.c
incubator/lucy/trunk/core/Lucy/Object/Obj.cfh
incubator/lucy/trunk/core/Lucy/Plan/BlobType.c
incubator/lucy/trunk/core/Lucy/Plan/FullTextType.c
incubator/lucy/trunk/core/Lucy/Plan/NumericType.c
incubator/lucy/trunk/core/Lucy/Plan/StringType.c
incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c
incubator/lucy/trunk/perl/xs/XSBind.c
Modified: incubator/lucy/trunk/clownfish/src/CFCBindAliases.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindAliases.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindAliases.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCBindAliases.c Fri Aug 5 01:51:17 2011
@@ -37,6 +37,7 @@ struct alias aliases[] = {
{"Cfish_Obj_Load", "Lucy_Obj_Load"},
{"Cfish_Obj_To_F64", "Lucy_Obj_To_F64"},
{"Cfish_Obj_To_I64", "Lucy_Obj_To_I64"},
+ {"Cfish_Obj_To_Bool", "Lucy_Obj_To_Bool"},
{"Cfish_Obj_To_Host", "Lucy_Obj_To_Host"},
{"Cfish_Obj_Dec_RefCount", "Lucy_Obj_Dec_RefCount"},
{"Cfish_Obj_Inc_RefCount", "Lucy_Obj_Inc_RefCount"},
@@ -67,6 +68,7 @@ struct alias aliases[] = {
{"CFISH_INTEGER64", "LUCY_INTEGER64"},
{"CFISH_FLOAT32", "LUCY_FLOAT32"},
{"CFISH_FLOAT64", "LUCY_FLOAT64"},
+ {"cfish_Bool_singleton", "lucy_Bool_singleton"},
{"CFISH_ERR", "LUCY_ERR"},
{"cfish_Err_new", "lucy_Err_new"},
Modified: incubator/lucy/trunk/clownfish/src/CFCDumpable.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDumpable.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDumpable.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCDumpable.c Fri Aug 5 01:51:17 2011
@@ -309,8 +309,20 @@ S_process_dump_member(CFCClass *klass, C
" Cfish_Hash_Store_Str(dump, \"%s\", %u, (cfish_Obj*)cfish_CB_newf(\"%%i64\", (int64_t)self->%s));\n";
char float_pattern[] =
" Cfish_Hash_Store_Str(dump, \"%s\", %u, (cfish_Obj*)cfish_CB_newf(\"%%f64\", (double)self->%s));\n";
- const char *pattern = CFCType_is_integer(type)
- ? int_pattern : float_pattern;
+ char bool_pattern[] =
+ " Cfish_Hash_Store_Str(dump, \"%s\", %u, (cfish_Obj*)cfish_Bool_singleton(self->%s));\n";
+ const char *pattern;
+ if (strcmp(specifier, "bool_t") == 0
+ || strcmp(specifier, "chy_bool_t") == 0
+ ) {
+ pattern = bool_pattern;
+ }
+ else if (CFCType_is_integer(type)) {
+ pattern = int_pattern;
+ }
+ else {
+ pattern = float_pattern;
+ }
size_t needed = strlen(pattern) + name_len * 2 + 20;
if (buf_size < needed) {
croak("Buffer not big enough (%lu < %lu)",
@@ -360,7 +372,14 @@ S_process_load_member(CFCClass *klass, C
croak("type_str too long: '%s'", type_str);
}
if (CFCType_is_integer(type)) {
- sprintf(extraction, "(%s)Cfish_Obj_To_I64(var)", type_str);
+ if (strcmp(specifier, "bool_t") == 0
+ || strcmp(specifier, "chy_bool_t") == 0
+ ) {
+ sprintf(extraction, "Cfish_Obj_To_Bool(var)");
+ }
+ else {
+ sprintf(extraction, "(%s)Cfish_Obj_To_I64(var)", type_str);
+ }
}
else if (CFCType_is_floating(type)) {
sprintf(extraction, "(%s)Cfish_Obj_To_F64(var)", type_str);
Modified: incubator/lucy/trunk/core/Lucy/Object/Num.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Object/Num.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Object/Num.c (original)
+++ incubator/lucy/trunk/core/Lucy/Object/Num.c Fri Aug 5 01:51:17 2011
@@ -365,6 +365,11 @@ static BoolNum false_obj = { BOOLNUM, {1
BoolNum *Bool_true_singleton = &true_obj;
BoolNum *Bool_false_singleton = &false_obj;
+BoolNum*
+Bool_singleton(bool_t value) {
+ return value ? CFISH_TRUE : CFISH_FALSE;
+}
+
void
Bool_destroy(BoolNum *self) {
UNUSED_VAR(self);
@@ -385,6 +390,11 @@ Bool_to_i64(BoolNum *self) {
return self->value;
}
+bool_t
+Bool_to_bool(BoolNum *self) {
+ return self->value;
+}
+
BoolNum*
Bool_clone(BoolNum *self) {
return self;
Modified: incubator/lucy/trunk/core/Lucy/Object/Num.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Object/Num.cfh?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Object/Num.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Object/Num.cfh Fri Aug 5 01:51:17 2011
@@ -245,6 +245,12 @@ class Lucy::Object::BoolNum cnick Bool i
inert BoolNum *true_singleton;
inert BoolNum *false_singleton;
+ /** Return either CFISH_TRUE or CFISH_FALSE depending on the supplied
+ * value.
+ */
+ inert BoolNum*
+ singleton(bool_t value);
+
public void
Destroy(BoolNum *self);
@@ -257,6 +263,9 @@ class Lucy::Object::BoolNum cnick Bool i
public double
To_F64(BoolNum *self);
+ public bool_t
+ To_Bool(BoolNum *self);
+
public int32_t
Hash_Sum(BoolNum *self);
Modified: incubator/lucy/trunk/core/Lucy/Object/Obj.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Object/Obj.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Object/Obj.c (original)
+++ incubator/lucy/trunk/core/Lucy/Object/Obj.c Fri Aug 5 01:51:17 2011
@@ -107,6 +107,11 @@ Obj_to_string(Obj *self) {
#endif
}
+bool_t
+Obj_to_bool(Obj *self) {
+ return !!Obj_To_I64(self);
+}
+
Obj*
Obj_dump(Obj *self) {
return (Obj*)Obj_To_String(self);
Modified: incubator/lucy/trunk/core/Lucy/Object/Obj.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Object/Obj.cfh?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Object/Obj.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Object/Obj.cfh Fri Aug 5 01:51:17 2011
@@ -147,6 +147,12 @@ class Lucy::Object::Obj {
public abstract double
To_F64(Obj *self);
+ /** Evaluate the object in a boolean context. By default, invokes
+ * To_I64() and returns true if it is non-zero.
+ */
+ public bool_t
+ To_Bool(Obj *self);
+
/** Serialize the object by writing to the supplied OutStream.
*/
public void
Modified: incubator/lucy/trunk/core/Lucy/Plan/BlobType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Plan/BlobType.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Plan/BlobType.c (original)
+++ incubator/lucy/trunk/core/Lucy/Plan/BlobType.c Fri Aug 5 01:51:17 2011
@@ -75,10 +75,10 @@ BlobType_dump_for_schema(BlobType *self)
Hash_Store_Str(dump, "boost", 5, (Obj*)CB_newf("%f64", self->boost));
}
if (self->indexed) {
- Hash_Store_Str(dump, "indexed", 7, (Obj*)CB_newf("1"));
+ Hash_Store_Str(dump, "indexed", 7, (Obj*)CFISH_TRUE);
}
if (self->stored) {
- Hash_Store_Str(dump, "stored", 6, (Obj*)CB_newf("1"));
+ Hash_Store_Str(dump, "stored", 6, (Obj*)CFISH_TRUE);
}
return dump;
@@ -109,8 +109,8 @@ BlobType_load(BlobType *self, Obj *dump)
BlobType_init(loaded, false);
if (boost_dump) { loaded->boost = (float)Obj_To_F64(boost_dump); }
- if (indexed_dump) { loaded->indexed = (bool_t)Obj_To_I64(indexed_dump); }
- if (stored_dump) { loaded->stored = (bool_t)Obj_To_I64(stored_dump); }
+ if (indexed_dump) { loaded->indexed = Obj_To_Bool(indexed_dump); }
+ if (stored_dump) { loaded->stored = Obj_To_Bool(stored_dump); }
return loaded;
}
Modified: incubator/lucy/trunk/core/Lucy/Plan/FullTextType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Plan/FullTextType.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Plan/FullTextType.c (original)
+++ incubator/lucy/trunk/core/Lucy/Plan/FullTextType.c Fri Aug 5 01:51:17 2011
@@ -80,16 +80,16 @@ FullTextType_dump_for_schema(FullTextTyp
Hash_Store_Str(dump, "boost", 5, (Obj*)CB_newf("%f64", self->boost));
}
if (!self->indexed) {
- Hash_Store_Str(dump, "indexed", 7, (Obj*)CB_newf("0"));
+ Hash_Store_Str(dump, "indexed", 7, (Obj*)CFISH_FALSE);
}
if (!self->stored) {
- Hash_Store_Str(dump, "stored", 6, (Obj*)CB_newf("0"));
+ Hash_Store_Str(dump, "stored", 6, (Obj*)CFISH_FALSE);
}
if (self->sortable) {
- Hash_Store_Str(dump, "sortable", 8, (Obj*)CB_newf("1"));
+ Hash_Store_Str(dump, "sortable", 8, (Obj*)CFISH_TRUE);
}
if (self->highlightable) {
- Hash_Store_Str(dump, "highlightable", 13, (Obj*)CB_newf("1"));
+ Hash_Store_Str(dump, "highlightable", 13, (Obj*)CFISH_TRUE);
}
return dump;
@@ -127,10 +127,10 @@ FullTextType_load(FullTextType *self, Ob
Obj *stored_dump = Hash_Fetch_Str(source, "stored", 6);
Obj *sort_dump = Hash_Fetch_Str(source, "sortable", 8);
Obj *hl_dump = Hash_Fetch_Str(source, "highlightable", 13);
- bool_t indexed = indexed_dump ? (bool_t)Obj_To_I64(indexed_dump) : true;
- bool_t stored = stored_dump ? (bool_t)Obj_To_I64(stored_dump) : true;
- bool_t sortable = sort_dump ? (bool_t)Obj_To_I64(sort_dump) : false;
- bool_t hl = hl_dump ? (bool_t)Obj_To_I64(hl_dump) : false;
+ bool_t indexed = indexed_dump ? Obj_To_Bool(indexed_dump) : true;
+ bool_t stored = stored_dump ? Obj_To_Bool(stored_dump) : true;
+ bool_t sortable = sort_dump ? Obj_To_Bool(sort_dump) : false;
+ bool_t hl = hl_dump ? Obj_To_Bool(hl_dump) : false;
// Extract an Analyzer.
Obj *analyzer_dump = Hash_Fetch_Str(source, "analyzer", 8);
Modified: incubator/lucy/trunk/core/Lucy/Plan/NumericType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Plan/NumericType.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Plan/NumericType.c (original)
+++ incubator/lucy/trunk/core/Lucy/Plan/NumericType.c Fri Aug 5 01:51:17 2011
@@ -51,13 +51,13 @@ NumType_dump_for_schema(NumericType *sel
Hash_Store_Str(dump, "boost", 5, (Obj*)CB_newf("%f64", self->boost));
}
if (!self->indexed) {
- Hash_Store_Str(dump, "indexed", 7, (Obj*)CB_newf("0"));
+ Hash_Store_Str(dump, "indexed", 7, (Obj*)CFISH_FALSE);
}
if (!self->stored) {
- Hash_Store_Str(dump, "stored", 6, (Obj*)CB_newf("0"));
+ Hash_Store_Str(dump, "stored", 6, (Obj*)CFISH_FALSE);
}
if (self->sortable) {
- Hash_Store_Str(dump, "sortable", 8, (Obj*)CB_newf("1"));
+ Hash_Store_Str(dump, "sortable", 8, (Obj*)CFISH_TRUE);
}
return dump;
@@ -112,9 +112,9 @@ NumType_load(NumericType *self, Obj *dum
Obj *indexed_dump = Hash_Fetch_Str(source, "indexed", 7);
Obj *stored_dump = Hash_Fetch_Str(source, "stored", 6);
Obj *sort_dump = Hash_Fetch_Str(source, "sortable", 8);
- bool_t indexed = indexed_dump ? (bool_t)Obj_To_I64(indexed_dump) : true;
- bool_t stored = stored_dump ? (bool_t)Obj_To_I64(stored_dump) : true;
- bool_t sortable = sort_dump ? (bool_t)Obj_To_I64(sort_dump) : false;
+ bool_t indexed = indexed_dump ? Obj_To_Bool(indexed_dump) : true;
+ bool_t stored = stored_dump ? Obj_To_Bool(stored_dump) : true;
+ bool_t sortable = sort_dump ? Obj_To_Bool(sort_dump) : false;
return NumType_init2(loaded, boost, indexed, stored, sortable);
}
Modified: incubator/lucy/trunk/core/Lucy/Plan/StringType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Plan/StringType.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Plan/StringType.c (original)
+++ incubator/lucy/trunk/core/Lucy/Plan/StringType.c Fri Aug 5 01:51:17 2011
@@ -61,13 +61,13 @@ StringType_dump_for_schema(StringType *s
Hash_Store_Str(dump, "boost", 5, (Obj*)CB_newf("%f64", self->boost));
}
if (!self->indexed) {
- Hash_Store_Str(dump, "indexed", 7, (Obj*)CB_newf("0"));
+ Hash_Store_Str(dump, "indexed", 7, (Obj*)CFISH_FALSE);
}
if (!self->stored) {
- Hash_Store_Str(dump, "stored", 6, (Obj*)CB_newf("0"));
+ Hash_Store_Str(dump, "stored", 6, (Obj*)CFISH_FALSE);
}
if (self->sortable) {
- Hash_Store_Str(dump, "sortable", 8, (Obj*)CB_newf("1"));
+ Hash_Store_Str(dump, "sortable", 8, (Obj*)CFISH_TRUE);
}
return dump;
@@ -98,18 +98,10 @@ StringType_load(StringType *self, Obj *d
UNUSED_VAR(self);
StringType_init(loaded);
- if (boost_dump) {
- loaded->boost = (float)Obj_To_F64(boost_dump);
- }
- if (indexed_dump) {
- loaded->indexed = (bool_t)Obj_To_I64(indexed_dump);
- }
- if (stored_dump) {
- loaded->stored = (bool_t)Obj_To_I64(stored_dump);
- }
- if (sortable_dump) {
- loaded->sortable = (bool_t)Obj_To_I64(sortable_dump);
- }
+ if (boost_dump) { loaded->boost = (float)Obj_To_F64(boost_dump); }
+ if (indexed_dump) { loaded->indexed = Obj_To_Bool(indexed_dump); }
+ if (stored_dump) { loaded->stored = Obj_To_Bool(stored_dump); }
+ if (sortable_dump) { loaded->sortable = Obj_To_Bool(sortable_dump); }
return loaded;
}
Modified: incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c (original)
+++ incubator/lucy/trunk/core/Lucy/Search/NoMatchQuery.c Fri Aug 5 01:51:17 2011
@@ -77,7 +77,7 @@ NoMatchQuery_dump(NoMatchQuery *self) {
= (NoMatchQuery_dump_t)SUPER_METHOD(NOMATCHQUERY, NoMatchQuery, Dump);
Hash *dump = (Hash*)CERTIFY(super_dump(self), HASH);
Hash_Store_Str(dump, "fails_to_match", 14,
- (Obj*)CB_newf("%i64", (int64_t)self->fails_to_match));
+ (Obj*)Bool_singleton(self->fails_to_match));
return (Obj*)dump;
}
@@ -88,12 +88,7 @@ NoMatchQuery_load(NoMatchQuery *self, Ob
= (NoMatchQuery_load_t)SUPER_METHOD(NOMATCHQUERY, NoMatchQuery, Load);
NoMatchQuery *loaded = super_load(self, dump);
Obj *fails = Cfish_Hash_Fetch_Str(source, "fails_to_match", 14);
- if (fails) {
- loaded->fails_to_match = (bool_t)!!Obj_To_I64(fails);
- }
- else {
- loaded->fails_to_match = true;
- }
+ loaded->fails_to_match = fails ? Obj_To_Bool(fails) : true;
return loaded;
}
Modified: incubator/lucy/trunk/perl/xs/XSBind.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/xs/XSBind.c?rev=1154069&r1=1154068&r2=1154069&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/xs/XSBind.c (original)
+++ incubator/lucy/trunk/perl/xs/XSBind.c Fri Aug 5 01:51:17 2011
@@ -140,6 +140,12 @@ XSBind_cfish_to_perl(cfish_Obj *obj) {
else if (Cfish_Obj_Is_A(obj, CFISH_FLOATNUM)) {
return newSVnv(Cfish_Obj_To_F64(obj));
}
+ else if (obj == (cfish_Obj*)CFISH_TRUE) {
+ return newSViv(1);
+ }
+ else if (obj == (cfish_Obj*)CFISH_FALSE) {
+ return newSViv(0);
+ }
else if (sizeof(IV) == 8 && Cfish_Obj_Is_A(obj, CFISH_INTNUM)) {
int64_t num = Cfish_Obj_To_I64(obj);
return newSViv((IV)num);