|
|
@@ -19,10 +19,12 @@ |
|
|
|
|
|
|
|
typedef int64_t timestamp_t; |
|
|
|
|
|
|
|
/* This code probably needs to be double-checked for the case |
|
|
|
where sizeof(long) != 8, so enforce that here with something |
|
|
|
that will fail at build time. */ |
|
|
|
const static char __long_ok[1 - 2*!(sizeof(int64_t) == sizeof(long))] = { 0 }; |
|
|
|
/* This code probably needs to be double-checked for the case where |
|
|
|
sizeof(long) != 8, so enforce that here with something that will |
|
|
|
fail at build time. We assume that the python integer type can |
|
|
|
hold an int64_t. */ |
|
|
|
const static char __long_ok[1 - 2*!(sizeof(int64_t) == |
|
|
|
sizeof(long int))] = { 0 }; |
|
|
|
|
|
|
|
/* Somewhat arbitrary, just so we can use fixed sizes for strings |
|
|
|
etc. */ |
|
|
@@ -56,7 +58,7 @@ static PyObject *raise_str(int line, int col, int code, const char *string) |
|
|
|
static PyObject *raise_int(int line, int col, int code, int64_t num) |
|
|
|
{ |
|
|
|
PyObject *o; |
|
|
|
o = Py_BuildValue("(iiiL)", line, col, code, num); |
|
|
|
o = Py_BuildValue("(iiil)", line, col, code, num); |
|
|
|
if (o != NULL) { |
|
|
|
PyErr_SetObject(ParseError, o); |
|
|
|
Py_DECREF(o); |
|
|
@@ -278,7 +280,7 @@ static PyObject *Rocket_append_string(Rocket *self, PyObject *args) |
|
|
|
but we need the null termination for strto*. If we had |
|
|
|
strnto* that took a length, we could use t# and not require |
|
|
|
a copy. */ |
|
|
|
if (!PyArg_ParseTuple(args, "isiiLLL:append_string", &count, |
|
|
|
if (!PyArg_ParseTuple(args, "isiilll:append_string", &count, |
|
|
|
&data, &offset, &linenum, |
|
|
|
&start, &end, &last_timestamp)) |
|
|
|
return NULL; |
|
|
@@ -392,10 +394,10 @@ static PyObject *Rocket_append_string(Rocket *self, PyObject *args) |
|
|
|
|
|
|
|
fflush(self->file); |
|
|
|
|
|
|
|
/* Build return value and return*/ |
|
|
|
/* Build return value and return */ |
|
|
|
offset = buf - data; |
|
|
|
PyObject *o; |
|
|
|
o = Py_BuildValue("(iiLi)", written, offset, last_timestamp, linenum); |
|
|
|
o = Py_BuildValue("(iili)", written, offset, last_timestamp, linenum); |
|
|
|
return o; |
|
|
|
err: |
|
|
|
PyErr_SetFromErrno(PyExc_OSError); |
|
|
@@ -525,6 +527,33 @@ err: |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**** |
|
|
|
* Extract timestamp |
|
|
|
*/ |
|
|
|
static PyObject *Rocket_extract_timestamp(Rocket *self, PyObject *args) |
|
|
|
{ |
|
|
|
long offset; |
|
|
|
union64_t t64; |
|
|
|
if (!PyArg_ParseTuple(args, "l", &offset)) |
|
|
|
return NULL; |
|
|
|
if (!self->file) { |
|
|
|
PyErr_SetString(PyExc_Exception, "no file"); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
/* Seek to target location and read timestamp */ |
|
|
|
if ((fseek(self->file, offset, SEEK_SET) < 0) || |
|
|
|
(fread(&t64.u, 8, 1, self->file) != 1)) { |
|
|
|
PyErr_SetFromErrno(PyExc_OSError); |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
/* Convert and return */ |
|
|
|
t64.u = le64toh(t64.u); |
|
|
|
return Py_BuildValue("l", t64.i); |
|
|
|
} |
|
|
|
|
|
|
|
/**** |
|
|
|
* Module and type setup |
|
|
|
*/ |
|
|
@@ -571,6 +600,11 @@ static PyMethodDef Rocket_methods[] = { |
|
|
|
"Extract count rows of data from the file at offset offset.\n" |
|
|
|
"Return an ascii formatted string according to the layout" }, |
|
|
|
|
|
|
|
{ "extract_timestamp", |
|
|
|
(PyCFunction)Rocket_extract_timestamp, METH_VARARGS, |
|
|
|
"extract_timestamp(self, offset)\n\n" |
|
|
|
"Extract a single timestamp from the file" }, |
|
|
|
|
|
|
|
{ NULL }, |
|
|
|
}; |
|
|
|
|
|
|
|