On Jul 5, 2013, at 1:34, Johan Jonkers <[email protected]> wrote:
> On 7/5/13 10:16 AM, Andi Vajda wrote:
>> On Jul 5, 2013, at 0:11, Johan Jonkers <[email protected]> wrote:
>>
>>> Hi Andi,
>>>
>>> I was able to compile it all into one module and that worked perfectly.
>>>
>>> I then tried to compile it again into two seperate modules and compared the
>>> generated wrappers. What I saw was that all methods in the SumWrapper class
>>> that had a reference to the Sum class were not wrapped (didn't see them in
>>> SumWrapper.h). I also checked the output to see if there was some sort of
>>> notification/warning saying there was a problem with these methods but
>>> didn't see anything.
>>> I am thinking that they aren't being wrapped because they somehow can't be
>>> resolved. I tried looking in the JCC code where that happens but haven't
>>> been very successful at that so far.
>> Please, list the commands you used. It's easier to debug this way.
>> Did you list the Sum class on the second jcc command line ?
> Below is part of the script I use to compile the modules.
>
> javac nl/seecr/freestyle/Sum.java -d build_seecr
> (cd build_seecr; jar -c nl > ../seecr.jar)
> javac org/cq2/freestyle/SumWrapper.java -d build_cq2 -cp ./seecr.jar
> (cd build_cq2; jar -c org > ../cq2.jar)
>
> JCC="python -m jcc.__main__"
>
> echo '#
> # Building CQ2 module
> #
> '
>
> ${JCC} \
> --root ${ROOT} \
> --use_full_names \
> --shared \
> --arch x86_64 \
> --jar cq2.jar \
> --classpath ./seecr.jar \
Why are you listing seecr.jar here ?
Andi..
> --python cq2 \
> --build \
> --install
>
> echo '#
> # Building Seecr module
> #
> '
>
> export PYTHONPATH=$(find ${ROOT} -type d -name "site-packages" | head -n 1)
> ${JCC} \
> --root ${ROOT} \
> --use_full_names \
> --import cq2 \
> --shared \
> --arch x86_64 \
> --jar seecr.jar \
> --python seecr \
> --build \
> --install \
> nl.seecr.freestyle.Sum
>>
>> Andi..
>>
>>> Regards,
>>>
>>> Johan
>>>
>>>
>>> On 7/4/13 10:18 PM, Andi Vajda wrote:
>>>> On Thu, 4 Jul 2013, Johan Jonkers wrote:
>>>>
>>>>> I've tried added the Sum class to the 2nd JCC call but it didn't solve
>>>>> the problem. The 'asSum' method isn't getting wrapped. Also,
>>>>> instantiating a SumWrapper with a Sum as argument results in the
>>>>> constructor without parameters being called; which I wasn't expecting.
>>>>>
>>>>>>>> c=SumWrapper(Sum(10))
>>>>> Empty constructor
>>>>>
>>>>> I tried compiling everything into one file and then I do get the asSum
>>>>> method wrapped but the constructor with a Sum as argument doesn't seem to
>>>>> work still. It doesn't call the empty constructor anymore but neither
>>>>> does it seem to set Sum object passed to it. I am a bit at a loss here on
>>>>> whats going wrong (or what I am doing wrong).
>>>> Yeah, let's take one thing at a time and the simpler one first.
>>>> Compiling all into one module, I was not able to reproduce the problem as
>>>> reported. I'm able to make a SumWrapper(Sum(10)) just fine.
>>>>
>>>> Here are the commands I used to try to reproduce this:
>>>>
>>>> - created two class files Sum.java and SumWrapper.java in their respective
>>>> packages as specified in your example
>>>> - mkdir classes
>>>> - javac -d classes *.java
>>>> - jar -cvf sum.jar -C classes .
>>>> - python -m jcc.__main__ --shared --arch x86_64 --use_full_names --jar
>>>> sum.jar --classpath . --python sum --build --install
>>>> - python
>>>> - import sum
>>>> - sum.initVM()
>>>> <jcc.JCCEnv object at 0x10029c0f0>
>>>> - from nl.seecr.freestyle import Sum
>>>> - from org.cq2.freestyle import SumWrapper
>>>> - Sum(10)
>>>> <Sum: nl.seecr.freestyle.Sum@64fef26a>
>>>> - SumWrapper(Sum(10))
>>>> <SumWrapper: org.cq2.freestyle.SumWrapper@70e69696>
>>>>
>>>> Please try to reproduce these steps and report back.
>>>> Once that works, let's move on to the problem of compiling these into
>>>> separate extension modules.
>>>>
>>>> Andi..
>>>>
>>>>> Any thoughts on this problem would be appreciated :-)
>>>>>
>>>>> Regards,
>>>>>
>>>>> Johan
>>>>>
>>>>> On 7/1/13 8:00 PM, Andi Vajda wrote:
>>>>>> On Mon, 1 Jul 2013, Johan Jonkers wrote:
>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I have been playing around with JCC to see if it would provide in the
>>>>>>> needs we have here at work to interface Java with Python. I have
>>>>>>> encountered one issue in which I hope someone on this mailinglist might
>>>>>>> be able to help me with. If this is not the right place to ask then I
>>>>>>> apologize in advance.
>>>>>>>
>>>>>>> This issue I am having is that I would like to create two packages
>>>>>>> compiled with JCC in which classes from one package are used by classes
>>>>>>> in the other pacakge. I would like to use those classes in Python but
>>>>>>> am having problems doing so that I don't understand yet.
>>>>>>>
>>>>>>> In package 1 is the class shown below:
>>>>>>>
>>>>>>> package nl.seecr.freestyle;
>>>>>>>
>>>>>>> public class Sum {
>>>>>>> private int _sum;
>>>>>>>
>>>>>>> public Sum() {
>>>>>>> _sum = 0;
>>>>>>> }
>>>>>>>
>>>>>>> public void add(int value) {
>>>>>>> _sum += value;
>>>>>>> }
>>>>>>>
>>>>>>> public int value() {
>>>>>>> return _sum;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> The second package holds a class what uses the Sum Class:
>>>>>>>
>>>>>>> package org.cq2.freestyle;
>>>>>>>
>>>>>>> import nl.seecr.freestyle.Sum;
>>>>>>>
>>>>>>> public class SumWrapper {
>>>>>>>
>>>>>>> private Sum total;
>>>>>>>
>>>>>>> public SumWrapper() {
>>>>>>> this(new Sum());
>>>>>>> System.out.println("Empty constructor");
>>>>>>> }
>>>>>>>
>>>>>>> public SumWrapper(Sum sum) {
>>>>>>> total = sum;
>>>>>>> }
>>>>>>>
>>>>>>> public void add(int value) {
>>>>>>> total.add(value);
>>>>>>> }
>>>>>>>
>>>>>>> public int value() {
>>>>>>> return total.value();
>>>>>>> }
>>>>>>>
>>>>>>> public Sum asSum() {
>>>>>>> Sum sum = new Sum();
>>>>>>> sum.add(value());
>>>>>>> return sum;
>>>>>>> }
>>>>>>>
>>>>>>> public void printValue() {
>>>>>>> System.out.println(value());
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> I can compile these classes into .class files and put them in jars and
>>>>>>> have those compiled with JCC:
>>>>>>> python -m jcc \
>>>>>>> --root ${ROOT} \
>>>>>>> --use_full_names \
>>>>>>> --shared \
>>>>>>> --arch x86_64 \
>>>>>>> --jar cq2.jar \
>>>>>>> --classpath ./seecr.jar \
>>>>>>> --python cq2 \
>>>>>>> --build \
>>>>>>> --install
>>>>>>>
>>>>>>> export PYTHON_PATH=${ROOT}/usr/local/lib/python2.7/dist-packages
>>>>>>> python -m jcc \
>>>>>>> --root ${ROOT} \
>>>>>>> --use_full_names \
>>>>>>> --import cq2 \
>>>>>>> --shared \
>>>>>>> --arch x86_64 \
>>>>>>> --jar seecr.jar \
>>>>>>> --python seecr \
>>>>>>> --build \
>>>>>>> --install
>>>>>>>
>>>>>>> In my understanding the "--import cq2" argument should prevent jcc from
>>>>>>> creating a wrapper for the Sum class in the seecr package itself but
>>>>>>> use the one in the cq2 package.
>>>>>>>
>>>>>>> This all compiles without errors but when I run the following python
>>>>>>> program:
>>>>>>>
>>>>>>> import seecr
>>>>>>> seecr.initVM()
>>>>>>>
>>>>>>> import cq2
>>>>>>> cq2.initVM()
>>>>>>>
>>>>>>> from nl.seecr.freestyle import Sum
>>>>>>> from org.cq2.freestyle import SumWrapper
>>>>>>>
>>>>>>> sum = Sum()
>>>>>>> sum.add(5)
>>>>>>> print "Sum value", sum.value()
>>>>>>>
>>>>>>> wrapper = SumWrapper(sum)
>>>>>>> print wrapper.value()
>>>>>>>
>>>>>>> The 1st print shows the value 5 as expected. The 2nd print however
>>>>>>> shows 0 and I had not expected that. If I run the same program in Java
>>>>>>> and use the jars I created earlier, the 2nd print shows 5 (as
>>>>>>> expected). The "Empty constructor" message is also shown when running
>>>>>>> this python program and I had not expected that to happen.
>>>>>>>
>>>>>>> The "asSum" method in the SumWrapper class is not available in the
>>>>>>> Python version of the class. I do not understand yet why that is.
>>>>>>>
>>>>>>> I haven't been able to find many examples or documentation on the
>>>>>>> options for compiling with JCC. I am hoping that someone here on the
>>>>>>> mailinglist can point me in the right direction. Any help would be
>>>>>>> really appreciated.
>>>>>> I haven't had time yet to reproduce the problem but you may want to try
>>>>>> to add an explicit request to wrap the Sum class - by just listing it on
>>>>>> the second jcc call command line. No wrapper will be generated for it,
>>>>>> because of the --import statement, but methods in the second jar with
>>>>>> Sum in their signature should then get wrapped.
>>>>>>
>>>>>> python -m jcc \
>>>>>> --root ${ROOT} \
>>>>>> --use_full_names \
>>>>>> --import cq2 \
>>>>>> --shared \
>>>>>> --arch x86_64 \
>>>>>> --jar seecr.jar \
>>>>>> --python seecr \
>>>>>> --build \
>>>>>> --install \
>>>>>> nl.seecr.freestyle.Sum
>>>>>>
>>>>>> Andi..
>>>>>
>>>>> --
>>>>> Johan Jonkers ? seecr.nl ? +31 (0) 655 734 175
>>>
>>> --
>>> Johan Jonkers ♦ seecr.nl ♦ +31 (0) 655 734 175
>
>
> --
> Johan Jonkers ♦ seecr.nl ♦ +31 (0) 655 734 175