You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/11/12 14:14:48 UTC
[1/6] lucy-clownfish git commit: Implement CB_Clear
Repository: lucy-clownfish
Updated Branches:
refs/heads/master cada6ca96 -> 71ea0c573
Implement CB_Clear
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/35719688
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/35719688
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/35719688
Branch: refs/heads/master
Commit: 3571968857f91a0028f4ef7f56ce0bdd92ac54ba
Parents: ae8edad
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 10 13:11:43 2015 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Nov 12 14:08:17 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/CharBuf.c | 5 +++++
runtime/core/Clownfish/CharBuf.cfh | 5 +++++
runtime/core/Clownfish/Test/TestCharBuf.c | 14 +++++++++++++-
3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/35719688/runtime/core/Clownfish/CharBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/CharBuf.c b/runtime/core/Clownfish/CharBuf.c
index e5e3aa2..6e54910 100644
--- a/runtime/core/Clownfish/CharBuf.c
+++ b/runtime/core/Clownfish/CharBuf.c
@@ -389,6 +389,11 @@ CB_Cat_IMP(CharBuf *self, String *string) {
}
void
+CB_Clear_IMP(CharBuf *self) {
+ self->size = 0;
+}
+
+void
CB_Set_Size_IMP(CharBuf *self, size_t size) {
if (size >= self->cap) {
THROW(ERR, "Can't set size of CharBuf beyond capacity");
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/35719688/runtime/core/Clownfish/CharBuf.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/CharBuf.cfh b/runtime/core/Clownfish/CharBuf.cfh
index 788c0d4..0112ae8 100644
--- a/runtime/core/Clownfish/CharBuf.cfh
+++ b/runtime/core/Clownfish/CharBuf.cfh
@@ -117,6 +117,11 @@ final class Clownfish::CharBuf nickname CB
char*
Grow(CharBuf *self, size_t size);
+ /** Clear the CharBuf.
+ */
+ void
+ Clear(CharBuf *self);
+
/** Set the CharBuf's `size` attribute.
*/
void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/35719688/runtime/core/Clownfish/Test/TestCharBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestCharBuf.c b/runtime/core/Clownfish/Test/TestCharBuf.c
index 30d8c11..5763e99 100644
--- a/runtime/core/Clownfish/Test/TestCharBuf.c
+++ b/runtime/core/Clownfish/Test/TestCharBuf.c
@@ -323,9 +323,20 @@ test_vcatf_x32(TestBatchRunner *runner) {
DECREF(got);
}
+static void
+test_Clear(TestBatchRunner *runner) {
+ CharBuf *cb = S_get_cb("foo");
+ CB_Clear(cb);
+ CB_Cat_Utf8(cb, "bar", 3);
+ String *string = CB_Yield_String(cb);
+ TEST_TRUE(runner, Str_Equals_Utf8(string, "bar", 3), "Clear");
+ DECREF(string);
+ DECREF(cb);
+}
+
void
TestCB_Run_IMP(TestCharBuf *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 26);
+ TestBatchRunner_Plan(runner, (TestBatch*)self, 27);
test_new(runner);
test_vcatf_percent(runner);
test_vcatf_s(runner);
@@ -344,5 +355,6 @@ TestCB_Run_IMP(TestCharBuf *self, TestBatchRunner *runner) {
test_Cat(runner);
test_Mimic_and_Clone(runner);
test_Get_Ptr8(runner);
+ test_Clear(runner);
}
[2/6] lucy-clownfish git commit: Implement BB_Utf8_To_String
Posted by nw...@apache.org.
Implement BB_Utf8_To_String
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ae8edad3
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ae8edad3
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ae8edad3
Branch: refs/heads/master
Commit: ae8edad36e156b90ea0750a170c8a8ec15667828
Parents: d30a279
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 10 13:04:48 2015 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Nov 12 14:08:17 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/ByteBuf.c | 10 ++++++++++
runtime/core/Clownfish/ByteBuf.cfh | 12 ++++++++++++
runtime/core/Clownfish/Test/TestByteBuf.c | 23 ++++++++++++++++++++++-
3 files changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae8edad3/runtime/core/Clownfish/ByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c
index 16a8292..11a0acc 100644
--- a/runtime/core/Clownfish/ByteBuf.c
+++ b/runtime/core/Clownfish/ByteBuf.c
@@ -207,6 +207,16 @@ BB_Yield_Blob_IMP(ByteBuf *self) {
return blob;
}
+String*
+BB_Utf8_To_String_IMP(ByteBuf *self) {
+ return Str_new_from_utf8(self->buf, self->size);
+}
+
+String*
+BB_Trusted_Utf8_To_String_IMP(ByteBuf *self) {
+ return Str_new_from_trusted_utf8(self->buf, self->size);
+}
+
int
BB_compare(const void *va, const void *vb) {
ByteBuf *a = *(ByteBuf**)va;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae8edad3/runtime/core/Clownfish/ByteBuf.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.cfh b/runtime/core/Clownfish/ByteBuf.cfh
index 95e503f..230bb86 100644
--- a/runtime/core/Clownfish/ByteBuf.cfh
+++ b/runtime/core/Clownfish/ByteBuf.cfh
@@ -117,6 +117,18 @@ final class Clownfish::ByteBuf nickname BB inherits Clownfish::Obj {
incremented Blob*
Yield_Blob(ByteBuf *self);
+ /** Return a String which holds a copy of the UTF-8 character data in
+ * the ByteBuf after checking for validity.
+ */
+ public incremented String*
+ Utf8_To_String(ByteBuf *self);
+
+ /** Return a String which holds a copy of the UTF-8 character data in
+ * the ByteBuf, skipping validity checks.
+ */
+ public incremented String*
+ Trusted_Utf8_To_String(ByteBuf *self);
+
/** Test whether the ByteBuf matches the passed-in bytes.
*/
bool
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ae8edad3/runtime/core/Clownfish/Test/TestByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestByteBuf.c b/runtime/core/Clownfish/Test/TestByteBuf.c
index d7eb045..57238bc 100644
--- a/runtime/core/Clownfish/Test/TestByteBuf.c
+++ b/runtime/core/Clownfish/Test/TestByteBuf.c
@@ -146,14 +146,35 @@ test_Cat(TestBatchRunner *runner) {
DECREF(wanted);
}
+static void
+test_Utf8_To_String(TestBatchRunner *runner) {
+ ByteBuf *bb = BB_new_bytes("foo", 3);
+
+ {
+ String *string = BB_Utf8_To_String(bb);
+ TEST_TRUE(runner, Str_Equals_Utf8(string, "foo", 3), "Utf8_To_String");
+ DECREF(string);
+ }
+
+ {
+ String *string = BB_Trusted_Utf8_To_String(bb);
+ TEST_TRUE(runner, Str_Equals_Utf8(string, "foo", 3),
+ "Trusted_Utf8_To_String");
+ DECREF(string);
+ }
+
+ DECREF(bb);
+}
+
void
TestBB_Run_IMP(TestByteBuf *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 20);
+ TestBatchRunner_Plan(runner, (TestBatch*)self, 22);
test_Equals(runner);
test_Grow(runner);
test_Clone(runner);
test_compare(runner);
test_Mimic(runner);
+ test_Utf8_To_String(runner);
test_Cat(runner);
}
[3/6] lucy-clownfish git commit: Add initializer BB_init_bytes
Posted by nw...@apache.org.
Add initializer BB_init_bytes
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/10f04e6c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/10f04e6c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/10f04e6c
Branch: refs/heads/master
Commit: 10f04e6c9d815575eab58ed6b10b1dd079c8ee86
Parents: cada6ca
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Nov 12 13:49:27 2015 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Nov 12 14:08:17 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/ByteBuf.c | 5 +++++
runtime/core/Clownfish/ByteBuf.cfh | 5 ++++-
2 files changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/10f04e6c/runtime/core/Clownfish/ByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c
index 210ed18..625da29 100644
--- a/runtime/core/Clownfish/ByteBuf.c
+++ b/runtime/core/Clownfish/ByteBuf.c
@@ -50,6 +50,11 @@ BB_init(ByteBuf *self, size_t capacity) {
ByteBuf*
BB_new_bytes(const void *bytes, size_t size) {
ByteBuf *self = (ByteBuf*)Class_Make_Obj(BYTEBUF);
+ return BB_init_bytes(self, bytes, size);
+}
+
+ByteBuf*
+BB_init_bytes(ByteBuf *self, const void *bytes, size_t size) {
BB_init(self, size);
memcpy(self->buf, bytes, size);
self->size = size;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/10f04e6c/runtime/core/Clownfish/ByteBuf.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.cfh b/runtime/core/Clownfish/ByteBuf.cfh
index 0235741..95e503f 100644
--- a/runtime/core/Clownfish/ByteBuf.cfh
+++ b/runtime/core/Clownfish/ByteBuf.cfh
@@ -36,11 +36,14 @@ final class Clownfish::ByteBuf nickname BB inherits Clownfish::Obj {
init(ByteBuf *self, size_t capacity);
/** Return a pointer to a new ByteBuf which holds a copy of the passed-in
- * string.
+ * bytes.
*/
inert incremented ByteBuf*
new_bytes(const void *bytes, size_t size);
+ inert ByteBuf*
+ init_bytes(ByteBuf *self, const void *bytes, size_t size);
+
/** Return a pointer to a new ByteBuf which assumes ownership of the
* passed-in string.
*/
[4/6] lucy-clownfish git commit: Implement Str_To_ByteBuf
Posted by nw...@apache.org.
Implement Str_To_ByteBuf
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2ba218ef
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2ba218ef
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2ba218ef
Branch: refs/heads/master
Commit: 2ba218ef6c7b7fd4a0136f4906f42db85888343a
Parents: 10f04e6
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Nov 12 13:50:05 2015 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Nov 12 14:08:17 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/String.c | 6 ++++++
runtime/core/Clownfish/String.cfh | 5 +++++
runtime/core/Clownfish/Test/TestString.c | 13 ++++++++++++-
3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2ba218ef/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.c b/runtime/core/Clownfish/String.c
index 4daaa83..7c2c0fa 100644
--- a/runtime/core/Clownfish/String.c
+++ b/runtime/core/Clownfish/String.c
@@ -26,6 +26,7 @@
#include "Clownfish/Class.h"
#include "Clownfish/String.h"
+#include "Clownfish/ByteBuf.h"
#include "Clownfish/CharBuf.h"
#include "Clownfish/Err.h"
#include "Clownfish/Util/Memory.h"
@@ -290,6 +291,11 @@ Str_To_Utf8_IMP(String *self) {
return buf;
}
+ByteBuf*
+Str_To_ByteBuf_IMP(String *self) {
+ return BB_new_bytes(self->ptr, self->size);
+}
+
String*
Str_Clone_IMP(String *self) {
return (String*)INCREF(self);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2ba218ef/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index 284e6ec..a2d6337 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -212,6 +212,11 @@ public final class Clownfish::String nickname Str
public char*
To_Utf8(String *self);
+ /** Return a ByteBuf which holds a copy of the String.
+ */
+ public incremented ByteBuf*
+ To_ByteBuf(String *self);
+
public incremented String*
Clone(String *self);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2ba218ef/runtime/core/Clownfish/Test/TestString.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestString.c b/runtime/core/Clownfish/Test/TestString.c
index c32dbd1..86103e2 100644
--- a/runtime/core/Clownfish/Test/TestString.c
+++ b/runtime/core/Clownfish/Test/TestString.c
@@ -24,6 +24,7 @@
#include "Clownfish/String.h"
#include "Clownfish/Boolean.h"
+#include "Clownfish/ByteBuf.h"
#include "Clownfish/CharBuf.h"
#include "Clownfish/Test.h"
#include "Clownfish/TestHarness/TestBatchRunner.h"
@@ -374,6 +375,15 @@ test_To_Utf8(TestBatchRunner *runner) {
}
static void
+test_To_ByteBuf(TestBatchRunner *runner) {
+ String *string = Str_newf("foo");
+ ByteBuf *bb = Str_To_ByteBuf(string);
+ TEST_TRUE(runner, BB_Equals_Bytes(bb, "foo", 3), "To_ByteBuf");
+ DECREF(bb);
+ DECREF(string);
+}
+
+static void
test_Length(TestBatchRunner *runner) {
String *string = Str_newf("a%s%sb%sc", smiley, smiley, smiley);
TEST_INT_EQ(runner, Str_Length(string), 6, "Length");
@@ -693,7 +703,7 @@ test_iterator_substring(TestBatchRunner *runner) {
void
TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 138);
+ TestBatchRunner_Plan(runner, (TestBatch*)self, 139);
test_new(runner);
test_Cat(runner);
test_Clone(runner);
@@ -705,6 +715,7 @@ TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) {
test_To_I64(runner);
test_To_String(runner);
test_To_Utf8(runner);
+ test_To_ByteBuf(runner);
test_Length(runner);
test_Compare_To(runner);
test_Starts_Ends_With(runner);
[5/6] lucy-clownfish git commit: Make BB_Mimic work with Strings
Posted by nw...@apache.org.
Make BB_Mimic work with Strings
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/d30a279f
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/d30a279f
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/d30a279f
Branch: refs/heads/master
Commit: d30a279ffeda9ff9d7e163ac0b3f3194f2b8e074
Parents: 2ba218e
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Nov 10 12:54:54 2015 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Nov 12 14:08:17 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/ByteBuf.c | 14 ++++++++++++--
runtime/core/Clownfish/Test/TestByteBuf.c | 8 +++++++-
2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d30a279f/runtime/core/Clownfish/ByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c
index 625da29..16a8292 100644
--- a/runtime/core/Clownfish/ByteBuf.c
+++ b/runtime/core/Clownfish/ByteBuf.c
@@ -26,6 +26,7 @@
#include "Clownfish/ByteBuf.h"
#include "Clownfish/Blob.h"
#include "Clownfish/Err.h"
+#include "Clownfish/String.h"
#include "Clownfish/Util/Memory.h"
static void
@@ -144,8 +145,17 @@ BB_Mimic_Bytes_IMP(ByteBuf *self, const void *bytes, size_t size) {
void
BB_Mimic_IMP(ByteBuf *self, Obj *other) {
- ByteBuf *twin = (ByteBuf*)CERTIFY(other, BYTEBUF);
- SI_mimic_bytes(self, twin->buf, twin->size);
+ if (Obj_is_a(other, BYTEBUF)) {
+ ByteBuf *twin = (ByteBuf*)other;
+ SI_mimic_bytes(self, twin->buf, twin->size);
+ }
+ else if (Obj_is_a(other, STRING)) {
+ String *string = (String*)other;
+ SI_mimic_bytes(self, Str_Get_Ptr8(string), Str_Get_Size(string));
+ }
+ else {
+ THROW(ERR, "ByteBuf can't mimic %o", Obj_get_class_name(other));
+ }
}
static CFISH_INLINE void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/d30a279f/runtime/core/Clownfish/Test/TestByteBuf.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestByteBuf.c b/runtime/core/Clownfish/Test/TestByteBuf.c
index 1fe41b8..d7eb045 100644
--- a/runtime/core/Clownfish/Test/TestByteBuf.c
+++ b/runtime/core/Clownfish/Test/TestByteBuf.c
@@ -27,6 +27,7 @@
#include "Clownfish/TestHarness/TestUtils.h"
#include "Clownfish/Blob.h"
#include "Clownfish/Class.h"
+#include "Clownfish/String.h"
TestByteBuf*
TestBB_new() {
@@ -118,6 +119,11 @@ test_Mimic(TestBatchRunner *runner) {
BB_Mimic(b, (Obj*)a);
TEST_TRUE(runner, BB_Equals(a, (Obj*)b), "Mimic");
+ String *string = Str_newf("baz");
+ BB_Mimic(b, (Obj*)string);
+ DECREF(string);
+ TEST_TRUE(runner, BB_Equals_Bytes(b, "baz", 3), "Mimic String");
+
DECREF(a);
DECREF(b);
}
@@ -142,7 +148,7 @@ test_Cat(TestBatchRunner *runner) {
void
TestBB_Run_IMP(TestByteBuf *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 19);
+ TestBatchRunner_Plan(runner, (TestBatch*)self, 20);
test_Equals(runner);
test_Grow(runner);
test_Clone(runner);
[6/6] lucy-clownfish git commit: Merge branch 'bytebuf-api-v2'
Posted by nw...@apache.org.
Merge branch 'bytebuf-api-v2'
This differs from the initial pull request by using methods instead
of constructors to convert between Strings and ByteBufs. This has
some advantages:
- Doesn't require custom code for host language wrappers.
- Allows direct access to ivars.
- Doesn't clutter up String constructors.
Obsoletes and resolves #43.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/71ea0c57
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/71ea0c57
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/71ea0c57
Branch: refs/heads/master
Commit: 71ea0c573f3493da15e192a6ab0f6f235f3c7291
Parents: cada6ca 3571968
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Nov 12 14:08:30 2015 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Thu Nov 12 14:10:21 2015 +0100
----------------------------------------------------------------------
runtime/core/Clownfish/ByteBuf.c | 29 ++++++++++++++++++++++++--
runtime/core/Clownfish/ByteBuf.cfh | 17 ++++++++++++++-
runtime/core/Clownfish/CharBuf.c | 5 +++++
runtime/core/Clownfish/CharBuf.cfh | 5 +++++
runtime/core/Clownfish/String.c | 6 ++++++
runtime/core/Clownfish/String.cfh | 5 +++++
runtime/core/Clownfish/Test/TestByteBuf.c | 29 +++++++++++++++++++++++++-
runtime/core/Clownfish/Test/TestCharBuf.c | 14 ++++++++++++-
runtime/core/Clownfish/Test/TestString.c | 13 +++++++++++-
9 files changed, 117 insertions(+), 6 deletions(-)
----------------------------------------------------------------------