Skip to content
Permalink
Browse files

Work on type conversions.

  • Loading branch information
Thrameos committed Mar 21, 2020
1 parent f1d07bd commit 2cbe28c64d6a62e98344695bb4f8391ba34d30ea
Showing with 23 additions and 19 deletions.
  1. +17 −4 doc/CHANGELOG.rst
  2. +4 −13 native/common/include/jp_primitive_accessor.h
  3. +2 −2 test/jpypetest/test_jmethod.py
@@ -7,8 +7,8 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o

- java.util.Map conforms to Python abc.Mapping API.

- float properly follows Java rules for conversion from double.
floats outside of range map to inf and -inf.
- JFloat properly follows Java rules for conversion from JDouble.
JFloats outside of range map to inf and -inf.

- Add support for direct conversion of multi-dimensional primitive arrays
with ``JArray.of(array, [dtype=type])``
@@ -24,12 +24,24 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o
- Proxies pass Python exceptions properly rather converting to
java.lang.RuntimeException

- java.lang.Number converts automatically from Python and Java numbers
- java.lang.Number converts automatically from Python and Java numbers.
Java primitive types will cast to their proper box type when passed
to methods and fields taking Number.

- java.lang.Object and java.lang.Number box signed, sized numpy types
(int8, int16, int32, int64, float32, float64) to the Java boxed type
with the same size automatically. Architecture dependent numpy
types map to Long or Double.
types map to Long or Double like other Python types.

- Explicit casting using primitives such as JInt will not produce an
OverflowError. Implicit casting from Python types such as int or float
will.

- Returns for number type primitives will retain their return type
information. These are derived from Python int and float types
thus no change in behavior unless chaining from a Java methods
which is not allowed in Java without a cast.
JBoolean and JChar still produce Python types only.

- Proxies created with JImplements properly implement toString, hashCode,
and equals.
@@ -40,6 +52,7 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o
- JProxy instances created with the convert=True argument will automatic
unwrap when passed from Java to Python.


- **0.7.2 - 2-28-2019**

- C++ and Java exceptions hold the traceback as a Python exception
@@ -182,7 +182,7 @@ class JPConversionLong : public JPConversion
} ;

template <typename base_t>
class JPConversionLongNumber : public JPConversion
class JPConversionLongNumber : public JPConversionLong<base_t>
{
public:

@@ -196,18 +196,9 @@ class JPConversionLongNumber : public JPConversion

virtual jvalue convert(JPMatch &match) override
{
jvalue res;
PyObject *obj = PyNumber_Long(match.object);
JP_PY_CHECK();
jlong val = PyLong_AsLongLong(obj);
Py_DECREF(obj);
if (val == -1)
JP_PY_CHECK();
if (match.type == JPMatch::_exact)
base_t::field(res) = (typename base_t::type_t) val;
else
base_t::field(res) = (typename base_t::type_t) base_t::assertRange(val);
return res;
JPPyObject obj = JPPyObject(JPPyRef::_call, PyNumber_Long(match.object));
match.object = obj.get();
return JPConversionLong<base_t>::convert(match);
}
} ;

@@ -243,8 +243,8 @@ def testJMethod_callFault(self):
def testJMethod_self(self):
Fixture = JClass("jpype.common.Fixture")
fixture = JClass("jpype.common.Fixture")()
self.assertEquals(fixture.callInt.__self__, fixture)
self.assertEquals(Fixture.callStaticInt.__self__, None)
self.assertEqual(fixture.callInt.__self__, fixture)
self.assertEqual(Fixture.callStaticInt.__self__, None)

def testJMethod_name(self):
fixture = JClass("jpype.common.Fixture")()

0 comments on commit 2cbe28c

Please sign in to comment.
You can’t perform that action at this time.