Skip to content

Commit

Permalink
Replace ssize_t with int64_t everywhere (since we won't support 32bit…
Browse files Browse the repository at this point in the history
… platforms)
  • Loading branch information
st-pasha committed May 10, 2017
1 parent 3906968 commit 3ede86a
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 129 deletions.
8 changes: 4 additions & 4 deletions c/colmapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


ColMapping*
ColMapping_from_array(ssize_t *array, ssize_t length, DataTable *dt)
ColMapping_from_array(int64_t *array, int64_t length, DataTable *dt)
{
ColMapping *res = malloc(sizeof(ColMapping));
if (res == NULL) return NULL;
Expand All @@ -12,7 +12,7 @@ ColMapping_from_array(ssize_t *array, ssize_t length, DataTable *dt)
res->stypes = malloc(sizeof(SType) * (size_t)length);
if (res->stypes == NULL) goto fail;
Column **columns = dt->columns;
for (ssize_t i = 0; i < length; i++) {
for (int64_t i = 0; i < length; i++) {
res->stypes[i] = columns[array[i]]->stype;
}
return res;
Expand All @@ -24,12 +24,12 @@ ColMapping_from_array(ssize_t *array, ssize_t length, DataTable *dt)


/*
ColMapping* ColMapping_alloc(ssize_t length)
ColMapping* ColMapping_alloc(int64_t length)
{
ColMapping *res = malloc(sizeof(ColMapping));
if (res == NULL) return NULL;
res->length = length;
res->indices = malloc(sizeof(ssize_t) * length);
res->indices = malloc(sizeof(int64_t) * length);
res->coltypes = malloc(sizeof(LType) * length);
if (res->indices == NULL || res->coltypes == NULL) goto fail;
return res;
Expand Down
8 changes: 4 additions & 4 deletions c/colmapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


typedef struct ColMapping {
ssize_t length;
ssize_t *indices;
int64_t length;
int64_t *indices;
SType *stypes;
} ColMapping;


ColMapping* ColMapping_from_array(ssize_t *array, ssize_t len, DataTable *dt);
// ColMapping* ColMapping_alloc(ssize_t length);
ColMapping* ColMapping_from_array(int64_t *array, int64_t len, DataTable *dt);
// ColMapping* ColMapping_alloc(int64_t length);
void ColMapping_dealloc(ColMapping *colmapping);


Expand Down
6 changes: 3 additions & 3 deletions c/column.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ Column* column_extract(Column *col, RowMapping *rowmapping)
// the required elements manually.
switch (stype) {
#define JINIT_SLICE \
ssize_t start = rowmapping->slice.start; \
ssize_t step = rowmapping->slice.step; \
ssize_t j = start - step;
int64_t start = rowmapping->slice.start; \
int64_t step = rowmapping->slice.step; \
int64_t j = start - step;
#define JITER_SLICE \
j += step;
#define JINIT_ARR(bits) \
Expand Down
9 changes: 4 additions & 5 deletions c/datatable.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
DataTable* dt_DataTable_call(
DataTable *self, RowMapping *rowmapping, ColMapping *colmapping)
{
ssize_t ncols = colmapping->length;
ssize_t nrows = rowmapping->length;
int64_t ncols = colmapping->length;
int64_t nrows = rowmapping->length;

// Computed on-demand only if we detect that it is needed
RowMapping *merged_rowindex = NULL;

Column **columns = calloc(sizeof(Column*), (size_t)ncols);
if (columns == NULL) return NULL;

for (ssize_t i = 0; i < ncols; ++i) {
ssize_t j = colmapping->indices[i];
for (int64_t i = 0; i < ncols; ++i) {
int64_t j = colmapping->indices[i];
Column *colj = self->columns[j];
if (colj->mtype == MT_VIEW) {
if (merged_rowindex == NULL) {
Expand Down Expand Up @@ -64,7 +64,6 @@ DataTable* dt_DataTable_call(




/**
* Free memory occupied by the :class:`DataTable` object. This function should
* be called from `DataTable_PyObject`s deallocator only.
Expand Down
4 changes: 2 additions & 2 deletions c/datatable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ typedef struct DataTable DataTable;
* which determines the actual struct type.
*/
typedef struct DataTable {
ssize_t nrows;
ssize_t ncols;
int64_t nrows;
int64_t ncols;
DataTable *source;
RowMapping *rowmapping;
Column **columns;
Expand Down
10 changes: 5 additions & 5 deletions c/datatablemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PyObject *dt_from_memmap(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
return NULL;

ssize_t ncols = PyList_Size(list);
int64_t ncols = PyList_Size(list);

DataTable *dt = malloc(sizeof(DataTable));
if (dt == NULL) return NULL;
Expand All @@ -34,7 +34,7 @@ PyObject *dt_from_memmap(PyObject *self, PyObject *args)
dt->columns = malloc(sizeof(Column) * (size_t)ncols);
if (dt->columns == NULL) return NULL;

ssize_t nrows = -1;
int64_t nrows = -1;
for (int i = 0; i < ncols; i++) {
PyObject *item = PyList_GetItem(list, i);
char *colname = PyUnicode_AsUTF8(item);
Expand Down Expand Up @@ -85,7 +85,7 @@ PyObject *dt_from_memmap(PyObject *self, PyObject *args)
// After memory-mapping the file, its descriptor is no longer needed
close(fd);

ssize_t nelems = (ssize_t)filesize / (ssize_t)elemsize;
int64_t nelems = (int64_t)filesize / (int64_t)elemsize;
if (nrows == -1)
nrows = nelems;
else if (nrows != nelems) {
Expand Down Expand Up @@ -156,8 +156,8 @@ static PyModuleDef datatablemodule = {
0,0,0,0,
};

static_assert(sizeof(ssize_t) == sizeof(Py_ssize_t),
"ssize_t and Py_ssize_t should refer to the same type");
static_assert(sizeof(int64_t) == sizeof(Py_ssize_t),
"int64_t and Py_ssize_t should refer to the same type");

/* Called when Python program imports the module */
PyMODINIT_FUNC
Expand Down
8 changes: 4 additions & 4 deletions c/fread_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static char *filename = NULL;
static char *input = NULL;
static char **na_strings = NULL;

static ssize_t ncols = 0;
static int64_t ncols = 0;
static int8_t *types = NULL;
static int8_t *sizes = NULL;
static StrBuf **strbufs = NULL;
Expand Down Expand Up @@ -120,7 +120,7 @@ void cleanup_fread_session(freadMainArgs *frargs) {
Py_XDECREF(frargs->freader);
}
if (strbufs) {
for (ssize_t i = 0; i < ncols; i++) {
for (int64_t i = 0; i < ncols; i++) {
if (strbufs[i]) {
free(strbufs[i]->buf);
free(strbufs[i]);
Expand Down Expand Up @@ -159,7 +159,7 @@ size_t allocateDT(int8_t *types_, int8_t *sizes_, int ncols_, int ndrop,
int64_t nrows) {
types = types_;
sizes = sizes_;
ncols = (ssize_t) ncols_;
ncols = (int64_t) ncols_;

if (nrows > INTPTR_MAX) {
PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -199,7 +199,7 @@ size_t allocateDT(int8_t *types_, int8_t *sizes_, int ncols_, int ndrop,
}

dt = malloc(sizeof(DataTable));
dt->nrows = (ssize_t) nrows;
dt->nrows = (int64_t) nrows;
dt->ncols = ncols - ndrop;
dt->source = NULL;
dt->rowmapping = NULL;
Expand Down
8 changes: 4 additions & 4 deletions c/py_colmapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ ColMapping_PyObject* ColMappingPy_from_array(PyObject *self, PyObject *args)
DataTable_PyObject *dt;
ColMapping *colmapping = NULL;
ColMapping_PyObject *res = NULL;
ssize_t *data = NULL;
int64_t *data = NULL;

// Unpack arguments and check their validity
if (!PyArg_ParseTuple(args, "O!O!:ColMapping.from_array",
&PyList_Type, &list, &DataTable_PyType, &dt))
return NULL;

// Convert Pythonic List into a regular C array of longs
ssize_t len = PyList_Size(list);
data = MALLOC(sizeof(ssize_t) * (size_t)len);
for (ssize_t i = 0; i < len; ++i) {
int64_t len = PyList_Size(list);
data = MALLOC(sizeof(int64_t) * (size_t)len);
for (int64_t i = 0; i < len; ++i) {
data[i] = PyLong_AsSsize_t(PyList_GET_ITEM(list, i));
}

Expand Down
2 changes: 1 addition & 1 deletion c/py_datatable.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ PyObject* write_column_to_file(PyObject *self, PyObject *args)
const void *ptr = col->data;
while (bytes_written < total_size) {
int64_t nbytes = min(total_size - bytes_written, buff_size);
ssize_t written = write(fd, ptr, (size_t)nbytes);
int64_t written = write(fd, ptr, (size_t)nbytes);
if (written <= 0) {
PyErr_Format(PyExc_RuntimeError,
"Error %d when writing to file", errno);
Expand Down
8 changes: 4 additions & 4 deletions c/py_datatable_fromlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ pyDataTable_from_list_of_lists(PyTypeObject *type, PyObject *args)
dt->ncols = 0;

// If the supplied list is empty, return the empty Datatable object
ssize_t listsize = Py_SIZE(list); // works both for lists and tuples
int64_t listsize = Py_SIZE(list); // works both for lists and tuples
if (listsize == 0) {
return pyDataTable_from_DataTable(dt);
}

// Basic check validity of the provided data.
ssize_t item0size = Py_SIZE(PyList_GET_ITEM(list, 0));
for (ssize_t i = 0; i < listsize; ++i) {
int64_t item0size = Py_SIZE(PyList_GET_ITEM(list, 0));
for (int64_t i = 0; i < listsize; ++i) {
PyObject *item = PyList_GET_ITEM(list, i);
if (!PyList_Check(item)) {
PyErr_SetString(PyExc_ValueError,
Expand All @@ -64,7 +64,7 @@ pyDataTable_from_list_of_lists(PyTypeObject *type, PyObject *args)
dt->columns = CALLOC(sizeof(Column), dt->ncols);

// Fill the data
for (ssize_t i = 0; i < dt->ncols; i++) {
for (int64_t i = 0; i < dt->ncols; i++) {
PyObject *src = PyList_GET_ITEM(list, i);
dt->columns[i] = TRY(column_from_list(src));
}
Expand Down
28 changes: 14 additions & 14 deletions c/py_datawindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "py_types.h"

// Forward declarations
static int _check_consistency(DataTable *dt, ssize_t row0, ssize_t row1,
ssize_t col0, ssize_t col1);
static int _check_consistency(DataTable *dt, int64_t row0, int64_t row1,
int64_t col0, int64_t col1);

int init_py_datawindow(PyObject *module)
{
Expand Down Expand Up @@ -38,7 +38,7 @@ static int __init__(DataWindow_PyObject *self, PyObject *args, PyObject *kwds)
DataTable *dt;
PyObject *stypes = NULL, *ltypes = NULL, *view = NULL;
int n_init_cols = 0;
ssize_t row0, row1, col0, col1;
int64_t row0, row1, col0, col1;

// Parse arguments and check their validity
static char *kwlist[] = {"dt", "row0", "row1", "col0", "col1", NULL};
Expand All @@ -50,14 +50,14 @@ static int __init__(DataWindow_PyObject *self, PyObject *args, PyObject *kwds)
return -1;

// Window dimensions
ssize_t ncols = col1 - col0;
ssize_t nrows = row1 - row0;
int64_t ncols = col1 - col0;
int64_t nrows = row1 - row0;

// Create and fill-in the `stypes` list
stypes = PyList_New((Py_ssize_t) ncols);
ltypes = PyList_New((Py_ssize_t) ncols);
if (stypes == NULL || ltypes == NULL) goto fail;
for (ssize_t i = col0; i < col1; i++) {
for (int64_t i = col0; i < col1; i++) {
Column *column = dt->columns[i];
SType stype = column->stype;
LType ltype = stype_info[stype].ltype;
Expand All @@ -71,13 +71,13 @@ static int __init__(DataWindow_PyObject *self, PyObject *args, PyObject *kwds)
int rindex_is_slice = rindex && rindex->type == RM_SLICE;
int32_t *rindexarr32 = rindex_is_arr32? rindex->ind32 : NULL;
int64_t *rindexarr64 = rindex_is_arr64? rindex->ind64 : NULL;
ssize_t rindexstart = rindex_is_slice? rindex->slice.start : 0;
ssize_t rindexstep = rindex_is_slice? rindex->slice.step : 0;
int64_t rindexstart = rindex_is_slice? rindex->slice.start : 0;
int64_t rindexstep = rindex_is_slice? rindex->slice.step : 0;

// Create and fill-in the `data` list
view = PyList_New((Py_ssize_t) ncols);
if (view == NULL) goto fail;
for (ssize_t i = col0; i < col1; ++i) {
for (int64_t i = col0; i < col1; ++i) {
Column *column = dt->columns[i];
void *coldata = column->data;
int isdata = (column->mtype != MT_VIEW);
Expand All @@ -91,10 +91,10 @@ static int __init__(DataWindow_PyObject *self, PyObject *args, PyObject *kwds)
PyList_SET_ITEM(view, n_init_cols++, py_coldata);

int n_init_rows = 0;
for (ssize_t j = row0; j < row1; ++j) {
ssize_t irow = isdata? j :
for (int64_t j = row0; j < row1; ++j) {
int64_t irow = isdata? j :
rindex_is_arr32? rindexarr32[j] :
rindex_is_arr64? (ssize_t) rindexarr64[j] :
rindex_is_arr64? (int64_t) rindexarr64[j] :
rindexstart + rindexstep * j;
PyObject *value = py_stype_formatters[column->stype](column, irow);
if (value == NULL) goto fail;
Expand Down Expand Up @@ -134,7 +134,7 @@ static int __init__(DataWindow_PyObject *self, PyObject *args, PyObject *kwds)
* :returns: 1 on success, 0 on failure
*/
static int _check_consistency(
DataTable *dt, ssize_t row0, ssize_t row1, ssize_t col0, ssize_t col1)
DataTable *dt, int64_t row0, int64_t row1, int64_t col0, int64_t col1)
{
// check correctness of the data window
if (col0 < 0 || col1 < col0 || col1 > dt->ncols ||
Expand Down Expand Up @@ -175,7 +175,7 @@ static int _check_consistency(
rindex->length, dt->nrows);
return 0;
}
for (ssize_t j = row0; j < row1; ++j) {
for (int64_t j = row0; j < row1; ++j) {
int32_t jsrc = rindex->ind32[j];
if (jsrc < 0 || jsrc >= dt->source->nrows) {
PyErr_Format(PyExc_RuntimeError,
Expand Down
2 changes: 1 addition & 1 deletion c/py_evaluator.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static PyObject* get_stack_value(Evaluator_PyObject *self, PyObject *args)
case 258: {
int64_t n = v.i8;
int64_t *arr = (int64_t*) self->stack[idx + 1].ptr;
RowMapping *rwm = rowmapping_from_i64_array(arr, (ssize_t)n);
RowMapping *rwm = rowmapping_from_i64_array(arr, (int64_t)n);
return (PyObject*) RowMappingPy_from_rowmapping(rwm);
}
default:
Expand Down
Loading

0 comments on commit 3ede86a

Please sign in to comment.