|
@@ -71,7 +71,7 @@ __reduce_persist__(PyObject *self, PyObject *pickler) const {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// First, streamify the object, if possible.
|
|
// First, streamify the object, if possible.
|
|
|
- string bam_stream;
|
|
|
|
|
|
|
+ vector_uchar bam_stream;
|
|
|
if (!_this->encode_to_bam_stream(bam_stream, writer)) {
|
|
if (!_this->encode_to_bam_stream(bam_stream, writer)) {
|
|
|
ostringstream stream;
|
|
ostringstream stream;
|
|
|
stream << "Could not bamify object of type " << _this->get_type() << "\n";
|
|
stream << "Could not bamify object of type " << _this->get_type() << "\n";
|
|
@@ -101,7 +101,6 @@ __reduce_persist__(PyObject *self, PyObject *pickler) const {
|
|
|
} else {
|
|
} else {
|
|
|
// The traditional pickle support: call the non-persistent version of this
|
|
// The traditional pickle support: call the non-persistent version of this
|
|
|
// function.
|
|
// function.
|
|
|
-
|
|
|
|
|
func = find_global_decode(this_class, "py_decode_TypedWritable_from_bam_stream");
|
|
func = find_global_decode(this_class, "py_decode_TypedWritable_from_bam_stream");
|
|
|
if (func == NULL) {
|
|
if (func == NULL) {
|
|
|
PyErr_SetString(PyExc_TypeError, "Couldn't find py_decode_TypedWritable_from_bam_stream()");
|
|
PyErr_SetString(PyExc_TypeError, "Couldn't find py_decode_TypedWritable_from_bam_stream()");
|
|
@@ -110,14 +109,15 @@ __reduce_persist__(PyObject *self, PyObject *pickler) const {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
- PyObject *result = Py_BuildValue("(O(Oy#))", func, this_class, bam_stream.data(), (Py_ssize_t) bam_stream.size());
|
|
|
|
|
-#else
|
|
|
|
|
- PyObject *result = Py_BuildValue("(O(Os#))", func, this_class, bam_stream.data(), (Py_ssize_t) bam_stream.size());
|
|
|
|
|
-#endif
|
|
|
|
|
- Py_DECREF(func);
|
|
|
|
|
- Py_DECREF(this_class);
|
|
|
|
|
- return result;
|
|
|
|
|
|
|
+ // PyTuple_SET_ITEM conveniently borrows the reference it is passed.
|
|
|
|
|
+ PyObject *args = PyTuple_New(2);
|
|
|
|
|
+ PyTuple_SET_ITEM(args, 0, this_class);
|
|
|
|
|
+ PyTuple_SET_ITEM(args, 1, Dtool_WrapValue(bam_stream));
|
|
|
|
|
+
|
|
|
|
|
+ PyObject *tuple = PyTuple_New(2);
|
|
|
|
|
+ PyTuple_SET_ITEM(tuple, 0, func);
|
|
|
|
|
+ PyTuple_SET_ITEM(tuple, 1, args);
|
|
|
|
|
+ return tuple;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -131,7 +131,8 @@ __reduce_persist__(PyObject *self, PyObject *pickler) const {
|
|
|
*/
|
|
*/
|
|
|
PyObject *Extension<TypedWritable>::
|
|
PyObject *Extension<TypedWritable>::
|
|
|
find_global_decode(PyObject *this_class, const char *func_name) {
|
|
find_global_decode(PyObject *this_class, const char *func_name) {
|
|
|
- PyObject *module_name = PyObject_GetAttrString(this_class, "__module__");
|
|
|
|
|
|
|
+ // Get the module in which BamWriter is defined.
|
|
|
|
|
+ PyObject *module_name = PyObject_GetAttrString((PyObject *)&Dtool_BamWriter, "__module__");
|
|
|
if (module_name != NULL) {
|
|
if (module_name != NULL) {
|
|
|
// borrowed reference
|
|
// borrowed reference
|
|
|
PyObject *sys_modules = PyImport_GetModuleDict();
|
|
PyObject *sys_modules = PyImport_GetModuleDict();
|
|
@@ -146,8 +147,8 @@ find_global_decode(PyObject *this_class, const char *func_name) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ Py_DECREF(module_name);
|
|
|
}
|
|
}
|
|
|
- Py_DECREF(module_name);
|
|
|
|
|
|
|
|
|
|
PyObject *bases = PyObject_GetAttrString(this_class, "__bases__");
|
|
PyObject *bases = PyObject_GetAttrString(this_class, "__bases__");
|
|
|
if (bases != NULL) {
|
|
if (bases != NULL) {
|
|
@@ -178,8 +179,8 @@ find_global_decode(PyObject *this_class, const char *func_name) {
|
|
|
* properly handle self-referential BAM objects.
|
|
* properly handle self-referential BAM objects.
|
|
|
*/
|
|
*/
|
|
|
PyObject *
|
|
PyObject *
|
|
|
-py_decode_TypedWritable_from_bam_stream(PyObject *this_class, const string &data) {
|
|
|
|
|
- return py_decode_TypedWritable_from_bam_stream_persist(NULL, this_class, data);
|
|
|
|
|
|
|
+py_decode_TypedWritable_from_bam_stream(PyObject *this_class, const vector_uchar &data) {
|
|
|
|
|
+ return py_decode_TypedWritable_from_bam_stream_persist(nullptr, this_class, data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -192,7 +193,7 @@ py_decode_TypedWritable_from_bam_stream(PyObject *this_class, const string &data
|
|
|
* direct/src/stdpy.
|
|
* direct/src/stdpy.
|
|
|
*/
|
|
*/
|
|
|
PyObject *
|
|
PyObject *
|
|
|
-py_decode_TypedWritable_from_bam_stream_persist(PyObject *pickler, PyObject *this_class, const string &data) {
|
|
|
|
|
|
|
+py_decode_TypedWritable_from_bam_stream_persist(PyObject *pickler, PyObject *this_class, const vector_uchar &data) {
|
|
|
|
|
|
|
|
PyObject *py_reader = NULL;
|
|
PyObject *py_reader = NULL;
|
|
|
if (pickler != NULL) {
|
|
if (pickler != NULL) {
|
|
@@ -210,28 +211,30 @@ py_decode_TypedWritable_from_bam_stream_persist(PyObject *pickler, PyObject *thi
|
|
|
// decode_from_bam_stream appropriate to this class.
|
|
// decode_from_bam_stream appropriate to this class.
|
|
|
|
|
|
|
|
PyObject *func = PyObject_GetAttrString(this_class, "decode_from_bam_stream");
|
|
PyObject *func = PyObject_GetAttrString(this_class, "decode_from_bam_stream");
|
|
|
- if (func == NULL) {
|
|
|
|
|
- return NULL;
|
|
|
|
|
|
|
+ if (func == nullptr) {
|
|
|
|
|
+ Py_XDECREF(py_reader);
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ PyObject *bytes = Dtool_WrapValue(data);
|
|
|
|
|
+ if (bytes == nullptr) {
|
|
|
|
|
+ Py_DECREF(func);
|
|
|
|
|
+ Py_XDECREF(py_reader);
|
|
|
|
|
+ return nullptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
PyObject *result;
|
|
PyObject *result;
|
|
|
- if (py_reader != NULL){
|
|
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
- result = PyObject_CallFunction(func, (char *)"(y#O)", data.data(), (Py_ssize_t) data.size(), py_reader);
|
|
|
|
|
-#else
|
|
|
|
|
- result = PyObject_CallFunction(func, (char *)"(s#O)", data.data(), (Py_ssize_t) data.size(), py_reader);
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ if (py_reader != nullptr) {
|
|
|
|
|
+ result = PyObject_CallFunctionObjArgs(func, bytes, py_reader, nullptr);
|
|
|
Py_DECREF(py_reader);
|
|
Py_DECREF(py_reader);
|
|
|
} else {
|
|
} else {
|
|
|
-#if PY_MAJOR_VERSION >= 3
|
|
|
|
|
- result = PyObject_CallFunction(func, (char *)"(y#)", data.data(), (Py_ssize_t) data.size());
|
|
|
|
|
-#else
|
|
|
|
|
- result = PyObject_CallFunction(func, (char *)"(s#)", data.data(), (Py_ssize_t) data.size());
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ result = PyObject_CallFunctionObjArgs(func, bytes, nullptr);
|
|
|
}
|
|
}
|
|
|
|
|
+ Py_DECREF(bytes);
|
|
|
|
|
+ Py_DECREF(func);
|
|
|
|
|
|
|
|
- if (result == NULL) {
|
|
|
|
|
- return NULL;
|
|
|
|
|
|
|
+ if (result == nullptr) {
|
|
|
|
|
+ return nullptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (result == Py_None) {
|
|
if (result == Py_None) {
|