I haven't yet figured out how to reproduce this in a minimal testcase, but I would like to report what I'm seeing already:
We have this struct:
struct LabelNucleiParameters
{
std::optional<double> fixedThreshold = DEFAULT_FIXED_THRESHOLD;
static constexpr std::optional<double> DEFAULT_FIXED_THRESHOLD = std::nullopt;
};
and then these snippets in our typesystems
<container-type name="std::optional" type="pair">
<include file-name="optional" location="global"/>
<conversion-rule>
<native-to-target>
if (static_cast<bool>(%in))
{
%INTYPE_0 value = *%in;
return %CONVERTTOPYTHON[%INTYPE_0](value);
}
else
Py_RETURN_NONE;
</native-to-target>
<target-to-native>
<add-conversion type="PyObject*">
if (!%in)
%out = {};
else
{
%OUTTYPE_0 value = %CONVERTTOCPP[%OUTTYPE_0](%in);
%out = value;
}
</add-conversion>
</target-to-native>
</conversion-rule>
</container-type>
<value-type name="LabelNucleiParameters">
shiboken then crashes on startup with this backtrace:
==147691==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x7fd8f2c07490 bp 0x7ffd78550e00 sp 0x7ffd78550df0 T0)
==147691==The signal is caused by a READ memory access.
==147691==Hint: address points to the zero page.
#0 0x7fd8f2c07490 in CopyCppToPython ../3rdParty/PySide2/sources/shiboken2/libshiboken/sbkconverter.cpp:226
#1 0x7fd8f2c07554 in Shiboken::Conversions::copyToPython(SbkConverter const*, void const*) ../3rdParty/PySide2/sources/shiboken2/libshiboken/sbkconverter.cpp:239
#2 0x7fd8aea7afe6 in init_Pipeline_LabelNucleiParameters(_object*) Python/KDAB/pipeline/PyQiTissue/Pipeline/pipeline_labelnucleiparameters_wrapper.cpp:550
#3 0x7fd8aea1111f in PyInit_Pipeline Python/KDAB/pipeline/PyQiTissue/Pipeline/pipeline_module_wrapper.cpp:1746
#4 0x7fd8f302ed2f (/usr/lib/libpython3.9.so.1.0+0x216d2f)
#5 0x7fd8f2f5333e (/usr/lib/libpython3.9.so.1.0+0x13b33e)
#6 0x7fd8f2f473d9 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x12f3d9)
#7 0x7fd8f2f409ac (/usr/lib/libpython3.9.so.1.0+0x1289ac)
#8 0x7fd8f2f52b0d in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13ab0d)
#9 0x7fd8f2f4651d in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x12e51d)
#10 0x7fd8f2f52969 in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13a969)
#11 0x7fd8f2f4210a in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x12a10a)
#12 0x7fd8f2f52969 in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13a969)
#13 0x7fd8f2f41ed6 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x129ed6)
#14 0x7fd8f2f52969 in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13a969)
#15 0x7fd8f2f41ed6 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x129ed6)
#16 0x7fd8f2f52969 in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13a969)
#17 0x7fd8f2f41ed6 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x129ed6)
#18 0x7fd8f2f52969 in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13a969)
#19 0x7fd8f2f52164 (/usr/lib/libpython3.9.so.1.0+0x13a164)
#20 0x7fd8f2f664ba in _PyObject_CallMethodIdObjArgs (/usr/lib/libpython3.9.so.1.0+0x14e4ba)
#21 0x7fd8f2f65ba4 in PyImport_ImportModuleLevelObject (/usr/lib/libpython3.9.so.1.0+0x14dba4)
#22 0x7fd8f2f89877 (/usr/lib/libpython3.9.so.1.0+0x171877)
#23 0x7fd8f2f64a42 (/usr/lib/libpython3.9.so.1.0+0x14ca42)
#24 0x7fd8f2f6398e in PyObject_Call (/usr/lib/libpython3.9.so.1.0+0x14b98e)
#25 0x7fd8f2f473d9 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.9.so.1.0+0x12f3d9)
#26 0x7fd8f2f409ac (/usr/lib/libpython3.9.so.1.0+0x1289ac)
#27 0x7fd8f2f52b0d in _PyFunction_Vectorcall (/usr/lib/libpython3.9.so.1.0+0x13ab0d)
#28 0x7fd8f2f895b9 in PyObject_CallFunction (/usr/lib/libpython3.9.so.1.0+0x1715b9)
#29 0x7fd8f2f88151 in PyImport_Import (/usr/lib/libpython3.9.so.1.0+0x170151)
#30 0x7fd8f300f3cc in PyImport_ImportModule (/usr/lib/libpython3.9.so.1.0+0x1f73cc)
#31 0x7fd8f2c1382f in Shiboken::Module::import(char const*) ../3rdParty/PySide2/sources/shiboken2/libshiboken/sbkmodule.cpp:67
#32 0x7fd8b027b07a in PyInit_QiTissue Python/KDAB/qitissue/PyQiTissue/QiTissue/qitissue_module_wrapper.cpp:2445
the reason is that in line 2445 of the module_wrapper the converters are not yet initialized, i.e. here's a snippet from qitissue_module_wrapper.cpp:
{
Shiboken::AutoDecRef requiredModule(Shiboken::Module::import("PyQiTissue.Pipeline"));
if (requiredModule.isNull())
return SBK_MODULE_INIT_ERROR;
SbkPyQiTissue_PipelineTypes = Shiboken::Module::getTypes(requiredModule);
SbkPyQiTissue_PipelineTypeConverters = Shiboken::Module::getTypeConverters(requiredModule);
}
Line 2445 is the line with the Module::import call. That then down the line tries to access the converter in pipeline_labelnucleiparameters_wrapper.cpp line 550:
PyDict_SetItemString(reinterpret_cast<PyTypeObject *>(Sbk_Pipeline_LabelNucleiParameters_TypeF())->tp_dict, "DEFAULT_FIXED_THRESHOLD", Shiboken::Conversions::copyToPython(SbkPyQiTissue_PipelineTypeConverters[SBK_PIPELINE_STD_OPTIONAL_DOUBLE_IDX], &Pipeline::LabelNucleiParameters::DEFAULT_FIXED_THRESHOLD));
but the SbkPyQiTissue_PipelineTypeConverters is not yet initialized and thus returns a nullptr, leading to the crash in copyToPython.