Improvements for Python3 Support
#7
Merged
SlavekB
merged 2 commits from deleted-message
into master
3 years ago
Loading…
Reference in New Issue
There is no content yet.
Delete Branch 'deleted-message'
Deleting a branch is permanent. It CANNOT be undone. Continue?
As part of the implementation of Python 3 support, the following improvements/fixes have been made:
Signed-off-by: aneejit1 aneejit1@gmail.com
Could you amend the commit message? There is a duplicated consecutive "from" in it.
8ad3cac8e3
to76444639b2
3 years ago'Tis done.
b275737d3c
to1d4d9cfcbe
3 years agoImprove the "underlying C/C++ object has been deleted" messageto Improvements for Python3 Support 3 years agoThings got a bit complicated after I fixed the "non-trivial designated initializers" error in python-tqt. The next thing that happened is that I started getting "initqt" or "PyInit_qt" for Python 2 and 3 respectively which is down to them having hidden visibility from the compiler option "-fvisibility=hidden" having been specified.
I've tried several things to get around this, but they mostly either didn't work or were rather messy. The aim was to add
__attribute__ ((visibility("default")))
to the function definition. This works for Python 2, but not Python 3. Turns out that Python 3.0 to 3.8 define the function asextern "C"
in the #define forPyMODINIT_FUNC
(3.9 onwards includes the attribute). If you add the attribute between PyMODINIT_FUNC and SIP_MODULE_ENTRY, there's a warning and it's ignored. I did toy with defining the function without PyMODINIT_FUNC, or doing a temporary#define PyObject __attribute__ ((visibility("default"))) PyObject
but neither option seemed to be a good idea.The only simple way I found around this is to add a
#pragma GCC visibility push(default)
and a corresponding#pragma GCC visibility pop
around the function which is done for gcc >= v4 or clang. I did add an end function to do the pop after the function's closing brace but removed it again as the compiler seems to be fine with placing the "pop" straight after the opening brace for the function. Even though this is redundant for Python 3.9 and above, I've not done anything to exclude it; it's more conditions to stop doing something that'll cause no harm.python-tqt is now importing the generated modules without problems.
@ -2331,2 +2334,4 @@
"#endif\n"
"{\n"
"#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)\n"
"#pragma GCC visibility pop\n"
Could it be easier to define in
sip-tqt.h
equivalent of macroKDE_EXPORT
and then use such macro instead of wrapping using#pragma
?I've been through that loop already and it doesn't work in this context. I initially created a
SIP_MODULE_EXPORT
macro and re-wrote the function definition as:The problem is Python defines
PyMODINIT_FUNC
asextern "C" PyObject*
so that the statement resolves itself toafter pre-processing which is not valid. The compiler issues a warning because of the
extern "C"
("warning: 'visibility' attribute ignored on non-class types") then ignores the attribute causing the initialisation function to be hidden. The resultant syntax would have to befor this to work, but that would mean not using PyMODINIT_FUNC at all. Since there are a number of possibilities for what PyMODINIT_FUNC could be set to in the Python headers, I figured it was safest not to try and override what it was doing.
The only other way I thought to do this was:
which is a particularly ugly hack of a solution.
While #pragma isn't the nicest way to do this, in this particular situation it worked out to be the most reliable way to get the desired result.
Thank you, I understand, using
#pragma
seems to be the easiest viable solution.Is it a good time to merge it? Or do you work on some other patches on this topic?
I've not got anything else to do with sip at the moment, so merge away!
@ -1432,6 +1432,7 @@ typedef struct _sipTQtAPI {
#define SIP_SHARE_MAP 0x0040 /* If the map slot might be occupied. */
#define SIP_CPP_HAS_REF 0x0080 /* If C/C++ has a reference. */
#define SIP_POSSIBLE_PROXY 0x0100 /* If there might be a proxy slot. */
#define SIP_CREATED 0x1000 /* If the C/C++ object has been created. */
Shouldn't this be 0x0200 rather than 0x1000?
I've copied from sip 4.19.23 which has several other flags defined that I'm not using here. Just in case more needs to be imported somewhere down the line, I figured it best to retain consistency between the two rather than have different values.
Yes, retaining consistency in case we backport some other ideas from upstream SIP is a good idea.
Ok, makes sense. I had missed the point you had backported code from upstream. In that case we need to clearly state that in the commit message, together with link to source code and reference to the fact that the code is provided under GPL 2 or higher.
Is there a specific wording or format you need? Perhaps an example?
OK, 'tis done.
Looks good, thanks for amending. Licensing and author copyright is an important thing, so we always have to be careful and transparent :-)
No specific wording, but you can look at the message here or here
1d4d9cfcbe
tob9448655a2
3 years agoThank you for your great cooperation.
Everything looks ready for merge.
b9448655a2
into master 3 years agoReviewers
b9448655a2
.