diff --git a/src/Python/PythonEmbed.cpp b/src/Python/PythonEmbed.cpp index 521fb4e4a..f5776f330 100644 --- a/src/Python/PythonEmbed.cpp +++ b/src/Python/PythonEmbed.cpp @@ -30,12 +30,17 @@ #ifdef slots // clashes with python headers #undef slots #endif -#include GC_PYTHONHEADER +#include // global instance of embedded python PythonEmbed *python; PyThreadState *mainThreadState; +// SIP module with GoldenCheetah Bindings +extern "C" { +extern PyObject *PyInit_goldencheetah(void); +}; + PythonEmbed::~PythonEmbed() { } @@ -49,6 +54,10 @@ PythonEmbed::PythonEmbed(const bool verbose, const bool interactive) : verbose(v // tell python our program name Py_SetProgramName((wchar_t*) name.toStdString().c_str()); + // our own module + int rc= PyImport_AppendInittab("goldencheetah", PyInit_goldencheetah); + fprintf(stderr, "Add import module GoldenCheetah rc=%d\n", rc); + // need to load the interpreter etc Py_InitializeEx(0); @@ -63,7 +72,8 @@ PythonEmbed::PythonEmbed(const bool verbose, const bool interactive) : verbose(v fprintf(stderr, "Python loaded [%s]\n", version.toStdString().c_str()); - // our base code - currently just traps stdout + // our base code - traps stdout and loads goldencheetan module + // mapping all the bindings to a GC object. std::string stdOutErr = ("import sys\n" "class CatchOutErr:\n" " def __init__(self):\n" @@ -72,11 +82,14 @@ PythonEmbed::PythonEmbed(const bool verbose, const bool interactive) : verbose(v " self.value += txt\n" "catchOutErr = CatchOutErr()\n" "sys.stdout = catchOutErr\n" - "sys.stderr = catchOutErr\n"); + "sys.stderr = catchOutErr\n" + "import goldencheetah\n" + "GC=goldencheetah.Bindings()\n"); PyRun_SimpleString(stdOutErr.c_str()); //invoke code to redirect - // our own module + + // setup trapping of output PyObject *pModule = PyImport_AddModule("__main__"); //create main module catcher = static_cast(PyObject_GetAttrString(pModule,"catchOutErr")); clear = static_cast(PyObject_GetAttrString(static_cast(catcher), "__init__")); diff --git a/src/Python/PythonEmbed.h b/src/Python/PythonEmbed.h index bb3a7635b..81f543639 100644 --- a/src/Python/PythonEmbed.h +++ b/src/Python/PythonEmbed.h @@ -37,7 +37,11 @@ class PythonEmbed { PythonEmbed(const bool verbose=false, const bool interactive=false); ~PythonEmbed(); - // catch and clear output + // catch and clear output - we use void* because we cannot + // include the python headers here as they redefine the slots + // mechanism that QT needs in header files. As a result they + // are cast to PyObject* the CPP source code (which are in turn + // typedefs so we can't even declare the class type here). void *catcher; void *clear; diff --git a/src/Python/SIP/Bindings.cpp b/src/Python/SIP/Bindings.cpp new file mode 100644 index 000000000..da4d04749 --- /dev/null +++ b/src/Python/SIP/Bindings.cpp @@ -0,0 +1,3 @@ +#include "Bindings.h" + +int Bindings::getValue() const { return 1; } diff --git a/src/Python/SIP/Bindings.h b/src/Python/SIP/Bindings.h new file mode 100644 index 000000000..70a9b1f90 --- /dev/null +++ b/src/Python/SIP/Bindings.h @@ -0,0 +1,6 @@ + +class Bindings { + + public: + int getValue() const; +}; diff --git a/src/Python/SIP/Makefile.hack b/src/Python/SIP/Makefile.hack new file mode 100644 index 000000000..fd85bde13 --- /dev/null +++ b/src/Python/SIP/Makefile.hack @@ -0,0 +1,14 @@ +# +# Run 'make' manually to regenerate the SRC files +# at some point later we will integrate into src.pro +# + +SRC= sipgoldencheetahBindings.cpp sipgoldencheetahcmodule.cpp +DEPS= goldencheetah.sip + +$(SRC): $(DEPS) + sip -c . goldencheetah.sip + +clean: + -rm $(SRC) + diff --git a/src/Python/SIP/goldencheetah.sip b/src/Python/SIP/goldencheetah.sip new file mode 100644 index 000000000..23b466266 --- /dev/null +++ b/src/Python/SIP/goldencheetah.sip @@ -0,0 +1,11 @@ +%Module goldencheetah + +class Bindings { + +%TypeHeaderCode +#include "Bindings.h" +%End + +public: + int getValue() const; +}; diff --git a/src/Python/SIP/sipAPIgoldencheetah.h b/src/Python/SIP/sipAPIgoldencheetah.h new file mode 100644 index 000000000..52be2976d --- /dev/null +++ b/src/Python/SIP/sipAPIgoldencheetah.h @@ -0,0 +1,201 @@ +/* + * Internal module API header file. + * + * Generated by SIP 4.19.6 + */ + +#ifndef _goldencheetahAPI_H +#define _goldencheetahAPI_H + +#include + +/* + * Convenient names to refer to various strings defined in this module. + * Only the class names are part of the public API. + */ +#define sipNameNr_goldencheetah 0 +#define sipName_goldencheetah &sipStrings_goldencheetah[0] +#define sipNameNr_getValue 14 +#define sipName_getValue &sipStrings_goldencheetah[14] +#define sipNameNr_Bindings 23 +#define sipName_Bindings &sipStrings_goldencheetah[23] + +#define sipMalloc sipAPI_goldencheetah->api_malloc +#define sipFree sipAPI_goldencheetah->api_free +#define sipBuildResult sipAPI_goldencheetah->api_build_result +#define sipCallMethod sipAPI_goldencheetah->api_call_method +#define sipCallProcedureMethod sipAPI_goldencheetah->api_call_procedure_method +#define sipCallErrorHandler sipAPI_goldencheetah->api_call_error_handler +#define sipParseResultEx sipAPI_goldencheetah->api_parse_result_ex +#define sipParseResult sipAPI_goldencheetah->api_parse_result +#define sipParseArgs sipAPI_goldencheetah->api_parse_args +#define sipParseKwdArgs sipAPI_goldencheetah->api_parse_kwd_args +#define sipParsePair sipAPI_goldencheetah->api_parse_pair +#define sipInstanceDestroyed sipAPI_goldencheetah->api_instance_destroyed +#define sipConvertFromSequenceIndex sipAPI_goldencheetah->api_convert_from_sequence_index +#define sipConvertFromVoidPtr sipAPI_goldencheetah->api_convert_from_void_ptr +#define sipConvertToVoidPtr sipAPI_goldencheetah->api_convert_to_void_ptr +#define sipAddException sipAPI_goldencheetah->api_add_exception +#define sipNoFunction sipAPI_goldencheetah->api_no_function +#define sipNoMethod sipAPI_goldencheetah->api_no_method +#define sipAbstractMethod sipAPI_goldencheetah->api_abstract_method +#define sipBadClass sipAPI_goldencheetah->api_bad_class +#define sipBadCatcherResult sipAPI_goldencheetah->api_bad_catcher_result +#define sipBadCallableArg sipAPI_goldencheetah->api_bad_callable_arg +#define sipBadOperatorArg sipAPI_goldencheetah->api_bad_operator_arg +#define sipTrace sipAPI_goldencheetah->api_trace +#define sipTransferBack sipAPI_goldencheetah->api_transfer_back +#define sipTransferTo sipAPI_goldencheetah->api_transfer_to +#define sipTransferBreak sipAPI_goldencheetah->api_transfer_break +#define sipSimpleWrapper_Type sipAPI_goldencheetah->api_simplewrapper_type +#define sipWrapper_Type sipAPI_goldencheetah->api_wrapper_type +#define sipWrapperType_Type sipAPI_goldencheetah->api_wrappertype_type +#define sipVoidPtr_Type sipAPI_goldencheetah->api_voidptr_type +#define sipGetPyObject sipAPI_goldencheetah->api_get_pyobject +#define sipGetAddress sipAPI_goldencheetah->api_get_address +#define sipGetMixinAddress sipAPI_goldencheetah->api_get_mixin_address +#define sipGetCppPtr sipAPI_goldencheetah->api_get_cpp_ptr +#define sipGetComplexCppPtr sipAPI_goldencheetah->api_get_complex_cpp_ptr +#define sipIsPyMethod sipAPI_goldencheetah->api_is_py_method +#define sipCallHook sipAPI_goldencheetah->api_call_hook +#define sipEndThread sipAPI_goldencheetah->api_end_thread +#define sipConnectRx sipAPI_goldencheetah->api_connect_rx +#define sipDisconnectRx sipAPI_goldencheetah->api_disconnect_rx +#define sipRaiseUnknownException sipAPI_goldencheetah->api_raise_unknown_exception +#define sipRaiseTypeException sipAPI_goldencheetah->api_raise_type_exception +#define sipBadLengthForSlice sipAPI_goldencheetah->api_bad_length_for_slice +#define sipAddTypeInstance sipAPI_goldencheetah->api_add_type_instance +#define sipFreeSipslot sipAPI_goldencheetah->api_free_sipslot +#define sipSameSlot sipAPI_goldencheetah->api_same_slot +#define sipPySlotExtend sipAPI_goldencheetah->api_pyslot_extend +#define sipConvertRx sipAPI_goldencheetah->api_convert_rx +#define sipAddDelayedDtor sipAPI_goldencheetah->api_add_delayed_dtor +#define sipCanConvertToType sipAPI_goldencheetah->api_can_convert_to_type +#define sipConvertToType sipAPI_goldencheetah->api_convert_to_type +#define sipForceConvertToType sipAPI_goldencheetah->api_force_convert_to_type +#define sipCanConvertToEnum sipAPI_goldencheetah->api_can_convert_to_enum +#define sipConvertToEnum sipAPI_goldencheetah->api_convert_to_enum +#define sipConvertToBool sipAPI_goldencheetah->api_convert_to_bool +#define sipReleaseType sipAPI_goldencheetah->api_release_type +#define sipConvertFromType sipAPI_goldencheetah->api_convert_from_type +#define sipConvertFromNewType sipAPI_goldencheetah->api_convert_from_new_type +#define sipConvertFromNewPyType sipAPI_goldencheetah->api_convert_from_new_pytype +#define sipConvertFromEnum sipAPI_goldencheetah->api_convert_from_enum +#define sipGetState sipAPI_goldencheetah->api_get_state +#define sipExportSymbol sipAPI_goldencheetah->api_export_symbol +#define sipImportSymbol sipAPI_goldencheetah->api_import_symbol +#define sipFindType sipAPI_goldencheetah->api_find_type +#define sipFindNamedEnum sipAPI_goldencheetah->api_find_named_enum +#define sipBytes_AsChar sipAPI_goldencheetah->api_bytes_as_char +#define sipBytes_AsString sipAPI_goldencheetah->api_bytes_as_string +#define sipString_AsASCIIChar sipAPI_goldencheetah->api_string_as_ascii_char +#define sipString_AsASCIIString sipAPI_goldencheetah->api_string_as_ascii_string +#define sipString_AsLatin1Char sipAPI_goldencheetah->api_string_as_latin1_char +#define sipString_AsLatin1String sipAPI_goldencheetah->api_string_as_latin1_string +#define sipString_AsUTF8Char sipAPI_goldencheetah->api_string_as_utf8_char +#define sipString_AsUTF8String sipAPI_goldencheetah->api_string_as_utf8_string +#define sipUnicode_AsWChar sipAPI_goldencheetah->api_unicode_as_wchar +#define sipUnicode_AsWString sipAPI_goldencheetah->api_unicode_as_wstring +#define sipConvertFromConstVoidPtr sipAPI_goldencheetah->api_convert_from_const_void_ptr +#define sipConvertFromVoidPtrAndSize sipAPI_goldencheetah->api_convert_from_void_ptr_and_size +#define sipConvertFromConstVoidPtrAndSize sipAPI_goldencheetah->api_convert_from_const_void_ptr_and_size +#define sipInvokeSlot sipAPI_goldencheetah->api_invoke_slot +#define sipInvokeSlotEx sipAPI_goldencheetah->api_invoke_slot_ex +#define sipSaveSlot sipAPI_goldencheetah->api_save_slot +#define sipClearAnySlotReference sipAPI_goldencheetah->api_clear_any_slot_reference +#define sipVisitSlot sipAPI_goldencheetah->api_visit_slot +#define sipWrappedTypeName(wt) ((wt)->wt_td->td_cname) +#define sipDeprecated sipAPI_goldencheetah->api_deprecated +#define sipGetReference sipAPI_goldencheetah->api_get_reference +#define sipKeepReference sipAPI_goldencheetah->api_keep_reference +#define sipRegisterProxyResolver sipAPI_goldencheetah->api_register_proxy_resolver +#define sipRegisterPyType sipAPI_goldencheetah->api_register_py_type +#define sipTypeFromPyTypeObject sipAPI_goldencheetah->api_type_from_py_type_object +#define sipTypeScope sipAPI_goldencheetah->api_type_scope +#define sipResolveTypedef sipAPI_goldencheetah->api_resolve_typedef +#define sipRegisterAttributeGetter sipAPI_goldencheetah->api_register_attribute_getter +#define sipIsAPIEnabled sipAPI_goldencheetah->api_is_api_enabled +#define sipSetDestroyOnExit sipAPI_goldencheetah->api_set_destroy_on_exit +#define sipEnableAutoconversion sipAPI_goldencheetah->api_enable_autoconversion +#define sipEnableOverflowChecking sipAPI_goldencheetah->api_enable_overflow_checking +#define sipInitMixin sipAPI_goldencheetah->api_init_mixin +#define sipExportModule sipAPI_goldencheetah->api_export_module +#define sipInitModule sipAPI_goldencheetah->api_init_module +#define sipGetInterpreter sipAPI_goldencheetah->api_get_interpreter +#define sipSetNewUserTypeHandler sipAPI_goldencheetah->api_set_new_user_type_handler +#define sipSetTypeUserData sipAPI_goldencheetah->api_set_type_user_data +#define sipGetTypeUserData sipAPI_goldencheetah->api_get_type_user_data +#define sipPyTypeDict sipAPI_goldencheetah->api_py_type_dict +#define sipPyTypeName sipAPI_goldencheetah->api_py_type_name +#define sipGetCFunction sipAPI_goldencheetah->api_get_c_function +#define sipGetMethod sipAPI_goldencheetah->api_get_method +#define sipFromMethod sipAPI_goldencheetah->api_from_method +#define sipGetDate sipAPI_goldencheetah->api_get_date +#define sipFromDate sipAPI_goldencheetah->api_from_date +#define sipGetDateTime sipAPI_goldencheetah->api_get_datetime +#define sipFromDateTime sipAPI_goldencheetah->api_from_datetime +#define sipGetTime sipAPI_goldencheetah->api_get_time +#define sipFromTime sipAPI_goldencheetah->api_from_time +#define sipIsUserType sipAPI_goldencheetah->api_is_user_type +#define sipGetFrame sipAPI_goldencheetah->api_get_frame +#define sipCheckPluginForType sipAPI_goldencheetah->api_check_plugin_for_type +#define sipUnicodeNew sipAPI_goldencheetah->api_unicode_new +#define sipUnicodeWrite sipAPI_goldencheetah->api_unicode_write +#define sipUnicodeData sipAPI_goldencheetah->api_unicode_data +#define sipGetBufferInfo sipAPI_goldencheetah->api_get_buffer_info +#define sipReleaseBufferInfo sipAPI_goldencheetah->api_release_buffer_info +#define sipIsOwnedByPython sipAPI_goldencheetah->api_is_owned_by_python +#define sipIsDerivedClass sipAPI_goldencheetah->api_is_derived_class +#define sipGetUserObject sipAPI_goldencheetah->api_get_user_object +#define sipSetUserObject sipAPI_goldencheetah->api_set_user_object +#define sipRegisterEventHandler sipAPI_goldencheetah->api_register_event_handler +#define sipLong_AsChar sipAPI_goldencheetah->api_long_as_char +#define sipLong_AsSignedChar sipAPI_goldencheetah->api_long_as_signed_char +#define sipLong_AsUnsignedChar sipAPI_goldencheetah->api_long_as_unsigned_char +#define sipLong_AsShort sipAPI_goldencheetah->api_long_as_short +#define sipLong_AsUnsignedShort sipAPI_goldencheetah->api_long_as_unsigned_short +#define sipLong_AsInt sipAPI_goldencheetah->api_long_as_int +#define sipLong_AsUnsignedInt sipAPI_goldencheetah->api_long_as_unsigned_int +#define sipLong_AsLong sipAPI_goldencheetah->api_long_as_long +#define sipLong_AsUnsignedLong sipAPI_goldencheetah->api_long_as_unsigned_long +#define sipLong_AsLongLong sipAPI_goldencheetah->api_long_as_long_long +#define sipLong_AsUnsignedLongLong sipAPI_goldencheetah->api_long_as_unsigned_long_long + +/* These are deprecated. */ +#define sipMapStringToClass sipAPI_goldencheetah->api_map_string_to_class +#define sipMapIntToClass sipAPI_goldencheetah->api_map_int_to_class +#define sipFindClass sipAPI_goldencheetah->api_find_class +#define sipFindMappedType sipAPI_goldencheetah->api_find_mapped_type +#define sipConvertToArray sipAPI_goldencheetah->api_convert_to_array +#define sipConvertToTypedArray sipAPI_goldencheetah->api_convert_to_typed_array +#define sipEnableGC sipAPI_goldencheetah->api_enable_gc +#define sipPrintObject sipAPI_goldencheetah->api_print_object +#define sipWrapper_Check(w) PyObject_TypeCheck((w), sipAPI_goldencheetah->api_wrapper_type) +#define sipGetWrapper(p, wt) sipGetPyObject((p), (wt)->wt_td) +#define sipReleaseInstance(p, wt, s) sipReleaseType((p), (wt)->wt_td, (s)) +#define sipReleaseMappedType sipReleaseType +#define sipCanConvertToInstance(o, wt, f) sipCanConvertToType((o), (wt)->wt_td, (f)) +#define sipCanConvertToMappedType sipCanConvertToType +#define sipConvertToInstance(o, wt, t, f, s, e) sipConvertToType((o), (wt)->wt_td, (t), (f), (s), (e)) +#define sipConvertToMappedType sipConvertToType +#define sipForceConvertToInstance(o, wt, t, f, s, e) sipForceConvertToType((o), (wt)->wt_td, (t), (f), (s), (e)) +#define sipForceConvertToMappedType sipForceConvertToType +#define sipConvertFromInstance(p, wt, t) sipConvertFromType((p), (wt)->wt_td, (t)) +#define sipConvertFromMappedType sipConvertFromType +#define sipConvertFromNamedEnum(v, pt) sipConvertFromEnum((v), ((sipEnumTypeObject *)(pt))->type) +#define sipConvertFromNewInstance(p, wt, t) sipConvertFromNewType((p), (wt)->wt_td, (t)) + +/* The strings used by this module. */ +extern const char sipStrings_goldencheetah[]; + +#define sipType_Bindings sipExportedTypes_goldencheetah[0] +#define sipClass_Bindings sipExportedTypes_goldencheetah[0]->u.td_wrapper_type + +extern sipClassTypeDef sipTypeDef_goldencheetah_Bindings; + +/* The SIP API, this module's API and the APIs of any imported modules. */ +extern const sipAPIDef *sipAPI_goldencheetah; +extern sipExportedModuleDef sipModuleAPI_goldencheetah; +extern sipTypeDef *sipExportedTypes_goldencheetah[]; + +#endif diff --git a/src/Python/SIP/sipgoldencheetahBindings.cpp b/src/Python/SIP/sipgoldencheetahBindings.cpp new file mode 100644 index 000000000..588f97c41 --- /dev/null +++ b/src/Python/SIP/sipgoldencheetahBindings.cpp @@ -0,0 +1,160 @@ +/* + * Interface wrapper code. + * + * Generated by SIP 4.19.6 + */ + +#include "sipAPIgoldencheetah.h" + +#line 6 "goldencheetah.sip" +#include "Bindings.h" +#line 12 "./sipgoldencheetahBindings.cpp" + + + +extern "C" {static PyObject *meth_Bindings_getValue(PyObject *, PyObject *);} +static PyObject *meth_Bindings_getValue(PyObject *sipSelf, PyObject *sipArgs) +{ + PyObject *sipParseErr = NULL; + + { + const ::Bindings *sipCpp; + + if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_Bindings, &sipCpp)) + { + int sipRes; + + sipRes = sipCpp->getValue(); + + return SIPLong_FromLong(sipRes); + } + } + + /* Raise an exception if the arguments couldn't be parsed. */ + sipNoMethod(sipParseErr, sipName_Bindings, sipName_getValue, NULL); + + return NULL; +} + + +/* Call the instance's destructor. */ +extern "C" {static void release_Bindings(void *, int);} +static void release_Bindings(void *sipCppV, int) +{ + delete reinterpret_cast< ::Bindings *>(sipCppV); +} + + +extern "C" {static void assign_Bindings(void *, SIP_SSIZE_T, void *);} +static void assign_Bindings(void *sipDst, SIP_SSIZE_T sipDstIdx, void *sipSrc) +{ + reinterpret_cast< ::Bindings *>(sipDst)[sipDstIdx] = *reinterpret_cast< ::Bindings *>(sipSrc); +} + + +extern "C" {static void *array_Bindings(SIP_SSIZE_T);} +static void *array_Bindings(SIP_SSIZE_T sipNrElem) +{ + return new ::Bindings[sipNrElem]; +} + + +extern "C" {static void *copy_Bindings(const void *, SIP_SSIZE_T);} +static void *copy_Bindings(const void *sipSrc, SIP_SSIZE_T sipSrcIdx) +{ + return new ::Bindings(reinterpret_cast(sipSrc)[sipSrcIdx]); +} + + +extern "C" {static void dealloc_Bindings(sipSimpleWrapper *);} +static void dealloc_Bindings(sipSimpleWrapper *sipSelf) +{ + if (sipIsOwnedByPython(sipSelf)) + { + release_Bindings(sipGetAddress(sipSelf), 0); + } +} + + +extern "C" {static void *init_type_Bindings(sipSimpleWrapper *, PyObject *, PyObject *, PyObject **, PyObject **, PyObject **);} +static void *init_type_Bindings(sipSimpleWrapper *, PyObject *sipArgs, PyObject *sipKwds, PyObject **sipUnused, PyObject **, PyObject **sipParseErr) +{ + ::Bindings *sipCpp = 0; + + { + if (sipParseKwdArgs(sipParseErr, sipArgs, sipKwds, NULL, sipUnused, "")) + { + sipCpp = new ::Bindings(); + + return sipCpp; + } + } + + { + const ::Bindings* a0; + + if (sipParseKwdArgs(sipParseErr, sipArgs, sipKwds, NULL, sipUnused, "J9", sipType_Bindings, &a0)) + { + sipCpp = new ::Bindings(*a0); + + return sipCpp; + } + } + + return NULL; +} + + +static PyMethodDef methods_Bindings[] = { + {SIP_MLNAME_CAST(sipName_getValue), meth_Bindings_getValue, METH_VARARGS, NULL} +}; + + +sipClassTypeDef sipTypeDef_goldencheetah_Bindings = { + { + -1, + 0, + 0, + SIP_TYPE_CLASS, + sipNameNr_Bindings, + {0}, + 0 + }, + { + sipNameNr_Bindings, + {0, 0, 1}, + 1, methods_Bindings, + 0, 0, + 0, 0, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + }, + 0, + -1, + -1, + 0, + 0, + init_type_Bindings, + 0, + 0, +#if PY_MAJOR_VERSION >= 3 + 0, + 0, +#else + 0, + 0, + 0, + 0, +#endif + dealloc_Bindings, + assign_Bindings, + array_Bindings, + copy_Bindings, + release_Bindings, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; diff --git a/src/Python/SIP/sipgoldencheetahcmodule.cpp b/src/Python/SIP/sipgoldencheetahcmodule.cpp new file mode 100644 index 000000000..9f6879770 --- /dev/null +++ b/src/Python/SIP/sipgoldencheetahcmodule.cpp @@ -0,0 +1,171 @@ +/* + * Module code. + * + * Generated by SIP 4.19.6 + */ + +#include "sipAPIgoldencheetah.h" + +#line 6 "goldencheetah.sip" +#include "Bindings.h" +#line 12 "./sipgoldencheetahcmodule.cpp" + +/* Define the strings used by this module. */ +const char sipStrings_goldencheetah[] = { + 'g', 'o', 'l', 'd', 'e', 'n', 'c', 'h', 'e', 'e', 't', 'a', 'h', 0, + 'g', 'e', 't', 'V', 'a', 'l', 'u', 'e', 0, + 'B', 'i', 'n', 'd', 'i', 'n', 'g', 's', 0, +}; + + +/* + * This defines each type in this module. + */ +sipTypeDef *sipExportedTypes_goldencheetah[] = { + &sipTypeDef_goldencheetah_Bindings.ctd_base, +}; + + +/* This defines this module. */ +sipExportedModuleDef sipModuleAPI_goldencheetah = { + 0, + SIP_API_MINOR_NR, + sipNameNr_goldencheetah, + 0, + sipStrings_goldencheetah, + NULL, + NULL, + 1, + sipExportedTypes_goldencheetah, + NULL, + 0, + NULL, + 0, + NULL, + NULL, + NULL, + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; + + +/* The SIP API and the APIs of any imported modules. */ +const sipAPIDef *sipAPI_goldencheetah; + + +/* The Python module initialisation function. */ +#if PY_MAJOR_VERSION >= 3 +#define SIP_MODULE_ENTRY PyInit_goldencheetah +#define SIP_MODULE_TYPE PyObject * +#define SIP_MODULE_DISCARD(r) Py_DECREF(r) +#define SIP_MODULE_RETURN(r) return (r) +#else +#define SIP_MODULE_ENTRY initgoldencheetah +#define SIP_MODULE_TYPE void +#define SIP_MODULE_DISCARD(r) +#define SIP_MODULE_RETURN(r) return +#endif + +#if defined(SIP_STATIC_MODULE) +extern "C" SIP_MODULE_TYPE SIP_MODULE_ENTRY() +#else +PyMODINIT_FUNC SIP_MODULE_ENTRY() +#endif +{ + static PyMethodDef sip_methods[] = { + {0, 0, 0, 0} + }; + +#if PY_MAJOR_VERSION >= 3 + static PyModuleDef sip_module_def = { + PyModuleDef_HEAD_INIT, + "goldencheetah", + NULL, + -1, + sip_methods, + NULL, + NULL, + NULL, + NULL + }; +#endif + + PyObject *sipModule, *sipModuleDict; + PyObject *sip_sipmod, *sip_capiobj; + + /* Initialise the module and get it's dictionary. */ +#if PY_MAJOR_VERSION >= 3 + sipModule = PyModule_Create(&sip_module_def); +#elif PY_VERSION_HEX >= 0x02050000 + sipModule = Py_InitModule(sipName_goldencheetah, sip_methods); +#else + sipModule = Py_InitModule(const_cast(sipName_goldencheetah), sip_methods); +#endif + + if (sipModule == NULL) + SIP_MODULE_RETURN(NULL); + + sipModuleDict = PyModule_GetDict(sipModule); + + /* Get the SIP module's API. */ +#if PY_VERSION_HEX >= 0x02050000 + sip_sipmod = PyImport_ImportModule(SIP_MODULE_NAME); +#else + sip_sipmod = PyImport_ImportModule(const_cast(SIP_MODULE_NAME)); +#endif + + if (sip_sipmod == NULL) + { + SIP_MODULE_DISCARD(sipModule); + SIP_MODULE_RETURN(NULL); + } + + sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod), "_C_API"); + Py_DECREF(sip_sipmod); + +#if defined(SIP_USE_PYCAPSULE) + if (sip_capiobj == NULL || !PyCapsule_CheckExact(sip_capiobj)) +#else + if (sip_capiobj == NULL || !PyCObject_Check(sip_capiobj)) +#endif + { + SIP_MODULE_DISCARD(sipModule); + SIP_MODULE_RETURN(NULL); + } + +#if defined(SIP_USE_PYCAPSULE) + sipAPI_goldencheetah = reinterpret_cast(PyCapsule_GetPointer(sip_capiobj, SIP_MODULE_NAME "._C_API")); +#else + sipAPI_goldencheetah = reinterpret_cast(PyCObject_AsVoidPtr(sip_capiobj)); +#endif + +#if defined(SIP_USE_PYCAPSULE) + if (sipAPI_goldencheetah == NULL) + { + SIP_MODULE_DISCARD(sipModule); + SIP_MODULE_RETURN(NULL); + } +#endif + + /* Export the module and publish it's API. */ + if (sipExportModule(&sipModuleAPI_goldencheetah,SIP_API_MAJOR_NR,SIP_API_MINOR_NR,0) < 0) + { + SIP_MODULE_DISCARD(sipModule); + SIP_MODULE_RETURN(0); + } + /* Initialise the module now all its dependencies have been set up. */ + if (sipInitModule(&sipModuleAPI_goldencheetah,sipModuleDict) < 0) + { + SIP_MODULE_DISCARD(sipModule); + SIP_MODULE_RETURN(0); + } + + SIP_MODULE_RETURN(sipModule); +} diff --git a/src/gcconfig.pri.in b/src/gcconfig.pri.in index 93e884342..8ee3f0dda 100644 --- a/src/gcconfig.pri.in +++ b/src/gcconfig.pri.in @@ -25,13 +25,12 @@ # Libs needed can typically be found by calling e.g # python3.6-config --libs # -#DEFINES += GC_WANT_PYTHON # below 3 lines work well on Linux style OS -#PYTHONHEADER = \ -##PYTHONINCLUDES = -I/usr/include +#DEFINES += GC_WANT_PYTHON +#PYTHONINCLUDES = -I/usr/include/python3.6 #PYTHONLIBS = -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m # below 3 lines work well on Windows -#PYTHONHEADER = \"\" +#DEFINES += GC_WANT_PYTHON #PYTHONINCLUDES = -I\"C:\Program Files\Python36\include\" #PYTHONLIBS = -L\"C:\Program Files\Python36\libs\" -lpython36 diff --git a/src/src.pro b/src/src.pro index 7fb4ea814..27d11b03e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -282,7 +282,7 @@ contains(DEFINES, "GC_WANT_PYTHON") { # add Python subdirectory to include path INCLUDEPATH += ./Python - DEFINES += GC_PYTHONHEADER=$${PYTHONHEADER} + DEFINES += SIP_STATIC_MODULE !isEmpty(PYTHONINCLUDES) QMAKE_CXXFLAGS += $${PYTHONINCLUDES} LIBS += $${PYTHONLIBS} @@ -290,6 +290,10 @@ contains(DEFINES, "GC_WANT_PYTHON") { HEADERS += Python/PythonEmbed.h Charts/PythonChart.h Python/PythonSyntax.h SOURCES += Python/PythonEmbed.cpp Charts/PythonChart.cpp Python/PythonSyntax.cpp + ## Python SIP generated module + SOURCES += Python/SIP/sipgoldencheetahBindings.cpp Python/SIP/sipgoldencheetahcmodule.cpp + SOURCES += Python/SIP/Bindings.cpp + DEFINES += GC_HAVE_PYTHON } else {