From: Panayotis K. <pan...@pa...> - 2011-05-19 23:35:45
|
I have two questions: 1) what is the reason of this variable static NSObject* dispatchObject = nil; in the NSObject class of the C backend? 2) I have a JAVA_OBJECT , say "o1" This object, (in java) it has a specific method, let's say public void myMethod(Object val) {..} How do I call this method from inside C, given I have the pointer o1 of this object? |
From: Arno P. <ar...@pu...> - 2011-05-20 01:19:20
|
On 5/19/11 4:35 PM, Panayotis Katsaloulis wrote: > I have two questions: > > 1) what is the reason of this variable > > static NSObject* dispatchObject = nil; > > in the NSObject class of the C backend? The C wrapper use this object to call the performSelectorOnMainThread: method on a real Objective-C object. > 2) I have a JAVA_OBJECT , say "o1" > This object, (in java) it has a specific method, let's say > public void myMethod(Object val) {..} > > How do I call this method from inside C, given I have the pointer o1 of this object? It depends if the call is made through an interface type or class type. I suggest that you write a mini-Java program that does this call (in Java) and then cross-compile it with --target=posix. Then you can look at the generated code. Arno |
From: Panayotis K. <pan...@pa...> - 2011-05-20 06:47:33
|
First of all, thank you Arno for being for one more time helpful. On May 20, 2011, at 4:18 AM, Arno Puder wrote: > > > On 5/19/11 4:35 PM, Panayotis Katsaloulis wrote: >> I have two questions: >> >> 1) what is the reason of this variable >> >> static NSObject* dispatchObject = nil; >> >> in the NSObject class of the C backend? > > The C wrapper use this object to call the performSelectorOnMainThread: > method on a real Objective-C object. The reason I ask is because I can not find it anywhere in the code, and probably it is a leftover. >> 2) I have a JAVA_OBJECT , say "o1" >> This object, (in java) it has a specific method, let's say >> public void myMethod(Object val) {..} >> >> How do I call this method from inside C, given I have the pointer o1 of this object? > > It depends if the call is made through an interface type or class type. > I suggest that you write a mini-Java program that does this call (in > Java) and then cross-compile it with --target=posix. Then you can look > at the generated code. I want to do this in the compatibility library for arbitrary objects, in order to implement a method of an interface, so I don't know in advance what this would be. Do you believe I should use reflection then? And a last probably silly question: How do I convert an ObjC String to java_lang_String ? (and for completeness and back?) |
From: Arno P. <ar...@pu...> - 2011-05-20 06:57:06
|
On 5/19/11 11:47 PM, Panayotis Katsaloulis wrote: >>> 1) what is the reason of this variable >>> >>> static NSObject* dispatchObject = nil; >>> >>> in the NSObject class of the C backend? >> >> The C wrapper use this object to call the performSelectorOnMainThread: >> method on a real Objective-C object. > > The reason I ask is because I can not find it anywhere in the code, and probably it is a leftover. ah, ok, you are right. It is indeed a left-over. The dispatcher object is created in performSelectorOnMainThread. >>> 2) I have a JAVA_OBJECT , say "o1" >>> This object, (in java) it has a specific method, let's say >>> public void myMethod(Object val) {..} >>> >>> How do I call this method from inside C, given I have the pointer o1 of this object? >> >> It depends if the call is made through an interface type or class type. >> I suggest that you write a mini-Java program that does this call (in >> Java) and then cross-compile it with --target=posix. Then you can look >> at the generated code. > > I want to do this in the compatibility library for arbitrary objects, in order to implement a method of an interface, so I don't know in advance what this would be. > Do you believe I should use reflection then? hmm. Do you want to be able to call arbitrary *methods* or a certain method on arbitrary *objects*? For the former you need reflected, for the latter not. Actually, take a look at [DispatcherObject run] (in NSObject.m) to get an idea how you can invoke a Java method from C code. > And a last probably silly question: > How do I convert an ObjC String to java_lang_String ? > (and for completeness and back?) NSString* toNSString(JAVA_OBJECT o) JAVA_OBJECT toJavaString(NSString* str) both defined in NSString.m Arno |
From: Panayotis K. <pan...@pa...> - 2011-05-20 07:10:45
|
On May 20, 2011, at 9:56 AM, Arno Puder wrote: > > hmm. Do you want to be able to call arbitrary *methods* or a certain > method on arbitrary *objects*? For the former you need reflected, for > the latter not. Actually, take a look at [DispatcherObject run] (in > NSObject.m) to get an idea how you can invoke a Java method from C code. certain method, arbitrary objects. I did, I actually found these two parts: java_lang_reflect_Method* method = (*(JAVA_OBJECT (*)(JAVA_OBJECT, JAVA_OBJECT, JAVA_OBJECT)) targetClass->tib->vtable[XMLVM_VTABLE_IDX_java_lang_Class_getMethod___java_lang_String_java_lang_Class_1ARRAY])(targetClass, methodName, paramTypes); and (*(JAVA_OBJECT (*)(JAVA_OBJECT, JAVA_OBJECT, JAVA_OBJECT)) method->tib->vtable[XMLVM_VTABLE_IDX_java_lang_reflect_Method_invoke___java_lang_Object_java_lang_Object_1ARRAY])(method, target, params); but I am a bit confused how to decode it. Moreover it seems that they use reflection - that's why I asked. >> And a last probably silly question: >> How do I convert an ObjC String to java_lang_String ? >> (and for completeness and back?) > > NSString* toNSString(JAVA_OBJECT o) > JAVA_OBJECT toJavaString(NSString* str) > > both defined in NSString.m > Oh , I missed that part - I was looking under java_lang_String :) |
From: Paul P. <bay...@gm...> - 2011-05-25 14:55:51
|
I'm going to go off on a tangent here, not really directed at this conversation, but somewhat relevant. My opinion is that reflection is a necessary evil that should be avoided whenever possible. One of the key words in that is "necessary." A great use of reflection is for web services or other generated code. And that equivalent is appropriately used in XMLVM. I believe it is okay in this type of situation because all parts using reflection are generated & not typed by hand. E.g. a web service is generated & a client is generated, so if an update occurs, we just regenerate. The "evil" part, in my opinion, comes when developers are manually typing method names & class names into Strings, thus avoiding the compiler. This is unfortunately not a rarity in the real world, such as in configuration files. My hope is that as annotations gain muster, they will help squash that practice where they can. I realize there are exceptions to what I just said, but I still try to avoid it at all costs. Since reflection is learned at a more advanced stage, it seems it is sometimes considered advantageous & advanced to use it, but I believe that to be a misconception. Anyways, I am not trying to contradict anything in this email chain, but rather just get on my soapbox about "evil" reflection & have a conversation in general. I'm interested if anyone has some other thoughts on this. Paul On Fri, May 20, 2011 at 2:10 AM, Panayotis Katsaloulis < pan...@pa...> wrote: > > On May 20, 2011, at 9:56 AM, Arno Puder wrote: > > > hmm. Do you want to be able to call arbitrary *methods* or a certain > method on arbitrary *objects*? For the former you need reflected, for > the latter not. Actually, take a look at [DispatcherObject run] (in > NSObject.m) to get an idea how you can invoke a Java method from C code. > > > > certain method, arbitrary objects. > I did, I actually found these two parts: > java_lang_reflect_Method* method = (*(JAVA_OBJECT (*)(JAVA_OBJECT, > JAVA_OBJECT, JAVA_OBJECT)) targetClass->tib->vtable[ > XMLVM_VTABLE_IDX_java_lang_Class_getMethod___java_lang_String_java_lang_Class_1ARRAY])(targetClass, > methodName, paramTypes); > and > (*(JAVA_OBJECT (*)(JAVA_OBJECT, JAVA_OBJECT, JAVA_OBJECT)) method->tib-> > vtable[ > XMLVM_VTABLE_IDX_java_lang_reflect_Method_invoke___java_lang_Object_java_lang_Object_1ARRAY])(method, > target, params); > but I am a bit confused how to decode it. > Moreover it seems that they use reflection - that's why I asked. > > > And a last probably silly question: > > How do I convert an ObjC String to java_lang_String ? > > (and for completeness and back?) > > > NSString* toNSString(JAVA_OBJECT o) > JAVA_OBJECT toJavaString(NSString* str) > > both defined in NSString.m > > > Oh , I missed that part - I was looking under java_lang_String :) > > > > ------------------------------------------------------------------------------ > What Every C/C++ and Fortran developer Should Know! > Read this article and learn how Intel has extended the reach of its > next-generation tools to help Windows* and Linux* C/C++ and Fortran > developers boost performance applications - including clusters. > http://p.sf.net/sfu/intel-dev2devmay > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > |
From: Panayotis K. <pan...@pa...> - 2011-05-26 16:11:16
|
On May 25, 2011, at 5:55 PM, Paul Poley wrote: > I'm going to go off on a tangent here, not really directed at this conversation, but somewhat relevant. > > My opinion is that reflection is a necessary evil that should be avoided whenever possible. One of the key words in that is "necessary." A great use of reflection is for web services or other generated code. And that equivalent is appropriately used in XMLVM. I believe it is okay in this type of situation because all parts using reflection are generated & not typed by hand. E.g. a web service is generated & a client is generated, so if an update occurs, we just regenerate. > > The "evil" part, in my opinion, comes when developers are manually typing method names & class names into Strings, thus avoiding the compiler. This is unfortunately not a rarity in the real world, such as in configuration files. My hope is that as annotations gain muster, they will help squash that practice where they can. > > I realize there are exceptions to what I just said, but I still try to avoid it at all costs. Since reflection is learned at a more advanced stage, it seems it is sometimes considered advantageous & advanced to use it, but I believe that to be a misconception. > > Anyways, I am not trying to contradict anything in this email chain, but rather just get on my soapbox about "evil" reflection & have a conversation in general. I'm interested if anyone has some other thoughts on this. > > Paul Exactly, this is the spirit of this change - to get rid of reflection. :) |
From: Paul P. <bay...@gm...> - 2011-05-26 16:35:04
|
That's good! I'll get off my soapbox :) On Thu, May 26, 2011 at 11:11 AM, Panayotis Katsaloulis < pan...@pa...> wrote: > > On May 25, 2011, at 5:55 PM, Paul Poley wrote: > > > I'm going to go off on a tangent here, not really directed at this > conversation, but somewhat relevant. > > > > My opinion is that reflection is a necessary evil that should be avoided > whenever possible. One of the key words in that is "necessary." A great > use of reflection is for web services or other generated code. And that > equivalent is appropriately used in XMLVM. I believe it is okay in this > type of situation because all parts using reflection are generated & not > typed by hand. E.g. a web service is generated & a client is generated, so > if an update occurs, we just regenerate. > > > > The "evil" part, in my opinion, comes when developers are manually typing > method names & class names into Strings, thus avoiding the compiler. This > is unfortunately not a rarity in the real world, such as in configuration > files. My hope is that as annotations gain muster, they will help squash > that practice where they can. > > > > I realize there are exceptions to what I just said, but I still try to > avoid it at all costs. Since reflection is learned at a more advanced > stage, it seems it is sometimes considered advantageous & advanced to use > it, but I believe that to be a misconception. > > > > Anyways, I am not trying to contradict anything in this email chain, but > rather just get on my soapbox about "evil" reflection & have a conversation > in general. I'm interested if anyone has some other thoughts on this. > > > > Paul > > Exactly, this is the spirit of this change - to get rid of reflection. :) > > ------------------------------------------------------------------------------ > vRanger cuts backup time in half-while increasing security. > With the market-leading solution for virtual backup and recovery, > you get blazing-fast, flexible, and affordable data protection. > Download your free trial now. > http://p.sf.net/sfu/quest-d2dcopy1 > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > |