// Helper functions for write_* and update_* since they do almost the same thing. static PyObject* _cdb_write_or_update_records(PyObject* self, PyObject* list, int type) { int len = PyList_Size(list); uint64_t i = 0; uint64_t cnt = 0; bool ret = false; cdb_t *cdb = ((StorageObject*)self)->cdb; cdb_record_t *records = alloca(sizeof(cdb_record_t) * len); // Turn any None's into NaN for (i = 0; i < len; i++) { PyObject* record = PyList_GetItem(list, i); PyObject* value = PyList_GetItem(record, 1); records[i].time = _parse_time(PyList_GetItem(record, 0)); records[i].value = (value == Py_None ? CDB_NAN : PyFloat_AsDouble(value)); } if (type == PY_CDB_WRITE) { ret = cdb_write_records(cdb, records, len, &cnt); } else { ret = cdb_update_records(cdb, records, len, &cnt); } if (ret != CDB_SUCCESS) { return PyErr_SetFromErrno(PyExc_IOError); } _cdb_py_update_header(self, cdb); return PyInt_FromLong(cnt); }
bool cdb_write_record(cdb_t *cdb, cdb_time_t time, double value) { cdb_record_t record[RECORD_SIZE]; uint64_t num_recs = 0; record->time = time; record->value = value; if (cdb_write_records(cdb, record, 1, &num_recs) != CDB_SUCCESS) { return false; } return true; }