[PyQt] Patch fixing some const issues
Shaheed Haque
srhaque at theiet.org
Fri Aug 11 13:47:17 BST 2017
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).
Please consider applying.
Thanks, Shaheed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170811/9d04d1dc/attachment.html>
-------------- next part --------------
*** gencode.c.original 2017-08-10 12:35:34.251842096 +0100
--- gencode.c 2017-08-11 13:16:13.854790929 +0100
***************
*** 4173,4183 ****
prcode(fp,
" ((%b *)sipDst)[sipDstIdx] = *((const %b *)sipSrc);\n"
, &mtd->type, &mtd->type);
else
prcode(fp,
! " reinterpret_cast<%b *>(sipDst)[sipDstIdx] = *reinterpret_cast<const %b *>(sipSrc);\n"
, &mtd->type, &mtd->type);
prcode(fp,
"}\n"
);
--- 4173,4183 ----
prcode(fp,
" ((%b *)sipDst)[sipDstIdx] = *((const %b *)sipSrc);\n"
, &mtd->type, &mtd->type);
else
prcode(fp,
! " reinterpret_cast<%b *>(sipDst)[sipDstIdx] = *reinterpret_cast<%b *>(const_cast<void *>(sipSrc));\n"
, &mtd->type, &mtd->type);
prcode(fp,
"}\n"
);
***************
*** 4235,4245 ****
" return sipPtr;\n"
, &mtd->type, &mtd->type
, &mtd->type);
else
prcode(fp,
! " return new %b(reinterpret_cast<const %b *>(sipSrc)[sipSrcIdx]);\n"
, &mtd->type, &mtd->type);
prcode(fp,
"}\n"
);
--- 4235,4245 ----
" return sipPtr;\n"
, &mtd->type, &mtd->type
, &mtd->type);
else
prcode(fp,
! " return new %b(reinterpret_cast<%b *>(const_cast<void *>(sipSrc))[sipSrcIdx]);\n"
, &mtd->type, &mtd->type);
prcode(fp,
"}\n"
);
***************
*** 5154,5164 ****
case enum_type:
if (vd->type.u.ed->fqcname != NULL)
{
prcode(fp,
! " return sipConvertFromEnum(sipVal, sipType_%C);\n"
, vd->type.u.ed->fqcname);
break;
}
--- 5154,5164 ----
case enum_type:
if (vd->type.u.ed->fqcname != NULL)
{
prcode(fp,
! " return sipConvertFromEnum(static_cast<int>(sipVal), sipType_%C);\n"
, vd->type.u.ed->fqcname);
break;
}
***************
*** 6767,6777 ****
prcode(fp,
" ((struct %U *)sipDst)[sipDstIdx] = *((const struct %U *)sipSrc);\n"
, cd, cd);
else
prcode(fp,
! " reinterpret_cast<%U *>(sipDst)[sipDstIdx] = *reinterpret_cast<const %U *>(sipSrc);\n"
, cd, cd);
prcode(fp,
"}\n"
);
--- 6767,6777 ----
prcode(fp,
" ((struct %U *)sipDst)[sipDstIdx] = *((const struct %U *)sipSrc);\n"
, cd, cd);
else
prcode(fp,
! " reinterpret_cast<%U *>(sipDst)[sipDstIdx] = *reinterpret_cast<%U *>(const_cast<void *>(sipSrc));\n"
, cd, cd);
prcode(fp,
"}\n"
);
***************
*** 6829,6839 ****
" return sipPtr;\n"
, cd, cd
, cd);
else
prcode(fp,
! " return new %U(reinterpret_cast<const %U *>(sipSrc)[sipSrcIdx]);\n"
, cd, cd);
prcode(fp,
"}\n"
);
--- 6829,6839 ----
" return sipPtr;\n"
, cd, cd
, cd);
else
prcode(fp,
! " return new %U(reinterpret_cast<%U *>(const_cast<void *>(sipSrc))[sipSrcIdx]);\n"
, cd, cd);
prcode(fp,
"}\n"
);
***************
*** 12086,12096 ****
case enum_type:
if (ad->u.ed->fqcname != NULL)
{
prcode(fp,
! " %s sipConvertFromEnum(%s,sipType_%C);\n"
, prefix, vname, ad->u.ed->fqcname);
break;
}
--- 12086,12096 ----
case enum_type:
if (ad->u.ed->fqcname != NULL)
{
prcode(fp,
! " %s sipConvertFromEnum(static_cast<int>(%s),sipType_%C);\n"
, prefix, vname, ad->u.ed->fqcname);
break;
}
More information about the PyQt
mailing list