-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add readEOS flag to BlobReader and BlobIO so that EOF read logic work… #538
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,25 +78,33 @@ class BlobReader | |
const uint8_t* data; | ||
size_t data_array_size; | ||
size_t seek_pos; | ||
bool readEOS; | ||
public: | ||
const int EOS = -1; | ||
|
||
BlobReader(const uint8_t* _data, size_t _data_array_size) | ||
: data(_data) | ||
, data_array_size(_data_array_size) | ||
, seek_pos(0) | ||
, readEOS(false) | ||
{ | ||
} | ||
|
||
bool isEOF() const { | ||
return seek_pos >= data_array_size; | ||
if(readEOS) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
long ftell() const { | ||
return seek_pos; | ||
} | ||
int get_c() { | ||
if(seek_pos >= data_array_size) | ||
if(seek_pos >= data_array_size) { | ||
readEOS = true; | ||
return EOS; | ||
} | ||
return data[seek_pos++]; | ||
} | ||
char * gets(char *buf, int n) { | ||
|
@@ -106,16 +114,19 @@ class BlobReader | |
buf[i++] = data[seek_pos++]; | ||
buf[n-1] = '\0'; | ||
|
||
if(i < max_write) | ||
if(i < max_write) { | ||
readEOS = true; | ||
return 0; | ||
else | ||
} else { | ||
return buf; | ||
} | ||
} | ||
int fputc(int FLIF_UNUSED(c)) { | ||
// cannot write on const memory | ||
return EOS; | ||
} | ||
void fseek(long offset, int where) { | ||
readEOS = false; | ||
switch(where) { | ||
case SEEK_SET: | ||
seek_pos = offset; | ||
|
@@ -146,8 +157,10 @@ class BlobIO | |
// keeps track how many bytes were written | ||
size_t bytes_used; | ||
size_t seek_pos; | ||
bool readEOS; | ||
|
||
void grow(size_t necessary_size) { | ||
readEOS = false; | ||
if(necessary_size < data_array_size) | ||
return; | ||
|
||
|
@@ -177,6 +190,7 @@ class BlobIO | |
, data_array_size(0) | ||
, bytes_used(0) | ||
, seek_pos(0) | ||
, readEOS(false) | ||
{ | ||
} | ||
|
||
|
@@ -200,14 +214,20 @@ class BlobIO | |
// nothing to do | ||
} | ||
bool isEOF() const { | ||
return seek_pos >= bytes_used; | ||
if(readEOS) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also be simplified (identical to line 94). |
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
int ftell() const { | ||
long ftell() const { | ||
return seek_pos; | ||
} | ||
int get_c() { | ||
if(seek_pos >= bytes_used) | ||
if(seek_pos >= bytes_used) { | ||
readEOS = true; | ||
return EOS; | ||
} | ||
return data[seek_pos++]; | ||
} | ||
char * gets(char *buf, int n) { | ||
|
@@ -217,10 +237,12 @@ class BlobIO | |
buf[i++] = data[seek_pos++]; | ||
buf[n-1] = '\0'; | ||
|
||
if(i < max_write) | ||
if(i < max_write) { | ||
readEOS = true; | ||
return 0; | ||
else | ||
} else { | ||
return buf; | ||
} | ||
} | ||
int fputs(const char *s) { | ||
size_t i = 0; | ||
|
@@ -243,6 +265,7 @@ class BlobIO | |
return c; | ||
} | ||
void fseek(long offset, int where) { | ||
readEOS = false; | ||
switch(where) { | ||
case SEEK_SET: | ||
seek_pos = offset; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to
return readEOS;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the form you describe makes it more difficult to actually debug the code when a developer wants to set a breakpoint that would get hit only in the EOF returns true case. By actually writing out the if block, the code can then be debugged with a breakpoint as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that most debuggers like gdb let you set conditional breakpoints for this purpose.