Omaha #4259 more cleanup of jep

Change-Id: I84a44ea8219132033f60ed3534fe0f00d9b5bbca

Former-commit-id: 022055f57c46cafe125cd407c2e384c46a5a8ead
This commit is contained in:
Nate Jensen 2015-04-14 11:06:51 -05:00
parent 1ea2da949f
commit a6491bd9d8
33 changed files with 901 additions and 931 deletions

View file

@ -1,6 +1,5 @@
package jep;
/**
* <pre>
* ClassEnquirer.java - Interface to enquire if a name is available
@ -8,6 +7,16 @@ package jep;
* determine if an attempt to import a module/class should be directed
* to the Python importer or the Java importer.
*
* TODO: Implement an OSGi class enquirer. Implement a pseudo-secure
* class enquirer. jep.findClass(name) ignores the import hook and wouldn't
* go through the secure enquirer, so it would still require a restricted
* ClassLoader to be secure. However, they could potentially be used in
* tandem for faster performance or dynamic behavior.
*
* TODO Potentially add a method to get a list of sub-packages. However,
* for the most part that won't work for any implementations except ClassList
* so perhaps it shouldn't be on the interface.
*
*
* Copyright (c) 2015 JEP AUTHORS.
*
@ -42,42 +51,56 @@ package jep;
public interface ClassEnquirer {
/**
* Checks if the name is likely available in Java. A return
* value of true implies the name corresponds to a Java package or class, but
* does not guarantee that an import will succeed. A return value of false
* implies that an import from Java would fail, but does not guarantee that an
* Checks if the name is likely available in Java. A return value of true
* implies the name corresponds to a Java package or class, but does not
* guarantee that an import will succeed. A return value of false implies
* that an import from Java would fail, but does not guarantee that an
* import will fail.
*
* @param name the name to check, such as java, java.util, java.util.ArrayList
* @return true if it's likely supported by Java, false if it's likely python
* @param name
* the name to check, such as java, java.util,
* java.util.ArrayList
* @return true if it's likely supported by Java, false if it's likely
* python
*/
public boolean contains(String name);
/**
* Whether or not this ClassEnquirer supports importing Java classes at the
* package level in addition to the class level. For example, with the
* right ClassLoader JEP should always be able to successfully import Java
* classes with syntax such as:
* package level in addition to the class level. For example, with the right
* ClassLoader JEP should always be able to successfully import Java classes
* with syntax such as:
*
* <p><blockquote><pre>
* <p>
* <blockquote>
*
* <pre>
* from java.util import ArrayList
* o = ArrayList()
* </p></blockquote></pre>
*
* </p>
* </blockquote></pre>
*
* However, only in some scenarios can the package be imported separately
* without the fully qualified name, such as:
*
* <p><blockquote><pre>
* <p>
* <blockquote>
*
* <pre>
* import java.util as ju
* o = ju.ArrayList()
* </p></blockquote></pre>
*
* </p>
* </blockquote></pre>
*
* This also roughly corresponds to whether or not dir(javaPackage) will
* return a list of available classes or only the classes that have been
* explicitly imported.
*
* @return true if this ClassEnquirer supports import of packages in addition
* to import of classes, false if it only supports importing classes.
* @return true if this ClassEnquirer supports import of packages in
* addition to import of classes, false if it only supports
* importing classes.
*/
public boolean supportsPackageImport();

View file

@ -9,7 +9,7 @@ import jep.python.*;
* <pre>
* InvocationHandler.java - Handle Proxy method calls.
*
* Copyright (c) 2004 - 2007 Mike Johnson.
* Copyright (c) 2015 JEP AUTHORS.
*
* This file is licenced under the the zlib/libpng License.
*

View file

@ -4,7 +4,7 @@ package jep;
* <pre>
* JepException.java - it happens.
*
* Copyright (c) 2004, 2005 Mike Johnson.
* Copyright (c) 2015 JEP AUTHORS.
*
* This file is licenced under the the zlib/libpng License.
*
@ -31,7 +31,7 @@ package jep;
*
* </pre>
* @author [mrjohnson0 at sourceforge.net] Mike Johnson
* @version $Id: JepException.java 342 2006-09-17 23:09:38Z mrjohnson0 $
* @version $Id$
*/
public class JepException extends Exception {

View file

@ -19,7 +19,7 @@ import jep.python.PyModule;
* <pre>
* JepScriptEngine.java - implements javax.script.ScriptEngine
*
* Copyright (c) 2004, 2005 Mike Johnson.
* Copyright (c) 2015 JEP AUTHORS.
*
* This file is licenced under the the zlib/libpng License.
*
@ -47,7 +47,7 @@ import jep.python.PyModule;
* </pre>
*
* @author [mrjohnson0 at sourceforge.net] Mike Johnson
* @version $Id: JepScriptEngine.java 366 2006-09-23 21:30:07Z albertstrasheim $
* @version $Id$
*/
public class JepScriptEngine implements ScriptEngine {
private Jep jep = null;

View file

@ -13,7 +13,7 @@ import javax.script.ScriptException;
* <pre>
* JepScriptEngineFactory.java - Embeds CPython in Java.
*
* Copyright (c) 2004, 2005 Mike Johnson.
* Copyright (c) 2015 JEP AUTHORS.
*
* This file is licenced under the the zlib/libpng License.
*
@ -41,7 +41,7 @@ import javax.script.ScriptException;
* </pre>
*
* @author [mrjohnson0 at sourceforge.net] Mike Johnson
* @version $Id: JepScriptEngineFactory.java 368 2006-09-23 22:02:37Z albertstrasheim $
* @version $Id$
*/
public class JepScriptEngineFactory implements ScriptEngineFactory {

View file

@ -10,7 +10,7 @@ import java.lang.reflect.InvocationHandler;
* <pre>
* Proxy.java - Extend java.lang.reflect.Proxy for callbacks.
*
* Copyright (c) 2004 - 2007 Mike Johnson.
* Copyright (c) 2015 JEP AUTHORS.
*
* This file is licenced under the the zlib/libpng License.
*

View file

@ -13,14 +13,26 @@ import jep.python.*;
* Created: Fri Apr 30 12:42:58 2004
*
* @author [mrjohnson0 at sourceforge.net] Mike Johnson
* @version $Id: Test.java 445 2007-11-20 06:57:06Z mrjohnson0 $
* @version $Id$
*/
public class Test implements Runnable {
private Jep jep = null;
private boolean testEval = false;
public static ClassLoader restrictedClassLoader = new ClassLoader() {
@Override
public Class<?> loadClass(final String name) throws ClassNotFoundException {
if (name.startsWith("java.io.")) {
throw new ClassNotFoundException("restricted class: " + name);
}
return super.loadClass(name);
}
};
public Test() {
} // Test constructor
}
public Test(boolean testEval) {
@ -28,6 +40,12 @@ public class Test implements Runnable {
}
public static enum TestEnum {
One,
Two
}
public void run() {
for(int i = 0; i < 1; i++) {
@ -146,11 +164,6 @@ public class Test implements Runnable {
}
}
protected void finalize() {
System.out.println("test instance finalized, you should see this " +
"if the reference counting worked...");
}
// get the jep used for this class
public Jep getJep() {
return this.jep;
@ -161,32 +174,8 @@ public class Test implements Runnable {
}
public int getInt() {
return 2147483647;
}
public byte getByte() {
return 123;
}
public char getChar() {
return 'c';
}
public short getShort() {
return 321;
}
public long getLong() {
return 9223372036854775807L;
}
public double getDouble() {
return 1.7976931348623157E308D;
}
public float getFloat() {
return 3.4028235E38F;
public TestEnum getEnum() {
return TestEnum.One;
}
public Integer getInteger() {
@ -280,6 +269,86 @@ public class Test implements Runnable {
public char charField = 'c';
public Class classField = this.getClass();
public boolean isBooleanField() {
return booleanField;
}
public void setBooleanField(boolean booleanField) {
this.booleanField = booleanField;
}
public byte getByteField() {
return byteField;
}
public void setByteField(byte byteField) {
this.byteField = byteField;
}
public char getCharField() {
return charField;
}
public void setCharField(char charField) {
this.charField = charField;
}
public Class getClassField() {
return classField;
}
public void setClassField(Class classField) {
this.classField = classField;
}
public double getDoubleField() {
return doubleField;
}
public void setDoubleField(double doubleField) {
this.doubleField = doubleField;
}
public float getFloatField() {
return floatField;
}
public void setFloatField(float floatField) {
this.floatField = floatField;
}
public int getIntField() {
return intField;
}
public void setIntField(int intField) {
this.intField = intField;
}
public long getLongField() {
return longField;
}
public void setLongField(long longField) {
this.longField = longField;
}
public short getShortField() {
return shortField;
}
public void setShortField(short shortField) {
this.shortField = shortField;
}
public String getStringField() {
return stringField;
}
public void setStringField(String stringField) {
this.stringField = stringField;
}
// -------------------------------------------------- static fields
@ -297,34 +366,80 @@ public class Test implements Runnable {
// -------------------------------------------------- static methods
public static String getStaticString() {
return "a static string.";
public static boolean isStaticBoolean() {
return staticBoolean;
}
public static boolean getStaticBoolean() {
return false;
public static void setStaticBoolean(boolean staticBoolean) {
Test.staticBoolean = staticBoolean;
}
public static int getStaticInt() {
return 123;
public static byte getStaticByte() {
return staticByte;
}
public static short getStaticShort() {
return 321;
public static void setStaticByte(byte staticByte) {
Test.staticByte = staticByte;
}
public static long getStaticLong() {
return 9223372036854775807L;
public static char getStaticChar() {
return staticChar;
}
public static void setStaticChar(char staticChar) {
Test.staticChar = staticChar;
}
public static double getStaticDouble() {
return 123123213.123D;
return staticDouble;
}
public static void setStaticDouble(double staticDouble) {
Test.staticDouble = staticDouble;
}
public static float getStaticFloat() {
return 12312.123F;
return staticFloat;
}
public static void setStaticFloat(float staticFloat) {
Test.staticFloat = staticFloat;
}
public static int getStaticInt() {
return staticInt;
}
public static void setStaticInt(int staticInt) {
Test.staticInt = staticInt;
}
public static long getStaticLong() {
return staticLong;
}
public static void setStaticLong(long staticLong) {
Test.staticLong = staticLong;
}
public static short getStaticShort() {
return staticShort;
}
public static void setStaticShort(short staticShort) {
Test.staticShort = staticShort;
}
public static String getStaticString() {
return staticString;
}
public static void setStaticString(String staticString) {
Test.staticString = staticString;
}
// -------------------------------------------------- other static methods
public static Object getStaticObject() {
return new Object();
}
@ -333,33 +448,17 @@ public class Test implements Runnable {
return;
}
public static byte getStaticByte() {
return 23;
}
public static char getStaticChar() {
return 'b';
}
public static Class getStaticClass() {
return Thread.currentThread().getClass();
}
public static void main(String argv[]) throws Throwable {
if(argv.length < 1) {
new Thread(new Test()).start();
new Thread(new Test()).start();
Jep jep = new Jep();
try {
jep.runScript("runtests.py");
}
else {
int count = Integer.parseInt(argv[0]);
for(int i = 0; i < count; i++)
new Thread(new Test()).start();
finally {
jep.close();
}
new Test().run();
System.gc();
}
} // Test

View file

@ -8,7 +8,10 @@ import java.util.concurrent.Executors;
* ndarrays, and closing/disposing interpreters. This demonstrates the issue
* where numpy's array2string or array_str reference is lost.
*
* Created: Autumn 2013
*
* @author David Gillingham
* @version $Id$
*/
public class TestNumpyArrayToString {

View file

@ -7,7 +7,9 @@ package jep;
* Python is confused about the thread state and GIL state due to the top level
* interpreter being initialized on the same thread as the sub-interpreter(s).
*
* Created: Mon Apr 13 2015
* Please see the TODO below for how to trigger the freeze.
*
* Created: Thu Apr 09 2015
*
* @author [ndjensen at gmail.com] Nate Jensen
* @version $Id$
@ -28,7 +30,7 @@ public class TestNumpyGILFreeze {
*/
public static void main(String[] args) {
/*
* TODO: To show the freeze, you need to alter Jep.pyInitialize() to
* TODO: To show the freeze, you need to alter Jep.TopInterpreter to
* NOT use a separate thread for System.loadLibrary("jep");
*/
createJepAndUseNumpy();

View file

@ -1,13 +1,13 @@
package jep;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* <pre>
* Util.java - utility functions
* Copyright (c) 2004 - 2007 Mike Johnson.
*
* Copyright (c) 2015 JEP AUTHORS.
*
* This file is licenced under the the zlib/libpng License.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any
* damages arising from the use of this software.
@ -26,6 +26,7 @@ import java.io.StringWriter;
*
* 3. This notice may not be removed or altered from any source
* distribution.
*
* Created: Fri Dec 22 13:21:02 2006
* </pre>
*
@ -36,43 +37,34 @@ public final class Util {
// these must be the same as util.h
public static final int JBOOLEAN_ID = 0;
public static final int JINT_ID = 1;
public static final int JLONG_ID = 2;
public static final int JOBJECT_ID = 3;
public static final int JSTRING_ID = 4;
public static final int JVOID_ID = 5;
public static final int JDOUBLE_ID = 6;
public static final int JSHORT_ID = 7;
public static final int JFLOAT_ID = 8;
public static final int JARRAY_ID = 9;
public static final int JCHAR_ID = 10;
public static final int JBYTE_ID = 11;
public static final int JCLASS_ID = 12;
private Util() {
}
/**
* <pre>
* &lt;b&gt;Internal use only&lt;/b&gt;
*
* <b>Internal use only</b>
*
* Does the same thing as util.c::get_jtype, but it's easier more
* stable to do this in java when able.
*
* </pre>
*
* @param obj
* an <code>Object</code> value
* @param obj an <code>Object</code> value
* @return an <code>int</code> one of the type _ID constants
*/
public static final int getTypeId(Object obj) {
@ -119,20 +111,19 @@ public final class Util {
return JOBJECT_ID;
}
/**
* <pre>
* &lt;b&gt;Internal use only&lt;/b&gt;
* Same as
* <code>
* getTypeId(Object)
* </code>
* but for Class. This is
*
* <b>Internal use only</b>
*
* Same as <code>getTypeId(Object)</code> but for Class. This is
* useful for determining the _ID for things like
* method.getReturnType.
*
* </pre>
*
* @param obj
* an <code>Object</code> value
* @param obj an <code>Object</code> value
* @return an <code>int</code> one of the type _ID constants
*/
public static final int getTypeId(Class<?> clazz) {
@ -177,18 +168,4 @@ public final class Util {
return JOBJECT_ID;
}
/**
* Returns a String version of the throwable with the stacktrace
*
* @param throwable
* the throwable
* @return the throwable's stacktrace
*/
public static String throwableAsString(Throwable throwable) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
throwable.printStackTrace(printWriter);
return stringWriter.toString();
}
}

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,12 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
#include "util.h"
#include "jep.h"
#include "pyembed.h"
@ -85,7 +79,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_run
const char *filename;
filename = jstring2char(env, str);
pyembed_run(env, tstate, (char *) filename);
pyembed_run(env, (intptr_t) tstate, (char *) filename);
release_utf_char(env, str, filename);
}
@ -124,7 +118,7 @@ JNIEXPORT jint JNICALL Java_jep_Jep_compileString
jint ret;
str = jstring2char(env, jstr);
ret = (jint) pyembed_compile_string(env, tstate, (char *) str);
ret = (jint) pyembed_compile_string(env, (intptr_t) tstate, (char *) str);
release_utf_char(env, jstr, str);
return ret;
}
@ -140,7 +134,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_eval
const char *str;
str = jstring2char(env, jstr);
pyembed_eval(env, tstate, (char *) str);
pyembed_eval(env, (intptr_t) tstate, (char *) str);
release_utf_char(env, jstr, str);
}
@ -156,7 +150,7 @@ JNIEXPORT jobject JNICALL Java_jep_Jep_getValue
jobject ret;
str = jstring2char(env, jstr);
ret = pyembed_getvalue(env, tstate, (char *) str);
ret = pyembed_getvalue(env, (intptr_t) tstate, (char *) str);
release_utf_char(env, jstr, str);
return ret;
}
@ -173,7 +167,7 @@ JNIEXPORT jobject JNICALL Java_jep_Jep_getValue_1floatarray
jobject ret;
str = jstring2char(env, jstr);
ret = pyembed_getvalue_array(env, tstate, (char *) str, JFLOAT_ID);
ret = pyembed_getvalue_array(env, (intptr_t) tstate, (char *) str, JFLOAT_ID);
release_utf_char(env, jstr, str);
return ret;
}
@ -190,7 +184,7 @@ JNIEXPORT jobject JNICALL Java_jep_Jep_getValue_1bytearray
jobject ret;
str = jstring2char(env, jstr);
ret = pyembed_getvalue_array(env, tstate, (char *) str, JBYTE_ID);
ret = pyembed_getvalue_array(env, (intptr_t) tstate, (char *) str, JBYTE_ID);
release_utf_char(env, jstr, str);
return ret;
}
@ -208,7 +202,7 @@ JNIEXPORT jlong JNICALL Java_jep_Jep_createModule
jlong ret;
str = jstring2char(env, jstr);
ret = pyembed_create_module(env, tstate, (char *) str);
ret = pyembed_create_module(env, (intptr_t) tstate, (char *) str);
release_utf_char(env, jstr, str);
return ret;
}
@ -221,7 +215,7 @@ JNIEXPORT jlong JNICALL Java_jep_Jep_createModule
*/
JNIEXPORT void JNICALL Java_jep_Jep_setClassLoader
(JNIEnv *env, jobject obj, jlong tstate, jobject cl) {
pyembed_setloader(env, tstate, cl);
pyembed_setloader(env, (intptr_t) tstate, cl);
}
@ -232,7 +226,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_setClassLoader
*/
JNIEXPORT void JNICALL Java_jep_Jep_close
(JNIEnv *env, jobject obj, jlong tstate) {
pyembed_thread_close(tstate);
pyembed_thread_close((intptr_t) tstate);
}
@ -248,7 +242,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2Ljava_lang_Object_2
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_object(env, tstate, 0, name, jval);
pyembed_setparameter_object(env, (intptr_t) tstate, 0, name, jval);
release_utf_char(env, jname, name);
}
@ -263,7 +257,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2Ljava_lang_Class_2
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_class(env, tstate, 0, name, jval);
pyembed_setparameter_class(env, (intptr_t) tstate, 0, name, jval);
release_utf_char(env, jname, name);
}
@ -279,7 +273,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2Ljava_lang_String_2
name = jstring2char(env, jname);
value = jstring2char(env, jval);
pyembed_setparameter_string(env, tstate, 0, name, value);
pyembed_setparameter_string(env, (intptr_t) tstate, 0, name, value);
release_utf_char(env, jname, name);
release_utf_char(env, jval, value);
}
@ -295,7 +289,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2I
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_int(env, tstate, 0, name, (int) jval);
pyembed_setparameter_int(env, (intptr_t) tstate, 0, name, (int) jval);
release_utf_char(env, jname, name);
}
@ -310,7 +304,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2J
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_long(env, tstate, 0, name, (jeplong) jval);
pyembed_setparameter_long(env, (intptr_t) tstate, 0, name, (jeplong) jval);
release_utf_char(env, jname, name);
}
@ -325,7 +319,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2D
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_double(env, tstate, 0, name, (double) jval);
pyembed_setparameter_double(env, (intptr_t) tstate, 0, name, (double) jval);
release_utf_char(env, jname, name);
}
@ -340,7 +334,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2F
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_float(env, tstate, 0, name, (float) jval);
pyembed_setparameter_float(env, (intptr_t) tstate, 0, name, (float) jval);
release_utf_char(env, jname, name);
}
@ -355,7 +349,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3Z
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}
@ -370,7 +364,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3I
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}
@ -385,7 +379,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3S
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}
@ -400,7 +394,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3B
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}
@ -415,7 +409,7 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3J
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}
@ -430,57 +424,10 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3D
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}
/*
* Class: jep_Jep
* Method: setNumeric
* Signature: (JLjava/lang/String;[FII)V
*/
JNIEXPORT void JNICALL Java_jep_Jep_setNumeric__JLjava_lang_String_2_3FII
(JNIEnv *env, jobject obj, jlong tstate, jstring jname, jfloatArray jarr, jint nx, jint ny) {
// function added by njensen
const char *name;
name = jstring2char(env, jname);
pyembed_setnumeric_array(env, tstate, 0, name, (jobjectArray) jarr, nx, ny);
release_utf_char(env, jname, name);
}
/*
* Class: jep_Jep
* Method: setNumeric
* Signature: (JLjava/lang/String;[III)V
*/
JNIEXPORT void JNICALL Java_jep_Jep_setNumeric__JLjava_lang_String_2_3III
(JNIEnv *env, jobject obj, jlong tstate, jstring jname, jintArray jarr, jint nx, jint ny) {
// function added by njensen
const char *name;
name = jstring2char(env, jname);
pyembed_setnumeric_array(env, tstate, 0, name, (jobjectArray) jarr, nx, ny);
release_utf_char(env, jname, name);
}
/*
* Class: jep_Jep
* Method: setNumeric
* Signature: (JLjava/lang/String;[BII)V
*/
JNIEXPORT void JNICALL Java_jep_Jep_setNumeric__JLjava_lang_String_2_3BII
(JNIEnv *env, jobject obj, jlong tstate, jstring jname, jbyteArray jarr, jint nx, jint ny) {
// function added by chammack
const char *name;
name = jstring2char(env, jname);
pyembed_setnumeric_array(env, tstate, 0, name, (jobjectArray) jarr, nx, ny);
release_utf_char(env, jname, name);
}
/*
* Class: jep_Jep
@ -492,6 +439,6 @@ JNIEXPORT void JNICALL Java_jep_Jep_set__JLjava_lang_String_2_3F
const char *name;
name = jstring2char(env, jname);
pyembed_setparameter_array(env, tstate, 0, name, (jobjectArray) jarr);
pyembed_setparameter_array(env, (intptr_t) tstate, 0, name, (jobjectArray) jarr);
release_utf_char(env, jname, name);
}

View file

@ -1120,6 +1120,7 @@ jobject pyembed_box_py(JNIEnv *env, PyObject *result) {
}
#endif
// TODO find a better solution than this
// convert everything else to string
{
jobject ret;
@ -1397,16 +1398,14 @@ static void pyembed_run_pyc(JepThread *jepThread,
magic = PyMarshal_ReadLongFromFile(fp);
if (magic != PyImport_GetMagicNumber()) {
PyErr_SetString(PyExc_RuntimeError,
"Bad magic number in .pyc file");
PyErr_SetString(PyExc_RuntimeError, "Bad magic number in .pyc file");
return;
}
(void) PyMarshal_ReadLongFromFile(fp);
v = (PyObject *) (intptr_t) PyMarshal_ReadLastObjectFromFile(fp);
if (v == NULL || !PyCode_Check(v)) {
Py_XDECREF(v);
PyErr_SetString(PyExc_RuntimeError,
"Bad code object in .pyc file");
PyErr_SetString(PyExc_RuntimeError, "Bad code object in .pyc file");
return;
}
co = (PyCodeObject *) v;
@ -1415,13 +1414,10 @@ static void pyembed_run_pyc(JepThread *jepThread,
Py_XDECREF(v);
}
/* Check whether a file maybe a pyc file: Look at the extension,
the file type, and, if we may close it, at the first few bytes. */
// gratuitously copyied from pythonrun.c::run_pyc_file
static int maybe_pyc_file(FILE *fp,
const char* filename,
const char* ext,
static int maybe_pyc_file(FILE *fp, const char* filename, const char* ext,
int closeit) {
if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0)
return 1;
@ -1432,7 +1428,8 @@ static int maybe_pyc_file(FILE *fp,
/* Read only two bytes of the magic. If the file was opened in
text mode, the bytes 3 and 4 of the magic (\r\n) might not
be read as they are on disk. */
unsigned int halfmagic = (unsigned int) PyImport_GetMagicNumber() & 0xFFFF;
unsigned int halfmagic = (unsigned int) PyImport_GetMagicNumber()
& 0xFFFF;
unsigned char buf[2];
/* Mess: In case of -x, the stream is NOT at its start now,
and ungetc() was used to push back the first newline,
@ -1447,8 +1444,8 @@ static int maybe_pyc_file(FILE *fp,
*/
int ispyc = 0;
if (ftell(fp) == 0) {
if(fread(buf, 1, 2, fp) == 2 &&
(buf[1]<<8 | buf[0]) == halfmagic)
if (fread(buf, 1, 2, fp) == 2
&& (buf[1] << 8 | buf[0]) == halfmagic)
ispyc = 1;
rewind(fp);
}

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,13 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
#ifndef _Included_pyembed
#define _Included_pyembed
@ -52,7 +45,6 @@
#include "Python.h"
#include "util.h"
#include "pyjobject.h"
#define DICT_KEY "jep"
@ -103,9 +95,4 @@ void pyembed_setparameter_long(JNIEnv*, intptr_t, intptr_t, const char*, jeplong
void pyembed_setparameter_double(JNIEnv*, intptr_t, intptr_t, const char*, double);
void pyembed_setparameter_float(JNIEnv*, intptr_t, intptr_t, const char*, float);
// added by njensen
void pyembed_setnumeric_array(JNIEnv*, intptr_t, intptr_t, const char*, jobjectArray, int, int);
static void init(void);
static int ran = 0;
#endif

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -31,13 +31,6 @@
of the python distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
#ifdef WIN32
# include "winconfig.h"
#endif
@ -66,7 +59,7 @@
#include "pyembed.h"
#include "util.h"
staticforward PyTypeObject PyJarray_Type;
PyAPI_DATA(PyTypeObject) PyJarray_Type;
extern PyMethodDef pyjarray_methods[];
@ -75,7 +68,7 @@ jmethodID objectComponentType = 0;
static void pyjarray_dealloc(PyJarray_Object *self);
static int pyjarray_init(JNIEnv*, PyJarray_Object*, int, PyObject*);
static int pyjarray_length(PyJarray_Object *self);
static int pyjarray_length(PyObject *self);
// called internally to make new PyJarray_Object instances
@ -120,7 +113,7 @@ PyObject* pyjarray_new_v(PyObject *isnull, PyObject *args) {
jclass clazz, componentClass;
JNIEnv *env = NULL;
jobjectArray arrayObj = NULL;
int typeId = -1;
long typeId = -1;
long size = -1;
// args
@ -139,10 +132,10 @@ PyObject* pyjarray_new_v(PyObject *isnull, PyObject *args) {
size = PyInt_AsLong(one);
if(PyInt_Check(two)) {
typeId = PyInt_AsLong(two);
typeId = (int) PyInt_AsLong(two);
if(size < 0)
return PyErr_Format(PyExc_ValueError, "Invalid size %i", size);
return PyErr_Format(PyExc_ValueError, "Invalid size %li", size);
// make a new primitive array
switch(typeId) {
@ -233,7 +226,7 @@ PyObject* pyjarray_new_v(PyObject *isnull, PyObject *args) {
pyarray = PyObject_NEW(PyJarray_Object, &PyJarray_Type);
pyarray->object = (*env)->NewGlobalRef(env, arrayObj);
pyarray->clazz = (*env)->NewGlobalRef(env, clazz);
pyarray->componentType = typeId;
pyarray->componentType = (int) typeId;
pyarray->componentClass = NULL;
pyarray->length = -1;
pyarray->pinnedArray = NULL;
@ -329,7 +322,7 @@ static int pyjarray_init(JNIEnv *env,
v = PyInt_AS_LONG(value);
for(i = 0; i < pyarray->length; i++)
ar[i] = v;
ar[i] = (jint) v;
break;
}
@ -545,9 +538,6 @@ static void pyjarray_dealloc(PyJarray_Object *self) {
#if USE_DEALLOC
JNIEnv *env = pyembed_get_env();
if(env) {
// njensen moved down farther!
// if(self->object)
// (*env)->DeleteGlobalRef(env, self->object);
if(self->clazz)
(*env)->DeleteGlobalRef(env, self->clazz);
if(self->componentClass)
@ -556,8 +546,8 @@ static void pyjarray_dealloc(PyJarray_Object *self) {
// can't guarantee mode 0 will work in this case...
pyjarray_release_pinned(self, JNI_ABORT);
// njensen: I moved this down here because it sometimes (but not always!)
// leaks when this is above the pyjarray_release_pinned
// pyjarray_release_pinned potentially uses self->object so we can
// only delete self->object afterwards
if(self->object)
(*env)->DeleteGlobalRef(env, self->object);
} // if env
@ -574,10 +564,7 @@ void pyjarray_release_pinned(PyJarray_Object *self, jint mode) {
if(!self->pinnedArray)
return;
// if(self->isCopy && mode == JNI_ABORT)
// njensen: I changed this to be !isCopy, if it's a copy we want to
// release the copy, otherwise it leaks. if we were operating on the
// raw data, then we don't want to release it.
// don't release if it's the raw data, but do release if it's a copy
if(!self->isCopy && mode == JNI_ABORT)
return;
@ -848,13 +835,13 @@ static int pyjarray_setitem(PyJarray_Object *self,
}
static PyObject* pyjarray_item(PyJarray_Object *self, int pos) {
static PyObject* pyjarray_item(PyJarray_Object *self, Py_ssize_t pos) {
PyObject *ret = NULL;
JNIEnv *env = pyembed_get_env();
if(self->length < 1) {
PyErr_Format(PyExc_IndexError,
"array assignment index out of range: %i", pos);
"array assignment index out of range: %zd", pos);
return NULL;
}
@ -871,7 +858,7 @@ static PyObject* pyjarray_item(PyJarray_Object *self, int pos) {
jstr = (jstring) (*env)->GetObjectArrayElement(env,
self->object,
pos);
(jsize) pos);
if(process_java_exception(env))
;
@ -896,7 +883,7 @@ static PyObject* pyjarray_item(PyJarray_Object *self, int pos) {
obj = (jobjectArray) (*env)->GetObjectArrayElement(env,
self->object,
pos);
(jsize) pos);
if(process_java_exception(env))
;
@ -916,7 +903,7 @@ static PyObject* pyjarray_item(PyJarray_Object *self, int pos) {
obj = (*env)->GetObjectArrayElement(env,
self->object,
pos);
(jsize) pos);
if(process_java_exception(env))
;
else if(obj != NULL)
@ -931,19 +918,19 @@ static PyObject* pyjarray_item(PyJarray_Object *self, int pos) {
}
case JBOOLEAN_ID:
ret = Py_BuildValue("i", ((jboolean *) self->pinnedArray)[pos]);
ret = Py_BuildValue("i", ((jboolean *) self->pinnedArray)[(jsize) pos]);
break;
case JSHORT_ID:
ret = Py_BuildValue("i", ((jshort *) self->pinnedArray)[pos]);
ret = Py_BuildValue("i", ((jshort *) self->pinnedArray)[(jsize) pos]);
break;
case JINT_ID:
ret = Py_BuildValue("i", ((jint *) self->pinnedArray)[pos]);
ret = Py_BuildValue("i", ((jint *) self->pinnedArray)[(jsize) pos]);
break;
case JBYTE_ID:
ret = Py_BuildValue("i", ((jbyte *) self->pinnedArray)[pos]);
ret = Py_BuildValue("i", ((jbyte *) self->pinnedArray)[(jsize) pos]);
break;
case JCHAR_ID: {
@ -955,15 +942,15 @@ static PyObject* pyjarray_item(PyJarray_Object *self, int pos) {
}
case JLONG_ID:
ret = PyLong_FromLongLong(((jlong *) self->pinnedArray)[pos]);
ret = PyLong_FromLongLong(((jlong *) self->pinnedArray)[(jsize) pos]);
break;
case JFLOAT_ID:
ret = PyFloat_FromDouble(((jfloat *) self->pinnedArray)[pos]);
ret = PyFloat_FromDouble(((jfloat *) self->pinnedArray)[(jsize) pos]);
break;
case JDOUBLE_ID:
ret = PyFloat_FromDouble(((jdouble *) self->pinnedArray)[pos]);
ret = PyFloat_FromDouble(((jdouble *) self->pinnedArray)[(jsize) pos]);
break;
default:
@ -1283,7 +1270,6 @@ static PyObject* listindex(PyJarray_Object *self, PyObject *args) {
static PyObject* pyjarray_commit(PyJarray_Object *self, PyObject *args) {
int pos;
PyObject *v;
if(!PyArg_ParseTuple(args, "", &v))
@ -1297,8 +1283,6 @@ static PyObject* pyjarray_commit(PyJarray_Object *self, PyObject *args) {
static int pyjarray_contains(PyJarray_Object *self, PyObject *el) {
JNIEnv *env = pyembed_get_env();
int pos = pyjarray_index(self, el);
if(PyErr_Occurred())
return -1;
@ -1310,12 +1294,14 @@ static int pyjarray_contains(PyJarray_Object *self, PyObject *el) {
// shamelessly taken from listobject.c
static PyObject* pyjarray_slice(PyJarray_Object *self, int ilow, int ihigh) {
static PyObject* pyjarray_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh) {
PyJarray_Object *pyarray = NULL;
jobjectArray arrayObj = NULL;
PyObject *ret = NULL;
int len, i;
PyJarray_Object *self = (PyJarray_Object *) _self;
Py_ssize_t len, i;
JNIEnv *env = pyembed_get_env();
if(ilow < 0)
@ -1490,10 +1476,10 @@ static PyObject* pyjarray_slice(PyJarray_Object *self, int ilow, int ihigh) {
for(i = 0; i < len; i++) {
jobject obj = (*env)->GetObjectArrayElement(env,
self->object,
ilow++);
(jsize) ilow++);
(*env)->SetObjectArrayElement(env,
arrayObj,
i,
(jsize) i,
obj);
if(obj)
(*env)->DeleteLocalRef(env, obj);
@ -1514,13 +1500,11 @@ static PyObject* pyjarray_slice(PyJarray_Object *self, int ilow, int ihigh) {
// shamelessly taken from listobject.c
static PyObject* pyjarray_subscript(PyJarray_Object *self, PyObject *item) {
JNIEnv *env = pyembed_get_env();
if(PyInt_Check(item)) {
long i = PyInt_AS_LONG(item);
if (i < 0)
i += self->length;
return pyjarray_item(self, i);
return pyjarray_item(self, (Py_ssize_t) i);
}
else if(PyLong_Check(item)) {
long i = PyLong_AsLong(item);
@ -1528,11 +1512,10 @@ static PyObject* pyjarray_subscript(PyJarray_Object *self, PyObject *item) {
return NULL;
if (i < 0)
i += self->length;
return pyjarray_item(self, i);
return pyjarray_item(self, (Py_ssize_t) i);
}
else {
PyErr_SetString(PyExc_TypeError,
"list indices must be integers");
PyErr_SetString(PyExc_TypeError, "list indices must be integers");
return NULL;
}
}
@ -1540,7 +1523,6 @@ static PyObject* pyjarray_subscript(PyJarray_Object *self, PyObject *item) {
static PyObject* pyjarray_str(PyJarray_Object *self) {
PyObject *ret;
JNIEnv *env = pyembed_get_env();
if(!self->pinnedArray) {
PyErr_SetString(PyExc_RuntimeError, "No pinned array.");
@ -1568,9 +1550,9 @@ static PyObject* pyjarray_str(PyJarray_Object *self) {
// -------------------------------------------------- sequence methods
static int pyjarray_length(PyJarray_Object *self) {
if(self)
return self->length;
static int pyjarray_length(PyObject *self) {
if(self && pyjarray_check(self))
return ((PyJarray_Object *) self)->length;
return 0;
}
@ -1597,23 +1579,23 @@ PyMethodDef pyjarray_methods[] = {
static PySequenceMethods list_as_sequence = {
(inquiry) pyjarray_length, /* sq_length */
(lenfunc) pyjarray_length, /* sq_length */
(binaryfunc) 0, /* sq_concat */
(intargfunc) 0, /* sq_repeat */
(intargfunc) pyjarray_item, /* sq_item */
(intintargfunc) pyjarray_slice, /* sq_slice */
(ssizeargfunc) 0, /* sq_repeat */
(ssizeargfunc) pyjarray_item, /* sq_item */
(ssizessizeargfunc) pyjarray_slice, /* sq_slice */
(intobjargproc) pyjarray_setitem, /* sq_ass_item */
(intintobjargproc) 0, /* sq_ass_slice */
(objobjproc) pyjarray_contains, /* sq_contains */
(binaryfunc) 0, /* sq_inplace_concat */
(intargfunc) 0, /* sq_inplace_repeat */
(ssizeargfunc) 0, /* sq_inplace_repeat */
};
static PyObject* pyjarray_iter(PyObject *);
static PyTypeObject PyJarray_Type = {
PyTypeObject PyJarray_Type = {
PyObject_HEAD_INIT(0)
0, /* ob_size */
"jarray", /* tp_name */
@ -1634,7 +1616,8 @@ static PyTypeObject PyJarray_Type = {
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_HAVE_ITER, /* tp_flags */
list_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
@ -1694,6 +1677,12 @@ static void pyjarrayiter_dealloc(PyJarrayIterObject *it) {
PyObject_Del(it);
}
/* the iterator's __iter()__ */
PyObject* pyjarray_iter_self(PyObject *self) {
Py_INCREF(self);
return self;
}
static PyObject *pyjarrayiter_next(PyJarrayIterObject *it) {
PyJarray_Object *seq;
PyObject *item;
@ -1704,9 +1693,8 @@ static PyObject *pyjarrayiter_next(PyJarrayIterObject *it) {
return NULL;
if (it->it_index < seq->length) {
item = pyjarray_item(seq, it->it_index);
item = (PyObject *) pyjarray_item(seq, it->it_index);
++it->it_index;
//Py_INCREF(item); // njensen: this leaks memory
return item;
}
@ -1716,11 +1704,11 @@ static PyObject *pyjarrayiter_next(PyJarrayIterObject *it) {
}
static int pyjarrayiter_len(PyJarrayIterObject *it) {
int len;
Py_ssize_t len;
if (it->it_seq) {
len = it->it_seq->length - it->it_index;
len = (int) (it->it_seq->length - it->it_index);
if (len >= 0)
return len;
return (int) len;
}
return 0;
}
@ -1756,13 +1744,14 @@ PyTypeObject PyJarrayIter_Type = {
(getattrofunc) pyjarrayiter_dealloc, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_HAVE_ITER, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
pyjarray_iter_self, /* tp_iter */
(iternextfunc) pyjarrayiter_next, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */

View file

@ -1,7 +1,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -25,13 +25,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
// shut up the compiler
#ifdef _POSIX_C_SOURCE

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -62,7 +62,7 @@
#include "pyjarray.h"
#include "util.h"
staticforward PyTypeObject PyJclass_Type;
PyAPI_DATA(PyTypeObject) PyJclass_Type;
static PyObject* pyjclass_add_inner_classes(JNIEnv*, jobject, PyJobject_Object*);
static void pyjclass_dealloc(PyJclass_Object*);
@ -518,7 +518,7 @@ static PyMethodDef pyjclass_methods[] = {
};
static PyTypeObject PyJclass_Type = {
PyTypeObject PyJclass_Type = {
PyObject_HEAD_INIT(0)
0,
"PyJclass",

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -65,7 +65,7 @@
#include "pyjclass.h"
#include "util.h"
staticforward PyTypeObject PyJfield_Type;
PyAPI_DATA(PyTypeObject) PyJfield_Type;
static void pyjfield_dealloc(PyJfield_Object *self);
@ -258,8 +258,9 @@ static void pyjfield_dealloc(PyJfield_Object *self) {
(*env)->DeleteGlobalRef(env, self->rfield);
}
if(self->pyFieldName)
if(self->pyFieldName) {
Py_DECREF(self->pyFieldName);
}
PyObject_Del(self);
#endif
@ -916,7 +917,7 @@ static PyMethodDef pyjfield_methods[] = {
};
static PyTypeObject PyJfield_Type = {
PyTypeObject PyJfield_Type = {
PyObject_HEAD_INIT(0)
0,
"PyJfield",

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.

View file

@ -2,8 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
@author Nate Jensen
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -60,7 +59,7 @@
#include "pyjobject.h"
#include "pyembed.h"
staticforward PyTypeObject PyJlist_Type;
PyAPI_DATA(PyTypeObject) PyJlist_Type;
static Py_ssize_t pyjlist_len(PyObject*);
static PyObject* pyjlist_add(PyObject*, PyObject*);
@ -529,20 +528,18 @@ static PySequenceMethods pyjlist_seq_methods = {
/*
* I set tp_base to PyJobject_Type so it has inheritance, but for the life
* of me I couldn't get it to inherit the methods, so I set the relevant
* methods directly.
* Inherits from PyJobject_Type
*/
static PyTypeObject PyJlist_Type = {
PyTypeObject PyJlist_Type = {
PyObject_HEAD_INIT(0)
0,
"jep.PyJlist",
sizeof(PyJlist_Object),
0,
(destructor) pyjobject_dealloc, /* tp_dealloc */
0, /* tp_dealloc */
0, /* tp_print */
(getattrfunc) pyjobject_getattr, /* tp_getattr */
(setattrfunc) pyjobject_setattr, /* tp_setattr */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
@ -550,7 +547,7 @@ static PyTypeObject PyJlist_Type = {
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
(reprfunc) pyjobject_str, /* tp_str */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */

View file

@ -2,8 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
@author Nate Jensen.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,13 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
#ifdef WIN32
# include "winconfig.h"
#endif
@ -67,7 +60,7 @@
#include "util.h"
#include "pyembed.h"
staticforward PyTypeObject PyJmethod_Type;
PyAPI_DATA(PyTypeObject) PyJmethod_Type;
static void pyjmethod_dealloc(PyJmethod_Object *self);
@ -75,7 +68,6 @@ static void pyjmethod_dealloc(PyJmethod_Object *self);
static jmethodID classGetName = 0;
static jmethodID methodGetType = 0;
static jmethodID methodGetParmTypes = 0;
static jmethodID methodGetExceptions = 0;
static jmethodID methodGetModifiers = 0;
// called internally to make new PyJmethod_Object instances.
@ -93,7 +85,6 @@ PyJmethod_Object* pyjmethod_new(JNIEnv *env,
pym = PyObject_NEW(PyJmethod_Object, &PyJmethod_Type);
pym->rmethod = (*env)->NewGlobalRef(env, rmethod);
// pym->pyjobject = pyjobject;
pym->parameters = NULL;
pym->lenParameters = 0;
pym->pyMethodName = NULL;
@ -152,7 +143,6 @@ PyJmethod_Object* pyjmethod_new_static(JNIEnv *env,
pym = PyObject_NEW(PyJmethod_Object, &PyJmethod_Type);
pym->rmethod = (*env)->NewGlobalRef(env, rmethod);
// pym->pyjobject = pyjobject;
pym->parameters = NULL;
pym->lenParameters = 0;
pym->pyMethodName = NULL;
@ -204,7 +194,6 @@ int pyjmethod_init(JNIEnv *env, PyJmethod_Object *self) {
jmethodID methodId;
jobject returnType = NULL;
jobjectArray paramArray = NULL;
jobjectArray exceptions = NULL;
jclass modClass = NULL;
jint modifier = -1;
jboolean isStatic = JNI_FALSE;
@ -346,9 +335,10 @@ static void pyjmethod_dealloc(PyJmethod_Object *self) {
if(self->rmethod)
(*env)->DeleteGlobalRef(env, self->rmethod);
if(self->pyMethodName)
if(self->pyMethodName) {
Py_DECREF(self->pyMethodName);
}
}
PyObject_Del(self);
#endif
@ -362,47 +352,6 @@ int pyjmethod_check(PyObject *obj) {
}
// called by python for __call__.
// we pass off processing to pyjobject's _find_method.
// sortof a dirty hack to get method overloading...
static PyObject* pyjmethod_call(PyJmethod_Object *self,
PyObject *args,
PyObject *keywords) {
PyObject *ret;
JNIEnv* env = NULL;
JepThread* jepthread = NULL;
if(!PyTuple_Check(args)) {
PyErr_Format(PyExc_RuntimeError, "args is not a valid tuple");
return NULL;
}
if(keywords != NULL) {
PyErr_Format(PyExc_RuntimeError, "Keywords are not supported.");
return NULL;
}
/*
* njensen changed all this for method speed optimizations.
* pyjmethods are tied to the java.lang.Methods which are tied
* to java.lang.Classes which are the same regardless of instance.
* So I removed pyjmethods having knowledge of the object instance, and
* instead they pass it through the calls, and we can reuse the method object
* for every object instance.
*
* To ensure the right object is called with the method at the right time,
* I had to wrap a pyjmethod in a new pyjmethodwrapper object that includes
* the original pyjmethod that we use with JNI, and the object it's called against
* which was determind by pyjobject's getattr when the dot operator is used.
*
*/
// shouldn't be possible to get here, should be going through wrapper.
return NULL;
}
// pyjmethod_call_internal. where the magic happens.
//
// okay, some of the magic -- we already the methodId, so we don't have
@ -411,7 +360,7 @@ static PyObject* pyjmethod_call(PyJmethod_Object *self,
//
// easy. :-)
PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
PyJobject_Object *object, // added by njensen
PyJobject_Object *instance,
PyObject *args) {
PyObject *result = NULL;
const char *str = NULL;
@ -426,11 +375,11 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(!self->parameters) {
if(!pyjmethod_init(env, self) || PyErr_Occurred())
return NULL;
return pyjmethod_call_internal(self, object, args);
return pyjmethod_call_internal(self, instance, args);
}
// validate we can call this method
if(!object->object && self->isStatic != JNI_TRUE) {
if(!instance->object && self->isStatic != JNI_TRUE) {
PyErr_Format(PyExc_RuntimeError,
"Instantiate this class before "
"calling an object method.");
@ -441,7 +390,7 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->lenParameters != PyTuple_GET_SIZE(args)) {
PyErr_Format(PyExc_RuntimeError,
"Invalid number of arguments: %i, expected %i.",
PyTuple_GET_SIZE(args),
(int) PyTuple_GET_SIZE(args),
self->lenParameters);
return NULL;
}
@ -450,26 +399,22 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
// ------------------------------ build jargs off python values
// added by njensen, hopefully 40 local references are enough per method call
// hopefully 40 local references are enough per method call
(*env)->PushLocalFrame(env, 40);
for(pos = 0; pos < self->lenParameters; pos++) {
PyObject *param = NULL;
int paramTypeId = -1;
jclass pclazz;
jclass paramType =
(jclass) (*env)->GetObjectArrayElement(env,
self->parameters,
pos);
jclass pclazz = NULL;
jclass paramType = (jclass) (*env)->GetObjectArrayElement(env,
self->parameters, pos);
param = PyTuple_GetItem(args, pos); /* borrowed */
if(PyErr_Occurred()) { /* borrowed */
// changed by njensen
goto EXIT_ERROR;
}
pclazz = (*env)->GetObjectClass(env, paramType);
if(process_java_exception(env) || !pclazz) {
// changed by njensen
goto EXIT_ERROR;
}
@ -485,7 +430,6 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
paramTypeId,
pos);
if(PyErr_Occurred()) { /* borrowed */
// changed by njensen
goto EXIT_ERROR;
}
@ -494,6 +438,7 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
// ------------------------------ call based off return type
switch(self->returnTypeId) {
case JSTRING_ID: {
@ -503,21 +448,21 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
jstr = (jstring) (*env)->CallStaticObjectMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
// not static, a method on class then.
if(!object->object)
if(!instance->object)
jstr = (jstring) (*env)->CallObjectMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
jstr = (jstring) (*env)->CallObjectMethodA(
env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -541,20 +486,20 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
obj = (jobjectArray) (*env)->CallStaticObjectMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
obj = (jobjectArray) (*env)->CallObjectMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
obj = (jobjectArray) (*env)->CallObjectMethodA(
env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -573,18 +518,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
obj = (*env)->CallStaticObjectMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
obj = (*env)->CallObjectMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
obj = (*env)->CallObjectMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -603,18 +548,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
obj = (*env)->CallStaticObjectMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
obj = (*env)->CallObjectMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
obj = (*env)->CallObjectMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -633,18 +578,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticIntMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallIntMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallIntMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -663,18 +608,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticByteMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallByteMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallByteMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -694,18 +639,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticCharMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallCharMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallCharMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -726,18 +671,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticShortMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallShortMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallShortMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -756,18 +701,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticDoubleMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallDoubleMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallDoubleMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -786,18 +731,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticFloatMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallFloatMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallFloatMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -816,18 +761,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticLongMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallLongMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallLongMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -846,18 +791,18 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
if(self->isStatic)
ret = (*env)->CallStaticBooleanMethodA(
env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else {
if(!object->object)
if(!instance->object)
ret = (*env)->CallBooleanMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
ret = (*env)->CallBooleanMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
}
@ -875,21 +820,22 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
// i hereby anoint thee a void method
if(self->isStatic)
(*env)->CallStaticVoidMethodA(env,
object->clazz,
instance->clazz,
self->methodId,
jargs);
else
(*env)->CallVoidMethodA(env,
object->object,
instance->object,
self->methodId,
jargs);
Py_BLOCK_THREADS;
process_java_exception(env);
break;
}
PyMem_Free(jargs);
(*env)->PopLocalFrame(env, NULL); // added by njensen
(*env)->PopLocalFrame(env, NULL);
if(PyErr_Occurred())
return NULL;
@ -910,7 +856,6 @@ PyObject* pyjmethod_call_internal(PyJmethod_Object *self,
return result;
// added by njensen
EXIT_ERROR:
PyMem_Free(jargs);
(*env)->PopLocalFrame(env, NULL);
@ -923,7 +868,7 @@ static PyMethodDef pyjmethod_methods[] = {
};
static PyTypeObject PyJmethod_Type = {
PyTypeObject PyJmethod_Type = {
PyObject_HEAD_INIT(0)
0,
"jep.PyJmethod",
@ -939,7 +884,7 @@ static PyTypeObject PyJmethod_Type = {
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
(ternaryfunc) pyjmethod_call, /* tp_call */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,13 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
// shut up the compiler
#ifdef _POSIX_C_SOURCE
@ -55,9 +48,6 @@ typedef struct {
PyObject_HEAD
jmethodID methodId; /* resolved methodid */
jobject rmethod; /* reflect/Method object */
// commented out by njensen
//PyJobject_Object *pyjobject; /* parent, should point to
// PyJObject_Object */
int returnTypeId; /* type id of return */
PyObject *pyMethodName; /* python name... :-) */
jobjectArray parameters; /* array of jclass parameter types */

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,12 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
New file created with modifications to pyjmethod.c
*/
#ifdef WIN32
# include "winconfig.h"
@ -62,18 +56,20 @@
#include "Python.h"
#include "pyjmethodwrapper.h"
#include "util.h"
#include "pyjobject.h"
#include "pyembed.h"
staticforward PyTypeObject PyJmethodWrapper_Type;
PyAPI_DATA(PyTypeObject) PyJmethodWrapper_Type;
static void pyjmethod_dealloc(PyJmethod_Object *self);
static void pyjmethodwrapper_dealloc(PyJmethodWrapper_Object *self);
PyJmethodWrapper_Object* pyjmethodwrapper_new(
PyJobject_Object *pyjobject,
PyJmethod_Object *pyjmethod
) {
/*
* Makes a new pyjmethodwrapper. This is required to reuse the pyjmethod
* objects across multiple instances, otherwise we'd lose track of which
* pyjobject is doing the calling.
*/
PyJmethodWrapper_Object* pyjmethodwrapper_new(PyJobject_Object *pyjobject, // the instance doing the calling
PyJmethod_Object *pyjmethod) { // the method to be called
PyJmethodWrapper_Object *pym = NULL;
if(PyType_Ready(&PyJmethodWrapper_Type) < 0)
@ -86,17 +82,23 @@ PyJmethodWrapper_Object* pyjmethodwrapper_new(
return pym;
}
static void pyjmethodwrapper_dealloc(PyJmethodWrapper_Object *self) {
#if USE_DEALLOC
if(self->object) {
Py_DECREF(self->object);
}
PyObject_Del(self);
#endif
}
// called by python for __call__.
// we pass off processing to pyjmethod.
/*
* Called by python for pyjobject.__call__. Since we reuse pyjmethod objects,
* a unique instance of pyjmethodwrapper is created for every method on a
* pyjobject to ensure the correct instance is used. We then pass off the
* actual invocation to the pyjmethod.
*/
static PyObject* pyjmethodwrapper_call(PyJmethodWrapper_Object *self,
PyObject *args,
PyObject *keywords) {
@ -114,8 +116,25 @@ static PyObject* pyjmethodwrapper_call(PyJmethodWrapper_Object *self,
}
obj = self->object;
// pyjobject_find_method will actually call the method
ret = pyjobject_find_method(obj, self->method->pyMethodName, args);
Py_XDECREF(obj);
/*
* This seems odd to Py_DECREF(self), but we had to Py_INCREF it
* over in pyjobject_getattr so that the garbage collector doesn't
* collect it before we even got to __call__ it.
*
* And now we want to make sure it gets cleaned up and can't tell if
* it will be reused. If it is going to be reused, such as stored in
* a variable and repeatedly called, we're still safe. For example:
*
* m = obj.doIt
* while condition:
* m()
*
* As long as m is in scope, there will still be a reference so it won't
* get garbage collected until m goes out of scope.
*/
Py_DECREF(self);
return ret;
@ -127,7 +146,7 @@ static PyMethodDef pyjmethodwrapper_methods[] = {
};
static PyTypeObject PyJmethodWrapper_Type = {
PyTypeObject PyJmethodWrapper_Type = {
PyObject_HEAD_INIT(0)
0,
"jep.PyJmethodWrapper",

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP_AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,12 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
New file created with modifications to pyjmethod.h
*/
// shut up the compiler
@ -48,14 +42,23 @@
#include "pyjobject.h"
#include "pyjmethod.h"
/*
* PyJmethodWrapper_Object enables the ability to reuse a pyjmethod for
* multiple instances of pyjobjects of the same underlying Java type.
*
* Pyjmethods are tied to java.lang.Methods, which are tied
* to java.lang.Classes, which are shared across all instances of a particular
* Class. To ensure the right object is called with the method, the pyjmethod
* wrapper includes both the pyjobject instance doing the calling and the
* pyjmethod to be called.
*/
typedef struct {
PyObject_HEAD
PyJmethod_Object *method;
PyJobject_Object *object;
PyJmethod_Object *method; /* the original pyjmethod tied to a java.lang.reflect.Method */
PyJobject_Object *object; /* the pyjobject that called this method */
} PyJmethodWrapper_Object;
PyJmethodWrapper_Object* pyjmethodwrapper_new(
PyJobject_Object*, PyJmethod_Object*);
PyJmethodWrapper_Object* pyjmethodwrapper_new(PyJobject_Object*,
PyJmethod_Object*);
#endif // ndef pyjmethodwrapper

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -236,7 +236,8 @@ static int pyjobject_init(JNIEnv *env, PyJobject_Object *pyjob) {
*/
lock = (*env)->FindClass(env, "java/lang/String");
if((*env)->MonitorEnter(env, lock) != JNI_OK) {
PyErr_Format(PyExc_RuntimeError, "Couldn't get synchronization lock on class method creation.");
PyErr_Format(PyExc_RuntimeError,
"Couldn't get synchronization lock on class method creation.");
}
if(classnamePyJMethodsDict == NULL) {
classnamePyJMethodsDict = PyDict_New();
@ -257,8 +258,7 @@ static int pyjobject_init(JNIEnv *env, PyJobject_Object *pyjob) {
// but then i call the method using clazz. methodIds for java
// classes are shared....
methodArray = (jobjectArray) (*env)->CallObjectMethod(env,
pyjob->clazz,
methodArray = (jobjectArray) (*env)->CallObjectMethod(env, pyjob->clazz,
classGetMethods);
if(process_java_exception(env) || !methodArray)
goto EXIT_ERROR;
@ -270,9 +270,7 @@ static int pyjobject_init(JNIEnv *env, PyJobject_Object *pyjob) {
PyJmethod_Object *pymethod = NULL;
jobject rmethod = NULL;
rmethod = (*env)->GetObjectArrayElement(env,
methodArray,
i);
rmethod = (*env)->GetObjectArrayElement(env, methodArray, i);
// make new PyJmethod_Object, linked to pyjob
if(pyjob->object)
@ -296,17 +294,20 @@ static int pyjobject_init(JNIEnv *env, PyJobject_Object *pyjob) {
(*env)->DeleteLocalRef(env, methodArray);
} // end of setting up cache for this Java Class
if((*env)->MonitorExit(env, lock) != JNI_OK) {
PyErr_Format(PyExc_RuntimeError, "Couldn't release synchronization lock on class method creation.");
PyErr_Format(PyExc_RuntimeError,
"Couldn't release synchronization lock on class method creation.");
}
// end of synchronization
len = PyList_Size(cachedMethodList);
for (i = 0; i < len; i++) {
PyJmethod_Object* pymethod = (PyJmethod_Object*) PyList_GetItem(cachedMethodList, i);
if(PyObject_SetAttr((PyObject *) pyjob, pymethod->pyMethodName, (PyObject*) pymethod) != 0) {
PyErr_Format(PyExc_RuntimeError, "Couldn't add method as attribute.");
}
else {
PyJmethod_Object* pymethod = (PyJmethod_Object*) PyList_GetItem(
cachedMethodList, i);
if(PyObject_SetAttr((PyObject *) pyjob, pymethod->pyMethodName,
(PyObject*) pymethod) != 0) {
PyErr_Format(PyExc_RuntimeError,
"Couldn't add method as attribute.");
} else {
pyjobject_addmethod(pyjob, pymethod->pyMethodName);
}
} // end of cached method optimizations
@ -882,7 +883,7 @@ static PyMethodDef pyjobject_methods[] = {
};
static PyTypeObject PyJobject_Type = {
PyTypeObject PyJobject_Type = {
PyObject_HEAD_INIT(0)
0, /* ob_size */
"PyJobject", /* tp_name */
@ -908,7 +909,7 @@ static PyTypeObject PyJobject_Type = {
"jobject", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
pyjobject_richcompare, /* tp_richcompare */
(richcmpfunc) pyjobject_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2008 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -26,13 +26,6 @@
distribution.
*/
/*
August 2, 2012
Modified by Raytheon (c) 2012 Raytheon Company. All Rights Reserved.
Modifications marked and described by 'njensen'
*/
// shut up the compiler
#ifdef _POSIX_C_SOURCE
@ -59,16 +52,21 @@ typedef struct {
PyObject *methods; /* list of method names */
PyObject *fields; /* list of field names */
int finishAttr; /* true if object attributes are finished */
PyObject *jclassname; // added by njensen
PyObject *javaClassName; /* string of the fully-qualified name of
the object's Java clazz */
} PyJobject_Object;
PyAPI_DATA(PyTypeObject) PyJobject_Type;
PyObject* pyjobject_new(JNIEnv*, jobject);
PyObject* pyjobject_new_class(JNIEnv*, jclass);
PyObject* pyjobject_find_method(PyJobject_Object*, PyObject*, PyObject*);
int pyjobject_check(PyObject *obj);
//added by njensen
static PyObject* pyjobject_numpy(PyJobject_Object *obj);
// these methods need to be available to pyjlist
int pyjobject_setattr(PyJobject_Object*, char*, PyObject*);
PyObject* pyjobject_getattr(PyJobject_Object*, char*);
void pyjobject_dealloc(PyJobject_Object*);
PyObject* pyjobject_str(PyJobject_Object*);
#endif // ndef pyjobject

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
Copyright (c) 2015 JEP AUTHORS.
This file is licenced under the the zlib/libpng License.
@ -1302,7 +1302,7 @@ int pyarg_matches_jtype(JNIEnv *env,
break;
case JBOOLEAN_ID:
if(PyInt_Check(param))
if(PyBool_Check(param))
return 1;
break;
}
@ -2105,7 +2105,7 @@ PyObject* convert_jprimitivearray_pyndarray(JNIEnv *env,
return pyjob;
}
/**
/*
* Converts a jep.NDArray to a numpy ndarray.
*
* @param env the JNI environment

View file

@ -2,7 +2,7 @@
/*
jep - Java Embedded Python
Copyright (c) 2004 - 2011 Mike Johnson.
Copyright (c) JEP AUTHORS.
This file is licenced under the the zlib/libpng License.