[PyQt] Patch fixing some const issues
Phil Thompson
phil at riverbankcomputing.com
Fri Aug 11 16:02:12 BST 2017
On 11 Aug 2017, at 1:47 pm, Shaheed Haque <srhaque at theiet.org> wrote:
>
> Hi,
>
> Based on 4.19.4.dev1708081632, I see some issues with the emitted code involving casts. There are several cases, but here is one example that illustrates the issue:
>
> === 4.19.4.dev1708081632 output ===
> static void assign_std_auto_ptr_0100GpgME_EditInteractor(void *sipDst, SIP_SSIZE_T sipDstIdx, const void *sipSrc)
> {
> reinterpret_cast< ::std::auto_ptr< ::GpgME::EditInteractor> *>(sipDst)[sipDstIdx] = *reinterpret_cast<const ::std::auto_ptr< ::GpgME::EditInteractor> *>(sipSrc);
> }
> ==============================
>
> The above won't compile with errors boiling down, IIUC, to the fact that the RHS has type "const something", and this is not compatible with the LHS which has type "something" without the const. Now, I'll confess that I'm a bit rusty on some of this, but I think the correct fix is to cast away the constness of sipSrc earlier, like this:
>
> === patched version ===
> static void assign_std_auto_ptr_0100GpgME_EditInteractor(void *sipDst, SIP_SSIZE_T sipDstIdx, const void *sipSrc)
> {
> reinterpret_cast< ::std::auto_ptr< ::GpgME::EditInteractor> *>(sipDst)[sipDstIdx] = *reinterpret_cast< ::std::auto_ptr< ::GpgME::EditInteractor> *>(const_cast<void *>(sipSrc));
> }
> ===================
>
> Now, the LHS and the RHS match, and the compiler is happy. There are 4 similar cases in gencode.c which I patched, as below. This patch also includes my diffs for the static_cast<int>s from https://www.riverbankcomputing.com/pipermail/pyqt/2017-August/039494.html.
>
> (There is also one slightly different usage of reinterpret_cast<const ...> but I am not sure if that is implicated or not).
I don't see why the RHS breaks the constness. Is std::auto_ptr doing something out of the ordinary?
Phil
More information about the PyQt
mailing list