Loading src/Load.cpp +16 −7 Original line number Original line Diff line number Diff line Loading @@ -85,6 +85,7 @@ namespace ale { "Check if Installed correctly and the function ale.loads exists."); "Check if Installed correctly and the function ale.loads exists."); } } // Create a Python tuple to hold the arguments to the method. // Create a Python tuple to hold the arguments to the method. PyObject *pArgs = PyTuple_New(3); PyObject *pArgs = PyTuple_New(3); if(!pArgs) { if(!pArgs) { Loading @@ -94,16 +95,19 @@ namespace ale { // Set the Python int as the first and second arguments to the method. // Set the Python int as the first and second arguments to the method. PyObject *pStringFileName = PyUnicode_FromString(filename.c_str()); PyObject *pStringFileName = PyUnicode_FromString(filename.c_str()); PyTuple_SetItem(pArgs, 0, pStringFileName); PyTuple_SetItem(pArgs, 0, pStringFileName); Py_INCREF(pStringFileName); // take ownership of reference PyObject *pStringProps = PyUnicode_FromString(props.c_str()); PyObject *pStringProps = PyUnicode_FromString(props.c_str()); PyTuple_SetItem(pArgs, 1, pStringProps); PyTuple_SetItem(pArgs, 1, pStringProps); Py_INCREF(pStringProps); // take ownership of reference PyObject *pStringFormatter = PyUnicode_FromString(formatter.c_str()); PyObject *pStringFormatter = PyUnicode_FromString(formatter.c_str()); PyTuple_SetItem(pArgs, 2, pStringFormatter); PyTuple_SetItem(pArgs, 2, pStringFormatter); Py_INCREF(pStringFormatter); // take ownership of reference // Call the function with the arguments. // Call the function with the arguments. PyObject* pResult = PyObject_CallObject(pFunc, pArgs); PyObject* pResult = PyObject_CallObject(pFunc, pArgs); if(!pResult) { if(!pResult) { throw invalid_argument("No Valid instrument found for label."); throw invalid_argument("No Valid instrument found for label."); } } Loading @@ -114,15 +118,20 @@ namespace ale { if(!temp_bytes){ if(!temp_bytes){ throw invalid_argument(getPyTraceback()); throw invalid_argument(getPyTraceback()); } } std::string cResult; std::string cResult; char *temp_str = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer char *temp_str = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer cResult = temp_str; // copy into std::string cResult = temp_str; // copy into std::string Py_DECREF(pResultStr); Py_DECREF(pResultStr); Py_DECREF(pStringFileName); Py_DECREF(pStringFileName); Py_DECREF(pStringProps); Py_DECREF(pStringProps); Py_DECREF(pStringFormatter); Py_DECREF(pStringFormatter); Py_DECREF(pArgs); return cResult; return cResult; } } Loading Loading
src/Load.cpp +16 −7 Original line number Original line Diff line number Diff line Loading @@ -85,6 +85,7 @@ namespace ale { "Check if Installed correctly and the function ale.loads exists."); "Check if Installed correctly and the function ale.loads exists."); } } // Create a Python tuple to hold the arguments to the method. // Create a Python tuple to hold the arguments to the method. PyObject *pArgs = PyTuple_New(3); PyObject *pArgs = PyTuple_New(3); if(!pArgs) { if(!pArgs) { Loading @@ -94,16 +95,19 @@ namespace ale { // Set the Python int as the first and second arguments to the method. // Set the Python int as the first and second arguments to the method. PyObject *pStringFileName = PyUnicode_FromString(filename.c_str()); PyObject *pStringFileName = PyUnicode_FromString(filename.c_str()); PyTuple_SetItem(pArgs, 0, pStringFileName); PyTuple_SetItem(pArgs, 0, pStringFileName); Py_INCREF(pStringFileName); // take ownership of reference PyObject *pStringProps = PyUnicode_FromString(props.c_str()); PyObject *pStringProps = PyUnicode_FromString(props.c_str()); PyTuple_SetItem(pArgs, 1, pStringProps); PyTuple_SetItem(pArgs, 1, pStringProps); Py_INCREF(pStringProps); // take ownership of reference PyObject *pStringFormatter = PyUnicode_FromString(formatter.c_str()); PyObject *pStringFormatter = PyUnicode_FromString(formatter.c_str()); PyTuple_SetItem(pArgs, 2, pStringFormatter); PyTuple_SetItem(pArgs, 2, pStringFormatter); Py_INCREF(pStringFormatter); // take ownership of reference // Call the function with the arguments. // Call the function with the arguments. PyObject* pResult = PyObject_CallObject(pFunc, pArgs); PyObject* pResult = PyObject_CallObject(pFunc, pArgs); if(!pResult) { if(!pResult) { throw invalid_argument("No Valid instrument found for label."); throw invalid_argument("No Valid instrument found for label."); } } Loading @@ -114,15 +118,20 @@ namespace ale { if(!temp_bytes){ if(!temp_bytes){ throw invalid_argument(getPyTraceback()); throw invalid_argument(getPyTraceback()); } } std::string cResult; std::string cResult; char *temp_str = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer char *temp_str = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer cResult = temp_str; // copy into std::string cResult = temp_str; // copy into std::string Py_DECREF(pResultStr); Py_DECREF(pResultStr); Py_DECREF(pStringFileName); Py_DECREF(pStringFileName); Py_DECREF(pStringProps); Py_DECREF(pStringProps); Py_DECREF(pStringFormatter); Py_DECREF(pStringFormatter); Py_DECREF(pArgs); return cResult; return cResult; } } Loading