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 2014/08/12 21:56:40 UTC

[5/5] git commit: refs/heads/const_pointers - Const InStream buffer

Const InStream buffer


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/049ae731
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/049ae731
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/049ae731

Branch: refs/heads/const_pointers
Commit: 049ae73194f79344e5c80b95459d21538ebcace7
Parents: 093dc8b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Aug 12 21:19:43 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 12 21:37:35 2014 +0200

----------------------------------------------------------------------
 core/Lucy/Index/BitVecDelDocs.c     | 1 +
 core/Lucy/Store/InStream.c          | 4 ++--
 core/Lucy/Store/InStream.cfh        | 6 +++---
 core/Lucy/Test/Store/TestIOChunks.c | 8 ++++----
 core/Lucy/Util/Json.c               | 2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/049ae731/core/Lucy/Index/BitVecDelDocs.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/BitVecDelDocs.c b/core/Lucy/Index/BitVecDelDocs.c
index 24b49a0..4cd1e50 100644
--- a/core/Lucy/Index/BitVecDelDocs.c
+++ b/core/Lucy/Index/BitVecDelDocs.c
@@ -39,6 +39,7 @@ BitVecDelDocs_init(BitVecDelDocs *self, Folder *folder,
         DECREF(self);
         RETHROW(error);
     }
+    // Cast away const-ness of buffer as we have no immutable BitVector.
     int32_t len    = (int32_t)InStream_Length(ivars->instream);
     ivars->bits    = (uint8_t*)InStream_Buf(ivars->instream, len);
     ivars->cap     = (uint32_t)(len * 8);

http://git-wip-us.apache.org/repos/asf/lucy/blob/049ae731/core/Lucy/Store/InStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/InStream.c b/core/Lucy/Store/InStream.c
index 8a47ff7..43881e8 100644
--- a/core/Lucy/Store/InStream.c
+++ b/core/Lucy/Store/InStream.c
@@ -286,7 +286,7 @@ InStream_Length_IMP(InStream *self) {
     return InStream_IVARS(self)->len;
 }
 
-char*
+const char*
 InStream_Buf_IMP(InStream *self, size_t request) {
     InStreamIVARS *const ivars = InStream_IVARS(self);
     const int64_t bytes_in_buf
@@ -330,7 +330,7 @@ InStream_Advance_Buf_IMP(InStream *self, const char *buf) {
         THROW(ERR, "Can't Advance_Buf backwards: (underrun: %i64))", underrun);
     }
     else {
-        ivars->buf += buf - ivars->buf;
+        ivars->buf = buf;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/049ae731/core/Lucy/Store/InStream.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/InStream.cfh b/core/Lucy/Store/InStream.cfh
index 6a7a89c..9e57ee0 100644
--- a/core/Lucy/Store/InStream.cfh
+++ b/core/Lucy/Store/InStream.cfh
@@ -35,8 +35,8 @@ class Lucy::Store::InStream inherits Clownfish::Obj {
 
     int64_t     offset;
     int64_t     len;
-    char       *buf;
-    char       *limit;
+    const char *buf;
+    const char *limit;
     String     *filename;
     FileHandle *file_handle;
     FileWindow *window;
@@ -115,7 +115,7 @@ class Lucy::Store::InStream inherits Clownfish::Obj {
      * @param request Advisory byte size request.
      * @return Pointer to the InStream's internal buffer.
      */
-    final char*
+    final const char*
     Buf(InStream *self, size_t request);
 
     /** Set the buf to a new value, checking for overrun.  The idiom is for

http://git-wip-us.apache.org/repos/asf/lucy/blob/049ae731/core/Lucy/Test/Store/TestIOChunks.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Store/TestIOChunks.c b/core/Lucy/Test/Store/TestIOChunks.c
index 1df0651..c09d665 100644
--- a/core/Lucy/Test/Store/TestIOChunks.c
+++ b/core/Lucy/Test/Store/TestIOChunks.c
@@ -80,7 +80,7 @@ test_Buf(TestBatchRunner *runner) {
     OutStream  *outstream = OutStream_open((Obj*)file);
     size_t      size      = IO_STREAM_BUF_SIZE * 2 + 5;
     InStream   *instream;
-    char       *buf;
+    const char *buf;
 
     for (uint32_t i = 0; i < size; i++) {
         OutStream_Write_U8(outstream, 'a');
@@ -104,9 +104,9 @@ test_Buf(TestBatchRunner *runner) {
     TEST_INT_EQ(runner, ivars->limit - buf, IO_STREAM_BUF_SIZE,
                 "Requesting over limit triggers refill");
 
-    int64_t  expected = InStream_Length(instream) - InStream_Tell(instream);
-    char    *buff     = InStream_Buf(instream, 100000);
-    int64_t  got      = CHY_PTR_TO_I64(ivars->limit) - CHY_PTR_TO_I64(buff);
+    int64_t     expected = InStream_Length(instream) - InStream_Tell(instream);
+    const char *buff     = InStream_Buf(instream, 100000);
+    int64_t     got      = CHY_PTR_TO_I64(ivars->limit) - CHY_PTR_TO_I64(buff);
     TEST_TRUE(runner, got == expected,
               "Requests greater than file size get pared down");
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/049ae731/core/Lucy/Util/Json.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/Json.c b/core/Lucy/Util/Json.c
index cb8625c..1d8ea9c 100644
--- a/core/Lucy/Util/Json.c
+++ b/core/Lucy/Util/Json.c
@@ -108,7 +108,7 @@ Json_slurp_json(Folder *folder, String *path) {
         return NULL;
     }
     size_t len = (size_t)InStream_Length(instream);
-    char *buf = InStream_Buf(instream, len);
+    const char *buf = InStream_Buf(instream, len);
     Obj *dump = S_parse_json(buf, len);
     InStream_Close(instream);
     DECREF(instream);