<div dir="ltr"><div>But nothing changes as I added the __dtor__<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>// typedef unsigned short BSTR;<br></div><div>%MappedType BSTR /TypeHint="str",TypeHintValue="''"/</div><div>{<br></div><div>%ConvertToTypeCode</div><div>...<br></div><div>%End</div><div><br></div><div>%ConvertFromTypeCode</div><div>
...

</div><div>%End<br>};</div><div>void __dtor__();<br>%MethodCode<br>    printf(">>>>>> __dtor__\n");<br>%End</div></blockquote><div><br></div><div>If place the __dtor__ inside the MappedType block, got syntax error when build...<br></div><div>Repace __dtor__ with __del__ is the same. Seems that __dtor__ is for struct/class only?<br></div><div><br></div><div>I can't find more information from the SIP docs.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 20, 2020 at 12:24 AM Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Have a look at %MethodCode for dtors.<br>
<br>
Phil<br>
<br>
On 19/02/2020 14:19, Weitian Leung wrote:<br>
> One more question, is it possible to insert handwritten code to the<br>
> MappeedType's release_XXX?<br>
> <br>
> When mapped one type to python's str, which type has it's own alloc <br>
> method<br>
> (The BSTR for example, SysStringAlloc etc). After passed to the C++ <br>
> call<br>
> and returned, we need to free the memory using it's own dealloc method.<br>
> <br>
> So is it possible do that? Or other way to call the dealloc method...<br>
> <br>
> On Wednesday, February 19, 2020, Weitian Leung <<a href="mailto:weitianleung@gmail.com" target="_blank">weitianleung@gmail.com</a>><br>
> wrote:<br>
>> Thanks, it works!<br>
>> <br>
>> On Wednesday, February 19, 2020, Phil Thompson <<br>
> <a href="mailto:phil@riverbankcomputing.com" target="_blank">phil@riverbankcomputing.com</a>> wrote:<br>
>>> On 17/02/2020 14:35, Weitian Leung wrote:<br>
>>>> <br>
>>>> Hi,<br>
>>>>     I'm noob in SIP. Say I have two abstract interfaces and one <br>
>>>> method<br>
> to<br>
>>>> create the object:<br>
>>>> <br>
>>>> struct IUnknown /Abstract/<br>
>>>>> <br>
>>>>> {<br>
>>>>>     virtual void AddRef() = 0;<br>
>>>>>     virtual void Release() = 0;<br>
>>>>> <br>
>>>>>     %GCClearCode<br>
>>>>>         printf("GCClearCode\n");<br>
>>>>>     %End<br>
>>>>> };<br>
>>>>> <br>
>>>>> struct IDemo : public IUnknown /Abstract/<br>
>>>>> {<br>
>>>>>     virtual void SayHi() = 0;<br>
>>>>> };<br>
>>>>> <br>
>>>> <br>
>>>> void createDemo(IDemo **demo /Out/);<br>
>>>>> <br>
>>>> <br>
>>>> <br>
>>>> Using in python side:<br>
>>>> idemo = demo.createDemo()<br>
>>>> idemo = None<br>
>>>> <br>
>>>> Is it possible to write some handwritten code that call the Release<br>
> method<br>
>>>> when idemo set to None or when  idemo doing GC?<br>
>>>> Or if we can call AddRef automatically when idemo assign to another<br>
> object.<br>
>>>> <br>
>>>> I known that on python side we can call AddRef/Release to make it <br>
>>>> works,<br>
>>>> but I want the code more python's way.<br>
>>>> <br>
>>>> The %GCClearCode handwritten code never called in this case.<br>
>>>> And the %GCTraverseCode handwritten code only call when the object <br>
>>>> make<br>
> an<br>
>>>> assignment to other object.<br>
>>>> Am I missing something?<br>
>>>> <br>
>>>> Please check the full code in the  attached file.<br>
>>> <br>
>>> <br>
> <a href="https://www.riverbankcomputing.com/static/Docs/sip/c_api.html#event-handlers" rel="noreferrer" target="_blank">https://www.riverbankcomputing.com/static/Docs/sip/c_api.html#event-handlers</a><br>
>>> <br>
>>> I've only just realised that that documentation is incomplete. The <br>
>>> two<br>
> event types currently implemented are...<br>
>>> <br>
>>> sipEventWrappedInstance,    /* After wrapping a C/C++ instance. */<br>
>>> sipEventCollectingWrapper,  /* When garbage collecting a wrapper <br>
>>> object.<br>
> */<br>
>>> <br>
>>> ...and the corresponding event handler signatures are...<br>
>>> <br>
>>> typedef void (*sipWrappedInstanceEventHandler)(void *sipCpp);<br>
>>> typedef void (*sipCollectingWrapperEventHandler)(sipSimpleWrapper<br>
> *sipSelf);<br>
>>> <br>
>>> Phil<br>
>>> <br>
<br>
</blockquote></div>