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 2013/06/30 00:10:59 UTC
[lucy-commits] [1/4] git commit: refs/heads/ivars-wip1 - Migrate Lucy's object
classes to IVARS.
Updated Branches:
refs/heads/ivars-wip1 5fb8c74df -> 9da803705
Migrate Lucy's object classes to IVARS.
Change BitVector and I32Array to access instance vars via an IVARS
struct rather than via `self`.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/9c05eff9
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/9c05eff9
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/9c05eff9
Branch: refs/heads/ivars-wip1
Commit: 9c05eff913bd494c5c6541bfbd65e47205fe0267
Parents: 5fb8c74
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jun 28 13:29:40 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Jun 28 13:29:40 2013 -0700
----------------------------------------------------------------------
core/Lucy/Object/BitVector.c | 172 +++++++++++++++++++++-----------------
core/Lucy/Object/I32Array.c | 24 +++---
2 files changed, 111 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/9c05eff9/core/Lucy/Object/BitVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Object/BitVector.c b/core/Lucy/Object/BitVector.c
index 7366a4c..c6940b3 100644
--- a/core/Lucy/Object/BitVector.c
+++ b/core/Lucy/Object/BitVector.c
@@ -56,29 +56,33 @@ BitVec_new(uint32_t capacity) {
BitVector*
BitVec_init(BitVector *self, uint32_t capacity) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
const uint32_t byte_size = (uint32_t)ceil(capacity / 8.0);
// Derive.
- self->bits = capacity
+ ivars->bits = capacity
? (uint8_t*)CALLOCATE(byte_size, sizeof(uint8_t))
: NULL;
// Assign.
- self->cap = byte_size * 8;
+ ivars->cap = byte_size * 8;
return self;
}
void
BitVec_destroy(BitVector* self) {
- FREEMEM(self->bits);
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ FREEMEM(ivars->bits);
SUPER_DESTROY(self, BITVECTOR);
}
BitVector*
BitVec_clone(BitVector *self) {
- BitVector *twin = BitVec_new(self->cap);
- uint32_t byte_size = (uint32_t)ceil(self->cap / 8.0);
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ BitVector *other = BitVec_new(ivars->cap);
+ uint32_t byte_size = (uint32_t)ceil(ivars->cap / 8.0);
+ BitVectorIVARS *const ovars = BitVec_IVARS(other);
// Forbid inheritance.
if (BitVec_Get_VTable(self) != BITVECTOR) {
@@ -86,78 +90,85 @@ BitVec_clone(BitVector *self) {
BitVec_Get_Class_Name(self));
}
- memcpy(twin->bits, self->bits, byte_size * sizeof(uint8_t));
+ memcpy(ovars->bits, ivars->bits, byte_size * sizeof(uint8_t));
- return twin;
+ return other;
}
uint8_t*
BitVec_get_raw_bits(BitVector *self) {
- return self->bits;
+ return BitVec_IVARS(self)->bits;
}
uint32_t
BitVec_get_capacity(BitVector *self) {
- return self->cap;
+ return BitVec_IVARS(self)->cap;
}
void
BitVec_mimic(BitVector *self, Obj *other) {
- BitVector *twin = (BitVector*)CERTIFY(other, BITVECTOR);
- const uint32_t my_byte_size = (uint32_t)ceil(self->cap / 8.0);
- const uint32_t twin_byte_size = (uint32_t)ceil(twin->cap / 8.0);
- if (my_byte_size > twin_byte_size) {
- uint32_t space = my_byte_size - twin_byte_size;
- memset(self->bits + twin_byte_size, 0, space);
+ CERTIFY(other, BITVECTOR);
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
+ const uint32_t my_byte_size = (uint32_t)ceil(ivars->cap / 8.0);
+ const uint32_t other_byte_size = (uint32_t)ceil(ovars->cap / 8.0);
+ if (my_byte_size > other_byte_size) {
+ uint32_t space = my_byte_size - other_byte_size;
+ memset(ivars->bits + other_byte_size, 0, space);
}
- else if (my_byte_size < twin_byte_size) {
- BitVec_Grow(self, twin->cap - 1);
+ else if (my_byte_size < other_byte_size) {
+ BitVec_Grow(self, ovars->cap - 1);
}
- memcpy(self->bits, twin->bits, twin_byte_size);
+ memcpy(ivars->bits, ovars->bits, other_byte_size);
}
void
BitVec_grow(BitVector *self, uint32_t capacity) {
- if (capacity > self->cap) {
- const size_t old_byte_cap = (size_t)ceil(self->cap / 8.0);
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ if (capacity > ivars->cap) {
+ const size_t old_byte_cap = (size_t)ceil(ivars->cap / 8.0);
const size_t new_byte_cap = (size_t)ceil((capacity + 1) / 8.0);
const size_t num_new_bytes = new_byte_cap - old_byte_cap;
- self->bits = (uint8_t*)REALLOCATE(self->bits, new_byte_cap);
- memset(self->bits + old_byte_cap, 0, num_new_bytes);
- self->cap = new_byte_cap * 8;
+ ivars->bits = (uint8_t*)REALLOCATE(ivars->bits, new_byte_cap);
+ memset(ivars->bits + old_byte_cap, 0, num_new_bytes);
+ ivars->cap = new_byte_cap * 8;
}
}
void
BitVec_set(BitVector *self, uint32_t tick) {
- if (tick >= self->cap) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ if (tick >= ivars->cap) {
uint32_t new_cap = (uint32_t)Memory_oversize(tick + 1, 0);
BitVec_Grow(self, new_cap);
}
- NumUtil_u1set(self->bits, tick);
+ NumUtil_u1set(ivars->bits, tick);
}
void
BitVec_clear(BitVector *self, uint32_t tick) {
- if (tick >= self->cap) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ if (tick >= ivars->cap) {
return;
}
- NumUtil_u1clear(self->bits, tick);
+ NumUtil_u1clear(ivars->bits, tick);
}
void
BitVec_clear_all(BitVector *self) {
- const size_t byte_size = (size_t)ceil(self->cap / 8.0);
- memset(self->bits, 0, byte_size);
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ const size_t byte_size = (size_t)ceil(ivars->cap / 8.0);
+ memset(ivars->bits, 0, byte_size);
}
bool
BitVec_get(BitVector *self, uint32_t tick) {
- if (tick >= self->cap) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ if (tick >= ivars->cap) {
return false;
}
- return NumUtil_u1get(self->bits, tick);
+ return NumUtil_u1get(ivars->bits, tick);
}
static int32_t
@@ -171,31 +182,32 @@ S_first_bit_in_nonzero_byte(uint8_t num) {
int32_t
BitVec_next_hit(BitVector *self, uint32_t tick) {
- size_t byte_size = (size_t)ceil(self->cap / 8.0);
- uint8_t *const limit = self->bits + byte_size;
- uint8_t *ptr = self->bits + (tick >> 3);
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ size_t byte_size = (size_t)ceil(ivars->cap / 8.0);
+ uint8_t *const limit = ivars->bits + byte_size;
+ uint8_t *ptr = ivars->bits + (tick >> 3);
if (ptr >= limit) {
return -1;
}
else if (*ptr != 0) {
// Special case the first byte.
- const int32_t base = (ptr - self->bits) * 8;
+ const int32_t base = (ptr - ivars->bits) * 8;
const int32_t min_sub_tick = tick & 0x7;
unsigned int byte = *ptr >> min_sub_tick;
if (byte) {
const int32_t candidate
= base + min_sub_tick + S_first_bit_in_nonzero_byte(byte);
- return candidate < (int32_t)self->cap ? candidate : -1;
+ return candidate < (int32_t)ivars->cap ? candidate : -1;
}
}
for (ptr++ ; ptr < limit; ptr++) {
if (*ptr != 0) {
// There's a non-zero bit in this byte.
- const int32_t base = (ptr - self->bits) * 8;
+ const int32_t base = (ptr - ivars->bits) * 8;
const int32_t candidate = base + S_first_bit_in_nonzero_byte(*ptr);
- return candidate < (int32_t)self->cap ? candidate : -1;
+ return candidate < (int32_t)ivars->cap ? candidate : -1;
}
}
@@ -204,11 +216,13 @@ BitVec_next_hit(BitVector *self, uint32_t tick) {
void
BitVec_and(BitVector *self, const BitVector *other) {
- uint8_t *bits_a = self->bits;
- uint8_t *bits_b = other->bits;
- const uint32_t min_cap = self->cap < other->cap
- ? self->cap
- : other->cap;
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ const BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
+ uint8_t *bits_a = ivars->bits;
+ uint8_t *bits_b = ovars->bits;
+ const uint32_t min_cap = ivars->cap < ovars->cap
+ ? ivars->cap
+ : ovars->cap;
const size_t byte_size = (size_t)ceil(min_cap / 8.0);
uint8_t *const limit = bits_a + byte_size;
@@ -219,8 +233,8 @@ BitVec_and(BitVector *self, const BitVector *other) {
}
// Set all remaining to zero.
- if (self->cap > min_cap) {
- const size_t self_byte_size = (size_t)ceil(self->cap / 8.0);
+ if (ivars->cap > min_cap) {
+ const size_t self_byte_size = (size_t)ceil(ivars->cap / 8.0);
memset(bits_a, 0, self_byte_size - byte_size);
}
}
@@ -237,27 +251,29 @@ BitVec_xor(BitVector *self, const BitVector *other) {
static void
S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ const BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
uint8_t *bits_a, *bits_b;
uint32_t max_cap, min_cap;
uint8_t *limit;
double byte_size;
// Sort out what the minimum and maximum caps are.
- if (self->cap < other->cap) {
- max_cap = other->cap;
- min_cap = self->cap;
+ if (ivars->cap < ovars->cap) {
+ max_cap = ovars->cap;
+ min_cap = ivars->cap;
}
else {
- max_cap = self->cap;
- min_cap = other->cap;
+ max_cap = ivars->cap;
+ min_cap = ovars->cap;
}
// Grow self if smaller than other, then calc pointers.
- if (max_cap > self->cap) { BitVec_Grow(self, max_cap); }
- bits_a = self->bits;
- bits_b = other->bits;
+ if (max_cap > ivars->cap) { BitVec_Grow(self, max_cap); }
+ bits_a = ivars->bits;
+ bits_b = ovars->bits;
byte_size = ceil(min_cap / 8.0);
- limit = self->bits + (size_t)byte_size;
+ limit = ivars->bits + (size_t)byte_size;
// Perform union of common bits.
if (operation == DO_OR) {
@@ -277,8 +293,8 @@ S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
}
// Copy remaining bits if other is bigger than self.
- if (other->cap > min_cap) {
- const double other_byte_size = ceil(other->cap / 8.0);
+ if (ovars->cap > min_cap) {
+ const double other_byte_size = ceil(ovars->cap / 8.0);
const size_t bytes_to_copy = (size_t)(other_byte_size - byte_size);
memcpy(bits_a, bits_b, bytes_to_copy);
}
@@ -286,11 +302,13 @@ S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
void
BitVec_and_not(BitVector *self, const BitVector *other) {
- uint8_t *bits_a = self->bits;
- uint8_t *bits_b = other->bits;
- const uint32_t min_cap = self->cap < other->cap
- ? self->cap
- : other->cap;
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ const BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
+ uint8_t *bits_a = ivars->bits;
+ uint8_t *bits_b = ovars->bits;
+ const uint32_t min_cap = ivars->cap < ovars->cap
+ ? ivars->cap
+ : ovars->cap;
const size_t byte_size = (size_t)ceil(min_cap / 8.0);
uint8_t *const limit = bits_a + byte_size;
@@ -303,47 +321,49 @@ BitVec_and_not(BitVector *self, const BitVector *other) {
void
BitVec_flip(BitVector *self, uint32_t tick) {
- if (tick >= self->cap) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
+ if (tick >= ivars->cap) {
uint32_t new_cap = (uint32_t)Memory_oversize(tick + 1, 0);
BitVec_Grow(self, new_cap);
}
- NumUtil_u1flip(self->bits, tick);
+ NumUtil_u1flip(ivars->bits, tick);
}
void
BitVec_flip_block(BitVector *self, uint32_t offset, uint32_t length) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
uint32_t first = offset;
uint32_t last = offset + length - 1;
// Bail if there's nothing to flip.
if (!length) { return; }
- if (last >= self->cap) { BitVec_Grow(self, last + 1); }
+ if (last >= ivars->cap) { BitVec_Grow(self, last + 1); }
// Flip partial bytes.
while (last % 8 != 0 && last > first) {
- NumUtil_u1flip(self->bits, last);
+ NumUtil_u1flip(ivars->bits, last);
last--;
}
while (first % 8 != 0 && first < last) {
- NumUtil_u1flip(self->bits, first);
+ NumUtil_u1flip(ivars->bits, first);
first++;
}
// Are first and last equal?
if (first == last) {
// There's only one bit left to flip.
- NumUtil_u1flip(self->bits, last);
+ NumUtil_u1flip(ivars->bits, last);
}
// They must be multiples of 8, then.
else {
const uint32_t start_tick = first >> 3;
const uint32_t limit_tick = last >> 3;
- uint8_t *bits = self->bits + start_tick;
- uint8_t *limit = self->bits + limit_tick;
+ uint8_t *bits = ivars->bits + start_tick;
+ uint8_t *limit = ivars->bits + limit_tick;
// Last actually belongs to the following byte (e.g. 8, in byte 2).
- NumUtil_u1flip(self->bits, last);
+ NumUtil_u1flip(ivars->bits, last);
// Flip whole bytes.
for (; bits < limit; bits++) {
@@ -354,9 +374,10 @@ BitVec_flip_block(BitVector *self, uint32_t offset, uint32_t length) {
uint32_t
BitVec_count(BitVector *self) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
uint32_t count = 0;
- const size_t byte_size = (size_t)ceil(self->cap / 8.0);
- uint8_t *ptr = self->bits;
+ const size_t byte_size = (size_t)ceil(ivars->cap / 8.0);
+ uint8_t *ptr = ivars->bits;
uint8_t *const limit = ptr + byte_size;
for (; ptr < limit; ptr++) {
@@ -368,12 +389,13 @@ BitVec_count(BitVector *self) {
I32Array*
BitVec_to_array(BitVector *self) {
+ BitVectorIVARS *const ivars = BitVec_IVARS(self);
uint32_t count = BitVec_Count(self);
uint32_t num_left = count;
- const uint32_t capacity = self->cap;
+ const uint32_t capacity = ivars->cap;
uint32_t *const array = (uint32_t*)CALLOCATE(count, sizeof(uint32_t));
- const size_t byte_size = (size_t)ceil(self->cap / 8.0);
- uint8_t *const bits = self->bits;
+ const size_t byte_size = (size_t)ceil(ivars->cap / 8.0);
+ uint8_t *const bits = ivars->bits;
uint8_t *const limit = bits + byte_size;
uint32_t num = 0;
uint32_t i = 0;
http://git-wip-us.apache.org/repos/asf/lucy/blob/9c05eff9/core/Lucy/Object/I32Array.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Object/I32Array.c b/core/Lucy/Object/I32Array.c
index 57609a1..84ed55e 100644
--- a/core/Lucy/Object/I32Array.c
+++ b/core/Lucy/Object/I32Array.c
@@ -42,36 +42,40 @@ I32Arr_new_steal(int32_t *ints, uint32_t size) {
I32Array*
I32Arr_init(I32Array *self, int32_t *ints, uint32_t size) {
- self->ints = ints;
- self->size = size;
+ I32ArrayIVARS *const ivars = I32Arr_IVARS(self);
+ ivars->ints = ints;
+ ivars->size = size;
return self;
}
void
I32Arr_destroy(I32Array *self) {
- FREEMEM(self->ints);
+ I32ArrayIVARS *const ivars = I32Arr_IVARS(self);
+ FREEMEM(ivars->ints);
SUPER_DESTROY(self, I32ARRAY);
}
void
I32Arr_set(I32Array *self, uint32_t tick, int32_t value) {
- if (tick >= self->size) {
- THROW(ERR, "Out of bounds: %u32 >= %u32", tick, self->size);
+ I32ArrayIVARS *const ivars = I32Arr_IVARS(self);
+ if (tick >= ivars->size) {
+ THROW(ERR, "Out of bounds: %u32 >= %u32", tick, ivars->size);
}
- self->ints[tick] = value;
+ ivars->ints[tick] = value;
}
int32_t
I32Arr_get(I32Array *self, uint32_t tick) {
- if (tick >= self->size) {
- THROW(ERR, "Out of bounds: %u32 >= %u32", tick, self->size);
+ I32ArrayIVARS *const ivars = I32Arr_IVARS(self);
+ if (tick >= ivars->size) {
+ THROW(ERR, "Out of bounds: %u32 >= %u32", tick, ivars->size);
}
- return self->ints[tick];
+ return ivars->ints[tick];
}
uint32_t
I32Arr_get_size(I32Array *self) {
- return self->size;
+ return I32Arr_IVARS(self)->size;
}
[lucy-commits] [2/4] Migrate Lucy's store classes to IVARS.
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/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/c02bb24e/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/c02bb24e/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/c02bb24e/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/c02bb24e/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/c02bb24e/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/c02bb24e/core/Lucy/Store/RAMFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/RAMFolder.c b/core/Lucy/Store/RAMFolder.c
index c0d21f0..77440e1 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;
}
@@ -292,7 +296,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)) {
;
@@ -315,7 +320,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 +330,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 +345,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/c02bb24e/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;
}
[lucy-commits] [4/4] git commit: refs/heads/ivars-wip1 - Access FileWindow member
vars via getters.
Posted by ma...@apache.org.
Access FileWindow member vars via getters.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/9da80370
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/9da80370
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/9da80370
Branch: refs/heads/ivars-wip1
Commit: 9da80370529fc2a05397171cface807a2d2c7ce3
Parents: c02bb24
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Sat Jun 29 15:07:37 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Jun 29 15:10:23 2013 -0700
----------------------------------------------------------------------
core/Lucy/Store/FSFileHandle.c | 5 +++--
core/Lucy/Store/FileWindow.c | 14 ++++++++++++++
core/Lucy/Store/FileWindow.cfh | 9 +++++++++
core/Lucy/Store/InStream.c | 25 +++++++++++++++----------
4 files changed, 41 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/9da80370/core/Lucy/Store/FSFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFileHandle.c b/core/Lucy/Store/FSFileHandle.c
index a81b338..74d61a5 100644
--- a/core/Lucy/Store/FSFileHandle.c
+++ b/core/Lucy/Store/FSFileHandle.c
@@ -15,7 +15,6 @@
*/
#define C_LUCY_FSFILEHANDLE
-#define C_LUCY_FILEWINDOW
#include "Lucy/Util/ToolSet.h"
#include <errno.h>
@@ -313,7 +312,9 @@ SI_window(FSFileHandle *self, FSFileHandleIVARS *ivars, FileWindow *window,
bool
FSFH_release_window(FSFileHandle *self, FileWindow *window) {
- if (!SI_unmap(self, window->buf, window->len)) { return false; }
+ char *buf = FileWindow_Get_Buf(window);
+ int64_t len = FileWindow_Get_Len(window);
+ if (!SI_unmap(self, buf, len)) { return false; }
FileWindow_Set_Window(window, NULL, 0, 0);
return true;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/9da80370/core/Lucy/Store/FileWindow.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FileWindow.c b/core/Lucy/Store/FileWindow.c
index 067c6a8..a410931 100644
--- a/core/Lucy/Store/FileWindow.c
+++ b/core/Lucy/Store/FileWindow.c
@@ -51,4 +51,18 @@ FileWindow_set_window(FileWindow *self, char *buf, int64_t offset,
ivars->len = len;
}
+char*
+FileWindow_get_buf(FileWindow *self) {
+ return FileWindow_IVARS(self)->buf;
+}
+
+int64_t
+FileWindow_get_offset(FileWindow *self) {
+ return FileWindow_IVARS(self)->offset;
+}
+
+int64_t
+FileWindow_get_len(FileWindow *self) {
+ return FileWindow_IVARS(self)->len;
+}
http://git-wip-us.apache.org/repos/asf/lucy/blob/9da80370/core/Lucy/Store/FileWindow.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FileWindow.cfh b/core/Lucy/Store/FileWindow.cfh
index dc1d17c..9b8a359 100644
--- a/core/Lucy/Store/FileWindow.cfh
+++ b/core/Lucy/Store/FileWindow.cfh
@@ -35,6 +35,15 @@ class Lucy::Store::FileWindow inherits Clownfish::Obj {
void
Set_Window(FileWindow *self, char *buf, int64_t offset, int64_t len);
+
+ char*
+ Get_Buf(FileWindow *self);
+
+ int64_t
+ Get_Offset(FileWindow *self);
+
+ int64_t
+ Get_Len(FileWindow *self);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/9da80370/core/Lucy/Store/InStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/InStream.c b/core/Lucy/Store/InStream.c
index 9526360..467bb64 100644
--- a/core/Lucy/Store/InStream.c
+++ b/core/Lucy/Store/InStream.c
@@ -15,7 +15,6 @@
*/
#define C_LUCY_INSTREAM
-#define C_LUCY_FILEWINDOW
#include "Lucy/Util/ToolSet.h"
#include "Lucy/Store/InStream.h"
@@ -201,9 +200,12 @@ S_fill(InStream *self, int64_t amount) {
// Make the request.
if (FH_Window(ivars->file_handle, window, real_file_pos, amount)) {
- char *const window_limit = window->buf + window->len;
- ivars->buf = window->buf
- - window->offset // theoretical start of real file
+ char *fw_buf = FileWindow_Get_Buf(window);
+ int64_t fw_offset = FileWindow_Get_Offset(window);
+ int64_t fw_len = FileWindow_Get_Len(window);
+ char *const window_limit = fw_buf + fw_len;
+ ivars->buf = fw_buf
+ - fw_offset // theoretical start of real file
+ ivars->offset // top of virtual file
+ virtual_file_pos; // position within virtual file
ivars->limit = window_limit - ivars->buf > remaining
@@ -226,8 +228,11 @@ void
InStream_seek(InStream *self, int64_t target) {
InStreamIVARS *const ivars = InStream_IVARS(self);
FileWindow *const window = ivars->window;
- int64_t virtual_window_top = window->offset - ivars->offset;
- int64_t virtual_window_end = virtual_window_top + window->len;
+ char *fw_buf = FileWindow_Get_Buf(window);
+ int64_t fw_offset = FileWindow_Get_Offset(window);
+ int64_t fw_len = FileWindow_Get_Len(window);
+ int64_t virtual_window_top = fw_offset - ivars->offset;
+ int64_t virtual_window_end = virtual_window_top + fw_len;
if (target < 0) {
THROW(ERR, "Can't Seek '%o' to negative target %i64", ivars->filename,
@@ -237,7 +242,7 @@ InStream_seek(InStream *self, int64_t target) {
else if (target >= virtual_window_top
&& target <= virtual_window_end
) {
- ivars->buf = window->buf - window->offset + ivars->offset + target;
+ ivars->buf = fw_buf - fw_offset + ivars->offset + target;
}
else if (target > ivars->len) {
THROW(ERR, "Can't Seek '%o' past EOF (%i64 > %i64)", ivars->filename,
@@ -257,9 +262,9 @@ InStream_seek(InStream *self, int64_t target) {
static INLINE int64_t
SI_tell(InStream *self) {
InStreamIVARS *const ivars = InStream_IVARS(self);
- FileWindow *const window = ivars->window;
- int64_t pos_in_buf = PTR_TO_I64(ivars->buf) - PTR_TO_I64(window->buf);
- return pos_in_buf + window->offset - ivars->offset;
+ char *fw_buf = FileWindow_Get_Buf(ivars->window);
+ int64_t pos_in_buf = PTR_TO_I64(ivars->buf) - PTR_TO_I64(fw_buf);
+ return pos_in_buf + FileWindow_Get_Offset(ivars->window) - ivars->offset;
}
int64_t
[lucy-commits] [3/4] git commit: refs/heads/ivars-wip1 - Migrate Lucy's store
classes to IVARS.
Posted by ma...@apache.org.
Migrate Lucy's store classes to IVARS.
Change all Lucy's store classes to access instance vars via an IVARS
struct rather than via `self`.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c02bb24e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c02bb24e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c02bb24e
Branch: refs/heads/ivars-wip1
Commit: c02bb24e82bfc1355528b419bf362b7ada5eea8e
Parents: 9c05eff
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jun 28 14:07:41 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Jun 29 14:59:50 2013 -0700
----------------------------------------------------------------------
core/Lucy/Store/CompoundFileReader.c | 142 ++++++++++++---------
core/Lucy/Store/CompoundFileWriter.c | 35 +++---
core/Lucy/Store/DirHandle.c | 14 ++-
core/Lucy/Store/FSDirHandle.c | 121 ++++++++++--------
core/Lucy/Store/FSFileHandle.c | 195 ++++++++++++++++-------------
core/Lucy/Store/FSFolder.c | 34 +++--
core/Lucy/Store/FileHandle.c | 13 +-
core/Lucy/Store/FileWindow.c | 16 +--
core/Lucy/Store/Folder.c | 27 ++--
core/Lucy/Store/InStream.c | 200 ++++++++++++++++--------------
core/Lucy/Store/Lock.c | 91 ++++++++------
core/Lucy/Store/LockFactory.c | 16 ++-
core/Lucy/Store/OutStream.c | 155 ++++++++++++-----------
core/Lucy/Store/RAMDirHandle.c | 40 +++---
core/Lucy/Store/RAMFile.c | 14 ++-
core/Lucy/Store/RAMFileHandle.c | 52 ++++----
core/Lucy/Store/RAMFileHandle.cfh | 1 +
core/Lucy/Store/RAMFolder.c | 29 +++--
core/Lucy/Store/SharedLock.c | 45 ++++---
19 files changed, 698 insertions(+), 542 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/CompoundFileReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/CompoundFileReader.c b/core/Lucy/Store/CompoundFileReader.c
index 21e08a8..c519498 100644
--- a/core/Lucy/Store/CompoundFileReader.c
+++ b/core/Lucy/Store/CompoundFileReader.c
@@ -35,6 +35,7 @@ CFReader_open(Folder *folder) {
CompoundFileReader*
CFReader_do_open(CompoundFileReader *self, Folder *folder) {
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
Hash *metadata = (Hash*)Json_slurp_json((Folder*)folder, cfmeta_file);
Err *error = NULL;
@@ -48,18 +49,18 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
}
else {
Obj *format = Hash_Fetch_Str(metadata, "format", 6);
- self->format = format ? (int32_t)Obj_To_I64(format) : 0;
- self->records = (Hash*)INCREF(Hash_Fetch_Str(metadata, "files", 5));
- if (self->format < 1) {
+ ivars->format = format ? (int32_t)Obj_To_I64(format) : 0;
+ ivars->records = (Hash*)INCREF(Hash_Fetch_Str(metadata, "files", 5));
+ if (ivars->format < 1) {
error = Err_new(CB_newf("Corrupt %o file: Missing or invalid 'format'",
cfmeta_file));
}
- else if (self->format > CFWriter_current_file_format) {
+ else if (ivars->format > CFWriter_current_file_format) {
error = Err_new(CB_newf("Unsupported compound file format: %i32 "
- "(current = %i32", self->format,
+ "(current = %i32", ivars->format,
CFWriter_current_file_format));
}
- else if (!self->records) {
+ else if (!ivars->records) {
error = Err_new(CB_newf("Corrupt %o file: missing 'files' key",
cfmeta_file));
}
@@ -73,19 +74,19 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
// Open an instream which we'll clone over and over.
CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
- self->instream = Folder_Open_In(folder, cf_file);
- if (!self->instream) {
+ ivars->instream = Folder_Open_In(folder, cf_file);
+ if (!ivars->instream) {
ERR_ADD_FRAME(Err_get_error());
DECREF(self);
return NULL;
}
// Assign.
- self->real_folder = (Folder*)INCREF(folder);
+ ivars->real_folder = (Folder*)INCREF(folder);
// Strip directory name from filepaths for old format.
- if (self->format == 1) {
- VArray *files = Hash_Keys(self->records);
+ if (ivars->format == 1) {
+ VArray *files = Hash_Keys(ivars->records);
ZombieCharBuf *filename = ZCB_BLANK();
ZombieCharBuf *folder_name
= IxFileNames_local_part(Folder_Get_Path(folder), ZCB_BLANK());
@@ -94,10 +95,10 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
for (uint32_t i = 0, max = VA_Get_Size(files); i < max; i++) {
CharBuf *orig = (CharBuf*)VA_Fetch(files, i);
if (CB_Starts_With(orig, (CharBuf*)folder_name)) {
- Obj *record = Hash_Delete(self->records, (Obj*)orig);
+ Obj *record = Hash_Delete(ivars->records, (Obj*)orig);
ZCB_Assign(filename, orig);
ZCB_Nip(filename, folder_name_len + sizeof(DIR_SEP) - 1);
- Hash_Store(self->records, (Obj*)filename, (Obj*)record);
+ Hash_Store(ivars->records, (Obj*)filename, (Obj*)record);
}
}
@@ -109,35 +110,38 @@ CFReader_do_open(CompoundFileReader *self, Folder *folder) {
void
CFReader_destroy(CompoundFileReader *self) {
- DECREF(self->real_folder);
- DECREF(self->instream);
- DECREF(self->records);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ DECREF(ivars->real_folder);
+ DECREF(ivars->instream);
+ DECREF(ivars->records);
SUPER_DESTROY(self, COMPOUNDFILEREADER);
}
Folder*
CFReader_get_real_folder(CompoundFileReader *self) {
- return self->real_folder;
+ return CFReader_IVARS(self)->real_folder;
}
void
CFReader_set_path(CompoundFileReader *self, const CharBuf *path) {
- Folder_Set_Path(self->real_folder, path);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ Folder_Set_Path(ivars->real_folder, path);
Folder_set_path((Folder*)self, path);
}
FileHandle*
CFReader_local_open_filehandle(CompoundFileReader *self,
const CharBuf *name, uint32_t flags) {
- Hash *entry = (Hash*)Hash_Fetch(self->records, (Obj*)name);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ Hash *entry = (Hash*)Hash_Fetch(ivars->records, (Obj*)name);
FileHandle *fh = NULL;
if (entry) {
Err_set_error(Err_new(CB_newf("Can't open FileHandle for virtual file %o in '%o'",
- name, self->path)));
+ name, ivars->path)));
}
else {
- fh = Folder_Local_Open_FileHandle(self->real_folder, name, flags);
+ fh = Folder_Local_Open_FileHandle(ivars->real_folder, name, flags);
if (!fh) {
ERR_ADD_FRAME(Err_get_error());
}
@@ -148,22 +152,23 @@ CFReader_local_open_filehandle(CompoundFileReader *self,
bool
CFReader_local_delete(CompoundFileReader *self, const CharBuf *name) {
- Hash *record = (Hash*)Hash_Delete(self->records, (Obj*)name);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ Hash *record = (Hash*)Hash_Delete(ivars->records, (Obj*)name);
DECREF(record);
if (record == NULL) {
- return Folder_Local_Delete(self->real_folder, name);
+ return Folder_Local_Delete(ivars->real_folder, name);
}
else {
// Once the number of virtual files falls to 0, remove the compound
// files.
- if (Hash_Get_Size(self->records) == 0) {
+ if (Hash_Get_Size(ivars->records) == 0) {
CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
- if (!Folder_Delete(self->real_folder, cf_file)) {
+ if (!Folder_Delete(ivars->real_folder, cf_file)) {
return false;
}
CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
- if (!Folder_Delete(self->real_folder, cfmeta_file)) {
+ if (!Folder_Delete(ivars->real_folder, cfmeta_file)) {
return false;
}
@@ -174,10 +179,11 @@ CFReader_local_delete(CompoundFileReader *self, const CharBuf *name) {
InStream*
CFReader_local_open_in(CompoundFileReader *self, const CharBuf *name) {
- Hash *entry = (Hash*)Hash_Fetch(self->records, (Obj*)name);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ Hash *entry = (Hash*)Hash_Fetch(ivars->records, (Obj*)name);
if (!entry) {
- InStream *instream = Folder_Local_Open_In(self->real_folder, name);
+ InStream *instream = Folder_Local_Open_In(ivars->real_folder, name);
if (!instream) {
ERR_ADD_FRAME(Err_get_error());
}
@@ -188,18 +194,18 @@ CFReader_local_open_in(CompoundFileReader *self, const CharBuf *name) {
Obj *offset = Hash_Fetch_Str(entry, "offset", 6);
if (!len || !offset) {
Err_set_error(Err_new(CB_newf("Malformed entry for '%o' in '%o'",
- name, Folder_Get_Path(self->real_folder))));
+ name, Folder_Get_Path(ivars->real_folder))));
return NULL;
}
- else if (CB_Get_Size(self->path)) {
- CharBuf *fullpath = CB_newf("%o/%o", self->path, name);
- InStream *instream = InStream_Reopen(self->instream, fullpath,
+ else if (CB_Get_Size(ivars->path)) {
+ CharBuf *fullpath = CB_newf("%o/%o", ivars->path, name);
+ InStream *instream = InStream_Reopen(ivars->instream, fullpath,
Obj_To_I64(offset), Obj_To_I64(len));
DECREF(fullpath);
return instream;
}
else {
- return InStream_Reopen(self->instream, name, Obj_To_I64(offset),
+ return InStream_Reopen(ivars->instream, name, Obj_To_I64(offset),
Obj_To_I64(len));
}
}
@@ -207,31 +213,35 @@ CFReader_local_open_in(CompoundFileReader *self, const CharBuf *name) {
bool
CFReader_local_exists(CompoundFileReader *self, const CharBuf *name) {
- if (Hash_Fetch(self->records, (Obj*)name)) { return true; }
- if (Folder_Local_Exists(self->real_folder, name)) { return true; }
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ if (Hash_Fetch(ivars->records, (Obj*)name)) { return true; }
+ if (Folder_Local_Exists(ivars->real_folder, name)) { return true; }
return false;
}
bool
CFReader_local_is_directory(CompoundFileReader *self, const CharBuf *name) {
- if (Hash_Fetch(self->records, (Obj*)name)) { return false; }
- if (Folder_Local_Is_Directory(self->real_folder, name)) { return true; }
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ if (Hash_Fetch(ivars->records, (Obj*)name)) { return false; }
+ if (Folder_Local_Is_Directory(ivars->real_folder, name)) { return true; }
return false;
}
void
CFReader_close(CompoundFileReader *self) {
- InStream_Close(self->instream);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ InStream_Close(ivars->instream);
}
bool
CFReader_local_mkdir(CompoundFileReader *self, const CharBuf *name) {
- if (Hash_Fetch(self->records, (Obj*)name)) {
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ if (Hash_Fetch(ivars->records, (Obj*)name)) {
Err_set_error(Err_new(CB_newf("Can't MkDir: '%o' exists", name)));
return false;
}
else {
- bool result = Folder_Local_MkDir(self->real_folder, name);
+ bool result = Folder_Local_MkDir(ivars->real_folder, name);
if (!result) { ERR_ADD_FRAME(Err_get_error()); }
return result;
}
@@ -239,8 +249,9 @@ CFReader_local_mkdir(CompoundFileReader *self, const CharBuf *name) {
Folder*
CFReader_local_find_folder(CompoundFileReader *self, const CharBuf *name) {
- if (Hash_Fetch(self->records, (Obj*)name)) { return false; }
- return Folder_Local_Find_Folder(self->real_folder, name);
+ CompoundFileReaderIVARS *const ivars = CFReader_IVARS(self);
+ if (Hash_Fetch(ivars->records, (Obj*)name)) { return false; }
+ return Folder_Local_Find_Folder(ivars->real_folder, name);
}
DirHandle*
@@ -260,14 +271,18 @@ CFReaderDH_new(CompoundFileReader *cf_reader) {
CFReaderDirHandle*
CFReaderDH_init(CFReaderDirHandle *self, CompoundFileReader *cf_reader) {
DH_init((DirHandle*)self, CFReader_Get_Path(cf_reader));
- self->cf_reader = (CompoundFileReader*)INCREF(cf_reader);
- self->elems = Hash_Keys(self->cf_reader->records);
- self->tick = -1;
+ CFReaderDirHandleIVARS *const ivars = CFReaderDH_IVARS(self);
+ ivars->cf_reader = (CompoundFileReader*)INCREF(cf_reader);
+
+ Hash *cf_records = CFReader_IVARS(ivars->cf_reader)->records;
+ ivars->elems = Hash_Keys(cf_records);
+ ivars->tick = -1;
// Accumulate entries from real Folder.
- DirHandle *dh = Folder_Local_Open_Dir(self->cf_reader->real_folder);
+ Folder *real_folder = CFReader_Get_Real_Folder(ivars->cf_reader);
+ DirHandle *dh = Folder_Local_Open_Dir(real_folder);
CharBuf *entry = DH_Get_Entry(dh);
while (DH_Next(dh)) {
- VA_Push(self->elems, (Obj*)CB_Clone(entry));
+ VA_Push(ivars->elems, (Obj*)CB_Clone(entry));
}
DECREF(dh);
return self;
@@ -275,29 +290,31 @@ CFReaderDH_init(CFReaderDirHandle *self, CompoundFileReader *cf_reader) {
bool
CFReaderDH_close(CFReaderDirHandle *self) {
- if (self->elems) {
- VA_Dec_RefCount(self->elems);
- self->elems = NULL;
+ CFReaderDirHandleIVARS *const ivars = CFReaderDH_IVARS(self);
+ if (ivars->elems) {
+ VA_Dec_RefCount(ivars->elems);
+ ivars->elems = NULL;
}
- if (self->cf_reader) {
- CFReader_Dec_RefCount(self->cf_reader);
- self->cf_reader = NULL;
+ if (ivars->cf_reader) {
+ CFReader_Dec_RefCount(ivars->cf_reader);
+ ivars->cf_reader = NULL;
}
return true;
}
bool
CFReaderDH_next(CFReaderDirHandle *self) {
- if (self->elems) {
- self->tick++;
- if (self->tick < (int32_t)VA_Get_Size(self->elems)) {
+ CFReaderDirHandleIVARS *const ivars = CFReaderDH_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;
}
}
@@ -306,10 +323,11 @@ CFReaderDH_next(CFReaderDirHandle *self) {
bool
CFReaderDH_entry_is_dir(CFReaderDirHandle *self) {
- if (self->elems) {
- CharBuf *name = (CharBuf*)VA_Fetch(self->elems, self->tick);
+ CFReaderDirHandleIVARS *const ivars = CFReaderDH_IVARS(self);
+ if (ivars->elems) {
+ CharBuf *name = (CharBuf*)VA_Fetch(ivars->elems, ivars->tick);
if (name) {
- return CFReader_Local_Is_Directory(self->cf_reader, name);
+ return CFReader_Local_Is_Directory(ivars->cf_reader, name);
}
}
return false;
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/CompoundFileWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/CompoundFileWriter.c b/core/Lucy/Store/CompoundFileWriter.c
index 2ff716b..c009e64 100644
--- a/core/Lucy/Store/CompoundFileWriter.c
+++ b/core/Lucy/Store/CompoundFileWriter.c
@@ -28,11 +28,12 @@ int32_t CFWriter_current_file_format = 2;
// Helper which does the heavy lifting for CFWriter_consolidate.
static void
-S_do_consolidate(CompoundFileWriter *self);
+S_do_consolidate(CompoundFileWriter *self, CompoundFileWriterIVARS *ivars);
// Clean up files which may be left over from previous merge attempts.
static void
-S_clean_up_old_temp_files(CompoundFileWriter *self);
+S_clean_up_old_temp_files(CompoundFileWriter *self,
+ CompoundFileWriterIVARS *ivars);
CompoundFileWriter*
CFWriter_new(Folder *folder) {
@@ -43,32 +44,37 @@ CFWriter_new(Folder *folder) {
CompoundFileWriter*
CFWriter_init(CompoundFileWriter *self, Folder *folder) {
- self->folder = (Folder*)INCREF(folder);
+ CompoundFileWriterIVARS *const ivars = CFWriter_IVARS(self);
+ ivars->folder = (Folder*)INCREF(folder);
return self;
}
void
CFWriter_destroy(CompoundFileWriter *self) {
- DECREF(self->folder);
+ CompoundFileWriterIVARS *const ivars = CFWriter_IVARS(self);
+ DECREF(ivars->folder);
SUPER_DESTROY(self, COMPOUNDFILEWRITER);
}
void
CFWriter_consolidate(CompoundFileWriter *self) {
+ CompoundFileWriterIVARS *const ivars = CFWriter_IVARS(self);
CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
- if (Folder_Exists(self->folder, cfmeta_file)) {
+ if (Folder_Exists(ivars->folder, cfmeta_file)) {
THROW(ERR, "Merge already performed for %o",
- Folder_Get_Path(self->folder));
+ Folder_Get_Path(ivars->folder));
}
else {
- S_clean_up_old_temp_files(self);
- S_do_consolidate(self);
+ S_clean_up_old_temp_files(self, ivars);
+ S_do_consolidate(self, ivars);
}
}
static void
-S_clean_up_old_temp_files(CompoundFileWriter *self) {
- Folder *folder = self->folder;
+S_clean_up_old_temp_files(CompoundFileWriter *self,
+ CompoundFileWriterIVARS *ivars) {
+ UNUSED_VAR(self);
+ Folder *folder = ivars->folder;
CharBuf *cfmeta_temp = (CharBuf*)ZCB_WRAP_STR("cfmeta.json.temp", 16);
CharBuf *cf_file = (CharBuf*)ZCB_WRAP_STR("cf.dat", 6);
@@ -85,8 +91,9 @@ S_clean_up_old_temp_files(CompoundFileWriter *self) {
}
static void
-S_do_consolidate(CompoundFileWriter *self) {
- Folder *folder = self->folder;
+S_do_consolidate(CompoundFileWriter *self, CompoundFileWriterIVARS *ivars) {
+ UNUSED_VAR(self);
+ Folder *folder = ivars->folder;
Hash *metadata = Hash_new(0);
Hash *sub_files = Hash_new(0);
VArray *files = Folder_List(folder, NULL);
@@ -143,8 +150,8 @@ S_do_consolidate(CompoundFileWriter *self) {
// Write metadata to cfmeta file.
CharBuf *cfmeta_temp = (CharBuf*)ZCB_WRAP_STR("cfmeta.json.temp", 16);
CharBuf *cfmeta_file = (CharBuf*)ZCB_WRAP_STR("cfmeta.json", 11);
- Json_spew_json((Obj*)metadata, (Folder*)self->folder, cfmeta_temp);
- rename_success = Folder_Rename(self->folder, cfmeta_temp, cfmeta_file);
+ Json_spew_json((Obj*)metadata, (Folder*)ivars->folder, cfmeta_temp);
+ rename_success = Folder_Rename(ivars->folder, cfmeta_temp, cfmeta_file);
if (!rename_success) { RETHROW(INCREF(Err_get_error())); }
// Clean up.
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/DirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/DirHandle.c b/core/Lucy/Store/DirHandle.c
index 6729d5d..c9e4b03 100644
--- a/core/Lucy/Store/DirHandle.c
+++ b/core/Lucy/Store/DirHandle.c
@@ -20,28 +20,30 @@
DirHandle*
DH_init(DirHandle *self, const CharBuf *dir) {
- self->dir = CB_Clone(dir);
- self->entry = CB_new(32);
+ DirHandleIVARS *const ivars = DH_IVARS(self);
+ ivars->dir = CB_Clone(dir);
+ ivars->entry = CB_new(32);
ABSTRACT_CLASS_CHECK(self, DIRHANDLE);
return self;
}
void
DH_destroy(DirHandle *self) {
+ DirHandleIVARS *const ivars = DH_IVARS(self);
DH_Close(self);
- DECREF(self->dir);
- DECREF(self->entry);
+ DECREF(ivars->dir);
+ DECREF(ivars->entry);
SUPER_DESTROY(self, DIRHANDLE);
}
CharBuf*
DH_get_dir(DirHandle *self) {
- return self->dir;
+ return DH_IVARS(self)->dir;
}
CharBuf*
DH_get_entry(DirHandle *self) {
- return self->entry;
+ return DH_IVARS(self)->entry;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/FSDirHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSDirHandle.c b/core/Lucy/Store/FSDirHandle.c
index 27ecb59..1d2d118 100644
--- a/core/Lucy/Store/FSDirHandle.c
+++ b/core/Lucy/Store/FSDirHandle.c
@@ -39,8 +39,9 @@ FSDH_open(const CharBuf *dir) {
void
FSDH_destroy(FSDirHandle *self) {
// Throw away saved error -- it's too late to call Close() now.
- DECREF(self->saved_error);
- self->saved_error = NULL;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ DECREF(ivars->saved_error);
+ ivars->saved_error = NULL;
SUPER_DESTROY(self, FSDIRHANDLE);
}
@@ -70,9 +71,10 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
char *path_ptr = search_string;
DH_init((DirHandle*)self, dir);
- self->sys_dir_entry = MALLOCATE(sizeof(WIN32_FIND_DATA));
- self->sys_dirhandle = INVALID_HANDLE_VALUE;
- self->saved_error = NULL;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ ivars->sys_dir_entry = MALLOCATE(sizeof(WIN32_FIND_DATA));
+ ivars->sys_dirhandle = INVALID_HANDLE_VALUE;
+ ivars->saved_error = NULL;
if (dir_path_size >= MAX_PATH - 2) {
// Deal with Windows ceiling on file path lengths.
@@ -87,9 +89,9 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
memcpy(path_ptr, dir_path_ptr, dir_path_size);
memcpy(path_ptr + dir_path_size, "\\*\0", 3);
- self->sys_dirhandle
- = FindFirstFile(search_string, (WIN32_FIND_DATA*)self->sys_dir_entry);
- if (INVALID_HANDLE_VALUE == self->sys_dirhandle) {
+ ivars->sys_dirhandle
+ = FindFirstFile(search_string, (WIN32_FIND_DATA*)ivars->sys_dir_entry);
+ if (INVALID_HANDLE_VALUE == ivars->sys_dirhandle) {
// Directory inaccessible or doesn't exist.
Err_set_error(Err_new(CB_newf("Failed to open dir '%o'", dir)));
CFISH_DECREF(self);
@@ -99,7 +101,7 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
// Compensate for the fact that FindFirstFile has already returned the
// first entry but DirHandle's API requires that you call Next() to
// start the iterator.
- self->delayed_iter = true;
+ ivars->delayed_iter = true;
}
return self;
@@ -107,7 +109,8 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
bool
FSDH_entry_is_dir(FSDirHandle *self) {
- WIN32_FIND_DATA *find_data = (WIN32_FIND_DATA*)self->sys_dir_entry;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ WIN32_FIND_DATA *find_data = (WIN32_FIND_DATA*)ivars->sys_dir_entry;
if (find_data) {
if ((find_data->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
return true;
@@ -118,7 +121,8 @@ FSDH_entry_is_dir(FSDirHandle *self) {
bool
FSDH_entry_is_symlink(FSDirHandle *self) {
- WIN32_FIND_DATA *find_data = (WIN32_FIND_DATA*)self->sys_dir_entry;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ WIN32_FIND_DATA *find_data = (WIN32_FIND_DATA*)ivars->sys_dir_entry;
if (find_data) {
if ((find_data->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
return true;
@@ -129,27 +133,28 @@ FSDH_entry_is_symlink(FSDirHandle *self) {
bool
FSDH_close(FSDirHandle *self) {
- if (self->sys_dirhandle && self->sys_dirhandle != INVALID_HANDLE_VALUE) {
- HANDLE dirhandle = (HANDLE)self->sys_dirhandle;
- self->sys_dirhandle = NULL;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ if (ivars->sys_dirhandle && ivars->sys_dirhandle != INVALID_HANDLE_VALUE) {
+ HANDLE dirhandle = (HANDLE)ivars->sys_dirhandle;
+ ivars->sys_dirhandle = NULL;
if (dirhandle != INVALID_HANDLE_VALUE && !FindClose(dirhandle)) {
- if (!self->saved_error) {
+ if (!ivars->saved_error) {
char *win_error = Err_win_error();
- self->saved_error
+ ivars->saved_error
= Err_new(CB_newf("Error while closing directory: %s",
win_error));
FREEMEM(win_error);
}
}
}
- if (self->sys_dir_entry) {
- FREEMEM(self->sys_dir_entry);
- self->sys_dir_entry = NULL;
+ if (ivars->sys_dir_entry) {
+ FREEMEM(ivars->sys_dir_entry);
+ ivars->sys_dir_entry = NULL;
}
// If we encountered an error condition previously, report it now.
- if (self->saved_error) {
- Err_set_error((Err*)CFISH_INCREF(self->saved_error));
+ if (ivars->saved_error) {
+ Err_set_error((Err*)CFISH_INCREF(ivars->saved_error));
return false;
}
else {
@@ -159,22 +164,23 @@ FSDH_close(FSDirHandle *self) {
bool
FSDH_next(FSDirHandle *self) {
- HANDLE dirhandle = (HANDLE)self->sys_dirhandle;
- WIN32_FIND_DATA *find_data = (WIN32_FIND_DATA*)self->sys_dir_entry;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ HANDLE dirhandle = (HANDLE)ivars->sys_dirhandle;
+ WIN32_FIND_DATA *find_data = (WIN32_FIND_DATA*)ivars->sys_dir_entry;
// Attempt to move forward or absorb cached iter.
if (!dirhandle || dirhandle == INVALID_HANDLE_VALUE) {
return false;
}
- else if (self->delayed_iter) {
- self->delayed_iter = false;
+ else if (ivars->delayed_iter) {
+ ivars->delayed_iter = false;
}
else if ((FindNextFile(dirhandle, find_data) == 0)) {
// Iterator exhausted. Verify that no errors were encountered.
- CB_Set_Size(self->entry, 0);
+ CB_Set_Size(ivars->entry, 0);
if (GetLastError() != ERROR_NO_MORE_FILES) {
char *win_error = Err_win_error();
- self->saved_error
+ ivars->saved_error
= Err_new(CB_newf("Error while traversing directory: %s",
win_error));
FREEMEM(win_error);
@@ -188,7 +194,7 @@ FSDH_next(FSDirHandle *self) {
return FSDH_Next(self);
}
else {
- CB_Mimic_Str(self->entry, find_data->cFileName, len);
+ CB_Mimic_Str(ivars->entry, find_data->cFileName, len);
return true;
}
}
@@ -203,11 +209,12 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
char *dir_path_ptr = (char*)CB_Get_Ptr8(dir);
DH_init((DirHandle*)self, dir);
- self->sys_dir_entry = NULL;
- self->fullpath = NULL;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ ivars->sys_dir_entry = NULL;
+ ivars->fullpath = NULL;
- self->sys_dirhandle = opendir(dir_path_ptr);
- if (!self->sys_dirhandle) {
+ ivars->sys_dirhandle = opendir(dir_path_ptr);
+ if (!ivars->sys_dirhandle) {
Err_set_error(Err_new(CB_newf("Failed to opendir '%o'", dir)));
DECREF(self);
return NULL;
@@ -218,13 +225,14 @@ FSDH_do_open(FSDirHandle *self, const CharBuf *dir) {
bool
FSDH_next(FSDirHandle *self) {
- self->sys_dir_entry = (struct dirent*)readdir((DIR*)self->sys_dirhandle);
- if (!self->sys_dir_entry) {
- CB_Set_Size(self->entry, 0);
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ ivars->sys_dir_entry = (struct dirent*)readdir((DIR*)ivars->sys_dirhandle);
+ if (!ivars->sys_dir_entry) {
+ CB_Set_Size(ivars->entry, 0);
return false;
}
else {
- struct dirent *sys_dir_entry = (struct dirent*)self->sys_dir_entry;
+ struct dirent *sys_dir_entry = (struct dirent*)ivars->sys_dir_entry;
#ifdef CHY_HAS_DIRENT_D_NAMLEN
size_t len = sys_dir_entry->d_namlen;
#else
@@ -234,7 +242,7 @@ FSDH_next(FSDirHandle *self) {
return FSDH_Next(self);
}
else {
- CB_Mimic_Str(self->entry, sys_dir_entry->d_name, len);
+ CB_Mimic_Str(ivars->entry, sys_dir_entry->d_name, len);
return true;
}
}
@@ -242,7 +250,8 @@ FSDH_next(FSDirHandle *self) {
bool
FSDH_entry_is_dir(FSDirHandle *self) {
- struct dirent *sys_dir_entry = (struct dirent*)self->sys_dir_entry;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ struct dirent *sys_dir_entry = (struct dirent*)ivars->sys_dir_entry;
if (!sys_dir_entry) { return false; }
// If d_type is available, try to avoid a stat() call. If it's not, or if
@@ -257,12 +266,12 @@ FSDH_entry_is_dir(FSDirHandle *self) {
#endif
struct stat stat_buf;
- if (!self->fullpath) {
- self->fullpath = CB_new(CB_Get_Size(self->dir) + 20);
+ if (!ivars->fullpath) {
+ ivars->fullpath = CB_new(CB_Get_Size(ivars->dir) + 20);
}
- CB_setf(self->fullpath, "%o%s%o", self->dir, CHY_DIR_SEP,
- self->entry);
- if (stat((char*)CB_Get_Ptr8(self->fullpath), &stat_buf) != -1) {
+ CB_setf(ivars->fullpath, "%o%s%o", ivars->dir, CHY_DIR_SEP,
+ ivars->entry);
+ if (stat((char*)CB_Get_Ptr8(ivars->fullpath), &stat_buf) != -1) {
if (stat_buf.st_mode & S_IFDIR) { return true; }
}
return false;
@@ -270,7 +279,8 @@ FSDH_entry_is_dir(FSDirHandle *self) {
bool
FSDH_entry_is_symlink(FSDirHandle *self) {
- struct dirent *sys_dir_entry = (struct dirent*)self->sys_dir_entry;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ struct dirent *sys_dir_entry = (struct dirent*)ivars->sys_dir_entry;
if (!sys_dir_entry) { return false; }
#ifdef CHY_HAS_DIRENT_D_TYPE
@@ -278,12 +288,12 @@ FSDH_entry_is_symlink(FSDirHandle *self) {
#else
{
struct stat stat_buf;
- if (!self->fullpath) {
- self->fullpath = CB_new(CB_Get_Size(self->dir) + 20);
+ if (!ivars->fullpath) {
+ ivars->fullpath = CB_new(CB_Get_Size(ivars->dir) + 20);
}
- CB_setf(self->fullpath, "%o%s%o", self->dir, CHY_DIR_SEP,
- self->entry);
- if (stat((char*)CB_Get_Ptr8(self->fullpath), &stat_buf) != -1) {
+ CB_setf(ivars->fullpath, "%o%s%o", ivars->dir, CHY_DIR_SEP,
+ ivars->entry);
+ if (stat((char*)CB_Get_Ptr8(ivars->fullpath), &stat_buf) != -1) {
if (stat_buf.st_mode & S_IFLNK) { return true; }
}
return false;
@@ -293,13 +303,14 @@ FSDH_entry_is_symlink(FSDirHandle *self) {
bool
FSDH_close(FSDirHandle *self) {
- if (self->fullpath) {
- CB_Dec_RefCount(self->fullpath);
- self->fullpath = NULL;
+ FSDirHandleIVARS *const ivars = FSDH_IVARS(self);
+ if (ivars->fullpath) {
+ CB_Dec_RefCount(ivars->fullpath);
+ ivars->fullpath = NULL;
}
- if (self->sys_dirhandle) {
- DIR *sys_dirhandle = (DIR*)self->sys_dirhandle;
- self->sys_dirhandle = NULL;
+ if (ivars->sys_dirhandle) {
+ DIR *sys_dirhandle = (DIR*)ivars->sys_dirhandle;
+ ivars->sys_dirhandle = NULL;
if (closedir(sys_dirhandle) == -1) {
Err_set_error(Err_new(CB_newf("Error closing dirhandle: %s",
strerror(errno))));
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/FSFileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFileHandle.c b/core/Lucy/Store/FSFileHandle.c
index d9f9b41..a81b338 100644
--- a/core/Lucy/Store/FSFileHandle.c
+++ b/core/Lucy/Store/FSFileHandle.c
@@ -61,7 +61,8 @@ SI_posix_flags(uint32_t fh_flags) {
// the requested length is 0, return NULL. If an error occurs, return NULL
// and set Err_error.
static INLINE void*
-SI_map(FSFileHandle *self, int64_t offset, int64_t len);
+SI_map(FSFileHandle *self, FSFileHandleIVARS *ivars, int64_t offset,
+ int64_t len);
// Release a memory mapped region assigned by SI_map.
static INLINE bool
@@ -69,11 +70,12 @@ SI_unmap(FSFileHandle *self, char *ptr, int64_t len);
// 32-bit or 64-bit inlined helpers for FSFH_window.
static INLINE bool
-SI_window(FSFileHandle *self, FileWindow *window, int64_t offset, int64_t len);
+SI_window(FSFileHandle *self, FSFileHandleIVARS *ivars, FileWindow *window,
+ int64_t offset, int64_t len);
// Architecture- and OS- specific initialization for a read-only FSFileHandle.
static INLINE bool
-SI_init_read_only(FSFileHandle *self);
+SI_init_read_only(FSFileHandle *self, FSFileHandleIVARS *ivars);
// Windows-specific routine needed for closing read-only handles.
#ifdef CHY_HAS_WINDOWS_H
@@ -90,6 +92,7 @@ FSFH_open(const CharBuf *path, uint32_t flags) {
FSFileHandle*
FSFH_do_open(FSFileHandle *self, const CharBuf *path, uint32_t flags) {
FH_do_open((FileHandle*)self, path, flags);
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
if (!path || !CB_Get_Size(path)) {
Err_set_error(Err_new(CB_newf("Missing required param 'path'")));
CFISH_DECREF(self);
@@ -98,31 +101,31 @@ FSFH_do_open(FSFileHandle *self, const CharBuf *path, uint32_t flags) {
// Attempt to open file.
if (flags & FH_WRITE_ONLY) {
- self->fd = open((char*)CB_Get_Ptr8(path), SI_posix_flags(flags), 0666);
- if (self->fd == -1) {
- self->fd = 0;
+ ivars->fd = open((char*)CB_Get_Ptr8(path), SI_posix_flags(flags), 0666);
+ if (ivars->fd == -1) {
+ ivars->fd = 0;
Err_set_error(Err_new(CB_newf("Attempt to open '%o' failed: %s",
path, strerror(errno))));
CFISH_DECREF(self);
return NULL;
}
if (flags & FH_EXCLUSIVE) {
- self->len = 0;
+ ivars->len = 0;
}
else {
// Derive length.
- self->len = lseek64(self->fd, INT64_C(0), SEEK_END);
- if (self->len == -1) {
+ ivars->len = lseek64(ivars->fd, INT64_C(0), SEEK_END);
+ if (ivars->len == -1) {
Err_set_error(Err_new(CB_newf("lseek64 on %o failed: %s",
- self->path, strerror(errno))));
+ ivars->path, strerror(errno))));
CFISH_DECREF(self);
return NULL;
}
else {
- int64_t check_val = lseek64(self->fd, INT64_C(0), SEEK_SET);
+ int64_t check_val = lseek64(ivars->fd, INT64_C(0), SEEK_SET);
if (check_val == -1) {
Err_set_error(Err_new(CB_newf("lseek64 on %o failed: %s",
- self->path, strerror(errno))));
+ ivars->path, strerror(errno))));
CFISH_DECREF(self);
return NULL;
}
@@ -130,11 +133,11 @@ FSFH_do_open(FSFileHandle *self, const CharBuf *path, uint32_t flags) {
}
}
else if (flags & FH_READ_ONLY) {
- if (SI_init_read_only(self)) {
+ if (SI_init_read_only(self, ivars)) {
// On 64-bit systems, map the whole file up-front.
- if (IS_64_BIT && self->len) {
- self->buf = (char*)SI_map(self, 0, self->len);
- if (!self->buf) {
+ if (IS_64_BIT && ivars->len) {
+ ivars->buf = (char*)SI_map(self, ivars, 0, ivars->len);
+ if (!ivars->buf) {
// An error occurred during SI_map, which has set
// Err_error for us already.
CFISH_DECREF(self);
@@ -159,23 +162,25 @@ FSFH_do_open(FSFileHandle *self, const CharBuf *path, uint32_t flags) {
bool
FSFH_close(FSFileHandle *self) {
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
+
// On 64-bit systems, cancel the whole-file mapping.
- if (IS_64_BIT && (self->flags & FH_READ_ONLY) && self->buf != NULL) {
- if (!SI_unmap(self, self->buf, self->len)) { return false; }
- self->buf = NULL;
+ if (IS_64_BIT && (ivars->flags & FH_READ_ONLY) && ivars->buf != NULL) {
+ if (!SI_unmap(self, ivars->buf, ivars->len)) { return false; }
+ ivars->buf = NULL;
}
// Close system-specific handles.
- if (self->fd) {
- if (close(self->fd)) {
+ if (ivars->fd) {
+ if (close(ivars->fd)) {
Err_set_error(Err_new(CB_newf("Failed to close file: %s",
strerror(errno))));
return false;
}
- self->fd = 0;
+ ivars->fd = 0;
}
#if (defined(CHY_HAS_WINDOWS_H) && !defined(CHY_HAS_SYS_MMAN_H))
- if (self->win_fhandle) {
+ if (ivars->win_fhandle) {
if (!SI_close_win_handles(self)) { return false; }
}
#endif
@@ -185,10 +190,12 @@ FSFH_close(FSFileHandle *self) {
bool
FSFH_write(FSFileHandle *self, const void *data, size_t len) {
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
+
if (len) {
// Write data, track file length, check for errors.
- int64_t check_val = write(self->fd, data, len);
- self->len += check_val;
+ int64_t check_val = write(ivars->fd, data, len);
+ ivars->len += check_val;
if ((size_t)check_val != len) {
if (check_val == -1) {
Err_set_error(Err_new(CB_newf("Error when writing %u64 bytes: %s",
@@ -207,14 +214,15 @@ FSFH_write(FSFileHandle *self, const void *data, size_t len) {
int64_t
FSFH_length(FSFileHandle *self) {
- return self->len;
+ return FSFH_IVARS(self)->len;
}
bool
FSFH_window(FSFileHandle *self, FileWindow *window, int64_t offset,
int64_t len) {
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
const 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;
}
@@ -223,13 +231,13 @@ FSFH_window(FSFileHandle *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 {
- return SI_window(self, window, offset, len);
+ return SI_window(self, ivars, window, offset, len);
}
}
@@ -238,9 +246,10 @@ FSFH_window(FSFileHandle *self, FileWindow *window, int64_t offset,
#if IS_64_BIT
static INLINE bool
-SI_window(FSFileHandle *self, FileWindow *window, int64_t offset,
- int64_t len) {
- FileWindow_Set_Window(window, self->buf + offset, offset, len);
+SI_window(FSFileHandle *self, FSFileHandleIVARS *ivars, FileWindow *window,
+ int64_t offset, int64_t len) {
+ UNUSED_VAR(self);
+ FileWindow_Set_Window(window, ivars->buf + offset, offset, len);
return true;
}
@@ -253,9 +262,10 @@ FSFH_release_window(FSFileHandle *self, FileWindow *window) {
bool
FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
const int64_t end = offset + len;
- if (self->flags & FH_WRITE_ONLY) {
+ if (ivars->flags & FH_WRITE_ONLY) {
Err_set_error(Err_new(CB_newf("Can't read from write-only filehandle")));
return false;
}
@@ -264,12 +274,12 @@ FSFH_read(FSFileHandle *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("Tried to read past EOF: offset %i64 + request %u64 > len %i64",
- offset, (uint64_t)len, self->len)));
+ offset, (uint64_t)len, ivars->len)));
return false;
}
- memcpy(dest, self->buf + offset, len);
+ memcpy(dest, ivars->buf + offset, len);
return true;
}
@@ -278,18 +288,19 @@ FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
#else
static INLINE bool
-SI_window(FSFileHandle *self, FileWindow *window, int64_t offset,
- int64_t len) {
+SI_window(FSFileHandle *self, FSFileHandleIVARS *ivars, FileWindow *window,
+ int64_t offset, int64_t len) {
// Release the previously mmap'd region, if any.
FSFH_release_window(self, window);
// Start map on a page boundary. Ensure that the window is at
// least wide enough to view all the data spec'd in the original
// request.
- const int64_t remainder = offset % self->page_size;
+ const int64_t remainder = offset % ivars->page_size;
const int64_t adjusted_offset = offset - remainder;
const int64_t adjusted_len = len + remainder;
- char *const buf = (char*)SI_map(self, adjusted_offset, adjusted_len);
+ char *const buf
+ = (char*)SI_map(self, ivars, adjusted_offset, adjusted_len);
if (len && buf == NULL) {
return false;
}
@@ -314,38 +325,38 @@ FSFH_release_window(FSFileHandle *self, FileWindow *window) {
#ifdef CHY_HAS_SYS_MMAN_H
static INLINE bool
-SI_init_read_only(FSFileHandle *self) {
+SI_init_read_only(FSFileHandle *self, FSFileHandleIVARS *ivars) {
// Open.
- self->fd = open((char*)CB_Get_Ptr8(self->path),
- SI_posix_flags(self->flags), 0666);
- if (self->fd == -1) {
- self->fd = 0;
- Err_set_error(Err_new(CB_newf("Can't open '%o': %s", self->path,
+ ivars->fd = open((char*)CB_Get_Ptr8(ivars->path),
+ SI_posix_flags(ivars->flags), 0666);
+ if (ivars->fd == -1) {
+ ivars->fd = 0;
+ Err_set_error(Err_new(CB_newf("Can't open '%o': %s", ivars->path,
strerror(errno))));
return false;
}
// Derive len.
- self->len = lseek64(self->fd, INT64_C(0), SEEK_END);
- if (self->len == -1) {
- Err_set_error(Err_new(CB_newf("lseek64 on %o failed: %s", self->path,
+ ivars->len = lseek64(ivars->fd, INT64_C(0), SEEK_END);
+ if (ivars->len == -1) {
+ Err_set_error(Err_new(CB_newf("lseek64 on %o failed: %s", ivars->path,
strerror(errno))));
return false;
}
else {
- int64_t check_val = lseek64(self->fd, INT64_C(0), SEEK_SET);
+ int64_t check_val = lseek64(ivars->fd, INT64_C(0), SEEK_SET);
if (check_val == -1) {
Err_set_error(Err_new(CB_newf("lseek64 on %o failed: %s",
- self->path, strerror(errno))));
+ ivars->path, strerror(errno))));
return false;
}
}
// Get system page size.
#if defined(_SC_PAGESIZE)
- self->page_size = sysconf(_SC_PAGESIZE);
+ ivars->page_size = sysconf(_SC_PAGESIZE);
#elif defined(_SC_PAGE_SIZE)
- self->page_size = sysconf(_SC_PAGE_SIZE);
+ ivars->page_size = sysconf(_SC_PAGE_SIZE);
#else
#error "Can't determine system memory page size"
#endif
@@ -354,17 +365,19 @@ SI_init_read_only(FSFileHandle *self) {
}
static INLINE void*
-SI_map(FSFileHandle *self, int64_t offset, int64_t len) {
+SI_map(FSFileHandle *self, FSFileHandleIVARS *ivars, int64_t offset,
+ int64_t len) {
+ UNUSED_VAR(self);
void *buf = NULL;
if (len) {
// Read-only memory mapping.
- buf = mmap(NULL, len, PROT_READ, MAP_SHARED, self->fd, offset);
+ buf = mmap(NULL, len, PROT_READ, MAP_SHARED, ivars->fd, offset);
if (buf == (void*)(-1)) {
Err_set_error(Err_new(CB_newf("mmap of offset %i64 and length %i64 (page size %i64) "
"against '%o' failed: %s",
- offset, len, self->page_size,
- self->path, strerror(errno))));
+ offset, len, ivars->page_size,
+ ivars->path, strerror(errno))));
return NULL;
}
}
@@ -377,7 +390,8 @@ SI_unmap(FSFileHandle *self, char *buf, int64_t len) {
if (buf != NULL) {
if (munmap(buf, len)) {
Err_set_error(Err_new(CB_newf("Failed to munmap '%o': %s",
- self->path, strerror(errno))));
+ FSFH_IVARS(self)->path,
+ strerror(errno))));
return false;
}
}
@@ -387,6 +401,7 @@ SI_unmap(FSFileHandle *self, char *buf, int64_t len) {
#if !IS_64_BIT
bool
FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
int64_t check_val;
// Sanity check.
@@ -397,7 +412,7 @@ FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
}
// Read.
- check_val = pread64(self->fd, dest, len, offset);
+ check_val = pread64(ivars->fd, dest, len, offset);
if (check_val != (int64_t)len) {
if (check_val == -1) {
Err_set_error(Err_new(CB_newf("Tried to read %u64 bytes, got %i64: %s",
@@ -419,16 +434,16 @@ FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
#elif defined(CHY_HAS_WINDOWS_H)
static INLINE bool
-SI_init_read_only(FSFileHandle *self) {
- char *filepath = (char*)CB_Get_Ptr8(self->path);
+SI_init_read_only(FSFileHandle *self, FSFileHandleIVARS *ivars) {
+ char *filepath = (char*)CB_Get_Ptr8(ivars->path);
SYSTEM_INFO sys_info;
// Get system page size.
GetSystemInfo(&sys_info);
- self->page_size = sys_info.dwAllocationGranularity;
+ ivars->page_size = sys_info.dwAllocationGranularity;
// Open.
- self->win_fhandle = CreateFile(
+ ivars->win_fhandle = CreateFile(
filepath,
GENERIC_READ,
FILE_SHARE_READ,
@@ -437,33 +452,33 @@ SI_init_read_only(FSFileHandle *self) {
FILE_ATTRIBUTE_READONLY | FILE_FLAG_OVERLAPPED,
NULL
);
- if (self->win_fhandle == INVALID_HANDLE_VALUE) {
+ if (ivars->win_fhandle == INVALID_HANDLE_VALUE) {
char *win_error = Err_win_error();
Err_set_error(Err_new(CB_newf("CreateFile for %o failed: %s",
- self->path, win_error)));
+ ivars->path, win_error)));
FREEMEM(win_error);
return false;
}
// Derive len.
DWORD file_size_hi;
- DWORD file_size_lo = GetFileSize(self->win_fhandle, &file_size_hi);
+ DWORD file_size_lo = GetFileSize(ivars->win_fhandle, &file_size_hi);
if (file_size_lo == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) {
Err_set_error(Err_new(CB_newf("GetFileSize for %o failed",
- self->path)));
+ ivars->path)));
return false;
}
- self->len = ((uint64_t)file_size_hi << 32) | file_size_lo;
+ ivars->len = ((uint64_t)file_size_hi << 32) | file_size_lo;
// Init mapping handle.
- self->buf = NULL;
- if (self->len) {
- self->win_maphandle = CreateFileMapping(self->win_fhandle, NULL,
- PAGE_READONLY, 0, 0, NULL);
- if (self->win_maphandle == NULL) {
+ ivars->buf = NULL;
+ if (ivars->len) {
+ ivars->win_maphandle = CreateFileMapping(ivars->win_fhandle, NULL,
+ PAGE_READONLY, 0, 0, NULL);
+ if (ivars->win_maphandle == NULL) {
char *win_error = Err_win_error();
Err_set_error(Err_new(CB_newf("CreateFileMapping for %o failed: %s",
- self->path, win_error)));
+ ivars->path, win_error)));
FREEMEM(win_error);
return false;
}
@@ -473,7 +488,8 @@ SI_init_read_only(FSFileHandle *self) {
}
static INLINE void*
-SI_map(FSFileHandle *self, int64_t offset, int64_t len) {
+SI_map(FSFileHandle *self, FSFileHandleIVARS *ivars, int64_t offset,
+ int64_t len) {
void *buf = NULL;
if (len) {
@@ -482,12 +498,12 @@ SI_map(FSFileHandle *self, int64_t offset, int64_t len) {
DWORD file_offset_hi = offs >> 32;
DWORD file_offset_lo = offs & 0xFFFFFFFF;
size_t amount = (size_t)len;
- buf = MapViewOfFile(self->win_maphandle, FILE_MAP_READ,
+ buf = MapViewOfFile(ivars->win_maphandle, FILE_MAP_READ,
file_offset_hi, file_offset_lo, amount);
if (buf == NULL) {
char *win_error = Err_win_error();
Err_set_error(Err_new(CB_newf("MapViewOfFile for %o failed: %s",
- self->path, win_error)));
+ ivars->path, win_error)));
FREEMEM(win_error);
}
}
@@ -496,12 +512,13 @@ SI_map(FSFileHandle *self, int64_t offset, int64_t len) {
}
static INLINE bool
-SI_unmap(FSFileHandle *self, char *buf, int64_t len) {
+SI_unmap(FSFileHandle *self, char *ptr, int64_t len) {
if (buf != NULL) {
if (!UnmapViewOfFile(buf)) {
char *win_error = Err_win_error();
Err_set_error(Err_new(CB_newf("Failed to unmap '%o': %s",
- self->path, win_error)));
+ FSFH_IVARS(self)->path,
+ win_error)));
FREEMEM(win_error);
return false;
}
@@ -511,26 +528,27 @@ SI_unmap(FSFileHandle *self, char *buf, int64_t len) {
static INLINE bool
SI_close_win_handles(FSFileHandle *self) {
+ FSFileHandleIVARS *ivars = FSFH_IVARS(self);
// Close both standard handle and mapping handle.
- if (self->win_maphandle) {
- if (!CloseHandle(self->win_maphandle)) {
+ if (ivars->win_maphandle) {
+ if (!CloseHandle(ivars->win_maphandle)) {
char *win_error = Err_win_error();
Err_set_error(Err_new(CB_newf("Failed to close file mapping handle: %s",
win_error)));
FREEMEM(win_error);
return false;
}
- self->win_maphandle = NULL;
+ ivars->win_maphandle = NULL;
}
- if (self->win_fhandle) {
- if (!CloseHandle(self->win_fhandle)) {
+ if (ivars->win_fhandle) {
+ if (!CloseHandle(ivars->win_fhandle)) {
char *win_error = Err_win_error();
Err_set_error(Err_new(CB_newf("Failed to close file handle: %s",
win_error)));
FREEMEM(win_error);
return false;
}
- self->win_fhandle = NULL;
+ ivars->win_fhandle = NULL;
}
return true;
@@ -539,6 +557,7 @@ SI_close_win_handles(FSFileHandle *self) {
#if !IS_64_BIT
bool
FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
+ FSFileHandleIVARS *const ivars = FSFH_IVARS(self);
BOOL check_val;
DWORD got;
OVERLAPPED read_op_state;
@@ -564,12 +583,12 @@ FSFH_read(FSFileHandle *self, char *dest, int64_t offset, size_t len) {
}
// Read.
- check_val = ReadFile(self->win_fhandle, dest, len, &got, &read_op_state);
+ check_val = ReadFile(ivars->win_fhandle, dest, len, &got, &read_op_state);
if (!check_val && GetLastError() == ERROR_IO_PENDING) {
// Read has been queued by the OS and will soon complete. Wait for
// it, since this is a blocking IO call from the point of the rest of
// the library.
- check_val = GetOverlappedResult(self->win_fhandle, &read_op_state,
+ check_val = GetOverlappedResult(ivars->win_fhandle, &read_op_state,
&got, TRUE);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/FSFolder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FSFolder.c b/core/Lucy/Store/FSFolder.c
index ab6b15c..c80fff5 100644
--- a/core/Lucy/Store/FSFolder.c
+++ b/core/Lucy/Store/FSFolder.c
@@ -90,8 +90,9 @@ FSFolder_init(FSFolder *self, const CharBuf *path) {
void
FSFolder_initialize(FSFolder *self) {
- if (!S_dir_ok(self->path)) {
- if (!S_create_dir(self->path)) {
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+ if (!S_dir_ok(ivars->path)) {
+ if (!S_create_dir(ivars->path)) {
RETHROW(INCREF(Err_get_error()));
}
}
@@ -99,7 +100,8 @@ FSFolder_initialize(FSFolder *self) {
bool
FSFolder_check(FSFolder *self) {
- return S_dir_ok(self->path);
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+ return S_dir_ok(ivars->path);
}
FileHandle*
@@ -123,14 +125,16 @@ FSFolder_local_mkdir(FSFolder *self, const CharBuf *name) {
DirHandle*
FSFolder_local_open_dir(FSFolder *self) {
- DirHandle *dh = (DirHandle*)FSDH_open(self->path);
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+ DirHandle *dh = (DirHandle*)FSDH_open(ivars->path);
if (!dh) { ERR_ADD_FRAME(Err_get_error()); }
return dh;
}
bool
FSFolder_local_exists(FSFolder *self, const CharBuf *name) {
- if (Hash_Fetch(self->entries, (Obj*)name)) {
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+ if (Hash_Fetch(ivars->entries, (Obj*)name)) {
return true;
}
else if (!S_is_local_entry(name)) {
@@ -150,8 +154,10 @@ FSFolder_local_exists(FSFolder *self, const CharBuf *name) {
bool
FSFolder_local_is_directory(FSFolder *self, const CharBuf *name) {
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+
// Check for a cached object, then fall back to a system call.
- Obj *elem = Hash_Fetch(self->entries, (Obj*)name);
+ Obj *elem = Hash_Fetch(ivars->entries, (Obj*)name);
if (elem && Obj_Is_A(elem, FOLDER)) {
return true;
}
@@ -191,6 +197,8 @@ FSFolder_hard_link(FSFolder *self, const CharBuf *from,
bool
FSFolder_local_delete(FSFolder *self, const CharBuf *name) {
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+
CharBuf *fullpath = S_fullpath(self, name);
char *path_ptr = (char*)CB_Get_Ptr8(fullpath);
#ifdef CHY_REMOVE_ZAPS_DIRS
@@ -198,18 +206,21 @@ FSFolder_local_delete(FSFolder *self, const CharBuf *name) {
#else
bool result = !rmdir(path_ptr) || !remove(path_ptr);
#endif
- DECREF(Hash_Delete(self->entries, (Obj*)name));
+ DECREF(Hash_Delete(ivars->entries, (Obj*)name));
DECREF(fullpath);
return result;
}
void
FSFolder_close(FSFolder *self) {
- Hash_Clear(self->entries);
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+ Hash_Clear(ivars->entries);
}
Folder*
FSFolder_local_find_folder(FSFolder *self, const CharBuf *name) {
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+
Folder *subfolder = NULL;
if (!name || !CB_Get_Size(name)) {
// No entity can be identified by NULL or empty string.
@@ -222,7 +233,7 @@ FSFolder_local_find_folder(FSFolder *self, const CharBuf *name) {
// Don't allow access outside of the main dir.
return NULL;
}
- else if (NULL != (subfolder = (Folder*)Hash_Fetch(self->entries, (Obj*)name))) {
+ else if (NULL != (subfolder = (Folder*)Hash_Fetch(ivars->entries, (Obj*)name))) {
if (Folder_Is_A(subfolder, FOLDER)) {
return subfolder;
}
@@ -248,7 +259,7 @@ FSFolder_local_find_folder(FSFolder *self, const CharBuf *name) {
subfolder = (Folder*)cf_reader;
}
}
- Hash_Store(self->entries, (Obj*)name, (Obj*)subfolder);
+ Hash_Store(ivars->entries, (Obj*)name, (Obj*)subfolder);
}
DECREF(fullpath);
@@ -257,7 +268,8 @@ FSFolder_local_find_folder(FSFolder *self, const CharBuf *name) {
static CharBuf*
S_fullpath(FSFolder *self, const CharBuf *path) {
- CharBuf *fullpath = CB_newf("%o%s%o", self->path, DIR_SEP, path);
+ FSFolderIVARS *const ivars = FSFolder_IVARS(self);
+ CharBuf *fullpath = CB_newf("%o%s%o", ivars->path, DIR_SEP, path);
if (DIR_SEP[0] != '/') {
CB_Swap_Chars(fullpath, '/', DIR_SEP[0]);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/FileHandle.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FileHandle.c b/core/Lucy/Store/FileHandle.c
index 9b37809..4fcb235 100644
--- a/core/Lucy/Store/FileHandle.c
+++ b/core/Lucy/Store/FileHandle.c
@@ -23,8 +23,9 @@ int32_t FH_object_count = 0;
FileHandle*
FH_do_open(FileHandle *self, const CharBuf *path, uint32_t flags) {
- self->path = path ? CB_Clone(path) : CB_new(0);
- self->flags = flags;
+ FileHandleIVARS *const ivars = FH_IVARS(self);
+ ivars->path = path ? CB_Clone(path) : CB_new(0);
+ ivars->flags = flags;
// Track number of live FileHandles released into the wild.
FH_object_count++;
@@ -35,8 +36,9 @@ FH_do_open(FileHandle *self, const CharBuf *path, uint32_t flags) {
void
FH_destroy(FileHandle *self) {
+ FileHandleIVARS *const ivars = FH_IVARS(self);
FH_Close(self);
- DECREF(self->path);
+ DECREF(ivars->path);
SUPER_DESTROY(self, FILEHANDLE);
// Decrement count of FileHandle objects in existence.
@@ -52,12 +54,13 @@ FH_grow(FileHandle *self, int64_t length) {
void
FH_set_path(FileHandle *self, const CharBuf *path) {
- CB_Mimic(self->path, (Obj*)path);
+ FileHandleIVARS *const ivars = FH_IVARS(self);
+ CB_Mimic(ivars->path, (Obj*)path);
}
CharBuf*
FH_get_path(FileHandle *self) {
- return self->path;
+ return FH_IVARS(self)->path;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/FileWindow.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/FileWindow.c b/core/Lucy/Store/FileWindow.c
index 51b747e..067c6a8 100644
--- a/core/Lucy/Store/FileWindow.c
+++ b/core/Lucy/Store/FileWindow.c
@@ -32,21 +32,23 @@ FileWindow_init(FileWindow *self) {
void
FileWindow_set_offset(FileWindow *self, int64_t offset) {
- if (self->buf != NULL) {
- if (offset != self->offset) {
+ FileWindowIVARS *const ivars = FileWindow_IVARS(self);
+ if (ivars->buf != NULL) {
+ if (offset != ivars->offset) {
THROW(ERR, "Can't set offset to %i64 instead of %i64 unless buf "
- "is NULL", offset, self->offset);
+ "is NULL", offset, ivars->offset);
}
}
- self->offset = offset;
+ ivars->offset = offset;
}
void
FileWindow_set_window(FileWindow *self, char *buf, int64_t offset,
int64_t len) {
- self->buf = buf;
- self->offset = offset;
- self->len = len;
+ FileWindowIVARS *const ivars = FileWindow_IVARS(self);
+ ivars->buf = buf;
+ ivars->offset = offset;
+ ivars->len = len;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/Folder.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Folder.c b/core/Lucy/Store/Folder.c
index 414a189..d87db4b 100644
--- a/core/Lucy/Store/Folder.c
+++ b/core/Lucy/Store/Folder.c
@@ -30,18 +30,20 @@
Folder*
Folder_init(Folder *self, const CharBuf *path) {
+ FolderIVARS *const ivars = Folder_IVARS(self);
+
// Init.
- self->entries = Hash_new(16);
+ ivars->entries = Hash_new(16);
// Copy.
if (path == NULL) {
- self->path = CB_new_from_trusted_utf8("", 0);
+ ivars->path = CB_new_from_trusted_utf8("", 0);
}
else {
// Copy path, strip trailing slash or equivalent.
- self->path = CB_Clone(path);
- if (CB_Ends_With_Str(self->path, DIR_SEP, strlen(DIR_SEP))) {
- CB_Chop(self->path, 1);
+ ivars->path = CB_Clone(path);
+ if (CB_Ends_With_Str(ivars->path, DIR_SEP, strlen(DIR_SEP))) {
+ CB_Chop(ivars->path, 1);
}
}
@@ -51,8 +53,9 @@ Folder_init(Folder *self, const CharBuf *path) {
void
Folder_destroy(Folder *self) {
- DECREF(self->path);
- DECREF(self->entries);
+ FolderIVARS *const ivars = Folder_IVARS(self);
+ DECREF(ivars->path);
+ DECREF(ivars->entries);
SUPER_DESTROY(self, FOLDER);
}
@@ -382,13 +385,14 @@ Folder_slurp_file(Folder *self, const CharBuf *path) {
CharBuf*
Folder_get_path(Folder *self) {
- return self->path;
+ return Folder_IVARS(self)->path;
}
void
Folder_set_path(Folder *self, const CharBuf *path) {
- DECREF(self->path);
- self->path = CB_Clone(path);
+ FolderIVARS *const ivars = Folder_IVARS(self);
+ DECREF(ivars->path);
+ ivars->path = CB_Clone(path);
}
void
@@ -409,7 +413,8 @@ Folder_consolidate(Folder *self, const CharBuf *path) {
ZombieCharBuf *name = IxFileNames_local_part(path, ZCB_BLANK());
CompoundFileReader *cf_reader = CFReader_open(folder);
if (!cf_reader) { RETHROW(INCREF(Err_get_error())); }
- Hash_Store(enclosing_folder->entries, (Obj*)name,
+ Hash *entries = Folder_IVARS(enclosing_folder)->entries;
+ Hash_Store(entries, (Obj*)name,
(Obj*)cf_reader);
}
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/InStream.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/InStream.c b/core/Lucy/Store/InStream.c
index 977d4a4..9526360 100644
--- a/core/Lucy/Store/InStream.c
+++ b/core/Lucy/Store/InStream.c
@@ -35,7 +35,7 @@ SI_read_bytes(InStream *self, char* buf, size_t len);
// Inlined version of InStream_Read_U8.
static INLINE uint8_t
-SI_read_u8(InStream *self);
+SI_read_u8(InStream *self, InStreamIVARS *const ivars);
// Ensure that the buffer contains exactly the specified amount of data.
static void
@@ -55,22 +55,24 @@ InStream_open(Obj *file) {
InStream*
InStream_do_open(InStream *self, Obj *file) {
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+
// Init.
- self->buf = NULL;
- self->limit = NULL;
- self->offset = 0;
- self->window = FileWindow_new();
+ ivars->buf = NULL;
+ ivars->limit = NULL;
+ ivars->offset = 0;
+ ivars->window = FileWindow_new();
// 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_READ_ONLY, (RAMFile*)file);
}
else if (Obj_Is_A(file, CHARBUF)) {
- self->file_handle
+ ivars->file_handle
= (FileHandle*)FSFH_open((CharBuf*)file, FH_READ_ONLY);
}
else {
@@ -79,16 +81,16 @@ InStream_do_open(InStream *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;
}
// Get length and filename from the FileHandle.
- self->filename = CB_Clone(FH_Get_Path(self->file_handle));
- self->len = FH_Length(self->file_handle);
- if (self->len == -1) {
+ ivars->filename = CB_Clone(FH_Get_Path(ivars->file_handle));
+ ivars->len = FH_Length(ivars->file_handle);
+ if (ivars->len == -1) {
ERR_ADD_FRAME(Err_get_error());
DECREF(self);
return NULL;
@@ -99,70 +101,77 @@ InStream_do_open(InStream *self, Obj *file) {
void
InStream_close(InStream *self) {
- if (self->file_handle) {
- FH_Release_Window(self->file_handle, self->window);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ if (ivars->file_handle) {
+ FH_Release_Window(ivars->file_handle, ivars->window);
// Note that we don't close the FileHandle, because it's probably
// shared.
- DECREF(self->file_handle);
- self->file_handle = NULL;
+ DECREF(ivars->file_handle);
+ ivars->file_handle = NULL;
}
}
void
InStream_destroy(InStream *self) {
- if (self->file_handle) {
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ if (ivars->file_handle) {
InStream_Close(self);
}
- DECREF(self->filename);
- DECREF(self->window);
+ DECREF(ivars->filename);
+ DECREF(ivars->window);
SUPER_DESTROY(self, INSTREAM);
}
InStream*
InStream_reopen(InStream *self, const CharBuf *filename, int64_t offset,
int64_t len) {
- if (!self->file_handle) {
- THROW(ERR, "Can't Reopen() closed InStream %o", self->filename);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ if (!ivars->file_handle) {
+ THROW(ERR, "Can't Reopen() closed InStream %o", ivars->filename);
}
- if (offset + len > FH_Length(self->file_handle)) {
+ if (offset + len > FH_Length(ivars->file_handle)) {
THROW(ERR, "Offset + length too large (%i64 + %i64 > %i64)",
- offset, len, FH_Length(self->file_handle));
+ offset, len, FH_Length(ivars->file_handle));
}
- InStream *twin = (InStream*)VTable_Make_Obj(self->vtable);
- InStream_do_open(twin, (Obj*)self->file_handle);
- if (filename != NULL) { CB_Mimic(twin->filename, (Obj*)filename); }
- twin->offset = offset;
- twin->len = len;
- InStream_Seek(twin, 0);
+ InStream *other = (InStream*)VTable_Make_Obj(ivars->vtable);
+ InStreamIVARS *const ovars = InStream_IVARS(other);
+ InStream_do_open(other, (Obj*)ivars->file_handle);
+ if (filename != NULL) { CB_Mimic(ovars->filename, (Obj*)filename); }
+ ovars->offset = offset;
+ ovars->len = len;
+ InStream_Seek(other, 0);
- return twin;
+ return other;
}
InStream*
InStream_clone(InStream *self) {
- InStream *twin = (InStream*)VTable_Make_Obj(self->vtable);
- InStream_do_open(twin, (Obj*)self->file_handle);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ InStream *twin = (InStream*)VTable_Make_Obj(ivars->vtable);
+ InStream_do_open(twin, (Obj*)ivars->file_handle);
InStream_Seek(twin, SI_tell(self));
return twin;
}
CharBuf*
InStream_get_filename(InStream *self) {
- return self->filename;
+ return InStream_IVARS(self)->filename;
}
static int64_t
S_refill(InStream *self) {
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+
// Determine the amount to request.
const int64_t sub_file_pos = SI_tell(self);
- const int64_t remaining = self->len - sub_file_pos;
+ const int64_t remaining = ivars->len - sub_file_pos;
const int64_t amount = remaining < IO_STREAM_BUF_SIZE
? remaining
: IO_STREAM_BUF_SIZE;
if (!remaining) {
THROW(ERR, "Read past EOF of '%o' (offset: %i64 len: %i64)",
- self->filename, self->offset, self->len);
+ ivars->filename, ivars->offset, ivars->len);
}
// Make the request.
@@ -178,31 +187,32 @@ InStream_refill(InStream *self) {
static void
S_fill(InStream *self, int64_t amount) {
- FileWindow *const window = self->window;
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ FileWindow *const window = ivars->window;
const int64_t virtual_file_pos = SI_tell(self);
- const int64_t real_file_pos = virtual_file_pos + self->offset;
- const int64_t remaining = self->len - virtual_file_pos;
+ const int64_t real_file_pos = virtual_file_pos + ivars->offset;
+ const int64_t remaining = ivars->len - virtual_file_pos;
// Throw an error if the requested amount would take us beyond EOF.
if (amount > remaining) {
THROW(ERR, "Read past EOF of %o (pos: %u64 len: %u64 request: %u64)",
- self->filename, virtual_file_pos, self->len, amount);
+ ivars->filename, virtual_file_pos, ivars->len, amount);
}
// Make the request.
- if (FH_Window(self->file_handle, window, real_file_pos, amount)) {
+ if (FH_Window(ivars->file_handle, window, real_file_pos, amount)) {
char *const window_limit = window->buf + window->len;
- self->buf = window->buf
- - window->offset // theoretical start of real file
- + self->offset // top of virtual file
- + virtual_file_pos; // position within virtual file
- self->limit = window_limit - self->buf > remaining
- ? self->buf + remaining
- : window_limit;
+ ivars->buf = window->buf
+ - window->offset // theoretical start of real file
+ + ivars->offset // top of virtual file
+ + virtual_file_pos; // position within virtual file
+ ivars->limit = window_limit - ivars->buf > remaining
+ ? ivars->buf + remaining
+ : window_limit;
}
else {
Err *error = Err_get_error();
- CB_catf(Err_Get_Mess(error), " (%o)", self->filename);
+ CB_catf(Err_Get_Mess(error), " (%o)", ivars->filename);
RETHROW(INCREF(error));
}
}
@@ -214,40 +224,42 @@ InStream_fill(InStream *self, int64_t amount) {
void
InStream_seek(InStream *self, int64_t target) {
- FileWindow *const window = self->window;
- int64_t virtual_window_top = window->offset - self->offset;
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ FileWindow *const window = ivars->window;
+ int64_t virtual_window_top = window->offset - ivars->offset;
int64_t virtual_window_end = virtual_window_top + window->len;
if (target < 0) {
- THROW(ERR, "Can't Seek '%o' to negative target %i64", self->filename,
+ THROW(ERR, "Can't Seek '%o' to negative target %i64", ivars->filename,
target);
}
// Seek within window if possible.
else if (target >= virtual_window_top
&& target <= virtual_window_end
) {
- self->buf = window->buf - window->offset + self->offset + target;
+ ivars->buf = window->buf - window->offset + ivars->offset + target;
}
- else if (target > self->len) {
- THROW(ERR, "Can't Seek '%o' past EOF (%i64 > %i64)", self->filename,
- target, self->len);
+ else if (target > ivars->len) {
+ THROW(ERR, "Can't Seek '%o' past EOF (%i64 > %i64)", ivars->filename,
+ target, ivars->len);
}
else {
// Target is outside window. Set all buffer and limit variables to
// NULL to trigger refill on the next read. Store the file position
// in the FileWindow's offset.
- FH_Release_Window(self->file_handle, window);
- self->buf = NULL;
- self->limit = NULL;
- FileWindow_Set_Offset(window, self->offset + target);
+ FH_Release_Window(ivars->file_handle, window);
+ ivars->buf = NULL;
+ ivars->limit = NULL;
+ FileWindow_Set_Offset(window, ivars->offset + target);
}
}
static INLINE int64_t
SI_tell(InStream *self) {
- FileWindow *const window = self->window;
- int64_t pos_in_buf = PTR_TO_I64(self->buf) - PTR_TO_I64(window->buf);
- return pos_in_buf + window->offset - self->offset;
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ FileWindow *const window = ivars->window;
+ int64_t pos_in_buf = PTR_TO_I64(ivars->buf) - PTR_TO_I64(window->buf);
+ return pos_in_buf + window->offset - ivars->offset;
}
int64_t
@@ -257,12 +269,13 @@ InStream_tell(InStream *self) {
int64_t
InStream_length(InStream *self) {
- return self->len;
+ return InStream_IVARS(self)->len;
}
char*
InStream_buf(InStream *self, size_t request) {
- const int64_t bytes_in_buf = PTR_TO_I64(self->limit) - PTR_TO_I64(self->buf);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ const int64_t bytes_in_buf = PTR_TO_I64(ivars->limit) - PTR_TO_I64(ivars->buf);
/* It's common for client code to overestimate how much is needed, because
* the request has to figure in worst-case for compressed data. However,
@@ -270,7 +283,7 @@ InStream_buf(InStream *self, size_t request) {
* bytes, they really need 1 byte, and there's 1k in the buffer), we can
* skip the following refill block. */
if ((int64_t)request > bytes_in_buf) {
- const int64_t remaining_in_file = self->len - SI_tell(self);
+ const int64_t remaining_in_file = ivars->len - SI_tell(self);
int64_t amount = request;
// Try to bump up small requests.
@@ -286,22 +299,23 @@ InStream_buf(InStream *self, size_t request) {
}
}
- return self->buf;
+ return ivars->buf;
}
void
InStream_advance_buf(InStream *self, char *buf) {
- if (buf > self->limit) {
- int64_t overrun = PTR_TO_I64(buf) - PTR_TO_I64(self->limit);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ if (buf > ivars->limit) {
+ int64_t overrun = PTR_TO_I64(buf) - PTR_TO_I64(ivars->limit);
THROW(ERR, "Supplied value is %i64 bytes beyond end of buffer",
overrun);
}
- else if (buf < self->buf) {
- int64_t underrun = PTR_TO_I64(self->buf) - PTR_TO_I64(buf);
+ else if (buf < ivars->buf) {
+ int64_t underrun = PTR_TO_I64(ivars->buf) - PTR_TO_I64(buf);
THROW(ERR, "Can't Advance_Buf backwards: (underrun: %i64))", underrun);
}
else {
- self->buf = buf;
+ ivars->buf = buf;
}
}
@@ -312,19 +326,20 @@ InStream_read_bytes(InStream *self, char* buf, size_t len) {
static INLINE void
SI_read_bytes(InStream *self, char* buf, size_t len) {
- const int64_t available = PTR_TO_I64(self->limit) - PTR_TO_I64(self->buf);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ const int64_t available = PTR_TO_I64(ivars->limit) - PTR_TO_I64(ivars->buf);
if (available >= (int64_t)len) {
// Request is entirely within buffer, so copy.
- memcpy(buf, self->buf, len);
- self->buf += len;
+ memcpy(buf, ivars->buf, len);
+ ivars->buf += len;
}
else {
// Pass along whatever we've got in the buffer.
if (available > 0) {
- memcpy(buf, self->buf, (size_t)available);
+ memcpy(buf, ivars->buf, (size_t)available);
buf += available;
len -= (size_t)available;
- self->buf += available;
+ ivars->buf += available;
}
if (len < IO_STREAM_BUF_SIZE) {
@@ -334,19 +349,19 @@ SI_read_bytes(InStream *self, char* buf, size_t len) {
int64_t orig_pos = SI_tell(self) - available;
int64_t orig_len = len + available;
THROW(ERR, "Read past EOF of %o (pos: %i64 len: %i64 "
- "request: %i64)", self->filename, orig_pos,
- self->len, orig_len);
+ "request: %i64)", ivars->filename, orig_pos,
+ ivars->len, orig_len);
}
- memcpy(buf, self->buf, len);
- self->buf += len;
+ memcpy(buf, ivars->buf, len);
+ ivars->buf += len;
}
else {
// Too big to handle via the buffer, so resort to a brute-force
// read.
const int64_t sub_file_pos = SI_tell(self);
- const int64_t real_file_pos = sub_file_pos + self->offset;
+ const int64_t real_file_pos = sub_file_pos + ivars->offset;
bool success
- = FH_Read(self->file_handle, buf, real_file_pos, len);
+ = FH_Read(ivars->file_handle, buf, real_file_pos, len);
if (!success) {
RETHROW(INCREF(Err_get_error()));
}
@@ -357,18 +372,20 @@ SI_read_bytes(InStream *self, char* buf, size_t len) {
int8_t
InStream_read_i8(InStream *self) {
- return (int8_t)SI_read_u8(self);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ return (int8_t)SI_read_u8(self, ivars);
}
static INLINE uint8_t
-SI_read_u8(InStream *self) {
- if (self->buf >= self->limit) { S_refill(self); }
- return (uint8_t)(*self->buf++);
+SI_read_u8(InStream *self, InStreamIVARS *ivars) {
+ if (ivars->buf >= ivars->limit) { S_refill(self); }
+ return (uint8_t)(*ivars->buf++);
}
uint8_t
InStream_read_u8(InStream *self) {
- return SI_read_u8(self);
+ InStreamIVARS *const ivars = InStream_IVARS(self);
+ return SI_read_u8(self, ivars);
}
static INLINE uint32_t
@@ -433,9 +450,10 @@ InStream_read_f64(InStream *self) {
uint32_t
InStream_read_c32(InStream *self) {
+ InStreamIVARS *const ivars = InStream_IVARS(self);
uint32_t retval = 0;
while (1) {
- const uint8_t ubyte = SI_read_u8(self);
+ const uint8_t ubyte = SI_read_u8(self, ivars);
retval = (retval << 7) | (ubyte & 0x7f);
if ((ubyte & 0x80) == 0) {
break;
@@ -446,9 +464,10 @@ InStream_read_c32(InStream *self) {
uint64_t
InStream_read_c64(InStream *self) {
+ InStreamIVARS *const ivars = InStream_IVARS(self);
uint64_t retval = 0;
while (1) {
- const uint8_t ubyte = SI_read_u8(self);
+ const uint8_t ubyte = SI_read_u8(self, ivars);
retval = (retval << 7) | (ubyte & 0x7f);
if ((ubyte & 0x80) == 0) {
break;
@@ -459,9 +478,10 @@ InStream_read_c64(InStream *self) {
int
InStream_read_raw_c64(InStream *self, char *buf) {
+ InStreamIVARS *const ivars = InStream_IVARS(self);
uint8_t *dest = (uint8_t*)buf;
do {
- *dest = SI_read_u8(self);
+ *dest = SI_read_u8(self, ivars);
} while ((*dest++ & 0x80) != 0);
return dest - (uint8_t*)buf;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/c02bb24e/core/Lucy/Store/Lock.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Store/Lock.c b/core/Lucy/Store/Lock.c
index 323b01d..6e8c68a 100644
--- a/core/Lucy/Store/Lock.c
+++ b/core/Lucy/Store/Lock.c
@@ -32,6 +32,8 @@
Lock*
Lock_init(Lock *self, Folder *folder, const CharBuf *name,
const CharBuf *host, int32_t timeout, int32_t interval) {
+ LockIVARS *const ivars = Lock_IVARS(self);
+
// Validate.
if (interval <= 0) {
DECREF(self);
@@ -52,51 +54,53 @@ Lock_init(Lock *self, Folder *folder, const CharBuf *name,
}
// Assign.
- self->folder = (Folder*)INCREF(folder);
- self->timeout = timeout;
- self->name = CB_Clone(name);
- self->host = CB_Clone(host);
- self->interval = interval;
+ ivars->folder = (Folder*)INCREF(folder);
+ ivars->timeout = timeout;
+ ivars->name = CB_Clone(name);
+ ivars->host = CB_Clone(host);
+ ivars->interval = interval;
// Derive.
- self->lock_path = CB_newf("locks/%o.lock", name);
+ ivars->lock_path = CB_newf("locks/%o.lock", name);
return self;
}
void
Lock_destroy(Lock *self) {
- DECREF(self->folder);
- DECREF(self->host);
- DECREF(self->name);
- DECREF(self->lock_path);
+ LockIVARS *const ivars = Lock_IVARS(self);
+ DECREF(ivars->folder);
+ DECREF(ivars->host);
+ DECREF(ivars->name);
+ DECREF(ivars->lock_path);
SUPER_DESTROY(self, LOCK);
}
CharBuf*
Lock_get_name(Lock *self) {
- return self->name;
+ return Lock_IVARS(self)->name;
}
CharBuf*
Lock_get_lock_path(Lock *self) {
- return self->lock_path;
+ return Lock_IVARS(self)->lock_path;
}
CharBuf*
Lock_get_host(Lock *self) {
- return self->host;
+ return Lock_IVARS(self)->host;
}
bool
Lock_obtain(Lock *self) {
- int32_t time_left = self->interval == 0 ? 0 : self->timeout;
+ LockIVARS *const ivars = Lock_IVARS(self);
+ int32_t time_left = ivars->interval == 0 ? 0 : ivars->timeout;
bool locked = Lock_Request(self);
while (!locked) {
- time_left -= self->interval;
+ time_left -= ivars->interval;
if (time_left <= 0) { break; }
- Sleep_millisleep(self->interval);
+ Sleep_millisleep(ivars->interval);
locked = Lock_Request(self);
}
@@ -118,7 +122,8 @@ LFLock_init(LockFileLock *self, Folder *folder, const CharBuf *name,
const CharBuf *host, int32_t timeout, int32_t interval) {
int pid = PID_getpid();
Lock_init((Lock*)self, folder, name, host, timeout, interval);
- self->link_path = CB_newf("%o.%o.%i64", self->lock_path, host, pid);
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
+ ivars->link_path = CB_newf("%o.%o.%i64", ivars->lock_path, host, pid);
return self;
}
@@ -129,26 +134,27 @@ LFLock_shared(LockFileLock *self) {
bool
LFLock_request(LockFileLock *self) {
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
Hash *file_data;
bool wrote_json;
bool success = false;
bool deletion_failed = false;
- if (Folder_Exists(self->folder, self->lock_path)) {
+ if (Folder_Exists(ivars->folder, ivars->lock_path)) {
Err_set_error((Err*)LockErr_new(CB_newf("Can't obtain lock: '%o' exists",
- self->lock_path)));
+ ivars->lock_path)));
return false;
}
// Create the "locks" subdirectory if necessary.
CharBuf *lock_dir_name = (CharBuf*)ZCB_WRAP_STR("locks", 5);
- if (!Folder_Exists(self->folder, lock_dir_name)) {
- if (!Folder_MkDir(self->folder, lock_dir_name)) {
+ if (!Folder_Exists(ivars->folder, lock_dir_name)) {
+ if (!Folder_MkDir(ivars->folder, lock_dir_name)) {
Err *mkdir_err = (Err*)CERTIFY(Err_get_error(), ERR);
LockErr *err = LockErr_new(CB_newf("Can't create 'locks' directory: %o",
Err_Get_Mess(mkdir_err)));
// Maybe our attempt failed because another process succeeded.
- if (Folder_Find_Folder(self->folder, lock_dir_name)) {
+ if (Folder_Find_Folder(ivars->folder, lock_dir_name)) {
DECREF(err);
}
else {
@@ -163,35 +169,35 @@ LFLock_request(LockFileLock *self) {
file_data = Hash_new(3);
Hash_Store_Str(file_data, "pid", 3,
(Obj*)CB_newf("%i32", (int32_t)PID_getpid()));
- Hash_Store_Str(file_data, "host", 4, INCREF(self->host));
- Hash_Store_Str(file_data, "name", 4, INCREF(self->name));
+ Hash_Store_Str(file_data, "host", 4, INCREF(ivars->host));
+ Hash_Store_Str(file_data, "name", 4, INCREF(ivars->name));
// Write to a temporary file, then use the creation of a hard link to
// ensure atomic but non-destructive creation of the lockfile with its
// complete contents.
- wrote_json = Json_spew_json((Obj*)file_data, self->folder, self->link_path);
+ wrote_json = Json_spew_json((Obj*)file_data, ivars->folder, ivars->link_path);
if (wrote_json) {
- success = Folder_Hard_Link(self->folder, self->link_path,
- self->lock_path);
+ success = Folder_Hard_Link(ivars->folder, ivars->link_path,
+ ivars->lock_path);
if (!success) {
Err *hard_link_err = (Err*)CERTIFY(Err_get_error(), ERR);
Err_set_error((Err*)LockErr_new(CB_newf("Failed to obtain lock at '%o': %o",
- self->lock_path,
+ ivars->lock_path,
Err_Get_Mess(hard_link_err))));
}
- deletion_failed = !Folder_Delete(self->folder, self->link_path);
+ deletion_failed = !Folder_Delete(ivars->folder, ivars->link_path);
}
else {
Err *spew_json_err = (Err*)CERTIFY(Err_get_error(), ERR);
Err_set_error((Err*)LockErr_new(CB_newf("Failed to obtain lock at '%o': %o",
- self->lock_path,
+ ivars->lock_path,
Err_Get_Mess(spew_json_err))));
}
DECREF(file_data);
// Verify that our temporary file got zapped.
if (wrote_json && deletion_failed) {
- CharBuf *mess = MAKE_MESS("Failed to delete '%o'", self->link_path);
+ CharBuf *mess = MAKE_MESS("Failed to delete '%o'", ivars->link_path);
Err_throw_mess(ERR, mess);
}
@@ -200,25 +206,29 @@ LFLock_request(LockFileLock *self) {
void
LFLock_release(LockFileLock *self) {
- if (Folder_Exists(self->folder, self->lock_path)) {
- LFLock_Maybe_Delete_File(self, self->lock_path, true, false);
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
+ if (Folder_Exists(ivars->folder, ivars->lock_path)) {
+ LFLock_Maybe_Delete_File(self, ivars->lock_path, true, false);
}
}
bool
LFLock_is_locked(LockFileLock *self) {
- return Folder_Exists(self->folder, self->lock_path);
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
+ return Folder_Exists(ivars->folder, ivars->lock_path);
}
void
LFLock_clear_stale(LockFileLock *self) {
- LFLock_Maybe_Delete_File(self, self->lock_path, false, true);
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
+ LFLock_Maybe_Delete_File(self, ivars->lock_path, false, true);
}
bool
LFLock_maybe_delete_file(LockFileLock *self, const CharBuf *path,
bool delete_mine, bool delete_other) {
- Folder *folder = self->folder;
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
+ Folder *folder = ivars->folder;
bool success = false;
ZombieCharBuf *scratch = ZCB_WRAP(path);
@@ -228,7 +238,7 @@ LFLock_maybe_delete_file(LockFileLock *self, const CharBuf *path,
return false;
}
ZCB_Nip(scratch, CB_Get_Size(lock_dir_name) + 1);
- if (!ZCB_Starts_With(scratch, self->name)) {
+ if (!ZCB_Starts_With(scratch, ivars->name)) {
return false;
}
@@ -243,9 +253,9 @@ LFLock_maybe_delete_file(LockFileLock *self, const CharBuf *path,
// Match hostname and lock name.
if (host != NULL
- && CB_Equals(host, (Obj*)self->host)
+ && CB_Equals(host, (Obj*)ivars->host)
&& name != NULL
- && CB_Equals(name, (Obj*)self->name)
+ && CB_Equals(name, (Obj*)ivars->name)
&& pid_buf != NULL
) {
// Verify that pid is either mine or dead.
@@ -273,7 +283,8 @@ LFLock_maybe_delete_file(LockFileLock *self, const CharBuf *path,
void
LFLock_destroy(LockFileLock *self) {
- DECREF(self->link_path);
+ LockFileLockIVARS *const ivars = LFLock_IVARS(self);
+ DECREF(ivars->link_path);
SUPER_DESTROY(self, LOCKFILELOCK);
}