lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [16/34] Migrate Lucy's store classes to IVARS.
Date Wed, 17 Jul 2013 14:12:36 GMT
http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/LockFactory.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/LockFactory.c b/core/Lucy/Store/LockFactory.c
index 2f1f362..4bcae61 100644
--- a/core/Lucy/Store/LockFactory.c
+++ b/core/Lucy/Store/LockFactory.c
@@ -34,29 +34,33 @@ LockFact_new(Folder *folder, const CharBuf *host) {
 
 LockFactory*
 LockFact_init(LockFactory *self, Folder *folder, const CharBuf *host) {
-    self->folder    = (Folder*)INCREF(folder);
-    self->host      = CB_Clone(host);
+    LockFactoryIVARS *const ivars = LockFact_IVARS(self);
+    ivars->folder    = (Folder*)INCREF(folder);
+    ivars->host      = CB_Clone(host);
     return self;
 }
 
 void
 LockFact_destroy(LockFactory *self) {
-    DECREF(self->folder);
-    DECREF(self->host);
+    LockFactoryIVARS *const ivars = LockFact_IVARS(self);
+    DECREF(ivars->folder);
+    DECREF(ivars->host);
     SUPER_DESTROY(self, LOCKFACTORY);
 }
 
 Lock*
 LockFact_make_lock(LockFactory *self, const CharBuf *name, int32_t timeout,
                    int32_t interval) {
-    return (Lock*)LFLock_new(self->folder, name, self->host, timeout,
+    LockFactoryIVARS *const ivars = LockFact_IVARS(self);
+    return (Lock*)LFLock_new(ivars->folder, name, ivars->host, timeout,
                              interval);
 }
 
 Lock*
 LockFact_make_shared_lock(LockFactory *self, const CharBuf *name,
                           int32_t timeout, int32_t interval) {
-    return (Lock*)ShLock_new(self->folder, name, self->host, timeout,
+    LockFactoryIVARS *const ivars = LockFact_IVARS(self);
+    return (Lock*)ShLock_new(ivars->folder, name, ivars->host, timeout,
                              interval);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/OutStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/OutStream.c b/core/Lucy/Store/OutStream.c
index 1a38066..b9122c2 100644
--- a/core/Lucy/Store/OutStream.c
+++ b/core/Lucy/Store/OutStream.c
@@ -27,15 +27,16 @@
 
 // Inlined version of OutStream_Write_Bytes.
 static INLINE void
-SI_write_bytes(OutStream *self, const void *bytes, size_t len);
+SI_write_bytes(OutStream *self, OutStreamIVARS *ivars,
+               const void *bytes, size_t len);
 
 // Inlined version of OutStream_Write_C32.
 static INLINE void
-SI_write_c32(OutStream *self, uint32_t value);
+SI_write_c32(OutStream *self, OutStreamIVARS *ivars, uint32_t value);
 
 // Flush content in the buffer to the FileHandle.
 static void
-S_flush(OutStream *self);
+S_flush(OutStream *self, OutStreamIVARS *ivars);
 
 OutStream*
 OutStream_open(Obj *file) {
@@ -45,22 +46,24 @@ OutStream_open(Obj *file) {
 
 OutStream*
 OutStream_do_open(OutStream *self, Obj *file) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+
     // Init.
-    self->buf         = (char*)MALLOCATE(IO_STREAM_BUF_SIZE);
-    self->buf_start   = 0;
-    self->buf_pos     = 0;
+    ivars->buf         = (char*)MALLOCATE(IO_STREAM_BUF_SIZE);
+    ivars->buf_start   = 0;
+    ivars->buf_pos     = 0;
 
     // Obtain a FileHandle.
     if (Obj_Is_A(file, FILEHANDLE)) {
-        self->file_handle = (FileHandle*)INCREF(file);
+        ivars->file_handle = (FileHandle*)INCREF(file);
     }
     else if (Obj_Is_A(file, RAMFILE)) {
-        self->file_handle
+        ivars->file_handle
             = (FileHandle*)RAMFH_open(NULL, FH_WRITE_ONLY, (RAMFile*)file);
     }
     else if (Obj_Is_A(file, CHARBUF)) {
-        self->file_handle = (FileHandle*)FSFH_open((CharBuf*)file,
-                                                   FH_WRITE_ONLY | FH_CREATE | FH_EXCLUSIVE);
+        ivars->file_handle = (FileHandle*)FSFH_open((CharBuf*)file,
+                                                    FH_WRITE_ONLY | FH_CREATE | FH_EXCLUSIVE);
     }
     else {
         Err_set_error(Err_new(CB_newf("Invalid type for param 'file': '%o'",
@@ -68,39 +71,41 @@ OutStream_do_open(OutStream *self, Obj *file) {
         DECREF(self);
         return NULL;
     }
-    if (!self->file_handle) {
+    if (!ivars->file_handle) {
         ERR_ADD_FRAME(Err_get_error());
         DECREF(self);
         return NULL;
     }
 
     // Derive filepath from FileHandle.
-    self->path = CB_Clone(FH_Get_Path(self->file_handle));
+    ivars->path = CB_Clone(FH_Get_Path(ivars->file_handle));
 
     return self;
 }
 
 void
 OutStream_destroy(OutStream *self) {
-    if (self->file_handle != NULL) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    if (ivars->file_handle != NULL) {
         // Inlined flush, ignoring errors.
-        if (self->buf_pos) {
-            FH_Write(self->file_handle, self->buf, self->buf_pos);
+        if (ivars->buf_pos) {
+            FH_Write(ivars->file_handle, ivars->buf, ivars->buf_pos);
         }
-        DECREF(self->file_handle);
+        DECREF(ivars->file_handle);
     }
-    DECREF(self->path);
-    FREEMEM(self->buf);
+    DECREF(ivars->path);
+    FREEMEM(ivars->buf);
     SUPER_DESTROY(self, OUTSTREAM);
 }
 
 CharBuf*
 OutStream_get_path(OutStream *self) {
-    return self->path;
+    return OutStream_IVARS(self)->path;
 }
 
 void
 OutStream_absorb(OutStream *self, InStream *instream) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
     char buf[IO_STREAM_BUF_SIZE];
     int64_t bytes_left = InStream_Length(instream);
 
@@ -115,21 +120,23 @@ OutStream_absorb(OutStream *self, InStream *instream) {
                                        ? (size_t)bytes_left
                                        : IO_STREAM_BUF_SIZE;
         InStream_Read_Bytes(instream, buf, bytes_this_iter);
-        SI_write_bytes(self, buf, bytes_this_iter);
+        SI_write_bytes(self, ivars, buf, bytes_this_iter);
         bytes_left -= bytes_this_iter;
     }
 }
 
 void
 OutStream_grow(OutStream *self, int64_t length) {
-    if (!FH_Grow(self->file_handle, length)) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    if (!FH_Grow(ivars->file_handle, length)) {
         RETHROW(INCREF(Err_get_error()));
     }
 }
 
 int64_t
 OutStream_tell(OutStream *self) {
-    return self->buf_start + self->buf_pos;
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    return ivars->buf_start + ivars->buf_pos;
 }
 
 int64_t
@@ -142,19 +149,21 @@ OutStream_align(OutStream *self, int64_t modulus) {
 
 void
 OutStream_flush(OutStream *self) {
-    S_flush(self);
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    S_flush(self, ivars);
 }
 
 static void
-S_flush(OutStream *self) {
-    if (self->file_handle == NULL) {
-        THROW(ERR, "Can't write to a closed OutStream for %o", self->path);
+S_flush(OutStream *self, OutStreamIVARS *ivars) {
+    UNUSED_VAR(self);
+    if (ivars->file_handle == NULL) {
+        THROW(ERR, "Can't write to a closed OutStream for %o", ivars->path);
     }
-    if (!FH_Write(self->file_handle, self->buf, self->buf_pos)) {
+    if (!FH_Write(ivars->file_handle, ivars->buf, ivars->buf_pos)) {
         RETHROW(INCREF(Err_get_error()));
     }
-    self->buf_start += self->buf_pos;
-    self->buf_pos = 0;
+    ivars->buf_start += ivars->buf_pos;
+    ivars->buf_pos = 0;
 }
 
 int64_t
@@ -164,117 +173,122 @@ OutStream_length(OutStream *self) {
 
 void
 OutStream_write_bytes(OutStream *self, const void *bytes, size_t len) {
-    SI_write_bytes(self, bytes, len);
+    SI_write_bytes(self, OutStream_IVARS(self), bytes, len);
 }
 
 static INLINE void
-SI_write_bytes(OutStream *self, const void *bytes, size_t len) {
+SI_write_bytes(OutStream *self, OutStreamIVARS *ivars,
+               const void *bytes, size_t len) {
     // If this data is larger than the buffer size, flush and write.
     if (len >= IO_STREAM_BUF_SIZE) {
-        S_flush(self);
-        if (!FH_Write(self->file_handle, bytes, len)) {
+        S_flush(self, ivars);
+        if (!FH_Write(ivars->file_handle, bytes, len)) {
             RETHROW(INCREF(Err_get_error()));
         }
-        self->buf_start += len;
+        ivars->buf_start += len;
     }
     // If there's not enough room in the buffer, flush then add.
-    else if (self->buf_pos + len >= IO_STREAM_BUF_SIZE) {
-        S_flush(self);
-        memcpy((self->buf + self->buf_pos), bytes, len);
-        self->buf_pos += len;
+    else if (ivars->buf_pos + len >= IO_STREAM_BUF_SIZE) {
+        S_flush(self, ivars);
+        memcpy((ivars->buf + ivars->buf_pos), bytes, len);
+        ivars->buf_pos += len;
     }
     // If there's room, just add these bytes to the buffer.
     else {
-        memcpy((self->buf + self->buf_pos), bytes, len);
-        self->buf_pos += len;
+        memcpy((ivars->buf + ivars->buf_pos), bytes, len);
+        ivars->buf_pos += len;
     }
 }
 
 static INLINE void
-SI_write_u8(OutStream *self, uint8_t value) {
-    if (self->buf_pos >= IO_STREAM_BUF_SIZE) {
-        S_flush(self);
+SI_write_u8(OutStream *self, OutStreamIVARS *ivars, uint8_t value) {
+    if (ivars->buf_pos >= IO_STREAM_BUF_SIZE) {
+        S_flush(self, ivars);
     }
-    self->buf[self->buf_pos++] = (char)value;
+    ivars->buf[ivars->buf_pos++] = (char)value;
 }
 
 void
 OutStream_write_i8(OutStream *self, int8_t value) {
-    SI_write_u8(self, (uint8_t)value);
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    SI_write_u8(self, ivars, (uint8_t)value);
 }
 
 void
 OutStream_write_u8(OutStream *self, uint8_t value) {
-    SI_write_u8(self, value);
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    SI_write_u8(self, ivars, value);
 }
 
 static INLINE void
-SI_write_u32(OutStream *self, uint32_t value) {
+SI_write_u32(OutStream *self, OutStreamIVARS *ivars, uint32_t value) {
 #ifdef BIG_END
-    SI_write_bytes(self, &value, 4);
+    SI_write_bytes(self, ivars, &value, 4);
 #else
     char  buf[4];
     char *buf_copy = buf;
     NumUtil_encode_bigend_u32(value, &buf_copy);
-    SI_write_bytes(self, buf, 4);
+    SI_write_bytes(self, ivars, buf, 4);
 #endif
 }
 
 void
 OutStream_write_i32(OutStream *self, int32_t value) {
-    SI_write_u32(self, (uint32_t)value);
+    SI_write_u32(self, OutStream_IVARS(self), (uint32_t)value);
 }
 
 void
 OutStream_write_u32(OutStream *self, uint32_t value) {
-    SI_write_u32(self, value);
+    SI_write_u32(self, OutStream_IVARS(self), value);
 }
 
 static INLINE void
-SI_write_u64(OutStream *self, uint64_t value) {
+SI_write_u64(OutStream *self, OutStreamIVARS *ivars, uint64_t value) {
 #ifdef BIG_END
-    SI_write_bytes(self, &value, 8);
+    SI_write_bytes(self, ivars, &value, 8);
 #else
     char  buf[sizeof(uint64_t)];
     char *buf_copy = buf;
     NumUtil_encode_bigend_u64(value, &buf_copy);
-    SI_write_bytes(self, buf, sizeof(uint64_t));
+    SI_write_bytes(self, ivars, buf, sizeof(uint64_t));
 #endif
 }
 
 void
 OutStream_write_i64(OutStream *self, int64_t value) {
-    SI_write_u64(self, (uint64_t)value);
+    SI_write_u64(self, OutStream_IVARS(self), (uint64_t)value);
 }
 
 void
 OutStream_write_u64(OutStream *self, uint64_t value) {
-    SI_write_u64(self, value);
+    SI_write_u64(self, OutStream_IVARS(self), value);
 }
 
 void
 OutStream_write_f32(OutStream *self, float value) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
     char  buf[sizeof(float)];
     char *buf_copy = buf;
     NumUtil_encode_bigend_f32(value, &buf_copy);
-    SI_write_bytes(self, buf_copy, sizeof(float));
+    SI_write_bytes(self, ivars, buf_copy, sizeof(float));
 }
 
 void
 OutStream_write_f64(OutStream *self, double value) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
     char  buf[sizeof(double)];
     char *buf_copy = buf;
     NumUtil_encode_bigend_f64(value, &buf_copy);
-    SI_write_bytes(self, buf_copy, sizeof(double));
+    SI_write_bytes(self, ivars, buf_copy, sizeof(double));
 }
 
 void
 OutStream_write_c32(OutStream *self, uint32_t value) {
-    SI_write_c32(self, value);
+    SI_write_c32(self, OutStream_IVARS(self), value);
 }
 
 static INLINE void
-SI_write_c32(OutStream *self, uint32_t value) {
+SI_write_c32(OutStream *self, OutStreamIVARS *ivars, uint32_t value) {
     uint8_t buf[C32_MAX_BYTES];
     uint8_t *ptr = buf + sizeof(buf) - 1;
 
@@ -288,11 +302,12 @@ SI_write_c32(OutStream *self, uint32_t value) {
         value >>= 7;
     }
 
-    SI_write_bytes(self, ptr, (buf + sizeof(buf)) - ptr);
+    SI_write_bytes(self, ivars, ptr, (buf + sizeof(buf)) - ptr);
 }
 
 void
 OutStream_write_c64(OutStream *self, uint64_t value) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
     uint8_t buf[C64_MAX_BYTES];
     uint8_t *ptr = buf + sizeof(buf) - 1;
 
@@ -306,24 +321,26 @@ OutStream_write_c64(OutStream *self, uint64_t value) {
         value >>= 7;
     }
 
-    SI_write_bytes(self, ptr, (buf + sizeof(buf)) - ptr);
+    SI_write_bytes(self, ivars, ptr, (buf + sizeof(buf)) - ptr);
 }
 
 void
 OutStream_write_string(OutStream *self, const char *string, size_t len) {
-    SI_write_c32(self, (uint32_t)len);
-    SI_write_bytes(self, string, len);
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    SI_write_c32(self, ivars, (uint32_t)len);
+    SI_write_bytes(self, ivars, string, len);
 }
 
 void
 OutStream_close(OutStream *self) {
-    if (self->file_handle) {
-        S_flush(self);
-        if (!FH_Close(self->file_handle)) {
+    OutStreamIVARS *const ivars = OutStream_IVARS(self);
+    if (ivars->file_handle) {
+        S_flush(self, ivars);
+        if (!FH_Close(ivars->file_handle)) {
             RETHROW(INCREF(Err_get_error()));
         }
-        DECREF(self->file_handle);
-        self->file_handle = NULL;
+        DECREF(ivars->file_handle);
+        ivars->file_handle = NULL;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/RAMDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMDirHandle.c b/core/Lucy/Store/RAMDirHandle.c
index 1553895..71f616b 100644
--- a/core/Lucy/Store/RAMDirHandle.c
+++ b/core/Lucy/Store/RAMDirHandle.c
@@ -31,37 +31,40 @@ RAMDH_new(RAMFolder *folder) {
 RAMDirHandle*
 RAMDH_init(RAMDirHandle *self, RAMFolder *folder) {
     DH_init((DirHandle*)self, RAMFolder_Get_Path(folder));
-    self->folder = (RAMFolder*)INCREF(folder);
-    self->elems  = Hash_Keys(self->folder->entries);
-    self->tick   = -1;
+    RAMDirHandleIVARS *const ivars = RAMDH_IVARS(self);
+    ivars->folder = (RAMFolder*)INCREF(folder);
+    ivars->elems  = Hash_Keys(RAMFolder_IVARS(ivars->folder)->entries);
+    ivars->tick   = -1;
     return self;
 }
 
 bool
 RAMDH_close(RAMDirHandle *self) {
-    if (self->elems) {
-        VA_Dec_RefCount(self->elems);
-        self->elems = NULL;
+    RAMDirHandleIVARS *const ivars = RAMDH_IVARS(self);
+    if (ivars->elems) {
+        VA_Dec_RefCount(ivars->elems);
+        ivars->elems = NULL;
     }
-    if (self->folder) {
-        RAMFolder_Dec_RefCount(self->folder);
-        self->folder = NULL;
+    if (ivars->folder) {
+        RAMFolder_Dec_RefCount(ivars->folder);
+        ivars->folder = NULL;
     }
     return true;
 }
 
 bool
 RAMDH_next(RAMDirHandle *self) {
-    if (self->elems) {
-        self->tick++;
-        if (self->tick < (int32_t)VA_Get_Size(self->elems)) {
+    RAMDirHandleIVARS *const ivars = RAMDH_IVARS(self);
+    if (ivars->elems) {
+        ivars->tick++;
+        if (ivars->tick < (int32_t)VA_Get_Size(ivars->elems)) {
             CharBuf *path = (CharBuf*)CERTIFY(
-                                VA_Fetch(self->elems, self->tick), CHARBUF);
-            CB_Mimic(self->entry, (Obj*)path);
+                                VA_Fetch(ivars->elems, ivars->tick), CHARBUF);
+            CB_Mimic(ivars->entry, (Obj*)path);
             return true;
         }
         else {
-            self->tick--;
+            ivars->tick--;
             return false;
         }
     }
@@ -70,10 +73,11 @@ RAMDH_next(RAMDirHandle *self) {
 
 bool
 RAMDH_entry_is_dir(RAMDirHandle *self) {
-    if (self->elems) {
-        CharBuf *name = (CharBuf*)VA_Fetch(self->elems, self->tick);
+    RAMDirHandleIVARS *const ivars = RAMDH_IVARS(self);
+    if (ivars->elems) {
+        CharBuf *name = (CharBuf*)VA_Fetch(ivars->elems, ivars->tick);
         if (name) {
-            return RAMFolder_Local_Is_Directory(self->folder, name);
+            return RAMFolder_Local_Is_Directory(ivars->folder, name);
         }
     }
     return false;

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/RAMFile.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMFile.c b/core/Lucy/Store/RAMFile.c
index 3e41a7f..6766c00 100644
--- a/core/Lucy/Store/RAMFile.c
+++ b/core/Lucy/Store/RAMFile.c
@@ -27,30 +27,32 @@ RAMFile_new(ByteBuf *contents, bool read_only) {
 
 RAMFile*
 RAMFile_init(RAMFile *self, ByteBuf *contents, bool read_only) {
-    self->contents = contents ? (ByteBuf*)INCREF(contents) : BB_new(0);
-    self->read_only = read_only;
+    RAMFileIVARS *const ivars = RAMFile_IVARS(self);
+    ivars->contents = contents ? (ByteBuf*)INCREF(contents) : BB_new(0);
+    ivars->read_only = read_only;
     return self;
 }
 
 void
 RAMFile_destroy(RAMFile *self) {
-    DECREF(self->contents);
+    RAMFileIVARS *const ivars = RAMFile_IVARS(self);
+    DECREF(ivars->contents);
     SUPER_DESTROY(self, RAMFILE);
 }
 
 ByteBuf*
 RAMFile_get_contents(RAMFile *self) {
-    return self->contents;
+    return RAMFile_IVARS(self)->contents;
 }
 
 bool
 RAMFile_read_only(RAMFile *self) {
-    return self->read_only;
+    return RAMFile_IVARS(self)->read_only;
 }
 
 void
 RAMFile_set_read_only(RAMFile *self, bool read_only) {
-    self->read_only = read_only;
+    RAMFile_IVARS(self)->read_only = read_only;
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/RAMFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMFileHandle.c b/core/Lucy/Store/RAMFileHandle.c
index 828cabe..16f8bc2 100644
--- a/core/Lucy/Store/RAMFileHandle.c
+++ b/core/Lucy/Store/RAMFileHandle.c
@@ -15,8 +15,6 @@
  */
 
 #define C_LUCY_RAMFILEHANDLE
-#define C_LUCY_RAMFILE
-#define C_LUCY_FILEWINDOW
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Store/RAMFileHandle.h"
@@ -40,6 +38,7 @@ RAMFH_do_open(RAMFileHandle *self, const CharBuf *path, uint32_t flags,
           ? true : false;
 
     FH_do_open((FileHandle*)self, path, flags);
+    RAMFileHandleIVARS *const ivars = RAMFH_IVARS(self);
 
     // Obtain a RAMFile.
     if (file) {
@@ -48,10 +47,10 @@ RAMFH_do_open(RAMFileHandle *self, const CharBuf *path, uint32_t flags,
             DECREF(self);
             return NULL;
         }
-        self->ram_file = (RAMFile*)INCREF(file);
+        ivars->ram_file = (RAMFile*)INCREF(file);
     }
     else if (can_create) {
-        self->ram_file = RAMFile_new(NULL, false);
+        ivars->ram_file = RAMFile_new(NULL, false);
     }
     else {
         Err_set_error(Err_new(CB_newf("Must supply either RAMFile or FH_CREATE | FH_WRITE_ONLY")));
@@ -61,25 +60,29 @@ RAMFH_do_open(RAMFileHandle *self, const CharBuf *path, uint32_t flags,
 
     // Prevent writes to to the RAMFile if FH_READ_ONLY was specified.
     if (flags & FH_READ_ONLY) {
-        RAMFile_Set_Read_Only(self->ram_file, true);
+        RAMFile_Set_Read_Only(ivars->ram_file, true);
     }
 
-    self->len = BB_Get_Size(self->ram_file->contents);
+    ivars->contents = (ByteBuf*)INCREF(RAMFile_Get_Contents(ivars->ram_file));
+    ivars->len      = BB_Get_Size(ivars->contents);
 
     return self;
 }
 
 void
 RAMFH_destroy(RAMFileHandle *self) {
-    DECREF(self->ram_file);
+    RAMFileHandleIVARS *const ivars = RAMFH_IVARS(self);
+    DECREF(ivars->ram_file);
+    DECREF(ivars->contents);
     SUPER_DESTROY(self, RAMFILEHANDLE);
 }
 
 bool
 RAMFH_window(RAMFileHandle *self, FileWindow *window, int64_t offset,
              int64_t len) {
+    RAMFileHandleIVARS *const ivars = RAMFH_IVARS(self);
     int64_t end = offset + len;
-    if (!(self->flags & FH_READ_ONLY)) {
+    if (!(ivars->flags & FH_READ_ONLY)) {
         Err_set_error(Err_new(CB_newf("Can't read from write-only handle")));
         return false;
     }
@@ -88,13 +91,13 @@ RAMFH_window(RAMFileHandle *self, FileWindow *window, int64_t offset,
                                       offset)));
         return false;
     }
-    else if (end > self->len) {
+    else if (end > ivars->len) {
         Err_set_error(Err_new(CB_newf("Tried to read past EOF: offset %i64 + request %i64
> len %i64",
-                                      offset, len, self->len)));
+                                      offset, len, ivars->len)));
         return false;
     }
     else {
-        char *const buf = BB_Get_Buf(self->ram_file->contents) + offset;
+        char *const buf = BB_Get_Buf(ivars->contents) + offset;
         FileWindow_Set_Window(window, buf, offset, len);
         return true;
     }
@@ -109,8 +112,9 @@ RAMFH_release_window(RAMFileHandle *self, FileWindow *window) {
 
 bool
 RAMFH_read(RAMFileHandle *self, char *dest, int64_t offset, size_t len) {
+    RAMFileHandleIVARS *const ivars = RAMFH_IVARS(self);
     int64_t end = offset + len;
-    if (!(self->flags & FH_READ_ONLY)) {
+    if (!(ivars->flags & FH_READ_ONLY)) {
         Err_set_error(Err_new(CB_newf("Can't read from write-only handle")));
         return false;
     }
@@ -119,13 +123,13 @@ RAMFH_read(RAMFileHandle *self, char *dest, int64_t offset, size_t len)
{
                                       offset)));
         return false;
     }
-    else if (end > self->len) {
+    else if (end > ivars->len) {
         Err_set_error(Err_new(CB_newf("Attempt to read %u64 bytes starting at %i64 goes past
EOF %u64",
-                                      (uint64_t)len, offset, self->len)));
+                                      (uint64_t)len, offset, ivars->len)));
         return false;
     }
     else {
-        char *const source = BB_Get_Buf(self->ram_file->contents) + offset;
+        char *const source = BB_Get_Buf(ivars->contents) + offset;
         memcpy(dest, source, len);
         return true;
     }
@@ -133,41 +137,43 @@ RAMFH_read(RAMFileHandle *self, char *dest, int64_t offset, size_t len)
{
 
 bool
 RAMFH_write(RAMFileHandle *self, const void *data, size_t len) {
-    if (self->ram_file->read_only) {
+    RAMFileHandleIVARS *const ivars = RAMFH_IVARS(self);
+    if (ivars->flags & FH_READ_ONLY) {
         Err_set_error(Err_new(CB_newf("Attempt to write to read-only RAMFile")));
         return false;
     }
-    BB_Cat_Bytes(self->ram_file->contents, data, len);
-    self->len += len;
+    BB_Cat_Bytes(ivars->contents, data, len);
+    ivars->len += len;
     return true;
 }
 
 bool
 RAMFH_grow(RAMFileHandle *self, int64_t len) {
+    RAMFileHandleIVARS *const ivars = RAMFH_IVARS(self);
     if (len > INT32_MAX) {
         Err_set_error(Err_new(CB_newf("Can't support RAM files of size %i64 (> %i32)",
                                       len, (int32_t)INT32_MAX)));
         return false;
     }
-    else if (self->ram_file->read_only) {
+    else if (ivars->flags & FH_READ_ONLY) {
         Err_set_error(Err_new(CB_newf("Can't grow read-only RAMFile '%o'",
-                                      self->path)));
+                                      ivars->path)));
         return false;
     }
     else {
-        BB_Grow(self->ram_file->contents, (size_t)len);
+        BB_Grow(ivars->contents, (size_t)len);
         return true;
     }
 }
 
 RAMFile*
 RAMFH_get_file(RAMFileHandle *self) {
-    return self->ram_file;
+    return RAMFH_IVARS(self)->ram_file;
 }
 
 int64_t
 RAMFH_length(RAMFileHandle *self) {
-    return self->len;
+    return RAMFH_IVARS(self)->len;
 }
 
 bool

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/RAMFileHandle.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMFileHandle.cfh b/core/Lucy/Store/RAMFileHandle.cfh
index 956f1b0..6e55f45 100644
--- a/core/Lucy/Store/RAMFileHandle.cfh
+++ b/core/Lucy/Store/RAMFileHandle.cfh
@@ -25,6 +25,7 @@ class Lucy::Store::RAMFileHandle cnick RAMFH
     inherits Lucy::Store::FileHandle {
 
     RAMFile *ram_file;
+    ByteBuf *contents;
     int64_t  len;
 
     inert incremented nullable RAMFileHandle*

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/RAMFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMFolder.c b/core/Lucy/Store/RAMFolder.c
index c0d21f0..055ef04 100644
--- a/core/Lucy/Store/RAMFolder.c
+++ b/core/Lucy/Store/RAMFolder.c
@@ -55,14 +55,15 @@ RAMFolder_check(RAMFolder *self) {
 
 bool
 RAMFolder_local_mkdir(RAMFolder *self, const CharBuf *name) {
-    if (Hash_Fetch(self->entries, (Obj*)name)) {
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
+    if (Hash_Fetch(ivars->entries, (Obj*)name)) {
         Err_set_error(Err_new(CB_newf("Can't MkDir, '%o' already exists",
                                       name)));
         return false;
     }
     else {
         CharBuf *fullpath = S_fullpath(self, name);
-        Hash_Store(self->entries, (Obj*)name,
+        Hash_Store(ivars->entries, (Obj*)name,
                    (Obj*)RAMFolder_new(fullpath));
         DECREF(fullpath);
         return true;
@@ -72,9 +73,10 @@ RAMFolder_local_mkdir(RAMFolder *self, const CharBuf *name) {
 FileHandle*
 RAMFolder_local_open_filehandle(RAMFolder *self, const CharBuf *name,
                                 uint32_t flags) {
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
     RAMFileHandle *fh;
     CharBuf *fullpath = S_fullpath(self, name);
-    RAMFile *file = (RAMFile*)Hash_Fetch(self->entries, (Obj*)name);
+    RAMFile *file = (RAMFile*)Hash_Fetch(ivars->entries, (Obj*)name);
     bool can_create
         = (flags & (FH_WRITE_ONLY | FH_CREATE)) == (FH_WRITE_ONLY | FH_CREATE)
           ? true : false;
@@ -99,7 +101,7 @@ RAMFolder_local_open_filehandle(RAMFolder *self, const CharBuf *name,
     if (fh) {
         if (!file) {
             file = RAMFH_Get_File(fh);
-            Hash_Store(self->entries, (Obj*)name, INCREF(file));
+            Hash_Store(ivars->entries, (Obj*)name, INCREF(file));
         }
     }
     else {
@@ -121,12 +123,14 @@ RAMFolder_local_open_dir(RAMFolder *self) {
 
 bool
 RAMFolder_local_exists(RAMFolder *self, const CharBuf *name) {
-    return !!Hash_Fetch(self->entries, (Obj*)name);
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
+    return !!Hash_Fetch(ivars->entries, (Obj*)name);
 }
 
 bool
 RAMFolder_local_is_directory(RAMFolder *self, const CharBuf *name) {
-    Obj *entry = Hash_Fetch(self->entries, (Obj*)name);
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
+    Obj *entry = Hash_Fetch(ivars->entries, (Obj*)name);
     if (entry && Obj_Is_A(entry, FOLDER)) { return true; }
     return false;
 }
@@ -182,7 +186,8 @@ S_rename_or_hard_link(RAMFolder *self, const CharBuf* from, const CharBuf
*to,
     }
 
     // Find the original element.
-    elem = Hash_Fetch(inner_from_folder->entries, (Obj*)from_name);
+    elem = Hash_Fetch(RAMFolder_IVARS(inner_from_folder)->entries,
+                      (Obj*)from_name);
     if (!elem) {
         if (Folder_Is_A(from_folder, COMPOUNDFILEREADER)
             && Folder_Local_Exists(from_folder, (CharBuf*)from_name)
@@ -198,7 +203,8 @@ S_rename_or_hard_link(RAMFolder *self, const CharBuf* from, const CharBuf
*to,
 
     // Execute the rename/hard-link.
     if (op == OP_RENAME) {
-        Obj *existing = Hash_Fetch(inner_to_folder->entries, (Obj*)to_name);
+        Obj *existing = Hash_Fetch(RAMFolder_IVARS(inner_to_folder)->entries,
+                                   (Obj*)to_name);
         if (existing) {
             bool conflict = false;
 
@@ -230,8 +236,10 @@ S_rename_or_hard_link(RAMFolder *self, const CharBuf* from, const CharBuf
*to,
 
         // Perform the store first, then the delete. Inform Folder objects
         // about the relocation.
-        Hash_Store(inner_to_folder->entries, (Obj*)to_name, INCREF(elem));
-        DECREF(Hash_Delete(inner_from_folder->entries, (Obj*)from_name));
+        Hash_Store(RAMFolder_IVARS(inner_to_folder)->entries,
+                   (Obj*)to_name, INCREF(elem));
+        DECREF(Hash_Delete(RAMFolder_IVARS(inner_from_folder)->entries,
+                           (Obj*)from_name));
         if (Obj_Is_A(elem, FOLDER)) {
             CharBuf *newpath = S_fullpath(inner_to_folder, (CharBuf*)to_name);
             Folder_Set_Path((Folder*)elem, newpath);
@@ -246,14 +254,15 @@ S_rename_or_hard_link(RAMFolder *self, const CharBuf* from, const CharBuf
*to,
         }
         else {
             Obj *existing
-                = Hash_Fetch(inner_to_folder->entries, (Obj*)to_name);
+                = Hash_Fetch(RAMFolder_IVARS(inner_to_folder)->entries,
+                             (Obj*)to_name);
             if (existing) {
                 Err_set_error(Err_new(CB_newf("'%o' already exists", to)));
                 return false;
             }
             else {
-                Hash_Store(inner_to_folder->entries, (Obj*)to_name,
-                           INCREF(elem));
+                Hash_Store(RAMFolder_IVARS(inner_to_folder)->entries,
+                           (Obj*)to_name, INCREF(elem));
             }
         }
     }
@@ -292,7 +301,8 @@ RAMFolder_hard_link(RAMFolder *self, const CharBuf *from, const CharBuf
*to) {
 
 bool
 RAMFolder_local_delete(RAMFolder *self, const CharBuf *name) {
-    Obj *entry = Hash_Fetch(self->entries, (Obj*)name);
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
+    Obj *entry = Hash_Fetch(ivars->entries, (Obj*)name);
     if (entry) {
         if (Obj_Is_A(entry, RAMFILE)) {
             ;
@@ -307,7 +317,7 @@ RAMFolder_local_delete(RAMFolder *self, const CharBuf *name) {
             else {
                 inner_folder = (RAMFolder*)CERTIFY(entry, RAMFOLDER);
             }
-            if (Hash_Get_Size(inner_folder->entries)) {
+            if (Hash_Get_Size(RAMFolder_IVARS(inner_folder)->entries)) {
                 // Can't delete non-empty dir.
                 return false;
             }
@@ -315,7 +325,7 @@ RAMFolder_local_delete(RAMFolder *self, const CharBuf *name) {
         else {
             return false;
         }
-        DECREF(Hash_Delete(self->entries, (Obj*)name));
+        DECREF(Hash_Delete(ivars->entries, (Obj*)name));
         return true;
     }
     else {
@@ -325,7 +335,8 @@ RAMFolder_local_delete(RAMFolder *self, const CharBuf *name) {
 
 Folder*
 RAMFolder_local_find_folder(RAMFolder *self, const CharBuf *path) {
-    Folder *local_folder = (Folder*)Hash_Fetch(self->entries, (Obj*)path);
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
+    Folder *local_folder = (Folder*)Hash_Fetch(ivars->entries, (Obj*)path);
     if (local_folder && Folder_Is_A(local_folder, FOLDER)) {
         return local_folder;
     }
@@ -339,8 +350,9 @@ RAMFolder_close(RAMFolder *self) {
 
 static CharBuf*
 S_fullpath(RAMFolder *self, const CharBuf *path) {
-    if (CB_Get_Size(self->path)) {
-        return CB_newf("%o/%o", self->path, path);
+    RAMFolderIVARS *const ivars = RAMFolder_IVARS(self);
+    if (CB_Get_Size(ivars->path)) {
+        return CB_newf("%o/%o", ivars->path, path);
     }
     else {
         return CB_Clone(path);

http://git-wip-us.apache.org/repos/asf/lucy/blob/d04580a1/core/Lucy/Store/SharedLock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/SharedLock.c b/core/Lucy/Store/SharedLock.c
index 5e5b2e0..702f9df 100644
--- a/core/Lucy/Store/SharedLock.c
+++ b/core/Lucy/Store/SharedLock.c
@@ -37,10 +37,11 @@ SharedLock*
 ShLock_init(SharedLock *self, Folder *folder, const CharBuf *name,
             const CharBuf *host, int32_t timeout, int32_t interval) {
     LFLock_init((LockFileLock*)self, folder, name, host, timeout, interval);
+    SharedLockIVARS *const ivars = ShLock_IVARS(self);
 
     // Override.
-    DECREF(self->lock_path);
-    self->lock_path = CB_newf("");
+    DECREF(ivars->lock_path);
+    ivars->lock_path = CB_newf("");
 
     return self;
 }
@@ -53,26 +54,27 @@ ShLock_shared(SharedLock *self) {
 
 bool
 ShLock_request(SharedLock *self) {
+    SharedLockIVARS *const ivars = ShLock_IVARS(self);
     uint32_t i = 0;
     ShLock_Request_t super_request
         = SUPER_METHOD_PTR(SHAREDLOCK, Lucy_ShLock_Request);
 
     // Empty lock_path indicates whether this particular instance is locked.
-    if (self->lock_path
-        && !CB_Equals_Str(self->lock_path, "", 0)
-        && Folder_Exists(self->folder, self->lock_path)
+    if (ivars->lock_path
+        && !CB_Equals_Str(ivars->lock_path, "", 0)
+        && Folder_Exists(ivars->folder, ivars->lock_path)
        ) {
         // Don't allow double obtain.
         Err_set_error((Err*)LockErr_new(CB_newf("Lock already obtained via '%o'",
-                                                self->lock_path)));
+                                                ivars->lock_path)));
         return false;
     }
 
-    DECREF(self->lock_path);
-    self->lock_path = CB_new(CB_Get_Size(self->name) + 10);
+    DECREF(ivars->lock_path);
+    ivars->lock_path = CB_new(CB_Get_Size(ivars->name) + 10);
     do {
-        CB_setf(self->lock_path, "locks/%o-%u32.lock", self->name, ++i);
-    } while (Folder_Exists(self->folder, self->lock_path));
+        CB_setf(ivars->lock_path, "locks/%o-%u32.lock", ivars->name, ++i);
+    } while (Folder_Exists(ivars->folder, ivars->lock_path));
 
     bool success = super_request(self);
     if (!success) { ERR_ADD_FRAME(Err_get_error()); }
@@ -81,27 +83,29 @@ ShLock_request(SharedLock *self) {
 
 void
 ShLock_release(SharedLock *self) {
-    if (self->lock_path && !CB_Equals_Str(self->lock_path, "", 0)) {
+    SharedLockIVARS *const ivars = ShLock_IVARS(self);
+    if (ivars->lock_path && !CB_Equals_Str(ivars->lock_path, "", 0)) {
         ShLock_Release_t super_release
             = SUPER_METHOD_PTR(SHAREDLOCK, Lucy_ShLock_Release);
         super_release(self);
 
         // Empty out lock_path.
-        DECREF(self->lock_path);
-        self->lock_path = CB_newf("");
+        DECREF(ivars->lock_path);
+        ivars->lock_path = CB_newf("");
     }
 }
 
 
 void
 ShLock_clear_stale(SharedLock *self) {
+    SharedLockIVARS *const ivars = ShLock_IVARS(self);
     DirHandle *dh;
     CharBuf   *entry;
     CharBuf   *candidate = NULL;
     CharBuf   *lock_dir_name = (CharBuf*)ZCB_WRAP_STR("locks", 5);
 
-    if (Folder_Find_Folder(self->folder, lock_dir_name)) {
-        dh = Folder_Open_Dir(self->folder, lock_dir_name);
+    if (Folder_Find_Folder(ivars->folder, lock_dir_name)) {
+        dh = Folder_Open_Dir(ivars->folder, lock_dir_name);
         if (!dh) { RETHROW(INCREF(Err_get_error())); }
         entry = DH_Get_Entry(dh);
     }
@@ -111,7 +115,7 @@ ShLock_clear_stale(SharedLock *self) {
 
     // Take a stab at any file that begins with our lock name.
     while (DH_Next(dh)) {
-        if (CB_Starts_With(entry, self->name)
+        if (CB_Starts_With(entry, ivars->name)
             && CB_Ends_With_Str(entry, ".lock", 5)
            ) {
             candidate = candidate ? candidate : CB_new(0);
@@ -126,12 +130,13 @@ ShLock_clear_stale(SharedLock *self) {
 
 bool
 ShLock_is_locked(SharedLock *self) {
+    SharedLockIVARS *const ivars = ShLock_IVARS(self);
     DirHandle *dh;
     CharBuf   *entry;
 
     CharBuf *lock_dir_name = (CharBuf*)ZCB_WRAP_STR("locks", 5);
-    if (Folder_Find_Folder(self->folder, lock_dir_name)) {
-        dh = Folder_Open_Dir(self->folder, lock_dir_name);
+    if (Folder_Find_Folder(ivars->folder, lock_dir_name)) {
+        dh = Folder_Open_Dir(ivars->folder, lock_dir_name);
         if (!dh) { RETHROW(INCREF(Err_get_error())); }
         entry = DH_Get_Entry(dh);
     }
@@ -141,7 +146,7 @@ ShLock_is_locked(SharedLock *self) {
 
     while (DH_Next(dh)) {
         // Translation:  $locked = 1 if $entry =~ /^\Q$name-\d+\.lock$/
-        if (CB_Starts_With(entry, self->name)
+        if (CB_Starts_With(entry, ivars->name)
             && CB_Ends_With_Str(entry, ".lock", 5)
            ) {
             ZombieCharBuf *scratch = ZCB_WRAP(entry);
@@ -151,7 +156,7 @@ ShLock_is_locked(SharedLock *self) {
             }
             if (ZCB_Code_Point_From(scratch, 1) == '-') {
                 ZCB_Chop(scratch, 1);
-                if (ZCB_Equals(scratch, (Obj*)self->name)) {
+                if (ZCB_Equals(scratch, (Obj*)ivars->name)) {
                     DECREF(dh);
                     return true;
                 }


Mime
View raw message