mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Rename all uses of ivar eof_position.
([MemoryStream -_initOnMallocBuffer:freeWhenDone:size: eofPosition:prefix:position:]): Method name changed to include freeWhenDone:. Set new ivar. ([MemoryStream -_initOnMallocBuffer:size: eofPosition:prefix:position:]): New method (with old name) that calls above method with `YES' for freeWhenDone:. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1797 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
622edf4290
commit
85070e08f3
1 changed files with 42 additions and 21 deletions
|
@ -69,6 +69,7 @@ static BOOL debug_memory_stream = NO;
|
||||||
|
|
||||||
/* xxx This interface will change */
|
/* xxx This interface will change */
|
||||||
- _initOnMallocBuffer: (char*)b
|
- _initOnMallocBuffer: (char*)b
|
||||||
|
freeWhenDone: (BOOL)f
|
||||||
size: (unsigned)s /* size of malloc'ed buffer */
|
size: (unsigned)s /* size of malloc'ed buffer */
|
||||||
eofPosition: (unsigned)l /* length of buffer with data for reading */
|
eofPosition: (unsigned)l /* length of buffer with data for reading */
|
||||||
prefix: (unsigned)p /* never read/write before this position */
|
prefix: (unsigned)p /* never read/write before this position */
|
||||||
|
@ -79,11 +80,26 @@ static BOOL debug_memory_stream = NO;
|
||||||
size = s;
|
size = s;
|
||||||
prefix = p;
|
prefix = p;
|
||||||
position = i;
|
position = i;
|
||||||
eofPosition = l;
|
eof_position = l;
|
||||||
|
free_when_done = f;
|
||||||
type = MALLOC_MEMORY_STREAM;
|
type = MALLOC_MEMORY_STREAM;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- _initOnMallocBuffer: (char*)b
|
||||||
|
size: (unsigned)s /* size of malloc'ed buffer */
|
||||||
|
eofPosition: (unsigned)l /* length of buffer with data for reading */
|
||||||
|
prefix: (unsigned)p /* never read/write before this position */
|
||||||
|
position: (unsigned)i /* current position for reading/writing */
|
||||||
|
{
|
||||||
|
return [self _initOnMallocBuffer: b
|
||||||
|
freeWhenDone: YES
|
||||||
|
size: s
|
||||||
|
eofPosition: l
|
||||||
|
prefix: p
|
||||||
|
position: i]
|
||||||
|
}
|
||||||
|
|
||||||
/* xxx This method will disappear. */
|
/* xxx This method will disappear. */
|
||||||
- initWithSize: (unsigned)s
|
- initWithSize: (unsigned)s
|
||||||
prefix: (unsigned)p
|
prefix: (unsigned)p
|
||||||
|
@ -91,8 +107,12 @@ static BOOL debug_memory_stream = NO;
|
||||||
{
|
{
|
||||||
char *b;
|
char *b;
|
||||||
OBJC_MALLOC(b, char, s);
|
OBJC_MALLOC(b, char, s);
|
||||||
return [self _initOnMallocBuffer:b size:s eofPosition:i
|
return [self _initOnMallocBuffer:b
|
||||||
prefix:p position:i];
|
freeWhenDone: YES
|
||||||
|
size: s
|
||||||
|
eofPosition: i
|
||||||
|
prefix: p
|
||||||
|
position: i];
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithCapacity: (unsigned)capacity
|
- initWithCapacity: (unsigned)capacity
|
||||||
|
@ -143,15 +163,15 @@ static BOOL debug_memory_stream = NO;
|
||||||
}
|
}
|
||||||
memcpy(buffer+prefix+position, b, l);
|
memcpy(buffer+prefix+position, b, l);
|
||||||
position += l;
|
position += l;
|
||||||
if (position > eofPosition)
|
if (position > eof_position)
|
||||||
eofPosition = position;
|
eof_position = position;
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) readBytes: (void*)b length: (int)l
|
- (int) readBytes: (void*)b length: (int)l
|
||||||
{
|
{
|
||||||
if (position+l > eofPosition)
|
if (position+l > eof_position)
|
||||||
l = eofPosition-position;
|
l = eof_position-position;
|
||||||
memcpy(b, buffer+prefix+position, l);
|
memcpy(b, buffer+prefix+position, l);
|
||||||
position += l;
|
position += l;
|
||||||
return l;
|
return l;
|
||||||
|
@ -159,7 +179,7 @@ static BOOL debug_memory_stream = NO;
|
||||||
|
|
||||||
- (id <String>) readLine
|
- (id <String>) readLine
|
||||||
{
|
{
|
||||||
char *nl = memchr(buffer+prefix+position, '\n', eofPosition-position);
|
char *nl = memchr(buffer+prefix+position, '\n', eof_position-position);
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
if (nl)
|
if (nl)
|
||||||
{
|
{
|
||||||
|
@ -219,8 +239,8 @@ void unchar_func(void *s, int c)
|
||||||
128 bytes left in the buffer and we try to write a string longer than
|
128 bytes left in the buffer and we try to write a string longer than
|
||||||
the num bytes left in the buffer. */
|
the num bytes left in the buffer. */
|
||||||
assert(prefix + position <= size);
|
assert(prefix + position <= size);
|
||||||
if (position > eofPosition)
|
if (position > eof_position)
|
||||||
eofPosition = position;
|
eof_position = position;
|
||||||
if (debug_memory_stream)
|
if (debug_memory_stream)
|
||||||
{
|
{
|
||||||
*(buffer+prefix+position) = '\0';
|
*(buffer+prefix+position) = '\0';
|
||||||
|
@ -253,7 +273,7 @@ void unchar_func(void *s, int c)
|
||||||
position += i;
|
position += i;
|
||||||
break;
|
break;
|
||||||
case STREAM_SEEK_FROM_END:
|
case STREAM_SEEK_FROM_END:
|
||||||
position = eofPosition + i;
|
position = eof_position + i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,13 +290,14 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
if (free_when_done)
|
||||||
OBJC_FREE(buffer);
|
OBJC_FREE(buffer);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) streamEof
|
- (BOOL) streamEof
|
||||||
{
|
{
|
||||||
if (position == eofPosition)
|
if (position == eof_position)
|
||||||
return YES;
|
return YES;
|
||||||
else
|
else
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -294,7 +315,7 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (void) setStreamBufferCapacity: (unsigned)s
|
- (void) setStreamBufferCapacity: (unsigned)s
|
||||||
{
|
{
|
||||||
if (s > prefix + eofPosition)
|
if (s > prefix + eof_position)
|
||||||
{
|
{
|
||||||
buffer = objc_realloc (buffer, s);
|
buffer = objc_realloc (buffer, s);
|
||||||
size = s;
|
size = s;
|
||||||
|
@ -303,13 +324,13 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (unsigned) streamEofPosition
|
- (unsigned) streamEofPosition
|
||||||
{
|
{
|
||||||
return eofPosition;
|
return eof_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setStreamEofPosition: (unsigned)i
|
- (void) setStreamEofPosition: (unsigned)i
|
||||||
{
|
{
|
||||||
if (i < size)
|
if (i < size)
|
||||||
eofPosition = i;
|
eof_position = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned) streamBufferPrefix
|
- (unsigned) streamBufferPrefix
|
||||||
|
@ -319,7 +340,7 @@ void unchar_func(void *s, int c)
|
||||||
|
|
||||||
- (unsigned) streamBufferLength
|
- (unsigned) streamBufferLength
|
||||||
{
|
{
|
||||||
return prefix + eofPosition;
|
return prefix + eof_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue