diff options
author | aneejit1 <aneejit1@gmail.com> | 2022-04-19 00:17:45 +0000 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2022-04-21 16:29:57 +0200 |
commit | 5b12d262dc940b6fe9e2766988917665c970318d (patch) | |
tree | 1ff5dc43f32d509aa1348ceac40e5ec6b372f028 /siplib/siplib.c | |
parent | 299bacc2dd874a55eb2e0d430a439b6fb5895e13 (diff) | |
download | sip4-tqt-5b12d262dc940b6fe9e2766988917665c970318d.tar.gz sip4-tqt-5b12d262dc940b6fe9e2766988917665c970318d.zip |
Updates for Python 3 Support
The following changes have been made to support Python 3:
- in sip-tqt.h, remove the cast in the "sipConvertFromSliceObject"
macro in versions 3.2+ as the API changed causing a compile error;
- in voidptr.h, alter the precompile conditions to remove the
PyCObject API cals for version 3.2+ (causes runtime symbol
resolution error) and amend the flags for "asstring";
- alter module import process in siplib.c to avoid re-loading an
already loaded module.
Signed-off-by: aneejit1 <aneejit1@gmail.com>
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'siplib/siplib.c')
-rw-r--r-- | siplib/siplib.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/siplib/siplib.c b/siplib/siplib.c index e799280..fff9457 100644 --- a/siplib/siplib.c +++ b/siplib/siplib.c @@ -648,6 +648,8 @@ static int add_all_lazy_attrs(sipTypeDef *td); static int objectify(const char *s, PyObject **objp); static void add_failure(PyObject **parseErrp, sipParseFailure *failure); static PyObject *bad_type_str(int arg_nr, PyObject *arg); +static sipExportedModuleDef *isModuleLoaded(sipExportedModuleDef *table, + char *name); /* @@ -1200,12 +1202,14 @@ static int sip_api_export_module(sipExportedModuleDef *client, { PyObject *mod; - if ((mod = PyImport_ImportModule(im->im_name)) == NULL) - return -1; + em = isModuleLoaded(moduleList, im->im_name); - for (em = moduleList; em != NULL; em = em->em_next) - if (strcmp(sipNameOfModule(em), im->im_name) == 0) - break; + if (em == NULL) + { + if ((mod = PyImport_ImportModule(im->im_name)) == NULL) + return -1; + em = isModuleLoaded(moduleList, im->im_name); + } if (em == NULL) { @@ -1277,6 +1281,22 @@ static int sip_api_export_module(sipExportedModuleDef *client, /* + * Find out if a client module has been loaded already. + */ +static sipExportedModuleDef *isModuleLoaded(sipExportedModuleDef *table, + char *name) +{ + sipExportedModuleDef *em = table; + + for (em = moduleList; em != NULL; em = em->em_next) + if (strcmp(sipNameOfModule(em), name) == 0) + return em; + + return NULL; +} + + +/* * Initialise the contents of a client module. By this time anything that * this depends on should have been initialised. A negative value is returned * and an exception raised if there was an error. |