0

I am testing just a small change to this code here: https://github.com/Roffild/RoffildLibrary/blob/master/Libraries/Roffild/PythonDLL/mql_class.c but it raised exception that I couldn't catch. Anybody has a clue why at least from a look at the code?

I modified a few places to make these 2 new methods compiled ok: the pyMQL_send just crashed without meaning full message while the pyMQL_test raised "SystemError: null argument to internal routine"

_DLLSTD(mqlint) pyMQL_send(const mqllong magic, const mqlstring value,
   const mqldouble _DLLOUTARRAY(inputs), const mqlint inputs_size,
   mqlstring _DLLOUTSTRING(buffer), const mqlint stringBufferLen)
{
   PyObject *arg1 = NULL;
   PyObject *arg2 = NULL;
   PyObject *arg3 = NULL;
   PyObject *result = NULL;

   PyObject **items = NULL;
   Py_ssize_t x, size;
   mqlstring str;
   mqlint ret = -1;

   PY_THREAD_START_OR(return ret);
   PyErr_Clear();
   arg1 = PyLong_FromLongLong(magic);
   arg2 = PyUnicode_FromWideChar(value, -1);
   arg3 = PyTuple_New(inputs_size);
   if (arg1 != NULL && arg2 != NULL && arg3 != NULL) {
      items = PySequence_Fast_ITEMS(arg3);
      for (x = 0; x < inputs_size; x++) {
         items[x] = PyFloat_FromDouble(inputs[x]);
      }
      result = PyObject_CallFunctionObjArgs(__interp->mql_send, arg1, arg2, arg3, NULL);
      if (result != NULL) {
         Py_DECREF(arg1);
         arg1 = PyObject_Str(result);
         str = PyUnicode_AsUnicodeAndSize(arg1, &size);
         ret = (mqlint)size;
         if (size > stringBufferLen) {
            size = stringBufferLen;
         }
         wmemcpy(buffer, str, size);
         buffer[size] = 0;
      }
   }
   Py_XDECREF(arg1);
   Py_XDECREF(arg2);
   Py_XDECREF(arg3);
   Py_XDECREF(result);
   PY_THREAD_STOP;
   return ret;
}

// altered from _getDouble
_DLLSTD(mqlint) pyMQL_test(const mqllong magic, const mqlstring value,
    const mqldouble _DLLOUTARRAY(inputs), const mqlint inputs_size,
    mqldouble _DLLOUTARRAY(outputs), const mqlint outputs_size)
{
    PyObject* arg1 = NULL;
    PyObject* arg2 = NULL;
    PyObject* arg3 = NULL;
    PyObject* result = NULL;
    PyObject* seq = NULL;

    PyObject** items = NULL;
    Py_ssize_t x, size;
    mqlint ret = -1;

    PY_THREAD_START_OR(return ret);
    PyErr_Clear();
    arg1 = PyLong_FromLongLong(magic);
    arg2 = PyUnicode_FromWideChar(value, -1);
    arg3 = PyTuple_New(inputs_size);
    if (arg1 != NULL && arg2 != NULL && arg3 != NULL) {
        items = PySequence_Fast_ITEMS(arg3);
        for (x = 0; x < inputs_size; x++) {
            items[x] = PyFloat_FromDouble(inputs[x]);
        }
        result = PyObject_CallFunctionObjArgs(__interp->mql_test, arg1, arg2, arg3, NULL);
        if (result != NULL) {
            if (result == Py_None) {
                ret = 0;
            }
            else {
                seq = PySequence_Fast(result, "This is not PySequence.");
                if (seq != NULL) {
                    size = PySequence_Fast_GET_SIZE(seq);
                    ret = (mqlint)size;
                    if (size > outputs_size) {
                        size = outputs_size;
                    }
                    items = PySequence_Fast_ITEMS(seq);
                    for (x = 0; x < size; x++) {
                        outputs[x] = PyFloat_AsDouble(items[x]);
                    }
                }
            }
        }
    }
    Py_XDECREF(arg1);
    Py_XDECREF(arg2);
    Py_XDECREF(arg3);
    Py_XDECREF(result);
    Py_XDECREF(seq);
    PY_THREAD_STOP;
    return ret;
}

0 Answers0