3 개의 매개 변수가있는 함수를 호출하는 임베디드 Python 인터프리터를 만들었습니다. 나는 성공적 매개 변수없이 기능이 작업을 수행하기 위해 관리,하지만 난 PyObject_CallObject
을 실행할 때 프로그램이 세그먼트 폴트와 충돌 :C++에서 매개 변수가있는 파이썬 함수 호출
#0 0x00007ffff79c3a25 in PyEval_EvalCodeEx() from /usr/lib/libpython3.2mu.so.1.0
#1 0x00007ffff79c42bf in ??() from /usr/lib/libpython3.2mu.so.1.0
#2 0x00007ffff79c730a in PyObject_Call() from /usr/lib/libpython3.2mu.so.1.0
#3 0x00000000004f3f31 in Huggle::Python::PythonScript::Hook_SpeedyFinished(Huggle::WikiEdit*, bool)()
호출의 소스 코드는 다음과 같습니다이 .CPP의
void PythonScript::Hook_SpeedyFinished(WikiEdit *edit, bool successfull)
{
if (edit == nullptr)
return;
if (this->ptr_Hook_SpeedyFinished != nullptr)
{
HUGGLE_DEBUG("Calling hook Hook_SpeedyFinished @" + this->Name, 2);
// let's make a new list of params
PyObject *args = PyTuple_New(3);
PyObject *page_name = PyUnicode_FromString(edit->Page->PageName.toUtf8().data());
PyObject *user_name = PyUnicode_FromString(edit->User->Username.toUtf8().data());
PyObject *success;
if (!successfull)
successfull = PyUnicode_FromString("fail");
else
successfull = PyUnicode_FromString("success");
if (PyTuple_SetItem(args, 0, page_name))
HUGGLE_DEBUG("Failed to pass page_name to tuple @hook_speedy_finished", 3);
if (PyTuple_SetItem(args, 1, user_name))
HUGGLE_DEBUG("Failed to pass user to tuple @hook_speedy_finished", 3);
if (PyTuple_SetItem(args, 2, success))
HUGGLE_DEBUG("Failed to pass success to tuple @hook_speedy_finished", 3);
PyObject_CallObject(this->ptr_Hook_SpeedyFinished, args);
HUGGLE_DEBUG("finished", 1);
}
}
전체 소스 코드 파일은 https://github.com/huggle/huggle3-qt-lx/blob/master/huggle/pythonengine.cpp
무엇이 잘못 되었나요? 이 함수를 호출하는 것이 적절한 방법일까요? 나는 다음과 같습니다 https://docs.python.org/3/c-api/object.html 및 https://docs.python.org/2/c-api/tuple.html
는 명백한 오류가 : 대신'success' (포인터 타입) 내가 successfull''에 문자열 변환 FC의 결과를 전달하고의. 나는 그것을 눈치 채지 못하는 바보입니다. P – Petr