summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/contents/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/analysis/contents/memory.c')
-rw-r--r--plugins/pychrysalide/analysis/contents/memory.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/plugins/pychrysalide/analysis/contents/memory.c b/plugins/pychrysalide/analysis/contents/memory.c
index d1da2e8..b960678 100644
--- a/plugins/pychrysalide/analysis/contents/memory.c
+++ b/plugins/pychrysalide/analysis/contents/memory.c
@@ -58,19 +58,26 @@ static PyObject *py_memory_content_new(PyTypeObject *, PyObject *, PyObject *);
static PyObject *py_memory_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
- PyObject *data; /* Données brutes à charger */
- int ret; /* Bilan de lecture des args. */
- char *buffer; /* Tampon interne de Python */
+ const char *data; /* Tampon interne de Python */
Py_ssize_t length; /* Taille utilisé de ce tampon */
+ int ret; /* Bilan de lecture des args. */
GBinContent *content; /* Version GLib du contenu */
- ret = PyArg_ParseTuple(args, "S", &data);
+#define MEMORY_CONTENT_DOC \
+ "MemoryContent builds a binary content from memory data only." \
+ " Thus no existing file backend is needed." \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " MemoryContent(data)" \
+ "\n" \
+ "Where data is provided as string or read-only bytes-like object." \
+ " The string may contain embedded null bytes."
+
+ ret = PyArg_ParseTuple(args, "s#", &data, &length);
if (!ret) return NULL;
- ret = PyBytes_AsStringAndSize(data, &buffer, &length);
- if (ret == -1) Py_RETURN_NONE;
-
- content = g_memory_content_new((const bin_t *)buffer, length);
+ content = g_memory_content_new((const bin_t *)data, length);
result = pygobject_new(G_OBJECT(content));
@@ -113,7 +120,7 @@ PyTypeObject *get_python_memory_content_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "PyChrysalide binary memory content",
+ .tp_doc = MEMORY_CONTENT_DOC,
.tp_methods = py_memory_content_methods,
.tp_getset = py_memory_content_getseters,