]> sigrok.org Git - libsigrokdecode.git/blobdiff - decode.c
Rename the scripts/ directory to decoders/.
[libsigrokdecode.git] / decode.c
index e6399db72ce346bf6d2dfc4e378a11ac0a2bcb4e..337979dee0e1bc411e73fbb1198af65dfab57cb2 100644 (file)
--- a/decode.c
+++ b/decode.c
 #include <stdio.h>
 #include <string.h>
 
+/* Re-define some string functions for Python >= 3.0. */
+#if PY_VERSION_HEX >= 0x03000000
+#define PyString_AsString PyBytes_AsString
+#define PyString_FromString PyBytes_FromString
+#define PyString_Check PyBytes_Check
+#endif
+
 /**
  * Initialize libsigrokdecode.
  *
- * @return 0 upon success, non-zero otherwise.
+ * @return SIGROKDECODE_OK upon success, a (negative) error code otherwise.
  */
 int sigrokdecode_init(void)
 {
@@ -34,14 +41,15 @@ int sigrokdecode_init(void)
 
        /* Add some more search directories for convenience. */
        /* FIXME: Check error code. */
+       /* FIXME: What happens if this function is called multiple times? */
        PyRun_SimpleString(
                "import sys;"
-               "sys.path.append('libsigrokdecode/scripts');"
-               "sys.path.append('../libsigrokdecode/scripts');"
+               "sys.path.append('libsigrokdecode/decoders');"
+               "sys.path.append('../libsigrokdecode/decoders');"
                "sys.path.append('/usr/local/share/sigrok');"
                );
 
-       return 0;
+       return SIGROKDECODE_OK;
 }
 
 /**
@@ -49,8 +57,8 @@ int sigrokdecode_init(void)
  *
  * TODO: @param entries.
  *
- * @return 0 upon success, non-zero otherwise. The 'outstr' argument will
- *         point to a malloc()ed string upon success.
+ * @return LIBSIGROKDECODE_OK upon success, a (negative) error code otherwise.
+ *         The 'outstr' argument points to a malloc()ed string upon success.
  */
 static int h_str(PyObject *py_res, PyObject *py_func, PyObject *py_mod,
                 const char *key, char **outstr)
@@ -87,14 +95,15 @@ static int h_str(PyObject *py_res, PyObject *py_func, PyObject *py_mod,
 
        Py_DECREF(py_str);
 
-       return 0;
+       return SIGROKDECODE_OK;
 }
 
 /**
  * TODO
  *
  * @param name TODO
- * @return 0 upon success, non-zero otherwise.
+ *
+ * @return LIBSIGROKDECODE_OK upon success, a (negative) error code otherwise.
  */
 int sigrokdecode_load_decoder(const char *name,
                              struct sigrokdecode_decoder **dec)
@@ -166,7 +175,7 @@ int sigrokdecode_load_decoder(const char *name,
 
        *dec = d;
 
-       return 0;
+       return SIGROKDECODE_OK;
 }
 
 /**
@@ -177,7 +186,8 @@ int sigrokdecode_load_decoder(const char *name,
  * @param inbuflen TODO
  * @param outbuf TODO
  * @param outbuflen TODO
- * @return 0 upon success, non-zero otherwise.
+ *
+ * @return LIBSIGROKDECODE_OK upon success, a (negative) error code otherwise.
  */
 int sigrokdecode_run_decoder(struct sigrokdecode_decoder *dec,
                             uint8_t *inbuf, uint64_t inbuflen,
@@ -259,18 +269,18 @@ int sigrokdecode_run_decoder(struct sigrokdecode_decoder *dec,
        Py_DECREF(py_func);
        Py_DECREF(py_mod);
 
-       return 0;
+       return SIGROKDECODE_OK;
 }
 
 /**
  * Shutdown libsigrokdecode.
  *
- * @return 0 upon success, non-zero otherwise.
+ * @return LIBSIGROKDECODE_OK upon success, a (negative) error code otherwise.
  */
 int sigrokdecode_shutdown(void)
 {
        /* Py_Finalize() returns void, any finalization errors are ignored. */
        Py_Finalize();
 
-       return 0;
+       return SIGROKDECODE_OK;
 }