Skip to content

Commit

Permalink
BUG: Fix parser field type compatability on 32-bit systems. (pandas-d…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffknupp authored and alanbato committed Nov 10, 2017
1 parent a894ee9 commit 19e7511
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions pandas/_libs/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ int parser_init(parser_t *self) {
sz = STREAM_INIT_SIZE / 10;
sz = sz ? sz : 1;
self->words = (char **)malloc(sz * sizeof(char *));
self->word_starts = (size_t *)malloc(sz * sizeof(size_t));
self->word_starts = (int64_t *)malloc(sz * sizeof(int64_t));
self->words_cap = sz;
self->words_len = 0;

// line pointers and metadata
self->line_start = (size_t *)malloc(sz * sizeof(size_t));
self->line_start = (int64_t *)malloc(sz * sizeof(int64_t));

self->line_fields = (size_t *)malloc(sz * sizeof(size_t));
self->line_fields = (int64_t *)malloc(sz * sizeof(int64_t));

self->lines_cap = sz;
self->lines = 0;
Expand Down Expand Up @@ -247,7 +247,7 @@ void parser_del(parser_t *self) {
}

static int make_stream_space(parser_t *self, size_t nbytes) {
size_t i, cap;
int64_t i, cap;
int status;
void *orig_ptr, *newptr;

Expand Down Expand Up @@ -419,7 +419,7 @@ static void append_warning(parser_t *self, const char *msg) {

static int end_line(parser_t *self) {
char *msg;
int fields;
int64_t fields;
int ex_fields = self->expected_fields;
size_t bufsize = 100; // for error or warning messages

Expand Down Expand Up @@ -468,8 +468,8 @@ static int end_line(parser_t *self) {
if (self->error_bad_lines) {
self->error_msg = (char *)malloc(bufsize);
snprintf(self->error_msg, bufsize,
"Expected %d fields in line %d, saw %d\n",
ex_fields, self->file_lines, fields);
"Expected %d fields in line %lld, saw %lld\n",
ex_fields, (long long)self->file_lines, (long long)fields);

TRACE(("Error at line %d, %d fields\n", self->file_lines, fields));

Expand All @@ -480,8 +480,9 @@ static int end_line(parser_t *self) {
// pass up error message
msg = (char *)malloc(bufsize);
snprintf(msg, bufsize,
"Skipping line %d: expected %d fields, saw %d\n",
self->file_lines, ex_fields, fields);
"Skipping line %lld: expected %d fields, saw %lld\n",
(long long)self->file_lines, ex_fields,
(long long)fields);
append_warning(self, msg);
free(msg);
}
Expand Down Expand Up @@ -632,7 +633,7 @@ static int parser_buffer_bytes(parser_t *self, size_t nbytes) {
stream = self->stream + self->stream_len; \
slen = self->stream_len; \
self->state = STATE; \
if (line_limit > 0 && self->lines == start_lines + (size_t)line_limit) { \
if (line_limit > 0 && self->lines == start_lines + (int64_t)line_limit) { \
goto linelimit; \
}

Expand All @@ -647,7 +648,7 @@ static int parser_buffer_bytes(parser_t *self, size_t nbytes) {
stream = self->stream + self->stream_len; \
slen = self->stream_len; \
self->state = STATE; \
if (line_limit > 0 && self->lines == start_lines + (size_t)line_limit) { \
if (line_limit > 0 && self->lines == start_lines + (int64_t)line_limit) { \
goto linelimit; \
}

Expand Down Expand Up @@ -1147,7 +1148,8 @@ static int parser_handle_eof(parser_t *self) {
case IN_QUOTED_FIELD:
self->error_msg = (char *)malloc(bufsize);
snprintf(self->error_msg, bufsize,
"EOF inside string starting at line %d", self->file_lines);
"EOF inside string starting at line %lld",
(long long)self->file_lines);
return -1;

case ESCAPED_CHAR:
Expand Down Expand Up @@ -1318,7 +1320,7 @@ void debug_print_parser(parser_t *self) {
char *token;

for (line = 0; line < self->lines; ++line) {
printf("(Parsed) Line %d: ", line);
printf("(Parsed) Line %lld: ", (long long)line);

for (j = 0; j < self->line_fields[j]; ++j) {
token = self->words[j + self->line_start[line]];
Expand Down

0 comments on commit 19e7511

Please sign in to comment.