Re: Make SWIG generated Java interface file not visible outside package
William S Fulton <[email protected]> Fri, 9 Aug 2024 19:32:32 +0100
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftCMyOVS-TvdAObpO1zpOFjPvu7kU9u2rhZpuFsrW42CCQ@mail.gmail.com> |
--===============3204119881326379250== Content-Type: multipart/alternative; boundary="000000000000f1ff69061f445f24" --000000000000f1ff69061f445f24 Content-Type: text/plain; charset="UTF-8" I've added support for the constantsmodifiers pragma for changing the visibility from public to default. See the commit https://github.com/swig/swig/commit/51b281eff092b074b3780d056444a9dc4f8b82b2 which has details and examples. This will go into swig-4.3.0. William On Tue, 25 Jun 2024 at 07:09, lille stor <[email protected]> wrote: > Hi William, > > Thanks for the info! > > I'm a bit confused now... I though that the sole purpose of typemap > "javainterfacemodifiers" was to actually change, e.g., the visibility of > the generated Java interface class. See this commit: > https://github.com/swig/swig/commit/c1b004f4fa62b1b15e047fd9462ddf3b46e55357 > <https://deref-gmx.com/mail/client/gVi7LFeAy8M/dereferrer/?redirectUrl=https%3A%2F%2Fgithub.com%2Fswig%2Fswig%2Fcommit%2Fc1b004f4fa62b1b15e047fd9462ddf3b46e55357>. > Also, when looking at this line > https://github.com/swig/swig/blob/ce2bb71a486bd575afb3c19ef98aae5f5e147905/Source/Modules/java.cxx#L2098 > <https://deref-gmx.com/mail/client/8i3vhEUjpo0/dereferrer/?redirectUrl=https%3A%2F%2Fgithub.com%2Fswig%2Fswig%2Fblob%2Fce2bb71a486bd575afb3c19ef98aae5f5e147905%2FSource%2FModules%2Fjava.cxx%23L2098> > (in java.cxx), it seems to indicate that. > > Not sure how to proceed from here... thanks for the clarification! > > > > *Sent:* Friday, June 21, 2024 at 4:05 PM > *From:* "William S Fulton" <[email protected]> > *To:* "lille stor" <[email protected]> > *Cc:* [email protected] > *Subject:* Re: [Swig-user] Make SWIG generated Java interface file not > visible outside package > > This is not possible as it is hard coded to 'public'. We could add in some > pragmas similar to the Java module class pragmas > https://swig.org/Doc4.2/Java.html#Java_module_class_pragmas to provide > this flexibility. I suggest adding in a Github issue for this. > > William > > On Thu, 20 Jun 2024 at 10:21, lille stor via Swig-user < > [email protected]> wrote: > >> I am using SWIG (version 4.2.1) to generate a Java wrapper for some C >> code. This C code has some constants that SWIG represents with the Java >> interface file below. As it stands, this interface can be accessed by >> classes outside the "abc" package because it is declared as "public". >> >> /* >> ---------------------------------------------------------------------------- >> * This file was automatically generated by SWIG ( >> http://www.swig.org). >> * Version 4.2.1 >> * >> * Do not make changes to this file unless you know what you are >> doing--modify >> * the SWIG interface file instead. >> * >> ----------------------------------------------------------------------------- >> */ >> package abc; >> public interface TestConstants { >> public final static int YES = TestJNI.YES_get(); >> public final static int NO = TestJNI.NO_get(); >> public final static int ENABLED = TestJNI.ENABLED_get(); >> public final static int DISABLED = TestJNI.DISABLED_get(); >> } >> >> >> How can I make this interface visible only to classes within the same >> package (i.e., change "public interface TestConstants" to just "interface >> TestConstants")? I have tried: >> >> %typemap(javainterfacemodifiers) SWIGTYPE "interface" >> >> ... but it did not work. How can I achieve this using SWIG? >> >> _______________________________________________ >> Swig-user mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/swig-user > > --000000000000f1ff69061f445f24 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>I've added support for the constantsmodifiers pra= gma for changing the visibility from public to default. See the commit <a h= ref=3D"https://github.com/swig/swig/commit/51b281eff092b074b3780d056444a9dc= 4f8b82b2">https://github.com/swig/swig/commit/51b281eff092b074b3780d056444a= 9dc4f8b82b2</a> which has details and examples. This will go into swig-4.3.= 0.<br></div><div><br></div><div>William<br></div><div><br></div></div><br><= div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, 25 = Jun 2024 at 07:09, lille stor <<a href=3D"mailto:[email protected]">lil= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad= ding-left:1ex"><div><div style=3D"font-family:Verdana;font-size:12px"><div> <div>Hi William,<br> <br> Thanks for the info!<br> <br> I'm a bit confused now... I though that the sole purpose of typemap &qu= ot;javainterfacemodifiers" was to actually change, e.g., the visibilit= y of the generated Java interface class. See this commit: <a href=3D"https:= //deref-gmx.com/mail/client/gVi7LFeAy8M/dereferrer/?redirectUrl=3Dhttps%3A%= 2F%2Fgithub.com%2Fswig%2Fswig%2Fcommit%2Fc1b004f4fa62b1b15e047fd9462ddf3b46= e55357" target=3D"_blank">https://github.com/swig/swig/commit/c1b004f4fa62b= 1b15e047fd9462ddf3b46e55357</a>. Also, when looking at this line <a href=3D= "https://deref-gmx.com/mail/client/8i3vhEUjpo0/dereferrer/?redirectUrl=3Dht= tps%3A%2F%2Fgithub.com%2Fswig%2Fswig%2Fblob%2Fce2bb71a486bd575afb3c19ef98aa= e5f5e147905%2FSource%2FModules%2Fjava.cxx%23L2098" target=3D"_blank">https:= //github.com/swig/swig/blob/ce2bb71a486bd575afb3c19ef98aae5f5e147905/Source= /Modules/java.cxx#L2098</a> (in java.cxx), it seems to indicate that.<br> <br> Not sure how to proceed from here... thanks for the clarification!</div> <div>=C2=A0</div> <div>=C2=A0</div> <div>=C2=A0 <div name=3D"quote" style=3D"margin:10px 5px 5px 10px;padding:10px 0px 10px= 10px;border-left:2px solid rgb(195,217,229)"> <div style=3D"margin:0px 0px 10px"><b>Sent:</b>=C2=A0Friday, June 21, 2024 = at 4:05 PM<br> <b>From:</b>=C2=A0"William S Fulton" <<a href=3D"mailto:wsf@fu= ltondesigns.co.uk" target=3D"_blank">[email protected]</a>><br> <b>To:</b>=C2=A0"lille stor" <<a href=3D"mailto:lille.stor@gmx= .com" target=3D"_blank">[email protected]</a>><br> <b>Cc:</b>=C2=A0<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a><br> <b>Subject:</b>=C2=A0Re: [Swig-user] Make SWIG generated Java interface fil= e not visible outside package</div> <div name=3D"quoted-content"> <div> <div>=C2=A0</div> <div>This is not possible as it is hard coded to 'public'. We could= add in some pragmas similar to the Java module class pragmas <a href=3D"ht= tps://swig.org/Doc4.2/Java.html#Java_module_class_pragmas" target=3D"_blank= ">https://swig.org/Doc4.2/Java.html#Java_module_class_pragmas</a> to provid= e this flexibility. I suggest adding in a Github issue for this.</div> <div>=C2=A0</div> <div>William</div> </div> =C2=A0 <div class=3D"gmail_quote"> <div class=3D"gmail_attr">On Thu, 20 Jun 2024 at 10:21, lille stor via Swig= -user <<a href=3D"mailto:[email protected]" target=3D"_bla= nk">[email protected]</a>> wrote:</div> <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-= left:1px solid rgb(204,204,204);padding-left:1ex"> <div> <div style=3D"font-family:Verdana;font-size:12px"> <div>I am using SWIG (version 4.2.1) to generate a Java wrapper for some C = code. This C code has some constants that SWIG represents with the Java int= erface file below. As it stands, this interface can be accessed by classes = outside the "abc" package because it is declared as "public&= quot;.</div> <div>=C2=A0</div> <div> <div>=C2=A0=C2=A0=C2=A0=C2=A0 /* ------------------------------------------= ----------------------------------<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* This file was automatically generated by S= WIG (<a href=3D"http://www.swig.org" target=3D"_blank">http://www.swig.org<= /a>).<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* Version 4.2.1<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0*<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* Do not make changes to this file unless yo= u know what you are doing--modify<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* the SWIG interface file instead.<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* ------------------------------------------= ----------------------------------- */</div> <div>=C2=A0=C2=A0=C2=A0=C2=A0 package abc;</div> <div>=C2=A0=C2=A0=C2=A0=C2=A0 public interface TestConstants {<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati= c int YES =3D TestJNI.YES_get();<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati= c int NO =3D TestJNI.NO_get();<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati= c int ENABLED =3D TestJNI.ENABLED_get();<br> =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 public final stati= c int DISABLED =3D TestJNI.DISABLED_get();<br> =C2=A0=C2=A0=C2=A0=C2=A0 }</div> <div>=C2=A0</div> </div> <div>=C2=A0</div> <div>How can I make this interface visible only to classes within the same = package (i.e., change "public interface TestConstants" to just &q= uot;interface TestConstants")? I have tried:</div> <div>=C2=A0</div> <div>=C2=A0=C2=A0=C2=A0=C2=A0 %typemap(javainterfacemodifiers) SWIGTYPE &qu= ot;interface"</div> <div>=C2=A0</div> <div>... but it did not work. How can I achieve this using SWIG?</div> <div>=C2=A0</div> </div> </div> _______________________________________________<br> Swig-user mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Swig-u= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/swig-user" target= =3D"_blank">https://lists.sourceforge.net/lists/listinfo/swig-user</a></blo= ckquote> </div> </div> </div> </div> </div></div></div> </blockquote></div> --000000000000f1ff69061f445f24-- --===============3204119881326379250== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============3204119881326379250== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user --===============3204119881326379250==--