Re: How to inject code at the top and bottom of each method generated in cpp wrap file by SWIG?
prajjwal prem <[email protected]> Tue, 25 Apr 2023 10:14:10 -0600
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CADqCKMxCtjXZNZ2MitFwAwmwg=B7G_QE_1G58uNb1BSCZx1cbg@mail.gmail.com> |
Hi Jim, Thanks for the solution. The typemap(ret) works perfectly for injecting the code at the end. But using typemap(check) does not include the declaration of the result variable. The c++ default constructor for result needs to be inside the injected mutex code. I tried using the optimal flag in typemap(out) but exception handling code overrides that behavior. Is there a way to tell swig that declaration of the result variable should be after the typemap(check)? Once again thanks for the solution above. On Mon, Apr 24, 2023 at 8:30 PM Jim <[email protected]> wrote: > > Hi Prajjwal, > You can try this : > > %typemap(ret) SWIGTYPE { > //inject-1 > } > > %typemap(ret) SWIGTYPE & { > //inject-2 > } > > %typemap(ret) SWIGTYPE * { > //inject-3 > } > > %typemap(check) SWIGTYPE * { > //inject-4 > } > > %typemap(check) SWIGTYPE { > //inject-5 > } > > Note: keyword *SWIGTYPE* math any type(eg int\long\bool\T)。*SWIGTYPE &* > match any reference type (eg. int & \ long & \ bool& \ T&)。 You can add > different typemap according to your function type as needed。 > > > > > At 2023-04-25 05:27:05, "prajjwal prem" <[email protected]> wrote: > > Hi All, > > How to inject code at the top and bottom of each method generated in cpp > wrap file by SWIG? > > For Example: > > SWIGEXPORT int SWIGSTDCALL CSharp_swig_generated_method___(void *jarg1) > > { > > int jresult; //SWIG generated > > > > *// inject code here like mutex begin* > > > > /* > > SWIG generated code > > */ > > > > jresult = result; > > > > *// inject code here like mutex end* > > > > return jresult; > > } > > > Best regards, > > Prajjwal > > _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user