You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-dev@lucene.apache.org by Toivo Henningsson <to...@modelon.com> on 2013/08/30 14:29:01 UTC

JCC for Java -> C++ and initializeClass

Hi,

I've been using JCC successfully for a number of months for wrapping Java code to use in a C++ program.
My question is about initializeClass. Right now, I'm calling

mypackage::MyClass::initializeClass(false);

on some of my classes during initialization (in the C++ code), as I got the impression that I am supposed to do. But it doesn't seem to make a difference if I remove those calls. Is it still required, and if it is, for what?

Best regards,
Toivo

Toivo Henningsson, PhD
Software Engineer
Simulation & Optimization R&D

Phone direct: +46 46 286 22 11
Email: toivo.henningsson@modelon.com<ma...@modelon.com>

[Description: Description: Modelon_2011_Gradient_RGB_400]
________________________________
Modelon AB
Ideon Science Park
SE-223 70 Lund, Sweden

Phone: +46 46 286 2200
Fax: +46 46 286 2201


Web: http://www.modelon.com<http://www.modelon.com/>



This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.

Re: JCC for Java -> C++ and initializeClass

Posted by Andi Vajda <va...@apache.org>.
On Aug 30, 2013, at 15:55, Toivo Henningsson <to...@modelon.com> wrote:

>> -----Original Message-----
>> From: Andi Vajda [mailto:vajda@apache.org]
>> Sent: den 30 augusti 2013 15:13
>> To: pylucene-dev@lucene.apache.org
>> Subject: Re: JCC for Java -> C++ and initializeClass
>> 
>> 
>> On Fri, 30 Aug 2013, Toivo Henningsson wrote:
>> 
>>> I've been using JCC successfully for a number of months for wrapping Java
>> code to use in a C++ program.
>>> My question is about initializeClass. Right now, I'm calling
>>> 
>>> mypackage::MyClass::initializeClass(false);
>>> 
>>> on some of my classes during initialization (in the C++ code), as I got the
>> impression that I am supposed to do. But it doesn't seem to make a difference if
>> I remove those calls. Is it still required, and if it is, for what?
>> 
>> initializeClass() is called for you, lazily, when the C++ wrapper class constructor is
>> called for the first time.
>> You can see this in the generated .h files.
> 
> Ok, great!
> 
> So it's only if I need to use something inside of a class before creating any instances that I need to call initializeClass()?

How could you other than static data ?
Check the source for the class first to see if what you're accessing calls initializeClass() for you.

Andi..

> 
>> If initializeClass() were not called for you, your code would be crashing really
>> fast.
> 
> I suspected as much :)
> 
> / Toivo
> 
> Toivo Henningsson, PhD
> Software Engineer
> Simulation & Optimization R&D
> 
> Phone direct: +46 46 286 22 11
> Email: toivo.henningsson@modelon.com
> 
> 
> 
> Modelon AB
> Ideon Science Park
> SE-223 70 Lund, Sweden Phone: +46 46 286 2200
> Fax: +46 46 286 2201
> Web: http://www.modelon.com
> This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.
> 

RE: JCC for Java -> C++ and initializeClass

Posted by Toivo Henningsson <to...@modelon.com>.
> -----Original Message-----
> From: Andi Vajda [mailto:vajda@apache.org]
> Sent: den 2 september 2013 10:00
> To: Toivo Henningsson
> Cc: pylucene-dev@lucene.apache.org
> Subject: Re: JCC for Java -> C++ and initializeClass
> > My only question now is: Do you plan to keep the other three cases (calling
> static/nonstatic methods, access to instance fields) safe when it comes to
> initializeClass?
> > Then I can write my code under that assumption.
>
> Yes, this has been quite stable and I don't anticipate any changes there.

Great, thanks!
 / Toivo

Toivo Henningsson, PhD
Software Engineer
Simulation & Optimization R&D

Phone direct: +46 46 286 22 11
Email: toivo.henningsson@modelon.com



Modelon AB
Ideon Science Park
SE-223 70 Lund, Sweden Phone: +46 46 286 2200
Fax: +46 46 286 2201
Web: http://www.modelon.com
This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.


Re: JCC for Java -> C++ and initializeClass

Posted by Andi Vajda <va...@apache.org>.
On Sep 2, 2013, at 9:56, Toivo Henningsson <to...@modelon.com> wrote:

>> -----Original Message-----
>> From: Andi Vajda [mailto:vajda@apache.org]
>> Sent: den 30 augusti 2013 16:11
>> To: Toivo Henningsson
>> Cc: pylucene-dev@lucene.apache.org
>> Subject: Re: JCC for Java -> C++ and initializeClass
>> 
>> 
>> On Aug 30, 2013, at 15:55, Toivo Henningsson
>> <to...@modelon.com> wrote:
>> 
>>>> -----Original Message-----
>>>> From: Andi Vajda [mailto:vajda@apache.org]
>>>> Sent: den 30 augusti 2013 15:13
>>>> To: pylucene-dev@lucene.apache.org
>>>> Subject: Re: JCC for Java -> C++ and initializeClass
>>>> 
>>>> 
>>>> On Fri, 30 Aug 2013, Toivo Henningsson wrote:
>>>> 
>>>>> I've been using JCC successfully for a number of months for wrapping
>>>>> Java
>>>> code to use in a C++ program.
>>>>> My question is about initializeClass. Right now, I'm calling
>>>>> 
>>>>> mypackage::MyClass::initializeClass(false);
>>>>> 
>>>>> on some of my classes during initialization (in the C++ code), as I
>>>>> got the
>>>> impression that I am supposed to do. But it doesn't seem to make a
>>>> difference if I remove those calls. Is it still required, and if it is, for what?
>>>> 
>>>> initializeClass() is called for you, lazily, when the C++ wrapper
>>>> class constructor is called for the first time.
>>>> You can see this in the generated .h files.
>>> 
>>> Ok, great!
>>> 
>>> So it's only if I need to use something inside of a class before creating any
>> instances that I need to call initializeClass()?
>> 
>> Thinking about this, from C++, there may be holes. From Python, when import
>> on the Python wrapper is called, initializeClass() ends up being called too.
> 
> I looked a bit at the source (generated and otherwise), and my conclusion was that
> * initializeClass() looks up class, method, field ids and static fields ==> it needs to be called before
>   * calling methods on the class (also static ones)
>   * accessing fields in the class
> * intializeClass() is called when
>   * a wrapper instance is created
>   * a static method is called
> I think that this leaves only the case when accessing a static field, which indeed is a hole.
> 
> My only question now is: Do you plan to keep the other three cases (calling static/nonstatic methods, access to instance fields) safe when it comes to initializeClass?
> Then I can write my code under that assumption.

Yes, this has been quite stable and I don't anticipate any changes there.

Andi..

> 
> / Toivo
> 
> Toivo Henningsson, PhD
> Software Engineer
> Simulation & Optimization R&D
> 
> Phone direct: +46 46 286 22 11
> Email: toivo.henningsson@modelon.com
> 
> 
> 
> Modelon AB
> Ideon Science Park
> SE-223 70 Lund, Sweden Phone: +46 46 286 2200
> Fax: +46 46 286 2201
> Web: http://www.modelon.com
> This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.
> 

RE: JCC for Java -> C++ and initializeClass

Posted by Toivo Henningsson <to...@modelon.com>.
> -----Original Message-----
> From: Andi Vajda [mailto:vajda@apache.org]
> Sent: den 30 augusti 2013 16:11
> To: Toivo Henningsson
> Cc: pylucene-dev@lucene.apache.org
> Subject: Re: JCC for Java -> C++ and initializeClass
>
>
> On Aug 30, 2013, at 15:55, Toivo Henningsson
> <to...@modelon.com> wrote:
>
> >> -----Original Message-----
> >> From: Andi Vajda [mailto:vajda@apache.org]
> >> Sent: den 30 augusti 2013 15:13
> >> To: pylucene-dev@lucene.apache.org
> >> Subject: Re: JCC for Java -> C++ and initializeClass
> >>
> >>
> >> On Fri, 30 Aug 2013, Toivo Henningsson wrote:
> >>
> >>> I've been using JCC successfully for a number of months for wrapping
> >>> Java
> >> code to use in a C++ program.
> >>> My question is about initializeClass. Right now, I'm calling
> >>>
> >>> mypackage::MyClass::initializeClass(false);
> >>>
> >>> on some of my classes during initialization (in the C++ code), as I
> >>> got the
> >> impression that I am supposed to do. But it doesn't seem to make a
> >> difference if I remove those calls. Is it still required, and if it is, for what?
> >>
> >> initializeClass() is called for you, lazily, when the C++ wrapper
> >> class constructor is called for the first time.
> >> You can see this in the generated .h files.
> >
> > Ok, great!
> >
> > So it's only if I need to use something inside of a class before creating any
> instances that I need to call initializeClass()?
>
> Thinking about this, from C++, there may be holes. From Python, when import
> on the Python wrapper is called, initializeClass() ends up being called too.

I looked a bit at the source (generated and otherwise), and my conclusion was that
 * initializeClass() looks up class, method, field ids and static fields ==> it needs to be called before
   * calling methods on the class (also static ones)
   * accessing fields in the class
 * intializeClass() is called when
   * a wrapper instance is created
   * a static method is called
I think that this leaves only the case when accessing a static field, which indeed is a hole.

My only question now is: Do you plan to keep the other three cases (calling static/nonstatic methods, access to instance fields) safe when it comes to initializeClass?
Then I can write my code under that assumption.

 / Toivo

Toivo Henningsson, PhD
Software Engineer
Simulation & Optimization R&D

Phone direct: +46 46 286 22 11
Email: toivo.henningsson@modelon.com



Modelon AB
Ideon Science Park
SE-223 70 Lund, Sweden Phone: +46 46 286 2200
Fax: +46 46 286 2201
Web: http://www.modelon.com
This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.


Re: JCC for Java -> C++ and initializeClass

Posted by Andi Vajda <va...@apache.org>.
On Aug 30, 2013, at 15:55, Toivo Henningsson <to...@modelon.com> wrote:

>> -----Original Message-----
>> From: Andi Vajda [mailto:vajda@apache.org]
>> Sent: den 30 augusti 2013 15:13
>> To: pylucene-dev@lucene.apache.org
>> Subject: Re: JCC for Java -> C++ and initializeClass
>> 
>> 
>> On Fri, 30 Aug 2013, Toivo Henningsson wrote:
>> 
>>> I've been using JCC successfully for a number of months for wrapping Java
>> code to use in a C++ program.
>>> My question is about initializeClass. Right now, I'm calling
>>> 
>>> mypackage::MyClass::initializeClass(false);
>>> 
>>> on some of my classes during initialization (in the C++ code), as I got the
>> impression that I am supposed to do. But it doesn't seem to make a difference if
>> I remove those calls. Is it still required, and if it is, for what?
>> 
>> initializeClass() is called for you, lazily, when the C++ wrapper class constructor is
>> called for the first time.
>> You can see this in the generated .h files.
> 
> Ok, great!
> 
> So it's only if I need to use something inside of a class before creating any instances that I need to call initializeClass()?

Thinking about this, from C++, there may be holes. From Python, when import on the Python wrapper is called, initializeClass() ends up being called too.

Andi..

> 
>> If initializeClass() were not called for you, your code would be crashing really
>> fast.
> 
> I suspected as much :)
> 
> / Toivo
> 
> Toivo Henningsson, PhD
> Software Engineer
> Simulation & Optimization R&D
> 
> Phone direct: +46 46 286 22 11
> Email: toivo.henningsson@modelon.com
> 
> 
> 
> Modelon AB
> Ideon Science Park
> SE-223 70 Lund, Sweden Phone: +46 46 286 2200
> Fax: +46 46 286 2201
> Web: http://www.modelon.com
> This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.
> 

RE: JCC for Java -> C++ and initializeClass

Posted by Toivo Henningsson <to...@modelon.com>.
> -----Original Message-----
> From: Andi Vajda [mailto:vajda@apache.org]
> Sent: den 30 augusti 2013 15:13
> To: pylucene-dev@lucene.apache.org
> Subject: Re: JCC for Java -> C++ and initializeClass
>
>
> On Fri, 30 Aug 2013, Toivo Henningsson wrote:
>
> > I've been using JCC successfully for a number of months for wrapping Java
> code to use in a C++ program.
> > My question is about initializeClass. Right now, I'm calling
> >
> > mypackage::MyClass::initializeClass(false);
> >
> > on some of my classes during initialization (in the C++ code), as I got the
> impression that I am supposed to do. But it doesn't seem to make a difference if
> I remove those calls. Is it still required, and if it is, for what?
>
> initializeClass() is called for you, lazily, when the C++ wrapper class constructor is
> called for the first time.
> You can see this in the generated .h files.

Ok, great!

So it's only if I need to use something inside of a class before creating any instances that I need to call initializeClass()?

> If initializeClass() were not called for you, your code would be crashing really
> fast.

I suspected as much :)

 / Toivo

Toivo Henningsson, PhD
Software Engineer
Simulation & Optimization R&D

Phone direct: +46 46 286 22 11
Email: toivo.henningsson@modelon.com



Modelon AB
Ideon Science Park
SE-223 70 Lund, Sweden Phone: +46 46 286 2200
Fax: +46 46 286 2201
Web: http://www.modelon.com
This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.


Re: JCC for Java -> C++ and initializeClass

Posted by Andi Vajda <va...@apache.org>.
On Fri, 30 Aug 2013, Toivo Henningsson wrote:

> I've been using JCC successfully for a number of months for wrapping Java code to use in a C++ program.
> My question is about initializeClass. Right now, I'm calling
>
> mypackage::MyClass::initializeClass(false);
>
> on some of my classes during initialization (in the C++ code), as I got the impression that I am supposed to do. But it doesn't seem to make a difference if I remove those calls. Is it still required, and if it is, for what?

initializeClass() is called for you, lazily, when the C++ wrapper class 
constructor is called for the first time.
You can see this in the generated .h files.

If initializeClass() were not called for you, your code would be crashing
really fast.

Andi..

>
> Best regards,
> Toivo
>
> Toivo Henningsson, PhD
> Software Engineer
> Simulation & Optimization R&D
>
> Phone direct: +46 46 286 22 11
> Email: toivo.henningsson@modelon.com<ma...@modelon.com>
>
> [Description: Description: Modelon_2011_Gradient_RGB_400]
> ________________________________
> Modelon AB
> Ideon Science Park
> SE-223 70 Lund, Sweden
>
> Phone: +46 46 286 2200
> Fax: +46 46 286 2201
>
>
> Web: http://www.modelon.com<http://www.modelon.com/>
>
>
>
> This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Modelon does not accept or assume any liability or responsibility for any use of or reliance on this email.
>