From e0821642a9348de819665bd53249bdb078ff2226 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Thu, 19 May 2022 08:34:13 +0200 Subject: [PATCH 001/128] Type hint the pysafe function, ensure it isn't leaked in public API, and enhance the testing --- jpype/_pykeywords.py | 65 ++++++++++++++++++++++++++++----- jpype/beans.py | 6 +-- test/jpypetest/test_keywords.py | 46 ++++++++++++++++------- 3 files changed, 91 insertions(+), 26 deletions(-) diff --git a/jpype/_pykeywords.py b/jpype/_pykeywords.py index 0c22631b1..70e10856d 100644 --- a/jpype/_pykeywords.py +++ b/jpype/_pykeywords.py @@ -15,21 +15,66 @@ # See NOTICE file for details. # # ***************************************************************************** +from __future__ import annotations + +import typing # This is a superset of the keywords in Python. # We use this so that jpype is a bit more version independent. -# Removing keywords from this list impacts the exposed interfaces, and therefore is a breaking change. -_KEYWORDS = set(( - 'False', 'None', 'True', 'and', 'as', 'assert', 'async', - 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', - 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', - 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'print', - 'raise', 'return', 'try', 'while', 'with', 'yield' -)) +# Adding and removing keywords from this list impacts the exposed interfaces, +# and therefore is technically a breaking change. +_KEYWORDS = { + 'False', + 'None', + 'True', + 'and', + 'as', + 'assert', + 'async', + 'await', + 'break', + 'class', + 'continue', + 'def', + 'del', + 'elif', + 'else', + 'except', + 'exec', + 'finally', + 'for', + 'from', + 'global', + 'if', + 'import', + 'in', + 'is', + 'lambda', + 'nonlocal', + 'not', + 'or', + 'pass', + 'print', # No longer a Python 3 keyword. Kept for backwards compatibility. + 'raise', + 'return', + 'try', + 'while', + 'with', + 'yield', +} + +def pysafe(s: str) -> typing.Optional[str]: + """ + Given an identifier name in Java, return an equivalent identifier name in + Python that is guaranteed to not collide with the Python grammar. -def pysafe(s): - if s.startswith("__"): + """ + if s.startswith("__") and s.endswith('__'): + # Dunder methods should not be considered safe. + # (see system defined names in the Python documentation + # https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers + # ) return None if s in _KEYWORDS: return s + "_" diff --git a/jpype/beans.py b/jpype/beans.py index e2e3f7b39..2e4bc2d2c 100644 --- a/jpype/beans.py +++ b/jpype/beans.py @@ -42,7 +42,7 @@ """ import _jpype from . import _jcustomizer -from ._pykeywords import pysafe +from ._pykeywords import pysafe as _pysafe def _extract_accessor_pairs(members): @@ -89,10 +89,10 @@ class _BeansCustomizer(object): def __jclass_init__(self): accessor_pairs = _extract_accessor_pairs(self.__dict__) for attr_name, (getter, setter) in accessor_pairs.items(): - attr_name = pysafe(attr_name) + attr_name = _pysafe(attr_name) # Don't mess with an existing member - if attr_name in self.__dict__: + if attr_name is None or attr_name in self.__dict__: continue # Add the property diff --git a/test/jpypetest/test_keywords.py b/test/jpypetest/test_keywords.py index 6c255770d..381b7f101 100644 --- a/test/jpypetest/test_keywords.py +++ b/test/jpypetest/test_keywords.py @@ -15,20 +15,40 @@ # See NOTICE file for details. # # ***************************************************************************** +import keyword # From the standard library. + +import pytest + import jpype -import common -import keyword -class KeywordsTestCase(common.JPypeTestCase): - def setUp(self): - common.JPypeTestCase.setUp(self) +@pytest.mark.parametrize( + "identifier", + list(keyword.kwlist) + [ + '__del__', + # Print is no longer a keyword in Python 3, but still protected to + # avoid API breaking in JPype v1. + 'print', + ] +) +def testPySafe__Keywords(identifier): + safe = jpype._pykeywords.pysafe(identifier) + if identifier.startswith("__"): + assert safe is None + else: + assert isinstance(safe, str), f"Fail on keyword {identifier}" + assert safe.endswith("_") + - def testKeywords(self): - for kw in keyword.kwlist: - safe = jpype._pykeywords.pysafe(kw) - if kw.startswith("_"): - continue - self.assertEqual(type(safe), str, "Fail on keyword %s" % kw) - self.assertTrue(safe.endswith("_")) - self.assertEqual(jpype._pykeywords.pysafe("__del__"), None) +@pytest.mark.parametrize( + "identifier", + [ + 'notSpecial', + '__notSpecial', + 'notSpecial__', + '_notSpecial_', + '_not__special_', + ]) +def testPySafe__NotKeywords(identifier): + safe = jpype._pykeywords.pysafe(identifier) + assert safe == identifier From b8e09a6c6f3fd277c4b61e8945ab81f529e3c7cc Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Mon, 23 May 2022 08:56:28 +0200 Subject: [PATCH 002/128] Include a test case for methods with double-underscore names --- jpype/_pykeywords.py | 2 +- test/harness/jpype/attr/TestKeywords.java | 30 +++++++++++++++++++++++ test/jpypetest/common.py | 2 -- test/jpypetest/test_keywords.py | 10 ++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/harness/jpype/attr/TestKeywords.java diff --git a/jpype/_pykeywords.py b/jpype/_pykeywords.py index 70e10856d..a438b80d4 100644 --- a/jpype/_pykeywords.py +++ b/jpype/_pykeywords.py @@ -70,7 +70,7 @@ def pysafe(s: str) -> typing.Optional[str]: Python that is guaranteed to not collide with the Python grammar. """ - if s.startswith("__") and s.endswith('__'): + if s.startswith("__") and s.endswith("__") and len(s) >= 4: # Dunder methods should not be considered safe. # (see system defined names in the Python documentation # https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers diff --git a/test/harness/jpype/attr/TestKeywords.java b/test/harness/jpype/attr/TestKeywords.java new file mode 100644 index 000000000..03dd4e86e --- /dev/null +++ b/test/harness/jpype/attr/TestKeywords.java @@ -0,0 +1,30 @@ +/* **************************************************************************** + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + See NOTICE file for details. +**************************************************************************** */ +package jpype.attr; + +public class TestKeywords +{ + + public String __leading_double_underscore() + { + return "foo"; + } + + public String __dunder_name__() + { + return "foo"; + } +} diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 1177eaeb2..7dee50d8a 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -127,8 +127,6 @@ def setUp(self): jpype.startJVM(jvm_path, *args, convertStrings=self._convertStrings) self.jpype = jpype.JPackage('jpype') - if sys.version < '3': - self.assertCountEqual = self.assertItemsEqual def tearDown(self): pass diff --git a/test/jpypetest/test_keywords.py b/test/jpypetest/test_keywords.py index 381b7f101..debe4f8ac 100644 --- a/test/jpypetest/test_keywords.py +++ b/test/jpypetest/test_keywords.py @@ -20,6 +20,7 @@ import pytest import jpype +import common @pytest.mark.parametrize( @@ -29,6 +30,7 @@ # Print is no longer a keyword in Python 3, but still protected to # avoid API breaking in JPype v1. 'print', + '____', # Not allowed. ] ) def testPySafe__Keywords(identifier): @@ -48,7 +50,15 @@ def testPySafe__Keywords(identifier): 'notSpecial__', '_notSpecial_', '_not__special_', + '__', '___', # Technically these are fine. ]) def testPySafe__NotKeywords(identifier): safe = jpype._pykeywords.pysafe(identifier) assert safe == identifier + + +class AttributeTestCase(common.JPypeTestCase): + def testPySafe(self): + cls = jpype.JPackage("jpype").attr.TestKeywords + self.assertTrue(hasattr(cls, "__leading_double_underscore")) + self.assertFalse(hasattr(cls, "__dunder_name__")) From c4d52524ccddaa664d8a597b7e67fee15c88ea19 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 13:51:25 +0200 Subject: [PATCH 003/128] compile with cxx14 std --- setupext/platform.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setupext/platform.py b/setupext/platform.py index 37f27e668..961e54ac1 100644 --- a/setupext/platform.py +++ b/setupext/platform.py @@ -77,19 +77,19 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): distutils.log.info("Add darwin settings") platform_specific['libraries'] = ['dl'] platform_specific['define_macros'] = [('MACOSX', 1)] - platform_specific['extra_compile_args'] = ['-g0', '-std=c++11', '-O2'] + platform_specific['extra_compile_args'] = ['-g0', '-std=c++14', '-O2'] jni_md_platform = 'darwin' elif platform.startswith('linux'): distutils.log.info("Add linux settings") platform_specific['libraries'] = ['dl'] - platform_specific['extra_compile_args'] = ['-g0', '-std=c++11', '-O2'] + platform_specific['extra_compile_args'] = ['-g0', '-std=c++14', '-O2'] jni_md_platform = 'linux' elif platform.startswith('aix7'): distutils.log.info("Add aix settings") platform_specific['libraries'] = ['dl'] - platform_specific['extra_compile_args'] = ['-g3', '-std=c++11', '-O2'] + platform_specific['extra_compile_args'] = ['-g3', '-std=c++14', '-O2'] jni_md_platform = 'aix7' elif platform.startswith('freebsd'): @@ -103,7 +103,7 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): elif platform.startswith('android'): distutils.log.info("Add android settings") platform_specific['libraries'] = ['dl', 'c++_shared', 'SDL2'] - platform_specific['extra_compile_args'] = ['-g0', '-std=c++11', '-fexceptions', '-frtti', '-O2'] + platform_specific['extra_compile_args'] = ['-g0', '-std=c++14', '-fexceptions', '-frtti', '-O2'] print("PLATFORM_SPECIFIC:", platform_specific) jni_md_platform = 'linux' From 64d4a3085eff43de4d1ea8172df0050f9d682ef0 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 13:53:21 +0200 Subject: [PATCH 004/128] clean unused imports --- setupext/build_ext.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/setupext/build_ext.py b/setupext/build_ext.py index a539b56b4..8d6d6264e 100644 --- a/setupext/build_ext.py +++ b/setupext/build_ext.py @@ -16,19 +16,17 @@ # See NOTICE file for details. # # ***************************************************************************** -import os -from setuptools.command.build_ext import build_ext -import sys -import subprocess import distutils.cmd import distutils.log -from distutils.errors import DistutilsPlatformError -from distutils.dir_util import copy_tree import glob -import re +import os import shlex import shutil -import sysconfig +import subprocess +from distutils.dir_util import copy_tree +from distutils.errors import DistutilsPlatformError + +from setuptools.command.build_ext import build_ext # This setup option constructs a prototype Makefile suitable for compiling From 460e6e94a001060002b502ccc25969920cc1c4e7 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 13:54:14 +0200 Subject: [PATCH 005/128] removed unused virtual (override already used). --- native/common/include/jp_arrayclass.h | 10 +- native/common/include/jp_booleantype.h | 50 ++++---- native/common/include/jp_boxedtype.h | 8 +- native/common/include/jp_buffertype.h | 2 +- native/common/include/jp_bytetype.h | 50 ++++---- native/common/include/jp_chartype.h | 52 ++++---- native/common/include/jp_class.h | 2 +- native/common/include/jp_classhints.h | 10 +- native/common/include/jp_classtype.h | 4 +- native/common/include/jp_doubletype.h | 50 ++++---- native/common/include/jp_floattype.h | 50 ++++---- native/common/include/jp_functional.h | 6 +- native/common/include/jp_inttype.h | 48 ++++---- native/common/include/jp_longtype.h | 50 ++++---- native/common/include/jp_method.h | 2 +- native/common/include/jp_methoddispatch.h | 2 +- native/common/include/jp_numbertype.h | 4 +- native/common/include/jp_objecttype.h | 2 +- native/common/include/jp_primitive_accessor.h | 32 ++--- native/common/include/jp_primitivetype.h | 4 +- native/common/include/jp_proxy.h | 16 +-- native/common/include/jp_shorttype.h | 50 ++++---- native/common/include/jp_stringtype.h | 8 +- native/common/include/jp_voidtype.h | 48 ++++---- native/common/jp_booleantype.cpp | 18 +-- native/common/jp_bytetype.cpp | 4 +- native/common/jp_chartype.cpp | 8 +- native/common/jp_classhints.cpp | 112 +++++++++--------- native/common/jp_doubletype.cpp | 6 +- native/common/jp_floattype.cpp | 4 +- native/common/jp_functional.cpp | 6 +- native/common/jp_inttype.cpp | 4 +- native/common/jp_longtype.cpp | 4 +- native/common/jp_platform.cpp | 6 +- native/common/jp_shorttype.cpp | 4 +- 35 files changed, 368 insertions(+), 368 deletions(-) diff --git a/native/common/include/jp_arrayclass.h b/native/common/include/jp_arrayclass.h index 9ffb325f8..167f582fe 100644 --- a/native/common/include/jp_arrayclass.h +++ b/native/common/include/jp_arrayclass.h @@ -28,11 +28,11 @@ class JPArrayClass : public JPClass JPClass* superClass, JPClass* componentType, jint modifiers); - virtual~ JPArrayClass(); + ~ JPArrayClass() override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; JPValue newArray(JPJavaFrame& frame, int length); @@ -54,7 +54,7 @@ class JPArrayClass : public JPClass return m_ComponentType; } - virtual bool isArray() const override + bool isArray() const override { return true; } diff --git a/native/common/include/jp_booleantype.h b/native/common/include/jp_booleantype.h index 6b19e0954..ddd5e2543 100755 --- a/native/common/include/jp_booleantype.h +++ b/native/common/include/jp_booleantype.h @@ -21,7 +21,7 @@ class JPBooleanType : public JPPrimitiveType public: JPBooleanType(); - virtual ~JPBooleanType(); + ~JPBooleanType() override; typedef jboolean type_t; typedef jbooleanArray array_t; @@ -36,32 +36,32 @@ class JPBooleanType : public JPPrimitiveType return v.z; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Boolean; } - virtual JPMatch::Type findJavaConversion(JPMatch& match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch& match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject *sequence) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'Z'; } @@ -70,26 +70,26 @@ class JPBooleanType : public JPPrimitiveType // These methods are required by primitive but are not used for a non // number type - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return field(v); } - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return field(v); } // GCOVR_EXCL_STOP - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_boxedtype.h b/native/common/include/jp_boxedtype.h index 2b6b64d21..c61a79e72 100644 --- a/native/common/include/jp_boxedtype.h +++ b/native/common/include/jp_boxedtype.h @@ -36,10 +36,10 @@ class JPBoxedType : public JPClass JPClassList& interfaces, jint modifiers, JPPrimitiveType* primitiveType); - virtual ~JPBoxedType(); + ~JPBoxedType() override; - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; JPPrimitiveType* getPrimitive() { @@ -47,7 +47,7 @@ class JPBoxedType : public JPClass } jobject box(JPJavaFrame &frame, jvalue v); - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; protected: JPPrimitiveType* m_PrimitiveType; diff --git a/native/common/include/jp_buffertype.h b/native/common/include/jp_buffertype.h index 2ccfa19bf..a045cc1b4 100644 --- a/native/common/include/jp_buffertype.h +++ b/native/common/include/jp_buffertype.h @@ -23,7 +23,7 @@ class JPBufferType : public JPClass { public: JPBufferType(JPJavaFrame& frame, jclass cls, const string& name, JPClass* superClass, const JPClassList& interfaces, jint modifiers); - virtual~ JPBufferType(); + ~ JPBufferType() override; char* getType() { diff --git a/native/common/include/jp_bytetype.h b/native/common/include/jp_bytetype.h index d4ee8586d..b93c0efdb 100755 --- a/native/common/include/jp_bytetype.h +++ b/native/common/include/jp_bytetype.h @@ -21,7 +21,7 @@ class JPByteType : public JPPrimitiveType public: JPByteType(); - virtual ~JPByteType() override; + ~JPByteType() override; public: typedef jbyte type_t; @@ -37,30 +37,30 @@ class JPByteType : public JPPrimitiveType return v.b; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Byte; } - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame &frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame &frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject*) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject*) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'B'; } @@ -74,25 +74,25 @@ class JPByteType : public JPPrimitiveType return l; } - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return field(v); } - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return field(v); } - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; private: diff --git a/native/common/include/jp_chartype.h b/native/common/include/jp_chartype.h index 730d57f22..f0ea7f925 100755 --- a/native/common/include/jp_chartype.h +++ b/native/common/include/jp_chartype.h @@ -21,13 +21,13 @@ class JPCharType : public JPPrimitiveType public: JPCharType(); - virtual ~JPCharType(); + ~JPCharType() override; public: typedef jchar type_t; typedef jcharArray array_t; - virtual JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; + JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; inline jchar& field(jvalue& v) { @@ -39,53 +39,53 @@ class JPCharType : public JPPrimitiveType return v.c; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Character; } - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject*) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject*) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'C'; } - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return field(v); } - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return field(v); } - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_class.h b/native/common/include/jp_class.h index 5c1419ca1..dfeaa3000 100644 --- a/native/common/include/jp_class.h +++ b/native/common/include/jp_class.h @@ -29,7 +29,7 @@ class JPClass : public JPResource JPClass* super, const JPClassList& interfaces, jint modifiers); - virtual ~JPClass(); + ~JPClass() override; void setHost(PyObject* host); diff --git a/native/common/include/jp_classhints.h b/native/common/include/jp_classhints.h index f2b8b8a20..b7599e869 100644 --- a/native/common/include/jp_classhints.h +++ b/native/common/include/jp_classhints.h @@ -32,7 +32,7 @@ class JPIndexConversion : public JPConversion { public: - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override; + void getInfo(JPClass *cls, JPConversionInfo &info) override; } ; @@ -40,16 +40,16 @@ class JPNumberConversion : public JPIndexConversion { public: - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override; + void getInfo(JPClass *cls, JPConversionInfo &info) override; } ; class JPConversionJavaValue : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override; - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override; - virtual jvalue convert(JPMatch &match) override; + JPMatch::Type matches(JPClass *cls, JPMatch &match) override; + void getInfo(JPClass *cls, JPConversionInfo &info) override; + jvalue convert(JPMatch &match) override; } ; class JPClassHints diff --git a/native/common/include/jp_classtype.h b/native/common/include/jp_classtype.h index e6c9d22c1..2c864766c 100644 --- a/native/common/include/jp_classtype.h +++ b/native/common/include/jp_classtype.h @@ -34,10 +34,10 @@ class JPClassType : public JPClass JPClassList& interfaces, jint modifiers); - virtual~ JPClassType(); + ~ JPClassType() override; public: // JPClass implementation - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; void getConversionInfo(JPConversionInfo &info) override; } ; diff --git a/native/common/include/jp_doubletype.h b/native/common/include/jp_doubletype.h index 209a204d2..101cb74f1 100755 --- a/native/common/include/jp_doubletype.h +++ b/native/common/include/jp_doubletype.h @@ -21,7 +21,7 @@ class JPDoubleType : public JPPrimitiveType public: JPDoubleType(); - virtual ~JPDoubleType(); + ~JPDoubleType() override; public: typedef jdouble type_t; @@ -37,31 +37,31 @@ class JPDoubleType : public JPPrimitiveType return v.d; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Double; } - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame &frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame &frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame &frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame &frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame &frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame &frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject*) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'D'; } @@ -70,26 +70,26 @@ class JPDoubleType : public JPPrimitiveType // These are required for primitives, but converters for do not currently // use them. - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return (jlong) field(v); } - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return (jdouble) field(v); } // GCOV_EXCL_STOP - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer& view, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_floattype.h b/native/common/include/jp_floattype.h index b0c73f4cf..69ce85e58 100755 --- a/native/common/include/jp_floattype.h +++ b/native/common/include/jp_floattype.h @@ -21,7 +21,7 @@ class JPFloatType : public JPPrimitiveType public: JPFloatType(); - virtual ~JPFloatType(); + ~JPFloatType() override; public: typedef jfloat type_t; @@ -37,32 +37,32 @@ class JPFloatType : public JPPrimitiveType return v.f; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Float; } - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame &frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame &frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject* sequence) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'F'; } @@ -70,26 +70,26 @@ class JPFloatType : public JPPrimitiveType // GCOVR_EXCL_START // This is required, but is not currently used. - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return (jlong) field(v); } // GCOVR_EXCL_STOP - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return (jdouble) field(v); } - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_functional.h b/native/common/include/jp_functional.h index 0e833fa0a..4fbc9fb0d 100644 --- a/native/common/include/jp_functional.h +++ b/native/common/include/jp_functional.h @@ -25,10 +25,10 @@ class JPFunctional : public JPClass JPClass* super, JPClassList& interfaces, jint modifiers); - virtual ~JPFunctional(); + ~JPFunctional() override; - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; string getMethod() { diff --git a/native/common/include/jp_inttype.h b/native/common/include/jp_inttype.h index 590be95bb..ac3d21fd7 100755 --- a/native/common/include/jp_inttype.h +++ b/native/common/include/jp_inttype.h @@ -21,7 +21,7 @@ class JPIntType : public JPPrimitiveType public: JPIntType(); - virtual ~JPIntType(); + ~JPIntType() override; public: typedef jint type_t; @@ -37,42 +37,42 @@ class JPIntType : public JPPrimitiveType return v.i; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Integer; } - virtual JPMatch::Type findJavaConversion(JPMatch& match) override; + JPMatch::Type findJavaConversion(JPMatch& match) override; void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject* sequence) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'I'; } - virtual jlong getAsLong(jvalue v) override // GCOVR_EXCL_LINE + jlong getAsLong(jvalue v) override // GCOVR_EXCL_LINE { return field(v); // GCOVR_EXCL_LINE } - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return field(v); } @@ -86,15 +86,15 @@ class JPIntType : public JPPrimitiveType return l; } - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_longtype.h b/native/common/include/jp_longtype.h index 0c2be13a0..67dead346 100755 --- a/native/common/include/jp_longtype.h +++ b/native/common/include/jp_longtype.h @@ -21,7 +21,7 @@ class JPLongType : public JPPrimitiveType public: JPLongType(); - virtual ~JPLongType(); + ~JPLongType() override; typedef jlong type_t; typedef jlongArray array_t; @@ -36,32 +36,32 @@ class JPLongType : public JPPrimitiveType return v.j; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Long; } - virtual JPMatch::Type findJavaConversion(JPMatch& match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch& match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject *sequence) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'J'; } @@ -69,13 +69,13 @@ class JPLongType : public JPPrimitiveType // GCOVR_EXCL_START // Required but not exercised currently - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return (jlong) field(v); } // GCOVR_EXCL_STOP - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return (jdouble) field(v); } @@ -85,15 +85,15 @@ class JPLongType : public JPPrimitiveType return l; } - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_method.h b/native/common/include/jp_method.h index 385e18202..dc889fcf3 100644 --- a/native/common/include/jp_method.h +++ b/native/common/include/jp_method.h @@ -31,7 +31,7 @@ class JPMethod : public JPResource JPMethodList& moreSpecific, jint modifiers); - virtual ~JPMethod(); + ~JPMethod() override; void setParameters( JPClass *returnType, diff --git a/native/common/include/jp_methoddispatch.h b/native/common/include/jp_methoddispatch.h index 462bb2c39..af90d2a68 100644 --- a/native/common/include/jp_methoddispatch.h +++ b/native/common/include/jp_methoddispatch.h @@ -30,7 +30,7 @@ class JPMethodDispatch : public JPResource JPMethodList& overloads, jint modifiers); - virtual ~JPMethodDispatch(); + ~JPMethodDispatch() override; private: JPMethodDispatch(const JPMethodDispatch& method); diff --git a/native/common/include/jp_numbertype.h b/native/common/include/jp_numbertype.h index d83fab56c..e0ab0785c 100644 --- a/native/common/include/jp_numbertype.h +++ b/native/common/include/jp_numbertype.h @@ -28,10 +28,10 @@ class JPNumberType : public JPClass JPClassList& interfaces, jint modifiers); - virtual~ JPNumberType(); + ~ JPNumberType() override; JPMatch::Type findJavaConversion(JPMatch& match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; + void getConversionInfo(JPConversionInfo &info) override; } ; #endif // _JPNUMBERTYPE_H_ \ No newline at end of file diff --git a/native/common/include/jp_objecttype.h b/native/common/include/jp_objecttype.h index 87d20452a..83d81a50d 100644 --- a/native/common/include/jp_objecttype.h +++ b/native/common/include/jp_objecttype.h @@ -34,7 +34,7 @@ class JPObjectType : public JPClass JPClassList& interfaces, jint modifiers); - virtual~ JPObjectType(); + ~ JPObjectType() override; JPMatch::Type findJavaConversion(JPMatch& match) override; void getConversionInfo(JPConversionInfo &info) override; diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index 8e72d809b..0fa72ec84 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -176,7 +176,7 @@ class JPConversionLong : public JPIndexConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyLong_CheckExact(match.object) && !PyIndex_Check(match.object)) return match.type = JPMatch::_none; @@ -184,7 +184,7 @@ class JPConversionLong : public JPIndexConversion return match.type = JPMatch::_implicit; } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; if (match.type == JPMatch::_exact) @@ -209,7 +209,7 @@ class JPConversionLongNumber : public JPConversionLong { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyNumber_Check(match.object)) return match.type = JPMatch::_none; @@ -217,14 +217,14 @@ class JPConversionLongNumber : public JPConversionLong return match.type = JPMatch::_explicit; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "SupportsFloat")); PyList_Append(info.expl, proto.get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPPyObject obj = JPPyObject::call(PyNumber_Long(match.object)); match.object = obj.get(); @@ -238,18 +238,18 @@ class JPConversionLongWiden : public JPConversion public: // GCOVR_EXCL_START - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { return JPMatch::_none; // Not used } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { // Not used } // GCOVR_EXCL_STOP - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPValue *value = match.getJavaSlot(); jvalue ret; @@ -264,7 +264,7 @@ class JPConversionAsFloat : public JPNumberConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyNumber_Check(match.object)) return match.type = JPMatch::_none; @@ -272,7 +272,7 @@ class JPConversionAsFloat : public JPNumberConversion return match.type = JPMatch::_implicit; } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; double val = PyFloat_AsDouble(match.object); @@ -288,7 +288,7 @@ class JPConversionLongAsFloat : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyLong_Check(match.object)) return match.type = JPMatch::_none; @@ -296,12 +296,12 @@ class JPConversionLongAsFloat : public JPConversion return match.type = JPMatch::_implicit; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.implicit, (PyObject*) & PyLong_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; jdouble v = PyLong_AsDouble(match.object); @@ -319,17 +319,17 @@ class JPConversionFloatWiden : public JPConversion // GCOVR_EXCL_START - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { return JPMatch::_none; // not used } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { } // GCOVR_EXCL_STOP - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPValue *value = match.getJavaSlot(); jvalue ret; diff --git a/native/common/include/jp_primitivetype.h b/native/common/include/jp_primitivetype.h index 281bebf71..e0a7514d1 100644 --- a/native/common/include/jp_primitivetype.h +++ b/native/common/include/jp_primitivetype.h @@ -21,10 +21,10 @@ class JPPrimitiveType : public JPClass { protected: JPPrimitiveType(const string& name); - virtual ~JPPrimitiveType(); + ~JPPrimitiveType() override; public: - virtual bool isPrimitive() const override; + bool isPrimitive() const override; virtual JPClass* getBoxedClass(JPContext *context) const = 0; diff --git a/native/common/include/jp_proxy.h b/native/common/include/jp_proxy.h index 04edeba34..6739be12f 100644 --- a/native/common/include/jp_proxy.h +++ b/native/common/include/jp_proxy.h @@ -54,24 +54,24 @@ class JPProxyDirect : public JPProxy { public: JPProxyDirect(JPContext* context, PyJPProxy* inst, JPClassList& intf); - virtual ~JPProxyDirect(); - virtual JPPyObject getCallable(const string& cname) override; + ~JPProxyDirect() override; + JPPyObject getCallable(const string& cname) override; } ; class JPProxyIndirect : public JPProxy { public: JPProxyIndirect(JPContext* context, PyJPProxy* inst, JPClassList& intf); - virtual ~JPProxyIndirect(); - virtual JPPyObject getCallable(const string& cname) override; + ~JPProxyIndirect() override; + JPPyObject getCallable(const string& cname) override; } ; class JPProxyFunctional : public JPProxy { public: JPProxyFunctional(JPContext* context, PyJPProxy* inst, JPClassList& intf); - virtual ~JPProxyFunctional(); - virtual JPPyObject getCallable(const string& cname) override; + ~JPProxyFunctional() override; + JPPyObject getCallable(const string& cname) override; private: JPFunctional *m_Functional; } ; @@ -87,10 +87,10 @@ class JPProxyType : public JPClass JPClass* super, JPClassList& interfaces, jint modifiers); - virtual~ JPProxyType(); + ~ JPProxyType() override; public: // JPClass implementation - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; private: JPClassRef m_ProxyClass; diff --git a/native/common/include/jp_shorttype.h b/native/common/include/jp_shorttype.h index 5a919cb1a..c22214606 100755 --- a/native/common/include/jp_shorttype.h +++ b/native/common/include/jp_shorttype.h @@ -21,7 +21,7 @@ class JPShortType : public JPPrimitiveType public: JPShortType(); - virtual ~JPShortType(); + ~JPShortType() override; typedef jshort type_t; typedef jshortArray array_t; @@ -36,42 +36,42 @@ class JPShortType : public JPPrimitiveType return v.s; } - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Short; } - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + void getConversionInfo(JPConversionInfo &info) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject *sequence) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual char getTypeCode() override + char getTypeCode() override { return 'S'; } - virtual jlong getAsLong(jvalue v) override + jlong getAsLong(jvalue v) override { return field(v); } - virtual jdouble getAsDouble(jvalue v) override + jdouble getAsDouble(jvalue v) override { return field(v); } @@ -85,15 +85,15 @@ class JPShortType : public JPPrimitiveType return l; } - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer &buffer, int subs, int base, jobject dims) override; } ; diff --git a/native/common/include/jp_stringtype.h b/native/common/include/jp_stringtype.h index 20c5345f5..ce634d17e 100644 --- a/native/common/include/jp_stringtype.h +++ b/native/common/include/jp_stringtype.h @@ -26,13 +26,13 @@ class JPStringType : public JPClass JPClass* super, JPClassList& interfaces, jint modifiers); - virtual ~JPStringType(); + ~JPStringType() override; public: - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; JPMatch::Type findJavaConversion(JPMatch& match) override; - virtual void getConversionInfo(JPConversionInfo &info) override; - virtual JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; + void getConversionInfo(JPConversionInfo &info) override; + JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; } ; #endif /* JP_STRINGTYPE_H */ \ No newline at end of file diff --git a/native/common/include/jp_voidtype.h b/native/common/include/jp_voidtype.h index 039119798..f22382652 100755 --- a/native/common/include/jp_voidtype.h +++ b/native/common/include/jp_voidtype.h @@ -21,44 +21,44 @@ class JPVoidType : public JPPrimitiveType public: JPVoidType(); - virtual ~JPVoidType(); + ~JPVoidType() override; - virtual JPClass* getBoxedClass(JPContext *context) const override + JPClass* getBoxedClass(JPContext *context) const override { return context->_java_lang_Void; } - virtual JPMatch::Type findJavaConversion(JPMatch &match) override; - virtual JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; + JPMatch::Type findJavaConversion(JPMatch &match) override; + JPPyObject convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) override; - virtual JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; - virtual JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; + JPPyObject invokeStatic(JPJavaFrame& frame, jclass, jmethodID, jvalue*) override; + JPPyObject invoke(JPJavaFrame& frame, jobject, jclass, jmethodID, jvalue*) override; - virtual JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; - virtual void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; - virtual JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; - virtual void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; + JPPyObject getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) override; + void setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObject* val) override; + JPPyObject getField(JPJavaFrame& frame, jobject c, jfieldID fid) override; + void setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* val) override; - virtual jarray newArrayOf(JPJavaFrame& frame, jsize size) override; - virtual void setArrayRange(JPJavaFrame& frame, jarray, + jarray newArrayOf(JPJavaFrame& frame, jsize size) override; + void setArrayRange(JPJavaFrame& frame, jarray, jsize start, jsize length, jsize step, PyObject *sequence) override; - virtual JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; - virtual void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; - virtual JPValue getValueFromObject(const JPValue& obj) override; + JPPyObject getArrayItem(JPJavaFrame& frame, jarray, jsize ndx) override; + void setArrayItem(JPJavaFrame& frame, jarray, jsize ndx, PyObject* val) override; + JPValue getValueFromObject(const JPValue& obj) override; - virtual char getTypeCode() override; - virtual jlong getAsLong(jvalue v) override; - virtual jdouble getAsDouble(jvalue v) override; + char getTypeCode() override; + jlong getAsLong(jvalue v) override; + jdouble getAsDouble(jvalue v) override; - virtual void getView(JPArrayView& view) override; - virtual void releaseView(JPArrayView& view) override; - virtual const char* getBufferFormat() override; - virtual Py_ssize_t getItemSize() override; - virtual void copyElements(JPJavaFrame &frame, + void getView(JPArrayView& view) override; + void releaseView(JPArrayView& view) override; + const char* getBufferFormat() override; + Py_ssize_t getItemSize() override; + void copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) override; - virtual PyObject *newMultiArray(JPJavaFrame &frame, + PyObject *newMultiArray(JPJavaFrame &frame, JPPyBuffer& view, int subs, int base, jobject dims) override; } ; diff --git a/native/common/jp_booleantype.cpp b/native/common/jp_booleantype.cpp index 25a6317ce..80c5d8d86 100644 --- a/native/common/jp_booleantype.cpp +++ b/native/common/jp_booleantype.cpp @@ -47,7 +47,7 @@ class JPConversionAsBoolean : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyBool_Check(match.object)) return match.type = JPMatch::_none; @@ -55,12 +55,12 @@ class JPConversionAsBoolean : public JPConversion return match.type = JPMatch::_exact; } - virtual void getInfo(JPClass * cls, JPConversionInfo &info) override + void getInfo(JPClass * cls, JPConversionInfo &info) override { PyList_Append(info.exact, (PyObject*) & PyBool_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; jlong v = PyObject_IsTrue(match.object); @@ -75,7 +75,7 @@ class JPConversionAsBooleanJBool : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); @@ -91,7 +91,7 @@ class JPConversionAsBooleanJBool : public JPConversionJavaValue return JPMatch::_implicit; // search no further. } - void getInfo(JPClass *cls, JPConversionInfo &info) + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_boolean->getHost()); @@ -104,7 +104,7 @@ class JPConversionAsBooleanLong : public JPConversionAsBoolean { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyLong_CheckExact(match.object) && !PyIndex_Check(match.object)) @@ -113,7 +113,7 @@ class JPConversionAsBooleanLong : public JPConversionAsBoolean return match.type = JPMatch::_implicit; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "SupportsIndex")); @@ -126,7 +126,7 @@ class JPConversionAsBooleanNumber : public JPConversionAsBoolean { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyNumber_Check(match.object)) return match.type = JPMatch::_none; @@ -134,7 +134,7 @@ class JPConversionAsBooleanNumber : public JPConversionAsBoolean return match.type = JPMatch::_explicit; } - virtual void getInfo(JPClass * cls, JPConversionInfo &info) override + void getInfo(JPClass * cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "SupportsFloat")); diff --git a/native/common/jp_bytetype.cpp b/native/common/jp_bytetype.cpp index a81db8407..51a90d2a5 100644 --- a/native/common/jp_bytetype.cpp +++ b/native/common/jp_bytetype.cpp @@ -54,7 +54,7 @@ class JPConversionJByte : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); if (value == NULL) @@ -69,7 +69,7 @@ class JPConversionJByte : public JPConversionJavaValue return JPMatch::_implicit; // stop the search } - void getInfo(JPClass *cls, JPConversionInfo &info) + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_byte->getHost()); diff --git a/native/common/jp_chartype.cpp b/native/common/jp_chartype.cpp index 24094bea5..e025b3553 100644 --- a/native/common/jp_chartype.cpp +++ b/native/common/jp_chartype.cpp @@ -79,12 +79,12 @@ class JPConversionAsChar : public JPConversion JP_TRACE_OUT; // GCOVR_EXCL_LINE } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.implicit, (PyObject*) & PyUnicode_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; res.c = JPPyString::asCharUTF16(match.object); @@ -96,7 +96,7 @@ class JPConversionAsJChar : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); if (value == NULL) @@ -113,7 +113,7 @@ class JPConversionAsJChar : public JPConversionJavaValue return JPMatch::_implicit; // stop search } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_char->getHost()); diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index 26494102f..d76cf32f2 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -144,11 +144,11 @@ class JPPythonConversion : public JPConversion method_ = JPPyObject::use(method); } - virtual ~JPPythonConversion() // GCOVR_EXCL_LINE + ~JPPythonConversion() override // GCOVR_EXCL_LINE { } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JP_TRACE_IN("JPPythonConversion::convert"); JPClass *cls = ((JPClass*) match.closure); @@ -190,11 +190,11 @@ class JPAttributeConversion : public JPPythonConversion { } - virtual ~JPAttributeConversion() // GCOVR_EXCL_LINE + ~JPAttributeConversion() override // GCOVR_EXCL_LINE { } - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPAttributeConversion::matches"); JPPyObject attr = JPPyObject::accept(PyObject_GetAttrString(match.object, attribute_.c_str())); @@ -206,7 +206,7 @@ class JPAttributeConversion : public JPPythonConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.attributes, JPPyString::fromStringUTF8(attribute_).get()); } @@ -237,11 +237,11 @@ class JPNoneConversion : public JPConversion type_ = JPPyObject::use(type); } - virtual ~JPNoneConversion() + ~JPNoneConversion() override { } - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPTypeConversion::matches"); if (!PyObject_IsInstance(match.object, type_.get())) @@ -253,12 +253,12 @@ class JPNoneConversion : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.none, type_.get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { return jvalue(); } @@ -277,11 +277,11 @@ class JPTypeConversion : public JPPythonConversion type_ = JPPyObject::use(type); } - virtual ~JPTypeConversion() + ~JPTypeConversion() override { } - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPTypeConversion::matches"); if ((exact_ && ((PyObject*) Py_TYPE(match.object)) == type_.get()) @@ -295,7 +295,7 @@ class JPTypeConversion : public JPPythonConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.implicit, type_.get()); } @@ -332,7 +332,7 @@ class JPHintsConversion : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { PyJPClassHints *pyhints = (PyJPClassHints*) cls->getHints(); // GCOVR_EXCL_START @@ -350,7 +350,7 @@ class JPHintsConversion : public JPConversion return match.type; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyJPClassHints *pyhints = (PyJPClassHints*) cls->getHints(); if (pyhints == NULL) @@ -359,7 +359,7 @@ class JPHintsConversion : public JPConversion hints->getInfo(cls, info); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { return jvalue(); } @@ -371,7 +371,7 @@ class JPConversionCharArray : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionCharArray::matches"); JPArrayClass* acls = (JPArrayClass*) cls; @@ -383,7 +383,7 @@ class JPConversionCharArray : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPArrayClass* acls = (JPArrayClass*) cls; if (acls->getComponentType() != cls->getContext()->_char) @@ -391,7 +391,7 @@ class JPConversionCharArray : public JPConversion PyList_Append(info.implicit, (PyObject*) & PyUnicode_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPJavaFrame *frame = match.frame; JP_TRACE("char[]"); @@ -413,7 +413,7 @@ class JPConversionByteArray : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionByteArray::matches"); JPArrayClass* acls = (JPArrayClass*) cls; @@ -425,7 +425,7 @@ class JPConversionByteArray : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPArrayClass* acls = (JPArrayClass*) cls; if (acls->getComponentType() != cls->getContext()->_byte) @@ -433,7 +433,7 @@ class JPConversionByteArray : public JPConversion PyList_Append(info.implicit, (PyObject*) & PyBytes_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPJavaFrame frame(*match.frame); jvalue res; @@ -451,7 +451,7 @@ class JPConversionBuffer : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionBuffer::matches"); JPArrayClass *acls = (JPArrayClass*) cls; @@ -489,12 +489,12 @@ class JPConversionBuffer : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { // This will be covered by Sequence } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JP_TRACE_IN("JPConversionBuffer::convert"); JPJavaFrame frame(*match.frame); @@ -514,7 +514,7 @@ class JPConversionSequence : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionSequence::matches"); if ( !PySequence_Check(match.object) || JPPyString::check(match.object)) @@ -546,7 +546,7 @@ class JPConversionSequence : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "Sequence")); @@ -557,7 +557,7 @@ class JPConversionSequence : public JPConversion PyList_Append(info.none, (PyObject*) & PyUnicode_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPJavaFrame frame(*match.frame); jvalue res; @@ -575,7 +575,7 @@ class JPConversionNull : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionNull::matches"); if (match.object != Py_None) @@ -585,11 +585,11 @@ class JPConversionNull : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue v; v.l = NULL; @@ -601,7 +601,7 @@ class JPConversionClass : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionClass::matches"); if (match.frame == NULL) @@ -615,13 +615,13 @@ class JPConversionClass : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); PyList_Append(info.implicit, (PyObject*) PyJPClass_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; JPClass* cls2 = (JPClass*) match.closure; @@ -634,7 +634,7 @@ class JPConversionObject : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionObject::matches"); JPValue *value = match.getJavaSlot(); @@ -661,13 +661,13 @@ class JPConversionObject : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); PyList_Append(info.exact, PyJPClass_create(frame, cls).get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; JPValue* value = match.getJavaSlot(); @@ -705,7 +705,7 @@ class JPConversionString : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionString::matches"); if (match.frame == NULL || !JPPyString::check(match.object)) @@ -717,12 +717,12 @@ class JPConversionString : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.implicit, (PyObject*) & PyUnicode_Type); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; string str = JPPyString::asStringUTF8(match.object); @@ -735,7 +735,7 @@ class JPConversionBox : public JPConversion { public: - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; JPPyObjectVector args(match.object, NULL); @@ -761,7 +761,7 @@ class JPConversionBoxBoolean : public JPConversionBox JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.implicit, (PyObject*) & PyBool_Type); } @@ -786,7 +786,7 @@ class JPConversionBoxLong : public JPConversionBox JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "SupportsIndex")); @@ -817,7 +817,7 @@ class JPConversionBoxDouble : public JPConversionBox { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionBoxDouble::matches"); if (match.frame == NULL) @@ -831,14 +831,14 @@ class JPConversionBoxDouble : public JPConversionBox JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "SupportsFloat")); PyList_Append(info.implicit, proto.get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPJavaFrame *frame = match.frame; PyTypeObject* type = Py_TYPE(match.object); @@ -858,7 +858,7 @@ class JPConversionJavaObjectAny : public JPConversionBox { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionJavaObjectAny::matches"); JPValue *value = match.getJavaSlot(); @@ -870,13 +870,13 @@ class JPConversionJavaObjectAny : public JPConversionBox JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); PyList_Append(info.implicit, PyJPClass_create(frame, cls->getContext()->_java_lang_Object).get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { jvalue res; JPJavaFrame *frame = match.frame; @@ -900,7 +900,7 @@ class JPConversionJavaNumberAny : public JPConversionJavaObjectAny { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionJavaNumberAny::matches"); JPContext *context = match.getContext(); @@ -925,7 +925,7 @@ class JPConversionJavaNumberAny : public JPConversionJavaObjectAny JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyList_Append(info.implicit, (PyObject*) PyJPNumberLong_Type); PyList_Append(info.implicit, (PyObject*) PyJPNumberFloat_Type); @@ -937,7 +937,7 @@ class JPConversionUnbox : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPContext *context = match.getContext(); if (context == NULL) @@ -951,7 +951,7 @@ class JPConversionUnbox : public JPConversion return match.type = JPMatch::_implicit; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); JPPrimitiveType *pcls = (JPPrimitiveType*) cls; @@ -960,7 +960,7 @@ class JPConversionUnbox : public JPConversion PyJPClass_create(frame, pcls->getBoxedClass(context)).get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPValue* value = match.getJavaSlot(); JPClass *cls = (JPClass*) match.closure; @@ -972,7 +972,7 @@ class JPConversionProxy : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionProxy::matches"); JPProxy* proxy = PyJPProxy_getJPProxy(match.object); @@ -994,11 +994,11 @@ class JPConversionProxy : public JPConversion JP_TRACE_OUT; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { return PyJPProxy_getJPProxy(match.object)->getProxy(); } diff --git a/native/common/jp_doubletype.cpp b/native/common/jp_doubletype.cpp index ab7c0643c..f092cbcf9 100644 --- a/native/common/jp_doubletype.cpp +++ b/native/common/jp_doubletype.cpp @@ -56,7 +56,7 @@ class JPConversionAsDoubleExact : public JPConversionAsFloat { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyFloat_CheckExact(match.object)) return match.type = JPMatch::_none; @@ -70,7 +70,7 @@ class JPConversionAsJDouble : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); if (value == NULL) @@ -108,7 +108,7 @@ class JPConversionAsJDouble : public JPConversionJavaValue } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_double->getHost()); diff --git a/native/common/jp_floattype.cpp b/native/common/jp_floattype.cpp index 317e88f17..b12693fcd 100644 --- a/native/common/jp_floattype.cpp +++ b/native/common/jp_floattype.cpp @@ -57,7 +57,7 @@ class JPConversionAsJFloat : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); if (value == NULL) @@ -93,7 +93,7 @@ class JPConversionAsJFloat : public JPConversionJavaValue return JPMatch::_implicit; // stop search } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_float->getHost()); diff --git a/native/common/jp_functional.cpp b/native/common/jp_functional.cpp index 47702256d..f41e9766a 100644 --- a/native/common/jp_functional.cpp +++ b/native/common/jp_functional.cpp @@ -37,7 +37,7 @@ class JPConversionFunctional : public JPConversion { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { if (!PyCallable_Check(match.object)) return match.type = JPMatch::_none; @@ -96,14 +96,14 @@ class JPConversionFunctional : public JPConversion return match.type = JPMatch::_implicit; } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "Callable")); PyList_Append(info.implicit, proto.get()); } - virtual jvalue convert(JPMatch &match) override + jvalue convert(JPMatch &match) override { JPFunctional *cls = (JPFunctional*) match.closure; JP_TRACE_IN("JPConversionFunctional::convert"); diff --git a/native/common/jp_inttype.cpp b/native/common/jp_inttype.cpp index 77defb97d..09b8f153d 100644 --- a/native/common/jp_inttype.cpp +++ b/native/common/jp_inttype.cpp @@ -57,7 +57,7 @@ class JPConversionJInt : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); if (value == NULL) @@ -91,7 +91,7 @@ class JPConversionJInt : public JPConversionJavaValue return JPMatch::_implicit; //short cut further checks } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_int->getHost()); diff --git a/native/common/jp_longtype.cpp b/native/common/jp_longtype.cpp index dc91feae1..259ac5ec9 100644 --- a/native/common/jp_longtype.cpp +++ b/native/common/jp_longtype.cpp @@ -55,7 +55,7 @@ class JPConversionJLong : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue* value = match.getJavaSlot(); if (value == NULL) @@ -90,7 +90,7 @@ class JPConversionJLong : public JPConversionJavaValue return JPMatch::_implicit; } - void getInfo(JPClass *cls, JPConversionInfo &info) + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_long->getHost()); diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index ae8a1878c..f5c73d498 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -112,7 +112,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter public: - virtual void loadLibrary(const char* path) override + void loadLibrary(const char* path) override { JP_TRACE_IN("LinuxPlatformAdapter::loadLibrary"); #if defined(_HPUX) && !defined(_IA64) @@ -137,7 +137,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter JP_TRACE_OUT; // GCOVR_EXCL_LINE } - virtual void unloadLibrary() override + void unloadLibrary() override { JP_TRACE_IN("LinuxPlatformAdapter::unloadLibrary"); int r = dlclose(jvmLibrary); @@ -150,7 +150,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter JP_TRACE_OUT; // GCOVR_EXCL_LINE } - virtual void* getSymbol(const char* name) override + void* getSymbol(const char* name) override { JP_TRACE_IN("LinuxPlatformAdapter::getSymbol"); JP_TRACE("Load", name); diff --git a/native/common/jp_shorttype.cpp b/native/common/jp_shorttype.cpp index 12e60d979..a524faf76 100644 --- a/native/common/jp_shorttype.cpp +++ b/native/common/jp_shorttype.cpp @@ -55,7 +55,7 @@ class JPConversionJShort : public JPConversionJavaValue { public: - virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override + JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue* value = match.getJavaSlot(); if (value == NULL) @@ -88,7 +88,7 @@ class JPConversionJShort : public JPConversionJavaValue return JPMatch::_implicit; //short cut further checks } - virtual void getInfo(JPClass *cls, JPConversionInfo &info) override + void getInfo(JPClass *cls, JPConversionInfo &info) override { JPContext *context = cls->getContext(); PyList_Append(info.exact, (PyObject*) context->_short->getHost()); From f45fe98e441f0f5d481e11e82e97b83681307b4c Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 13:57:23 +0200 Subject: [PATCH 006/128] use explicit ctor --- native/python/include/jp_pythontypes.h | 2 +- native/python/jp_pythontypes.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 58575cd1e..6e253a8f0 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -79,7 +79,7 @@ class JPPyObject * @param obj is the python object. * @param i is a dummy to make sure this ctor was not called accidentally. */ - JPPyObject(PyObject* obj, int i); + explicit JPPyObject(PyObject* obj); public: diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index 3bf4b4e37..60a07acec 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -50,7 +50,7 @@ JPPyObject JPPyObject::use(PyObject* obj) assertValid(obj); Py_INCREF(obj); } - return JPPyObject(obj, 0); + return JPPyObject(obj); } /** @@ -64,7 +64,7 @@ JPPyObject JPPyObject::accept(PyObject* obj) JP_TRACE_PY("pyref new(accept)", obj); if (obj == NULL) PyErr_Clear(); - return JPPyObject(obj, 1); + return JPPyObject(obj); } /** @@ -79,7 +79,7 @@ JPPyObject JPPyObject::claim(PyObject* obj) JP_TRACE_PY("pyref new(claim)", obj); ASSERT_NOT_NULL(obj); assertValid(obj); - return JPPyObject(obj, 2); + return JPPyObject(obj); } /** @@ -95,10 +95,10 @@ JPPyObject JPPyObject::call(PyObject* obj) JP_PY_CHECK(); ASSERT_NOT_NULL(obj); assertValid(obj); - return JPPyObject(obj, 3); + return JPPyObject(obj); } -JPPyObject::JPPyObject(PyObject* obj, int i) +JPPyObject::JPPyObject(PyObject* obj) : m_PyObject(obj) { } From d10a8ff4bf517cd21354415d0fa05c2b0b6a28fb Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:02:29 +0200 Subject: [PATCH 007/128] prefer using x = y; instead of typedef --- native/common/include/jp_booleantype.h | 4 ++-- native/common/include/jp_bytetype.h | 4 ++-- native/common/include/jp_chartype.h | 4 ++-- native/common/include/jp_context.h | 8 ++++---- native/common/include/jp_doubletype.h | 4 ++-- native/common/include/jp_exception.h | 6 +++--- native/common/include/jp_floattype.h | 4 ++-- native/common/include/jp_inttype.h | 4 ++-- native/common/include/jp_longtype.h | 4 ++-- native/common/include/jp_primitive_accessor.h | 5 +++-- native/common/include/jp_shorttype.h | 4 ++-- native/common/include/jpype.h | 16 ++++++++-------- native/common/jp_chartype.cpp | 2 +- 13 files changed, 35 insertions(+), 34 deletions(-) diff --git a/native/common/include/jp_booleantype.h b/native/common/include/jp_booleantype.h index ddd5e2543..cdc4b6d6a 100755 --- a/native/common/include/jp_booleantype.h +++ b/native/common/include/jp_booleantype.h @@ -23,8 +23,8 @@ class JPBooleanType : public JPPrimitiveType JPBooleanType(); ~JPBooleanType() override; - typedef jboolean type_t; - typedef jbooleanArray array_t; + using type_t = jboolean; + using array_t = jbooleanArray; static inline jboolean& field(jvalue& v) { diff --git a/native/common/include/jp_bytetype.h b/native/common/include/jp_bytetype.h index b93c0efdb..aceee617b 100755 --- a/native/common/include/jp_bytetype.h +++ b/native/common/include/jp_bytetype.h @@ -24,8 +24,8 @@ class JPByteType : public JPPrimitiveType ~JPByteType() override; public: - typedef jbyte type_t; - typedef jbyteArray array_t; + using type_t = jbyte; + using array_t = jbyteArray; static inline jbyte& field(jvalue& v) { diff --git a/native/common/include/jp_chartype.h b/native/common/include/jp_chartype.h index f0ea7f925..0b7f17e8a 100755 --- a/native/common/include/jp_chartype.h +++ b/native/common/include/jp_chartype.h @@ -24,8 +24,8 @@ class JPCharType : public JPPrimitiveType ~JPCharType() override; public: - typedef jchar type_t; - typedef jcharArray array_t; + using type_t = jchar; + using array_t = jcharArray; JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; diff --git a/native/common/include/jp_context.h b/native/common/include/jp_context.h index c5a3134dd..45fc8fa7a 100644 --- a/native/common/include/jp_context.h +++ b/native/common/include/jp_context.h @@ -67,10 +67,10 @@ class JPRef } } ; -typedef JPRef JPClassRef; -typedef JPRef JPObjectRef; -typedef JPRef JPArrayRef; -typedef JPRef JPThrowableRef; +using JPClassRef = JPRef; +using JPObjectRef = JPRef; +using JPArrayRef = JPRef; +using JPThrowableRef = JPRef; class JPStackInfo; class JPGarbageCollection; diff --git a/native/common/include/jp_doubletype.h b/native/common/include/jp_doubletype.h index 101cb74f1..49d77620a 100755 --- a/native/common/include/jp_doubletype.h +++ b/native/common/include/jp_doubletype.h @@ -24,8 +24,8 @@ class JPDoubleType : public JPPrimitiveType ~JPDoubleType() override; public: - typedef jdouble type_t; - typedef jdoubleArray array_t; + using type_t = jdouble; + using array_t = jdoubleArray; static inline jdouble& field(jvalue& v) { diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 7bcb6ef18..a60056f90 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -104,13 +104,13 @@ class JPStackInfo return line_; } } ; -typedef vector JPStackTrace; +using JPStackTrace = vector; -typedef union +using JPErrorUnion = union { int i; void* l; -} JPErrorUnion; +}; /** * Exception issued by JPype to indicate an internal problem. diff --git a/native/common/include/jp_floattype.h b/native/common/include/jp_floattype.h index 69ce85e58..ea29530cd 100755 --- a/native/common/include/jp_floattype.h +++ b/native/common/include/jp_floattype.h @@ -24,8 +24,8 @@ class JPFloatType : public JPPrimitiveType ~JPFloatType() override; public: - typedef jfloat type_t; - typedef jfloatArray array_t; + using type_t = jfloat; + using array_t = jfloatArray; static inline jfloat& field(jvalue& v) { diff --git a/native/common/include/jp_inttype.h b/native/common/include/jp_inttype.h index ac3d21fd7..7716a5279 100755 --- a/native/common/include/jp_inttype.h +++ b/native/common/include/jp_inttype.h @@ -24,8 +24,8 @@ class JPIntType : public JPPrimitiveType ~JPIntType() override; public: - typedef jint type_t; - typedef jintArray array_t; + using type_t = jint; + using array_t = jintArray; static inline jint& field(jvalue& v) { diff --git a/native/common/include/jp_longtype.h b/native/common/include/jp_longtype.h index 67dead346..baedcb743 100755 --- a/native/common/include/jp_longtype.h +++ b/native/common/include/jp_longtype.h @@ -23,8 +23,8 @@ class JPLongType : public JPPrimitiveType JPLongType(); ~JPLongType() override; - typedef jlong type_t; - typedef jlongArray array_t; + using type_t = jlong; + using array_t = jlongArray; static inline jlong& field(jvalue& v) { diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index 0fa72ec84..f090a9748 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -23,8 +23,9 @@ template class JPPrimitiveArrayAccessor { - typedef void (JPJavaFrame::*releaseFnc)(array_t, ptr_t, jint); - typedef ptr_t (JPJavaFrame::*accessFnc)(array_t, jboolean*); + using releaseFnc = void (JPJavaFrame::*)(array_t, ptr_t, jint); + typede; +using accessFnc = ptr_t (JPJavaFrame::*)(array_t, jboolean *); JPJavaFrame& _frame; array_t _array; diff --git a/native/common/include/jp_shorttype.h b/native/common/include/jp_shorttype.h index c22214606..f60c8d29c 100755 --- a/native/common/include/jp_shorttype.h +++ b/native/common/include/jp_shorttype.h @@ -23,8 +23,8 @@ class JPShortType : public JPPrimitiveType JPShortType(); ~JPShortType() override; - typedef jshort type_t; - typedef jshortArray array_t; + using type_t = jshort; + using array_t = jshortArray; static inline jshort& field(jvalue& v) { diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index 7930e2fc8..ca5dd8cbe 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -105,12 +105,12 @@ extern int PyJPModuleFault_check(uint32_t code); #endif /** Definition of commonly used template types */ -typedef vector StringVector; +using StringVector = vector; /** * Converter are used for bulk byte transfers from Python to Java. */ -typedef jvalue (*jconverter)(void*) ; +using jconverter = jvalue (*)(void *) ; /** * Create a converter for a bulk byte transfer. @@ -157,13 +157,13 @@ class JPContext; class JPBuffer; class JPPyObject; -extern "C" typedef void (*JCleanupHook)(void*) ; +extern "C" using JCleanupHook = void (*)(void *) ; extern "C" struct JPConversionInfo; -typedef vector JPClassList; -typedef vector JPFieldList; -typedef vector JPMethodDispatchList; -typedef vector JPMethodList; +using JPClassList = vector; +using JPFieldList = vector; +using JPMethodDispatchList = vector; +using JPMethodList = vector; class JPResource { @@ -183,7 +183,7 @@ class JPResource #ifndef PyObject_HEAD struct _object; -typedef _object PyObject; +using PyObject = _object; #endif // Base utility headers diff --git a/native/common/jp_chartype.cpp b/native/common/jp_chartype.cpp index e025b3553..f5841b94a 100644 --- a/native/common/jp_chartype.cpp +++ b/native/common/jp_chartype.cpp @@ -66,7 +66,7 @@ JPValue JPCharType::getValueFromObject(const JPValue& obj) class JPConversionAsChar : public JPConversion { - typedef JPCharType base_t; + using base_t = JPCharType; public: JPMatch::Type matches(JPClass *cls, JPMatch &match) override From 383bde1fd25f0196c7e3b0c1ed372e828231ca5b Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:11:08 +0200 Subject: [PATCH 008/128] f --- native/common/include/jp_primitive_accessor.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index f090a9748..5a8eccbb2 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -24,8 +24,7 @@ template class JPPrimitiveArrayAccessor { using releaseFnc = void (JPJavaFrame::*)(array_t, ptr_t, jint); - typede; -using accessFnc = ptr_t (JPJavaFrame::*)(array_t, jboolean *); + using accessFnc = ptr_t (JPJavaFrame::*)(array_t, jboolean *); JPJavaFrame& _frame; array_t _array; From 73f5b0187095750acd068ce50191c2e11d086523 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:11:41 +0200 Subject: [PATCH 009/128] removed unused header --- native/python/pyjp_value.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index 6947a7631..6159e8f20 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -15,7 +15,6 @@ *****************************************************************************/ #include "jpype.h" #include "pyjp.h" -#include "jp_boxedtype.h" #include "jp_stringtype.h" #ifdef __cplusplus From 58553d521249d4f307af452d8c44c3fc006bdaec Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:13:45 +0200 Subject: [PATCH 010/128] follow up-use-using (union) --- native/common/include/jp_exception.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index a60056f90..19d9b22ce 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -106,11 +106,11 @@ class JPStackInfo } ; using JPStackTrace = vector; -using JPErrorUnion = union +typedef union { - int i; - void* l; -}; + int i; + void* l; +} JPErrorUnion; /** * Exception issued by JPype to indicate an internal problem. From e4ea8baf2f521c80f2fd0bad9540c4de417fc8eb Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:33:06 +0200 Subject: [PATCH 011/128] use auto --- native/common/include/jp_primitive_accessor.h | 8 ++-- native/common/jp_array.cpp | 10 ++--- native/common/jp_arrayclass.cpp | 2 +- native/common/jp_booleantype.cpp | 4 +- native/common/jp_buffertype.cpp | 2 +- native/common/jp_bytetype.cpp | 6 +-- native/common/jp_chartype.cpp | 4 +- native/common/jp_class.cpp | 4 +- native/common/jp_classhints.cpp | 44 +++++++++---------- native/common/jp_classloader.cpp | 2 +- native/common/jp_context.cpp | 2 +- native/common/jp_doubletype.cpp | 8 ++-- native/common/jp_exception.cpp | 14 +++--- native/common/jp_floattype.cpp | 8 ++-- native/common/jp_functional.cpp | 8 ++-- native/common/jp_inttype.cpp | 6 +-- native/common/jp_javaframe.cpp | 4 +- native/common/jp_longtype.cpp | 8 ++-- native/common/jp_method.cpp | 10 ++--- native/common/jp_methoddispatch.cpp | 8 ++-- native/common/jp_primitivetype.cpp | 2 +- native/common/jp_proxy.cpp | 6 +-- native/common/jp_reference_queue.cpp | 2 +- native/common/jp_shorttype.cpp | 8 ++-- native/common/jp_typefactory.cpp | 32 +++++++------- native/common/jp_typemanager.cpp | 4 +- native/python/jp_pythontypes.cpp | 2 +- native/python/pyjp_array.cpp | 10 ++--- native/python/pyjp_char.cpp | 10 ++--- native/python/pyjp_class.cpp | 34 +++++++------- native/python/pyjp_classhints.cpp | 2 +- native/python/pyjp_field.cpp | 2 +- native/python/pyjp_method.cpp | 6 +-- native/python/pyjp_module.cpp | 8 ++-- native/python/pyjp_number.cpp | 6 +-- native/python/pyjp_object.cpp | 2 +- native/python/pyjp_package.cpp | 2 +- native/python/pyjp_proxy.cpp | 2 +- native/python/pyjp_value.cpp | 8 ++-- 39 files changed, 155 insertions(+), 155 deletions(-) diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index 5a8eccbb2..61fa5d31d 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -103,7 +103,7 @@ template PyObject *convertMultiArray( } // Reserve space for array. - jobjectArray contents = (jobjectArray) context->_java_lang_Object->newArrayOf(frame, subs); + auto contents = (jobjectArray) context->_java_lang_Object->newArrayOf(frame, subs); std::vector indices(view.ndim); int u = view.ndim - 1; int k = 0; @@ -112,7 +112,7 @@ template PyObject *convertMultiArray( jboolean isCopy; void *mem = frame.getEnv()->GetPrimitiveArrayCritical(a0, &isCopy); JP_TRACE_JAVA("GetPrimitiveArrayCritical", mem); - type_t *dest = (type_t*) mem; + auto *dest = (type_t*) mem; Py_ssize_t step; if (view.strides == NULL) @@ -189,13 +189,13 @@ class JPConversionLong : public JPIndexConversion jvalue res; if (match.type == JPMatch::_exact) { - jlong val = (jlong) PyLong_AsUnsignedLongLongMask(match.object); + auto val = (jlong) PyLong_AsUnsignedLongLongMask(match.object); if (val == -1) JP_PY_CHECK(); // GCOVR_EXCL_LINE base_t::field(res) = (typename base_t::type_t) val; } else { - jlong val = (jlong) PyLong_AsLongLong(match.object); + auto val = (jlong) PyLong_AsLongLong(match.object); if (val == -1) JP_PY_CHECK(); // GCOVR_EXCL_LINE base_t::field(res) = (typename base_t::type_t) base_t::assertRange(val); diff --git a/native/common/jp_array.cpp b/native/common/jp_array.cpp index 2adf57e90..f92fa3c68 100644 --- a/native/common/jp_array.cpp +++ b/native/common/jp_array.cpp @@ -135,7 +135,7 @@ jarray JPArray::clone(JPJavaFrame& frame, PyObject* obj) { JPValue value = m_Class->newArray(frame, m_Length); JPClass* compType = m_Class->getComponentType(); - jarray out = (jarray) value.getValue().l; + auto out = (jarray) value.getValue().l; compType->setArrayRange(frame, out, 0, m_Length, 1, obj); return out; } @@ -148,7 +148,7 @@ JPArrayView::JPArrayView(JPArray* array) m_Buffer.obj = NULL; m_Buffer.ndim = 1; m_Buffer.suboffsets = NULL; - JPPrimitiveType *type = (JPPrimitiveType*) array->getClass()->getComponentType(); + auto *type = (JPPrimitiveType*) array->getClass()->getComponentType(); type->getView(*this); m_Strides[0] = m_Buffer.itemsize * array->m_Step; m_Shape[0] = array->m_Length; @@ -172,7 +172,7 @@ JPArrayView::JPArrayView(JPArray* array, jobject collection) jobject item1 = frame.GetObjectArrayElement((jobjectArray) collection, 1); // First element is the primitive type that we are packing the array from - JPPrimitiveType *componentType = (JPPrimitiveType*) + auto *componentType = (JPPrimitiveType*) frame.findClass((jclass) item0); // Second element is the shape of the array from which we compute the @@ -211,7 +211,7 @@ JPArrayView::JPArrayView(JPArray* array, jobject collection) Py_ssize_t last = m_Shape[dims - 1]; for (Py_ssize_t i = 0; i < len - 2; i++) { - jarray a1 = (jarray) frame.GetObjectArrayElement((jobjectArray) collection, (jsize) i + 2); + auto a1 = (jarray) frame.GetObjectArrayElement((jobjectArray) collection, (jsize) i + 2); componentType->copyElements(frame, a1, 0, (jsize) last, m_Memory, offset); offset += (int) (itemsize * last); frame.DeleteLocalRef(a1); @@ -250,7 +250,7 @@ void JPArrayView::reference() bool JPArrayView::unreference() { m_RefCount--; - JPPrimitiveType *type = (JPPrimitiveType*) m_Array->getClass()->getComponentType(); + auto *type = (JPPrimitiveType*) m_Array->getClass()->getComponentType(); if (m_RefCount == 0 && !m_Owned) type->releaseView(*this); return m_RefCount == 0; diff --git a/native/common/jp_arrayclass.cpp b/native/common/jp_arrayclass.cpp index c719af0e6..bb80ce163 100644 --- a/native/common/jp_arrayclass.cpp +++ b/native/common/jp_arrayclass.cpp @@ -79,7 +79,7 @@ JPPyObject JPArrayClass::convertToPythonObject(JPJavaFrame& frame, jvalue value, jvalue JPArrayClass::convertToJavaVector(JPJavaFrame& frame, JPPyObjectVector& refs, jsize start, jsize end) { JP_TRACE_IN("JPArrayClass::convertToJavaVector"); - jsize length = (jsize) (end - start); + auto length = (jsize) (end - start); jarray array = m_ComponentType->newArrayOf(frame, length); jvalue res; diff --git a/native/common/jp_booleantype.cpp b/native/common/jp_booleantype.cpp index 80c5d8d86..213b8105f 100644 --- a/native/common/jp_booleantype.cpp +++ b/native/common/jp_booleantype.cpp @@ -288,7 +288,7 @@ void JPBooleanType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPBooleanType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetBooleanArrayRegion(array, ndx, 1, &val); jvalue v; @@ -341,7 +341,7 @@ Py_ssize_t JPBooleanType::getItemSize() void JPBooleanType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jboolean* b = (jboolean*) ((char*) memory + offset); + auto* b = (jboolean*) ((char*) memory + offset); frame.GetBooleanArrayRegion((jbooleanArray) a, start, len, b); } diff --git a/native/common/jp_buffertype.cpp b/native/common/jp_buffertype.cpp index 9fcbf4f61..16732b292 100644 --- a/native/common/jp_buffertype.cpp +++ b/native/common/jp_buffertype.cpp @@ -61,7 +61,7 @@ JPBufferType::JPBufferType(JPJavaFrame& frame, m_Size = 8; } else { - JPBufferType* super = dynamic_cast (m_SuperClass); + auto* super = dynamic_cast (m_SuperClass); if (super == NULL) JP_RAISE(PyExc_TypeError, "Unsupported buffer type"); // GCOVR_EXCL_LINE m_Type = super->m_Type; diff --git a/native/common/jp_bytetype.cpp b/native/common/jp_bytetype.cpp index 51a90d2a5..f4ef0b8c9 100644 --- a/native/common/jp_bytetype.cpp +++ b/native/common/jp_bytetype.cpp @@ -42,7 +42,7 @@ JPValue JPByteType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - JPBoxedType* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = (JPBoxedType*) frame.findClassForObject(jo); field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, 0); return JPValue(this, v); } @@ -226,7 +226,7 @@ void JPByteType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPByteType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetByteArrayRegion(array, ndx, 1, &val); jvalue v; @@ -279,7 +279,7 @@ Py_ssize_t JPByteType::getItemSize() void JPByteType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jbyte* b = (jbyte*) ((char*) memory + offset); + auto* b = (jbyte*) ((char*) memory + offset); frame.GetByteArrayRegion((jbyteArray) a, start, len, b); } diff --git a/native/common/jp_chartype.cpp b/native/common/jp_chartype.cpp index f5841b94a..376eb2fa6 100644 --- a/native/common/jp_chartype.cpp +++ b/native/common/jp_chartype.cpp @@ -229,7 +229,7 @@ void JPCharType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPCharType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetCharArrayRegion(array, ndx, 1, &val); jvalue v; @@ -282,7 +282,7 @@ Py_ssize_t JPCharType::getItemSize() void JPCharType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jchar* b = (jchar*) ((char*) memory + offset); + auto* b = (jchar*) ((char*) memory + offset); frame.GetCharArrayRegion((jcharArray) a, start, len, b); } diff --git a/native/common/jp_class.cpp b/native/common/jp_class.cpp index 3ff941aad..361e6fe31 100644 --- a/native/common/jp_class.cpp +++ b/native/common/jp_class.cpp @@ -263,7 +263,7 @@ void JPClass::setArrayRange(JPJavaFrame& frame, jarray a, PyObject* vals) { JP_TRACE_IN("JPClass::setArrayRange"); - jobjectArray array = (jobjectArray) a; + auto array = (jobjectArray) a; // Verify before we start the conversion, as we wont be able // to abort once we start @@ -307,7 +307,7 @@ void JPClass::setArrayItem(JPJavaFrame& frame, jarray a, jsize ndx, PyObject* va JPPyObject JPClass::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { JP_TRACE_IN("JPClass::getArrayItem"); - jobjectArray array = (jobjectArray) a; + auto array = (jobjectArray) a; jobject obj = frame.GetObjectArrayElement(array, ndx); JPClass *retType = this; diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index d76cf32f2..fcd4dd156 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -91,7 +91,7 @@ JPClassHints::JPClassHints() JPClassHints::~JPClassHints() { - for (std::list::iterator iter = conversions.begin(); + for (auto iter = conversions.begin(); iter != conversions.end(); ++iter) { delete *iter; @@ -102,7 +102,7 @@ JPClassHints::~JPClassHints() JPMatch::Type JPClassHints::getConversion(JPMatch& match, JPClass *cls) { JPConversion *best = NULL; - for (std::list::iterator iter = conversions.begin(); + for (auto iter = conversions.begin(); iter != conversions.end(); ++iter) { JPMatch::Type quality = (*iter)->matches(cls, match); @@ -321,7 +321,7 @@ void JPClassHints::excludeConversion(PyObject *type) void JPClassHints::getInfo(JPClass *cls, JPConversionInfo &info) { - for (std::list::iterator iter = conversions.begin(); + for (auto iter = conversions.begin(); iter != conversions.end(); ++iter) { (*iter)->getInfo(cls, info); @@ -334,7 +334,7 @@ class JPHintsConversion : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { - PyJPClassHints *pyhints = (PyJPClassHints*) cls->getHints(); + auto *pyhints = (PyJPClassHints*) cls->getHints(); // GCOVR_EXCL_START if (pyhints == NULL) { @@ -352,7 +352,7 @@ class JPHintsConversion : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { - PyJPClassHints *pyhints = (PyJPClassHints*) cls->getHints(); + auto *pyhints = (PyJPClassHints*) cls->getHints(); if (pyhints == NULL) return; JPClassHints *hints = pyhints->m_Hints; @@ -374,7 +374,7 @@ class JPConversionCharArray : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionCharArray::matches"); - JPArrayClass* acls = (JPArrayClass*) cls; + auto* acls = (JPArrayClass*) cls; if (match.frame == NULL || !JPPyString::check(match.object) || acls->getComponentType() != match.getContext()->_char) return match.type = JPMatch::_none; @@ -385,7 +385,7 @@ class JPConversionCharArray : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { - JPArrayClass* acls = (JPArrayClass*) cls; + auto* acls = (JPArrayClass*) cls; if (acls->getComponentType() != cls->getContext()->_char) return; PyList_Append(info.implicit, (PyObject*) & PyUnicode_Type); @@ -416,7 +416,7 @@ class JPConversionByteArray : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionByteArray::matches"); - JPArrayClass* acls = (JPArrayClass*) cls; + auto* acls = (JPArrayClass*) cls; if (match.frame == NULL || !PyBytes_Check(match.object) || acls->getComponentType() != match.frame->getContext()->_byte) return match.type = JPMatch::_none; @@ -427,7 +427,7 @@ class JPConversionByteArray : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { - JPArrayClass* acls = (JPArrayClass*) cls; + auto* acls = (JPArrayClass*) cls; if (acls->getComponentType() != cls->getContext()->_byte) return; PyList_Append(info.implicit, (PyObject*) & PyBytes_Type); @@ -454,7 +454,7 @@ class JPConversionBuffer : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionBuffer::matches"); - JPArrayClass *acls = (JPArrayClass*) cls; + auto *acls = (JPArrayClass*) cls; JPClass *componentType = acls->getComponentType(); if ( !componentType->isPrimitive()) return match.type = JPMatch::_none; @@ -499,8 +499,8 @@ class JPConversionBuffer : public JPConversion JP_TRACE_IN("JPConversionBuffer::convert"); JPJavaFrame frame(*match.frame); jvalue res; - JPArrayClass *acls = (JPArrayClass *) match.closure; - jsize length = (jsize) PySequence_Length(match.object); + auto *acls = (JPArrayClass *) match.closure; + auto length = (jsize) PySequence_Length(match.object); JPClass *ccls = acls->getComponentType(); jarray array = ccls->newArrayOf(frame, (jsize) length); ccls->setArrayRange(frame, array, 0, length, 1, match.object); @@ -519,7 +519,7 @@ class JPConversionSequence : public JPConversion JP_TRACE_IN("JPConversionSequence::matches"); if ( !PySequence_Check(match.object) || JPPyString::check(match.object)) return match.type = JPMatch::_none; - JPArrayClass *acls = (JPArrayClass*) cls; + auto *acls = (JPArrayClass*) cls; JPClass *componentType = acls->getComponentType(); JPPySequence seq = JPPySequence::use(match.object); jlong length = seq.size(); @@ -551,7 +551,7 @@ class JPConversionSequence : public JPConversion PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "Sequence")); PyList_Append(info.implicit, proto.get()); - JPArrayClass* acls = (JPArrayClass*) cls; + auto* acls = (JPArrayClass*) cls; if (acls->getComponentType() == cls->getContext()->_char) return; PyList_Append(info.none, (PyObject*) & PyUnicode_Type); @@ -561,8 +561,8 @@ class JPConversionSequence : public JPConversion { JPJavaFrame frame(*match.frame); jvalue res; - JPArrayClass *acls = (JPArrayClass *) match.closure; - jsize length = (jsize) PySequence_Length(match.object); + auto *acls = (JPArrayClass *) match.closure; + auto length = (jsize) PySequence_Length(match.object); JPClass *ccls = acls->getComponentType(); jarray array = ccls->newArrayOf(frame, (jsize) length); ccls->setArrayRange(frame, array, 0, length, 1, match.object); @@ -624,7 +624,7 @@ class JPConversionClass : public JPConversion jvalue convert(JPMatch &match) override { jvalue res; - JPClass* cls2 = (JPClass*) match.closure; + auto* cls2 = (JPClass*) match.closure; res.l = match.frame->NewLocalRef(cls2->getJavaClass()); return res; } @@ -739,7 +739,7 @@ class JPConversionBox : public JPConversion { jvalue res; JPPyObjectVector args(match.object, NULL); - JPClass *cls = (JPClass*) match.closure; + auto *cls = (JPClass*) match.closure; JPValue pobj = cls->newInstance(*match.frame, args); res.l = pobj.getJavaObject(); return res; @@ -888,7 +888,7 @@ class JPConversionJavaObjectAny : public JPConversionBox } else { // Okay we need to box it. - JPPrimitiveType* type = (JPPrimitiveType*) (value->getClass()); + auto* type = (JPPrimitiveType*) (value->getClass()); match.closure = type->getBoxedClass(frame->getContext()); res = JPConversionBox::convert(match); return res; @@ -943,7 +943,7 @@ class JPConversionUnbox : public JPConversion if (context == NULL) return match.type = JPMatch::_none; JPValue *slot = match.slot; - JPPrimitiveType *pcls = (JPPrimitiveType*) cls; + auto *pcls = (JPPrimitiveType*) cls; if (slot->getClass() != pcls->getBoxedClass(context)) return match.type = JPMatch::_none; match.conversion = this; @@ -954,7 +954,7 @@ class JPConversionUnbox : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); - JPPrimitiveType *pcls = (JPPrimitiveType*) cls; + auto *pcls = (JPPrimitiveType*) cls; JPContext *context = cls->getContext(); PyList_Append(info.implicit, PyJPClass_create(frame, pcls->getBoxedClass(context)).get()); @@ -963,7 +963,7 @@ class JPConversionUnbox : public JPConversion jvalue convert(JPMatch &match) override { JPValue* value = match.getJavaSlot(); - JPClass *cls = (JPClass*) match.closure; + auto *cls = (JPClass*) match.closure; return cls->getValueFromObject(*value); } } _unboxConversion; diff --git a/native/common/jp_classloader.cpp b/native/common/jp_classloader.cpp index ea22d6b62..b7c48ee46 100644 --- a/native/common/jp_classloader.cpp +++ b/native/common/jp_classloader.cpp @@ -99,7 +99,7 @@ JPClassLoader::JPClassLoader(JPJavaFrame& frame) v[0].l = frame.NewStringUTF("org.jpype.classloader.DynamicClassLoader"); v[1].z = true; v[2].l = cl; - jclass dyClass = (jclass) frame.CallStaticObjectMethodA(m_ClassClass.get(), m_ForNameID, v); + auto dyClass = (jclass) frame.CallStaticObjectMethodA(m_ClassClass.get(), m_ForNameID, v); // dycl.newInstance(systemClassLoader); jmethodID newDyLoader = frame.GetMethodID(dyClass, "", "(Ljava/lang/ClassLoader;)V"); diff --git a/native/common/jp_context.cpp b/native/common/jp_context.cpp index 40a017216..ae2a7c289 100644 --- a/native/common/jp_context.cpp +++ b/native/common/jp_context.cpp @@ -398,7 +398,7 @@ void JPContext::shutdownJVM(bool destroyJVM, bool freeJVM) } JP_TRACE("Delete resources"); - for (std::list::iterator iter = m_Resources.begin(); + for (auto iter = m_Resources.begin(); iter != m_Resources.end(); ++iter) { delete *iter; diff --git a/native/common/jp_doubletype.cpp b/native/common/jp_doubletype.cpp index f092cbcf9..27ad8d854 100644 --- a/native/common/jp_doubletype.cpp +++ b/native/common/jp_doubletype.cpp @@ -43,7 +43,7 @@ JPValue JPDoubleType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - JPBoxedType* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = (JPBoxedType*) frame.findClassForObject(jo); field(v) = (type_t) frame.CallDoubleMethodA(jo, jb->m_DoubleValueID, 0); return JPValue(this, v); } @@ -87,7 +87,7 @@ class JPConversionAsJDouble : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - JPPrimitiveType *prim = (JPPrimitiveType*) cls2; + auto *prim = (JPPrimitiveType*) cls2; switch (prim->getTypeCode()) { case 'B': @@ -267,7 +267,7 @@ void JPDoubleType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPDoubleType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetDoubleArrayRegion(array, ndx, 1, &val); jvalue v; @@ -320,7 +320,7 @@ Py_ssize_t JPDoubleType::getItemSize() void JPDoubleType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jdouble* b = (jdouble*) ((char*) memory + offset); + auto* b = (jdouble*) ((char*) memory + offset); frame.GetDoubleArrayRegion((jdoubleArray) a, start, len, b); } diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 477e99a86..f16121f12 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -202,7 +202,7 @@ void JPypeException::convertJavaToPython() } // GCOVR_EXCL_STOP - PyObject *type = (PyObject*) Py_TYPE(pyvalue.get()); + auto *type = (PyObject*) Py_TYPE(pyvalue.get()); Py_INCREF(type); // Add cause to the exception @@ -537,7 +537,7 @@ PyTracebackObject *tb_create( return NULL; // Create a traceback - PyTracebackObject *traceback = (PyTracebackObject*) + auto *traceback = (PyTracebackObject*) PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type); // We could fail in process @@ -563,7 +563,7 @@ PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace) { PyTracebackObject *last_traceback = NULL; PyObject *dict = PyModule_GetDict(PyJPModule); - for (JPStackTrace::iterator iter = trace.begin(); iter != trace.end(); ++iter) + for (auto iter = trace.begin(); iter != trace.end(); ++iter) { last_traceback = tb_create(last_traceback, dict, iter->getFile(), iter->getFunction(), iter->getLine()); @@ -584,7 +584,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab return JPPyObject(); JNIEnv* env = frame.getEnv(); - jobjectArray obj = (jobjectArray) env->CallObjectMethodA(context->getJavaContext(), + auto obj = (jobjectArray) env->CallObjectMethodA(context->getJavaContext(), context->m_Context_GetStackFrameID, args); // Eat any exceptions that were generated @@ -598,9 +598,9 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab for (jsize i = 0; i < sz; i += 4) { string filename, method; - jstring jclassname = (jstring) frame.GetObjectArrayElement(obj, i); - jstring jmethodname = (jstring) frame.GetObjectArrayElement(obj, i + 1); - jstring jfilename = (jstring) frame.GetObjectArrayElement(obj, i + 2); + auto jclassname = (jstring) frame.GetObjectArrayElement(obj, i); + auto jmethodname = (jstring) frame.GetObjectArrayElement(obj, i + 1); + auto jfilename = (jstring) frame.GetObjectArrayElement(obj, i + 2); if (jfilename != NULL) filename = frame.toStringUTF8(jfilename); else diff --git a/native/common/jp_floattype.cpp b/native/common/jp_floattype.cpp index b12693fcd..1eb53668c 100644 --- a/native/common/jp_floattype.cpp +++ b/native/common/jp_floattype.cpp @@ -44,7 +44,7 @@ JPValue JPFloatType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - JPBoxedType* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = (JPBoxedType*) frame.findClassForObject(jo); field(v) = (type_t) frame.CallFloatMethodA(jo, jb->m_FloatValueID, 0); return JPValue(this, v); } @@ -74,7 +74,7 @@ class JPConversionAsJFloat : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - JPPrimitiveType *prim = (JPPrimitiveType*) cls2; + auto *prim = (JPPrimitiveType*) cls2; switch (prim->getTypeCode()) { case 'B': @@ -250,7 +250,7 @@ void JPFloatType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPFloatType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetFloatArrayRegion(array, ndx, 1, &val); jvalue v; @@ -303,7 +303,7 @@ Py_ssize_t JPFloatType::getItemSize() void JPFloatType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jfloat* b = (jfloat*) ((char*) memory + offset); + auto* b = (jfloat*) ((char*) memory + offset); frame.GetFloatArrayRegion((jfloatArray) a, start, len, b); } diff --git a/native/common/jp_functional.cpp b/native/common/jp_functional.cpp index f41e9766a..687294917 100644 --- a/native/common/jp_functional.cpp +++ b/native/common/jp_functional.cpp @@ -55,7 +55,7 @@ class JPConversionFunctional : public JPConversion if (PyFunction_Check(match.object)) { PyObject* func = match.object; - PyCodeObject* code = (PyCodeObject*) PyFunction_GetCode(func); // borrowed + auto* code = (PyCodeObject*) PyFunction_GetCode(func); // borrowed Py_ssize_t args = code->co_argcount; bool is_varargs = ((code->co_flags&CO_VARARGS)==CO_VARARGS); int optional = 0; @@ -73,7 +73,7 @@ class JPConversionFunctional : public JPConversion else if (PyMethod_Check(match.object)) { PyObject* func = PyMethod_Function(match.object); // borrowed - PyCodeObject* code = (PyCodeObject*) PyFunction_GetCode(func); // borrowed + auto* code = (PyCodeObject*) PyFunction_GetCode(func); // borrowed Py_ssize_t args = code->co_argcount; bool is_varargs = ((code->co_flags&CO_VARARGS)==CO_VARARGS); int optional = 0; @@ -105,11 +105,11 @@ class JPConversionFunctional : public JPConversion jvalue convert(JPMatch &match) override { - JPFunctional *cls = (JPFunctional*) match.closure; + auto *cls = (JPFunctional*) match.closure; JP_TRACE_IN("JPConversionFunctional::convert"); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::inner(context); - PyJPProxy *self = (PyJPProxy*) PyJPProxy_Type->tp_alloc(PyJPProxy_Type, 0); + auto *self = (PyJPProxy*) PyJPProxy_Type->tp_alloc(PyJPProxy_Type, 0); JP_PY_CHECK(); JPClassList cl; cl.push_back(cls); diff --git a/native/common/jp_inttype.cpp b/native/common/jp_inttype.cpp index 09b8f153d..cd8efcb7d 100644 --- a/native/common/jp_inttype.cpp +++ b/native/common/jp_inttype.cpp @@ -44,7 +44,7 @@ JPValue JPIntType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - JPBoxedType* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = (JPBoxedType*) frame.findClassForObject(jo); field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, 0); return JPValue(this, v); } @@ -74,7 +74,7 @@ class JPConversionJInt : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - JPPrimitiveType *prim = (JPPrimitiveType*) cls2; + auto *prim = (JPPrimitiveType*) cls2; switch (prim->getTypeCode()) { case 'C': @@ -252,7 +252,7 @@ void JPIntType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPIntType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetIntArrayRegion(array, ndx, 1, &val); jvalue v; diff --git a/native/common/jp_javaframe.cpp b/native/common/jp_javaframe.cpp index 925042930..26f3b6eba 100644 --- a/native/common/jp_javaframe.cpp +++ b/native/common/jp_javaframe.cpp @@ -1075,7 +1075,7 @@ class JPStringAccessor string JPJavaFrame::toString(jobject o) { - jstring str = (jstring) CallObjectMethodA(o, m_Context->m_Object_ToStringID, 0); + auto str = (jstring) CallObjectMethodA(o, m_Context->m_Object_ToStringID, 0); return toStringUTF8(str); } @@ -1234,7 +1234,7 @@ jobject JPJavaFrame::getPackageObject(jobject pkg, const string& str) jarray JPJavaFrame::getPackageContents(jobject pkg) { jvalue v; - JAVA_RETURN(jarray, "JPJavaFrame::getPackageContents", + JAVA_RETURN(auto, "JPJavaFrame::getPackageContents", (jarray) CallObjectMethodA(pkg, m_Context->m_Package_GetContentsID, &v)); } diff --git a/native/common/jp_longtype.cpp b/native/common/jp_longtype.cpp index 259ac5ec9..a61b1647f 100644 --- a/native/common/jp_longtype.cpp +++ b/native/common/jp_longtype.cpp @@ -42,7 +42,7 @@ JPValue JPLongType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - JPBoxedType* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = (JPBoxedType*) frame.findClassForObject(jo); field(v) = (type_t) frame.CallLongMethodA(jo, jb->m_LongValueID, 0); return JPValue(this, v); } @@ -71,7 +71,7 @@ class JPConversionJLong : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - JPPrimitiveType *prim = (JPPrimitiveType*) cls2; + auto *prim = (JPPrimitiveType*) cls2; switch (prim->getTypeCode()) { case 'I': @@ -252,7 +252,7 @@ void JPLongType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPLongType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetLongArrayRegion(array, ndx, 1, &val); jvalue v; @@ -305,7 +305,7 @@ Py_ssize_t JPLongType::getItemSize() void JPLongType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jlong* b = (jlong*) ((char*) memory + offset); + auto* b = (jlong*) ((char*) memory + offset); frame.GetLongArrayRegion((jlongArray) a, start, len, b); } diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index 03048104f..b121ac3d5 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -56,7 +56,7 @@ string JPMethod::toString() const JPMatch::Type matchVars(JPJavaFrame &frame, JPMethodMatch& match, JPPyObjectVector &arg, size_t start, JPClass *vartype) { JP_TRACE_IN("JPMethod::matchVars"); - JPArrayClass *arraytype = (JPArrayClass*) vartype; + auto *arraytype = (JPArrayClass*) vartype; JPClass *type = arraytype->getComponentType(); size_t len = arg.size(); @@ -191,7 +191,7 @@ void JPMethod::packArgs(JPJavaFrame &frame, JPMethodMatch &match, { JP_TRACE("Pack indirect varargs"); len = tlen - 1; - JPArrayClass* type = (JPArrayClass*) m_ParameterTypes[tlen - 1]; + auto* type = (JPArrayClass*) m_ParameterTypes[tlen - 1]; v[tlen - 1 - match.m_Skip] = type->convertToJavaVector(frame, arg, (jsize) tlen - 1, (jsize) arg.size()); } @@ -284,7 +284,7 @@ JPPyObject JPMethod::invokeCallerSensitive(JPMethodMatch& match, JPPyObjectVecto JPClass *cls = m_ParameterTypes[i + match.m_Skip - match.m_Offset]; if (cls->isPrimitive()) { - JPPrimitiveType* type = (JPPrimitiveType*) cls; + auto* type = (JPPrimitiveType*) cls; PyObject *u = arg[i + match.m_Skip]; JPMatch conv(&frame, u); JPClass *boxed = type->getBoxedClass(context); @@ -345,7 +345,7 @@ string JPMethod::matchReport(JPPyObjectVector& args) res << m_ReturnType->getCanonicalName() << " ("; bool isFirst = true; - for (vector::iterator it = m_ParameterTypes.begin(); it != m_ParameterTypes.end(); it++) + for (auto it = m_ParameterTypes.begin(); it != m_ParameterTypes.end(); it++) { if (isFirst && !isStatic()) { @@ -386,7 +386,7 @@ string JPMethod::matchReport(JPPyObjectVector& args) bool JPMethod::checkMoreSpecificThan(JPMethod* other) const { - for (JPMethodList::const_iterator it = m_MoreSpecificOverloads.begin(); + for (auto it = m_MoreSpecificOverloads.begin(); it != m_MoreSpecificOverloads.end(); ++it) { diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index d1c5af5e8..86facd85b 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -72,7 +72,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch // Check each overload in order (the TypeManager orders them by priority // according to Java overload rules). - for (JPMethodList::iterator it = m_Overloads.begin(); it != m_Overloads.end(); ++it) + for (auto it = m_Overloads.begin(); it != m_Overloads.end(); ++it) { JPMethod* current = *it; @@ -145,7 +145,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << " between:" << std::endl; - for (vector::iterator it = ambiguous.begin(); it != ambiguous.end(); ++it) + for (auto it = ambiguous.begin(); it != ambiguous.end(); ++it) { ss << "\t" << (*it)->toString() << std::endl; } @@ -176,7 +176,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << ", options are:" << std::endl; - for (JPMethodList::iterator it = m_Overloads.begin(); + for (auto it = m_Overloads.begin(); it != m_Overloads.end(); ++it) { @@ -229,7 +229,7 @@ string JPMethodDispatch::matchReport(JPPyObjectVector& args) stringstream res; res << "Match report for method " << m_Name << ", has " << m_Overloads.size() << " overloads." << endl; - for (JPMethodList::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) + for (auto cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { JPMethod* current = *cur; res << " " << current->matchReport(args); diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index a530f04dd..c3e8f3502 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -40,7 +40,7 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) if (n < 0) n = -n; - PyLongObject *newobj = (PyLongObject *) wrapper->tp_alloc(wrapper, n); + auto *newobj = (PyLongObject *) wrapper->tp_alloc(wrapper, n); if (newobj == NULL) return NULL; diff --git a/native/common/jp_proxy.cpp b/native/common/jp_proxy.cpp index c65ba657d..53a85bc2d 100644 --- a/native/common/jp_proxy.cpp +++ b/native/common/jp_proxy.cpp @@ -54,7 +54,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( jlongArray parameterTypePtrs, jobjectArray args) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); // We need the resources to be held for the full duration of the proxy. @@ -90,7 +90,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( } // Find the return type - JPClass* returnClass = (JPClass*) returnTypePtr; + auto* returnClass = (JPClass*) returnTypePtr; JP_TRACE("Get return type", returnClass->getCanonicalName()); // convert the arguments into a python list @@ -123,7 +123,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( if (returnClass->findJavaConversion(returnMatch) == JPMatch::_none) JP_RAISE(PyExc_TypeError, "Return value is not compatible with required type."); jvalue res = returnMatch.convert(); - JPBoxedType *boxed = (JPBoxedType *) ((JPPrimitiveType*) returnClass)->getBoxedClass(context); + auto *boxed = (JPBoxedType *) ((JPPrimitiveType*) returnClass)->getBoxedClass(context); jvalue res2; res2.l = boxed->box(frame, res); return frame.keep(res2.l); diff --git a/native/common/jp_reference_queue.cpp b/native/common/jp_reference_queue.cpp index 131fc40a6..c5d204cba 100644 --- a/native/common/jp_reference_queue.cpp +++ b/native/common/jp_reference_queue.cpp @@ -55,7 +55,7 @@ JNIEXPORT void JNICALL Java_org_jpype_ref_JPypeReferenceNative_removeHostReferen JPPyCallAcquire callback; if (cleanup != 0) { - JCleanupHook func = (JCleanupHook) cleanup; + auto func = (JCleanupHook) cleanup; (*func)((void*) host); } } catch (...) // GCOVR_EXCL_LINE diff --git a/native/common/jp_shorttype.cpp b/native/common/jp_shorttype.cpp index a524faf76..87609e225 100644 --- a/native/common/jp_shorttype.cpp +++ b/native/common/jp_shorttype.cpp @@ -42,7 +42,7 @@ JPValue JPShortType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - JPBoxedType* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = (JPBoxedType*) frame.findClassForObject(jo); field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, 0); return JPValue(this, v); } @@ -72,7 +72,7 @@ class JPConversionJShort : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - JPPrimitiveType *prim = (JPPrimitiveType*) cls2; + auto *prim = (JPPrimitiveType*) cls2; switch (prim->getTypeCode()) { case 'C': @@ -249,7 +249,7 @@ void JPShortType::setArrayRange(JPJavaFrame& frame, jarray a, JPPyObject JPShortType::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) { - array_t array = (array_t) a; + auto array = (array_t) a; type_t val; frame.GetShortArrayRegion(array, ndx, 1, &val); jvalue v; @@ -302,7 +302,7 @@ Py_ssize_t JPShortType::getItemSize() void JPShortType::copyElements(JPJavaFrame &frame, jarray a, jsize start, jsize len, void* memory, int offset) { - jshort* b = (jshort*) ((char*) memory + offset); + auto* b = (jshort*) ((char*) memory + offset); frame.GetShortArrayRegion((jshortArray) a, start, len, b); } diff --git a/native/common/jp_typefactory.cpp b/native/common/jp_typefactory.cpp index df74f4133..3e647deeb 100644 --- a/native/common/jp_typefactory.cpp +++ b/native/common/jp_typefactory.cpp @@ -91,11 +91,11 @@ extern "C" JNIEXPORT void JNICALL Java_org_jpype_manager_TypeFactoryNative_newWrapper( JNIEnv *env, jobject self, jlong contextPtr, jlong jcls) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_newWrapper"); JPPyCallAcquire callback; - JPClass* cls = (JPClass*) jcls; + auto* cls = (JPClass*) jcls; PyJPClass_hook(frame, cls); JP_JAVA_CATCH(); // GCOVR_EXCL_LINE } @@ -105,7 +105,7 @@ JNIEXPORT void JNICALL Java_org_jpype_manager_TypeFactoryNative_destroy( jlongArray resources, jint sz) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_destroy"); JPPrimitiveArrayAccessor accessor(frame, resources, @@ -126,15 +126,15 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineMethodDis jlongArray overloadPtrs, jint modifiers) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_defineMethodDispatch"); - JPClass* cls = (JPClass*) clsPtr; + auto* cls = (JPClass*) clsPtr; JPMethodList overloadList; convert(frame, overloadPtrs, overloadList); string cname = frame.toStringUTF8(name); JP_TRACE(cname); - JPMethodDispatch* dispatch = new JPMethodDispatch(cls, cname, overloadList, modifiers); + auto* dispatch = new JPMethodDispatch(cls, cname, overloadList, modifiers); return (jlong) dispatch; JP_JAVA_CATCH(0); // GCOVR_EXCL_LINE } @@ -147,12 +147,12 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineArrayClas jlong componentClass, jint modifiers) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_defineArrayClass"); string cname = frame.toStringUTF8(name); JP_TRACE(cname); - JPArrayClass* result = new JPArrayClass(frame, cls, + auto* result = new JPArrayClass(frame, cls, cname, (JPClass*) superClass, (JPClass*) componentClass, @@ -170,7 +170,7 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineObjectCla jint modifiers) { // All resources are created here are owned by Java and deleted by Java shutdown routine - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_defineObjectClass"); string className = frame.toStringUTF8(name); @@ -305,7 +305,7 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_definePrimitive jint modifiers) { // These resources are created by the boxed types - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_definePrimitive"); string cname = frame.toStringUTF8(name); @@ -367,10 +367,10 @@ JNIEXPORT void JNICALL Java_org_jpype_manager_TypeFactoryNative_assignMembers( jlongArray methodPtrs, jlongArray fieldPtrs) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_assignMembers"); - JPClass* cls = (JPClass*) clsPtr; + auto* cls = (JPClass*) clsPtr; JPMethodDispatchList methodList; convert(frame, methodPtrs, methodList); @@ -392,7 +392,7 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineField( jlong fieldType, jint modifiers) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_defineField"); string cname = frame.toStringUTF8(name); @@ -415,7 +415,7 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineMethod( jobject method, jlongArray overloadList, jint modifiers) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_defineMethod"); jmethodID mid = frame.FromReflectedMethod(method); @@ -440,12 +440,12 @@ JNIEXPORT void JNICALL Java_org_jpype_manager_TypeFactoryNative_populateMethod( jlongArray argumentTypes ) { - JPContext* context = (JPContext*) contextPtr; + auto* context = (JPContext*) contextPtr; JPJavaFrame frame = JPJavaFrame::external(context, env); JP_JAVA_TRY("JPTypeFactory_populateMethod"); JPClassList cargs; convert(frame, argumentTypes, cargs); - JPMethod *methodPtr = (JPMethod*) method; + auto *methodPtr = (JPMethod*) method; methodPtr->setParameters((JPClass*) returnType, cargs); JP_JAVA_CATCH(); // GCOVR_EXCL_LINE } diff --git a/native/common/jp_typemanager.cpp b/native/common/jp_typemanager.cpp index 82ff13f60..fd594020a 100644 --- a/native/common/jp_typemanager.cpp +++ b/native/common/jp_typemanager.cpp @@ -53,7 +53,7 @@ JPClass* JPTypeManager::findClassByName(const string& name) JPJavaFrame frame = JPJavaFrame::outer(m_Context); jvalue val; val.l = (jobject) frame.fromStringUTF8(name); - JPClass* out = (JPClass*) (frame.CallLongMethodA(m_JavaTypeManager.get(), m_FindClassByName, &val)); + auto* out = (JPClass*) (frame.CallLongMethodA(m_JavaTypeManager.get(), m_FindClassByName, &val)); if (out == NULL) { stringstream err; @@ -70,7 +70,7 @@ JPClass* JPTypeManager::findClassForObject(jobject obj) JPJavaFrame frame = JPJavaFrame::outer(m_Context); jvalue val; val.l = obj; - JPClass *cls = (JPClass*) (frame.CallLongMethodA(m_JavaTypeManager.get(), m_FindClassForObject, &val)); + auto *cls = (JPClass*) (frame.CallLongMethodA(m_JavaTypeManager.get(), m_FindClassForObject, &val)); frame.check(); JP_TRACE("ClassName", cls == NULL ? "null" : cls->getCanonicalName()); return cls; diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index 60a07acec..1606487a4 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -409,7 +409,7 @@ JPPyCallRelease::JPPyCallRelease() JPPyCallRelease::~JPPyCallRelease() { // Reaquire the lock - PyThreadState *save = (PyThreadState *) m_State1; + auto *save = (PyThreadState *) m_State1; PyEval_RestoreThread(save); } diff --git a/native/python/pyjp_array.cpp b/native/python/pyjp_array.cpp index 9dc53774c..00bd027e1 100644 --- a/native/python/pyjp_array.cpp +++ b/native/python/pyjp_array.cpp @@ -36,7 +36,7 @@ extern "C" static PyObject *PyJPArray_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPArray_new"); - PyJPArray* self = (PyJPArray*) type->tp_alloc(type, 0); + auto* self = (PyJPArray*) type->tp_alloc(type, 0); JP_PY_CHECK(); self->m_Array = NULL; self->m_View = NULL; @@ -61,7 +61,7 @@ static int PyJPArray_init(PyObject *self, PyObject *args, PyObject *kwargs) return -1; JPClass *cls = PyJPClass_getJPClass((PyObject*) Py_TYPE(self)); - JPArrayClass* arrayClass = dynamic_cast (cls); + auto* arrayClass = dynamic_cast (cls); if (arrayClass == NULL) JP_RAISE(PyExc_TypeError, "Class must be array type"); @@ -69,7 +69,7 @@ static int PyJPArray_init(PyObject *self, PyObject *args, PyObject *kwargs) JPValue *value = PyJPValue_getJavaSlot(v); if (value != NULL) { - JPArrayClass* arrayClass2 = dynamic_cast (value->getClass()); + auto* arrayClass2 = dynamic_cast (value->getClass()); if (arrayClass2 == NULL) JP_RAISE(PyExc_TypeError, "Class must be array type"); if (arrayClass2 != arrayClass) @@ -158,7 +158,7 @@ static PyObject *PyJPArray_getItem(PyJPArray *self, PyObject *item) if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - Py_ssize_t length = (Py_ssize_t) self->m_Array->getLength(); + auto length = (Py_ssize_t) self->m_Array->getLength(); if (PySlice_Unpack(item, &start, &stop, &step) < 0) return NULL; @@ -225,7 +225,7 @@ static int PyJPArray_assignSubscript(PyJPArray *self, PyObject *item, PyObject * if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - Py_ssize_t length = (Py_ssize_t) self->m_Array->getLength(); + auto length = (Py_ssize_t) self->m_Array->getLength(); if (PySlice_Unpack(item, &start, &stop, &step) < 0) return -1; diff --git a/native/python/pyjp_char.cpp b/native/python/pyjp_char.cpp index 5b4ab19da..03dc3f799 100644 --- a/native/python/pyjp_char.cpp +++ b/native/python/pyjp_char.cpp @@ -79,7 +79,7 @@ static int assertNotNull(JPValue *javaSlot) PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) { - PyJPChar *self = (PyJPChar*) PyJPValue_alloc(type, 0); + auto *self = (PyJPChar*) PyJPValue_alloc(type, 0); if (self == 0) return 0; self->m_Data[0] = 0; @@ -115,7 +115,7 @@ PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) } else { - Py_UCS2 *data = (Py_UCS2*) ( ((PyCompactUnicodeObject*) self) + 1); + auto *data = (Py_UCS2*) ( ((PyCompactUnicodeObject*) self) + 1); data[0] = p; data[1] = 0; _PyUnicode_STATE(self).kind = PyUnicode_2BYTE_KIND; @@ -154,15 +154,15 @@ Py_UCS2 fromJPChar(PyJPChar *self) { if (_PyUnicode_STATE(self).ascii == 1) { - Py_UCS1 *data = (Py_UCS1*) (((PyASCIIObject*) self) + 1); + auto *data = (Py_UCS1*) (((PyASCIIObject*) self) + 1); return data[0]; } if (_PyUnicode_STATE(self).kind == PyUnicode_1BYTE_KIND) { - Py_UCS1 *data = (Py_UCS1*) ( ((PyCompactUnicodeObject*) self) + 1); + auto *data = (Py_UCS1*) ( ((PyCompactUnicodeObject*) self) + 1); return data[0]; } - Py_UCS2 *data = (Py_UCS2*) ( ((PyCompactUnicodeObject*) self) + 1); + auto *data = (Py_UCS2*) ( ((PyCompactUnicodeObject*) self) + 1); return data[0]; } diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index 2b9bab9da..9d72cc321 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -93,7 +93,7 @@ PyObject *PyJPClass_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return 0; } - PyTypeObject *typenew = (PyTypeObject*) PyType_Type.tp_new(type, args, kwargs); + auto *typenew = (PyTypeObject*) PyType_Type.tp_new(type, args, kwargs); // GCOVR_EXCL_START // Sanity checks. Not testable @@ -135,8 +135,8 @@ PyObject* PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) { JP_PY_TRY("PyJPClass_FromSpecWithBases"); // Python lacks a FromSpecWithMeta so we are going to have to fake it here. - PyTypeObject* type = (PyTypeObject*) PyJPClass_Type->tp_alloc(PyJPClass_Type, 0); - PyHeapTypeObject* heap = (PyHeapTypeObject*) type; + auto* type = (PyTypeObject*) PyJPClass_Type->tp_alloc(PyJPClass_Type, 0); + auto* heap = (PyHeapTypeObject*) type; type->tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE; type->tp_name = spec->name; const char *s = strrchr(spec->name, '.'); @@ -354,7 +354,7 @@ PyObject* PyJPClass_mro(PyTypeObject *self) // Merge together all bases std::list out; - for (std::list::iterator iter = bases.begin(); + for (auto iter = bases.begin(); iter != bases.end(); ++iter) { PyObject *l = ((PyTypeObject*) * iter)->tp_bases; @@ -374,7 +374,7 @@ PyObject* PyJPClass_mro(PyTypeObject *self) { PyObject* front = bases.front(); bases.pop_front(); - for (std::list::iterator iter = bases.begin(); + for (auto iter = bases.begin(); iter != bases.end(); ++iter) { if (PySequence_Contains(((PyTypeObject*) * iter)->tp_bases, front)) @@ -387,7 +387,7 @@ PyObject* PyJPClass_mro(PyTypeObject *self) if (front != NULL) { out.push_back(front); - PyObject* next = (PyObject*) ((PyTypeObject*) front)->tp_base; + auto* next = (PyObject*) ((PyTypeObject*) front)->tp_base; if (next) { bases.remove(next); @@ -398,7 +398,7 @@ PyObject* PyJPClass_mro(PyTypeObject *self) PyObject *obj = PyTuple_New(out.size()); int j = 0; - for (std::list::iterator iter = out.begin(); + for (auto iter = out.begin(); iter != out.end(); ++iter) { Py_INCREF(*iter); @@ -617,7 +617,7 @@ static int PyJPClass_setHints(PyObject *self, PyObject *value, PyObject *closure { JP_PY_TRY("PyJPClass_setHints", self); PyJPModule_getContext(); - PyJPClass *cls = (PyJPClass*) self; + auto *cls = (PyJPClass*) self; PyObject *hints = cls->m_Class->getHints(); if (hints != NULL) { @@ -719,7 +719,7 @@ static PyObject *PyJPClass_array(PyJPClass *self, PyObject *item) if (PyIndex_Check(item)) { long sz = PyLong_AsLong(item); - JPArrayClass *cls = (JPArrayClass*) self->m_Class->newArrayType(frame, 1); + auto *cls = (JPArrayClass*) self->m_Class->newArrayType(frame, 1); JPValue v = cls->newArray(frame, sz); return cls->convertToPythonObject(frame, v.getValue(), true).keep(); } @@ -848,7 +848,7 @@ static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) // a slice then we need to copy it here. if (PyObject_IsInstance(other, (PyObject*) PyJPArray_Type)) { - PyJPArray *array = (PyJPArray*) other; + auto *array = (PyJPArray*) other; if (array->m_Array->isSlice()) { JPJavaFrame frame = JPJavaFrame::outer(context); @@ -1075,7 +1075,7 @@ JPPyObject PyJPClass_getBases(JPJavaFrame &frame, JPClass* cls) baseType = JPPyObject::use((PyObject*) PyJPException_Type); } else if (cls->isArray()) { - JPArrayClass* acls = (JPArrayClass*) cls; + auto* acls = (JPArrayClass*) cls; if (acls->getComponentType()->isPrimitive()) baseType = JPPyObject::use((PyObject*) PyJPArrayPrimitive_Type); else @@ -1125,7 +1125,7 @@ JPPyObject PyJPClass_create(JPJavaFrame &frame, JPClass* cls) JP_TRACE_IN("PyJPClass_create", cls); // Check the cache for speed - PyObject *host = (PyObject*) cls->getHost(); + auto *host = (PyObject*) cls->getHost(); if (host == NULL) { frame.newWrapper(cls); @@ -1138,7 +1138,7 @@ JPPyObject PyJPClass_create(JPJavaFrame &frame, JPClass* cls) void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) { JPContext *context = frame.getContext(); - PyObject *host = (PyObject*) cls->getHost(); + auto *host = (PyObject*) cls->getHost(); if (host != NULL) return; @@ -1155,13 +1155,13 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) return; const JPFieldList & instFields = cls->getFields(); - for (JPFieldList::const_iterator iter = instFields.begin(); iter != instFields.end(); iter++) + for (auto iter = instFields.begin(); iter != instFields.end(); iter++) { JPPyObject fieldName(JPPyString::fromStringUTF8((*iter)->getName())); PyDict_SetItem(members.get(), fieldName.get(), PyJPField_create(*iter).get()); } const JPMethodDispatchList& m_Methods = cls->getMethods(); - for (JPMethodDispatchList::const_iterator iter = m_Methods.begin(); iter != m_Methods.end(); iter++) + for (auto iter = m_Methods.begin(); iter != m_Methods.end(); iter++) { JPPyObject methodName(JPPyString::fromStringUTF8((*iter)->getName())); PyDict_SetItem(members.get(), methodName.get(), @@ -1171,7 +1171,7 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) if (cls->isInterface()) { const JPMethodDispatchList& m_Methods = context->_java_lang_Object->getMethods(); - for (JPMethodDispatchList::const_iterator iter = m_Methods.begin(); iter != m_Methods.end(); iter++) + for (auto iter = m_Methods.begin(); iter != m_Methods.end(); iter++) { JPPyObject methodName(JPPyString::fromStringUTF8((*iter)->getName())); PyDict_SetItem(members.get(), methodName.get(), @@ -1186,7 +1186,7 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) JP_TRACE("type new"); // Create the type using the meta class magic JPPyObject vself = JPPyObject::call(PyJPClass_Type->tp_new(PyJPClass_Type, rc.get(), PyJPClassMagic)); - PyJPClass *self = (PyJPClass*) vself.get(); + auto *self = (PyJPClass*) vself.get(); // Attach the javaSlot self->m_Class = cls; diff --git a/native/python/pyjp_classhints.cpp b/native/python/pyjp_classhints.cpp index f0f95b338..e90c4c9ec 100644 --- a/native/python/pyjp_classhints.cpp +++ b/native/python/pyjp_classhints.cpp @@ -24,7 +24,7 @@ extern "C" PyObject *PyJPClassHints_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPClassHints_new", type); - PyJPClassHints *self = (PyJPClassHints*) type->tp_alloc(type, 0); + auto *self = (PyJPClassHints*) type->tp_alloc(type, 0); self->m_Hints = new JPClassHints(); return (PyObject*) self; JP_PY_CATCH(NULL); diff --git a/native/python/pyjp_field.cpp b/native/python/pyjp_field.cpp index 3460097d4..ca73ba8ab 100644 --- a/native/python/pyjp_field.cpp +++ b/native/python/pyjp_field.cpp @@ -134,7 +134,7 @@ void PyJPField_initType(PyObject* module) JPPyObject PyJPField_create(JPField* m) { JP_TRACE_IN("PyJPField_create"); - PyJPField* self = (PyJPField*) PyJPField_Type->tp_alloc(PyJPField_Type, 0); + auto* self = (PyJPField*) PyJPField_Type->tp_alloc(PyJPField_Type, 0); JP_PY_CHECK(); self->m_Field = m; return JPPyObject::claim((PyObject*) self); diff --git a/native/python/pyjp_method.cpp b/native/python/pyjp_method.cpp index cfa7640e0..882af492d 100644 --- a/native/python/pyjp_method.cpp +++ b/native/python/pyjp_method.cpp @@ -201,7 +201,7 @@ static PyObject *PyJPMethod_getDoc(PyJPMethod *self, void *ctxt) JPPyObject ov = JPPyObject::call(PyTuple_New(overloads.size())); int i = 0; JPClass* methodClass = frame.findClassByName("java.lang.reflect.Method"); - for (JPMethodList::const_iterator iter = overloads.begin(); iter != overloads.end(); ++iter) + for (auto iter = overloads.begin(); iter != overloads.end(); ++iter) { JP_TRACE("Set overload", i); jvalue v; @@ -253,7 +253,7 @@ PyObject *PyJPMethod_getAnnotations(PyJPMethod *self, void *ctxt) JPPyObject ov = JPPyObject::call(PyTuple_New(overloads.size())); int i = 0; JPClass* methodClass = frame.findClassByName("java.lang.reflect.Method"); - for (JPMethodList::const_iterator iter = overloads.begin(); iter != overloads.end(); ++iter) + for (auto iter = overloads.begin(); iter != overloads.end(); ++iter) { JP_TRACE("Set overload", i); jvalue v; @@ -410,7 +410,7 @@ void PyJPMethod_initType(PyObject* module) JPPyObject PyJPMethod_create(JPMethodDispatch *m, PyObject *instance) { JP_TRACE_IN("PyJPMethod_create"); - PyJPMethod* self = (PyJPMethod*) PyJPMethod_Type->tp_alloc(PyJPMethod_Type, 0); + auto* self = (PyJPMethod*) PyJPMethod_Type->tp_alloc(PyJPMethod_Type, 0); JP_PY_CHECK(); self->m_Method = m; self->m_Instance = instance; diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 341328621..cdbafdfeb 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -173,7 +173,7 @@ PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name) Py_ssize_t n = PyTuple_Size(mro); for (Py_ssize_t i = 0; i < n; ++i) { - PyTypeObject *type2 = (PyTypeObject*) PyTuple_GetItem(mro, i); + auto *type2 = (PyTypeObject*) PyTuple_GetItem(mro, i); PyObject *res = PyDict_GetItem(type2->tp_dict, attr_name); if (res) { @@ -465,7 +465,7 @@ PyObject *PyJPModule_hasClass(PyObject* module, PyObject *obj) return NULL; } - PyObject *host = (PyObject*) cls->getHost(); + auto *host = (PyObject*) cls->getHost(); return PyBool_FromLong(host != NULL); JP_PY_CATCH(NULL); } @@ -850,12 +850,12 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) // Now we have a valid format code, so next lets get a converter for // the type. - JPPrimitiveType *pcls = (JPPrimitiveType *) cls; + auto *pcls = (JPPrimitiveType *) cls; // Convert the shape Py_ssize_t subs = 1; Py_ssize_t base = 1; - jintArray jdims = (jintArray) context->_int->newArrayOf(frame, view.ndim); + auto jdims = (jintArray) context->_int->newArrayOf(frame, view.ndim); if (view.shape != NULL) { JPPrimitiveArrayAccessor accessor(frame, jdims, diff --git a/native/python/pyjp_number.cpp b/native/python/pyjp_number.cpp index 2edec08e6..55a93e3d3 100644 --- a/native/python/pyjp_number.cpp +++ b/native/python/pyjp_number.cpp @@ -37,7 +37,7 @@ static PyObject *PyJPNumber_new(PyTypeObject *type, PyObject *args, PyObject *kw JP_PY_TRY("PyJPNumber_new", type); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - JPClass *cls = (JPClass*) PyJPClass_getJPClass((PyObject*) type); + auto *cls = (JPClass*) PyJPClass_getJPClass((PyObject*) type); if (cls == NULL) JP_RAISE(PyExc_TypeError, "Class type incorrect"); @@ -412,7 +412,7 @@ JPPyObject PyJPNumber_create(JPJavaFrame &frame, JPPyObject& wrapper, const JPVa jlong l = 0; if (value.getValue().l != 0) { - JPBoxedType* jb = (JPBoxedType*) value.getClass(); + auto* jb = (JPBoxedType*) value.getClass(); l = frame.CallLongMethodA(value.getJavaObject(), jb->m_LongValueID, 0); } PyObject *args = PyTuple_Pack(1, PyLong_FromLongLong(l)); @@ -423,7 +423,7 @@ JPPyObject PyJPNumber_create(JPJavaFrame &frame, JPPyObject& wrapper, const JPVa jdouble l = 0; if (value.getValue().l != 0) { - JPBoxedType* jb = (JPBoxedType*) value.getClass(); + auto* jb = (JPBoxedType*) value.getClass(); l = frame.CallDoubleMethodA(value.getJavaObject(), jb->m_DoubleValueID, 0); } PyObject *args = PyTuple_Pack(1, PyFloat_FromDouble(l)); diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index 494175f12..9836fd973 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -287,7 +287,7 @@ static PyObject* PyJPException_expandStacktrace(PyObject* self) JPValue *val = PyJPValue_getJavaSlot(self); // These two are loop invariants and must match each time - jthrowable th = (jthrowable) val->getValue().l; + auto th = (jthrowable) val->getValue().l; JPPyObject exc = JPPyObject::use(self); PyJPException_normalize(frame, exc, th, NULL); diff --git a/native/python/pyjp_package.cpp b/native/python/pyjp_package.cpp index 84317deef..5a00740f7 100644 --- a/native/python/pyjp_package.cpp +++ b/native/python/pyjp_package.cpp @@ -61,7 +61,7 @@ static void dtor(PyObject *self) JPContext *context = JPContext_global; if (context == NULL || !context->isRunning()) return; - jobject jo = (jobject) PyCapsule_GetPointer(self, NULL); + auto jo = (jobject) PyCapsule_GetPointer(self, NULL); if (jo == NULL) return; JPJavaFrame frame = JPJavaFrame::outer(context); diff --git a/native/python/pyjp_proxy.cpp b/native/python/pyjp_proxy.cpp index 2be2cf34a..249e11fce 100644 --- a/native/python/pyjp_proxy.cpp +++ b/native/python/pyjp_proxy.cpp @@ -30,7 +30,7 @@ static PyObject *PyJPProxy_new(PyTypeObject *type, PyObject *args, PyObject *kwa JP_PY_TRY("PyJPProxy_new"); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - PyJPProxy *self = (PyJPProxy*) type->tp_alloc(type, 0); + auto *self = (PyJPProxy*) type->tp_alloc(type, 0); JP_PY_CHECK(); // Parse arguments diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index 6159e8f20..8d9b143bf 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -110,7 +110,7 @@ JPValue* PyJPValue_getJavaSlot(PyObject* self) Py_ssize_t offset = PyJPValue_getJavaSlotOffset(self); if (offset == 0) return NULL; - JPValue* value = (JPValue*) (((char*) self) + offset); + auto* value = (JPValue*) (((char*) self) + offset); if (value->getClass() == NULL) return NULL; return value; @@ -189,7 +189,7 @@ PyObject* PyJPValue_str(PyObject* self) Py_INCREF(cache); return cache; } - jstring jstr = (jstring) value->getValue().l; + auto jstr = (jstring) value->getValue().l; string str; str = frame.toStringUTF8(jstr); cache = JPPyString::fromStringUTF8(str).keep(); @@ -279,7 +279,7 @@ void PyJPValue_assignJavaSlot(JPJavaFrame &frame, PyObject* self, const JPValue& } // GCOVR_EXCL_STOP - JPValue* slot = (JPValue*) (((char*) self) + offset); + auto* slot = (JPValue*) (((char*) self) + offset); // GCOVR_EXCL_START // This is a sanity check that should never trigger in normal operations. if (slot->getClass() != NULL) @@ -302,6 +302,6 @@ bool PyJPValue_isSetJavaSlot(PyObject* self) Py_ssize_t offset = PyJPValue_getJavaSlotOffset(self); if (offset == 0) return false; // GCOVR_EXCL_LINE - JPValue* slot = (JPValue*) (((char*) self) + offset); + auto* slot = (JPValue*) (((char*) self) + offset); return slot->getClass() != NULL; } \ No newline at end of file From 826b3cf3549ab058cdf3e2013f03785a78b0b0eb Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:38:14 +0200 Subject: [PATCH 012/128] use nullptr --- native/common/include/jp_context.h | 12 +- native/common/include/jp_javaframe.h | 4 +- native/common/include/jp_match.h | 4 +- native/common/include/jp_primitive_accessor.h | 8 +- native/common/include/jp_tracer.h | 14 +- native/common/include/jp_value.h | 4 +- native/common/jp_array.cpp | 8 +- native/common/jp_arrayclass.cpp | 2 +- native/common/jp_booleantype.cpp | 6 +- native/common/jp_boxedtype.cpp | 16 +- native/common/jp_buffer.cpp | 2 +- native/common/jp_buffertype.cpp | 4 +- native/common/jp_bytetype.cpp | 6 +- native/common/jp_chartype.cpp | 6 +- native/common/jp_class.cpp | 40 ++--- native/common/jp_classhints.cpp | 66 +++---- native/common/jp_classloader.cpp | 10 +- native/common/jp_context.cpp | 134 +++++++------- native/common/jp_convert.cpp | 2 +- native/common/jp_doubletype.cpp | 6 +- native/common/jp_exception.cpp | 76 ++++---- native/common/jp_floattype.cpp | 6 +- native/common/jp_functional.cpp | 2 +- native/common/jp_gc.cpp | 8 +- native/common/jp_inttype.cpp | 8 +- native/common/jp_javaframe.cpp | 30 ++-- native/common/jp_longtype.cpp | 6 +- native/common/jp_method.cpp | 10 +- native/common/jp_methoddispatch.cpp | 6 +- native/common/jp_platform.cpp | 6 +- native/common/jp_primitivetype.cpp | 6 +- native/common/jp_proxy.cpp | 26 +-- native/common/jp_reference_queue.cpp | 8 +- native/common/jp_shorttype.cpp | 6 +- native/common/jp_stringtype.cpp | 2 +- native/common/jp_tracer.cpp | 16 +- native/common/jp_typefactory.cpp | 4 +- native/common/jp_typemanager.cpp | 2 +- native/common/jp_value.cpp | 2 +- native/common/jp_voidtype.cpp | 8 +- native/python/include/jp_pythontypes.h | 6 +- native/python/jp_pythontypes.cpp | 36 ++-- native/python/pyjp_array.cpp | 68 +++---- native/python/pyjp_buffer.cpp | 12 +- native/python/pyjp_char.cpp | 128 ++++++------- native/python/pyjp_class.cpp | 168 +++++++++--------- native/python/pyjp_classhints.cpp | 28 +-- native/python/pyjp_field.cpp | 16 +- native/python/pyjp_method.cpp | 84 ++++----- native/python/pyjp_module.cpp | 156 ++++++++-------- native/python/pyjp_monitor.cpp | 16 +- native/python/pyjp_number.cpp | 72 ++++---- native/python/pyjp_object.cpp | 82 ++++----- native/python/pyjp_package.cpp | 94 +++++----- native/python/pyjp_proxy.cpp | 22 +-- native/python/pyjp_value.cpp | 52 +++--- 56 files changed, 816 insertions(+), 816 deletions(-) diff --git a/native/common/include/jp_context.h b/native/common/include/jp_context.h index 45fc8fa7a..a997f59e4 100644 --- a/native/common/include/jp_context.h +++ b/native/common/include/jp_context.h @@ -33,7 +33,7 @@ class JPRef JPRef() { - m_Context = 0; + m_Context = nullptr; m_Ref = 0; } @@ -41,7 +41,7 @@ class JPRef { m_Context = context; m_Ref = 0; - if (context == 0) + if (context == nullptr) return; JPJavaFrame frame = JPJavaFrame::outer(m_Context); m_Ref = (jref) frame.NewGlobalRef((jobject) obj); @@ -280,7 +280,7 @@ template JPRef::JPRef(const JPRef& other) { m_Context = other.m_Context; - if (m_Context != NULL) + if (m_Context != nullptr) { JPJavaFrame frame = JPJavaFrame::external(m_Context, m_Context->getEnv()); m_Ref = (jref) frame.NewGlobalRef((jobject) other.m_Ref); @@ -294,7 +294,7 @@ JPRef::JPRef(const JPRef& other) template JPRef::~JPRef() { - if (m_Ref != 0 && m_Context != 0) + if (m_Ref != 0 && m_Context != nullptr) { m_Context->ReleaseGlobalRef((jobject) m_Ref); } @@ -307,7 +307,7 @@ JPRef& JPRef::operator=(const JPRef& other) return *this; // m_Context may or may not be set up here, so we need to use a // different frame for unreferencing and referencing - if (m_Context != 0 && m_Ref != 0) + if (m_Context != nullptr && m_Ref != 0) { // GCOVR_EXCL_START // This code is not currently used. JPJavaFrame frame = JPJavaFrame::external(m_Context, m_Context->getEnv()); @@ -316,7 +316,7 @@ JPRef& JPRef::operator=(const JPRef& other) } // GCOVR_EXCL_STOP m_Context = other.m_Context; m_Ref = other.m_Ref; - if (m_Context != 0 && m_Ref != 0) + if (m_Context != nullptr && m_Ref != 0) { JPJavaFrame frame = JPJavaFrame::external(m_Context, m_Context->getEnv()); m_Ref = (jref) frame.NewGlobalRef((jobject) m_Ref); diff --git a/native/common/include/jp_javaframe.h b/native/common/include/jp_javaframe.h index ca8160f7d..4b804f5dd 100644 --- a/native/common/include/jp_javaframe.h +++ b/native/common/include/jp_javaframe.h @@ -70,7 +70,7 @@ class JPJavaFrame */ static JPJavaFrame outer(JPContext* context, int size = LOCAL_FRAME_DEFAULT) { - return JPJavaFrame(context, NULL, size, true); + return JPJavaFrame(context, nullptr, size, true); } /** Create a new JavaFrame when called internal when @@ -84,7 +84,7 @@ class JPJavaFrame */ static JPJavaFrame inner(JPContext* context, int size = LOCAL_FRAME_DEFAULT) { - return JPJavaFrame(context, NULL, size, false); + return JPJavaFrame(context, nullptr, size, false); } /** Create a new JavaFrame when called from Java. diff --git a/native/common/include/jp_match.h b/native/common/include/jp_match.h index fa7ea5292..1eec52d53 100644 --- a/native/common/include/jp_match.h +++ b/native/common/include/jp_match.h @@ -36,8 +36,8 @@ class JPMatch JPContext *getContext() { - if (frame == NULL) - return NULL; + if (frame == nullptr) + return nullptr; return frame->getContext(); } diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index 61fa5d31d..acd03b1f2 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -96,10 +96,10 @@ template PyObject *convertMultiArray( JPContext *context = frame.getContext(); Py_buffer& view = buffer.getView(); jconverter converter = getConverter(view.format, (int) view.itemsize, code); - if (converter == NULL) + if (converter == nullptr) { PyErr_Format(PyExc_TypeError, "No type converter found"); - return NULL; + return nullptr; } // Reserve space for array. @@ -115,7 +115,7 @@ template PyObject *convertMultiArray( auto *dest = (type_t*) mem; Py_ssize_t step; - if (view.strides == NULL) + if (view.strides == nullptr) step = view.itemsize; else step = view.strides[u]; @@ -164,7 +164,7 @@ template PyObject *convertMultiArray( // Convert it to Python JPClass *type = context->_java_lang_Object; - if (out != NULL) + if (out != nullptr) type = frame.findClassForObject(out); jvalue v; v.l = out; diff --git a/native/common/include/jp_tracer.h b/native/common/include/jp_tracer.h index 552d586a5..175384c9a 100644 --- a/native/common/include/jp_tracer.h +++ b/native/common/include/jp_tracer.h @@ -58,7 +58,7 @@ class JPypeTracer public: - JPypeTracer(const char *name, void *ref = 0); + JPypeTracer(const char *name, void *ref = nullptr); ~JPypeTracer(); void gotError(const JPStackInfo& info) @@ -96,14 +96,14 @@ inline void trace(const T& msg) return; std::stringstream str; str << msg; - JPypeTracer::trace1(NULL, str.str().c_str()); + JPypeTracer::trace1(nullptr, str.str().c_str()); } inline void trace(const char *msg) { if ((_PyJPModule_trace & 1) == 0) return; - JPypeTracer::trace1(NULL, msg); + JPypeTracer::trace1(nullptr, msg); } template @@ -113,7 +113,7 @@ inline void trace(const T1& msg1, const T2 & msg2) return; std::stringstream str; str << msg1 << " " << msg2; - JPypeTracer::trace1(NULL, str.str().c_str()); + JPypeTracer::trace1(nullptr, str.str().c_str()); } inline void trace(const char *msg1, const char *msg2) @@ -130,7 +130,7 @@ inline void trace(const T1& msg1, const T2& msg2, const T3 & msg3) return; std::stringstream str; str << msg1 << " " << msg2 << " " << msg3; - JPypeTracer::trace1(NULL, str.str().c_str()); + JPypeTracer::trace1(nullptr, str.str().c_str()); } template @@ -140,7 +140,7 @@ inline void trace(const T1& msg1, const T2& msg2, const T3& msg3, const T4 & msg return; std::stringstream str; str << msg1 << " " << msg2 << " " << msg3 << " " << msg4; - JPypeTracer::trace1(NULL, str.str().c_str()); + JPypeTracer::trace1(nullptr, str.str().c_str()); } template @@ -150,7 +150,7 @@ inline void trace(const T1& msg1, const T2& msg2, const T3& msg3, const T4& msg4 return; std::stringstream str; str << msg1 << " " << msg2 << " " << msg3 << " " << msg4 << " " << msg5; - JPypeTracer::trace1(NULL, str.str().c_str()); + JPypeTracer::trace1(nullptr, str.str().c_str()); } } diff --git a/native/common/include/jp_value.h b/native/common/include/jp_value.h index 78c48ba8e..b58c66ea1 100644 --- a/native/common/include/jp_value.h +++ b/native/common/include/jp_value.h @@ -28,9 +28,9 @@ class JPValue public: JPValue() - : m_Class(NULL) + : m_Class(nullptr) { - m_Value.l = 0; + m_Value.l = nullptr; } JPValue(JPClass* clazz, const jvalue& value) diff --git a/native/common/jp_array.cpp b/native/common/jp_array.cpp index f92fa3c68..1d34fed05 100644 --- a/native/common/jp_array.cpp +++ b/native/common/jp_array.cpp @@ -145,9 +145,9 @@ JPArrayView::JPArrayView(JPArray* array) JPJavaFrame frame = JPJavaFrame::outer(array->m_Class->getContext()); m_Array = array; m_RefCount = 0; - m_Buffer.obj = NULL; + m_Buffer.obj = nullptr; m_Buffer.ndim = 1; - m_Buffer.suboffsets = NULL; + m_Buffer.suboffsets = nullptr; auto *type = (JPPrimitiveType*) array->getClass()->getComponentType(); type->getView(*this); m_Strides[0] = m_Buffer.itemsize * array->m_Step; @@ -218,9 +218,9 @@ JPArrayView::JPArrayView(JPArray* array, jobject collection) } // Copy values into Python buffer for consumption - m_Buffer.obj = NULL; + m_Buffer.obj = nullptr; m_Buffer.ndim = dims; - m_Buffer.suboffsets = NULL; + m_Buffer.suboffsets = nullptr; m_Buffer.itemsize = itemsize; m_Buffer.format = const_cast (componentType->getBufferFormat()); m_Buffer.buf = (char*) m_Memory + m_Buffer.itemsize * array->m_Start; diff --git a/native/common/jp_arrayclass.cpp b/native/common/jp_arrayclass.cpp index bb80ce163..c8b153117 100644 --- a/native/common/jp_arrayclass.cpp +++ b/native/common/jp_arrayclass.cpp @@ -67,7 +67,7 @@ JPPyObject JPArrayClass::convertToPythonObject(JPJavaFrame& frame, jvalue value, JP_TRACE_IN("JPArrayClass::convertToPythonObject"); if (!cast) { - if (value.l == NULL) + if (value.l == nullptr) return JPPyObject::getNone(); } JPPyObject wrapper = PyJPClass_create(frame, this); diff --git a/native/common/jp_booleantype.cpp b/native/common/jp_booleantype.cpp index 213b8105f..337add3c5 100644 --- a/native/common/jp_booleantype.cpp +++ b/native/common/jp_booleantype.cpp @@ -39,7 +39,7 @@ JPValue JPBooleanType::getValueFromObject(const JPValue& obj) JPContext *context = obj.getClass()->getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; - field(v) = frame.CallBooleanMethodA(obj.getValue().l, context->_java_lang_Boolean->m_BooleanValueID, 0) != 0; + field(v) = frame.CallBooleanMethodA(obj.getValue().l, context->_java_lang_Boolean->m_BooleanValueID, nullptr) != 0; return JPValue(this, v); } @@ -79,7 +79,7 @@ class JPConversionAsBooleanJBool : public JPConversionJavaValue { JPValue *value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return match.type = JPMatch::_none; match.type = JPMatch::_none; // Implied conversion from boxed to primitive (JLS 5.1.8) @@ -204,7 +204,7 @@ JPPyObject JPBooleanType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallBooleanMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualBooleanMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_boxedtype.cpp b/native/common/jp_boxedtype.cpp index 241e1287b..1f1e9f90f 100644 --- a/native/common/jp_boxedtype.cpp +++ b/native/common/jp_boxedtype.cpp @@ -32,12 +32,12 @@ m_PrimitiveType(primitiveType) m_CtorID = frame.GetMethodID(clss, "", s.c_str()); } - m_DoubleValueID = NULL; - m_FloatValueID = NULL; - m_LongValueID = NULL; - m_IntValueID = NULL; - m_BooleanValueID = NULL; - m_CharValueID = NULL; + m_DoubleValueID = nullptr; + m_FloatValueID = nullptr; + m_LongValueID = nullptr; + m_IntValueID = nullptr; + m_BooleanValueID = nullptr; + m_CharValueID = nullptr; if (name != "java.lang.Void" && name != "java.lang.Boolean" && name != "java.lang.Character" ) { @@ -106,7 +106,7 @@ JPPyObject JPBoxedType::convertToPythonObject(JPJavaFrame& frame, jvalue value, if (!cast) { // This loses type - if (value.l == NULL) + if (value.l == nullptr) { return JPPyObject::getNone(); } @@ -123,7 +123,7 @@ JPPyObject JPBoxedType::convertToPythonObject(JPJavaFrame& frame, jvalue value, { jchar value2 = 0; // Not null get the char value - if (value.l != 0) + if (value.l != nullptr) value2 = context->_char->getValueFromObject(JPValue(this, value)).getValue().c; // Create a char string object obj = JPPyObject::call(PyJPChar_Create((PyTypeObject*) wrapper.get(), value2)); diff --git a/native/common/jp_buffer.cpp b/native/common/jp_buffer.cpp index 019f03eb0..f9d6d30b3 100644 --- a/native/common/jp_buffer.cpp +++ b/native/common/jp_buffer.cpp @@ -37,7 +37,7 @@ JPBuffer::JPBuffer(const JPValue &value) m_Buffer.readonly = frame.isBufferReadOnly(m_Object.get()); m_Buffer.shape = &m_Capacity; m_Buffer.strides = &m_Buffer.itemsize; - m_Buffer.suboffsets = 0; + m_Buffer.suboffsets = nullptr; JP_TRACE_OUT; // GCOVR_EXCL_LINE } diff --git a/native/common/jp_buffertype.cpp b/native/common/jp_buffertype.cpp index 16732b292..b772716d0 100644 --- a/native/common/jp_buffertype.cpp +++ b/native/common/jp_buffertype.cpp @@ -62,7 +62,7 @@ JPBufferType::JPBufferType(JPJavaFrame& frame, } else { auto* super = dynamic_cast (m_SuperClass); - if (super == NULL) + if (super == nullptr) JP_RAISE(PyExc_TypeError, "Unsupported buffer type"); // GCOVR_EXCL_LINE m_Type = super->m_Type; m_Size = super->m_Size; @@ -76,7 +76,7 @@ JPBufferType::~JPBufferType() JPPyObject JPBufferType::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool cast) { JP_TRACE_IN("JPBufferClass::convertToPythonObject"); - if (!cast && value.l == NULL) + if (!cast && value.l == nullptr) return JPPyObject::getNone(); // GCOVR_EXCL_LINE JPPyObject wrapper = PyJPClass_create(frame, this); JPPyObject obj = PyJPBuffer_create(frame, (PyTypeObject*) wrapper.get(), JPValue(this, value)); diff --git a/native/common/jp_bytetype.cpp b/native/common/jp_bytetype.cpp index f4ef0b8c9..95f981114 100644 --- a/native/common/jp_bytetype.cpp +++ b/native/common/jp_bytetype.cpp @@ -43,7 +43,7 @@ JPValue JPByteType::getValueFromObject(const JPValue& obj) jvalue v; jobject jo = obj.getValue().l; auto* jb = (JPBoxedType*) frame.findClassForObject(jo); - field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, 0); + field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, nullptr); return JPValue(this, v); } @@ -57,7 +57,7 @@ class JPConversionJByte : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return match.type = JPMatch::_none; match.type = JPMatch::_none; // Implied conversion from boxed to primitive (JLS 5.1.8) @@ -137,7 +137,7 @@ JPPyObject JPByteType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jme jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallByteMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualByteMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_chartype.cpp b/native/common/jp_chartype.cpp index 376eb2fa6..e48a779ce 100644 --- a/native/common/jp_chartype.cpp +++ b/native/common/jp_chartype.cpp @@ -60,7 +60,7 @@ JPValue JPCharType::getValueFromObject(const JPValue& obj) JPContext *context = obj.getClass()->getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; - field(v) = frame.CallCharMethodA(obj.getValue().l, context->_java_lang_Character->m_CharValueID, 0); + field(v) = frame.CallCharMethodA(obj.getValue().l, context->_java_lang_Character->m_CharValueID, nullptr); return JPValue(this, v); } @@ -99,7 +99,7 @@ class JPConversionAsJChar : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return match.type = JPMatch::_none; match.type = JPMatch::_none; @@ -179,7 +179,7 @@ JPPyObject JPCharType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jme jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallCharMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualCharMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_class.cpp b/native/common/jp_class.cpp index 361e6fe31..6280aa256 100644 --- a/native/common/jp_class.cpp +++ b/native/common/jp_class.cpp @@ -23,9 +23,9 @@ JPClass::JPClass( const string& name, jint modifiers) { - m_Context = NULL; + m_Context = nullptr; m_CanonicalName = name; - m_SuperClass = NULL; + m_SuperClass = nullptr; m_Interfaces = JPClassList(); m_Modifiers = modifiers; } @@ -63,7 +63,7 @@ jclass JPClass::getJavaClass() const { jclass cls = m_Class.get(); // This sanity check should not be possible to exercise - if (cls == 0) + if (cls == nullptr) JP_RAISE(PyExc_RuntimeError, "Class is null"); // GCOVR_EXCL_LINE return cls; } @@ -88,7 +88,7 @@ void JPClass::assignMembers(JPMethodDispatch* ctor, JPValue JPClass::newInstance(JPJavaFrame& frame, JPPyObjectVector& args) { - if (m_Constructors == NULL) + if (m_Constructors == nullptr) { if (this->isInterface()) { @@ -104,7 +104,7 @@ JPValue JPClass::newInstance(JPJavaFrame& frame, JPPyObjectVector& args) JPContext* JPClass::getContext() const { // This sanity check is for during shutdown. - if (m_Context == 0) + if (m_Context == nullptr) JP_RAISE(PyExc_RuntimeError, "Null context"); // GCOVR_EXCL_LINE return m_Context; } @@ -127,7 +127,7 @@ JPClass* JPClass::newArrayType(JPJavaFrame &frame, long d) jarray JPClass::newArrayOf(JPJavaFrame& frame, jsize sz) { - return frame.NewObjectArray(sz, getJavaClass(), NULL); + return frame.NewObjectArray(sz, getJavaClass(), nullptr); } // // @@ -138,7 +138,7 @@ jarray JPClass::newArrayOf(JPJavaFrame& frame, jsize sz) string JPClass::toString() const { // This sanity check will not be hit in normal operation - if (m_Context == 0) + if (m_Context == nullptr) return m_CanonicalName; // GCOVR_EXCL_LINE JPJavaFrame frame = JPJavaFrame::outer(m_Context); return frame.toString(m_Class.get()); @@ -148,11 +148,11 @@ string JPClass::toString() const string JPClass::getName() const { // This sanity check will not be hit in normal operation - if (m_Context == 0) + if (m_Context == nullptr) return m_CanonicalName; // GCOVR_EXCL_LINE JPJavaFrame frame = JPJavaFrame::outer(m_Context); return frame.toString(frame.CallObjectMethodA( - (jobject) m_Class.get(), m_Context->m_Class_GetNameID, NULL)); + (jobject) m_Class.get(), m_Context->m_Class_GetNameID, nullptr)); } // @@ -163,7 +163,7 @@ JPPyObject JPClass::getStaticField(JPJavaFrame& frame, jclass c, jfieldID fid) JP_TRACE_IN("JPClass::getStaticField"); jobject r = frame.GetStaticObjectField(c, fid); JPClass* type = this; - if (r != NULL) + if (r != nullptr) type = frame.findClassForObject(r); jvalue v; v.l = r; @@ -176,7 +176,7 @@ JPPyObject JPClass::getField(JPJavaFrame& frame, jobject c, jfieldID fid) JP_TRACE_IN("JPClass::getField"); jobject r = frame.GetObjectField(c, fid); JPClass* type = this; - if (r != NULL) + if (r != nullptr) type = frame.findClassForObject(r); jvalue v; v.l = r; @@ -194,7 +194,7 @@ JPPyObject JPClass::invokeStatic(JPJavaFrame& frame, jclass claz, jmethodID mth, } JPClass *type = this; - if (v.l != NULL) + if (v.l != nullptr) type = frame.findClassForObject(v.l); return type->convertToPythonObject(frame, v, false); @@ -210,9 +210,9 @@ JPPyObject JPClass::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jmetho // Call method { JPPyCallRelease call; - if (obj == NULL) + if (obj == nullptr) JP_RAISE(PyExc_ValueError, "method called on null object"); - if (clazz == NULL) + if (clazz == nullptr) v.l = frame.CallObjectMethodA(obj, mth, val); else v.l = frame.CallNonvirtualObjectMethodA(obj, clazz, mth, val); @@ -220,7 +220,7 @@ JPPyObject JPClass::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jmetho // Get the return type JPClass *type = this; - if (v.l != NULL) + if (v.l != nullptr) type = frame.findClassForObject(v.l); return type->convertToPythonObject(frame, v, false); @@ -313,7 +313,7 @@ JPPyObject JPClass::getArrayItem(JPJavaFrame& frame, jarray a, jsize ndx) JPClass *retType = this; jvalue v; v.l = obj; - if (obj != NULL) + if (obj != nullptr) retType = frame.findClassForObject(v.l); return retType->convertToPythonObject(frame, v, false); JP_TRACE_OUT; @@ -350,7 +350,7 @@ JPPyObject JPClass::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool // // We will still need to have the concept of null objects // but we can get those through JObject(None, cls). - if (value.l == NULL) + if (value.l == nullptr) { return JPPyObject::getNone(); } @@ -366,13 +366,13 @@ JPPyObject JPClass::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool if (isThrowable()) { JPPyObject tuple0; - if (value.l == NULL) + if (value.l == nullptr) { tuple0 = JPPyObject::call(PyTuple_New(0)); } else { jstring m = frame.getMessage((jthrowable) value.l); - if (m != NULL) + if (m != nullptr) { tuple0 = JPPyObject::call(PyTuple_Pack(1, JPPyString::fromStringUTF8(frame.toStringUTF8(m)).get())); @@ -385,7 +385,7 @@ JPPyObject JPClass::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool JPPyObject tuple1 = JPPyObject::call(PyTuple_Pack(2, _JObjectKey, tuple0.get())); // Exceptions need new and init - obj = JPPyObject::call(PyObject_Call(wrapper.get(), tuple1.get(), NULL)); + obj = JPPyObject::call(PyObject_Call(wrapper.get(), tuple1.get(), nullptr)); } else { PyTypeObject *type = ((PyTypeObject*) wrapper.get()); diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index fcd4dd156..49ead89c8 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -23,22 +23,22 @@ JPMatch::JPMatch() { - conversion = NULL; - frame = NULL; - object = NULL; + conversion = nullptr; + frame = nullptr; + object = nullptr; type = JPMatch::_none; slot = (JPValue*) - 1; - closure = 0; + closure = nullptr; } JPMatch::JPMatch(JPJavaFrame *fr, PyObject *obj) { - conversion = NULL; + conversion = nullptr; frame = fr; object = obj; type = JPMatch::_none; slot = (JPValue*) - 1; - closure = 0; + closure = nullptr; } JPValue *JPMatch::getJavaSlot() @@ -51,7 +51,7 @@ JPValue *JPMatch::getJavaSlot() jvalue JPMatch::convert() { // Sanity check, this should not happen - if (conversion == NULL) + if (conversion == nullptr) JP_RAISE(PyExc_SystemError, "Fail in conversion"); // GCOVR_EXCL_LINE return conversion->convert(*this); } @@ -61,7 +61,7 @@ JPMethodMatch::JPMethodMatch(JPJavaFrame &frame, JPPyObjectVector& args, bool ca { m_Type = JPMatch::_none; m_IsVarIndirect = false; - m_Overload = 0; + m_Overload = nullptr; m_Offset = 0; m_Skip = 0; m_Hash = callInstance ? 0 : 1000; @@ -101,7 +101,7 @@ JPClassHints::~JPClassHints() JPMatch::Type JPClassHints::getConversion(JPMatch& match, JPClass *cls) { - JPConversion *best = NULL; + JPConversion *best = nullptr; for (auto iter = conversions.begin(); iter != conversions.end(); ++iter) { @@ -112,7 +112,7 @@ JPMatch::Type JPClassHints::getConversion(JPMatch& match, JPClass *cls) best = (*iter); } match.conversion = best; - if (best == NULL) + if (best == nullptr) return match.type = JPMatch::_none; return match.type = JPMatch::_explicit; } @@ -154,9 +154,9 @@ class JPPythonConversion : public JPConversion JPClass *cls = ((JPClass*) match.closure); JPPyObject args = JPPyObject::call(PyTuple_Pack(2, cls->getHost(), match.object)); - JPPyObject ret = JPPyObject::call(PyObject_Call(method_.get(), args.get(), NULL)); + JPPyObject ret = JPPyObject::call(PyObject_Call(method_.get(), args.get(), nullptr)); JPValue *value = PyJPValue_getJavaSlot(ret.get()); - if (value != NULL) + if (value != nullptr) { jvalue v = value->getValue(); JP_TRACE("Value", v.l); @@ -164,7 +164,7 @@ class JPPythonConversion : public JPConversion return v; } JPProxy *proxy = PyJPProxy_getJPProxy(ret.get()); - if (proxy != NULL) + if (proxy != nullptr) { jvalue v = proxy->getProxy(); JP_TRACE("Proxy", v.l); @@ -336,12 +336,12 @@ class JPHintsConversion : public JPConversion { auto *pyhints = (PyJPClassHints*) cls->getHints(); // GCOVR_EXCL_START - if (pyhints == NULL) + if (pyhints == nullptr) { // Force creation of the class that will create the hints PyJPClass_create(*match.frame, cls); pyhints = (PyJPClassHints*) cls->getHints(); - if (pyhints == NULL) + if (pyhints == nullptr) return match.type = JPMatch::_none; } // GCOVR_EXCL_STOP @@ -353,7 +353,7 @@ class JPHintsConversion : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { auto *pyhints = (PyJPClassHints*) cls->getHints(); - if (pyhints == NULL) + if (pyhints == nullptr) return; JPClassHints *hints = pyhints->m_Hints; hints->getInfo(cls, info); @@ -375,7 +375,7 @@ class JPConversionCharArray : public JPConversion { JP_TRACE_IN("JPConversionCharArray::matches"); auto* acls = (JPArrayClass*) cls; - if (match.frame == NULL || !JPPyString::check(match.object) || + if (match.frame == nullptr || !JPPyString::check(match.object) || acls->getComponentType() != match.getContext()->_char) return match.type = JPMatch::_none; match.conversion = this; @@ -417,7 +417,7 @@ class JPConversionByteArray : public JPConversion { JP_TRACE_IN("JPConversionByteArray::matches"); auto* acls = (JPArrayClass*) cls; - if (match.frame == NULL || !PyBytes_Check(match.object) || + if (match.frame == nullptr || !PyBytes_Check(match.object) || acls->getComponentType() != match.frame->getContext()->_byte) return match.type = JPMatch::_none; match.conversion = this; @@ -438,7 +438,7 @@ class JPConversionByteArray : public JPConversion JPJavaFrame frame(*match.frame); jvalue res; Py_ssize_t size = 0; - char *buffer = NULL; + char *buffer = nullptr; PyBytes_AsStringAndSize(match.object, &buffer, &size); // internal reference jbyteArray byteArray = frame.NewByteArray((jsize) size); frame.SetByteArrayRegion(byteArray, 0, (jsize) size, (jbyte*) buffer); @@ -592,7 +592,7 @@ class JPConversionNull : public JPConversion jvalue convert(JPMatch &match) override { jvalue v; - v.l = NULL; + v.l = nullptr; return v; } } _nullConversion; @@ -604,10 +604,10 @@ class JPConversionClass : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionClass::matches"); - if (match.frame == NULL) + if (match.frame == nullptr) return match.type = JPMatch::_none; JPClass* cls2 = PyJPClass_getJPClass(match.object); - if (cls2 == NULL) + if (cls2 == nullptr) return match.type = JPMatch::_none; match.conversion = this; match.closure = cls2; @@ -638,11 +638,11 @@ class JPConversionObject : public JPConversion { JP_TRACE_IN("JPConversionObject::matches"); JPValue *value = match.getJavaSlot(); - if (value == NULL || match.frame == NULL) + if (value == nullptr || match.frame == nullptr) return match.type = JPMatch::_none; match.conversion = this; JPClass *oc = value->getClass(); - if (oc == NULL) + if (oc == nullptr) return match.type = JPMatch::_none; if (oc == cls) { @@ -680,7 +680,7 @@ JPMatch::Type JPConversionJavaValue::matches(JPClass *cls, JPMatch &match) { JP_TRACE_IN("JPConversionJavaValue::matches"); JPValue *slot = match.getJavaSlot(); - if (slot == NULL || slot->getClass() != cls) + if (slot == nullptr || slot->getClass() != cls) return match.type = JPMatch::_none; match.conversion = this; return match.type = JPMatch::_exact; @@ -708,7 +708,7 @@ class JPConversionString : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionString::matches"); - if (match.frame == NULL || !JPPyString::check(match.object)) + if (match.frame == nullptr || !JPPyString::check(match.object)) return match.type = JPMatch::_none; match.conversion = this; if (cls == match.getContext()->_java_lang_String) @@ -738,7 +738,7 @@ class JPConversionBox : public JPConversion jvalue convert(JPMatch &match) override { jvalue res; - JPPyObjectVector args(match.object, NULL); + JPPyObjectVector args(match.object, nullptr); auto *cls = (JPClass*) match.closure; JPValue pobj = cls->newInstance(*match.frame, args); res.l = pobj.getJavaObject(); @@ -775,7 +775,7 @@ class JPConversionBoxLong : public JPConversionBox JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionBoxLong::matches"); - if (match.frame == NULL) + if (match.frame == nullptr) return match.type = JPMatch::_none; if (PyLong_CheckExact(match.object) || PyIndex_Check(match.object)) { @@ -820,7 +820,7 @@ class JPConversionBoxDouble : public JPConversionBox JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionBoxDouble::matches"); - if (match.frame == NULL) + if (match.frame == nullptr) return match.type = JPMatch::_none; if (PyNumber_Check(match.object)) { @@ -862,7 +862,7 @@ class JPConversionJavaObjectAny : public JPConversionBox { JP_TRACE_IN("JPConversionJavaObjectAny::matches"); JPValue *value = match.getJavaSlot(); - if (value == NULL || match.frame == NULL || value->getClass() == NULL) + if (value == nullptr || match.frame == nullptr || value->getClass() == nullptr) return match.type = JPMatch::_none; match.conversion = this; match.type = (value->getClass() == cls) ? JPMatch::_exact : JPMatch::_implicit; @@ -907,7 +907,7 @@ class JPConversionJavaNumberAny : public JPConversionJavaObjectAny JPValue *value = match.getJavaSlot(); // This converter only works for number types, thus boolean and char // are excluded. - if (value == NULL || match.frame == NULL || value->getClass() == NULL + if (value == nullptr || match.frame == nullptr || value->getClass() == nullptr || value->getClass() == context->_boolean || value->getClass() == context->_char) return match.type = JPMatch::_none; @@ -940,7 +940,7 @@ class JPConversionUnbox : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPContext *context = match.getContext(); - if (context == NULL) + if (context == nullptr) return match.type = JPMatch::_none; JPValue *slot = match.slot; auto *pcls = (JPPrimitiveType*) cls; @@ -976,7 +976,7 @@ class JPConversionProxy : public JPConversion { JP_TRACE_IN("JPConversionProxy::matches"); JPProxy* proxy = PyJPProxy_getJPProxy(match.object); - if (proxy == NULL || match.frame == NULL) + if (proxy == nullptr || match.frame == nullptr) return match.type = JPMatch::_none; // Check if any of the interfaces matches ... diff --git a/native/common/jp_classloader.cpp b/native/common/jp_classloader.cpp index b7c48ee46..9e754fb8d 100644 --- a/native/common/jp_classloader.cpp +++ b/native/common/jp_classloader.cpp @@ -34,10 +34,10 @@ static jobject toURL(JPJavaFrame &frame, const string& path) // url = file.toURI().toURL(); jmethodID toURI = frame.GetMethodID(fileClass, "toURI", "()Ljava/net/URI;"); - jobject uri = frame.CallObjectMethodA(file, toURI, NULL); + jobject uri = frame.CallObjectMethodA(file, toURI, nullptr); jclass uriClass = frame.GetObjectClass(uri); jmethodID toURL = frame.GetMethodID(uriClass, "toURL", "()Ljava/net/URL;"); - return frame.CallObjectMethodA(uri, toURL, NULL); + return frame.CallObjectMethodA(uri, toURL, nullptr); } JPClassLoader::JPClassLoader(JPJavaFrame& frame) @@ -53,10 +53,10 @@ JPClassLoader::JPClassLoader(JPJavaFrame& frame) jmethodID getSystemClassLoader = frame.GetStaticMethodID(classLoaderClass, "getSystemClassLoader", "()Ljava/lang/ClassLoader;"); m_SystemClassLoader = JPObjectRef(frame, - frame.CallStaticObjectMethodA(classLoaderClass, getSystemClassLoader, 0)); + frame.CallStaticObjectMethodA(classLoaderClass, getSystemClassLoader, nullptr)); jclass dynamicLoaderClass = frame.getEnv()->FindClass("org/jpype/classloader/DynamicClassLoader"); - if (dynamicLoaderClass != NULL) + if (dynamicLoaderClass != nullptr) { // Easy the Dynamic loader is already in the path, so just use it as the bootloader jmethodID newDyLoader = frame.GetMethodID(dynamicLoaderClass, "", @@ -83,7 +83,7 @@ JPClassLoader::JPClassLoader(JPJavaFrame& frame) // urlArray = new URL[]{url}; jclass urlClass = frame.GetObjectClass(url1); - jobjectArray urlArray = frame.NewObjectArray(1, urlClass, NULL); + jobjectArray urlArray = frame.NewObjectArray(1, urlClass, nullptr); frame.SetObjectArrayElement(urlArray, 0, url1); // frame.SetObjectArrayElement(urlArray, 1, url2); diff --git a/native/common/jp_context.cpp b/native/common/jp_context.cpp index ae2a7c289..f0412d6bd 100644 --- a/native/common/jp_context.cpp +++ b/native/common/jp_context.cpp @@ -46,60 +46,60 @@ void JPRef_failed() JPContext::JPContext() { - m_JavaVM = 0; - _void = 0; - _byte = 0; - _boolean = 0; - _char = 0; - _short = 0; - _int = 0; - _long = 0; - _float = 0; - _double = 0; - - _java_lang_Void = 0; - _java_lang_Boolean = 0; - _java_lang_Byte = 0; - _java_lang_Character = 0; - _java_lang_Short = 0; - _java_lang_Integer = 0; - _java_lang_Long = 0; - _java_lang_Float = 0; - _java_lang_Double = 0; - - _java_lang_Object = 0; - _java_lang_Class = 0; - _java_lang_String = 0; - - _java_lang_reflect_Method = 0; - _java_lang_reflect_Field = 0; - _java_nio_ByteBuffer = 0; - - m_TypeManager = 0; - m_ClassLoader = 0; - - m_Object_ToStringID = 0; - m_Object_EqualsID = 0; + m_JavaVM = nullptr; + _void = nullptr; + _byte = nullptr; + _boolean = nullptr; + _char = nullptr; + _short = nullptr; + _int = nullptr; + _long = nullptr; + _float = nullptr; + _double = nullptr; + + _java_lang_Void = nullptr; + _java_lang_Boolean = nullptr; + _java_lang_Byte = nullptr; + _java_lang_Character = nullptr; + _java_lang_Short = nullptr; + _java_lang_Integer = nullptr; + _java_lang_Long = nullptr; + _java_lang_Float = nullptr; + _java_lang_Double = nullptr; + + _java_lang_Object = nullptr; + _java_lang_Class = nullptr; + _java_lang_String = nullptr; + + _java_lang_reflect_Method = nullptr; + _java_lang_reflect_Field = nullptr; + _java_nio_ByteBuffer = nullptr; + + m_TypeManager = nullptr; + m_ClassLoader = nullptr; + + m_Object_ToStringID = nullptr; + m_Object_EqualsID = nullptr; m_Running = false; // Java Functions - m_Object_ToStringID = NULL; - m_Object_EqualsID = NULL; - m_Object_HashCodeID = NULL; - m_CallMethodID = NULL; - m_Class_GetNameID = NULL; - m_Context_collectRectangularID = NULL; - m_Context_assembleID = NULL; - m_String_ToCharArrayID = NULL; - m_Context_CreateExceptionID = NULL; - m_Context_GetExcClassID = NULL; - m_Context_GetExcValueID = NULL; - m_CompareToID = NULL; - m_Buffer_IsReadOnlyID = NULL; - m_Context_OrderID = NULL; - m_Object_GetClassID = NULL; - m_Throwable_GetCauseID = NULL; - m_Context_GetStackFrameID = NULL; + m_Object_ToStringID = nullptr; + m_Object_EqualsID = nullptr; + m_Object_HashCodeID = nullptr; + m_CallMethodID = nullptr; + m_Class_GetNameID = nullptr; + m_Context_collectRectangularID = nullptr; + m_Context_assembleID = nullptr; + m_String_ToCharArrayID = nullptr; + m_Context_CreateExceptionID = nullptr; + m_Context_GetExcClassID = nullptr; + m_Context_GetExcValueID = nullptr; + m_CompareToID = nullptr; + m_Buffer_IsReadOnlyID = nullptr; + m_Context_OrderID = nullptr; + m_Object_GetClassID = nullptr; + m_Throwable_GetCauseID = nullptr; + m_Context_GetStackFrameID = nullptr; m_Embedded = false; m_GC = new JPGarbageCollection(this); @@ -113,7 +113,7 @@ JPContext::~JPContext() bool JPContext::isRunning() { - if (m_JavaVM == NULL || !m_Running) + if (m_JavaVM == nullptr || !m_Running) { return false; } @@ -125,14 +125,14 @@ bool JPContext::isRunning() */ void assertJVMRunning(JPContext* context, const JPStackInfo& info) { - if (_JVMNotRunning == NULL) + if (_JVMNotRunning == nullptr) { _JVMNotRunning = PyObject_GetAttrString(PyJPModule, "JVMNotRunning"); JP_PY_CHECK(); Py_INCREF(_JVMNotRunning); } - if (context == NULL) + if (context == nullptr) { throw JPypeException(JPError::_python_exc, _JVMNotRunning, "Java Context is null", info); } @@ -176,7 +176,7 @@ void JPContext::startJVM(const string& vmPath, const StringVector& args, // Pack the arguments JP_TRACE("Pack arguments"); JavaVMInitArgs jniArgs; - jniArgs.options = NULL; + jniArgs.options = nullptr; // prepare this ... jniArgs.version = USE_JNI_VERSION; @@ -194,7 +194,7 @@ void JPContext::startJVM(const string& vmPath, const StringVector& args, } // Launch the JVM - JNIEnv* env = NULL; + JNIEnv* env = nullptr; JP_TRACE("Create JVM"); try { @@ -206,7 +206,7 @@ void JPContext::startJVM(const string& vmPath, const StringVector& args, JP_TRACE("JVM created"); delete [] jniArgs.options; - if (m_JavaVM == NULL) + if (m_JavaVM == nullptr) { JP_TRACE("Unable to start"); JP_RAISE(PyExc_RuntimeError, "Unable to start JVM"); @@ -277,7 +277,7 @@ void JPContext::initializeResources(JNIEnv* env, bool interrupt) jvalue val[4]; val[0].j = (jlong) this; val[1].l = m_ClassLoader->getBootLoader(); - val[2].l = 0; + val[2].l = nullptr; val[3].z = interrupt; if (!m_Embedded) @@ -299,7 +299,7 @@ void JPContext::initializeResources(JNIEnv* env, bool interrupt) jmethodID getTypeManager = frame.GetMethodID(contextClass, "getTypeManager", "()Lorg/jpype/manager/TypeManager;"); m_TypeManager->m_JavaTypeManager = JPObjectRef(frame, - frame.CallObjectMethodA(m_JavaContext.get(), getTypeManager, 0)); + frame.CallObjectMethodA(m_JavaContext.get(), getTypeManager, nullptr)); // Set up methods after everything is start so we get better error // messages @@ -376,7 +376,7 @@ void JPContext::onShutdown() void JPContext::shutdownJVM(bool destroyJVM, bool freeJVM) { JP_TRACE_IN("JPContext::shutdown"); - if (m_JavaVM == NULL) + if (m_JavaVM == nullptr) JP_RAISE(PyExc_RuntimeError, "Attempt to shutdown without a live JVM"); // if (m_Embedded) // JP_RAISE(PyExc_RuntimeError, "Cannot shutdown from embedded Python"); @@ -393,7 +393,7 @@ void JPContext::shutdownJVM(bool destroyJVM, bool freeJVM) if (freeJVM) { JP_TRACE("Unload JVM"); - m_JavaVM = NULL; + m_JavaVM = nullptr; JPPlatformAdapter::getAdapter()->unloadLibrary(); } @@ -412,7 +412,7 @@ void JPContext::ReleaseGlobalRef(jobject obj) { JP_TRACE_IN("JPContext::ReleaseGlobalRef", obj); // Check if the JVM is already shutdown - if (m_JavaVM == NULL) + if (m_JavaVM == nullptr) return; // Get the environment and release the resource if we can. @@ -431,7 +431,7 @@ void JPContext::ReleaseGlobalRef(jobject obj) void JPContext::attachCurrentThread() { JNIEnv* env; - jint res = m_JavaVM->functions->AttachCurrentThread(m_JavaVM, (void**) &env, NULL); + jint res = m_JavaVM->functions->AttachCurrentThread(m_JavaVM, (void**) &env, nullptr); if (res != JNI_OK) JP_RAISE(PyExc_RuntimeError, "Unable to attach to thread"); } @@ -439,7 +439,7 @@ void JPContext::attachCurrentThread() void JPContext::attachCurrentThreadAsDaemon() { JNIEnv* env; - jint res = m_JavaVM->functions->AttachCurrentThreadAsDaemon(m_JavaVM, (void**) &env, NULL); + jint res = m_JavaVM->functions->AttachCurrentThreadAsDaemon(m_JavaVM, (void**) &env, nullptr); if (res != JNI_OK) JP_RAISE(PyExc_RuntimeError, "Unable to attach to thread as daemon"); } @@ -457,8 +457,8 @@ void JPContext::detachCurrentThread() JNIEnv* JPContext::getEnv() { - JNIEnv* env = NULL; - if (m_JavaVM == NULL) + JNIEnv* env = nullptr; + if (m_JavaVM == nullptr) { JP_RAISE(PyExc_RuntimeError, "JVM is null"); } @@ -471,7 +471,7 @@ JNIEnv* JPContext::getEnv() { // We will attach as daemon so that the newly attached thread does // not deadlock the shutdown. The user can convert later if they want. - res = m_JavaVM->AttachCurrentThreadAsDaemon((void**) &env, NULL); + res = m_JavaVM->AttachCurrentThreadAsDaemon((void**) &env, nullptr); if (res != JNI_OK) JP_RAISE(PyExc_RuntimeError, "Unable to attach to local thread"); } diff --git a/native/common/jp_convert.cpp b/native/common/jp_convert.cpp index 04e5f6e4d..919417461 100644 --- a/native/common/jp_convert.cpp +++ b/native/common/jp_convert.cpp @@ -128,7 +128,7 @@ class Reverse jconverter getConverter(const char* from, int itemsize, const char* to) { // If not specified then the type is bytes - if (from == NULL) + if (from == nullptr) from = "B"; // Skip specifiers diff --git a/native/common/jp_doubletype.cpp b/native/common/jp_doubletype.cpp index 27ad8d854..6cf155bf7 100644 --- a/native/common/jp_doubletype.cpp +++ b/native/common/jp_doubletype.cpp @@ -44,7 +44,7 @@ JPValue JPDoubleType::getValueFromObject(const JPValue& obj) jvalue v; jobject jo = obj.getValue().l; auto* jb = (JPBoxedType*) frame.findClassForObject(jo); - field(v) = (type_t) frame.CallDoubleMethodA(jo, jb->m_DoubleValueID, 0); + field(v) = (type_t) frame.CallDoubleMethodA(jo, jb->m_DoubleValueID, nullptr); return JPValue(this, v); } @@ -73,7 +73,7 @@ class JPConversionAsJDouble : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return match.type = JPMatch::_none; match.type = JPMatch::_none; @@ -183,7 +183,7 @@ JPPyObject JPDoubleType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, j jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallDoubleMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualDoubleMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index f16121f12..3281af32c 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -28,7 +28,7 @@ JPypeException::JPypeException(JPJavaFrame &frame, jthrowable th, const JPStackI JP_TRACE("JAVA EXCEPTION THROWN with java throwable"); m_Context = frame.getContext(); m_Type = JPError::_java_error; - m_Error.l = NULL; + m_Error.l = nullptr; m_Message = frame.toString(th); from(stackInfo); } @@ -127,7 +127,7 @@ string JPypeException::getMessage() bool isJavaThrowable(PyObject* exceptionClass) { JPClass* cls = PyJPClass_getJPClass(exceptionClass); - if (cls == NULL) + if (cls == nullptr) return false; return cls->isThrowable(); } @@ -137,7 +137,7 @@ void JPypeException::convertJavaToPython() // Welcome to paranoia land, where they really are out to get you! JP_TRACE_IN("JPypeException::convertJavaToPython"); // GCOVR_EXCL_START - if (m_Context == NULL) + if (m_Context == nullptr) { PyErr_SetString(PyExc_RuntimeError, "Unable to convert java error, context is null."); return; @@ -151,7 +151,7 @@ void JPypeException::convertJavaToPython() v.l = th; // GCOVR_EXCL_START // This is condition is only hit if something fails during the initial boot - if (m_Context->getJavaContext() == NULL || m_Context->m_Context_GetExcClassID == NULL) + if (m_Context->getJavaContext() == nullptr || m_Context->m_Context_GetExcClassID == nullptr) { PyErr_SetString(PyExc_SystemError, frame.toString(th).c_str()); return; @@ -180,7 +180,7 @@ void JPypeException::convertJavaToPython() // GCOVR_EXCL_START // This sanity check can only fail if the type system fails to find a // class for the current exception. - if (cls == NULL) + if (cls == nullptr) { // Nope, no class found PyErr_SetString(PyExc_RuntimeError, frame.toString(th).c_str()); @@ -207,14 +207,14 @@ void JPypeException::convertJavaToPython() // Add cause to the exception JPPyObject args = JPPyObject::call(Py_BuildValue("(s)", "Java Exception")); - JPPyObject cause = JPPyObject::call(PyObject_Call(PyExc_Exception, args.get(), NULL)); - JPPyObject trace = PyTrace_FromJavaException(frame, th, NULL); + JPPyObject cause = JPPyObject::call(PyObject_Call(PyExc_Exception, args.get(), nullptr)); + JPPyObject trace = PyTrace_FromJavaException(frame, th, nullptr); // Attach Java causes as well. try { jthrowable jcause = frame.getCause(th); - if (jcause != NULL) + if (jcause != nullptr) { jvalue a; a.l = (jobject) jcause; @@ -246,7 +246,7 @@ void JPypeException::convertPythonToJava(JPContext* context) { eframe.good = false; JPValue* javaExc = PyJPValue_getJavaSlot(eframe.m_ExceptionValue.get()); - if (javaExc != NULL) + if (javaExc != nullptr) { th = (jthrowable) javaExc->getJavaObject(); JP_TRACE("Throwing Java", frame.toString(th)); @@ -255,7 +255,7 @@ void JPypeException::convertPythonToJava(JPContext* context) } } - if (context->m_Context_CreateExceptionID == NULL) + if (context->m_Context_CreateExceptionID == nullptr) { frame.ThrowNew(frame.FindClass("java/lang/RuntimeException"), getMessage().c_str()); return; @@ -325,11 +325,11 @@ void JPypeException::toPython() ss << "JVM DLL not found: " << mesg; PyObject* val = Py_BuildValue("(iz)", m_Error.i, ss.str().c_str()); - if (val != NULL) + if (val != nullptr) { - PyObject* exc = PyObject_Call(PyExc_OSError, val, NULL); + PyObject* exc = PyObject_Call(PyExc_OSError, val, nullptr); Py_DECREF(val); - if (exc != NULL) + if (exc != nullptr) { PyErr_SetObject(PyExc_OSError, exc); Py_DECREF(exc); @@ -341,11 +341,11 @@ void JPypeException::toPython() ss << "JVM DLL not found: " << mesg; PyObject* val = Py_BuildValue("(izzi)", 2, ss.str().c_str(), NULL, m_Error.i); - if (val != NULL) + if (val != nullptr) { - PyObject* exc = PyObject_Call(PyExc_OSError, val, NULL); + PyObject* exc = PyObject_Call(PyExc_OSError, val, nullptr); Py_DECREF(val); - if (exc != NULL) + if (exc != nullptr) { PyErr_SetObject(PyExc_OSError, exc); Py_DECREF(exc); @@ -373,7 +373,7 @@ void JPypeException::toPython() eframe.normalize(); JPPyObject args = JPPyObject::call(Py_BuildValue("(s)", "C++ Exception")); JPPyObject trace = JPPyObject::call(PyTrace_FromJPStackTrace(m_Trace)); - JPPyObject cause = JPPyObject::accept(PyObject_Call(PyExc_Exception, args.get(), NULL)); + JPPyObject cause = JPPyObject::accept(PyObject_Call(PyExc_Exception, args.get(), nullptr)); if (!cause.isNull()) { PyException_SetTraceback(cause.get(), trace.get()); @@ -409,7 +409,7 @@ void JPypeException::toPython() JPTracer::trace("Fatal error in exception handling"); // You shall not pass! - int *i = 0; + int *i = nullptr; *i = 0; } // GCOVR_EXCL_STOP @@ -472,7 +472,7 @@ void JPypeException::toJava(JPContext *context) JPTracer::trace(info.getFile(), info.getFunction(), info.getLine()); // Take one for the team. - int *i = 0; + int *i = nullptr; *i = 0; // GCOVR_EXCL_STOP } catch (...) // GCOVR_EXCL_LINE @@ -482,7 +482,7 @@ void JPypeException::toJava(JPContext *context) JPTracer::trace("Fatal error in exception handling"); // It is pointless, I can't go on. - int *i = 0; + int *i = nullptr; *i = 0; // GCOVR_EXCL_STOP } @@ -500,8 +500,8 @@ PyTracebackObject *tb_create( PyCodeObject *code = PyCode_NewEmpty(filename, funcname, linenum); // If we don't get the code object there is no point - if (code == NULL) - return NULL; + if (code == nullptr) + return nullptr; // This is a bit of a kludge. Python lacks a way to directly create // a frame from a code object except when creating from the threadstate. @@ -520,31 +520,31 @@ PyTracebackObject *tb_create( // portable, but we have to create a big (uninitialized object) each time we // want to pass in the previous frame. PyThreadState state; - if (last_traceback != NULL) + if (last_traceback != nullptr) state.frame = last_traceback->tb_frame; else - state.frame = NULL; + state.frame = nullptr; // Create a frame for the traceback. - PyFrameObject *frame = PyFrame_New(&state, code, dict, NULL); + PyFrameObject *frame = PyFrame_New(&state, code, dict, nullptr); // frame just borrows the reference rather than claiming it // so we need to get rid of the extra reference here. Py_DECREF(code); // If we don't get the frame object there is no point - if (frame == NULL) - return NULL; + if (frame == nullptr) + return nullptr; // Create a traceback auto *traceback = (PyTracebackObject*) PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type); // We could fail in process - if (traceback == NULL) + if (traceback == nullptr) { Py_DECREF(frame); - return NULL; + return nullptr; } // Set the fields @@ -561,26 +561,26 @@ PyTracebackObject *tb_create( PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace) { - PyTracebackObject *last_traceback = NULL; + PyTracebackObject *last_traceback = nullptr; PyObject *dict = PyModule_GetDict(PyJPModule); for (auto iter = trace.begin(); iter != trace.end(); ++iter) { last_traceback = tb_create(last_traceback, dict, iter->getFile(), iter->getFunction(), iter->getLine()); } - if (last_traceback == NULL) + if (last_traceback == nullptr) Py_RETURN_NONE; return (PyObject*) last_traceback; } JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowable prev) { - PyTracebackObject *last_traceback = NULL; + PyTracebackObject *last_traceback = nullptr; JPContext *context = frame.getContext(); jvalue args[2]; args[0].l = th; args[1].l = prev; - if (context->m_Context_GetStackFrameID == NULL) + if (context->m_Context_GetStackFrameID == nullptr) return JPPyObject(); JNIEnv* env = frame.getEnv(); @@ -591,7 +591,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab if (env->ExceptionCheck() == JNI_TRUE) env->ExceptionClear(); - if (obj == NULL) + if (obj == nullptr) return JPPyObject(); jsize sz = frame.GetArrayLength(obj); PyObject *dict = PyModule_GetDict(PyJPModule); @@ -601,14 +601,14 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab auto jclassname = (jstring) frame.GetObjectArrayElement(obj, i); auto jmethodname = (jstring) frame.GetObjectArrayElement(obj, i + 1); auto jfilename = (jstring) frame.GetObjectArrayElement(obj, i + 2); - if (jfilename != NULL) + if (jfilename != nullptr) filename = frame.toStringUTF8(jfilename); else filename = frame.toStringUTF8(jclassname) + ".java"; - if (jmethodname != NULL) + if (jmethodname != nullptr) method = frame.toStringUTF8(jclassname) + "." + frame.toStringUTF8(jmethodname); jint lineNum = - frame.CallIntMethodA(frame.GetObjectArrayElement(obj, i + 3), context->_java_lang_Integer->m_IntValueID, 0); + frame.CallIntMethodA(frame.GetObjectArrayElement(obj, i + 3), context->_java_lang_Integer->m_IntValueID, nullptr); last_traceback = tb_create(last_traceback, dict, filename.c_str(), method.c_str(), lineNum); @@ -616,7 +616,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab frame.DeleteLocalRef(jmethodname); frame.DeleteLocalRef(jfilename); } - if (last_traceback == NULL) + if (last_traceback == nullptr) return JPPyObject(); return JPPyObject::call((PyObject*) last_traceback); } diff --git a/native/common/jp_floattype.cpp b/native/common/jp_floattype.cpp index 1eb53668c..a15a0c4ad 100644 --- a/native/common/jp_floattype.cpp +++ b/native/common/jp_floattype.cpp @@ -45,7 +45,7 @@ JPValue JPFloatType::getValueFromObject(const JPValue& obj) jvalue v; jobject jo = obj.getValue().l; auto* jb = (JPBoxedType*) frame.findClassForObject(jo); - field(v) = (type_t) frame.CallFloatMethodA(jo, jb->m_FloatValueID, 0); + field(v) = (type_t) frame.CallFloatMethodA(jo, jb->m_FloatValueID, nullptr); return JPValue(this, v); } @@ -60,7 +60,7 @@ class JPConversionAsJFloat : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return match.type = JPMatch::_none; match.type = JPMatch::_none; @@ -166,7 +166,7 @@ JPPyObject JPFloatType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jm jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallFloatMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualFloatMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_functional.cpp b/native/common/jp_functional.cpp index 687294917..3c52f4429 100644 --- a/native/common/jp_functional.cpp +++ b/native/common/jp_functional.cpp @@ -82,7 +82,7 @@ class JPConversionFunctional : public JPConversion optional = PyTuple_Size(defaults.get()); const int jargs = cls->getContext()->getTypeManager()->interfaceParameterCount(cls); // Bound self argument removes one argument - if ((PyMethod_Self(match.object))!=NULL) // borrowed + if ((PyMethod_Self(match.object))!=nullptr) // borrowed args--; // Too few arguments if (!is_varargs && args < jargs) diff --git a/native/common/jp_gc.cpp b/native/common/jp_gc.cpp index 8b711f997..505373580 100644 --- a/native/common/jp_gc.cpp +++ b/native/common/jp_gc.cpp @@ -117,9 +117,9 @@ JPGarbageCollection::JPGarbageCollection(JPContext *context) running = false; in_python_gc = false; java_triggered = false; - python_gc = NULL; - _SystemClass = NULL; - _gcMethodID = NULL; + python_gc = nullptr; + _SystemClass = nullptr; + _gcMethodID = nullptr; last_python = 0; last_java = 0; @@ -248,7 +248,7 @@ void JPGarbageCollection::onEnd() low_water = (low_water + high_water) / 2; // Don't reset the limit if it was count triggered JPJavaFrame frame = JPJavaFrame::outer(m_Context); - frame.CallStaticVoidMethodA(_SystemClass, _gcMethodID, 0); + frame.CallStaticVoidMethodA(_SystemClass, _gcMethodID, nullptr); python_triggered++; } } diff --git a/native/common/jp_inttype.cpp b/native/common/jp_inttype.cpp index cd8efcb7d..9523be1ae 100644 --- a/native/common/jp_inttype.cpp +++ b/native/common/jp_inttype.cpp @@ -31,7 +31,7 @@ JPIntType::~JPIntType() JPPyObject JPIntType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { JPPyObject tmp = JPPyObject::call(PyLong_FromLong(field(val))); - if (getHost() == NULL) + if (getHost() == nullptr) return tmp; JPPyObject out = JPPyObject::call(convertLong(getHost(), (PyLongObject*) tmp.get())); PyJPValue_assignJavaSlot(frame, out.get(), JPValue(this, val)); @@ -45,7 +45,7 @@ JPValue JPIntType::getValueFromObject(const JPValue& obj) jvalue v; jobject jo = obj.getValue().l; auto* jb = (JPBoxedType*) frame.findClassForObject(jo); - field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, 0); + field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, nullptr); return JPValue(this, v); } @@ -60,7 +60,7 @@ class JPConversionJInt : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue *value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return JPMatch::_none; match.type = JPMatch::_none; @@ -162,7 +162,7 @@ JPPyObject JPIntType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jmet jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallIntMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualIntMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_javaframe.cpp b/native/common/jp_javaframe.cpp index 26f3b6eba..bf2765f7a 100644 --- a/native/common/jp_javaframe.cpp +++ b/native/common/jp_javaframe.cpp @@ -37,7 +37,7 @@ static void jpype_frame_check(int popped) JPJavaFrame::JPJavaFrame(JPContext* context, JNIEnv* p_env, int size, bool outer) : m_Context(context), m_Env(p_env), m_Popped(false), m_Outer(outer) { - if (p_env == NULL) + if (p_env == nullptr) m_Env = context->getEnv(); // Create a memory management frame to live in @@ -72,7 +72,7 @@ JPJavaFrame::~JPJavaFrame() if (!m_Popped) { JP_TRACE_JAVA("~JavaFrame", (jobject) - 2); - m_Env->PopLocalFrame(NULL); + m_Env->PopLocalFrame(nullptr); JP_FRAME_CHECK(); } @@ -1022,7 +1022,7 @@ jlong JPJavaFrame::GetDirectBufferCapacity(jobject obj) jboolean JPJavaFrame::isBufferReadOnly(jobject obj) { - return CallBooleanMethodA(obj, m_Context->m_Buffer_IsReadOnlyID, 0); + return CallBooleanMethodA(obj, m_Context->m_Buffer_IsReadOnlyID, nullptr); } jboolean JPJavaFrame::orderBuffer(jobject obj) @@ -1038,7 +1038,7 @@ jboolean JPJavaFrame::orderBuffer(jobject obj) jclass JPJavaFrame::getClass(jobject obj) { - return (jclass) CallObjectMethodA(obj, m_Context->m_Object_GetClassID, 0); + return (jclass) CallObjectMethodA(obj, m_Context->m_Object_GetClassID, nullptr); } // GCOVR_EXCL_STOP @@ -1075,7 +1075,7 @@ class JPStringAccessor string JPJavaFrame::toString(jobject o) { - auto str = (jstring) CallObjectMethodA(o, m_Context->m_Object_ToStringID, 0); + auto str = (jstring) CallObjectMethodA(o, m_Context->m_Object_ToStringID, nullptr); return toStringUTF8(str); } @@ -1101,7 +1101,7 @@ jstring JPJavaFrame::fromStringUTF8(const string& str) jobject JPJavaFrame::toCharArray(jstring jstr) { - return CallObjectMethodA(jstr, m_Context->m_String_ToCharArrayID, 0); + return CallObjectMethodA(jstr, m_Context->m_String_ToCharArrayID, nullptr); } bool JPJavaFrame::equals(jobject o1, jobject o2 ) @@ -1113,13 +1113,13 @@ bool JPJavaFrame::equals(jobject o1, jobject o2 ) jint JPJavaFrame::hashCode(jobject o) { - return CallIntMethodA(o, m_Context->m_Object_HashCodeID, 0); + return CallIntMethodA(o, m_Context->m_Object_HashCodeID, nullptr); } jobject JPJavaFrame::collectRectangular(jarray obj) { - if (m_Context->m_Context_collectRectangularID == 0) - return 0; + if (m_Context->m_Context_collectRectangularID == nullptr) + return nullptr; jvalue v; v.l = (jobject) obj; JAVA_RETURN(jobject, "JPJavaFrame::collectRectangular", @@ -1130,8 +1130,8 @@ jobject JPJavaFrame::collectRectangular(jarray obj) jobject JPJavaFrame::assemble(jobject dims, jobject parts) { - if (m_Context->m_Context_collectRectangularID == 0) - return 0; + if (m_Context->m_Context_collectRectangularID == nullptr) + return nullptr; jvalue v[2]; v[0].l = (jobject) dims; v[1].l = (jobject) parts; @@ -1155,8 +1155,8 @@ jobject JPJavaFrame::newArrayInstance(jclass c, jintArray dims) jobject JPJavaFrame::callMethod(jobject method, jobject obj, jobject args) { JP_TRACE_IN("JPJavaFrame::callMethod"); - if (m_Context->m_CallMethodID == 0) - return NULL; + if (m_Context->m_CallMethodID == nullptr) + return nullptr; JPJavaFrame frame(*this); jvalue v[3]; v[0].l = method; @@ -1199,12 +1199,12 @@ jint JPJavaFrame::compareTo(jobject obj, jobject obj2) jthrowable JPJavaFrame::getCause(jthrowable th) { - return (jthrowable) CallObjectMethodA((jobject) th, m_Context->m_Throwable_GetCauseID, NULL); + return (jthrowable) CallObjectMethodA((jobject) th, m_Context->m_Throwable_GetCauseID, nullptr); } jstring JPJavaFrame::getMessage(jthrowable th) { - return (jstring) CallObjectMethodA((jobject) th, m_Context->m_Throwable_GetMessageID, NULL); + return (jstring) CallObjectMethodA((jobject) th, m_Context->m_Throwable_GetMessageID, nullptr); } jboolean JPJavaFrame::isPackage(const string& str) diff --git a/native/common/jp_longtype.cpp b/native/common/jp_longtype.cpp index a61b1647f..37e5e88a9 100644 --- a/native/common/jp_longtype.cpp +++ b/native/common/jp_longtype.cpp @@ -43,7 +43,7 @@ JPValue JPLongType::getValueFromObject(const JPValue& obj) jvalue v; jobject jo = obj.getValue().l; auto* jb = (JPBoxedType*) frame.findClassForObject(jo); - field(v) = (type_t) frame.CallLongMethodA(jo, jb->m_LongValueID, 0); + field(v) = (type_t) frame.CallLongMethodA(jo, jb->m_LongValueID, nullptr); return JPValue(this, v); } @@ -58,7 +58,7 @@ class JPConversionJLong : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue* value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return match.type = JPMatch::_none; // Implied conversion from boxed to primitive (JLS 5.1.8) @@ -162,7 +162,7 @@ JPPyObject JPLongType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jme jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallLongMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualLongMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index b121ac3d5..0dddcfd23 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -227,7 +227,7 @@ JPPyObject JPMethod::invoke(JPJavaFrame& frame, JPMethodMatch& match, JPPyObject { JPValue* selfObj = PyJPValue_getJavaSlot(arg[0]); jobject c; - if (selfObj == NULL) + if (selfObj == nullptr) { // This only can be hit by calling an instance method as a // class object. We already know it is safe to convert. @@ -237,7 +237,7 @@ JPPyObject JPMethod::invoke(JPJavaFrame& frame, JPMethodMatch& match, JPPyObject { c = selfObj->getJavaObject(); } - jclass clazz = NULL; + jclass clazz = nullptr; if (!isAbstract() && !instance) { clazz = m_Class->getJavaClass(); @@ -265,20 +265,20 @@ JPPyObject JPMethod::invokeCallerSensitive(JPMethodMatch& match, JPPyObjectVecto //Proxy the call to // public static Object callMethod(Method method, Object obj, Object[] args) - jobject self = NULL; + jobject self = nullptr; size_t len = alen; if (!isStatic()) { JP_TRACE("Call instance"); len--; JPValue *selfObj = PyJPValue_getJavaSlot(arg[0]); - if (selfObj == NULL) + if (selfObj == nullptr) JP_RAISE(PyExc_RuntimeError, "Null object"); // GCOVR_EXCL_LINE self = selfObj->getJavaObject(); } // Convert arguments - jobjectArray ja = frame.NewObjectArray((jsize) len, context->_java_lang_Object->getJavaClass(), NULL); + jobjectArray ja = frame.NewObjectArray((jsize) len, context->_java_lang_Object->getJavaClass(), nullptr); for (jsize i = 0; i < (jsize) len; ++i) { JPClass *cls = m_ParameterTypes[i + match.m_Skip - match.m_Offset]; diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index 86facd85b..e858e1faa 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -52,7 +52,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch // Then make sure we don't hit the rare case that the hash was -1 by chance. // Then make sure it isn't variadic list match, as the hash of an opaque list // element can't be resolved without going through the resolution process. - if (m_LastCache.m_Hash == bestMatch.m_Hash && m_LastCache.m_Overload != 0 + if (m_LastCache.m_Hash == bestMatch.m_Hash && m_LastCache.m_Overload != nullptr && !m_LastCache.m_Overload->isVarArgs()) { bestMatch.m_Overload = m_LastCache.m_Overload; @@ -63,7 +63,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch return true; else // bad match so forget the overload. - bestMatch.m_Overload = 0; + bestMatch.m_Overload = nullptr; } // We need two copies of the match. One to hold the best match we have @@ -91,7 +91,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch continue; // If this is the first match then make it the best. - if (bestMatch.m_Overload == 0) + if (bestMatch.m_Overload == nullptr) { bestMatch = match; continue; diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index f5c73d498..028bd082e 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -123,7 +123,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter jvmLibrary = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); #endif // HPUX // GCOVR_EXCL_START - if (jvmLibrary == NULL) + if (jvmLibrary == nullptr) { JP_TRACE("null library"); JP_TRACE("errno", errno); @@ -157,7 +157,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter void* res = dlsym(jvmLibrary, name); JP_TRACE("Res", res); // GCOVR_EXCL_START - if (res == NULL) + if (res == nullptr) { JP_TRACE("errno", errno); std::stringstream msg; @@ -180,7 +180,7 @@ PLATFORM_ADAPTER* adapter; JPPlatformAdapter* JPPlatformAdapter::getAdapter() { - if (adapter == NULL) + if (adapter == nullptr) adapter = new PLATFORM_ADAPTER(); return adapter; } diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index c3e8f3502..604a5e425 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -34,15 +34,15 @@ bool JPPrimitiveType::isPrimitive() const PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) { - if (wrapper == NULL) + if (wrapper == nullptr) JP_RAISE(PyExc_SystemError, "bad wrapper"); Py_ssize_t n = Py_SIZE(tmp); if (n < 0) n = -n; auto *newobj = (PyLongObject *) wrapper->tp_alloc(wrapper, n); - if (newobj == NULL) - return NULL; + if (newobj == nullptr) + return nullptr; ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp); for (Py_ssize_t i = 0; i < n; i++) diff --git a/native/common/jp_proxy.cpp b/native/common/jp_proxy.cpp index 53a85bc2d..9f1bb0568 100644 --- a/native/common/jp_proxy.cpp +++ b/native/common/jp_proxy.cpp @@ -37,7 +37,7 @@ JPPyObject getArgs(JPContext* context, jlongArray parameterTypePtrs, { jobject obj = frame.GetObjectArrayElement(args, i); JPClass* type = frame.findClassForObject(obj); - if (type == NULL) + if (type == nullptr) type = reinterpret_cast (types[i]); JPValue val = type->getValueFromObject(JPValue(type, obj)); PyTuple_SetItem(pyargs.get(), i, type->convertToPythonObject(frame, val, false).keep()); @@ -71,7 +71,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( { env->functions->ThrowNew(env, context->m_RuntimeException.get(), "host reference is null"); - return NULL; + return nullptr; } // GCOVR_EXCL_STOP @@ -86,7 +86,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( { JP_TRACE("Callable not found"); JP_RAISE_METHOD_NOT_FOUND(cname); - return NULL; + return nullptr; } // Find the return type @@ -98,13 +98,13 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( JPPyObject pyargs = getArgs(context, parameterTypePtrs, args); JP_TRACE("Call Python"); - JPPyObject returnValue = JPPyObject::call(PyObject_Call(callable.get(), pyargs.get(), NULL)); + JPPyObject returnValue = JPPyObject::call(PyObject_Call(callable.get(), pyargs.get(), nullptr)); JP_TRACE("Handle return", Py_TYPE(returnValue.get())->tp_name); if (returnClass == context->_void) { JP_TRACE("Void return"); - return NULL; + return nullptr; } // This is a SystemError where the caller return null without @@ -148,7 +148,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( env->functions->ThrowNew(env, context->m_RuntimeException.get(), "unknown error occurred"); } - return NULL; + return nullptr; JP_TRACE_OUT; // GCOVR_EXCL_LINE } } @@ -162,7 +162,7 @@ JPProxy::JPProxy(JPContext* context, PyJPProxy* inst, JPClassList& intf) // Convert the interfaces to a Class[] jobjectArray ar = frame.NewObjectArray((int) intf.size(), - m_Context->_java_lang_Class->getJavaClass(), NULL); + m_Context->_java_lang_Class->getJavaClass(), nullptr); for (unsigned int i = 0; i < intf.size(); i++) { frame.SetObjectArrayElement(ar, i, intf[i]->getJavaClass()); @@ -177,7 +177,7 @@ JPProxy::JPProxy(JPContext* context, PyJPProxy* inst, JPClassList& intf) jobject proxy = frame.CallStaticObjectMethodA(context->m_ProxyClass.get(), context->m_Proxy_NewID, v); m_Proxy = JPObjectRef(m_Context, proxy); - m_Ref = NULL; + m_Ref = nullptr; JP_TRACE_OUT; } @@ -185,7 +185,7 @@ JPProxy::~JPProxy() { try { - if (m_Ref != NULL && m_Context->isRunning()) + if (m_Ref != nullptr && m_Context->isRunning()) { m_Context->getEnv()->DeleteWeakGlobalRef(m_Ref); } @@ -206,19 +206,19 @@ jvalue JPProxy::getProxy() JPContext* context = getContext(); JPJavaFrame frame = JPJavaFrame::inner(context); - jobject instance = NULL; - if (m_Ref != NULL) + jobject instance = nullptr; + if (m_Ref != nullptr) { instance = frame.NewLocalRef(m_Ref); } - if (instance == NULL) + if (instance == nullptr) { // Use the proxy to make an instance JP_TRACE("Create handler"); Py_INCREF(m_Instance); instance = frame.CallObjectMethodA(m_Proxy.get(), - m_Context->m_Proxy_NewInstanceID, 0); + m_Context->m_Proxy_NewInstanceID, nullptr); m_Ref = frame.NewWeakGlobalRef(instance); } jvalue out; diff --git a/native/common/jp_reference_queue.cpp b/native/common/jp_reference_queue.cpp index c5d204cba..134960096 100644 --- a/native/common/jp_reference_queue.cpp +++ b/native/common/jp_reference_queue.cpp @@ -21,8 +21,8 @@ #include "jp_gc.h" #include "pyjp.h" -static jobject s_ReferenceQueue = NULL; -static jmethodID s_ReferenceQueueRegisterMethod = NULL; +static jobject s_ReferenceQueue = nullptr; +static jmethodID s_ReferenceQueueRegisterMethod = nullptr; extern "C" { @@ -85,7 +85,7 @@ void JPReferenceQueue::registerRef(JPJavaFrame &frame, jobject obj, PyObject* ho // There are certain calls such as exception handling in which the // Python object is null. In those cases, we don't need to bind the Java // object lifespan and can just ignore it. - if (hostRef == 0) + if (hostRef == nullptr) return; // MATCH TO DECREF IN releasePython @@ -103,7 +103,7 @@ void JPReferenceQueue::registerRef(JPJavaFrame &frame, jobject obj, void* host, args[1].j = (jlong) host; args[2].j = (jlong) func; - if (s_ReferenceQueue == NULL) + if (s_ReferenceQueue == nullptr) JP_RAISE(PyExc_SystemError, "Memory queue not installed"); JP_TRACE("Register reference"); frame.CallVoidMethodA(s_ReferenceQueue, s_ReferenceQueueRegisterMethod, args); diff --git a/native/common/jp_shorttype.cpp b/native/common/jp_shorttype.cpp index 87609e225..696689fe1 100644 --- a/native/common/jp_shorttype.cpp +++ b/native/common/jp_shorttype.cpp @@ -43,7 +43,7 @@ JPValue JPShortType::getValueFromObject(const JPValue& obj) jvalue v; jobject jo = obj.getValue().l; auto* jb = (JPBoxedType*) frame.findClassForObject(jo); - field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, 0); + field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, nullptr); return JPValue(this, v); } @@ -58,7 +58,7 @@ class JPConversionJShort : public JPConversionJavaValue JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JPValue* value = match.getJavaSlot(); - if (value == NULL) + if (value == nullptr) return JPMatch::_none; match.type = JPMatch::_none; @@ -159,7 +159,7 @@ JPPyObject JPShortType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jm jvalue v; { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) field(v) = frame.CallShortMethodA(obj, mth, val); else field(v) = frame.CallNonvirtualShortMethodA(obj, clazz, mth, val); diff --git a/native/common/jp_stringtype.cpp b/native/common/jp_stringtype.cpp index 4ba607d6f..107d6bde4 100644 --- a/native/common/jp_stringtype.cpp +++ b/native/common/jp_stringtype.cpp @@ -39,7 +39,7 @@ JPPyObject JPStringType::convertToPythonObject(JPJavaFrame& frame, jvalue val, b if (!cast) { // This loses type - if (val.l == NULL) + if (val.l == nullptr) { return JPPyObject::getNone(); } diff --git a/native/common/jp_tracer.cpp b/native/common/jp_tracer.cpp index 0383bc738..0b7e73f88 100644 --- a/native/common/jp_tracer.cpp +++ b/native/common/jp_tracer.cpp @@ -44,7 +44,7 @@ template class lock_guard #endif static int jpype_traceLevel = 0; -static JPypeTracer* jpype_tracer_last = NULL; +static JPypeTracer* jpype_tracer_last = nullptr; std::mutex trace_lock; @@ -92,7 +92,7 @@ void JPypeTracer::traceIn(const char* msg, void* ref) std::lock_guard guard(trace_lock); jpype_indent(jpype_traceLevel); JPYPE_TRACING_OUTPUT << "> " << msg ; - if (ref != NULL) + if (ref != nullptr) JPYPE_TRACING_OUTPUT << " id=\"" << ref << "\""; JPYPE_TRACING_OUTPUT << endl; JPYPE_TRACING_OUTPUT.flush(); @@ -121,7 +121,7 @@ void JPypeTracer::traceJavaObject(const char* msg, const void* ref) { if ((_PyJPModule_trace & 4) == 0) return; - if (ref == (void*) 0) + if (ref == (void*) nullptr) { JPypeTracer::trace1("JNI", msg); return; @@ -147,7 +147,7 @@ void JPypeTracer::tracePythonObject(const char* msg, PyObject* ref) { if ((_PyJPModule_trace & 2) == 0) return; - if (ref != NULL) + if (ref != nullptr) { stringstream str; str << msg << " " << (void*) ref << " " << ref->ob_refcnt << " " << Py_TYPE(ref)->tp_name; @@ -169,13 +169,13 @@ void JPypeTracer::trace1(const char* source, const char* msg) std::lock_guard guard(trace_lock); string name = "unknown"; - if (jpype_tracer_last != NULL) + if (jpype_tracer_last != nullptr) name = jpype_tracer_last->m_Name; jpype_indent(jpype_traceLevel); - if (source != NULL) + if (source != nullptr) JPYPE_TRACING_OUTPUT << source << ": "; - if (source == NULL || (_PyJPModule_trace & 16) != 0) + if (source == nullptr || (_PyJPModule_trace & 16) != 0) JPYPE_TRACING_OUTPUT << name << ": "; JPYPE_TRACING_OUTPUT << msg << endl; JPYPE_TRACING_OUTPUT.flush(); @@ -189,7 +189,7 @@ void JPypeTracer::trace2(const char* msg1, const char* msg2) std::lock_guard guard(trace_lock); string name = "unknown"; - if (jpype_tracer_last != NULL) + if (jpype_tracer_last != nullptr) name = jpype_tracer_last->m_Name; jpype_indent(jpype_traceLevel); diff --git a/native/common/jp_typefactory.cpp b/native/common/jp_typefactory.cpp index 3e647deeb..70c9ec660 100644 --- a/native/common/jp_typefactory.cpp +++ b/native/common/jp_typefactory.cpp @@ -176,9 +176,9 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineObjectCla string className = frame.toStringUTF8(name); JP_TRACE(className); JPClassList interfaces; - if (interfacePtrs != NULL) + if (interfacePtrs != nullptr) convert(frame, interfacePtrs, interfaces); - JPClass* result = NULL; + JPClass* result = nullptr; if (!JPModifier::isSpecial(modifiers)) { // Create a normal class diff --git a/native/common/jp_typemanager.cpp b/native/common/jp_typemanager.cpp index fd594020a..a1636bee2 100644 --- a/native/common/jp_typemanager.cpp +++ b/native/common/jp_typemanager.cpp @@ -54,7 +54,7 @@ JPClass* JPTypeManager::findClassByName(const string& name) jvalue val; val.l = (jobject) frame.fromStringUTF8(name); auto* out = (JPClass*) (frame.CallLongMethodA(m_JavaTypeManager.get(), m_FindClassByName, &val)); - if (out == NULL) + if (out == nullptr) { stringstream err; err << "Class " << name << " is not found"; diff --git a/native/common/jp_value.cpp b/native/common/jp_value.cpp index d7bcbdbd3..2f0d830bc 100644 --- a/native/common/jp_value.cpp +++ b/native/common/jp_value.cpp @@ -19,7 +19,7 @@ jobject JPValue::getJavaObject() const { // This is all sanity check // GCOVR_EXCL_START - if (m_Class == NULL) + if (m_Class == nullptr) JP_RAISE(PyExc_RuntimeError, "Null class"); if (!m_Class->isPrimitive()) // GCOVR_EXCL_STOP diff --git a/native/common/jp_voidtype.cpp b/native/common/jp_voidtype.cpp index fcbe9cff3..f053e633a 100644 --- a/native/common/jp_voidtype.cpp +++ b/native/common/jp_voidtype.cpp @@ -38,7 +38,7 @@ JPPyObject JPVoidType::invoke(JPJavaFrame& frame, jobject obj, jclass clazz, jme { { JPPyCallRelease call; - if (clazz == NULL) + if (clazz == nullptr) frame.CallVoidMethodA(obj, mth, val); else frame.CallNonvirtualVoidMethodA(obj, clazz, mth, val); @@ -53,7 +53,7 @@ JPValue JPVoidType::getValueFromObject(const JPValue& obj) // This is needed if we call a caller sensitive method // and we get a return which is expected to be a void object JP_TRACE_IN("JPVoidType::getValueFromObject"); - return JPValue(this, (jobject) 0); + return JPValue(this, (jobject) nullptr); JP_TRACE_OUT; } @@ -119,7 +119,7 @@ void JPVoidType::releaseView(JPArrayView& view) const char* JPVoidType::getBufferFormat() { - return NULL; + return nullptr; } Py_ssize_t JPVoidType::getItemSize() @@ -151,7 +151,7 @@ jdouble JPVoidType::getAsDouble(jvalue v) PyObject *JPVoidType::newMultiArray(JPJavaFrame &frame, JPPyBuffer& view, int subs, int base, jobject dims) { - return NULL; + return nullptr; } // GCOVR_EXCL_STOP diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 6e253a8f0..6caae56a0 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -117,7 +117,7 @@ class JPPyObject */ static JPPyObject call(PyObject* obj); - JPPyObject() : m_PyObject(NULL) + JPPyObject() : m_PyObject(nullptr) { } @@ -142,7 +142,7 @@ class JPPyObject PyObject* keepNull() { PyObject *out = m_PyObject; - m_PyObject = NULL; + m_PyObject = nullptr; return out; } @@ -160,7 +160,7 @@ class JPPyObject */ bool isNull() const { - return m_PyObject == NULL; + return m_PyObject == nullptr; } /** diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index 1606487a4..7779af235 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -45,7 +45,7 @@ static void assertValid(PyObject *obj) JPPyObject JPPyObject::use(PyObject* obj) { JP_TRACE_PY("pyref use(inc)", obj); - if (obj != NULL) + if (obj != nullptr) { assertValid(obj); Py_INCREF(obj); @@ -62,7 +62,7 @@ JPPyObject JPPyObject::use(PyObject* obj) JPPyObject JPPyObject::accept(PyObject* obj) { JP_TRACE_PY("pyref new(accept)", obj); - if (obj == NULL) + if (obj == nullptr) PyErr_Clear(); return JPPyObject(obj); } @@ -106,7 +106,7 @@ JPPyObject::JPPyObject(PyObject* obj) JPPyObject::JPPyObject(const JPPyObject &self) : m_PyObject(self.m_PyObject) { - if (m_PyObject != NULL) + if (m_PyObject != nullptr) { incref(); JP_TRACE_PY("pyref copy ctor(inc)", m_PyObject); @@ -115,7 +115,7 @@ JPPyObject::JPPyObject(const JPPyObject &self) JPPyObject::~JPPyObject() { - if (m_PyObject != NULL) + if (m_PyObject != nullptr) { JP_TRACE_PY("pyref dtor(dec)", m_PyObject); decref(); @@ -129,13 +129,13 @@ JPPyObject& JPPyObject::operator=(const JPPyObject& self) { if (m_PyObject == self.m_PyObject) return *this; - if (m_PyObject != NULL) + if (m_PyObject != nullptr) { JP_TRACE_PY("pyref op=(dec)", m_PyObject); decref(); } m_PyObject = self.m_PyObject; - if (m_PyObject != NULL) + if (m_PyObject != nullptr) { incref(); JP_TRACE_PY("pyref op=(inc)", m_PyObject); @@ -147,13 +147,13 @@ PyObject* JPPyObject::keep() { // This can only happen if we have a fatal error in our reference // management system. It should never be triggered by the user. - if (m_PyObject == NULL) + if (m_PyObject == nullptr) { JP_RAISE(PyExc_SystemError, "Attempt to keep null reference"); // GCOVR_EXCL_LINE } JP_TRACE_PY("pyref keep ", m_PyObject); PyObject *out = m_PyObject; - m_PyObject = NULL; + m_PyObject = nullptr; return out; } @@ -167,7 +167,7 @@ void JPPyObject::decref() { assertValid(m_PyObject); Py_DECREF(m_PyObject); - m_PyObject = 0; + m_PyObject = nullptr; } JPPyObject JPPyObject::getNone() @@ -306,18 +306,18 @@ string JPPyString::asStringUTF8(PyObject* pyobj) if (PyUnicode_Check(pyobj)) { Py_ssize_t size = 0; - char *buffer = NULL; + char *buffer = nullptr; JPPyObject val = JPPyObject::call(PyUnicode_AsEncodedString(pyobj, "UTF-8", "strict")); PyBytes_AsStringAndSize(val.get(), &buffer, &size); JP_PY_CHECK(); - if (buffer != NULL) + if (buffer != nullptr) return string(buffer, size); else return string(); } else if (PyBytes_Check(pyobj)) { Py_ssize_t size = 0; - char *buffer = NULL; + char *buffer = nullptr; PyBytes_AsStringAndSize(pyobj, &buffer, &size); JP_PY_CHECK(); return string(buffer, size); @@ -359,7 +359,7 @@ JPPyObjectVector::JPPyObjectVector(PyObject* inst, PyObject* sequence) m_Instance = JPPyObject::use(inst); m_Sequence = JPPyObject::use(sequence); size_t n = 0; - if (sequence != NULL) + if (sequence != nullptr) n = PySequence_Size(m_Sequence.get()); m_Contents.resize(n + 1); for (size_t i = 0; i < n; ++i) @@ -373,7 +373,7 @@ bool JPPyErr::fetch(JPPyObject& exceptionClass, JPPyObject& exceptionValue, JPPy { PyObject *v1, *v2, *v3; PyErr_Fetch(&v1, &v2, &v3); - if (v1 == NULL && v2 == NULL && v3 == NULL) + if (v1 == nullptr && v2 == nullptr && v3 == nullptr) return false; exceptionClass = JPPyObject::accept(v1); exceptionValue = JPPyObject::accept(v2); @@ -429,13 +429,13 @@ char *JPPyBuffer::getBufferPtr(std::vector& indices) { char *pointer = (char*) m_View.buf; // No shape is just a 1D array - if (m_View.shape == NULL) + if (m_View.shape == nullptr) { return pointer; } // No strides is C contiguous ND array - if (m_View.strides == NULL) + if (m_View.strides == nullptr) { Py_ssize_t index = 0; for (int i = 0; i < m_View.ndim; i++) @@ -450,7 +450,7 @@ char *JPPyBuffer::getBufferPtr(std::vector& indices) for (int i = 0; i < m_View.ndim; i++) { pointer += m_View.strides[i] * indices[i]; - if (m_View.suboffsets != NULL && m_View.suboffsets[i] >= 0 ) + if (m_View.suboffsets != nullptr && m_View.suboffsets[i] >= 0 ) { pointer = *((char**) pointer) + m_View.suboffsets[i]; } @@ -487,7 +487,7 @@ void JPPyErrFrame::normalize() if (!PyExceptionInstance_Check(m_ExceptionValue.get())) { JPPyObject args = JPPyObject::call(PyTuple_Pack(1, m_ExceptionValue.get())); - m_ExceptionValue = JPPyObject::call(PyObject_Call(m_ExceptionClass.get(), args.get(), NULL)); + m_ExceptionValue = JPPyObject::call(PyObject_Call(m_ExceptionClass.get(), args.get(), nullptr)); PyException_SetTraceback(m_ExceptionValue.get(), m_ExceptionTrace.get()); JPPyErr::restore(m_ExceptionClass, m_ExceptionValue, m_ExceptionTrace); JPPyErr::fetch(m_ExceptionClass, m_ExceptionValue, m_ExceptionTrace); diff --git a/native/python/pyjp_array.cpp b/native/python/pyjp_array.cpp index 00bd027e1..6a75add1f 100644 --- a/native/python/pyjp_array.cpp +++ b/native/python/pyjp_array.cpp @@ -38,10 +38,10 @@ static PyObject *PyJPArray_new(PyTypeObject *type, PyObject *args, PyObject *kwa JP_PY_TRY("PyJPArray_new"); auto* self = (PyJPArray*) type->tp_alloc(type, 0); JP_PY_CHECK(); - self->m_Array = NULL; - self->m_View = NULL; + self->m_Array = nullptr; + self->m_View = nullptr; return (PyObject*) self; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static int PyJPArray_init(PyObject *self, PyObject *args, PyObject *kwargs) @@ -62,15 +62,15 @@ static int PyJPArray_init(PyObject *self, PyObject *args, PyObject *kwargs) JPClass *cls = PyJPClass_getJPClass((PyObject*) Py_TYPE(self)); auto* arrayClass = dynamic_cast (cls); - if (arrayClass == NULL) + if (arrayClass == nullptr) JP_RAISE(PyExc_TypeError, "Class must be array type"); JPValue *value = PyJPValue_getJavaSlot(v); - if (value != NULL) + if (value != nullptr) { auto* arrayClass2 = dynamic_cast (value->getClass()); - if (arrayClass2 == NULL) + if (arrayClass2 == nullptr) JP_RAISE(PyExc_TypeError, "Class must be array type"); if (arrayClass2 != arrayClass) JP_RAISE(PyExc_TypeError, "Array class mismatch"); @@ -121,14 +121,14 @@ static PyObject *PyJPArray_repr(PyJPArray *self) { JP_PY_TRY("PyJPArray_repr"); return PyUnicode_FromFormat("", Py_TYPE(self)->tp_name); - JP_PY_CATCH(0); + JP_PY_CATCH(nullptr); } static Py_ssize_t PyJPArray_len(PyJPArray *self) { JP_PY_TRY("PyJPArray_len"); PyJPModule_getContext(); - if (self->m_Array == NULL) + if (self->m_Array == nullptr) JP_RAISE(PyExc_ValueError, "Null array"); // GCOVR_EXCL_LINE return self->m_Array->getLength(); JP_PY_CATCH(-1); @@ -144,14 +144,14 @@ static PyObject *PyJPArray_getItem(PyJPArray *self, PyObject *item) JP_PY_TRY("PyJPArray_getArrayItem"); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - if (self->m_Array == NULL) + if (self->m_Array == nullptr) JP_RAISE(PyExc_ValueError, "Null array"); if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) - return NULL; // GCOVR_EXCL_LINE + return nullptr; // GCOVR_EXCL_LINE return self->m_Array->getItem((jsize) i).keep(); } @@ -161,7 +161,7 @@ static PyObject *PyJPArray_getItem(PyJPArray *self, PyObject *item) auto length = (Py_ssize_t) self->m_Array->getLength(); if (PySlice_Unpack(item, &start, &stop, &step) < 0) - return NULL; + return nullptr; slicelength = PySlice_AdjustIndices(length, &start, &stop, step); @@ -175,7 +175,7 @@ static PyObject *PyJPArray_getItem(PyJPArray *self, PyObject *item) JPPyObject tuple = JPPyObject::call(PyTuple_New(0)); - JPPyObject newArray = JPPyObject::claim(Py_TYPE(self)->tp_new(Py_TYPE(self), tuple.get(), NULL)); + JPPyObject newArray = JPPyObject::claim(Py_TYPE(self)->tp_new(Py_TYPE(self), tuple.get(), nullptr)); // Copy over the JPValue PyJPValue_assignJavaSlot(frame, newArray.get(), @@ -189,7 +189,7 @@ static PyObject *PyJPArray_getItem(PyJPArray *self, PyObject *item) } JP_RAISE(PyExc_TypeError, "Unsupported getItem type"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static int PyJPArray_assignSubscript(PyJPArray *self, PyObject *item, PyObject *value) @@ -199,9 +199,9 @@ static int PyJPArray_assignSubscript(PyJPArray *self, PyObject *item, PyObject * JPJavaFrame frame = JPJavaFrame::outer(context); // Verified with numpy that item deletion on immutable should // be ValueError - if ( value == NULL) + if ( value == nullptr) JP_RAISE(PyExc_ValueError, "item deletion not supported"); - if (self->m_Array == NULL) + if (self->m_Array == nullptr) JP_RAISE(PyExc_ValueError, "Null array"); // Watch out for self assignment @@ -251,14 +251,14 @@ static void PyJPArray_releaseBuffer(PyJPArray *self, Py_buffer *view) if (!context->isRunning()) { delete self->m_View; - self->m_View = NULL; + self->m_View = nullptr; return; } JPJavaFrame frame = JPJavaFrame::outer(context); - if (self->m_View == NULL || !self->m_View->unreference()) + if (self->m_View == nullptr || !self->m_View->unreference()) return; delete self->m_View; - self->m_View = NULL; + self->m_View = nullptr; JP_PY_CATCH(); // GCOVR_EXCL_LINE } @@ -267,7 +267,7 @@ int PyJPArray_getBuffer(PyJPArray *self, Py_buffer *view, int flags) JP_PY_TRY("PyJPArray_getBuffer"); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - if (self->m_Array == NULL) + if (self->m_Array == nullptr) JP_RAISE(PyExc_ValueError, "Null array"); if (!self->m_Array->getClass()->isPrimitiveArray()) @@ -299,7 +299,7 @@ int PyJPArray_getBuffer(PyJPArray *self, Py_buffer *view, int flags) return -1; } - if (result == NULL) + if (result == nullptr) { PyErr_SetString(PyExc_BufferError, "Java array buffer is not rectangular primitives"); return -1; @@ -308,7 +308,7 @@ int PyJPArray_getBuffer(PyJPArray *self, Py_buffer *view, int flags) // If it is rectangular so try to create a view try { - if (self->m_View == NULL) + if (self->m_View == nullptr) self->m_View = new JPArrayView(self->m_Array, result); JP_PY_CHECK(); self->m_View->reference(); @@ -316,15 +316,15 @@ int PyJPArray_getBuffer(PyJPArray *self, Py_buffer *view, int flags) // If strides are not requested and this is a slice then fail if ((flags & PyBUF_STRIDES) != PyBUF_STRIDES) - view->strides = NULL; + view->strides = nullptr; // If shape is not requested if ((flags & PyBUF_ND) != PyBUF_ND) - view->shape = NULL; + view->shape = nullptr; // If format is not requested if ((flags & PyBUF_FORMAT) != PyBUF_FORMAT) - view->format = NULL; + view->format = nullptr; // Okay all successful so reference the parent object view->obj = (PyObject*) self; @@ -349,7 +349,7 @@ int PyJPArrayPrimitive_getBuffer(PyJPArray *self, Py_buffer *view, int flags) JP_PY_TRY("PyJPArrayPrimitive_getBuffer"); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - if (self->m_Array == NULL) + if (self->m_Array == nullptr) JP_RAISE(PyExc_ValueError, "Null array"); try { @@ -359,7 +359,7 @@ int PyJPArrayPrimitive_getBuffer(PyJPArray *self, Py_buffer *view, int flags) return -1; } - if (self->m_View == NULL) + if (self->m_View == nullptr) { self->m_View = new JPArrayView(self->m_Array); } @@ -374,18 +374,18 @@ int PyJPArrayPrimitive_getBuffer(PyJPArray *self, Py_buffer *view, int flags) { if (view->strides[0] != view->itemsize) JP_RAISE(PyExc_BufferError, "slices required strides"); - view->strides = NULL; + view->strides = nullptr; } // If shape is not requested if ((flags & PyBUF_ND) != PyBUF_ND) { - view->shape = NULL; + view->shape = nullptr; } // If format is not requested if ((flags & PyBUF_FORMAT) != PyBUF_FORMAT) - view->format = NULL; + view->format = nullptr; // Okay all successful so reference the parent object view->obj = (PyObject*) self; @@ -410,12 +410,12 @@ static const char *length_doc = static PyMethodDef arrayMethods[] = { {"__getitem__", (PyCFunction) (&PyJPArray_getItem), METH_O | METH_COEXIST, ""}, - {NULL}, + {nullptr}, }; static PyGetSetDef arrayGetSets[] = { - {"length", (getter) (&PyJPArray_length), NULL, const_cast (length_doc)}, - {0} + {"length", (getter) (&PyJPArray_length), nullptr, const_cast (length_doc)}, + {nullptr} }; static PyType_Slot arraySlots[] = { @@ -436,7 +436,7 @@ static PyBufferProcs arrayBuffer = { (releasebufferproc) & PyJPArray_releaseBuffer }; -PyTypeObject *PyJPArray_Type = NULL; +PyTypeObject *PyJPArray_Type = nullptr; static PyType_Spec arraySpec = { "_jpype._JArray", sizeof (PyJPArray), @@ -454,7 +454,7 @@ static PyType_Slot arrayPrimSlots[] = { {0} }; -PyTypeObject *PyJPArrayPrimitive_Type = NULL; +PyTypeObject *PyJPArrayPrimitive_Type = nullptr; static PyType_Spec arrayPrimSpec = { "_jpype._JArrayPrimitive", 0, diff --git a/native/python/pyjp_buffer.cpp b/native/python/pyjp_buffer.cpp index e2f56e1f6..c944f20e8 100644 --- a/native/python/pyjp_buffer.cpp +++ b/native/python/pyjp_buffer.cpp @@ -41,7 +41,7 @@ static PyObject *PyJPBuffer_repr(PyJPBuffer *self) { JP_PY_TRY("PyJPBuffer_repr"); return PyUnicode_FromFormat("", Py_TYPE(self)->tp_name); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static void PyJPBuffer_releaseBuffer(PyJPBuffer *self, Py_buffer *view) @@ -55,7 +55,7 @@ int PyJPBuffer_getBuffer(PyJPBuffer *self, Py_buffer *view, int flags) JP_PY_TRY("PyJPBufferPrimitive_getBuffer"); JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - if (self->m_Buffer == NULL) + if (self->m_Buffer == nullptr) JP_RAISE(PyExc_ValueError, "Null buffer"); // GCOVR_EXCL_LINE try { @@ -80,18 +80,18 @@ int PyJPBuffer_getBuffer(PyJPBuffer *self, Py_buffer *view, int flags) { if (view->strides[0] != view->itemsize) JP_RAISE(PyExc_BufferError, "slices required strides"); - view->strides = NULL; + view->strides = nullptr; } // If shape is not requested if ((flags & PyBUF_ND) != PyBUF_ND) { - view->shape = NULL; + view->shape = nullptr; } // If format is not requested if ((flags & PyBUF_FORMAT) != PyBUF_FORMAT) - view->format = NULL; + view->format = nullptr; // Okay all successful so reference the parent object view->obj = (PyObject*) self; @@ -121,7 +121,7 @@ static PyBufferProcs directBuffer = { (releasebufferproc) & PyJPBuffer_releaseBuffer }; -PyTypeObject *PyJPBuffer_Type = NULL; +PyTypeObject *PyJPBuffer_Type = nullptr; static PyType_Spec bufferSpec = { "_jpype._JBuffer", sizeof (PyJPBuffer), diff --git a/native/python/pyjp_char.cpp b/native/python/pyjp_char.cpp index 03dc3f799..b36eca8be 100644 --- a/native/python/pyjp_char.cpp +++ b/native/python/pyjp_char.cpp @@ -23,7 +23,7 @@ extern "C" { #endif -PyTypeObject *PyJPChar_Type = NULL; +PyTypeObject *PyJPChar_Type = nullptr; struct PyJPChar { @@ -54,10 +54,10 @@ static Py_UCS4 ord(PyObject *c) static int isNull(JPValue *javaSlot) { - if (javaSlot != NULL ) + if (javaSlot != nullptr ) { JPClass *cls = javaSlot->getClass(); - if (cls->isPrimitive() || javaSlot->getValue().l != NULL) + if (cls->isPrimitive() || javaSlot->getValue().l != nullptr) return 0; } return 1; @@ -66,7 +66,7 @@ static int isNull(JPValue *javaSlot) static PyObject* notSupported() { PyErr_SetString(PyExc_TypeError, "unsupported operation"); - return 0; + return nullptr; } static int assertNotNull(JPValue *javaSlot) @@ -80,8 +80,8 @@ static int assertNotNull(JPValue *javaSlot) PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) { auto *self = (PyJPChar*) PyJPValue_alloc(type, 0); - if (self == 0) - return 0; + if (self == nullptr) + return nullptr; self->m_Data[0] = 0; self->m_Data[1] = 0; self->m_Data[2] = 0; @@ -109,8 +109,8 @@ PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) data[0] = p; data[1] = 0; _PyUnicode_WSTR_LENGTH(self) = 0; - _PyUnicode_WSTR(self) = NULL; - self->m_Obj.utf8 = NULL; + _PyUnicode_WSTR(self) = nullptr; + self->m_Obj.utf8 = nullptr; self->m_Obj.utf8_length = 0; } else { @@ -126,9 +126,9 @@ PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) } else { _PyUnicode_WSTR_LENGTH(self) = 0; - _PyUnicode_WSTR(self) = NULL; + _PyUnicode_WSTR(self) = nullptr; } - self->m_Obj.utf8 = NULL; + self->m_Obj.utf8 = nullptr; self->m_Obj.utf8_length = 0; } return (PyObject*) self; @@ -142,7 +142,7 @@ Py_UCS2 fromJPValue(const JPValue & value) if (cls->isPrimitive()) return (Py_UCS2) (value.getValue().c); JPPrimitiveType* pcls = ((JPBoxedType*) cls)->getPrimitive(); - if (value.getValue().l == 0) + if (value.getValue().l == nullptr) return (Py_UCS2) - 1; else return (Py_UCS2) (pcls->getValueFromObject(value).getValue().c); @@ -171,10 +171,10 @@ static PyObject * PyJPChar_new(PyTypeObject *type, PyObject *pyargs, PyObject * JP_PY_TRY("PyJPChar_new"); // Get the Java class from the type. JPClass *cls = PyJPClass_getJPClass((PyObject*) type); - if (cls == NULL) + if (cls == nullptr) { // GCOVR_EXCL_START PyErr_SetString(PyExc_TypeError, "Java class type is incorrect"); - return 0; + return nullptr; } // GCOVR_EXCL_STOP JPContext *context = PyJPModule_getContext(); @@ -184,7 +184,7 @@ static PyObject * PyJPChar_new(PyTypeObject *type, PyObject *pyargs, PyObject * if (PyTuple_Size(pyargs) != 1) { PyErr_SetString(PyExc_TypeError, "Java chars require one argument"); - return 0; + return nullptr; } JPValue jv; @@ -210,14 +210,14 @@ static PyObject * PyJPChar_new(PyTypeObject *type, PyObject *pyargs, PyObject * { // This is not strictly true as we can cast a float to a char PyErr_SetString(PyExc_TypeError, "Java require index or str with length 1"); - return 0; + return nullptr; } PyObject *self = PyJPChar_Create(type, fromJPValue(jv)); JP_PY_CHECK(); PyJPValue_assignJavaSlot(frame, self, jv); return self; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_str(PyJPChar *self) @@ -225,16 +225,16 @@ static PyObject *PyJPChar_str(PyJPChar *self) JP_PY_TRY("PyJPChar_str"); PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); - if (javaSlot == NULL) + if (javaSlot == nullptr) { // GCOVR_EXCL_START // A slot is required PyErr_SetString(PyExc_TypeError, "Java slot is not set on Java char"); - return 0; + return nullptr; } // GCOVR_EXCL_STOP if (isNull(javaSlot)) return JPPyString::fromStringUTF8("None").keep(); return PyUnicode_FromOrdinal(fromJPChar(self)); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_repr(PyJPChar *self) @@ -242,16 +242,16 @@ static PyObject *PyJPChar_repr(PyJPChar *self) JP_PY_TRY("PyJPChar_repr"); PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); - if (javaSlot == NULL) + if (javaSlot == nullptr) { // GCOVR_EXCL_START // A slot is required PyErr_SetString(PyExc_TypeError, "Java slot is not set on Java char"); - return 0; + return nullptr; } // GCOVR_EXCL_STOP if (isNull(javaSlot)) return JPPyString::fromStringUTF8("None").keep(); return PyUnicode_Type.tp_repr((PyObject*) self); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_index(PyJPChar *self) @@ -260,9 +260,9 @@ static PyObject *PyJPChar_index(PyJPChar *self) PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); if (assertNotNull(javaSlot)) - return 0; + return nullptr; return PyLong_FromLong(fromJPChar(self)); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_float(PyJPChar *self) @@ -271,9 +271,9 @@ static PyObject *PyJPChar_float(PyJPChar *self) PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); if (assertNotNull(javaSlot)) - return 0; + return nullptr; return PyFloat_FromDouble(fromJPChar(self)); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_abs(PyJPChar *self) @@ -282,12 +282,12 @@ static PyObject *PyJPChar_abs(PyJPChar *self) PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); if (assertNotNull(javaSlot)) - return 0; + return nullptr; // Promote to int as per Java rules JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar(self))); return PyLong_Type.tp_as_number->nb_absolute(v.get()); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static Py_ssize_t PyJPChar_len(PyJPChar *self) @@ -305,28 +305,28 @@ static PyObject *apply(PyObject *first, PyObject *second, PyObject* (*func)(PyOb { JPValue *slot0 = PyJPValue_getJavaSlot(first); JPValue *slot1 = PyJPValue_getJavaSlot(second); - if (slot0 != NULL && slot1 != NULL) + if (slot0 != nullptr && slot1 != nullptr) { if (assertNotNull(slot0)) - return 0; + return nullptr; if (assertNotNull(slot1)) - return 0; + return nullptr; JPPyObject v1 = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)first))); JPPyObject v2 = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)second))); return func(v1.get(), v2.get()); } - else if (slot0 != NULL) + else if (slot0 != nullptr) { if (assertNotNull(slot0)) - return 0; + return nullptr; // Promote to int as per Java rules JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)first))); return func(v.get(), second); } - else if (slot1 != NULL) + else if (slot1 != nullptr) { if (assertNotNull(slot1)) - return 0; + return nullptr; // Promote to int as per Java rules JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)second))); return func(first, v.get()); @@ -340,7 +340,7 @@ static PyObject *PyJPChar_and(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_and"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_And); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_or(PyObject *first, PyObject *second) @@ -348,7 +348,7 @@ static PyObject *PyJPChar_or(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_or"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Or); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_xor(PyObject *first, PyObject *second) @@ -356,7 +356,7 @@ static PyObject *PyJPChar_xor(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_xor"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Xor); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_add(PyObject *first, PyObject *second) @@ -365,20 +365,20 @@ static PyObject *PyJPChar_add(PyObject *first, PyObject *second) PyJPModule_getContext(); // Check that JVM is running JPValue *slot0 = PyJPValue_getJavaSlot(first); JPValue *slot1 = PyJPValue_getJavaSlot(second); - if (slot1 != NULL && slot0 != NULL) + if (slot1 != nullptr && slot0 != nullptr) { if (assertNotNull(slot0)) - return 0; + return nullptr; if (assertNotNull(slot1)) - return 0; + return nullptr; JPPyObject v1 = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)first))); JPPyObject v2 = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)second))); return PyNumber_Add(v1.get(), v2.get()); } - else if (slot0 != NULL) + else if (slot0 != nullptr) { if (assertNotNull(slot0)) - return 0; + return nullptr; if (PyUnicode_Check(second)) return PyUnicode_Concat(first, second); @@ -386,10 +386,10 @@ static PyObject *PyJPChar_add(PyObject *first, PyObject *second) JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*)first))); return PyNumber_Add(v.get(), second); } - else if (slot1 != NULL) + else if (slot1 != nullptr) { if (assertNotNull(slot1)) - return 0; + return nullptr; if (PyUnicode_Check(first)) return PyUnicode_Concat(first, second); @@ -398,7 +398,7 @@ static PyObject *PyJPChar_add(PyObject *first, PyObject *second) return PyNumber_Add(first, v.get()); } return notSupported(); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } @@ -407,7 +407,7 @@ static PyObject *PyJPChar_subtract(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_subtract"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Subtract); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_mult(PyObject *first, PyObject *second) @@ -415,7 +415,7 @@ static PyObject *PyJPChar_mult(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_mult"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Multiply); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_rshift(PyObject *first, PyObject *second) @@ -423,7 +423,7 @@ static PyObject *PyJPChar_rshift(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_rshift"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Rshift); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_lshift(PyObject *first, PyObject *second) @@ -431,7 +431,7 @@ static PyObject *PyJPChar_lshift(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_lshift"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Lshift); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_floordiv(PyObject *first, PyObject *second) @@ -439,7 +439,7 @@ static PyObject *PyJPChar_floordiv(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_floordiv"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_FloorDivide); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_divmod(PyObject *first, PyObject *second) @@ -447,7 +447,7 @@ static PyObject *PyJPChar_divmod(PyObject *first, PyObject *second) JP_PY_TRY("PyJPChar_divmod"); PyJPModule_getContext(); // Check that JVM is running return apply(first, second, PyNumber_Divmod); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_neg(PyJPChar *self) @@ -456,11 +456,11 @@ static PyObject *PyJPChar_neg(PyJPChar *self) PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); if (assertNotNull(javaSlot)) - return 0; + return nullptr; // Promote to int as per Java rules JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar(self))); return PyNumber_Negative(v.get()); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_pos(PyJPChar *self) @@ -469,11 +469,11 @@ static PyObject *PyJPChar_pos(PyJPChar *self) PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); if (assertNotNull(javaSlot)) - return 0; + return nullptr; // Promote to int as per Java rules JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar(self))); return PyNumber_Positive(v.get()); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPChar_inv(PyJPChar *self) @@ -482,11 +482,11 @@ static PyObject *PyJPChar_inv(PyJPChar *self) PyJPModule_getContext(); // Check that JVM is running JPValue *javaSlot = PyJPValue_getJavaSlot((PyObject*) self); if (assertNotNull(javaSlot)) - return 0; + return nullptr; // Promote to int as per Java rules JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar(self))); return PyNumber_Invert(v.get()); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPJChar_compare(PyObject *self, PyObject *other, int op) @@ -497,7 +497,7 @@ static PyObject *PyJPJChar_compare(PyObject *self, PyObject *other, int op) JPValue *javaSlot0 = PyJPValue_getJavaSlot(self); if (isNull(javaSlot0)) { - if (javaSlot1 != NULL && isNull(javaSlot1)) + if (javaSlot1 != nullptr && isNull(javaSlot1)) other = Py_None; if (op == Py_EQ) return PyBool_FromLong(other == Py_None ); @@ -508,7 +508,7 @@ static PyObject *PyJPJChar_compare(PyObject *self, PyObject *other, int op) return out; JP_RAISE_PYTHON(); } - if (javaSlot1 != NULL && isNull(javaSlot1)) + if (javaSlot1 != nullptr && isNull(javaSlot1)) return PyBool_FromLong(op == Py_NE); if (PyUnicode_Check(other)) @@ -531,7 +531,7 @@ static PyObject *PyJPJChar_compare(PyObject *self, PyObject *other, int op) JPPyObject v = JPPyObject::call(PyLong_FromLong(fromJPChar((PyJPChar*) self))); return PyLong_Type.tp_richcompare(v.get(), other, op); } - if (javaSlot1 != NULL) + if (javaSlot1 != nullptr) { // char <=> object // object <=> char @@ -551,7 +551,7 @@ static PyObject *PyJPJChar_compare(PyObject *self, PyObject *other, int op) PyObject *out = Py_NotImplemented; Py_INCREF(out); return out; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static Py_hash_t PyJPChar_hash(PyObject *self) @@ -579,12 +579,12 @@ static int PyJPChar_bool(PyJPChar *self) static PyMethodDef charMethods[] = { // {"thing", (PyCFunction) PyJPMethod_matchReport, METH_VARARGS, ""}, - {NULL}, + {nullptr}, }; struct PyGetSetDef charGetSet[] = { // {"thing", (getter) PyJPMethod_getSelf, NULL, NULL, NULL}, - {NULL}, + {nullptr}, }; static PyType_Slot charSlots[] = { diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index 9d72cc321..484bb014f 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -34,7 +34,7 @@ struct PyJPClass PyObject *m_Doc; } ; -PyObject* PyJPClassMagic = NULL; +PyObject* PyJPClassMagic = nullptr; #ifdef __cplusplus extern "C" @@ -73,7 +73,7 @@ PyObject *PyJPClass_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *item = PyTuple_GetItem(bases, i); JPClass *cls = PyJPClass_getJPClass(item); - if (cls != NULL && cls->isFinal()) + if (cls != nullptr && cls->isFinal()) { PyErr_Format(PyExc_TypeError, "Cannot extend final class '%s'", ((PyTypeObject*) item)->tp_name); @@ -82,28 +82,28 @@ PyObject *PyJPClass_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } int magic = 0; - if (kwargs == PyJPClassMagic || (kwargs != NULL && PyDict_GetItemString(kwargs, "internal") != 0)) + if (kwargs == PyJPClassMagic || (kwargs != nullptr && PyDict_GetItemString(kwargs, "internal") != nullptr)) { magic = 1; - kwargs = NULL; + kwargs = nullptr; } if (magic == 0) { PyErr_Format(PyExc_TypeError, "Java classes cannot be extended in Python"); - return 0; + return nullptr; } auto *typenew = (PyTypeObject*) PyType_Type.tp_new(type, args, kwargs); // GCOVR_EXCL_START // Sanity checks. Not testable - if (typenew == 0) - return NULL; - if (typenew->tp_finalize != NULL && typenew->tp_finalize != (destructor) PyJPValue_finalize) + if (typenew == nullptr) + return nullptr; + if (typenew->tp_finalize != nullptr && typenew->tp_finalize != (destructor) PyJPValue_finalize) { Py_DECREF(typenew); PyErr_SetString(PyExc_TypeError, "finalizer conflict"); - return NULL; + return nullptr; } // This sanity check is trigger if the user attempts to build their own @@ -113,7 +113,7 @@ PyObject *PyJPClass_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { Py_DECREF(typenew); PyErr_SetString(PyExc_TypeError, "alloc conflict"); - return NULL; + return nullptr; } // GCOVR_EXCL_STOP @@ -124,9 +124,9 @@ PyObject *PyJPClass_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { typenew->tp_new = PyJPException_Type->tp_new; } - ((PyJPClass*) typenew)->m_Doc = NULL; + ((PyJPClass*) typenew)->m_Doc = nullptr; return (PyObject*) typenew; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject* examine(PyObject *module, PyObject *other); @@ -140,14 +140,14 @@ PyObject* PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) type->tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE; type->tp_name = spec->name; const char *s = strrchr(spec->name, '.'); - if (s == NULL) + if (s == nullptr) s = spec->name; else s++; heap->ht_qualname = PyUnicode_FromString(s); heap->ht_name = heap->ht_qualname; Py_INCREF(heap->ht_name); - if (bases == NULL) + if (bases == nullptr) type->tp_bases = PyTuple_Pack(1, (PyObject*) & PyBaseObject_Type); else { @@ -288,8 +288,8 @@ PyObject* PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) // safety check to make sure we implemented all properly. This error should // never happen in production code. if (PyType_IS_GC(type) && ( - type->tp_traverse==NULL || - type->tp_clear==NULL)) + type->tp_traverse==nullptr || + type->tp_clear==nullptr)) { PyErr_Format(PyExc_TypeError, "GC requirements failed for %s", spec->name); JP_RAISE_PYTHON(); @@ -297,7 +297,7 @@ PyObject* PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) PyType_Ready(type); PyDict_SetItemString(type->tp_dict, "__module__", PyUnicode_FromString("_jpype")); return (PyObject*) type; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } int PyJPClass_init(PyObject *self, PyObject *args, PyObject *kwargs) @@ -307,9 +307,9 @@ int PyJPClass_init(PyObject *self, PyObject *args, PyObject *kwargs) return 0; // Set the host object - PyObject *name = NULL; - PyObject *bases = NULL; - PyObject *members = NULL; + PyObject *name = nullptr; + PyObject *bases = nullptr; + PyObject *members = nullptr; if (!PyArg_ParseTuple(args, "OOO", &name, &bases, &members)) return -1; @@ -329,7 +329,7 @@ int PyJPClass_init(PyObject *self, PyObject *args, PyObject *kwargs) } // Call the type init - int rc = PyType_Type.tp_init(self, args, NULL); + int rc = PyType_Type.tp_init(self, args, nullptr); if (rc == -1) return rc; // GCOVR_EXCL_LINE no clue how to trigger this one @@ -380,11 +380,11 @@ PyObject* PyJPClass_mro(PyTypeObject *self) if (PySequence_Contains(((PyTypeObject*) * iter)->tp_bases, front)) { bases.push_back(front); - front = NULL; + front = nullptr; break; } } - if (front != NULL) + if (front != nullptr) { out.push_back(front); auto* next = (PyObject*) ((PyTypeObject*) front)->tp_base; @@ -415,13 +415,13 @@ PyObject *PyJPClass_getattro(PyObject *obj, PyObject *name) PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", Py_TYPE(name)->tp_name); - return NULL; + return nullptr; } // Private members are accessed directly PyObject* pyattr = PyType_Type.tp_getattro(obj, name); - if (pyattr == NULL) - return NULL; + if (pyattr == nullptr) + return nullptr; JPPyObject attr = JPPyObject::claim(pyattr); // Private members go regardless @@ -438,8 +438,8 @@ PyObject *PyJPClass_getattro(PyObject *obj, PyObject *name) const char *name_str = PyUnicode_AsUTF8(name); PyErr_Format(PyExc_AttributeError, "Field '%s' is static", name_str); - return NULL; - JP_PY_CATCH(NULL); + return nullptr; + JP_PY_CATCH(nullptr); } int PyJPClass_setattro(PyObject *self, PyObject *attr_name, PyObject *v) @@ -467,7 +467,7 @@ int PyJPClass_setattro(PyObject *self, PyObject *attr_name, PyObject *v) } descrsetfunc desc = Py_TYPE(f.get())->tp_descr_set; - if (desc != NULL) + if (desc != nullptr) return desc(f.get(), self, v); // Not a descriptor @@ -502,11 +502,11 @@ PyObject* PyJPClass_subclasscheck(PyTypeObject *type, PyTypeObject *test) // Check for class inheritance first JPClass *testClass = PyJPClass_getJPClass((PyObject*) test); JPClass *typeClass = PyJPClass_getJPClass((PyObject*) type); - if (testClass == NULL) + if (testClass == nullptr) Py_RETURN_FALSE; if (testClass == typeClass) Py_RETURN_TRUE; - if (typeClass != NULL) + if (typeClass != nullptr) { if (typeClass->isPrimitive()) Py_RETURN_FALSE; @@ -532,7 +532,7 @@ PyObject* PyJPClass_subclasscheck(PyTypeObject *type, PyTypeObject *test) Py_RETURN_TRUE; } Py_RETURN_FALSE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPClass_class(PyObject *self, PyObject *closure) @@ -541,13 +541,13 @@ static PyObject *PyJPClass_class(PyObject *self, PyObject *closure) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue* javaSlot = PyJPValue_getJavaSlot(self); - if (javaSlot == NULL) + if (javaSlot == nullptr) { PyErr_SetString(PyExc_AttributeError, "Java slot is null"); - return NULL; + return nullptr; } return javaSlot->getClass()->convertToPythonObject(frame, javaSlot->getValue(), false).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static int PyJPClass_setClass(PyObject *self, PyObject *type, PyObject *closure) @@ -556,7 +556,7 @@ static int PyJPClass_setClass(PyObject *self, PyObject *type, PyObject *closure) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue* javaSlot = PyJPValue_getJavaSlot(type); - if (javaSlot == NULL || javaSlot->getClass() != context->_java_lang_Class) + if (javaSlot == nullptr || javaSlot->getClass() != context->_java_lang_Class) { PyErr_SetString(PyExc_TypeError, "Java class instance is required"); return -1; @@ -570,7 +570,7 @@ static int PyJPClass_setClass(PyObject *self, PyObject *type, PyObject *closure) JPClass* cls = frame.findClass((jclass) javaSlot->getJavaObject()); JP_TRACE("Set host", cls, javaSlot->getClass()->getCanonicalName().c_str()); - if (cls->getHost() == NULL) + if (cls->getHost() == nullptr) cls->setHost(self); ((PyJPClass*) self)->m_Class = cls; return 0; @@ -582,7 +582,7 @@ static PyObject *PyJPClass_hints(PyJPClass *self, PyObject *closure) JP_PY_TRY("PyJPClass_hints"); PyJPModule_getContext(); JPPyObject hints = JPPyObject::use(self->m_Class->getHints()); - if (hints.get() == NULL) + if (hints.get() == nullptr) Py_RETURN_NONE; // GCOVR_EXCL_LINE only triggered if JClassPost failed if (PyObject_HasAttrString((PyObject*) self, "returns") == 1) @@ -610,7 +610,7 @@ static PyObject *PyJPClass_hints(PyJPClass *self, PyObject *closure) PyObject_SetAttrString(hints.get(), "none", none.get()); PyObject_SetAttrString(hints.get(), "attributes", attribs.get()); return hints.keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static int PyJPClass_setHints(PyObject *self, PyObject *value, PyObject *closure) @@ -619,7 +619,7 @@ static int PyJPClass_setHints(PyObject *self, PyObject *value, PyObject *closure PyJPModule_getContext(); auto *cls = (PyJPClass*) self; PyObject *hints = cls->m_Class->getHints(); - if (hints != NULL) + if (hints != nullptr) { PyErr_SetString(PyExc_AttributeError, "_hints can't be set"); return -1; @@ -637,7 +637,7 @@ PyObject* PyJPClass_instancecheck(PyTypeObject *self, PyObject *test) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPClass *testClass = PyJPClass_getJPClass((PyObject*) test); - return PyBool_FromLong(testClass != NULL && testClass->isInterface()); + return PyBool_FromLong(testClass != nullptr && testClass->isInterface()); } if ((PyObject*) self == _JException) { @@ -664,7 +664,7 @@ static PyObject *PyJPClass_canCast(PyJPClass *self, PyObject *other) // Report to user return PyBool_FromLong(match.type == JPMatch::_exact || match.type == JPMatch::_implicit); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } // Added for auditing @@ -692,7 +692,7 @@ static PyObject *PyJPClass_canConvertToJava(PyJPClass *self, PyObject *other) // Not sure how this could happen Py_RETURN_NONE; // GCOVR_EXCL_LINE - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } // Return true if the slice is all indices @@ -732,7 +732,7 @@ static PyObject *PyJPClass_array(PyJPClass *self, PyObject *item) return PyJPClass_create(frame, cls).keep(); } PyErr_Format(PyExc_TypeError, "Bad array specification on slice"); - return NULL; + return nullptr; } if (PyTuple_Check(item)) @@ -761,7 +761,7 @@ static PyObject *PyJPClass_array(PyJPClass *self, PyObject *item) if (defined + undefined != dims) { PyErr_SetString(PyExc_TypeError, "Invalid array definition"); - return NULL; + return nullptr; } // Get the type @@ -789,7 +789,7 @@ static PyObject *PyJPClass_array(PyJPClass *self, PyObject *item) } PyErr_Format(PyExc_TypeError, "Bad array specification"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) @@ -801,7 +801,7 @@ static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) JPValue *val = PyJPValue_getJavaSlot(other); // Cast on non-Java - if (val == NULL || val->getClass()->isPrimitive()) + if (val == nullptr || val->getClass()->isPrimitive()) { JPMatch match(&frame, other); type->findJavaConversion(match); @@ -813,7 +813,7 @@ static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) Py_TYPE(other)->tp_name, type->getCanonicalName().c_str() ); - return NULL; + return nullptr; } jvalue v = match.convert(); return type->convertToPythonObject(frame, v, true).keep(); @@ -822,14 +822,14 @@ static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) // Cast on java object // if (!type->isSubTypeOf(val->getClass())) jobject obj = val->getJavaObject(); - if (obj == NULL) + if (obj == nullptr) { jvalue v; - v.l = NULL; + v.l = nullptr; return type->convertToPythonObject(frame, v, true).keep(); } JPClass *otherClass = frame.findClassForObject(obj); - if (otherClass == NULL) + if (otherClass == nullptr) { return type->convertToPythonObject(frame, val->getValue(), true).keep(); } @@ -841,7 +841,7 @@ static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) otherClass->getCanonicalName().c_str(), type->getCanonicalName().c_str() ); - return NULL; + return nullptr; } // Special case. If the otherClass is an array and the array is @@ -861,13 +861,13 @@ static PyObject *PyJPClass_cast(PyJPClass *self, PyObject *other) return type->convertToPythonObject(frame, val->getValue(), true).keep(); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPClass_castEq(PyJPClass *self, PyObject *other) { PyErr_Format(PyExc_TypeError, "Invalid operation"); - return NULL; + return nullptr; } // Added for auditing @@ -888,13 +888,13 @@ static PyObject *PyJPClass_convertToJava(PyJPClass *self, PyObject *other) if (match.type == JPMatch::_none) { PyErr_SetString(PyExc_TypeError, "Unable to create an instance."); - return 0; + return nullptr; } // Otherwise give back a PyJPValue jvalue v = match.convert(); return cls->convertToPythonObject(frame, v, true).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPClass_repr(PyJPClass *self) @@ -902,7 +902,7 @@ static PyObject *PyJPClass_repr(PyJPClass *self) JP_PY_TRY("PyJPClass_repr"); string name = ((PyTypeObject*) self)->tp_name; return PyUnicode_FromFormat("", name.c_str()); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPClass_getDoc(PyJPClass *self, void *ctxt) @@ -921,11 +921,11 @@ static PyObject *PyJPClass_getDoc(PyJPClass *self, void *ctxt) JP_TRACE("Pack arguments"); JPPyObject args = JPPyObject::call(PyTuple_Pack(1, self)); JP_TRACE("Call Python"); - self->m_Doc = PyObject_Call(_JClassDoc, args.get(), NULL); + self->m_Doc = PyObject_Call(_JClassDoc, args.get(), nullptr); Py_XINCREF(self->m_Doc); return self->m_Doc; } - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } int PyJPClass_setDoc(PyJPClass *self, PyObject *obj, void *ctxt) @@ -941,14 +941,14 @@ int PyJPClass_setDoc(PyJPClass *self, PyObject *obj, void *ctxt) PyObject* PyJPClass_customize(PyJPClass *self, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPClass_customize"); - PyObject *name = NULL; - PyObject *value = NULL; + PyObject *name = nullptr; + PyObject *value = nullptr; if (!PyArg_ParseTuple(args, "OO", &name, &value)) - return NULL; + return nullptr; if (PyType_Type.tp_setattro((PyObject*) self, name, value) == -1) - return NULL; + return nullptr; Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyMethodDef classMethods[] = { @@ -961,14 +961,14 @@ static PyMethodDef classMethods[] = { {"_canCast", (PyCFunction) PyJPClass_canCast, METH_O, ""}, {"__getitem__", (PyCFunction) PyJPClass_array, METH_O | METH_COEXIST, ""}, {"_customize", (PyCFunction) PyJPClass_customize, METH_VARARGS, ""}, - {NULL}, + {nullptr}, }; static PyGetSetDef classGetSets[] = { {"class_", (getter) PyJPClass_class, (setter) PyJPClass_setClass, ""}, {"_hints", (getter) PyJPClass_hints, (setter) PyJPClass_setHints, ""}, - {"__doc__", (getter) PyJPClass_getDoc, (setter) PyJPClass_setDoc, NULL, NULL}, - {0} + {"__doc__", (getter) PyJPClass_getDoc, (setter) PyJPClass_setDoc, nullptr, nullptr}, + {nullptr} }; static PyType_Slot classSlots[] = { @@ -990,7 +990,7 @@ static PyType_Slot classSlots[] = { {0} }; -PyTypeObject* PyJPClass_Type = NULL; +PyTypeObject* PyJPClass_Type = nullptr; static PyType_Spec classSpec = { "_jpype._JClass", sizeof (PyJPClass), @@ -1017,21 +1017,21 @@ JPClass* PyJPClass_getJPClass(PyObject* obj) { try { - if (obj == NULL) - return NULL; + if (obj == nullptr) + return nullptr; if (PyJPClass_Check(obj)) return ((PyJPClass*) obj)->m_Class; JPValue* javaSlot = PyJPValue_getJavaSlot(obj); - if (javaSlot == NULL) - return NULL; + if (javaSlot == nullptr) + return nullptr; JPClass *cls = javaSlot->getClass(); if (cls != cls->getContext()->_java_lang_Class) - return NULL; + return nullptr; JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); return frame.findClass((jclass) javaSlot->getJavaObject()); } catch (...) // GCOVR_EXCL_LINE { - return NULL; // GCOVR_EXCL_LINE + return nullptr; // GCOVR_EXCL_LINE } } @@ -1083,13 +1083,13 @@ JPPyObject PyJPClass_getBases(JPJavaFrame &frame, JPClass* cls) } else if (cls->getCanonicalName() == "java.lang.Comparable") { baseType = JPPyObject::use((PyObject*) PyJPComparable_Type); - } else if (super == NULL) + } else if (super == nullptr) { baseType = JPPyObject::use((PyObject*) PyJPObject_Type); } const JPClassList& baseItf = cls->getInterfaces(); - size_t count = baseItf.size() + (!baseType.isNull() ? 1 : 0) + (super != NULL ? 1 : 0); + size_t count = baseItf.size() + (!baseType.isNull() ? 1 : 0) + (super != nullptr ? 1 : 0); // Pack into a tuple JPPyObject result = JPPyObject::call(PyList_New(count)); @@ -1098,7 +1098,7 @@ JPPyObject PyJPClass_getBases(JPJavaFrame &frame, JPClass* cls) { PyList_SetItem(result.get(), i, PyJPClass_create(frame, baseItf[i]).keep()); } - if (super != NULL) + if (super != nullptr) { PyList_SetItem(result.get(), i++, PyJPClass_create(frame, super).keep()); } @@ -1126,7 +1126,7 @@ JPPyObject PyJPClass_create(JPJavaFrame &frame, JPClass* cls) // Check the cache for speed auto *host = (PyObject*) cls->getHost(); - if (host == NULL) + if (host == nullptr) { frame.newWrapper(cls); host = (PyObject*) cls->getHost(); @@ -1139,7 +1139,7 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) { JPContext *context = frame.getContext(); auto *host = (PyObject*) cls->getHost(); - if (host != NULL) + if (host != nullptr) return; @@ -1151,7 +1151,7 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) // Catch creation loop, the process of creating our parent host = (PyObject*) cls->getHost(); - if (host != NULL) + if (host != nullptr) return; const JPFieldList & instFields = cls->getFields(); @@ -1165,7 +1165,7 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) { JPPyObject methodName(JPPyString::fromStringUTF8((*iter)->getName())); PyDict_SetItem(members.get(), methodName.get(), - PyJPMethod_create(*iter, NULL).get()); + PyJPMethod_create(*iter, nullptr).get()); } if (cls->isInterface()) @@ -1175,13 +1175,13 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) { JPPyObject methodName(JPPyString::fromStringUTF8((*iter)->getName())); PyDict_SetItem(members.get(), methodName.get(), - PyJPMethod_create(*iter, NULL).get()); + PyJPMethod_create(*iter, nullptr).get()); } } // Call the customizer to make any required changes to the tables. JP_TRACE("call pre"); - JPPyObject rc = JPPyObject::call(PyObject_Call(_JClassPre, args.get(), NULL)); + JPPyObject rc = JPPyObject::call(PyObject_Call(_JClassPre, args.get(), nullptr)); JP_TRACE("type new"); // Create the type using the meta class magic @@ -1201,5 +1201,5 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) // Call the post load routine to attach inner classes JP_TRACE("call post"); args = JPPyObject::call(PyTuple_Pack(1, self)); - JPPyObject rc2 = JPPyObject::call(PyObject_Call(_JClassPost, args.get(), NULL)); + JPPyObject rc2 = JPPyObject::call(PyObject_Call(_JClassPost, args.get(), nullptr)); } diff --git a/native/python/pyjp_classhints.cpp b/native/python/pyjp_classhints.cpp index e90c4c9ec..55b72e448 100644 --- a/native/python/pyjp_classhints.cpp +++ b/native/python/pyjp_classhints.cpp @@ -27,7 +27,7 @@ PyObject *PyJPClassHints_new(PyTypeObject *type, PyObject *args, PyObject *kwarg auto *self = (PyJPClassHints*) type->tp_alloc(type, 0); self->m_Hints = new JPClassHints(); return (PyObject*) self; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } int PyJPClassHints_init(PyJPClassHints *self, PyObject *args, PyObject *kwargs) @@ -51,7 +51,7 @@ PyObject *PyJPClassHints_str(PyJPClassHints *self) { JP_PY_TRY("PyJPClassHints_str", self); return PyUnicode_FromFormat(""); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPClassHints_addAttributeConversion(PyJPClassHints *self, PyObject* args, PyObject* kwargs) @@ -60,17 +60,17 @@ PyObject *PyJPClassHints_addAttributeConversion(PyJPClassHints *self, PyObject* char* attribute; PyObject *method; if (!PyArg_ParseTuple(args, "sO", &attribute, &method)) - return NULL; + return nullptr; JP_TRACE(attribute); JP_TRACE(Py_TYPE(method)->tp_name); if (!PyCallable_Check(method)) { PyErr_SetString(PyExc_TypeError, "callable method is required"); - return NULL; + return nullptr; } self->m_Hints->addAttributeConversion(string(attribute), method); Py_RETURN_NONE; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static void badType(PyObject* t) @@ -85,20 +85,20 @@ PyObject *PyJPClassHints_addTypeConversion(PyJPClassHints *self, PyObject* args, PyObject *method; unsigned char exact; if (!PyArg_ParseTuple(args, "OOb", &type, &method, &exact)) - return NULL; + return nullptr; if (!PyType_Check(type) && !PyObject_HasAttrString((PyObject*) type, "__instancecheck__")) { badType(type); - return NULL; + return nullptr; } if (!PyCallable_Check(method)) { PyErr_SetString(PyExc_TypeError, "callable method is required"); - return NULL; + return nullptr; } self->m_Hints->addTypeConversion(type, method, exact != 0); Py_RETURN_NONE; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } PyObject *PyJPClassHints_excludeConversion(PyJPClassHints *self, PyObject* types, PyObject* kwargs) @@ -113,7 +113,7 @@ PyObject *PyJPClassHints_excludeConversion(PyJPClassHints *self, PyObject* types if (!PyType_Check(t) && !PyObject_HasAttrString(t, "__instancecheck__")) { badType(t); - return NULL; + return nullptr; } } for (Py_ssize_t i = 0; i < sz; ++i) @@ -125,19 +125,19 @@ PyObject *PyJPClassHints_excludeConversion(PyJPClassHints *self, PyObject* types if (!PyType_Check(types) && !PyObject_HasAttrString( types, "__instancecheck__")) { badType(types); - return NULL; + return nullptr; } self->m_Hints->excludeConversion(types); } Py_RETURN_NONE; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyMethodDef classMethods[] = { {"_addAttributeConversion", (PyCFunction) & PyJPClassHints_addAttributeConversion, METH_VARARGS, ""}, {"_addTypeConversion", (PyCFunction) & PyJPClassHints_addTypeConversion, METH_VARARGS, ""}, {"_excludeConversion", (PyCFunction) & PyJPClassHints_excludeConversion, METH_O, ""}, - {NULL}, + {nullptr}, }; static PyType_Slot hintsSlots[] = { @@ -150,7 +150,7 @@ static PyType_Slot hintsSlots[] = { {0} }; -PyTypeObject *PyJPClassHints_Type = NULL; +PyTypeObject *PyJPClassHints_Type = nullptr; PyType_Spec PyJPClassHintsSpec = { "_jpype._JClassHints", sizeof (PyJPClassHints), diff --git a/native/python/pyjp_field.cpp b/native/python/pyjp_field.cpp index ca73ba8ab..017fc5580 100644 --- a/native/python/pyjp_field.cpp +++ b/native/python/pyjp_field.cpp @@ -30,7 +30,7 @@ struct PyJPField static void PyJPField_dealloc(PyJPField *self) { - self->m_Field = NULL; + self->m_Field = nullptr; Py_TYPE(self)->tp_free(self); } @@ -44,14 +44,14 @@ static PyObject *PyJPField_get(PyJPField *self, PyObject *obj, PyObject *type) frame.clearInterrupt(false); if (self->m_Field->isStatic()) return self->m_Field->getStaticField().keep(); - if (obj == NULL) + if (obj == nullptr) JP_RAISE(PyExc_AttributeError, "Field is not static"); JPValue *jval = PyJPValue_getJavaSlot(obj); - if (jval == NULL) + if (jval == nullptr) JP_RAISE(PyExc_AttributeError, "Field requires instance value"); return self->m_Field->getField(jval->getValue().l).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static int PyJPField_set(PyJPField *self, PyObject *obj, PyObject *pyvalue) @@ -75,7 +75,7 @@ static int PyJPField_set(PyJPField *self, PyObject *obj, PyObject *pyvalue) return -1; } JPValue *jval = PyJPValue_getJavaSlot(obj); - if (jval == NULL) + if (jval == nullptr) { PyErr_Format(PyExc_AttributeError, "Field requires instance value, not '%s'", Py_TYPE(obj)->tp_name); return -1; @@ -94,11 +94,11 @@ static PyObject *PyJPField_repr(PyJPField *self) self->m_Field->getName().c_str(), self->m_Field->getClass()->getCanonicalName().c_str() ); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyGetSetDef fieldGetSets[] = { - {0} + {nullptr} }; static PyType_Slot fieldSlots[] = { @@ -110,7 +110,7 @@ static PyType_Slot fieldSlots[] = { {0} }; -PyTypeObject *PyJPField_Type = NULL; +PyTypeObject *PyJPField_Type = nullptr; PyType_Spec PyJPFieldSpec = { "_jpype._JField", sizeof (PyJPField), diff --git a/native/python/pyjp_method.cpp b/native/python/pyjp_method.cpp index 882af492d..9edc7e835 100644 --- a/native/python/pyjp_method.cpp +++ b/native/python/pyjp_method.cpp @@ -66,25 +66,25 @@ static PyObject *PyJPMethod_get(PyJPMethod *self, PyObject *obj, PyObject *type) { JP_PY_TRY("PyJPMethod_get"); PyJPModule_getContext(); - if (obj == NULL) + if (obj == nullptr) { Py_INCREF((PyObject*) self); JP_TRACE_PY("method get (inc)", (PyObject*) self); return (PyObject*) self; } PyJPMethod *out = (PyJPMethod*) PyJPMethod_create(self->m_Method, obj).keep(); - if (self->m_Doc != NULL) + if (self->m_Doc != nullptr) { out->m_Doc = self->m_Doc; Py_INCREF(out->m_Doc); } - if (self->m_Annotations != NULL) + if (self->m_Annotations != nullptr) { out->m_Annotations = self->m_Annotations; Py_INCREF(out->m_Annotations); } return (PyObject*) out; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_call(PyJPMethod *self, PyObject *args, PyObject *kwargs) @@ -96,8 +96,8 @@ static PyObject *PyJPMethod_call(PyJPMethod *self, PyObject *args, PyObject *kwa // Clear any pending interrupts if we are on the main thread if (hasInterrupt()) frame.clearInterrupt(false); - PyObject *out = NULL; - if (self->m_Instance == NULL) + PyObject *out = nullptr; + if (self->m_Instance == nullptr) { JPPyObjectVector vargs(args); out = self->m_Method->invoke(frame, vargs, false).keep(); @@ -107,7 +107,7 @@ static PyObject *PyJPMethod_call(PyJPMethod *self, PyObject *args, PyObject *kwa out = self->m_Method->invoke(frame, vargs, true).keep(); } return out; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_matches(PyJPMethod *self, PyObject *args, PyObject *kwargs) @@ -116,7 +116,7 @@ static PyObject *PyJPMethod_matches(PyJPMethod *self, PyObject *args, PyObject * JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JP_TRACE(self->m_Method->getName()); - if (self->m_Instance == NULL) + if (self->m_Instance == nullptr) { JPPyObjectVector vargs(args); return PyBool_FromLong(self->m_Method->matches(frame, vargs, false)); @@ -125,7 +125,7 @@ static PyObject *PyJPMethod_matches(PyJPMethod *self, PyObject *args, PyObject * JPPyObjectVector vargs(self->m_Instance, args); return PyBool_FromLong(self->m_Method->matches(frame, vargs, true)); } - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_str(PyJPMethod *self) @@ -136,7 +136,7 @@ static PyObject *PyJPMethod_str(PyJPMethod *self) return PyUnicode_FromFormat("%s.%s", self->m_Method->getClass()->getCanonicalName().c_str(), self->m_Method->getName().c_str()); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_repr(PyJPMethod *self) @@ -144,21 +144,21 @@ static PyObject *PyJPMethod_repr(PyJPMethod *self) JP_PY_TRY("PyJPMethod_repr"); PyJPModule_getContext(); return PyUnicode_FromFormat("", - (self->m_Instance != NULL) ? "bound " : "", + (self->m_Instance != nullptr) ? "bound " : "", self->m_Method->getName().c_str(), self->m_Method->getClass()->getCanonicalName().c_str()); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_getSelf(PyJPMethod *self, void *ctxt) { JP_PY_TRY("PyJPMethod_getSelf"); PyJPModule_getContext(); - if (self->m_Instance == NULL) + if (self->m_Instance == nullptr) Py_RETURN_NONE; Py_INCREF(self->m_Instance); return self->m_Instance; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_getNone(PyJPMethod *self, void *ctxt) @@ -171,7 +171,7 @@ static PyObject *PyJPMethod_getName(PyJPMethod *self, void *ctxt) JP_PY_TRY("PyJPMethod_getName"); PyJPModule_getContext(); return JPPyString::fromStringUTF8(self->m_Method->getName()).keep(); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_getQualName(PyJPMethod *self, void *ctxt) @@ -181,7 +181,7 @@ static PyObject *PyJPMethod_getQualName(PyJPMethod *self, void *ctxt) return PyUnicode_FromFormat("%s.%s", self->m_Method->getClass()->getCanonicalName().c_str(), self->m_Method->getName().c_str()); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPMethod_getDoc(PyJPMethod *self, void *ctxt) @@ -219,11 +219,11 @@ static PyObject *PyJPMethod_getDoc(PyJPMethod *self, void *ctxt) JPPyObject args = JPPyObject::call(PyTuple_Pack(3, self, obj.get(), ov.get())); JP_TRACE("Call Python"); - self->m_Doc = PyObject_Call(_JMethodDoc, args.get(), NULL); + self->m_Doc = PyObject_Call(_JMethodDoc, args.get(), nullptr); Py_XINCREF(self->m_Doc); return self->m_Doc; } - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } int PyJPMethod_setDoc(PyJPMethod *self, PyObject *obj, void *ctxt) @@ -271,12 +271,12 @@ PyObject *PyJPMethod_getAnnotations(PyJPMethod *self, void *ctxt) JPPyObject args = JPPyObject::call(PyTuple_Pack(3, self, obj.get(), ov.get())); JP_TRACE("Call Python"); - self->m_Annotations = PyObject_Call(_JMethodAnnotations, args.get(), NULL); + self->m_Annotations = PyObject_Call(_JMethodAnnotations, args.get(), nullptr); } Py_XINCREF(self->m_Annotations); return self->m_Annotations; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } int PyJPMethod_setAnnotations(PyJPMethod *self, PyObject* obj, void *ctx) @@ -291,14 +291,14 @@ PyObject *PyJPMethod_getCodeAttr(PyJPMethod *self, void *ctx, const char *attr) { JP_PY_TRY("PyJPMethod_getCodeAttr"); PyJPModule_getContext(); - if (self->m_CodeRep == NULL) + if (self->m_CodeRep == nullptr) { JPPyObject args = JPPyObject::call(PyTuple_Pack(1, self)); JP_TRACE("Call Python"); - self->m_CodeRep = PyObject_Call(_JMethodCode, args.get(), NULL); + self->m_CodeRep = PyObject_Call(_JMethodCode, args.get(), nullptr); } return PyObject_GetAttrString(self->m_CodeRep, attr); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPMethod_getCode(PyJPMethod *self, void *ctxt) @@ -321,7 +321,7 @@ PyObject *PyJPMethod_isBeanAccessor(PyJPMethod *self, PyObject *arg) JP_PY_TRY("PyJPMethod_isBeanAccessor"); PyJPModule_getContext(); return PyBool_FromLong(self->m_Method->isBeanAccessor()); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPMethod_isBeanMutator(PyJPMethod *self, PyObject *arg) @@ -329,7 +329,7 @@ PyObject *PyJPMethod_isBeanMutator(PyJPMethod *self, PyObject *arg) JP_PY_TRY("PyJPMethod_isBeanMutator"); PyJPModule_getContext(); return PyBool_FromLong(self->m_Method->isBeanMutator()); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPMethod_matchReport(PyJPMethod *self, PyObject *args) @@ -339,7 +339,7 @@ PyObject *PyJPMethod_matchReport(PyJPMethod *self, PyObject *args) JPPyObjectVector vargs(args); string report = self->m_Method->matchReport(vargs); return JPPyString::fromStringUTF8(report).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyMethodDef methodMethods[] = { @@ -348,21 +348,21 @@ static PyMethodDef methodMethods[] = { {"matchReport", (PyCFunction) (&PyJPMethod_matchReport), METH_VARARGS, ""}, // This is currently private but may be promoted {"_matches", (PyCFunction) (&PyJPMethod_matches), METH_VARARGS, ""}, - {NULL}, + {nullptr}, }; struct PyGetSetDef methodGetSet[] = { - {"__self__", (getter) (&PyJPMethod_getSelf), NULL, NULL, NULL}, - {"__name__", (getter) (&PyJPMethod_getName), NULL, NULL, NULL}, - {"__doc__", (getter) (&PyJPMethod_getDoc), (setter) (&PyJPMethod_setDoc), NULL, NULL}, - {"__annotations__", (getter) (&PyJPMethod_getAnnotations), (setter) (&PyJPMethod_setAnnotations), NULL, NULL}, - {"__closure__", (getter) (&PyJPMethod_getClosure), NULL, NULL, NULL}, - {"__code__", (getter) (&PyJPMethod_getCode), NULL, NULL, NULL}, - {"__defaults__", (getter) (&PyJPMethod_getNone), NULL, NULL, NULL}, - {"__kwdefaults__", (getter) (&PyJPMethod_getNone), NULL, NULL, NULL}, - {"__globals__", (getter) (&PyJPMethod_getGlobals), NULL, NULL, NULL}, - {"__qualname__", (getter) (&PyJPMethod_getQualName), NULL, NULL, NULL}, - {NULL}, + {"__self__", (getter) (&PyJPMethod_getSelf), nullptr, nullptr, nullptr}, + {"__name__", (getter) (&PyJPMethod_getName), nullptr, nullptr, nullptr}, + {"__doc__", (getter) (&PyJPMethod_getDoc), (setter) (&PyJPMethod_setDoc), nullptr, nullptr}, + {"__annotations__", (getter) (&PyJPMethod_getAnnotations), (setter) (&PyJPMethod_setAnnotations), nullptr, nullptr}, + {"__closure__", (getter) (&PyJPMethod_getClosure), nullptr, nullptr, nullptr}, + {"__code__", (getter) (&PyJPMethod_getCode), nullptr, nullptr, nullptr}, + {"__defaults__", (getter) (&PyJPMethod_getNone), nullptr, nullptr, nullptr}, + {"__kwdefaults__", (getter) (&PyJPMethod_getNone), nullptr, nullptr, nullptr}, + {"__globals__", (getter) (&PyJPMethod_getGlobals), nullptr, nullptr, nullptr}, + {"__qualname__", (getter) (&PyJPMethod_getQualName), nullptr, nullptr, nullptr}, + {nullptr}, }; static PyType_Slot methodSlots[] = { @@ -378,7 +378,7 @@ static PyType_Slot methodSlots[] = { {0} }; -PyTypeObject *PyJPMethod_Type = NULL; +PyTypeObject *PyJPMethod_Type = nullptr; static PyType_Spec methodSpec = { "_jpype._JMethod", sizeof (PyJPMethod), @@ -414,9 +414,9 @@ JPPyObject PyJPMethod_create(JPMethodDispatch *m, PyObject *instance) JP_PY_CHECK(); self->m_Method = m; self->m_Instance = instance; - self->m_Doc = NULL; - self->m_Annotations = NULL; - self->m_CodeRep = NULL; + self->m_Doc = nullptr; + self->m_Annotations = nullptr; + self->m_CodeRep = nullptr; Py_XINCREF(self->m_Instance); return JPPyObject::claim((PyObject*) self); JP_TRACE_OUT; /// GCOVR_EXCL_LINE diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index cdbafdfeb..13249461b 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -59,19 +59,19 @@ class JPViewWrapper } ; -PyObject* _JArray = NULL; -PyObject* _JChar = NULL; -PyObject* _JObject = NULL; -PyObject* _JInterface = NULL; -PyObject* _JException = NULL; -PyObject* _JClassPre = NULL; -PyObject* _JClassPost = NULL; -PyObject* _JClassDoc = NULL; -PyObject* _JMethodDoc = NULL; -PyObject* _JMethodAnnotations = NULL; -PyObject* _JMethodCode = NULL; -PyObject* _JObjectKey = NULL; -PyObject* _JVMNotRunning = NULL; +PyObject* _JArray = nullptr; +PyObject* _JChar = nullptr; +PyObject* _JObject = nullptr; +PyObject* _JInterface = nullptr; +PyObject* _JException = nullptr; +PyObject* _JClassPre = nullptr; +PyObject* _JClassPost = nullptr; +PyObject* _JClassDoc = nullptr; +PyObject* _JMethodDoc = nullptr; +PyObject* _JMethodAnnotations = nullptr; +PyObject* _JMethodCode = nullptr; +PyObject* _JObjectKey = nullptr; +PyObject* _JVMNotRunning = nullptr; void PyJPModule_loadResources(PyObject* module) { @@ -121,7 +121,7 @@ void PyJPModule_loadResources(PyObject* module) JP_PY_CHECK(); Py_INCREF(_JMethodCode); - _JObjectKey = PyCapsule_New(module, "constructor key", NULL); + _JObjectKey = PyCapsule_New(module, "constructor key", nullptr); } catch (JPypeException&) // GCOVR_EXCL_LINE { @@ -148,7 +148,7 @@ void PyJP_SetStringWithCause(PyObject *exception, PyObject *exc1, *val1, *tb1; PyErr_Fetch(&exc1, &val1, &tb1); PyErr_NormalizeException(&exc1, &val1, &tb1); - if (tb1 != NULL) + if (tb1 != nullptr) { PyException_SetTraceback(val1, tb1); Py_DECREF(tb1); @@ -166,8 +166,8 @@ void PyJP_SetStringWithCause(PyObject *exception, PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name) { JP_PY_TRY("Py_GetAttrDescriptor"); - if (type->tp_mro == NULL) - return NULL; // GCOVR_EXCL_LINE + if (type->tp_mro == nullptr) + return nullptr; // GCOVR_EXCL_LINE PyObject *mro = type->tp_mro; Py_ssize_t n = PyTuple_Size(mro); @@ -192,13 +192,13 @@ PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name) } } - return NULL; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + return nullptr; + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } int PyJP_IsSubClassSingle(PyTypeObject* type, PyTypeObject* obj) { - if (type == NULL || obj == NULL) + if (type == nullptr || obj == nullptr) return 0; // GCOVR_EXCL_LINE PyObject* mro1 = obj->tp_mro; Py_ssize_t n1 = PyTuple_Size(mro1); @@ -210,7 +210,7 @@ int PyJP_IsSubClassSingle(PyTypeObject* type, PyTypeObject* obj) int PyJP_IsInstanceSingle(PyObject* obj, PyTypeObject* type) { - if (type == NULL || obj == NULL) + if (type == nullptr || obj == nullptr) return 0; // GCOVR_EXCL_LINE return PyJP_IsSubClassSingle(type, Py_TYPE(obj)); } @@ -230,12 +230,12 @@ static PyObject* PyJPModule_startup(PyObject* module, PyObject* pyargs) if (!PyArg_ParseTuple(pyargs, "OO!bbb", &vmPath, &PyTuple_Type, &vmOpt, &ignoreUnrecognized, &convertStrings, &interrupt)) - return NULL; + return nullptr; if (!(JPPyString::check(vmPath))) { PyErr_SetString(PyExc_TypeError, "Java JVM path must be a string"); - return NULL; + return nullptr; } string cVmPath = JPPyString::asStringUTF8(vmPath); @@ -257,7 +257,7 @@ static PyObject* PyJPModule_startup(PyObject* module, PyObject* pyargs) } else { PyErr_SetString(PyExc_TypeError, "VM Arguments must be strings"); - return NULL; + return nullptr; } } @@ -265,7 +265,7 @@ static PyObject* PyJPModule_startup(PyObject* module, PyObject* pyargs) if (JPContext_global->isRunning()) { PyErr_SetString(PyExc_OSError, "JVM is already started"); - return NULL; + return nullptr; } // install the gc hook @@ -274,7 +274,7 @@ static PyObject* PyJPModule_startup(PyObject* module, PyObject* pyargs) JPContext_global->startJVM(cVmPath, args, ignoreUnrecognized != 0, convertStrings != 0, interrupt != 0); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject* PyJPModule_shutdown(PyObject* obj, PyObject* pyargs, PyObject* kwargs) @@ -284,11 +284,11 @@ static PyObject* PyJPModule_shutdown(PyObject* obj, PyObject* pyargs, PyObject* char freeJVM = true; if (!PyArg_ParseTuple(pyargs, "bb", &destroyJVM, &freeJVM)) - return NULL; + return nullptr; JPContext_global->shutdownJVM(destroyJVM, freeJVM); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } #endif @@ -304,7 +304,7 @@ static PyObject* PyJPModule_attachThread(PyObject* obj) JP_PY_TRY("PyJPModule_attachThread"); PyJPModule_getContext()->attachCurrentThread(); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject* PyJPModule_attachThreadAsDaemon(PyObject* obj) @@ -312,7 +312,7 @@ static PyObject* PyJPModule_attachThreadAsDaemon(PyObject* obj) JP_PY_TRY("PyJPModule_attachThreadAsDaemon"); PyJPModule_getContext()->attachCurrentThreadAsDaemon(); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject* PyJPModule_detachThread(PyObject* obj) @@ -321,7 +321,7 @@ static PyObject* PyJPModule_detachThread(PyObject* obj) if (JPContext_global->isRunning()) JPContext_global->detachCurrentThread(); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } #endif @@ -331,14 +331,14 @@ static PyObject* PyJPModule_isThreadAttached(PyObject* obj) if (!JPContext_global->isRunning()) return PyBool_FromLong(0); // GCOVR_EXCL_LINE return PyBool_FromLong(JPContext_global->isThreadAttached()); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } // Cleanup hook for Py_buffer static void releaseView(void* view) { - if (view != 0) + if (view != nullptr) { PyBuffer_Release((Py_buffer*) view); delete (Py_buffer*) view; @@ -355,7 +355,7 @@ static PyObject* PyJPModule_convertToDirectByteBuffer(PyObject* self, PyObject* { JPViewWrapper vw; if (PyObject_GetBuffer(src, vw.view, PyBUF_WRITABLE) == -1) - return NULL; + return nullptr; // Create a byte buffer jvalue v; @@ -363,12 +363,12 @@ static PyObject* PyJPModule_convertToDirectByteBuffer(PyObject* self, PyObject* // Bind lifespan of the view to the java object. frame.registerRef(v.l, vw.view, &releaseView); - vw.view = 0; + vw.view = nullptr; JPClass *type = frame.findClassForObject(v.l); return type->convertToPythonObject(frame, v, false).keep(); } PyErr_SetString(PyExc_TypeError, "convertToDirectByteBuffer requires buffer support"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject* PyJPModule_enableStacktraces(PyObject* self, PyObject* src) @@ -385,23 +385,23 @@ PyObject *PyJPModule_newArrayType(PyObject *module, PyObject *args) PyObject *type, *dims; if (!PyArg_ParseTuple(args, "OO", &type, &dims)) - return NULL; + return nullptr; if (!PyIndex_Check(dims)) { PyErr_SetString(PyExc_TypeError, "dims must be an integer"); - return NULL; + return nullptr; } long d = PyLong_AsLong(dims); JPClass* cls = PyJPClass_getJPClass(type); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_TypeError, "Java class required"); - return NULL; + return nullptr; } JPClass* arraycls = cls->newArrayType(frame, d); return PyJPClass_create(frame, arraycls).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPModule_getClass(PyObject* module, PyObject *obj) @@ -415,30 +415,30 @@ PyObject *PyJPModule_getClass(PyObject* module, PyObject *obj) { // String From Python cls = frame.findClassByName(JPPyString::asStringUTF8(obj)); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_ValueError, "Unable to find Java class"); - return NULL; + return nullptr; } } else { // From an existing java.lang.Class object JPValue *value = PyJPValue_getJavaSlot(obj); - if (value == 0 || value->getClass() != context->_java_lang_Class) + if (value == nullptr || value->getClass() != context->_java_lang_Class) { PyErr_Format(PyExc_TypeError, "JClass requires str or java.lang.Class instance, not '%s'", Py_TYPE(obj)->tp_name); - return NULL; + return nullptr; } cls = frame.findClass((jclass) value->getValue().l); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_ValueError, "Unable to find class"); - return NULL; + return nullptr; } } return PyJPClass_create(frame, cls).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPModule_hasClass(PyObject* module, PyObject *obj) @@ -454,33 +454,33 @@ PyObject *PyJPModule_hasClass(PyObject* module, PyObject *obj) { // String From Python cls = frame.findClassByName(JPPyString::asStringUTF8(obj)); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_ValueError, "Unable to find Java class"); - return NULL; + return nullptr; } } else { PyErr_Format(PyExc_TypeError, "str is required, not '%s'", Py_TYPE(obj)->tp_name); - return NULL; + return nullptr; } auto *host = (PyObject*) cls->getHost(); - return PyBool_FromLong(host != NULL); - JP_PY_CATCH(NULL); + return PyBool_FromLong(host != nullptr); + JP_PY_CATCH(nullptr); } static PyObject *PyJPModule_arrayFromBuffer(PyObject *module, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPModule_arrayFromBuffer"); - PyObject *source = 0; - PyObject *dtype = 0; + PyObject *source = nullptr; + PyObject *dtype = nullptr; if (!PyArg_ParseTuple(args, "OO", &source, &dtype)) - return NULL; + return nullptr; if (!PyObject_CheckBuffer(source)) { PyErr_Format(PyExc_TypeError, "'%s' does not support buffers", Py_TYPE(source)->tp_name); - return NULL; + return nullptr; } // NUMPy does a series of probes looking for the best supported format, @@ -501,8 +501,8 @@ static PyObject *PyJPModule_arrayFromBuffer(PyObject *module, PyObject *args, Py return PyJPModule_convertBuffer(buffer, dtype); } PyErr_Format(PyExc_TypeError, "buffer protocol for '%s' not supported", Py_TYPE(source)->tp_name); - return NULL; - JP_PY_CATCH(NULL); + return nullptr; + JP_PY_CATCH(nullptr); } PyObject *PyJPModule_collect(PyObject* module, PyObject *obj) @@ -514,7 +514,7 @@ PyObject *PyJPModule_collect(PyObject* module, PyObject *obj) if (!PyUnicode_Check(a1)) { PyErr_SetString(PyExc_TypeError, "Bad callback argument"); - return NULL; + return nullptr; } if (PyUnicode_ReadChar(a1, 2) == 'a') { @@ -557,12 +557,12 @@ static PyObject* PyJPModule_isPackage(PyObject *module, PyObject *pkg) if (!PyUnicode_Check(pkg)) { PyErr_Format(PyExc_TypeError, "isPackage required unicode"); - return NULL; + return nullptr; } JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); return PyBool_FromLong(frame.isPackage(JPPyString::asStringUTF8(pkg))); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } @@ -610,7 +610,7 @@ PyObject* examine(PyObject *module, PyObject *other) printf("======\n"); return PyBool_FromLong(ret); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } // GCOVR_EXCL_STOP #endif @@ -695,7 +695,7 @@ static PyMethodDef moduleMethods[] = { {"examine", (PyCFunction) examine, METH_O, ""}, // sentinel - {NULL} + {nullptr} }; static struct PyModuleDef moduledef = { @@ -706,8 +706,8 @@ static struct PyModuleDef moduledef = { moduleMethods, }; -PyObject *PyJPModule = NULL; -JPContext* JPContext_global = NULL; +PyObject *PyJPModule = nullptr; +JPContext* JPContext_global = nullptr; PyMODINIT_FUNC PyInit__jpype() { @@ -746,7 +746,7 @@ PyMODINIT_FUNC PyInit__jpype() _PyJPModule_trace = true; return module; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } #ifdef __cplusplus @@ -785,18 +785,18 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) // Okay two possibilities here. We have a valid dtype specified, // or we need to figure it out from the buffer. - JPClass *cls = NULL; + JPClass *cls = nullptr; - if (view.suboffsets != NULL && view.suboffsets[view.ndim - 1] > 0) + if (view.suboffsets != nullptr && view.suboffsets[view.ndim - 1] > 0) { PyErr_Format(PyExc_TypeError, "last dimension is not contiguous"); - return NULL; + return nullptr; } // First lets find out what we are unpacking Py_ssize_t itemsize = view.itemsize; char *format = view.format; - if (format == NULL) + if (format == nullptr) format = "B"; // Standard size for 'l' is 4 in docs, but numpy uses format 'l' for long long if (itemsize == 8 && format[0] == 'l') @@ -804,13 +804,13 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) if (itemsize == 8 && format[0] == 'L') format = "Q"; - if (dtype != NULL && dtype != Py_None ) + if (dtype != nullptr && dtype != Py_None ) { cls = PyJPClass_getJPClass(dtype); - if (cls == NULL || !cls->isPrimitive()) + if (cls == nullptr || !cls->isPrimitive()) { PyErr_Format(PyExc_TypeError, "'%s' is not a Java primitive type", Py_TYPE(dtype)->tp_name); - return NULL; + return nullptr; } } else { @@ -841,10 +841,10 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) default: break; } - if (cls == NULL) + if (cls == nullptr) { PyErr_Format(PyExc_TypeError, "'%s' type code not supported without dtype specified", format); - return NULL; + return nullptr; } } @@ -856,7 +856,7 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) Py_ssize_t subs = 1; Py_ssize_t base = 1; auto jdims = (jintArray) context->_int->newArrayOf(frame, view.ndim); - if (view.shape != NULL) + if (view.shape != nullptr) { JPPrimitiveArrayAccessor accessor(frame, jdims, &JPJavaFrame::GetIntArrayElements, &JPJavaFrame::ReleaseIntArrayElements); @@ -876,7 +876,7 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) if (view.ndim > 1) { PyErr_Format(PyExc_TypeError, "buffer dims inconsistent"); - return NULL; + return nullptr; } base = view.len / view.itemsize; } diff --git a/native/python/pyjp_monitor.cpp b/native/python/pyjp_monitor.cpp index 6c7b18fa9..d02c1e69a 100644 --- a/native/python/pyjp_monitor.cpp +++ b/native/python/pyjp_monitor.cpp @@ -32,7 +32,7 @@ struct PyJPMonitor static int PyJPMonitor_init(PyJPMonitor *self, PyObject *args) { JP_PY_TRY("PyJPMonitor_init"); - self->m_Monitor = NULL; + self->m_Monitor = nullptr; JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); @@ -42,7 +42,7 @@ static int PyJPMonitor_init(PyJPMonitor *self, PyObject *args) return -1; JPValue *v1 = PyJPValue_getJavaSlot(value); - if (v1 == NULL) + if (v1 == nullptr) { PyErr_SetString(PyExc_TypeError, "Java object is required."); return -1; @@ -60,7 +60,7 @@ static int PyJPMonitor_init(PyJPMonitor *self, PyObject *args) return -1; } - if (v1->getValue().l == NULL) + if (v1->getValue().l == nullptr) { PyErr_SetString(PyExc_TypeError, "Java null cannot be used to synchronize."); return -1; @@ -83,7 +83,7 @@ static PyObject *PyJPMonitor_str(PyJPMonitor *self) { JP_PY_TRY("PyJPMonitor_str"); return PyUnicode_FromFormat(""); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPMonitor_enter(PyJPMonitor *self, PyObject *args) @@ -93,7 +93,7 @@ static PyObject *PyJPMonitor_enter(PyJPMonitor *self, PyObject *args) JPJavaFrame frame = JPJavaFrame::outer(context); self->m_Monitor->enter(); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPMonitor_exit(PyJPMonitor *self, PyObject *args) @@ -103,13 +103,13 @@ static PyObject *PyJPMonitor_exit(PyJPMonitor *self, PyObject *args) JPJavaFrame frame = JPJavaFrame::outer(context); self->m_Monitor->exit(); Py_RETURN_NONE; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyMethodDef monitorMethods[] = { {"__enter__", (PyCFunction) (&PyJPMonitor_enter), METH_NOARGS, ""}, {"__exit__", (PyCFunction) (&PyJPMonitor_exit), METH_VARARGS, ""}, - {NULL}, + {nullptr}, }; static PyType_Slot monitorSlots[] = { @@ -128,7 +128,7 @@ PyType_Spec PyJPMonitorSpec = { monitorSlots }; -PyTypeObject* PyJPMonitor_Type = NULL; +PyTypeObject* PyJPMonitor_Type = nullptr; #ifdef __cplusplus } diff --git a/native/python/pyjp_number.cpp b/native/python/pyjp_number.cpp index 55a93e3d3..8ab28ef2b 100644 --- a/native/python/pyjp_number.cpp +++ b/native/python/pyjp_number.cpp @@ -20,9 +20,9 @@ static bool isNull(PyObject *self) { JPValue *javaSlot = PyJPValue_getJavaSlot(self); - if (javaSlot != NULL + if (javaSlot != nullptr && !javaSlot->getClass()->isPrimitive() - && javaSlot->getValue().l == 0) + && javaSlot->getValue().l == nullptr) return true; return false; } @@ -38,7 +38,7 @@ static PyObject *PyJPNumber_new(PyTypeObject *type, PyObject *args, PyObject *kw JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); auto *cls = (JPClass*) PyJPClass_getJPClass((PyObject*) type); - if (cls == NULL) + if (cls == nullptr) JP_RAISE(PyExc_TypeError, "Class type incorrect"); jvalue val; @@ -77,9 +77,9 @@ static PyObject *PyJPNumber_new(PyTypeObject *type, PyObject *args, PyObject *kw } else { PyErr_Format(PyExc_TypeError, "Type '%s' is not a number class", type->tp_name); - return NULL; + return nullptr; } - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberLong_int(PyObject *self) @@ -90,7 +90,7 @@ static PyObject *PyJPNumberLong_int(PyObject *self) if (!isNull(self)) return PyLong_Type.tp_as_number->nb_int(self); PyErr_SetString(PyExc_TypeError, "cast of null pointer would return non-int"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberLong_float(PyObject *self) @@ -101,7 +101,7 @@ static PyObject *PyJPNumberLong_float(PyObject *self) if (!isNull(self)) return PyLong_Type.tp_as_number->nb_float(self); PyErr_SetString(PyExc_TypeError, "cast of null pointer would return non-float"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberFloat_int(PyObject *self) @@ -112,7 +112,7 @@ static PyObject *PyJPNumberFloat_int(PyObject *self) if (!isNull(self)) return PyFloat_Type.tp_as_number->nb_int(self); PyErr_SetString(PyExc_TypeError, "cast of null pointer would return non-int"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberFloat_float(PyObject *self) @@ -123,7 +123,7 @@ static PyObject *PyJPNumberFloat_float(PyObject *self) if (!isNull(self)) return PyFloat_Type.tp_as_number->nb_float(self); PyErr_SetString(PyExc_TypeError, "cast of null pointer would return non-float"); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberLong_str(PyObject *self) @@ -134,7 +134,7 @@ static PyObject *PyJPNumberLong_str(PyObject *self) if (isNull(self)) return Py_TYPE(Py_None)->tp_str(Py_None); return PyLong_Type.tp_str(self); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberFloat_str(PyObject *self) @@ -145,7 +145,7 @@ static PyObject *PyJPNumberFloat_str(PyObject *self) if (isNull(self)) return Py_TYPE(Py_None)->tp_str(Py_None); return PyFloat_Type.tp_str(self); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberLong_repr(PyObject *self) @@ -156,7 +156,7 @@ static PyObject *PyJPNumberLong_repr(PyObject *self) if (isNull(self)) return Py_TYPE(Py_None)->tp_str(Py_None); return PyLong_Type.tp_repr(self); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberFloat_repr(PyObject *self) @@ -167,7 +167,7 @@ static PyObject *PyJPNumberFloat_repr(PyObject *self) if (isNull(self)) return Py_TYPE(Py_None)->tp_str(Py_None); return PyFloat_Type.tp_repr(self); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static const char* op_names[] = { @@ -195,7 +195,7 @@ static PyObject *PyJPNumberLong_compare(PyObject *self, PyObject *other, int op) return out; } return PyLong_Type.tp_richcompare(self, other, op); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPNumberFloat_compare(PyObject *self, PyObject *other, int op) @@ -219,7 +219,7 @@ static PyObject *PyJPNumberFloat_compare(PyObject *self, PyObject *other, int op return out; } return PyFloat_Type.tp_richcompare(self, other, op); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static Py_hash_t PyJPNumberLong_hash(PyObject *self) @@ -228,12 +228,12 @@ static Py_hash_t PyJPNumberLong_hash(PyObject *self) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue *javaSlot = PyJPValue_getJavaSlot(self); - if (javaSlot == NULL) + if (javaSlot == nullptr) return Py_TYPE(Py_None)->tp_hash(Py_None); if (!javaSlot->getClass()->isPrimitive()) { jobject o = javaSlot->getJavaObject(); - if (o == NULL) + if (o == nullptr) return Py_TYPE(Py_None)->tp_hash(Py_None); } return PyLong_Type.tp_hash(self); @@ -246,12 +246,12 @@ static Py_hash_t PyJPNumberFloat_hash(PyObject *self) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue *javaSlot = PyJPValue_getJavaSlot(self); - if (javaSlot == NULL) + if (javaSlot == nullptr) return Py_TYPE(Py_None)->tp_hash(Py_None); if (!javaSlot->getClass()->isPrimitive()) { jobject o = javaSlot->getJavaObject(); - if (o == NULL) + if (o == nullptr) return Py_TYPE(Py_None)->tp_hash(Py_None); } return PyFloat_Type.tp_hash(self); @@ -267,17 +267,17 @@ static PyObject *PyJPBoolean_new(PyTypeObject *type, PyObject *args, PyObject *k if (PyTuple_Size(args) != 1) { PyErr_SetString(PyExc_TypeError, "Requires one argument"); - return NULL; + return nullptr; } int i = PyObject_IsTrue(PyTuple_GetItem(args, 0)); PyObject *args2 = PyTuple_Pack(1, PyLong_FromLong(i)); self = JPPyObject::call(PyLong_Type.tp_new(type, args2, kwargs)); Py_DECREF(args2); JPClass *cls = PyJPClass_getJPClass((PyObject*) type); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_TypeError, "Class type incorrect"); - return NULL; + return nullptr; } JPMatch match(&frame, self.get()); cls->findJavaConversion(match); @@ -285,7 +285,7 @@ static PyObject *PyJPBoolean_new(PyTypeObject *type, PyObject *args, PyObject *k PyJPValue_assignJavaSlot(frame, self.get(), JPValue(cls, val)); JP_TRACE("new", self.get()); return self.keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject* PyJPBoolean_str(PyObject* self) @@ -296,7 +296,7 @@ static PyObject* PyJPBoolean_str(PyObject* self) if (PyLong_AsLong(self) == 0) return Py_TYPE(Py_False)->tp_str(Py_False); return Py_TYPE(Py_True)->tp_str(Py_True); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyType_Slot numberLongSlots[] = { @@ -312,7 +312,7 @@ static PyType_Slot numberLongSlots[] = { {0} }; -PyTypeObject *PyJPNumberLong_Type = NULL; +PyTypeObject *PyJPNumberLong_Type = nullptr; PyType_Spec numberLongSpec = { "_jpype._JNumberLong", 0, @@ -334,7 +334,7 @@ static PyType_Slot numberFloatSlots[] = { {0} }; -PyTypeObject *PyJPNumberFloat_Type = NULL; +PyTypeObject *PyJPNumberFloat_Type = nullptr; PyType_Spec numberFloatSpec = { "_jpype._JNumberFloat", 0, @@ -356,7 +356,7 @@ static PyType_Slot numberBooleanSlots[] = { {0} }; -PyTypeObject *PyJPNumberBool_Type = NULL; +PyTypeObject *PyJPNumberBool_Type = nullptr; PyType_Spec numberBooleanSpec = { "_jpype._JBoolean", 0, @@ -402,32 +402,32 @@ JPPyObject PyJPNumber_create(JPJavaFrame &frame, JPPyObject& wrapper, const JPVa if (value.getClass() == context->_java_lang_Boolean) { jlong l = 0; - if (value.getValue().l != 0) - l = frame.CallBooleanMethodA(value.getJavaObject(), context->_java_lang_Boolean->m_BooleanValueID, 0); + if (value.getValue().l != nullptr) + l = frame.CallBooleanMethodA(value.getJavaObject(), context->_java_lang_Boolean->m_BooleanValueID, nullptr); PyObject *args = PyTuple_Pack(1, PyLong_FromLongLong(l)); - return JPPyObject::call(PyLong_Type.tp_new((PyTypeObject*) wrapper.get(), args, NULL)); + return JPPyObject::call(PyLong_Type.tp_new((PyTypeObject*) wrapper.get(), args, nullptr)); } if (PyObject_IsSubclass(wrapper.get(), (PyObject*) & PyLong_Type)) { jlong l = 0; - if (value.getValue().l != 0) + if (value.getValue().l != nullptr) { auto* jb = (JPBoxedType*) value.getClass(); - l = frame.CallLongMethodA(value.getJavaObject(), jb->m_LongValueID, 0); + l = frame.CallLongMethodA(value.getJavaObject(), jb->m_LongValueID, nullptr); } PyObject *args = PyTuple_Pack(1, PyLong_FromLongLong(l)); - return JPPyObject::call(PyLong_Type.tp_new((PyTypeObject*) wrapper.get(), args, NULL)); + return JPPyObject::call(PyLong_Type.tp_new((PyTypeObject*) wrapper.get(), args, nullptr)); } if (PyObject_IsSubclass(wrapper.get(), (PyObject*) & PyFloat_Type)) { jdouble l = 0; - if (value.getValue().l != 0) + if (value.getValue().l != nullptr) { auto* jb = (JPBoxedType*) value.getClass(); - l = frame.CallDoubleMethodA(value.getJavaObject(), jb->m_DoubleValueID, 0); + l = frame.CallDoubleMethodA(value.getJavaObject(), jb->m_DoubleValueID, nullptr); } PyObject *args = PyTuple_Pack(1, PyFloat_FromDouble(l)); - return JPPyObject::call(PyFloat_Type.tp_new((PyTypeObject*) wrapper.get(), args, NULL)); + return JPPyObject::call(PyFloat_Type.tp_new((PyTypeObject*) wrapper.get(), args, nullptr)); } JP_RAISE(PyExc_TypeError, "unable to convert"); //GCOVR_EXCL_LINE } diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index 9836fd973..0924170cf 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -27,10 +27,10 @@ static PyObject *PyJPObject_new(PyTypeObject *type, PyObject *pyargs, PyObject * JP_PY_TRY("PyJPObject_new"); // Get the Java class from the type. JPClass *cls = PyJPClass_getJPClass((PyObject*) type); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_TypeError, "Java class type is incorrect"); - return NULL; + return nullptr; } // Create an instance (this may fail) @@ -46,7 +46,7 @@ static PyObject *PyJPObject_new(PyTypeObject *type, PyObject *pyargs, PyObject * JP_FAULT_RETURN("PyJPObject_init.null", self); PyJPValue_assignJavaSlot(frame, self, jv); return self; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPObject_compare(PyObject *self, PyObject *other, int op) @@ -55,8 +55,8 @@ static PyObject *PyJPObject_compare(PyObject *self, PyObject *other, int op) if (op == Py_NE) { PyObject *ret = PyJPObject_compare(self, other, Py_EQ); - if (ret == NULL) - return NULL; + if (ret == nullptr) + return nullptr; int rc = (ret == Py_False); Py_DECREF(ret); return PyBool_FromLong(rc); @@ -74,13 +74,13 @@ static PyObject *PyJPObject_compare(PyObject *self, PyObject *other, int op) JPValue *javaSlot1 = PyJPValue_getJavaSlot(other); // First slot is Null - if (javaSlot0 == NULL || javaSlot0->getValue().l == NULL) + if (javaSlot0 == nullptr || javaSlot0->getValue().l == nullptr) { - if (javaSlot1 == NULL) + if (javaSlot1 == nullptr) return PyBool_FromLong(other == Py_None); if (javaSlot1->getClass()->isPrimitive()) Py_RETURN_FALSE; - if (javaSlot1->getValue().l == NULL) + if (javaSlot1->getValue().l == nullptr) Py_RETURN_TRUE; Py_RETURN_FALSE; } @@ -88,7 +88,7 @@ static PyObject *PyJPObject_compare(PyObject *self, PyObject *other, int op) // Check second slot is Null if (other == Py_None) Py_RETURN_FALSE; - if (javaSlot1 == NULL) + if (javaSlot1 == nullptr) { // This block seems like a giant waste as there are very few cases in which // a converted object would ever satisfy equals. But this was the original @@ -101,11 +101,11 @@ static PyObject *PyJPObject_compare(PyObject *self, PyObject *other, int op) } if (javaSlot1->getClass()->isPrimitive()) Py_RETURN_FALSE; - if (javaSlot1->getValue().l == NULL) + if (javaSlot1->getValue().l == nullptr) Py_RETURN_FALSE; return PyBool_FromLong(frame.equals(javaSlot0->getValue().l, javaSlot1->getValue().l)); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) @@ -120,20 +120,20 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) bool null1 = false; // First slot is Null - if (self == Py_None || javaSlot0 == NULL || - (!javaSlot0->getClass()->isPrimitive() && javaSlot0->getValue().l == NULL)) + if (self == Py_None || javaSlot0 == nullptr || + (!javaSlot0->getClass()->isPrimitive() && javaSlot0->getValue().l == nullptr)) null0 = true; - if (other == Py_None || (javaSlot1 != NULL && - !javaSlot1->getClass()->isPrimitive() && javaSlot1->getValue().l == NULL)) + if (other == Py_None || (javaSlot1 != nullptr && + !javaSlot1->getClass()->isPrimitive() && javaSlot1->getValue().l == nullptr)) null1 = true; - jobject obj0 = NULL; - jobject obj1 = NULL; + jobject obj0 = nullptr; + jobject obj1 = nullptr; if (!null0) obj0 = javaSlot0->getValue().l; - if (!null0 && !null1 && javaSlot1 == NULL) + if (!null0 && !null1 && javaSlot1 == nullptr) { // Okay here is the hard part. We need to figure out what type // of object to create to make them comparable. We can't assume @@ -143,18 +143,18 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) // because of type erasure we can't actually get. JPClass *cls2 = javaSlot0->getClass(); JPMatch match(&frame, other); - while (cls2 != NULL && !cls2->findJavaConversion(match) && !JPModifier::isComparable(cls2->getModifiers())) + while (cls2 != nullptr && !cls2->findJavaConversion(match) && !JPModifier::isComparable(cls2->getModifiers())) cls2 = cls2->getSuperClass(); // This should never happen. - if (cls2 == NULL) + if (cls2 == nullptr) { PyObject *out = Py_NotImplemented; Py_INCREF(out); return out; } obj1 = match.convert().l; - } else if (!null1 && javaSlot1 != NULL) + } else if (!null1 && javaSlot1 != nullptr) obj1 = javaSlot1->getValue().l; switch (op) @@ -190,7 +190,7 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) return PyBool_FromLong(frame.compareTo(obj0, obj1) >= 0); } PyErr_SetString(PyExc_ValueError, "can't compare null"); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static Py_hash_t PyJPObject_hash(PyObject *obj) @@ -199,10 +199,10 @@ static Py_hash_t PyJPObject_hash(PyObject *obj) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue *javaSlot = PyJPValue_getJavaSlot(obj); - if (javaSlot == NULL) + if (javaSlot == nullptr) return Py_TYPE(Py_None)->tp_hash(Py_None); jobject o = javaSlot->getJavaObject(); - if (o == NULL) + if (o == nullptr) return Py_TYPE(Py_None)->tp_hash(Py_None); return frame.hashCode(o); JP_PY_CATCH(0); @@ -212,7 +212,7 @@ static PyObject *PyJPObject_repr(PyObject *self) { JP_PY_TRY("PyJPObject_repr"); return PyUnicode_FromFormat("", Py_TYPE(self)->tp_name); - JP_PY_CATCH(0); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static PyType_Slot objectSlots[] = { @@ -227,7 +227,7 @@ static PyType_Slot objectSlots[] = { {0} }; -PyTypeObject *PyJPObject_Type = NULL; +PyTypeObject *PyJPObject_Type = nullptr; static PyType_Spec objectSpec = { "_jpype._JObject", 0, @@ -241,10 +241,10 @@ static PyObject *PyJPException_new(PyTypeObject *type, PyObject *pyargs, PyObjec JP_PY_TRY("PyJPException_new"); // Get the Java class from the type. JPClass *cls = PyJPClass_getJPClass((PyObject*) type); - if (cls == NULL) + if (cls == nullptr) { // GCOVR_EXCL_START PyErr_SetString(PyExc_TypeError, "Java class type is incorrect"); - return NULL; + return nullptr; } // GCOVR_EXCL_STOP // Special constructor path for Exceptions @@ -264,7 +264,7 @@ static PyObject *PyJPException_new(PyTypeObject *type, PyObject *pyargs, PyObjec JP_FAULT_RETURN("PyJPException_init.null", self); PyJPValue_assignJavaSlot(frame, self, jv); return self; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static int PyJPException_init(PyObject *self, PyObject *pyargs, PyObject *kwargs) @@ -289,15 +289,15 @@ static PyObject* PyJPException_expandStacktrace(PyObject* self) // These two are loop invariants and must match each time auto th = (jthrowable) val->getValue().l; JPPyObject exc = JPPyObject::use(self); - PyJPException_normalize(frame, exc, th, NULL); + PyJPException_normalize(frame, exc, th, nullptr); Py_RETURN_NONE; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } PyObject *PyJPException_args(PyBaseExceptionObject *self) { - if (self->args == NULL) + if (self->args == nullptr) Py_RETURN_NONE; // GCOVR_EXCL_LINE Py_INCREF(self->args); return self->args; @@ -305,15 +305,15 @@ PyObject *PyJPException_args(PyBaseExceptionObject *self) static PyMethodDef exceptionMethods[] = { {"_expandStacktrace", (PyCFunction) PyJPException_expandStacktrace, METH_NOARGS, ""}, - {NULL}, + {nullptr}, }; static PyGetSetDef exceptionGetSets[] = { - {"_args", (getter) PyJPException_args, NULL, ""}, - {0} + {"_args", (getter) PyJPException_args, nullptr, ""}, + {nullptr} }; -PyTypeObject *PyJPException_Type = NULL; +PyTypeObject *PyJPException_Type = nullptr; static PyType_Slot excSlots[] = { {Py_tp_new, (void*) &PyJPException_new}, {Py_tp_init, (void*) &PyJPException_init}, @@ -339,7 +339,7 @@ static PyType_Slot comparableSlots[] = { {0} }; -PyTypeObject *PyJPComparable_Type = NULL; +PyTypeObject *PyJPComparable_Type = nullptr; static PyType_Spec comparableSpec = { "_jpype._JComparable", 0, @@ -354,7 +354,7 @@ static PyType_Spec comparableSpec = { void PyJPObject_initType(PyObject* module) { - PyJPObject_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&objectSpec, NULL); + PyJPObject_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&objectSpec, nullptr); JP_PY_CHECK(); // GCOVR_EXCL_LINE PyModule_AddObject(module, "_JObject", (PyObject*) PyJPObject_Type); JP_PY_CHECK(); // GCOVR_EXCL_LINE @@ -379,7 +379,7 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j { JP_TRACE_IN("PyJPException_normalize"); JPContext *context = frame.getContext(); - while (th != NULL) + while (th != nullptr) { // Attach the frame to first JPPyObject trace = PyTrace_FromJavaException(frame, th, enclosing); @@ -388,7 +388,7 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j // Check for the next in the cause list enclosing = th; th = frame.getCause(th); - if (th == NULL) + if (th == nullptr) return; jvalue v; v.l = (jobject) th; @@ -396,7 +396,7 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j // This may already be a Python exception JPValue *val = PyJPValue_getJavaSlot(next.get()); - if (val == NULL) + if (val == nullptr) { PyException_SetCause(exc.get(), next.keep()); return; diff --git a/native/python/pyjp_package.cpp b/native/python/pyjp_package.cpp index 5a00740f7..67cd17e3a 100644 --- a/native/python/pyjp_package.cpp +++ b/native/python/pyjp_package.cpp @@ -22,47 +22,47 @@ extern "C" { #endif -PyTypeObject *PyJPPackage_Type = NULL; -static PyObject *PyJPPackage_Dict = NULL; +PyTypeObject *PyJPPackage_Type = nullptr; +static PyObject *PyJPPackage_Dict = nullptr; static PyObject *PyJPPackage_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPPackage_new"); - PyObject *name = NULL; + PyObject *name = nullptr; if (!PyArg_Parse(args, "(U)", &name)) - return 0; + return nullptr; // Check the cache PyObject *obj = PyDict_GetItem(PyJPPackage_Dict, name); - if (obj != NULL) + if (obj != nullptr) { Py_INCREF(obj); return obj; } // Otherwise create a new object - PyObject *self = PyModule_Type.tp_new(PyJPPackage_Type, args, NULL); - int rc = PyModule_Type.tp_init(self, args, NULL); + PyObject *self = PyModule_Type.tp_new(PyJPPackage_Type, args, nullptr); + int rc = PyModule_Type.tp_init(self, args, nullptr); if (rc != 0) { // If we fail clean up the mess. Py_DECREF(self); - return 0; + return nullptr; } // Place in cache PyDict_SetItem(PyJPPackage_Dict, name, self); return self; - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } static void dtor(PyObject *self) { JPContext *context = JPContext_global; - if (context == NULL || !context->isRunning()) + if (context == nullptr || !context->isRunning()) return; - auto jo = (jobject) PyCapsule_GetPointer(self, NULL); - if (jo == NULL) + auto jo = (jobject) PyCapsule_GetPointer(self, nullptr); + if (jo == nullptr) return; JPJavaFrame frame = JPJavaFrame::outer(context); frame.DeleteGlobalRef(jo); @@ -73,9 +73,9 @@ static jobject getPackage(JPJavaFrame &frame, PyObject *self) PyObject *dict = PyModule_GetDict(self); // borrowed PyObject *capsule = PyDict_GetItemString(dict, "_jpackage"); // borrowed jobject jo; - if (capsule != NULL) + if (capsule != nullptr) { - jo = (jobject) PyCapsule_GetPointer(capsule, NULL); + jo = (jobject) PyCapsule_GetPointer(capsule, nullptr); return jo; } @@ -84,10 +84,10 @@ static jobject getPackage(JPJavaFrame &frame, PyObject *self) jo = frame.getPackage(name); // Found it, use it. - if (jo != NULL) + if (jo != nullptr) { jo = frame.NewGlobalRef(jo); - capsule = PyCapsule_New(jo, NULL, dtor); + capsule = PyCapsule_New(jo, nullptr, dtor); PyDict_SetItemString(dict, "_jpackage", capsule); // no steal // Py_DECREF(capsule); return jo; @@ -95,7 +95,7 @@ static jobject getPackage(JPJavaFrame &frame, PyObject *self) // Otherwise, this is a bad package. PyErr_Format(PyExc_AttributeError, "Java package '%s' is not valid", name); - return NULL; + return nullptr; } /** @@ -115,15 +115,15 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) if (!PyUnicode_Check(attr)) { PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%s'", Py_TYPE(attr)->tp_name); - return NULL; + return nullptr; } PyObject *dict = PyModule_GetDict(self); - if (dict != NULL) + if (dict != nullptr) { // Check the cache PyObject *out = PyDict_GetItem(PyModule_GetDict(self), attr); - if (out != NULL) + if (out != nullptr) { Py_INCREF(out); return out; @@ -141,12 +141,12 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) PyErr_Format(PyExc_RuntimeError, "Unable to import '%s.%U' without JVM", PyModule_GetName(self), attr); - return 0; + return nullptr; } JPJavaFrame frame = JPJavaFrame::outer(context); jobject pkg = getPackage(frame, self); - if (pkg == NULL) - return NULL; + if (pkg == nullptr) + return nullptr; JPPyObject out; jobject obj; @@ -164,18 +164,18 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) err.normalize(); err.clear(); JPPyObject tuple0 = JPPyObject::call(PyTuple_Pack(3, self, attr, err.m_ExceptionValue.get())); - PyObject *rc = PyObject_Call(h.get(), tuple0.get(), NULL); - if (rc == 0) - return 0; + PyObject *rc = PyObject_Call(h.get(), tuple0.get(), nullptr); + if (rc == nullptr) + return nullptr; Py_DECREF(rc); // GCOVR_EXCL_LINE } throw; // GCOVR_EXCL_LINE } - if (obj == NULL) + if (obj == nullptr) { PyErr_Format(PyExc_AttributeError, "Java package '%s' has no attribute '%U'", PyModule_GetName(self), attr); - return NULL; + return nullptr; } else if (frame.IsInstanceOf(obj, context->_java_lang_Class->getJavaClass())) out = PyJPClass_create(frame, frame.findClass((jclass) obj)); else if (frame.IsInstanceOf(obj, context->_java_lang_String->getJavaClass())) @@ -183,7 +183,7 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) JPPyObject u = JPPyObject::call(PyUnicode_FromFormat("%s.%U", PyModule_GetName(self), attr)); JPPyObject args = JPPyObject::call(PyTuple_Pack(1, u.get())); - out = JPPyObject::call(PyObject_Call((PyObject*) PyJPPackage_Type, args.get(), NULL)); + out = JPPyObject::call(PyObject_Call((PyObject*) PyJPPackage_Type, args.get(), nullptr)); } else { // We should be able to handle Python classes, datafiles, etc, @@ -191,12 +191,12 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) // that are not packages or classes should appear as Buffers or // some other resource type. PyErr_Format(PyExc_AttributeError, "'%U' is unknown object type in Java package", attr); - return NULL; + return nullptr; } // Cache the item for now PyDict_SetItem(dict, attr, out.get()); // no steal return out.keep(); - JP_PY_CATCH(NULL); // GCOVR_EXCL_LINE + JP_PY_CATCH(nullptr); // GCOVR_EXCL_LINE } /** @@ -218,21 +218,21 @@ static PyObject *PyJPPackage_str(PyObject *self, PyObject *args, PyObject *kwarg { JP_PY_TRY("PyJPPackage_str"); return PyModule_GetNameObject(self); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPPackage_repr(PyObject *self, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPPackage_repr"); return PyUnicode_FromFormat("", PyModule_GetName(self)); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPPackage_call(PyObject *self, PyObject *args, PyObject *kwargs) { JP_PY_TRY("PyJPPackage_call"); PyErr_Format(PyExc_TypeError, "Package `%s` is not callable.", PyModule_GetName(self)); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static PyObject *PyJPPackage_package(PyObject *self) @@ -251,8 +251,8 @@ static PyObject *PyJPPackage_dir(PyObject *self) JPContext* context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); jobject pkg = getPackage(frame, self); - if (pkg == NULL) - return NULL; + if (pkg == nullptr) + return nullptr; jarray o = frame.getPackageContents(pkg); Py_ssize_t len = frame.GetArrayLength(o); @@ -264,7 +264,7 @@ static PyObject *PyJPPackage_dir(PyObject *self) PyList_SetItem(out.get(), i, PyUnicode_FromFormat("%s", str.c_str())); } return out.keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } /** @@ -282,30 +282,30 @@ static PyObject *PyJPPackage_cast(PyObject *self, PyObject *other) JP_PY_TRY("PyJPPackage_cast"); PyObject *dict = PyModule_GetDict(self); PyObject* matmul = PyDict_GetItemString(dict, "__matmul__"); - if (matmul == NULL) + if (matmul == nullptr) Py_RETURN_NOTIMPLEMENTED; JPPyObject args = JPPyObject::call(PyTuple_Pack(2, self, other)); - return PyObject_Call(matmul, args.get(), NULL); - JP_PY_CATCH(NULL); + return PyObject_Call(matmul, args.get(), nullptr); + JP_PY_CATCH(nullptr); } static PyObject *PyJPPackage_castEq(PyObject *self, PyObject *other) { PyErr_Format(PyExc_TypeError, "Matmul equals not support for Java packages"); - return NULL; + return nullptr; } static PyMethodDef packageMethods[] = { {"__dir__", (PyCFunction) PyJPPackage_dir, METH_NOARGS}, - {NULL}, + {nullptr}, }; static PyGetSetDef packageGetSets[] = { - {"__all__", (getter) PyJPPackage_dir, NULL, ""}, - {"__name__", (getter) PyJPPackage_str, NULL, ""}, - {"__package__", (getter) PyJPPackage_package, NULL, ""}, - {"__path__", (getter) PyJPPackage_path, NULL, ""}, - {0} + {"__all__", (getter) PyJPPackage_dir, nullptr, ""}, + {"__name__", (getter) PyJPPackage_str, nullptr, ""}, + {"__package__", (getter) PyJPPackage_package, nullptr, ""}, + {"__path__", (getter) PyJPPackage_path, nullptr, ""}, + {nullptr} }; static PyType_Slot packageSlots[] = { diff --git a/native/python/pyjp_proxy.cpp b/native/python/pyjp_proxy.cpp index 249e11fce..48603bbc5 100644 --- a/native/python/pyjp_proxy.cpp +++ b/native/python/pyjp_proxy.cpp @@ -38,13 +38,13 @@ static PyObject *PyJPProxy_new(PyTypeObject *type, PyObject *args, PyObject *kwa PyObject *pyintf; int convert = 0; if (!PyArg_ParseTuple(args, "OO|p", &target, &pyintf, &convert)) - return NULL; + return nullptr; // Pack interfaces if (!PySequence_Check(pyintf)) { PyErr_SetString(PyExc_TypeError, "third argument must be a list of interface"); - return NULL; + return nullptr; } JPClassList interfaces; @@ -56,10 +56,10 @@ static PyObject *PyJPProxy_new(PyTypeObject *type, PyObject *args, PyObject *kwa for (jlong i = 0; i < len; i++) { JPClass *cls = PyJPClass_getJPClass(intf[i].get()); - if (cls == NULL) + if (cls == nullptr) { PyErr_SetString(PyExc_TypeError, "interfaces must be object class instances"); - return NULL; + return nullptr; } interfaces.push_back(cls); } @@ -75,7 +75,7 @@ static PyObject *PyJPProxy_new(PyTypeObject *type, PyObject *args, PyObject *kwa JP_TRACE("Proxy", self); JP_TRACE("Target", target); return (PyObject*) self; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } static int PyJPProxy_traverse(PyJPProxy *self, visitproc visit, void *arg) @@ -139,13 +139,13 @@ static PyMethodDef proxyMethods[] = { {"equals", (PyCFunction) (&PyJPProxy_equals), METH_O, ""}, {"hashCode", (PyCFunction) (&PyJPProxy_hash), METH_NOARGS, ""}, {"toString", (PyCFunction) (&PyJPProxy_toString), METH_NOARGS, ""}, - {NULL}, + {nullptr}, }; static PyGetSetDef proxyGetSets[] = { - {"__javainst__", (getter) PyJPProxy_inst, NULL, ""}, - {"__javaclass__", (getter) PyJPProxy_class, NULL, ""}, - {0} + {"__javainst__", (getter) PyJPProxy_inst, nullptr, ""}, + {"__javaclass__", (getter) PyJPProxy_class, nullptr, ""}, + {nullptr} }; static PyType_Slot proxySlots[] = { @@ -158,7 +158,7 @@ static PyType_Slot proxySlots[] = { {0} }; -PyTypeObject *PyJPProxy_Type = NULL; +PyTypeObject *PyJPProxy_Type = nullptr; PyType_Spec PyJPProxySpec = { "_jpype._JProxy", sizeof (PyJPProxy), @@ -184,5 +184,5 @@ JPProxy *PyJPProxy_getJPProxy(PyObject* obj) { if (PyObject_IsInstance(obj, (PyObject*) PyJPProxy_Type)) return ((PyJPProxy*) obj)->m_Proxy; - return NULL; + return nullptr; } diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index 8d9b143bf..b8d4273b6 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -44,7 +44,7 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) const size_t size = _PyObject_VAR_SIZE(type, nitems + 1) + sizeof (JPValue); PyObject *obj = (PyType_IS_GC(type)) ? _PyObject_GC_Malloc(size) : (PyObject *) PyObject_MALLOC(size); - if (obj == NULL) + if (obj == nullptr) return PyErr_NoMemory(); // GCOVR_EXCL_LINE memset(obj, 0, size); @@ -66,12 +66,12 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) } JP_TRACE("alloc", type->tp_name, obj); return obj; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } bool PyJPValue_hasJavaSlot(PyTypeObject* type) { - if (type == NULL + if (type == nullptr || type->tp_alloc != (allocfunc) PyJPValue_alloc || type->tp_finalize != (destructor) PyJPValue_finalize) return false; // GCOVR_EXCL_LINE @@ -81,7 +81,7 @@ bool PyJPValue_hasJavaSlot(PyTypeObject* type) Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self) { PyTypeObject *type = Py_TYPE(self); - if (type == NULL + if (type == nullptr || type->tp_alloc != (allocfunc) PyJPValue_alloc || type->tp_finalize != (destructor) PyJPValue_finalize) return 0; @@ -109,10 +109,10 @@ JPValue* PyJPValue_getJavaSlot(PyObject* self) { Py_ssize_t offset = PyJPValue_getJavaSlotOffset(self); if (offset == 0) - return NULL; + return nullptr; auto* value = (JPValue*) (((char*) self) + offset); - if (value->getClass() == NULL) - return NULL; + if (value->getClass() == nullptr) + return nullptr; return value; } @@ -121,7 +121,7 @@ void PyJPValue_free(void* obj) JP_PY_TRY("PyJPValue_free", obj); // Normally finalize is not run on simple classes. PyTypeObject *type = Py_TYPE(obj); - if (type->tp_finalize != NULL) + if (type->tp_finalize != nullptr) type->tp_finalize((PyObject*) obj); if (type->tp_flags & Py_TPFLAGS_HAVE_GC) PyObject_GC_Del(obj); @@ -135,16 +135,16 @@ void PyJPValue_finalize(void* obj) JP_PY_TRY("PyJPValue_finalize", obj); JP_TRACE("type", Py_TYPE(obj)->tp_name); JPValue* value = PyJPValue_getJavaSlot((PyObject*) obj); - if (value == NULL) + if (value == nullptr) return; JPContext *context = JPContext_global; - if (context == NULL || !context->isRunning()) + if (context == nullptr || !context->isRunning()) return; JPJavaFrame frame = JPJavaFrame::outer(context); JPClass* cls = value->getClass(); // This one can't check for initialized because we may need to delete a stale // resource after shutdown. - if (cls != NULL && context->isRunning() && !cls->isPrimitive()) + if (cls != nullptr && context->isRunning() && !cls->isPrimitive()) { JP_TRACE("Value", cls->getCanonicalName(), &(value->getValue())); JP_TRACE("Dereference object"); @@ -161,26 +161,26 @@ PyObject* PyJPValue_str(PyObject* self) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue* value = PyJPValue_getJavaSlot(self); - if (value == NULL) + if (value == nullptr) { PyErr_SetString(PyExc_TypeError, "Not a Java value"); - return NULL; + return nullptr; } JPClass* cls = value->getClass(); if (cls->isPrimitive()) { PyErr_SetString(PyExc_TypeError, "toString requires a Java object"); - return NULL; + return nullptr; } - if (value->getValue().l == NULL) + if (value->getValue().l == nullptr) return JPPyString::fromStringUTF8("null").keep(); if (cls == context->_java_lang_String) { PyObject *cache; - JPPyObject dict = JPPyObject::accept(PyObject_GenericGetDict(self, NULL)); + JPPyObject dict = JPPyObject::accept(PyObject_GenericGetDict(self, nullptr)); if (!dict.isNull()) { cache = PyDict_GetItemString(dict.get(), "_jstr"); @@ -200,7 +200,7 @@ PyObject* PyJPValue_str(PyObject* self) // In general toString is not immutable, so we won't cache it. return JPPyString::fromStringUTF8(frame.toString(value->getValue().l)).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name) @@ -211,13 +211,13 @@ PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name) PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", Py_TYPE(name)->tp_name); - return NULL; + return nullptr; } // Private members are accessed directly PyObject* pyattr = PyBaseObject_Type.tp_getattro(obj, name); - if (pyattr == NULL) - return NULL; + if (pyattr == nullptr) + return nullptr; JPPyObject attr = JPPyObject::accept(pyattr); // Private members go regardless @@ -233,8 +233,8 @@ PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name) return attr.keep(); PyErr_Format(PyExc_AttributeError, "Field '%U' is static", name); - return NULL; - JP_PY_CATCH(NULL); + return nullptr; + JP_PY_CATCH(nullptr); } int PyJPValue_setattro(PyObject *self, PyObject *name, PyObject *value) @@ -251,7 +251,7 @@ int PyJPValue_setattro(PyObject *self, PyObject *name, PyObject *value) return -1; } descrsetfunc desc = Py_TYPE(f.get())->tp_descr_set; - if (desc != NULL) + if (desc != nullptr) return desc(f.get(), self, value); // Not a descriptor @@ -282,13 +282,13 @@ void PyJPValue_assignJavaSlot(JPJavaFrame &frame, PyObject* self, const JPValue& auto* slot = (JPValue*) (((char*) self) + offset); // GCOVR_EXCL_START // This is a sanity check that should never trigger in normal operations. - if (slot->getClass() != NULL) + if (slot->getClass() != nullptr) { JP_RAISE(PyExc_SystemError, "Slot assigned twice"); } // GCOVR_EXCL_STOP JPClass* cls = value.getClass(); - if (cls != NULL && !cls->isPrimitive()) + if (cls != nullptr && !cls->isPrimitive()) { jvalue q; q.l = frame.NewGlobalRef(value.getValue().l); @@ -303,5 +303,5 @@ bool PyJPValue_isSetJavaSlot(PyObject* self) if (offset == 0) return false; // GCOVR_EXCL_LINE auto* slot = (JPValue*) (((char*) self) + offset); - return slot->getClass() != NULL; + return slot->getClass() != nullptr; } \ No newline at end of file From c07c3078b8b2927993532212b77f509381a47ede Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 14:43:41 +0200 Subject: [PATCH 013/128] typos --- native/common/include/jp_exception.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 19d9b22ce..7c5c6fb7b 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -19,22 +19,22 @@ /* All exception are passed as JPypeException. The type of the exception * is specified at creation. Exceptions may be of type * - _java_error - exception generated from within java. - * - _python_error - excepction generated from within python. + * - _python_error - exception generated from within python. * - _runtime_error - Failure that will issue a runtime error in python and java. * - _type_error - Failure that will issue a type error in python. * * We must throw the correct exception so that it can properly be handled - * when returning back to the native code. + * when returning to the native code. * * If we are returning to python, and it is a * - _python_error, then we assume that a python exception has already been * placed in the python virtual machine. - * - _java_error, then we will covert it to a python object with the correct + * - _java_error, then we will convert it to a python object with the correct * object type. * - otherwise, then we will convert it to the requested python error. * * If we are returning to java, and it is a - * - _java_error, they we assume there is already an Java exception queue + * - _java_error, then we assume there is already a Java exception queue * in the virtual machine. * - otherwise convert to a RuntimeException. * From ad7807b65ac5c702c7a8bffc2b3c64ebdbd4a39e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:01:17 +0200 Subject: [PATCH 014/128] JPPrimitiveType explicit ctor (std:string& name) --- native/common/include/jp_primitivetype.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/common/include/jp_primitivetype.h b/native/common/include/jp_primitivetype.h index e0a7514d1..35d3e5e87 100644 --- a/native/common/include/jp_primitivetype.h +++ b/native/common/include/jp_primitivetype.h @@ -20,7 +20,7 @@ class JPPrimitiveType : public JPClass { protected: - JPPrimitiveType(const string& name); + explicit JPPrimitiveType(const string& name); ~JPPrimitiveType() override; public: From 55ec01fc1682e2370445964f13515c2748d95ca7 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:07:19 +0200 Subject: [PATCH 015/128] jpype.h remove duplicated included headers. Use nullptr in JP_RAISE --- native/common/include/jpype.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index ca5dd8cbe..6c26cb0c1 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -65,7 +65,6 @@ #include #include #include -#include #include #include #include @@ -175,10 +174,10 @@ class JPResource // These must be macros so that we can update the pattern and // maintain the appropriate auditing information. C++ does not // have a lot for facilities to make this easy. -#define JP_RAISE_PYTHON() { throw JPypeException(JPError::_python_error, NULL, JP_STACKINFO()); } +#define JP_RAISE_PYTHON() { throw JPypeException(JPError::_python_error, nullptr, JP_STACKINFO()); } #define JP_RAISE_OS_ERROR_UNIX(err, msg) { throw JPypeException(JPError::_os_error_unix, msg, err, JP_STACKINFO()); } #define JP_RAISE_OS_ERROR_WINDOWS(err, msg) { throw JPypeException(JPError::_os_error_windows, msg, err, JP_STACKINFO()); } -#define JP_RAISE_METHOD_NOT_FOUND(msg) { throw JPypeException(JPError::_method_not_found, NULL, msg, JP_STACKINFO()); } +#define JP_RAISE_METHOD_NOT_FOUND(msg) { throw JPypeException(JPError::_method_not_found, nullptr, msg, JP_STACKINFO()); } #define JP_RAISE(type, msg) { throw JPypeException(JPError::_python_exc, type, msg, JP_STACKINFO()); } #ifndef PyObject_HEAD @@ -205,6 +204,5 @@ using PyObject = _object; // Primitives classes #include "jp_primitivetype.h" -#include "jp_typemanager.h" #endif // _JPYPE_H_ \ No newline at end of file From 390efa6796b7e03705ac9f31f7f391dc263bd4de Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:15:51 +0200 Subject: [PATCH 016/128] use initializer to avoid code duplication --- native/common/include/jp_context.h | 126 ++++++++++++++--------------- native/common/jp_context.cpp | 68 +--------------- 2 files changed, 64 insertions(+), 130 deletions(-) diff --git a/native/common/include/jp_context.h b/native/common/include/jp_context.h index a997f59e4..f6ba2ffbb 100644 --- a/native/common/include/jp_context.h +++ b/native/common/include/jp_context.h @@ -170,52 +170,52 @@ class JPContext } // Java type resources - JPPrimitiveType* _void; - JPPrimitiveType* _boolean; - JPPrimitiveType* _byte; - JPPrimitiveType* _char; - JPPrimitiveType* _short; - JPPrimitiveType* _int; - JPPrimitiveType* _long; - JPPrimitiveType* _float; - JPPrimitiveType* _double; - - JPBoxedType* _java_lang_Void; - JPBoxedType* _java_lang_Boolean; - JPBoxedType* _java_lang_Byte; - JPBoxedType* _java_lang_Character; - JPBoxedType* _java_lang_Short; - JPBoxedType* _java_lang_Integer; - JPBoxedType* _java_lang_Long; - JPBoxedType* _java_lang_Float; - JPBoxedType* _java_lang_Double; - - JPClass* _java_lang_Object; - JPClass* _java_lang_Class; - JPClass* _java_lang_reflect_Field; - JPClass* _java_lang_reflect_Method; - JPClass* _java_lang_Throwable; - JPStringType* _java_lang_String; - JPClass* _java_nio_ByteBuffer; + JPPrimitiveType* _void{}; + JPPrimitiveType* _boolean{}; + JPPrimitiveType* _byte{}; + JPPrimitiveType* _char{}; + JPPrimitiveType* _short{}; + JPPrimitiveType* _int{}; + JPPrimitiveType* _long{}; + JPPrimitiveType* _float{}; + JPPrimitiveType* _double{}; + + JPBoxedType* _java_lang_Void{}; + JPBoxedType* _java_lang_Boolean{}; + JPBoxedType* _java_lang_Byte{}; + JPBoxedType* _java_lang_Character{}; + JPBoxedType* _java_lang_Short{}; + JPBoxedType* _java_lang_Integer{}; + JPBoxedType* _java_lang_Long{}; + JPBoxedType* _java_lang_Float{}; + JPBoxedType* _java_lang_Double{}; + + JPClass* _java_lang_Object{}; + JPClass* _java_lang_Class{}; + JPClass* _java_lang_reflect_Field{}; + JPClass* _java_lang_reflect_Method{}; + JPClass* _java_lang_Throwable{}; + JPStringType* _java_lang_String{}; + JPClass* _java_nio_ByteBuffer{}; private: void loadEntryPoints(const string& path); - jint(JNICALL * CreateJVM_Method)(JavaVM **pvm, void **penv, void *args); - jint(JNICALL * GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize * nVms); + jint(JNICALL * CreateJVM_Method)(JavaVM **pvm, void **penv, void *args){}; + jint(JNICALL * GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize * nVms){}; private: JPContext(const JPContext& orig); - JavaVM *m_JavaVM; + JavaVM *m_JavaVM{}; // Java half JPObjectRef m_JavaContext; // Services - JPTypeManager *m_TypeManager; - JPClassLoader *m_ClassLoader; + JPTypeManager *m_TypeManager{}; + JPClassLoader *m_ClassLoader{}; public: JPClassRef m_ContextClass; @@ -226,43 +226,43 @@ class JPContext JPClassRef m_Array; // Java Functions - jmethodID m_Object_ToStringID; - jmethodID m_Object_EqualsID; - jmethodID m_Object_HashCodeID; - jmethodID m_CallMethodID; - jmethodID m_Class_GetNameID; - jmethodID m_Context_collectRectangularID; - jmethodID m_Context_assembleID; - jmethodID m_String_ToCharArrayID; - jmethodID m_Context_CreateExceptionID; - jmethodID m_Context_GetExcClassID; - jmethodID m_Context_GetExcValueID; - jmethodID m_Context_ClearInterruptID; - jmethodID m_CompareToID; - jmethodID m_Buffer_IsReadOnlyID; - jmethodID m_Context_OrderID; - jmethodID m_Object_GetClassID; - jmethodID m_Array_NewInstanceID; - jmethodID m_Throwable_GetCauseID; - jmethodID m_Throwable_GetMessageID; - jmethodID m_Context_GetFunctionalID; + jmethodID m_Object_ToStringID{}; + jmethodID m_Object_EqualsID{}; + jmethodID m_Object_HashCodeID{}; + jmethodID m_CallMethodID{}; + jmethodID m_Class_GetNameID{}; + jmethodID m_Context_collectRectangularID{}; + jmethodID m_Context_assembleID{}; + jmethodID m_String_ToCharArrayID{}; + jmethodID m_Context_CreateExceptionID{}; + jmethodID m_Context_GetExcClassID{}; + jmethodID m_Context_GetExcValueID{}; + jmethodID m_Context_ClearInterruptID{}; + jmethodID m_CompareToID{}; + jmethodID m_Buffer_IsReadOnlyID{}; + jmethodID m_Context_OrderID{}; + jmethodID m_Object_GetClassID{}; + jmethodID m_Array_NewInstanceID{}; + jmethodID m_Throwable_GetCauseID{}; + jmethodID m_Throwable_GetMessageID{}; + jmethodID m_Context_GetFunctionalID{}; friend class JPProxy; JPClassRef m_ProxyClass; - jmethodID m_Proxy_NewID; - jmethodID m_Proxy_NewInstanceID; - - jmethodID m_Context_IsPackageID; - jmethodID m_Context_GetPackageID; - jmethodID m_Package_GetObjectID; - jmethodID m_Package_GetContentsID; - jmethodID m_Context_NewWrapperID; + jmethodID m_Proxy_NewID{}; + jmethodID m_Proxy_NewInstanceID{}; + + jmethodID m_Context_IsPackageID{}; + jmethodID m_Context_GetPackageID{}; + jmethodID m_Package_GetObjectID{}; + jmethodID m_Package_GetContentsID{}; + jmethodID m_Context_NewWrapperID{}; public: - jmethodID m_Context_GetStackFrameID; + jmethodID m_Context_GetStackFrameID{}; void onShutdown(); private: - bool m_Running; - bool m_ConvertStrings; + bool m_Running{}; + bool m_ConvertStrings{}; bool m_Embedded; public: JPGarbageCollection *m_GC; diff --git a/native/common/jp_context.cpp b/native/common/jp_context.cpp index f0412d6bd..764d3fd19 100644 --- a/native/common/jp_context.cpp +++ b/native/common/jp_context.cpp @@ -16,25 +16,13 @@ #include "jpype.h" #include "pyjp.h" #include "jp_typemanager.h" -#include "jp_boxedtype.h" #include "jp_stringtype.h" #include "jp_classloader.h" -#include "jp_voidtype.h" -#include "jp_booleantype.h" -#include "jp_bytetype.h" -#include "jp_chartype.h" -#include "jp_shorttype.h" -#include "jp_inttype.h" -#include "jp_longtype.h" -#include "jp_floattype.h" -#include "jp_doubletype.h" #include "jp_proxy.h" #include "jp_platform.h" #include "jp_gc.h" -JPResource::~JPResource() -{ -} +JPResource::~JPResource() = default; #define USE_JNI_VERSION JNI_VERSION_1_4 @@ -46,60 +34,6 @@ void JPRef_failed() JPContext::JPContext() { - m_JavaVM = nullptr; - _void = nullptr; - _byte = nullptr; - _boolean = nullptr; - _char = nullptr; - _short = nullptr; - _int = nullptr; - _long = nullptr; - _float = nullptr; - _double = nullptr; - - _java_lang_Void = nullptr; - _java_lang_Boolean = nullptr; - _java_lang_Byte = nullptr; - _java_lang_Character = nullptr; - _java_lang_Short = nullptr; - _java_lang_Integer = nullptr; - _java_lang_Long = nullptr; - _java_lang_Float = nullptr; - _java_lang_Double = nullptr; - - _java_lang_Object = nullptr; - _java_lang_Class = nullptr; - _java_lang_String = nullptr; - - _java_lang_reflect_Method = nullptr; - _java_lang_reflect_Field = nullptr; - _java_nio_ByteBuffer = nullptr; - - m_TypeManager = nullptr; - m_ClassLoader = nullptr; - - m_Object_ToStringID = nullptr; - m_Object_EqualsID = nullptr; - m_Running = false; - - // Java Functions - m_Object_ToStringID = nullptr; - m_Object_EqualsID = nullptr; - m_Object_HashCodeID = nullptr; - m_CallMethodID = nullptr; - m_Class_GetNameID = nullptr; - m_Context_collectRectangularID = nullptr; - m_Context_assembleID = nullptr; - m_String_ToCharArrayID = nullptr; - m_Context_CreateExceptionID = nullptr; - m_Context_GetExcClassID = nullptr; - m_Context_GetExcValueID = nullptr; - m_CompareToID = nullptr; - m_Buffer_IsReadOnlyID = nullptr; - m_Context_OrderID = nullptr; - m_Object_GetClassID = nullptr; - m_Throwable_GetCauseID = nullptr; - m_Context_GetStackFrameID = nullptr; m_Embedded = false; m_GC = new JPGarbageCollection(this); From e143934436086698d833fa8ff23a7da52a469241 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:32:25 +0200 Subject: [PATCH 017/128] do not polute jpype.h with stringstream, iostream etc. --- native/common/include/jpype.h | 7 +++---- native/common/jp_exception.cpp | 21 ++++++++------------- native/common/jp_method.cpp | 2 +- native/common/jp_methoddispatch.cpp | 2 +- native/common/jp_platform.cpp | 2 +- native/common/jp_tracer.cpp | 14 +++++++------- 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index 6c26cb0c1..00844cee1 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -62,9 +62,8 @@ #include #include -#include #include -#include +//#include #include #include #include @@ -72,10 +71,10 @@ using std::map; using std::string; using std::stringstream; -using std::cout; +/*using std::cout; using std::cerr; using std::endl; -using std::vector; +*/using std::vector; using std::list; #ifdef JP_INSTRUMENTATION diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 3281af32c..4d0992d0a 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -18,7 +18,6 @@ #include "jpype.h" #include "jp_exception.h" #include "pyjp.h" -#include "jp_reference_queue.h" PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace); @@ -83,10 +82,6 @@ JPypeException& JPypeException::operator = (const JPypeException& ex) } // GCOVR_EXCL_STOP -JPypeException::~JPypeException() -{ -} - void JPypeException::from(const JPStackInfo& info) { JP_TRACE("EXCEPTION FROM: ", info.getFile(), info.getLine()); @@ -111,8 +106,8 @@ string JPypeException::getMessage() // Must be bullet proof try { - stringstream str; - str << m_Message << endl; + std::stringstream str; + str << m_Message << std::endl; JP_TRACE(str.str()); return str.str(); // GCOVR_EXCL_START @@ -563,10 +558,10 @@ PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace) { PyTracebackObject *last_traceback = nullptr; PyObject *dict = PyModule_GetDict(PyJPModule); - for (auto iter = trace.begin(); iter != trace.end(); ++iter) + for (auto & iter : trace) { - last_traceback = tb_create(last_traceback, dict, iter->getFile(), - iter->getFunction(), iter->getLine()); + last_traceback = tb_create(last_traceback, dict, iter.getFile(), + iter.getFunction(), iter.getLine()); } if (last_traceback == nullptr) Py_RETURN_NONE; @@ -581,7 +576,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab args[0].l = th; args[1].l = prev; if (context->m_Context_GetStackFrameID == nullptr) - return JPPyObject(); + return {}; JNIEnv* env = frame.getEnv(); auto obj = (jobjectArray) env->CallObjectMethodA(context->getJavaContext(), @@ -592,7 +587,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab env->ExceptionClear(); if (obj == nullptr) - return JPPyObject(); + return {}; jsize sz = frame.GetArrayLength(obj); PyObject *dict = PyModule_GetDict(PyJPModule); for (jsize i = 0; i < sz; i += 4) @@ -617,6 +612,6 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab frame.DeleteLocalRef(jfilename); } if (last_traceback == nullptr) - return JPPyObject(); + return {}; return JPPyObject::call((PyObject*) last_traceback); } diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index 0dddcfd23..2196dd463 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -380,7 +380,7 @@ string JPMethod::matchReport(JPPyObjectVector& args) break; } // GCOVR_EXCL_STOP - res << endl; + res << std::endl; return res.str(); } diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index e858e1faa..dcc5a4815 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -227,7 +227,7 @@ bool JPMethodDispatch::matches(JPJavaFrame& frame, JPPyObjectVector& args, bool string JPMethodDispatch::matchReport(JPPyObjectVector& args) { stringstream res; - res << "Match report for method " << m_Name << ", has " << m_Overloads.size() << " overloads." << endl; + res << "Match report for method " << m_Name << ", has " << m_Overloads.size() << " overloads." << std::endl; for (auto cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index 028bd082e..0de7fc674 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -144,7 +144,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter // GCOVR_EXCL_START if (r != 0) // error { - cerr << dlerror() << endl; + std::cerr << dlerror() << std::endl; } // GCOVR_EXCL_STOP JP_TRACE_OUT; // GCOVR_EXCL_LINE diff --git a/native/common/jp_tracer.cpp b/native/common/jp_tracer.cpp index 0b7e73f88..6a158182d 100644 --- a/native/common/jp_tracer.cpp +++ b/native/common/jp_tracer.cpp @@ -48,7 +48,7 @@ static JPypeTracer* jpype_tracer_last = nullptr; std::mutex trace_lock; -#define JPYPE_TRACING_OUTPUT cerr +#define JPYPE_TRACING_OUTPUT std::cerr static int INDENT_WIDTH = 2; static const char *INDENT = " "; @@ -94,7 +94,7 @@ void JPypeTracer::traceIn(const char* msg, void* ref) JPYPE_TRACING_OUTPUT << "> " << msg ; if (ref != nullptr) JPYPE_TRACING_OUTPUT << " id=\"" << ref << "\""; - JPYPE_TRACING_OUTPUT << endl; + JPYPE_TRACING_OUTPUT << std::endl; JPYPE_TRACING_OUTPUT.flush(); jpype_traceLevel++; } @@ -109,10 +109,10 @@ void JPypeTracer::traceOut(const char* msg, bool error) jpype_indent(jpype_traceLevel); if (error) { - JPYPE_TRACING_OUTPUT << "EXCEPTION! " << msg << endl; + JPYPE_TRACING_OUTPUT << "EXCEPTION! " << msg << std::endl; } else { - JPYPE_TRACING_OUTPUT << "< " << msg << endl; + JPYPE_TRACING_OUTPUT << "< " << msg << std::endl; } JPYPE_TRACING_OUTPUT.flush(); } @@ -177,7 +177,7 @@ void JPypeTracer::trace1(const char* source, const char* msg) JPYPE_TRACING_OUTPUT << source << ": "; if (source == nullptr || (_PyJPModule_trace & 16) != 0) JPYPE_TRACING_OUTPUT << name << ": "; - JPYPE_TRACING_OUTPUT << msg << endl; + JPYPE_TRACING_OUTPUT << msg << std::endl; JPYPE_TRACING_OUTPUT.flush(); } @@ -193,14 +193,14 @@ void JPypeTracer::trace2(const char* msg1, const char* msg2) name = jpype_tracer_last->m_Name; jpype_indent(jpype_traceLevel); - JPYPE_TRACING_OUTPUT << name << ": " << msg1 << " " << msg2 << endl; + JPYPE_TRACING_OUTPUT << name << ": " << msg1 << " " << msg2 << std::endl; JPYPE_TRACING_OUTPUT.flush(); } void JPypeTracer::traceLocks(const string& msg, void* ref) { std::lock_guard guard(trace_lock); - JPYPE_TRACING_OUTPUT << msg << ": " << ref << endl; + JPYPE_TRACING_OUTPUT << msg << ": " << ref << std::endl; JPYPE_TRACING_OUTPUT.flush(); } From 93618e1d3a8a8bfdc37a48b8632045a4fcde5deb Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:42:43 +0200 Subject: [PATCH 018/128] do not polute jpype.h with stringstream, iostream etc. --- native/common/include/jpype.h | 14 +++++--------- native/common/jp_class.cpp | 14 ++++++-------- native/common/jp_method.cpp | 12 +++++------- native/common/jp_methoddispatch.cpp | 7 +++---- native/common/jp_tracer.cpp | 6 +++--- native/common/jp_typefactory.cpp | 2 +- native/common/jp_typemanager.cpp | 6 +----- 7 files changed, 24 insertions(+), 37 deletions(-) diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index 00844cee1..32375ec99 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -51,7 +51,7 @@ #else -// For all the compilers than understand standards +// For all the compilers that understand standards #if (__cplusplus >= 201103L) #define NO_EXCEPT_FALSE noexcept(false) #else @@ -66,16 +66,12 @@ //#include #include #include -#include +//#include using std::map; using std::string; -using std::stringstream; -/*using std::cout; -using std::cerr; -using std::endl; -*/using std::vector; -using std::list; +using std::vector; +//using std::list; #ifdef JP_INSTRUMENTATION @@ -103,7 +99,7 @@ extern int PyJPModuleFault_check(uint32_t code); #endif /** Definition of commonly used template types */ -using StringVector = vector; +using StringVector = std::vector; /** * Converter are used for bulk byte transfers from Python to Java. diff --git a/native/common/jp_class.cpp b/native/common/jp_class.cpp index 6280aa256..6a6196995 100644 --- a/native/common/jp_class.cpp +++ b/native/common/jp_class.cpp @@ -45,9 +45,7 @@ JPClass::JPClass(JPJavaFrame& frame, m_Modifiers = modifiers; } -JPClass::~JPClass() -{ -} +JPClass::~JPClass()= default; void JPClass::setHost(PyObject* host) { @@ -113,7 +111,7 @@ JPClass* JPClass::newArrayType(JPJavaFrame &frame, long d) { if (d < 0 || d > 255) JP_RAISE(PyExc_ValueError, "Invalid array dimensions"); - stringstream ss; + std::stringstream ss; for (long i = 0; i < d; ++i) ss << "["; if (isPrimitive()) @@ -234,9 +232,9 @@ void JPClass::setStaticField(JPJavaFrame& frame, jclass c, jfieldID fid, PyObjec JPMatch match(&frame, obj); if (findJavaConversion(match) < JPMatch::_implicit) { - stringstream err; + std::stringstream err; err << "unable to convert to " << getCanonicalName(); - JP_RAISE(PyExc_TypeError, err.str().c_str()); + JP_RAISE(PyExc_TypeError, err.str()); } jobject val = match.convert().l; frame.SetStaticObjectField(c, fid, val); @@ -249,9 +247,9 @@ void JPClass::setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* ob JPMatch match(&frame, obj); if (findJavaConversion(match) < JPMatch::_implicit) { - stringstream err; + std::stringstream err; err << "unable to convert to " << getCanonicalName(); - JP_RAISE(PyExc_TypeError, err.str().c_str()); + JP_RAISE(PyExc_TypeError, err.str()); } jobject val = match.convert().l; frame.SetObjectField(c, fid, val); diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index 2196dd463..49de0304b 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -340,12 +340,12 @@ string JPMethod::matchReport(JPPyObjectVector& args) ensureTypeCache(); JPContext *context = m_Class->getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); - stringstream res; + std::stringstream res; res << m_ReturnType->getCanonicalName() << " ("; bool isFirst = true; - for (auto it = m_ParameterTypes.begin(); it != m_ParameterTypes.end(); it++) + for (auto & m_ParameterType : m_ParameterTypes) { if (isFirst && !isStatic()) { @@ -353,7 +353,7 @@ string JPMethod::matchReport(JPPyObjectVector& args) continue; } isFirst = false; - res << (*it)->getCanonicalName(); + res << m_ParameterType->getCanonicalName(); } res << ") ==> "; @@ -386,11 +386,9 @@ string JPMethod::matchReport(JPPyObjectVector& args) bool JPMethod::checkMoreSpecificThan(JPMethod* other) const { - for (auto it = m_MoreSpecificOverloads.begin(); - it != m_MoreSpecificOverloads.end(); - ++it) + for (auto m_MoreSpecificOverload : m_MoreSpecificOverloads) { - if (other == *it) + if (other == m_MoreSpecificOverload) return true; } return false; diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index dcc5a4815..506003d5d 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -226,13 +226,12 @@ bool JPMethodDispatch::matches(JPJavaFrame& frame, JPPyObjectVector& args, bool string JPMethodDispatch::matchReport(JPPyObjectVector& args) { - stringstream res; + std::stringstream res; res << "Match report for method " << m_Name << ", has " << m_Overloads.size() << " overloads." << std::endl; - for (auto cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) + for (auto current : m_Overloads) { - JPMethod* current = *cur; - res << " " << current->matchReport(args); + res << " " << current->matchReport(args); } return res.str(); } diff --git a/native/common/jp_tracer.cpp b/native/common/jp_tracer.cpp index 6a158182d..6d3dedc46 100644 --- a/native/common/jp_tracer.cpp +++ b/native/common/jp_tracer.cpp @@ -138,7 +138,7 @@ void JPypeTracer::traceJavaObject(const char* msg, const void* ref) JPypeTracer::trace1("- JNI", msg); return; } - stringstream str; + std::stringstream str; str << msg << " " << (void*) ref ; JPypeTracer::trace1("JNI", str.str().c_str()); } @@ -149,13 +149,13 @@ void JPypeTracer::tracePythonObject(const char* msg, PyObject* ref) return; if (ref != nullptr) { - stringstream str; + std::stringstream str; str << msg << " " << (void*) ref << " " << ref->ob_refcnt << " " << Py_TYPE(ref)->tp_name; JPypeTracer::trace1("PY", str.str().c_str()); } else { - stringstream str; + std::stringstream str; str << msg << " " << (void*) ref; JPypeTracer::trace1("PY", str.str().c_str()); } diff --git a/native/common/jp_typefactory.cpp b/native/common/jp_typefactory.cpp index 70c9ec660..754f4c7ae 100644 --- a/native/common/jp_typefactory.cpp +++ b/native/common/jp_typefactory.cpp @@ -290,7 +290,7 @@ JNIEXPORT jlong JNICALL Java_org_jpype_manager_TypeFactoryNative_defineObjectCla return (jlong) (context->_java_lang_reflect_Field = new JPClass(frame, cls, className, (JPClass*) superClass, interfaces, modifiers)); - stringstream ss; + std::stringstream ss; ss << "Special class not defined for " << className; JP_RAISE(PyExc_RuntimeError, ss.str()); return (jlong) result; diff --git a/native/common/jp_typemanager.cpp b/native/common/jp_typemanager.cpp index a1636bee2..fe0dd2240 100644 --- a/native/common/jp_typemanager.cpp +++ b/native/common/jp_typemanager.cpp @@ -33,10 +33,6 @@ JPTypeManager::JPTypeManager(JPJavaFrame& frame) JP_TRACE_OUT; } -JPTypeManager::~JPTypeManager() -{ -} - JPClass* JPTypeManager::findClass(jclass obj) { JP_TRACE_IN("JPTypeManager::findClass"); @@ -56,7 +52,7 @@ JPClass* JPTypeManager::findClassByName(const string& name) auto* out = (JPClass*) (frame.CallLongMethodA(m_JavaTypeManager.get(), m_FindClassByName, &val)); if (out == nullptr) { - stringstream err; + std::stringstream err; err << "Class " << name << " is not found"; JP_RAISE(PyExc_TypeError, err.str().c_str()); } From 13b8a65a477c9d03793d714962c5473a80df96bd Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:44:38 +0200 Subject: [PATCH 019/128] f --- native/common/include/jpype.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index 32375ec99..bcf819cc9 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -63,15 +63,10 @@ #include #include #include -//#include -#include -#include -//#include using std::map; using std::string; using std::vector; -//using std::list; #ifdef JP_INSTRUMENTATION From 3764856e66db69b8629249688b9b0443d59918b1 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:45:12 +0200 Subject: [PATCH 020/128] explicit ctors --- native/common/include/jp_classloader.h | 2 +- native/common/include/jp_doubletype.h | 2 +- native/common/include/jp_typemanager.h | 2 +- native/common/jp_doubletype.cpp | 4 ---- native/python/include/jp_pythontypes.h | 2 +- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/native/common/include/jp_classloader.h b/native/common/include/jp_classloader.h index 14c943157..526879f42 100644 --- a/native/common/include/jp_classloader.h +++ b/native/common/include/jp_classloader.h @@ -30,7 +30,7 @@ class JPClassLoader public: /** Initialize the class loader. */ - JPClassLoader(JPJavaFrame& frame); + explicit JPClassLoader(JPJavaFrame& frame); /** Load a class by name from the jpype.jar. * diff --git a/native/common/include/jp_doubletype.h b/native/common/include/jp_doubletype.h index 49d77620a..2024b328c 100755 --- a/native/common/include/jp_doubletype.h +++ b/native/common/include/jp_doubletype.h @@ -21,7 +21,7 @@ class JPDoubleType : public JPPrimitiveType public: JPDoubleType(); - ~JPDoubleType() override; + ~JPDoubleType() override = default; public: using type_t = jdouble; diff --git a/native/common/include/jp_typemanager.h b/native/common/include/jp_typemanager.h index 6038d86ee..abb34e2e6 100644 --- a/native/common/include/jp_typemanager.h +++ b/native/common/include/jp_typemanager.h @@ -29,7 +29,7 @@ class JPTypeManager * Initialize the type manager caches */ explicit JPTypeManager(JPJavaFrame& frame); - ~JPTypeManager(); + ~JPTypeManager() = default; /** * Find a class using a native name. diff --git a/native/common/jp_doubletype.cpp b/native/common/jp_doubletype.cpp index 6cf155bf7..b1e6794ad 100644 --- a/native/common/jp_doubletype.cpp +++ b/native/common/jp_doubletype.cpp @@ -24,10 +24,6 @@ JPDoubleType::JPDoubleType() { } -JPDoubleType::~JPDoubleType() -{ -} - JPPyObject JPDoubleType::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool cast) { PyTypeObject * wrapper = getHost(); diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 6caae56a0..3abfec017 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -228,7 +228,7 @@ class JPPySequence { JPPyObject m_Sequence; - JPPySequence(PyObject* obj) + explicit JPPySequence(PyObject* obj) { m_Sequence = JPPyObject::use(obj); } From 391457db8d83dde924cc2cbc4af2fbc38560342d Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:46:21 +0200 Subject: [PATCH 021/128] f --- native/common/include/jpype.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index bcf819cc9..a9614cfbd 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -94,7 +94,7 @@ extern int PyJPModuleFault_check(uint32_t code); #endif /** Definition of commonly used template types */ -using StringVector = std::vector; +using StringVector = vector; /** * Converter are used for bulk byte transfers from Python to Java. From c42d6f30e59b73c1e6df239d1e4e4f0c834178c2 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:48:02 +0200 Subject: [PATCH 022/128] JPypeException derives from std::exception (is this ok?) --- native/common/include/jp_exception.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 7c5c6fb7b..aaa1eb849 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -119,7 +119,7 @@ typedef union * to Python as the majority of errors are reported there. * */ -class JPypeException +class JPypeException : std::exception { public: JPypeException(JPJavaFrame &frame, jthrowable, const JPStackInfo& stackInfo); @@ -128,7 +128,7 @@ class JPypeException JPypeException(int type, const string& msn, int error, const JPStackInfo& stackInfo); JPypeException(const JPypeException& ex); JPypeException& operator = (const JPypeException& ex); - ~JPypeException(); + ~JPypeException() override = default; void from(const JPStackInfo& info); @@ -147,7 +147,7 @@ class JPypeException /** Transfer handling of this exception to java. */ void toJava(JPContext* context); - int getExceptionType() + int getExceptionType() const { return m_Type; } @@ -159,6 +159,6 @@ class JPypeException JPStackTrace m_Trace; string m_Message; JPThrowableRef m_Throwable; -} ; +}; #endif \ No newline at end of file From c6c5ebc943686f8c282b0c813188ba7277d7bcfe Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:49:12 +0200 Subject: [PATCH 023/128] explicit ctors --- native/common/include/jp_array.h | 4 ++-- native/common/include/jp_buffer.h | 2 +- native/common/include/jp_gc.h | 2 +- native/common/include/jp_tracer.h | 2 +- native/common/include/jp_value.h | 4 ++-- native/common/jp_classhints.cpp | 4 ++-- native/python/include/jp_pythontypes.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/native/common/include/jp_array.h b/native/common/include/jp_array.h index f6f75830d..b82618af5 100644 --- a/native/common/include/jp_array.h +++ b/native/common/include/jp_array.h @@ -23,7 +23,7 @@ class JPArray; class JPArrayView { public: - JPArrayView(JPArray* array); + explicit JPArrayView(JPArray* array); JPArrayView(JPArray* array, jobject collection); ~JPArrayView(); void reference(); @@ -47,7 +47,7 @@ class JPArray { friend class JPArrayView; public: - JPArray(const JPValue& array); + explicit JPArray(const JPValue& array); JPArray(JPArray* cls, jsize start, jsize stop, jsize step); virtual~ JPArray(); diff --git a/native/common/include/jp_buffer.h b/native/common/include/jp_buffer.h index b202d404c..3fca57a0c 100644 --- a/native/common/include/jp_buffer.h +++ b/native/common/include/jp_buffer.h @@ -26,7 +26,7 @@ class JPBufferType; class JPBuffer { public: - JPBuffer(const JPValue& array); + explicit JPBuffer(const JPValue& array); virtual~ JPBuffer(); JPBufferType* getClass() diff --git a/native/common/include/jp_gc.h b/native/common/include/jp_gc.h index e37bd45f5..c20117c1c 100644 --- a/native/common/include/jp_gc.h +++ b/native/common/include/jp_gc.h @@ -30,7 +30,7 @@ class JPGarbageCollection { public: - JPGarbageCollection(JPContext *context); + explicit JPGarbageCollection(JPContext *context); void init(JPJavaFrame& frame); diff --git a/native/common/include/jp_tracer.h b/native/common/include/jp_tracer.h index 175384c9a..735e905bd 100644 --- a/native/common/include/jp_tracer.h +++ b/native/common/include/jp_tracer.h @@ -58,7 +58,7 @@ class JPypeTracer public: - JPypeTracer(const char *name, void *ref = nullptr); + explicit JPypeTracer(const char *name, void *ref = nullptr); ~JPypeTracer(); void gotError(const JPStackInfo& info) diff --git a/native/common/include/jp_value.h b/native/common/include/jp_value.h index b58c66ea1..b66e0b56b 100644 --- a/native/common/include/jp_value.h +++ b/native/common/include/jp_value.h @@ -65,12 +65,12 @@ class JPValue jobject getJavaObject() const; - operator jvalue&() + explicit operator jvalue&() { return m_Value; } - operator const jvalue&() const + explicit operator const jvalue&() const { return m_Value; } diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index 49ead89c8..b3de8b91b 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -139,7 +139,7 @@ class JPPythonConversion : public JPConversion { public: - JPPythonConversion(PyObject *method) + explicit JPPythonConversion(PyObject *method) { method_ = JPPyObject::use(method); } @@ -232,7 +232,7 @@ class JPNoneConversion : public JPConversion { public: - JPNoneConversion(PyObject *type) + explicit JPNoneConversion(PyObject *type) { type_ = JPPyObject::use(type); } diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 3abfec017..113c92b5e 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -269,7 +269,7 @@ class JPPyObjectVector /** Use an existing sequence members as a vector. */ - JPPyObjectVector(PyObject* sequence); + explicit JPPyObjectVector(PyObject* sequence); /** Use an existing sequence members as a vector plus the * object instance. From 95239d534c1c067fc436db9b239de179449ac0e6 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 15:59:23 +0200 Subject: [PATCH 024/128] cstr conversion not needed --- native/common/jp_typemanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/common/jp_typemanager.cpp b/native/common/jp_typemanager.cpp index fe0dd2240..618975ff2 100644 --- a/native/common/jp_typemanager.cpp +++ b/native/common/jp_typemanager.cpp @@ -54,7 +54,7 @@ JPClass* JPTypeManager::findClassByName(const string& name) { std::stringstream err; err << "Class " << name << " is not found"; - JP_RAISE(PyExc_TypeError, err.str().c_str()); + JP_RAISE(PyExc_TypeError, err.str()); } return out; JP_TRACE_OUT; From bf0296c5ce49429d2c5f7792498645510f087113 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:02:56 +0200 Subject: [PATCH 025/128] const --- native/common/include/jp_match.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/common/include/jp_match.h b/native/common/include/jp_match.h index 1eec52d53..ce9367ae4 100644 --- a/native/common/include/jp_match.h +++ b/native/common/include/jp_match.h @@ -34,7 +34,7 @@ class JPMatch JPMatch(); JPMatch(JPJavaFrame *frame, PyObject *object); - JPContext *getContext() + JPContext *getContext() const { if (frame == nullptr) return nullptr; From f4fe48dee52b8f22d7839b66a23ad677e2fb8993 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:03:20 +0200 Subject: [PATCH 026/128] no type repetition --- native/common/include/jp_javaframe.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/common/include/jp_javaframe.h b/native/common/include/jp_javaframe.h index 4b804f5dd..624ee5e29 100644 --- a/native/common/include/jp_javaframe.h +++ b/native/common/include/jp_javaframe.h @@ -70,7 +70,7 @@ class JPJavaFrame */ static JPJavaFrame outer(JPContext* context, int size = LOCAL_FRAME_DEFAULT) { - return JPJavaFrame(context, nullptr, size, true); + return {context, nullptr, size, true}; } /** Create a new JavaFrame when called internal when @@ -84,7 +84,7 @@ class JPJavaFrame */ static JPJavaFrame inner(JPContext* context, int size = LOCAL_FRAME_DEFAULT) { - return JPJavaFrame(context, nullptr, size, false); + return {context, nullptr, size, false}; } /** Create a new JavaFrame when called from Java. @@ -99,7 +99,7 @@ class JPJavaFrame */ static JPJavaFrame external(JPContext* context, JNIEnv* env, int size = LOCAL_FRAME_DEFAULT) { - return JPJavaFrame(context, env, size, false); + return {context, env, size, false}; } JPJavaFrame(const JPJavaFrame& frame); From c70d9f773cb88c876b3b96b1b32506da587eaaf2 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:04:13 +0200 Subject: [PATCH 027/128] no shadow --- native/common/jp_method.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index 49de0304b..680277bbd 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -231,8 +231,8 @@ JPPyObject JPMethod::invoke(JPJavaFrame& frame, JPMethodMatch& match, JPPyObject { // This only can be hit by calling an instance method as a // class object. We already know it is safe to convert. - jvalue v = match.m_Arguments[0].convert(); - c = v.l; + auto val = match.m_Arguments[0].convert(); + c = val.l; } else { c = selfObj->getJavaObject(); From 36dd3b50ec7e20995c7bf6b1a022289b195aa3b9 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:32:00 +0200 Subject: [PATCH 028/128] use range operator, default dtor --- native/common/jp_classhints.cpp | 35 +++++++++++---------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index b3de8b91b..1ed5da7ce 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -81,20 +81,14 @@ JPMethodMatch::JPMethodMatch(JPJavaFrame &frame, JPPyObjectVector& args, bool ca } } -JPConversion::~JPConversion() -{ -} - -JPClassHints::JPClassHints() -{ -} +JPConversion::~JPConversion() = default; +JPClassHints::JPClassHints() = default; JPClassHints::~JPClassHints() { - for (auto iter = conversions.begin(); - iter != conversions.end(); ++iter) + for (auto & conversion : conversions) { - delete *iter; + delete conversion; } conversions.clear(); } @@ -102,14 +96,13 @@ JPClassHints::~JPClassHints() JPMatch::Type JPClassHints::getConversion(JPMatch& match, JPClass *cls) { JPConversion *best = nullptr; - for (auto iter = conversions.begin(); - iter != conversions.end(); ++iter) + for (auto & conversion : conversions) { - JPMatch::Type quality = (*iter)->matches(cls, match); + JPMatch::Type quality = conversion->matches(cls, match); if (quality > JPMatch::_explicit) return match.type; if (quality != JPMatch::_none) - best = (*iter); + best = conversion; } match.conversion = best; if (best == nullptr) @@ -144,9 +137,7 @@ class JPPythonConversion : public JPConversion method_ = JPPyObject::use(method); } - ~JPPythonConversion() override // GCOVR_EXCL_LINE - { - } + ~JPPythonConversion() override = default; jvalue convert(JPMatch &match) override { @@ -190,9 +181,7 @@ class JPAttributeConversion : public JPPythonConversion { } - ~JPAttributeConversion() override // GCOVR_EXCL_LINE - { - } + ~JPAttributeConversion() override = default; JPMatch::Type matches(JPClass *cls, JPMatch &match) override { @@ -919,7 +908,7 @@ class JPConversionJavaNumberAny : public JPConversionJavaObjectAny // If it is any primitive except char and boolean then implicit if (oc->isPrimitive()) return match.type = JPMatch::_implicit; - // Otherwise check if it is assignable according to Java + // Otherwise, check if it is assignable according to Java bool assignable = match.frame->IsAssignableFrom(oc->getJavaClass(), cls->getJavaClass()) != 0; return match.type = (assignable ? JPMatch::_implicit : JPMatch::_none); JP_TRACE_OUT; @@ -981,9 +970,9 @@ class JPConversionProxy : public JPConversion // Check if any of the interfaces matches ... vector itf = proxy->getInterfaces(); - for (unsigned int i = 0; i < itf.size(); i++) + for (auto & i : itf) { - if (match.frame->IsAssignableFrom(itf[i]->getJavaClass(), cls->getJavaClass())) + if (match.frame->IsAssignableFrom(i->getJavaClass(), cls->getJavaClass())) { JP_TRACE("implicit proxy"); match.conversion = this; From 002500f5a48e381aa2e4b01dadc7bad9cd15feff Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:37:59 +0200 Subject: [PATCH 029/128] minor --- native/common/jp_javaframe.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/common/jp_javaframe.cpp b/native/common/jp_javaframe.cpp index bf2765f7a..16fde4c2f 100644 --- a/native/common/jp_javaframe.cpp +++ b/native/common/jp_javaframe.cpp @@ -76,7 +76,7 @@ JPJavaFrame::~JPJavaFrame() JP_FRAME_CHECK(); } - // It is not safe to detach as we would loss all local references including + // It is not safe to detach as we would lose all local references including // any we want to keep. } @@ -126,10 +126,10 @@ jobject JPJavaFrame::NewGlobalRef(jobject obj) /*****************************************************************************/ // Exceptions - +// TODO: why is this never used? Should be deleted if obsolete. bool JPJavaFrame::ExceptionCheck() { - return (m_Env->ExceptionCheck() ? true : false); + return m_Env->ExceptionCheck() != 0; } void JPJavaFrame::ExceptionDescribe() From 88c71d5b99d168fa13b635d540bd565fd069c78b Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:38:56 +0200 Subject: [PATCH 030/128] fix explicit conversion for JPValue --- native/common/include/jp_value.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/native/common/include/jp_value.h b/native/common/include/jp_value.h index b66e0b56b..4a3b994ee 100644 --- a/native/common/include/jp_value.h +++ b/native/common/include/jp_value.h @@ -28,7 +28,6 @@ class JPValue public: JPValue() - : m_Class(nullptr) { m_Value.l = nullptr; } @@ -44,9 +43,7 @@ class JPValue m_Value.l = value; } - ~JPValue() - { - } + ~JPValue() = default; JPClass* getClass() const { @@ -65,16 +62,19 @@ class JPValue jobject getJavaObject() const; - explicit operator jvalue&() + // Cast operators to jvalue. + // TODO: these could be explicit too, right? + operator jvalue&() { return m_Value; } - explicit operator const jvalue&() const + operator const jvalue&() const { return m_Value; } + // TODO: never used. JPValue& global(JPJavaFrame& frame) { m_Value.l = frame.NewGlobalRef(m_Value.l); @@ -82,8 +82,8 @@ class JPValue } private: - JPClass* m_Class; - jvalue m_Value; + JPClass* m_Class{}; + jvalue m_Value{}; } ; #endif // _JPVALUE_H_ From ee9597944bf23c42d01df335c82ec7e30cc6a4c9 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:39:06 +0200 Subject: [PATCH 031/128] initializer --- native/common/include/jp_exception.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index aaa1eb849..6a7cc4e14 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -153,9 +153,9 @@ class JPypeException : std::exception } private: - JPContext* m_Context; + JPContext* m_Context{}; int m_Type; - JPErrorUnion m_Error; + JPErrorUnion m_Error{}; JPStackTrace m_Trace; string m_Message; JPThrowableRef m_Throwable; From 79dbb7b4b4a63b0f39990a2dd5485d11d1315e08 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:42:00 +0200 Subject: [PATCH 032/128] modernize: use = default for empty bodied ctors --- native/common/include/jp_encoding.h | 3 +-- native/common/jp_array.cpp | 3 +-- native/common/jp_arrayclass.cpp | 3 +-- native/common/jp_booleantype.cpp | 3 +-- native/common/jp_boxedtype.cpp | 3 +-- native/common/jp_buffer.cpp | 3 +-- native/common/jp_buffertype.cpp | 3 +-- native/common/jp_bytetype.cpp | 3 +-- native/common/jp_chartype.cpp | 3 +-- native/common/jp_classhints.cpp | 6 ++---- native/common/jp_classtype.cpp | 3 +-- native/common/jp_encoding.cpp | 3 +-- native/common/jp_field.cpp | 3 +-- native/common/jp_floattype.cpp | 3 +-- native/common/jp_functional.cpp | 3 +-- native/common/jp_inttype.cpp | 3 +-- native/common/jp_longtype.cpp | 3 +-- native/common/jp_method.cpp | 3 +-- native/common/jp_methoddispatch.cpp | 3 +-- native/common/jp_monitor.cpp | 3 +-- native/common/jp_numbertype.cpp | 3 +-- native/common/jp_objecttype.cpp | 3 +-- native/common/jp_platform.cpp | 3 +-- native/common/jp_primitivetype.cpp | 3 +-- native/common/jp_proxy.cpp | 12 ++++-------- native/common/jp_shorttype.cpp | 3 +-- native/common/jp_stringtype.cpp | 3 +-- native/common/jp_voidtype.cpp | 3 +-- native/python/include/jp_pythontypes.h | 5 ++--- 29 files changed, 34 insertions(+), 67 deletions(-) diff --git a/native/common/include/jp_encoding.h b/native/common/include/jp_encoding.h index 4e3e78bcb..3cbf302e8 100644 --- a/native/common/include/jp_encoding.h +++ b/native/common/include/jp_encoding.h @@ -25,8 +25,7 @@ class JPEncoding public: JPEncoding() - { - } + = default; virtual ~JPEncoding(); /** Store a code point in an outgoing buffer. */ diff --git a/native/common/jp_array.cpp b/native/common/jp_array.cpp index 1d34fed05..afc0f5f66 100644 --- a/native/common/jp_array.cpp +++ b/native/common/jp_array.cpp @@ -64,8 +64,7 @@ JPArray::JPArray(JPArray* instance, jsize start, jsize stop, jsize step) } JPArray::~JPArray() -{ -} += default; jsize JPArray::getLength() { diff --git a/native/common/jp_arrayclass.cpp b/native/common/jp_arrayclass.cpp index c8b153117..304a9ec8e 100644 --- a/native/common/jp_arrayclass.cpp +++ b/native/common/jp_arrayclass.cpp @@ -31,8 +31,7 @@ JPArrayClass::JPArrayClass(JPJavaFrame& frame, } JPArrayClass::~JPArrayClass() -{ -} += default; JPMatch::Type JPArrayClass::findJavaConversion(JPMatch &match) { diff --git a/native/common/jp_booleantype.cpp b/native/common/jp_booleantype.cpp index 337add3c5..703317bab 100644 --- a/native/common/jp_booleantype.cpp +++ b/native/common/jp_booleantype.cpp @@ -26,8 +26,7 @@ JPBooleanType::JPBooleanType() } JPBooleanType::~JPBooleanType() -{ -} += default; JPPyObject JPBooleanType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { diff --git a/native/common/jp_boxedtype.cpp b/native/common/jp_boxedtype.cpp index 1f1e9f90f..962e437fe 100644 --- a/native/common/jp_boxedtype.cpp +++ b/native/common/jp_boxedtype.cpp @@ -60,8 +60,7 @@ m_PrimitiveType(primitiveType) } JPBoxedType::~JPBoxedType() -{ -} += default; JPMatch::Type JPBoxedType::findJavaConversion(JPMatch &match) { diff --git a/native/common/jp_buffer.cpp b/native/common/jp_buffer.cpp index f9d6d30b3..a462ae1ac 100644 --- a/native/common/jp_buffer.cpp +++ b/native/common/jp_buffer.cpp @@ -42,8 +42,7 @@ JPBuffer::JPBuffer(const JPValue &value) } JPBuffer::~JPBuffer() -{ -} += default; bool JPBuffer::isReadOnly() { diff --git a/native/common/jp_buffertype.cpp b/native/common/jp_buffertype.cpp index b772716d0..8859747ea 100644 --- a/native/common/jp_buffertype.cpp +++ b/native/common/jp_buffertype.cpp @@ -70,8 +70,7 @@ JPBufferType::JPBufferType(JPJavaFrame& frame, } JPBufferType::~JPBufferType() -{ -} += default; JPPyObject JPBufferType::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool cast) { diff --git a/native/common/jp_bytetype.cpp b/native/common/jp_bytetype.cpp index 95f981114..1c25f4d9c 100644 --- a/native/common/jp_bytetype.cpp +++ b/native/common/jp_bytetype.cpp @@ -25,8 +25,7 @@ JPByteType::JPByteType() } JPByteType::~JPByteType() -{ -} += default; JPPyObject JPByteType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { diff --git a/native/common/jp_chartype.cpp b/native/common/jp_chartype.cpp index e48a779ce..f079cb9c7 100644 --- a/native/common/jp_chartype.cpp +++ b/native/common/jp_chartype.cpp @@ -26,8 +26,7 @@ JPCharType::JPCharType() } JPCharType::~JPCharType() -{ -} += default; JPValue JPCharType::newInstance(JPJavaFrame& frame, JPPyObjectVector& args) { diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index 1ed5da7ce..c8f0572d7 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -227,8 +227,7 @@ class JPNoneConversion : public JPConversion } ~JPNoneConversion() override - { - } + = default; JPMatch::Type matches(JPClass *cls, JPMatch &match) override { @@ -267,8 +266,7 @@ class JPTypeConversion : public JPPythonConversion } ~JPTypeConversion() override - { - } + = default; JPMatch::Type matches(JPClass *cls, JPMatch &match) override { diff --git a/native/common/jp_classtype.cpp b/native/common/jp_classtype.cpp index f02c30e25..67d9c0d59 100644 --- a/native/common/jp_classtype.cpp +++ b/native/common/jp_classtype.cpp @@ -30,8 +30,7 @@ JPClassType::JPClassType(JPJavaFrame& frame, } JPClassType::~JPClassType() -{ -} += default; JPMatch::Type JPClassType::findJavaConversion(JPMatch& match) { diff --git a/native/common/jp_encoding.cpp b/native/common/jp_encoding.cpp index 8313b1d1d..e7914b62a 100644 --- a/native/common/jp_encoding.cpp +++ b/native/common/jp_encoding.cpp @@ -41,8 +41,7 @@ // has the downside that we can't test it currently. JPEncoding::~JPEncoding() -{ -} += default; // char* to stream from // https://stackoverflow.com/questions/7781898/get-an-istream-from-a-char diff --git a/native/common/jp_field.cpp b/native/common/jp_field.cpp index 296198617..d291e5f71 100644 --- a/native/common/jp_field.cpp +++ b/native/common/jp_field.cpp @@ -33,8 +33,7 @@ JPField::JPField(JPJavaFrame& frame, } JPField::~JPField() -{ -} += default; JPPyObject JPField::getStaticField() { diff --git a/native/common/jp_floattype.cpp b/native/common/jp_floattype.cpp index a15a0c4ad..e8926edd8 100644 --- a/native/common/jp_floattype.cpp +++ b/native/common/jp_floattype.cpp @@ -26,8 +26,7 @@ JPFloatType::JPFloatType() } JPFloatType::~JPFloatType() -{ -} += default; JPPyObject JPFloatType::convertToPythonObject(JPJavaFrame& frame, jvalue value, bool cast) { diff --git a/native/common/jp_functional.cpp b/native/common/jp_functional.cpp index 3c52f4429..6ff15c214 100644 --- a/native/common/jp_functional.cpp +++ b/native/common/jp_functional.cpp @@ -29,8 +29,7 @@ JPFunctional::JPFunctional(JPJavaFrame& frame, jclass clss, } JPFunctional::~JPFunctional() -{ -} += default; class JPConversionFunctional : public JPConversion diff --git a/native/common/jp_inttype.cpp b/native/common/jp_inttype.cpp index 9523be1ae..15132c07d 100644 --- a/native/common/jp_inttype.cpp +++ b/native/common/jp_inttype.cpp @@ -25,8 +25,7 @@ JPIntType::JPIntType() } JPIntType::~JPIntType() -{ -} += default; JPPyObject JPIntType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { diff --git a/native/common/jp_longtype.cpp b/native/common/jp_longtype.cpp index 37e5e88a9..57f28937e 100644 --- a/native/common/jp_longtype.cpp +++ b/native/common/jp_longtype.cpp @@ -25,8 +25,7 @@ JPLongType::JPLongType() } JPLongType::~JPLongType() -{ -} += default; JPPyObject JPLongType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index 680277bbd..87e6a09cf 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -37,8 +37,7 @@ JPMethod::JPMethod(JPJavaFrame& frame, } JPMethod::~JPMethod() -{ -} += default; void JPMethod::setParameters( JPClass *returnType, diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index 506003d5d..2200ee940 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -31,8 +31,7 @@ JPMethodDispatch::JPMethodDispatch(JPClass* clazz, } JPMethodDispatch::~JPMethodDispatch() -{ -} += default; const string& JPMethodDispatch::getName() const { diff --git a/native/common/jp_monitor.cpp b/native/common/jp_monitor.cpp index 655dbe223..201ddcd6a 100644 --- a/native/common/jp_monitor.cpp +++ b/native/common/jp_monitor.cpp @@ -22,8 +22,7 @@ JPMonitor::JPMonitor(JPContext* context, jobject value) : m_Value(context, value } JPMonitor::~JPMonitor() -{ -} += default; void JPMonitor::enter() { diff --git a/native/common/jp_numbertype.cpp b/native/common/jp_numbertype.cpp index c851d6e2a..a098bc8d7 100644 --- a/native/common/jp_numbertype.cpp +++ b/native/common/jp_numbertype.cpp @@ -28,8 +28,7 @@ JPNumberType::JPNumberType(JPJavaFrame& frame, } JPNumberType::~JPNumberType() -{ -} += default; JPMatch::Type JPNumberType::findJavaConversion(JPMatch& match) { diff --git a/native/common/jp_objecttype.cpp b/native/common/jp_objecttype.cpp index 1d5657bec..5d4ac89a6 100644 --- a/native/common/jp_objecttype.cpp +++ b/native/common/jp_objecttype.cpp @@ -28,8 +28,7 @@ JPObjectType::JPObjectType(JPJavaFrame& frame, } JPObjectType::~JPObjectType() -{ -} += default; JPMatch::Type JPObjectType::findJavaConversion(JPMatch& match) { diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index 0de7fc674..ea7b0cd4e 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -17,8 +17,7 @@ #include "jp_platform.h" JPPlatformAdapter::~JPPlatformAdapter() -{ -} += default; #ifdef WIN32 #include diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index 604a5e425..711533b68 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -21,8 +21,7 @@ JPPrimitiveType::JPPrimitiveType(const string& name) } JPPrimitiveType::~JPPrimitiveType() -{ -} += default; bool JPPrimitiveType::isPrimitive() const { diff --git a/native/common/jp_proxy.cpp b/native/common/jp_proxy.cpp index 9f1bb0568..2b9e6b01c 100644 --- a/native/common/jp_proxy.cpp +++ b/native/common/jp_proxy.cpp @@ -243,8 +243,7 @@ JPProxyType::JPProxyType(JPJavaFrame& frame, } JPProxyType::~JPProxyType() -{ -} += default; JPPyObject JPProxyType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { @@ -265,8 +264,7 @@ JPProxyDirect::JPProxyDirect(JPContext* context, PyJPProxy* inst, JPClassList& i } JPProxyDirect::~JPProxyDirect() -{ -} += default; JPPyObject JPProxyDirect::getCallable(const string& cname) { @@ -279,8 +277,7 @@ JPProxyIndirect::JPProxyIndirect(JPContext* context, PyJPProxy* inst, JPClassLis } JPProxyIndirect::~JPProxyIndirect() -{ -} += default; JPPyObject JPProxyIndirect::getCallable(const string& cname) { @@ -297,8 +294,7 @@ JPProxyFunctional::JPProxyFunctional(JPContext* context, PyJPProxy* inst, JPClas } JPProxyFunctional::~JPProxyFunctional() -{ -} += default; JPPyObject JPProxyFunctional::getCallable(const string& cname) { diff --git a/native/common/jp_shorttype.cpp b/native/common/jp_shorttype.cpp index 696689fe1..e7cce5b44 100644 --- a/native/common/jp_shorttype.cpp +++ b/native/common/jp_shorttype.cpp @@ -25,8 +25,7 @@ JPShortType::JPShortType() } JPShortType::~JPShortType() -{ -} += default; JPPyObject JPShortType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { diff --git a/native/common/jp_stringtype.cpp b/native/common/jp_stringtype.cpp index 107d6bde4..629f4a85f 100644 --- a/native/common/jp_stringtype.cpp +++ b/native/common/jp_stringtype.cpp @@ -28,8 +28,7 @@ JPStringType::JPStringType(JPJavaFrame& frame, } JPStringType::~JPStringType() -{ -} += default; JPPyObject JPStringType::convertToPythonObject(JPJavaFrame& frame, jvalue val, bool cast) { diff --git a/native/common/jp_voidtype.cpp b/native/common/jp_voidtype.cpp index f053e633a..ba10c3a39 100644 --- a/native/common/jp_voidtype.cpp +++ b/native/common/jp_voidtype.cpp @@ -22,8 +22,7 @@ JPVoidType::JPVoidType() } JPVoidType::~JPVoidType() -{ -} += default; JPPyObject JPVoidType::invokeStatic(JPJavaFrame& frame, jclass claz, jmethodID mth, jvalue* val) { diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 113c92b5e..92bcc6120 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -238,9 +238,8 @@ class JPPySequence /** Needed for named constructor. */ JPPySequence(const JPPySequence& seq) - : m_Sequence(seq.m_Sequence) - { - } + + = default; /** Use an existing Python sequence in C++. */ From b35a9b9921ec3ac37e639c5efe1244826d0eb7ee Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 16:59:38 +0200 Subject: [PATCH 033/128] match return type --- native/common/jp_functional.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/jp_functional.cpp b/native/common/jp_functional.cpp index 6ff15c214..f7f55540b 100644 --- a/native/common/jp_functional.cpp +++ b/native/common/jp_functional.cpp @@ -57,7 +57,7 @@ class JPConversionFunctional : public JPConversion auto* code = (PyCodeObject*) PyFunction_GetCode(func); // borrowed Py_ssize_t args = code->co_argcount; bool is_varargs = ((code->co_flags&CO_VARARGS)==CO_VARARGS); - int optional = 0; + Py_ssize_t optional = 0; JPPyObject defaults = JPPyObject::accept(PyObject_GetAttrString(func, "__defaults__")); if (!defaults.isNull() && defaults.get() != Py_None) optional = PyTuple_Size(defaults.get()); @@ -75,7 +75,7 @@ class JPConversionFunctional : public JPConversion auto* code = (PyCodeObject*) PyFunction_GetCode(func); // borrowed Py_ssize_t args = code->co_argcount; bool is_varargs = ((code->co_flags&CO_VARARGS)==CO_VARARGS); - int optional = 0; + Py_ssize_t optional = 0; JPPyObject defaults = JPPyObject::accept(PyObject_GetAttrString(func, "__defaults__")); if (!defaults.isNull() && defaults.get() != Py_None) optional = PyTuple_Size(defaults.get()); From 528a69cea4719f265212bcce200430bf12abc91c Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 17:00:01 +0200 Subject: [PATCH 034/128] emplace back, where involved types would be copied. --- native/common/jp_exception.cpp | 2 +- native/python/pyjp_module.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 4d0992d0a..d4019b0b7 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -85,7 +85,7 @@ JPypeException& JPypeException::operator = (const JPypeException& ex) void JPypeException::from(const JPStackInfo& info) { JP_TRACE("EXCEPTION FROM: ", info.getFile(), info.getLine()); - m_Trace.push_back(info); + m_Trace.emplace_back(info); } // Okay from this point on we have to suit up in full Kevlar because diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 13249461b..b167dfd73 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -253,7 +253,7 @@ static PyObject* PyJPModule_startup(PyObject* module, PyObject* pyargs) // TODO support unicode string v = JPPyString::asStringUTF8(obj.get()); JP_TRACE("arg", v); - args.push_back(v); + args.emplace_back(v); } else { PyErr_SetString(PyExc_TypeError, "VM Arguments must be strings"); From 347de60bb3547c53f839415b390d9beb2fb90672 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 17:18:21 +0200 Subject: [PATCH 035/128] use move --- native/common/include/jp_methoddispatch.h | 2 +- native/common/jp_classhints.cpp | 11 +++++++---- native/common/jp_methoddispatch.cpp | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/native/common/include/jp_methoddispatch.h b/native/common/include/jp_methoddispatch.h index af90d2a68..0762b43d1 100644 --- a/native/common/include/jp_methoddispatch.h +++ b/native/common/include/jp_methoddispatch.h @@ -26,7 +26,7 @@ class JPMethodDispatch : public JPResource * Create a new method based on class and a name; */ JPMethodDispatch(JPClass *clazz, - const string& name, + string name, JPMethodList& overloads, jint modifiers); diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index c8f0572d7..5ba6bd583 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -13,12 +13,15 @@ See NOTICE file for details. *****************************************************************************/ +#include + #include #include "jpype.h" -#include "jp_classhints.h" #include "jp_arrayclass.h" -#include "jp_stringtype.h" +#include "jp_classhints.h" #include "jp_proxy.h" +#include "jp_stringtype.h" + #include "pyjp.h" JPMatch::JPMatch() @@ -176,8 +179,8 @@ class JPAttributeConversion : public JPPythonConversion { public: - JPAttributeConversion(const string &attribute, PyObject *method) - : JPPythonConversion(method), attribute_(attribute) + JPAttributeConversion(string attribute, PyObject *method) + : JPPythonConversion(method), attribute_(std::move(attribute)) { } diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index 2200ee940..acf2adc69 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -14,15 +14,16 @@ See NOTICE file for details. *****************************************************************************/ #include +#include #include "jpype.h" #include "jp_method.h" #include "jp_methoddispatch.h" JPMethodDispatch::JPMethodDispatch(JPClass* clazz, - const string& name, + string name, JPMethodList& overloads, jint modifiers) -: m_Name(name) +: m_Name(std::move(name)) { m_Class = clazz; m_Overloads = overloads; From c2f0dccfd03197995aaf993dd7ab085688bb82e1 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 17:18:40 +0200 Subject: [PATCH 036/128] added fixme about build_ext.parallel --- setupext/build_ext.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setupext/build_ext.py b/setupext/build_ext.py index 8d6d6264e..6e386507c 100644 --- a/setupext/build_ext.py +++ b/setupext/build_ext.py @@ -234,6 +234,7 @@ def build_extensions(self): # has to be last call print("Call build extensions") + # FIXME: self.parallel seems to not be initialized properly. super().build_extensions() def build_extension(self, ext): From 4c9d5ce8126220b01af0e2109a4d5f86c46c786d Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 17:27:11 +0200 Subject: [PATCH 037/128] use common c++ std in Platform() --- setupext/platform.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/setupext/platform.py b/setupext/platform.py index 961e54ac1..5ea17ea48 100644 --- a/setupext/platform.py +++ b/setupext/platform.py @@ -59,37 +59,36 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): platform_specific['extra_link_args'] = [] distutils.log.info("Configure platform to", platform) + cpp_std = "c++14" + gcc_like_cflags = ['-g0', f'-std={cpp_std}', '-O2'] - static = True if platform == 'win32': distutils.log.info("Add windows settings") - # platform_specific['libraries'] = ['Advapi32'] platform_specific['define_macros'] = [('WIN32', 1)] if sys.version > '3': platform_specific['extra_compile_args'] = [ - '/Zi', '/EHsc', '/std:c++14'] + '/Zi', '/EHsc', f'/std:{cpp_std}'] else: platform_specific['extra_compile_args'] = ['/Zi', '/EHsc'] - # platform_specific['extra_link_args'] = ['/DEBUG'] jni_md_platform = 'win32' elif platform == 'darwin': distutils.log.info("Add darwin settings") platform_specific['libraries'] = ['dl'] platform_specific['define_macros'] = [('MACOSX', 1)] - platform_specific['extra_compile_args'] = ['-g0', '-std=c++14', '-O2'] + platform_specific['extra_compile_args'] = gcc_like_cflags jni_md_platform = 'darwin' elif platform.startswith('linux'): distutils.log.info("Add linux settings") platform_specific['libraries'] = ['dl'] - platform_specific['extra_compile_args'] = ['-g0', '-std=c++14', '-O2'] + platform_specific['extra_compile_args'] = gcc_like_cflags jni_md_platform = 'linux' elif platform.startswith('aix7'): distutils.log.info("Add aix settings") platform_specific['libraries'] = ['dl'] - platform_specific['extra_compile_args'] = ['-g3', '-std=c++14', '-O2'] + platform_specific['extra_compile_args'] = gcc_like_cflags jni_md_platform = 'aix7' elif platform.startswith('freebsd'): @@ -103,11 +102,10 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): elif platform.startswith('android'): distutils.log.info("Add android settings") platform_specific['libraries'] = ['dl', 'c++_shared', 'SDL2'] - platform_specific['extra_compile_args'] = ['-g0', '-std=c++14', '-fexceptions', '-frtti', '-O2'] + platform_specific['extra_compile_args'] = gcc_like_cflags + ['-fexceptions', '-frtti'] print("PLATFORM_SPECIFIC:", platform_specific) jni_md_platform = 'linux' - static = False elif platform == 'zos': distutils.log.info("Add zos settings") @@ -116,7 +114,7 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): elif platform == 'sunos5': distutils.log.info("Add solaris settings") jni_md_platform = 'solaris' - + else: jni_md_platform = '' distutils.log.warn("Your platform '%s' is not being handled explicitly." From 4577ef16d44f6a885563d9da23076fb6d13b311a Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 17:28:49 +0200 Subject: [PATCH 038/128] removed unused code --- setupext/build_ext.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/setupext/build_ext.py b/setupext/build_ext.py index 6e386507c..b126048d4 100644 --- a/setupext/build_ext.py +++ b/setupext/build_ext.py @@ -184,11 +184,6 @@ def initialize_options(self, *args): self.jar = False import distutils.sysconfig cfg_vars = distutils.sysconfig.get_config_vars() - replacement = { - '-Wstrict-prototypes': '', - '-Wimplicit-function-declaration': '', - } - tracing = self.distribution.enable_tracing # Arguments to remove so we set debugging and optimization level remove_args = ['-O0', '-O1', '-O2', '-O3', '-g'] @@ -196,12 +191,12 @@ def initialize_options(self, *args): for k, v in cfg_vars.items(): if not isinstance(v, str): continue - if not k == "OPT" and not "FLAGS" in k: + if not k == "OPT" and "FLAGS" not in k: continue args = v.split() for r in remove_args: - args = list(filter((r).__ne__, args)) + args = list(filter(r.__ne__, args)) cfg_vars[k] = " ".join(args) super().initialize_options() From ee03db863f9c2f1459e6f646f4ef4bc55ea4e56c Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 17:48:53 +0200 Subject: [PATCH 039/128] mark unimplemented private special functions with "delete" --- native/common/include/jp_context.h | 2 +- native/common/include/jp_field.h | 4 ++-- native/python/include/jp_pythontypes.h | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/native/common/include/jp_context.h b/native/common/include/jp_context.h index f6ba2ffbb..f073a8d3f 100644 --- a/native/common/include/jp_context.h +++ b/native/common/include/jp_context.h @@ -206,7 +206,7 @@ class JPContext jint(JNICALL * GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize * nVms){}; private: - JPContext(const JPContext& orig); + JPContext(const JPContext& orig) = delete; JavaVM *m_JavaVM{}; diff --git a/native/common/include/jp_field.h b/native/common/include/jp_field.h index 48f18c1f7..7917ade64 100644 --- a/native/common/include/jp_field.h +++ b/native/common/include/jp_field.h @@ -75,8 +75,8 @@ class JPField } private: - JPField(const JPField&); - JPField& operator=(const JPField&) ; + JPField(const JPField&) = delete; + JPField& operator=(const JPField&) = delete ; string m_Name; JPClass* m_Class; diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 92bcc6120..98aad3026 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -253,7 +253,7 @@ class JPPySequence jlong size(); private: - JPPySequence& operator= (const JPPySequence& ) ; + JPPySequence& operator= (const JPPySequence& ) = delete ; } ; @@ -291,8 +291,8 @@ class JPPyObjectVector } private: - JPPyObjectVector& operator= (const JPPyObjectVector& ) ; - JPPyObjectVector(const JPPyObjectVector& ); + JPPyObjectVector& operator= (const JPPyObjectVector& ) = delete ; + JPPyObjectVector(const JPPyObjectVector& ) = delete; private: JPPyObject m_Instance; From 55328c266fd3f32b9a3ec6ccc017d343d4f96a13 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 18:38:07 +0200 Subject: [PATCH 040/128] disallow copying (delete copy ctors, made public). --- native/common/include/jp_context.h | 4 ++-- native/common/include/jp_field.h | 7 ++++--- native/python/include/jp_pythontypes.h | 7 +++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/native/common/include/jp_context.h b/native/common/include/jp_context.h index f073a8d3f..d5cd4c4b9 100644 --- a/native/common/include/jp_context.h +++ b/native/common/include/jp_context.h @@ -120,8 +120,9 @@ class JPContext JPContext(); virtual ~JPContext(); + JPContext(const JPContext& orig) = delete; - // JVM control functions + // JVM control functions bool isRunning(); void startJVM(const string& vmPath, const StringVector& args, bool ignoreUnrecognized, bool convertStrings, bool interrupt); @@ -206,7 +207,6 @@ class JPContext jint(JNICALL * GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize * nVms){}; private: - JPContext(const JPContext& orig) = delete; JavaVM *m_JavaVM{}; diff --git a/native/common/include/jp_field.h b/native/common/include/jp_field.h index 7917ade64..11fa0a21c 100644 --- a/native/common/include/jp_field.h +++ b/native/common/include/jp_field.h @@ -38,6 +38,10 @@ class JPField */ virtual ~JPField(); + // disallow copying. + JPField(const JPField&) = delete; + JPField& operator=(const JPField&) = delete; + jobject getJavaObject() { return this->m_Field.get(); @@ -75,9 +79,6 @@ class JPField } private: - JPField(const JPField&) = delete; - JPField& operator=(const JPField&) = delete ; - string m_Name; JPClass* m_Class; JPObjectRef m_Field; diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 98aad3026..36dcec70c 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -252,8 +252,7 @@ class JPPySequence jlong size(); -private: - JPPySequence& operator= (const JPPySequence& ) = delete ; + JPPySequence& operator= (const JPPySequence&) = delete; } ; @@ -290,8 +289,8 @@ class JPPyObjectVector return m_Instance; } -private: - JPPyObjectVector& operator= (const JPPyObjectVector& ) = delete ; + // disallow copying + JPPyObjectVector& operator= (const JPPyObjectVector& ) = delete; JPPyObjectVector(const JPPyObjectVector& ) = delete; private: From eec272f238faf8cfaadf5a6c0ae6c7daa94b8439 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 18:49:32 +0200 Subject: [PATCH 041/128] follow up: explicit ctor (updated comment) --- native/python/include/jp_pythontypes.h | 1 - 1 file changed, 1 deletion(-) diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index 36dcec70c..f174d69d9 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -77,7 +77,6 @@ class JPPyObject /** Create a new reference to a Python object. * * @param obj is the python object. - * @param i is a dummy to make sure this ctor was not called accidentally. */ explicit JPPyObject(PyObject* obj); From bee2ab8e86c7e29395aa7753c3b3c35cf6344768 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 19:24:43 +0200 Subject: [PATCH 042/128] refactor jpypeexception to be a std::runtime_error --- native/common/include/jp_exception.h | 13 +++++++------ native/common/jp_exception.cpp | 26 +++++++++++++------------- native/python/pyjp_class.cpp | 22 +++++++++++----------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 6a7cc4e14..6a6120cdb 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -39,7 +39,7 @@ * - otherwise convert to a RuntimeException. * */ - +#include #ifndef __FUNCTION_NAME__ #ifdef WIN32 //WINDOWS #define __FUNCTION_NAME__ __FUNCTION__ @@ -70,7 +70,7 @@ extern int _method_not_found; // Macro to use when hardening code // Most of these will be removed after core is debugged, but // a few are necessary to handle off normal conditions. -#define ASSERT_NOT_NULL(X) {if (X==NULL) { JP_RAISE(PyExc_RuntimeError, "Null Pointer Exception");} } +#define ASSERT_NOT_NULL(X) {if ((X)==NULL) { JP_RAISE(PyExc_RuntimeError, "Null Pointer Exception");} } // Macro to add stack trace info when multiple paths lead to the same trouble spot #define JP_CATCH catch (JPypeException& ex) { ex.from(JP_STACKINFO()); throw; } @@ -119,20 +119,22 @@ typedef union * to Python as the majority of errors are reported there. * */ -class JPypeException : std::exception +class JPypeException : std::runtime_error { public: JPypeException(JPJavaFrame &frame, jthrowable, const JPStackInfo& stackInfo); JPypeException(int type, void* error, const JPStackInfo& stackInfo); JPypeException(int type, void* error, const string& msn, const JPStackInfo& stackInfo); JPypeException(int type, const string& msn, int error, const JPStackInfo& stackInfo); - JPypeException(const JPypeException& ex); + // The copy constructor for an object thrown as an exception must be declared noexcept, including any implicitly-defined copy constructors. + // Any function declared noexcept that terminates by throwing an exception violates ERR55-CPP. Honor exception specifications. + JPypeException(const std::runtime_error &unnamed, const JPypeException &ex) noexcept; JPypeException& operator = (const JPypeException& ex); ~JPypeException() override = default; void from(const JPStackInfo& info); - string getMessage(); + string getMessage() noexcept; void convertJavaToPython(); void convertPythonToJava(JPContext* context); @@ -157,7 +159,6 @@ class JPypeException : std::exception int m_Type; JPErrorUnion m_Error{}; JPStackTrace m_Trace; - string m_Message; JPThrowableRef m_Throwable; }; diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index d4019b0b7..687d3f1be 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -22,31 +22,31 @@ PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace); JPypeException::JPypeException(JPJavaFrame &frame, jthrowable th, const JPStackInfo& stackInfo) -: m_Throwable(frame, th) +: m_Throwable(frame, th), std::runtime_error(frame.toString(th)) { JP_TRACE("JAVA EXCEPTION THROWN with java throwable"); m_Context = frame.getContext(); m_Type = JPError::_java_error; m_Error.l = nullptr; - m_Message = frame.toString(th); from(stackInfo); } JPypeException::JPypeException(int type, void* error, const JPStackInfo& stackInfo) +: std::runtime_error("None") { JP_TRACE("EXCEPTION THROWN with error", error); m_Type = type; m_Error.l = error; - m_Message = "None"; from(stackInfo); } JPypeException::JPypeException(int type, void* errType, const string& msn, const JPStackInfo& stackInfo) +: std::runtime_error(msn) { JP_TRACE("EXCEPTION THROWN", errType, msn); m_Type = type; m_Error.l = errType; - m_Message = msn; + //m_Message = msn; from(stackInfo); } @@ -54,30 +54,30 @@ JPypeException::JPypeException(int type, void* errType, const string& msn, const // This is only used during startup for OSError JPypeException::JPypeException(int type, const string& msn, int errType, const JPStackInfo& stackInfo) +: std::runtime_error(msn) { JP_TRACE("EXCEPTION THROWN", errType, msn); m_Type = type; m_Error.i = errType; - m_Message = msn; from(stackInfo); } -JPypeException::JPypeException(const JPypeException& ex) -: m_Context(ex.m_Context), m_Trace(ex.m_Trace), m_Throwable(ex.m_Throwable) +JPypeException::JPypeException(const std::runtime_error &unnamed, const JPypeException &ex) noexcept +: runtime_error(unnamed), m_Context(ex.m_Context), m_Trace(ex.m_Trace), m_Throwable(ex.m_Throwable) { m_Type = ex.m_Type; m_Error = ex.m_Error; - m_Message = ex.m_Message; } JPypeException& JPypeException::operator = (const JPypeException& ex) { + if(this == &ex) + return *this; m_Context = ex.m_Context; m_Type = ex.m_Type; m_Trace = ex.m_Trace; m_Throwable = ex.m_Throwable; m_Error = ex.m_Error; - m_Message = ex.m_Message; return *this; } // GCOVR_EXCL_STOP @@ -99,15 +99,15 @@ void JPypeException::from(const JPStackInfo& info) // they are actually out to get you. // // Onward my friends to victory or a glorious segfault! - -string JPypeException::getMessage() +// TODO: actually we can replace this completely with what() of runtime_error! +string JPypeException::getMessage() noexcept { JP_TRACE_IN("JPypeException::getMessage"); - // Must be bullet proof + // Must be bulletproof try { std::stringstream str; - str << m_Message << std::endl; + str << std::runtime_error::what() << std::endl; JP_TRACE(str.str()); return str.str(); // GCOVR_EXCL_START diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index 484bb014f..193be84a4 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -1089,7 +1089,7 @@ JPPyObject PyJPClass_getBases(JPJavaFrame &frame, JPClass* cls) } const JPClassList& baseItf = cls->getInterfaces(); - size_t count = baseItf.size() + (!baseType.isNull() ? 1 : 0) + (super != nullptr ? 1 : 0); + Py_ssize_t count = baseItf.size() + (!baseType.isNull() ? 1 : 0) + (super != nullptr ? 1 : 0); // Pack into a tuple JPPyObject result = JPPyObject::call(PyList_New(count)); @@ -1155,27 +1155,27 @@ void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls) return; const JPFieldList & instFields = cls->getFields(); - for (auto iter = instFields.begin(); iter != instFields.end(); iter++) + for (auto instField : instFields) { - JPPyObject fieldName(JPPyString::fromStringUTF8((*iter)->getName())); - PyDict_SetItem(members.get(), fieldName.get(), PyJPField_create(*iter).get()); + JPPyObject fieldName(JPPyString::fromStringUTF8(instField->getName())); + PyDict_SetItem(members.get(), fieldName.get(), PyJPField_create(instField).get()); } const JPMethodDispatchList& m_Methods = cls->getMethods(); - for (auto iter = m_Methods.begin(); iter != m_Methods.end(); iter++) + for (auto m_Method : m_Methods) { - JPPyObject methodName(JPPyString::fromStringUTF8((*iter)->getName())); + JPPyObject methodName(JPPyString::fromStringUTF8(m_Method->getName())); PyDict_SetItem(members.get(), methodName.get(), - PyJPMethod_create(*iter, nullptr).get()); + PyJPMethod_create(m_Method, nullptr).get()); } if (cls->isInterface()) { - const JPMethodDispatchList& m_Methods = context->_java_lang_Object->getMethods(); - for (auto iter = m_Methods.begin(); iter != m_Methods.end(); iter++) + const JPMethodDispatchList& m_Methods2 = context->_java_lang_Object->getMethods(); + for (auto m_Method : m_Methods2) { - JPPyObject methodName(JPPyString::fromStringUTF8((*iter)->getName())); + JPPyObject methodName(JPPyString::fromStringUTF8(m_Method->getName())); PyDict_SetItem(members.get(), methodName.get(), - PyJPMethod_create(*iter, nullptr).get()); + PyJPMethod_create(m_Method, nullptr).get()); } } From 78819bb7ebefbb948ac3bfee067bc4fd8e86ffcf Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 19:39:11 +0200 Subject: [PATCH 043/128] removed getMessage --- native/common/include/jp_exception.h | 2 - native/common/jp_context.cpp | 6 +-- native/common/jp_exception.cpp | 56 +++++++--------------------- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 6a6120cdb..43b6db298 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -134,8 +134,6 @@ class JPypeException : std::runtime_error void from(const JPStackInfo& info); - string getMessage() noexcept; - void convertJavaToPython(); void convertPythonToJava(JPContext* context); diff --git a/native/common/jp_context.cpp b/native/common/jp_context.cpp index 764d3fd19..6f09155d9 100644 --- a/native/common/jp_context.cpp +++ b/native/common/jp_context.cpp @@ -103,7 +103,6 @@ void JPContext::startJVM(const string& vmPath, const StringVector& args, loadEntryPoints(vmPath); } catch (JPypeException& ex) { - ex.getMessage(); throw; } @@ -332,10 +331,9 @@ void JPContext::shutdownJVM(bool destroyJVM, bool freeJVM) } JP_TRACE("Delete resources"); - for (auto iter = m_Resources.begin(); - iter != m_Resources.end(); ++iter) + for (auto & m_Resource : m_Resources) { - delete *iter; + delete m_Resource; } m_Resources.clear(); diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 687d3f1be..f0a3b06fd 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -15,6 +15,7 @@ *****************************************************************************/ #include #include + #include "jpype.h" #include "jp_exception.h" #include "pyjp.h" @@ -88,37 +89,6 @@ void JPypeException::from(const JPStackInfo& info) m_Trace.emplace_back(info); } -// Okay from this point on we have to suit up in full Kevlar because -// this code must handle every conceivable and still reach a resolution. -// Exceptions may be throws during initialization where only a fraction -// of the resources are available, during the middle of normal operation, -// or worst of all as the system is being yanked out from under us during -// shutdown. Each and every one of these cases must be considered. -// Further each and every function called here must be hardened similarly -// or they will become the weak link. And remember it is not paranoia if -// they are actually out to get you. -// -// Onward my friends to victory or a glorious segfault! -// TODO: actually we can replace this completely with what() of runtime_error! -string JPypeException::getMessage() noexcept -{ - JP_TRACE_IN("JPypeException::getMessage"); - // Must be bulletproof - try - { - std::stringstream str; - str << std::runtime_error::what() << std::endl; - JP_TRACE(str.str()); - return str.str(); - // GCOVR_EXCL_START - } catch (...) - { - return "error during get message"; - } - JP_TRACE_OUT; - // GCOVR_EXCL_STOP -} - bool isJavaThrowable(PyObject* exceptionClass) { JPClass* cls = PyJPClass_getJPClass(exceptionClass); @@ -252,7 +222,7 @@ void JPypeException::convertPythonToJava(JPContext* context) if (context->m_Context_CreateExceptionID == nullptr) { - frame.ThrowNew(frame.FindClass("java/lang/RuntimeException"), getMessage().c_str()); + frame.ThrowNew(frame.FindClass("java/lang/RuntimeException"), std::runtime_error::what()); return; } @@ -279,7 +249,7 @@ int JPError::_method_not_found = 20; void JPypeException::toPython() { - string mesg; + const char* mesg; JP_TRACE_IN("JPypeException::toPython"); JP_TRACE("err", PyErr_Occurred()); try @@ -290,7 +260,7 @@ void JPypeException::toPython() if (PyErr_CheckSignals()!=0) return; - mesg = getMessage(); + mesg = std::runtime_error::what(); JP_TRACE(m_Error.l); JP_TRACE(mesg.c_str()); @@ -311,7 +281,7 @@ void JPypeException::toPython() // This is hit when a proxy fails to implement a required // method. Only older style proxies should be able hit this. JP_TRACE("Runtime error"); - PyErr_SetString(PyExc_RuntimeError, mesg.c_str()); + PyErr_SetString(PyExc_RuntimeError, mesg); }// This section is only reachable during startup of the JVM. // GCOVR_EXCL_START else if (m_Type == JPError::_os_error_unix) @@ -352,13 +322,13 @@ void JPypeException::toPython() { // All others are Python errors JP_TRACE(Py_TYPE(m_Error.l)->tp_name); - PyErr_SetString((PyObject*) m_Error.l, mesg.c_str()); + PyErr_SetString((PyObject*) m_Error.l, mesg); } else { // This should not be possible unless we failed to cover one of the // exception type codes. JP_TRACE("Unknown error"); - PyErr_SetString(PyExc_RuntimeError, mesg.c_str()); // GCOVR_EXCL_LINE + PyErr_SetString(PyExc_RuntimeError, mesg); // GCOVR_EXCL_LINE } // Attach our info as the cause @@ -388,9 +358,9 @@ void JPypeException::toPython() JPTracer::trace("Inner Python:", ((PyTypeObject*) eframe.m_ExceptionClass.get())->tp_name); return; // Let these go to Python so we can see the error } else if (ex.m_Type == JPError::_java_error) - JPTracer::trace("Inner Java:", ex.getMessage()); + JPTracer::trace("Inner Java:", ex.what()); else - JPTracer::trace("Inner:", ex.getMessage()); + JPTracer::trace("Inner:", ex.what()); JPStackInfo info = ex.m_Trace.front(); JPTracer::trace(info.getFile(), info.getFunction(), info.getLine()); @@ -416,7 +386,7 @@ void JPypeException::toJava(JPContext *context) JP_TRACE_IN("JPypeException::toJava"); try { - string mesg = getMessage(); + const char* mesg = what(); JPJavaFrame frame = JPJavaFrame::external(context, context->getEnv()); if (m_Type == JPError::_java_error) { @@ -433,7 +403,7 @@ void JPypeException::toJava(JPContext *context) if (m_Type == JPError::_method_not_found) { - frame.ThrowNew(context->m_NoSuchMethodError.get(), mesg.c_str()); + frame.ThrowNew(context->m_NoSuchMethodError.get(), mesg); return; } @@ -450,14 +420,14 @@ void JPypeException::toJava(JPContext *context) JPPyCallAcquire callback; // All others are Python errors JP_TRACE(Py_TYPE(m_Error.l)->tp_name); - PyErr_SetString((PyObject*) m_Error.l, mesg.c_str()); + PyErr_SetString((PyObject*) m_Error.l, mesg); convertPythonToJava(context); return; } // All others are issued as RuntimeExceptions JP_TRACE("String exception"); - frame.ThrowNew(context->m_RuntimeException.get(), mesg.c_str()); + frame.ThrowNew(context->m_RuntimeException.get(), mesg); return; } catch (JPypeException& ex) // GCOVR_EXCL_LINE { // GCOVR_EXCL_START From 7f10e506d7292ad793483075e63370766fdf4322 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 20:10:57 +0200 Subject: [PATCH 044/128] jpypeexception: reordering, simplification --- native/common/include/jp_exception.h | 2 +- native/common/jp_exception.cpp | 29 +++++++++++----------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 43b6db298..cc486092a 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -128,7 +128,7 @@ class JPypeException : std::runtime_error JPypeException(int type, const string& msn, int error, const JPStackInfo& stackInfo); // The copy constructor for an object thrown as an exception must be declared noexcept, including any implicitly-defined copy constructors. // Any function declared noexcept that terminates by throwing an exception violates ERR55-CPP. Honor exception specifications. - JPypeException(const std::runtime_error &unnamed, const JPypeException &ex) noexcept; + JPypeException(const JPypeException &ex) noexcept = default; JPypeException& operator = (const JPypeException& ex); ~JPypeException() override = default; diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index f0a3b06fd..e1988cf72 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -23,29 +23,28 @@ PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace); JPypeException::JPypeException(JPJavaFrame &frame, jthrowable th, const JPStackInfo& stackInfo) -: m_Throwable(frame, th), std::runtime_error(frame.toString(th)) +: std::runtime_error(frame.toString(th)), + m_Context(frame.getContext()), + m_Type(JPError::_java_error), + m_Throwable(frame, th) { JP_TRACE("JAVA EXCEPTION THROWN with java throwable"); - m_Context = frame.getContext(); - m_Type = JPError::_java_error; m_Error.l = nullptr; from(stackInfo); } JPypeException::JPypeException(int type, void* error, const JPStackInfo& stackInfo) -: std::runtime_error("None") +: std::runtime_error("None"), m_Type(type) { JP_TRACE("EXCEPTION THROWN with error", error); - m_Type = type; m_Error.l = error; from(stackInfo); } JPypeException::JPypeException(int type, void* errType, const string& msn, const JPStackInfo& stackInfo) -: std::runtime_error(msn) +: std::runtime_error(msn), m_Type(type) { JP_TRACE("EXCEPTION THROWN", errType, msn); - m_Type = type; m_Error.l = errType; //m_Message = msn; from(stackInfo); @@ -55,26 +54,20 @@ JPypeException::JPypeException(int type, void* errType, const string& msn, const // This is only used during startup for OSError JPypeException::JPypeException(int type, const string& msn, int errType, const JPStackInfo& stackInfo) -: std::runtime_error(msn) +: std::runtime_error(msn), m_Type(type) { JP_TRACE("EXCEPTION THROWN", errType, msn); - m_Type = type; m_Error.i = errType; from(stackInfo); } -JPypeException::JPypeException(const std::runtime_error &unnamed, const JPypeException &ex) noexcept -: runtime_error(unnamed), m_Context(ex.m_Context), m_Trace(ex.m_Trace), m_Throwable(ex.m_Throwable) -{ - m_Type = ex.m_Type; - m_Error = ex.m_Error; -} - JPypeException& JPypeException::operator = (const JPypeException& ex) { if(this == &ex) + { return *this; - m_Context = ex.m_Context; + } + m_Context = ex.m_Context; m_Type = ex.m_Type; m_Trace = ex.m_Trace; m_Throwable = ex.m_Throwable; @@ -262,7 +255,7 @@ void JPypeException::toPython() mesg = std::runtime_error::what(); JP_TRACE(m_Error.l); - JP_TRACE(mesg.c_str()); + JP_TRACE(mesg); // We already have a Python error on the stack. if (PyErr_Occurred()) From 0df72fe8a29ae7675598e0c3fe88403f335a9037 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 20:55:01 +0200 Subject: [PATCH 045/128] jpypeexception: initialize mesg --- native/common/jp_exception.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index e1988cf72..8831575ca 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -242,7 +242,7 @@ int JPError::_method_not_found = 20; void JPypeException::toPython() { - const char* mesg; + const char* mesg = nullptr; JP_TRACE_IN("JPypeException::toPython"); JP_TRACE("err", PyErr_Occurred()); try From 6a92aa97924fda01519620097ac898f10e37c0bf Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 21:06:29 +0200 Subject: [PATCH 046/128] method move arguments, default ctor impl, delete copy construction --- native/common/include/jp_javaframe.h | 6 +++--- native/common/include/jp_method.h | 17 +++++++++-------- native/common/include/jp_methoddispatch.h | 7 ++----- native/common/jp_method.cpp | 3 +-- native/common/jp_typefactory.cpp | 3 +-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/native/common/include/jp_javaframe.h b/native/common/include/jp_javaframe.h index 624ee5e29..a2ebbe25f 100644 --- a/native/common/include/jp_javaframe.h +++ b/native/common/include/jp_javaframe.h @@ -194,10 +194,10 @@ class JPJavaFrame JPClass *findClassByName(const string& name); JPClass *findClassForObject(jobject obj); -private: - // not implemented - JPJavaFrame& operator= (const JPJavaFrame& frame); + // not implemented + JPJavaFrame& operator= (const JPJavaFrame& frame) = delete; +private: jint PushLocalFrame(jint); jobject PopLocalFrame(jobject); diff --git a/native/common/include/jp_method.h b/native/common/include/jp_method.h index dc889fcf3..ab6789ee0 100644 --- a/native/common/include/jp_method.h +++ b/native/common/include/jp_method.h @@ -22,7 +22,7 @@ class JPMethod : public JPResource { friend class JPMethodDispatch; public: - JPMethod(); + JPMethod() = default; JPMethod(JPJavaFrame& frame, JPClass* claz, const string& name, @@ -35,7 +35,7 @@ class JPMethod : public JPResource void setParameters( JPClass *returnType, - JPClassList parameterTypes); + JPClassList&& parameterTypes); /** Check to see if this overload matches the argument list. * @@ -97,22 +97,23 @@ class JPMethod : public JPResource return m_Method.get(); } + JPMethod& operator=(const JPMethod&) = delete; + private: void packArgs(JPJavaFrame &frame, JPMethodMatch &match, vector &v, JPPyObjectVector &arg); void ensureTypeCache(); JPMethod(const JPMethod& o); - JPMethod& operator=(const JPMethod&) ; private: - JPClass* m_Class; + JPClass* m_Class{}; string m_Name; JPObjectRef m_Method; - jmethodID m_MethodID; - JPClass* m_ReturnType; + jmethodID m_MethodID{}; + JPClass* m_ReturnType{}; JPClassList m_ParameterTypes; JPMethodList m_MoreSpecificOverloads; - jint m_Modifiers; + jint m_Modifiers{}; } ; -#endif // _JPMETHODOVERLOAD_H_ \ No newline at end of file +#endif // _JPMETHOD_H_ \ No newline at end of file diff --git a/native/common/include/jp_methoddispatch.h b/native/common/include/jp_methoddispatch.h index 0762b43d1..3fd6f98a5 100644 --- a/native/common/include/jp_methoddispatch.h +++ b/native/common/include/jp_methoddispatch.h @@ -31,10 +31,8 @@ class JPMethodDispatch : public JPResource jint modifiers); ~JPMethodDispatch() override; - -private: - JPMethodDispatch(const JPMethodDispatch& method); - JPMethodDispatch& operator=(const JPMethodDispatch& method); + JPMethodDispatch(const JPMethodDispatch& method) = delete; + JPMethodDispatch& operator=(const JPMethodDispatch& method) = delete; public: @@ -83,7 +81,6 @@ class JPMethodDispatch : public JPResource * when matching with a non-static. */ bool findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch, JPPyObjectVector& vargs, bool searchInstance, bool raise); - void dumpOverloads(); JPClass* m_Class; string m_Name; diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index 87e6a09cf..e199b0d1c 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -15,7 +15,6 @@ *****************************************************************************/ #include "jpype.h" #include "jp_arrayclass.h" -#include "jp_boxedtype.h" #include "jp_method.h" #include "pyjp.h" @@ -41,7 +40,7 @@ JPMethod::~JPMethod() void JPMethod::setParameters( JPClass *returnType, - JPClassList parameterTypes) + JPClassList&& parameterTypes) { m_ReturnType = returnType; m_ParameterTypes = parameterTypes; diff --git a/native/common/jp_typefactory.cpp b/native/common/jp_typefactory.cpp index 754f4c7ae..6388f3764 100644 --- a/native/common/jp_typefactory.cpp +++ b/native/common/jp_typefactory.cpp @@ -68,7 +68,6 @@ template void convert(JPJavaFrame& frame, jlongArray array, vector& { out[i] = (T) values[i]; } - return; } #ifdef JP_TRACING_ENABLE @@ -446,7 +445,7 @@ JNIEXPORT void JNICALL Java_org_jpype_manager_TypeFactoryNative_populateMethod( JPClassList cargs; convert(frame, argumentTypes, cargs); auto *methodPtr = (JPMethod*) method; - methodPtr->setParameters((JPClass*) returnType, cargs); + methodPtr->setParameters((JPClass*) returnType, std::move(cargs)); JP_JAVA_CATCH(); // GCOVR_EXCL_LINE } From 0bf704413bc1f0729700b6c98e8449c0d430bec8 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 21:20:52 +0200 Subject: [PATCH 047/128] jpypeexcetion: copy ctor --- native/common/include/jp_exception.h | 2 +- native/common/jp_exception.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index cc486092a..5a31e04dc 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -128,7 +128,7 @@ class JPypeException : std::runtime_error JPypeException(int type, const string& msn, int error, const JPStackInfo& stackInfo); // The copy constructor for an object thrown as an exception must be declared noexcept, including any implicitly-defined copy constructors. // Any function declared noexcept that terminates by throwing an exception violates ERR55-CPP. Honor exception specifications. - JPypeException(const JPypeException &ex) noexcept = default; + JPypeException(const JPypeException &ex) noexcept; JPypeException& operator = (const JPypeException& ex); ~JPypeException() override = default; diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 8831575ca..a472e578b 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -61,6 +61,13 @@ JPypeException::JPypeException(int type, const string& msn, int errType, const from(stackInfo); } +JPypeException::JPypeException(const JPypeException &ex) noexcept + : runtime_error(ex), m_Context(ex.m_Context), m_Trace(ex.m_Trace), m_Throwable(ex.m_Throwable) +{ + m_Type = ex.m_Type; + m_Error = ex.m_Error; +} + JPypeException& JPypeException::operator = (const JPypeException& ex) { if(this == &ex) From e434a881a86efee189b28a51907df085155cfd77 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 21:45:04 +0200 Subject: [PATCH 048/128] removed fixme (parallel only works for multiple extensions, not source files of it) --- setup.py | 5 ++--- setupext/build_ext.py | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 8e428e0e2..7f7617ee2 100644 --- a/setup.py +++ b/setup.py @@ -19,13 +19,12 @@ # ***************************************************************************** import sys from pathlib import Path -from setuptools import setup + from setuptools import Extension -import glob +from setuptools import setup import setupext - if '--android' in sys.argv: platform = 'android' sys.argv.remove('--android') diff --git a/setupext/build_ext.py b/setupext/build_ext.py index b126048d4..7d42e9960 100644 --- a/setupext/build_ext.py +++ b/setupext/build_ext.py @@ -229,7 +229,6 @@ def build_extensions(self): # has to be last call print("Call build extensions") - # FIXME: self.parallel seems to not be initialized properly. super().build_extensions() def build_extension(self, ext): From 5579dbc5e3ec99a486f5a5df5c69471c802a7e40 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 21:56:03 +0200 Subject: [PATCH 049/128] added assertion about Jpypeexception to be nothrow copy constructable --- native/common/jp_exception.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index a472e578b..a0dadf26c 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -20,6 +20,9 @@ #include "jp_exception.h" #include "pyjp.h" +static_assert(std::is_nothrow_copy_constructible::value, + "S must be nothrow copy constructible"); + PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace); JPypeException::JPypeException(JPJavaFrame &frame, jthrowable th, const JPStackInfo& stackInfo) @@ -563,7 +566,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab for (jsize i = 0; i < sz; i += 4) { string filename, method; - auto jclassname = (jstring) frame.GetObjectArrayElement(obj, i); + auto jclassname = static_cast(frame.GetObjectArrayElement(obj, i)); auto jmethodname = (jstring) frame.GetObjectArrayElement(obj, i + 1); auto jfilename = (jstring) frame.GetObjectArrayElement(obj, i + 2); if (jfilename != nullptr) From c4d0881a9eb35e6939bef6671c82f2d722678a11 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 21:58:53 +0200 Subject: [PATCH 050/128] use dynamic_cast --- native/common/include/jp_primitive_accessor.h | 6 +++--- native/common/jp_array.cpp | 10 +++++----- native/common/jp_buffer.cpp | 2 +- native/common/jp_bytetype.cpp | 2 +- native/common/jp_class.cpp | 2 +- native/common/jp_classhints.cpp | 20 +++++++++---------- native/common/jp_doubletype.cpp | 4 ++-- native/common/jp_floattype.cpp | 4 ++-- native/common/jp_inttype.cpp | 4 ++-- native/common/jp_longtype.cpp | 4 ++-- native/common/jp_method.cpp | 8 ++++---- native/common/jp_proxy.cpp | 4 ++-- native/common/jp_shorttype.cpp | 4 ++-- native/python/pyjp_char.cpp | 2 +- native/python/pyjp_class.cpp | 4 ++-- native/python/pyjp_module.cpp | 2 +- native/python/pyjp_number.cpp | 4 ++-- 17 files changed, 43 insertions(+), 43 deletions(-) diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index acd03b1f2..130179b7b 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -253,8 +253,8 @@ class JPConversionLongWiden : public JPConversion { JPValue *value = match.getJavaSlot(); jvalue ret; - base_t::field(ret) = (typename base_t::type_t) ((JPPrimitiveType*) - value->getClass())->getAsLong(value->getValue()); + base_t::field(ret) = (typename base_t::type_t) (dynamic_cast( + value->getClass()))->getAsLong(value->getValue()); return ret; } } ; @@ -333,7 +333,7 @@ class JPConversionFloatWiden : public JPConversion { JPValue *value = match.getJavaSlot(); jvalue ret; - base_t::field(ret) = (typename base_t::type_t) ((JPPrimitiveType*) value->getClass())->getAsDouble(value->getValue()); + base_t::field(ret) = (typename base_t::type_t) (dynamic_cast( value->getClass()))->getAsDouble(value->getValue()); return ret; } } ; diff --git a/native/common/jp_array.cpp b/native/common/jp_array.cpp index afc0f5f66..5f14dbb9a 100644 --- a/native/common/jp_array.cpp +++ b/native/common/jp_array.cpp @@ -27,7 +27,7 @@ JPArray::JPArray(const JPValue &value) : m_Object(value.getClass()->getContext(), (jarray) value.getValue().l) { - m_Class = (JPArrayClass*) value.getClass(); + m_Class = dynamic_cast( value.getClass()); JPJavaFrame frame = JPJavaFrame::outer(m_Class->getContext()); JP_TRACE_IN("JPArray::JPArray"); ASSERT_NOT_NULL(m_Class); @@ -147,7 +147,7 @@ JPArrayView::JPArrayView(JPArray* array) m_Buffer.obj = nullptr; m_Buffer.ndim = 1; m_Buffer.suboffsets = nullptr; - auto *type = (JPPrimitiveType*) array->getClass()->getComponentType(); + auto *type = dynamic_cast( array->getClass()->getComponentType()); type->getView(*this); m_Strides[0] = m_Buffer.itemsize * array->m_Step; m_Shape[0] = array->m_Length; @@ -171,8 +171,8 @@ JPArrayView::JPArrayView(JPArray* array, jobject collection) jobject item1 = frame.GetObjectArrayElement((jobjectArray) collection, 1); // First element is the primitive type that we are packing the array from - auto *componentType = (JPPrimitiveType*) - frame.findClass((jclass) item0); + auto *componentType = dynamic_cast( + frame.findClass((jclass) item0)); // Second element is the shape of the array from which we compute the // memory size, the shape, and strides @@ -249,7 +249,7 @@ void JPArrayView::reference() bool JPArrayView::unreference() { m_RefCount--; - auto *type = (JPPrimitiveType*) m_Array->getClass()->getComponentType(); + auto *type = dynamic_cast( m_Array->getClass()->getComponentType()); if (m_RefCount == 0 && !m_Owned) type->releaseView(*this); return m_RefCount == 0; diff --git a/native/common/jp_buffer.cpp b/native/common/jp_buffer.cpp index a462ae1ac..d98bbaed0 100644 --- a/native/common/jp_buffer.cpp +++ b/native/common/jp_buffer.cpp @@ -22,7 +22,7 @@ JPBuffer::JPBuffer(const JPValue &value) : m_Object(value.getClass()->getContext(), value.getValue().l) { - m_Class = (JPBufferType*) value.getClass(); + m_Class = dynamic_cast( value.getClass()); JPJavaFrame frame = JPJavaFrame::outer(m_Class->getContext()); JP_TRACE_IN("JPBuffer::JPBuffer"); m_Address = frame.GetDirectBufferAddress(m_Object.get()); diff --git a/native/common/jp_bytetype.cpp b/native/common/jp_bytetype.cpp index 1c25f4d9c..3cca54ae2 100644 --- a/native/common/jp_bytetype.cpp +++ b/native/common/jp_bytetype.cpp @@ -41,7 +41,7 @@ JPValue JPByteType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - auto* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = dynamic_cast( frame.findClassForObject(jo)); field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, nullptr); return JPValue(this, v); } diff --git a/native/common/jp_class.cpp b/native/common/jp_class.cpp index 6a6196995..265ee2757 100644 --- a/native/common/jp_class.cpp +++ b/native/common/jp_class.cpp @@ -115,7 +115,7 @@ JPClass* JPClass::newArrayType(JPJavaFrame &frame, long d) for (long i = 0; i < d; ++i) ss << "["; if (isPrimitive()) - ss << ((JPPrimitiveType*) this)->getTypeCode(); + ss << (dynamic_cast( this))->getTypeCode(); else if (isArray()) ss << getName(); else diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index 5ba6bd583..3fb50102c 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -364,7 +364,7 @@ class JPConversionCharArray : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionCharArray::matches"); - auto* acls = (JPArrayClass*) cls; + auto* acls = dynamic_cast( cls); if (match.frame == nullptr || !JPPyString::check(match.object) || acls->getComponentType() != match.getContext()->_char) return match.type = JPMatch::_none; @@ -375,7 +375,7 @@ class JPConversionCharArray : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { - auto* acls = (JPArrayClass*) cls; + auto* acls = dynamic_cast( cls); if (acls->getComponentType() != cls->getContext()->_char) return; PyList_Append(info.implicit, (PyObject*) & PyUnicode_Type); @@ -406,7 +406,7 @@ class JPConversionByteArray : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionByteArray::matches"); - auto* acls = (JPArrayClass*) cls; + auto* acls = dynamic_cast( cls); if (match.frame == nullptr || !PyBytes_Check(match.object) || acls->getComponentType() != match.frame->getContext()->_byte) return match.type = JPMatch::_none; @@ -417,7 +417,7 @@ class JPConversionByteArray : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { - auto* acls = (JPArrayClass*) cls; + auto* acls = dynamic_cast( cls); if (acls->getComponentType() != cls->getContext()->_byte) return; PyList_Append(info.implicit, (PyObject*) & PyBytes_Type); @@ -444,7 +444,7 @@ class JPConversionBuffer : public JPConversion JPMatch::Type matches(JPClass *cls, JPMatch &match) override { JP_TRACE_IN("JPConversionBuffer::matches"); - auto *acls = (JPArrayClass*) cls; + auto *acls = dynamic_cast( cls); JPClass *componentType = acls->getComponentType(); if ( !componentType->isPrimitive()) return match.type = JPMatch::_none; @@ -509,7 +509,7 @@ class JPConversionSequence : public JPConversion JP_TRACE_IN("JPConversionSequence::matches"); if ( !PySequence_Check(match.object) || JPPyString::check(match.object)) return match.type = JPMatch::_none; - auto *acls = (JPArrayClass*) cls; + auto *acls = dynamic_cast( cls); JPClass *componentType = acls->getComponentType(); JPPySequence seq = JPPySequence::use(match.object); jlong length = seq.size(); @@ -541,7 +541,7 @@ class JPConversionSequence : public JPConversion PyObject *typing = PyImport_AddModule("jpype.protocol"); JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "Sequence")); PyList_Append(info.implicit, proto.get()); - auto* acls = (JPArrayClass*) cls; + auto* acls = dynamic_cast( cls); if (acls->getComponentType() == cls->getContext()->_char) return; PyList_Append(info.none, (PyObject*) & PyUnicode_Type); @@ -878,7 +878,7 @@ class JPConversionJavaObjectAny : public JPConversionBox } else { // Okay we need to box it. - auto* type = (JPPrimitiveType*) (value->getClass()); + auto* type = dynamic_cast (value->getClass()); match.closure = type->getBoxedClass(frame->getContext()); res = JPConversionBox::convert(match); return res; @@ -933,7 +933,7 @@ class JPConversionUnbox : public JPConversion if (context == nullptr) return match.type = JPMatch::_none; JPValue *slot = match.slot; - auto *pcls = (JPPrimitiveType*) cls; + auto *pcls = dynamic_cast( cls); if (slot->getClass() != pcls->getBoxedClass(context)) return match.type = JPMatch::_none; match.conversion = this; @@ -944,7 +944,7 @@ class JPConversionUnbox : public JPConversion void getInfo(JPClass *cls, JPConversionInfo &info) override { JPJavaFrame frame = JPJavaFrame::outer(cls->getContext()); - auto *pcls = (JPPrimitiveType*) cls; + auto *pcls = dynamic_cast( cls); JPContext *context = cls->getContext(); PyList_Append(info.implicit, PyJPClass_create(frame, pcls->getBoxedClass(context)).get()); diff --git a/native/common/jp_doubletype.cpp b/native/common/jp_doubletype.cpp index b1e6794ad..391f85306 100644 --- a/native/common/jp_doubletype.cpp +++ b/native/common/jp_doubletype.cpp @@ -39,7 +39,7 @@ JPValue JPDoubleType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - auto* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = dynamic_cast( frame.findClassForObject(jo)); field(v) = (type_t) frame.CallDoubleMethodA(jo, jb->m_DoubleValueID, nullptr); return JPValue(this, v); } @@ -83,7 +83,7 @@ class JPConversionAsJDouble : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - auto *prim = (JPPrimitiveType*) cls2; + auto *prim = dynamic_cast( cls2); switch (prim->getTypeCode()) { case 'B': diff --git a/native/common/jp_floattype.cpp b/native/common/jp_floattype.cpp index e8926edd8..8be73ed58 100644 --- a/native/common/jp_floattype.cpp +++ b/native/common/jp_floattype.cpp @@ -43,7 +43,7 @@ JPValue JPFloatType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - auto* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = dynamic_cast( frame.findClassForObject(jo)); field(v) = (type_t) frame.CallFloatMethodA(jo, jb->m_FloatValueID, nullptr); return JPValue(this, v); } @@ -73,7 +73,7 @@ class JPConversionAsJFloat : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - auto *prim = (JPPrimitiveType*) cls2; + auto *prim = dynamic_cast( cls2); switch (prim->getTypeCode()) { case 'B': diff --git a/native/common/jp_inttype.cpp b/native/common/jp_inttype.cpp index 15132c07d..c2152d4a0 100644 --- a/native/common/jp_inttype.cpp +++ b/native/common/jp_inttype.cpp @@ -43,7 +43,7 @@ JPValue JPIntType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - auto* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = dynamic_cast( frame.findClassForObject(jo)); field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, nullptr); return JPValue(this, v); } @@ -73,7 +73,7 @@ class JPConversionJInt : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - auto *prim = (JPPrimitiveType*) cls2; + auto *prim = dynamic_cast( cls2); switch (prim->getTypeCode()) { case 'C': diff --git a/native/common/jp_longtype.cpp b/native/common/jp_longtype.cpp index 57f28937e..104c926cc 100644 --- a/native/common/jp_longtype.cpp +++ b/native/common/jp_longtype.cpp @@ -41,7 +41,7 @@ JPValue JPLongType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - auto* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = dynamic_cast( frame.findClassForObject(jo)); field(v) = (type_t) frame.CallLongMethodA(jo, jb->m_LongValueID, nullptr); return JPValue(this, v); } @@ -70,7 +70,7 @@ class JPConversionJLong : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - auto *prim = (JPPrimitiveType*) cls2; + auto *prim = dynamic_cast( cls2); switch (prim->getTypeCode()) { case 'I': diff --git a/native/common/jp_method.cpp b/native/common/jp_method.cpp index e199b0d1c..debc9557d 100644 --- a/native/common/jp_method.cpp +++ b/native/common/jp_method.cpp @@ -54,7 +54,7 @@ string JPMethod::toString() const JPMatch::Type matchVars(JPJavaFrame &frame, JPMethodMatch& match, JPPyObjectVector &arg, size_t start, JPClass *vartype) { JP_TRACE_IN("JPMethod::matchVars"); - auto *arraytype = (JPArrayClass*) vartype; + auto *arraytype = dynamic_cast( vartype); JPClass *type = arraytype->getComponentType(); size_t len = arg.size(); @@ -189,7 +189,7 @@ void JPMethod::packArgs(JPJavaFrame &frame, JPMethodMatch &match, { JP_TRACE("Pack indirect varargs"); len = tlen - 1; - auto* type = (JPArrayClass*) m_ParameterTypes[tlen - 1]; + auto* type = dynamic_cast( m_ParameterTypes[tlen - 1]); v[tlen - 1 - match.m_Skip] = type->convertToJavaVector(frame, arg, (jsize) tlen - 1, (jsize) arg.size()); } @@ -282,7 +282,7 @@ JPPyObject JPMethod::invokeCallerSensitive(JPMethodMatch& match, JPPyObjectVecto JPClass *cls = m_ParameterTypes[i + match.m_Skip - match.m_Offset]; if (cls->isPrimitive()) { - auto* type = (JPPrimitiveType*) cls; + auto* type = dynamic_cast( cls); PyObject *u = arg[i + match.m_Skip]; JPMatch conv(&frame, u); JPClass *boxed = type->getBoxedClass(context); @@ -309,7 +309,7 @@ JPPyObject JPMethod::invokeCallerSensitive(JPMethodMatch& match, JPPyObjectVecto if (retType->isPrimitive()) { JP_TRACE("Return primitive"); - JPClass *boxed = ((JPPrimitiveType*) retType)->getBoxedClass(context); + JPClass *boxed = (dynamic_cast( retType))->getBoxedClass(context); JPValue out = retType->getValueFromObject(JPValue(boxed, o)); return retType->convertToPythonObject(frame, out.getValue(), false); } else diff --git a/native/common/jp_proxy.cpp b/native/common/jp_proxy.cpp index 2b9e6b01c..a9d83de2d 100644 --- a/native/common/jp_proxy.cpp +++ b/native/common/jp_proxy.cpp @@ -123,7 +123,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( if (returnClass->findJavaConversion(returnMatch) == JPMatch::_none) JP_RAISE(PyExc_TypeError, "Return value is not compatible with required type."); jvalue res = returnMatch.convert(); - auto *boxed = (JPBoxedType *) ((JPPrimitiveType*) returnClass)->getBoxedClass(context); + auto *boxed = dynamic_cast( (dynamic_cast( returnClass))->getBoxedClass(context)); jvalue res2; res2.l = boxed->box(frame, res); return frame.keep(res2.l); @@ -290,7 +290,7 @@ JPPyObject JPProxyIndirect::getCallable(const string& cname) JPProxyFunctional::JPProxyFunctional(JPContext* context, PyJPProxy* inst, JPClassList& intf) : JPProxy(context, inst, intf) { - m_Functional = (JPFunctional*) intf[0]; + m_Functional = dynamic_cast( intf[0]); } JPProxyFunctional::~JPProxyFunctional() diff --git a/native/common/jp_shorttype.cpp b/native/common/jp_shorttype.cpp index e7cce5b44..3ea1b8a40 100644 --- a/native/common/jp_shorttype.cpp +++ b/native/common/jp_shorttype.cpp @@ -41,7 +41,7 @@ JPValue JPShortType::getValueFromObject(const JPValue& obj) JPJavaFrame frame = JPJavaFrame::outer(context); jvalue v; jobject jo = obj.getValue().l; - auto* jb = (JPBoxedType*) frame.findClassForObject(jo); + auto* jb = dynamic_cast( frame.findClassForObject(jo)); field(v) = (type_t) frame.CallIntMethodA(jo, jb->m_IntValueID, nullptr); return JPValue(this, v); } @@ -71,7 +71,7 @@ class JPConversionJShort : public JPConversionJavaValue if (cls2->isPrimitive()) { // https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.1.2 - auto *prim = (JPPrimitiveType*) cls2; + auto *prim = dynamic_cast( cls2); switch (prim->getTypeCode()) { case 'C': diff --git a/native/python/pyjp_char.cpp b/native/python/pyjp_char.cpp index b36eca8be..431f93a13 100644 --- a/native/python/pyjp_char.cpp +++ b/native/python/pyjp_char.cpp @@ -141,7 +141,7 @@ Py_UCS2 fromJPValue(const JPValue & value) JPClass* cls = value.getClass(); if (cls->isPrimitive()) return (Py_UCS2) (value.getValue().c); - JPPrimitiveType* pcls = ((JPBoxedType*) cls)->getPrimitive(); + JPPrimitiveType* pcls = (dynamic_cast( cls))->getPrimitive(); if (value.getValue().l == nullptr) return (Py_UCS2) - 1; else diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index 193be84a4..47d2ba683 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -719,7 +719,7 @@ static PyObject *PyJPClass_array(PyJPClass *self, PyObject *item) if (PyIndex_Check(item)) { long sz = PyLong_AsLong(item); - auto *cls = (JPArrayClass*) self->m_Class->newArrayType(frame, 1); + auto *cls = dynamic_cast( self->m_Class->newArrayType(frame, 1)); JPValue v = cls->newArray(frame, sz); return cls->convertToPythonObject(frame, v.getValue(), true).keep(); } @@ -1075,7 +1075,7 @@ JPPyObject PyJPClass_getBases(JPJavaFrame &frame, JPClass* cls) baseType = JPPyObject::use((PyObject*) PyJPException_Type); } else if (cls->isArray()) { - auto* acls = (JPArrayClass*) cls; + auto* acls = dynamic_cast( cls); if (acls->getComponentType()->isPrimitive()) baseType = JPPyObject::use((PyObject*) PyJPArrayPrimitive_Type); else diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index b167dfd73..35481b424 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -850,7 +850,7 @@ static PyObject *PyJPModule_convertBuffer(JPPyBuffer& buffer, PyObject *dtype) // Now we have a valid format code, so next lets get a converter for // the type. - auto *pcls = (JPPrimitiveType *) cls; + auto *pcls = dynamic_cast( cls); // Convert the shape Py_ssize_t subs = 1; diff --git a/native/python/pyjp_number.cpp b/native/python/pyjp_number.cpp index 8ab28ef2b..5f342b83c 100644 --- a/native/python/pyjp_number.cpp +++ b/native/python/pyjp_number.cpp @@ -412,7 +412,7 @@ JPPyObject PyJPNumber_create(JPJavaFrame &frame, JPPyObject& wrapper, const JPVa jlong l = 0; if (value.getValue().l != nullptr) { - auto* jb = (JPBoxedType*) value.getClass(); + auto* jb = dynamic_cast( value.getClass()); l = frame.CallLongMethodA(value.getJavaObject(), jb->m_LongValueID, nullptr); } PyObject *args = PyTuple_Pack(1, PyLong_FromLongLong(l)); @@ -423,7 +423,7 @@ JPPyObject PyJPNumber_create(JPJavaFrame &frame, JPPyObject& wrapper, const JPVa jdouble l = 0; if (value.getValue().l != nullptr) { - auto* jb = (JPBoxedType*) value.getClass(); + auto* jb = dynamic_cast( value.getClass()); l = frame.CallDoubleMethodA(value.getJavaObject(), jb->m_DoubleValueID, nullptr); } PyObject *args = PyTuple_Pack(1, PyFloat_FromDouble(l)); From acb66657598136940b54e47cede97f96aa6bb654 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 22:08:47 +0200 Subject: [PATCH 051/128] no const cast needed here --- native/common/include/jp_buffertype.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/include/jp_buffertype.h b/native/common/include/jp_buffertype.h index a045cc1b4..75b704037 100644 --- a/native/common/include/jp_buffertype.h +++ b/native/common/include/jp_buffertype.h @@ -25,9 +25,9 @@ class JPBufferType : public JPClass JPBufferType(JPJavaFrame& frame, jclass cls, const string& name, JPClass* superClass, const JPClassList& interfaces, jint modifiers); ~ JPBufferType() override; - char* getType() + const char* getType() { - return const_cast (m_Type); + return m_Type; } int getSize() From ff73c4e92e9d5505b0c4228f5ed448b429e492b8 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 22:12:05 +0200 Subject: [PATCH 052/128] jpbuffer: const, initialize fields --- native/common/include/jp_buffer.h | 8 ++++---- native/common/include/jp_buffertype.h | 2 +- native/common/jp_buffer.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/native/common/include/jp_buffer.h b/native/common/include/jp_buffer.h index 3fca57a0c..4916d1d23 100644 --- a/native/common/include/jp_buffer.h +++ b/native/common/include/jp_buffer.h @@ -39,19 +39,19 @@ class JPBuffer return m_Object.get(); } - bool isReadOnly(); + bool isReadOnly() const; Py_buffer& getView(); - bool isValid(); + bool isValid() const; private: JPBufferType* m_Class; JPObjectRef m_Object; void *m_Address; Py_ssize_t m_Capacity; - Py_buffer m_Buffer; - char m_Format[3]; + Py_buffer m_Buffer{}; + char m_Format[3]{}; } ; #endif // _JPBUFFER_H_ \ No newline at end of file diff --git a/native/common/include/jp_buffertype.h b/native/common/include/jp_buffertype.h index 75b704037..e93393e5f 100644 --- a/native/common/include/jp_buffertype.h +++ b/native/common/include/jp_buffertype.h @@ -30,7 +30,7 @@ class JPBufferType : public JPClass return m_Type; } - int getSize() + int getSize() const { return m_Size; } diff --git a/native/common/jp_buffer.cpp b/native/common/jp_buffer.cpp index d98bbaed0..a4c2e4b76 100644 --- a/native/common/jp_buffer.cpp +++ b/native/common/jp_buffer.cpp @@ -44,7 +44,7 @@ JPBuffer::JPBuffer(const JPValue &value) JPBuffer::~JPBuffer() = default; -bool JPBuffer::isReadOnly() +bool JPBuffer::isReadOnly() const { return m_Buffer.readonly != 0; } @@ -54,7 +54,7 @@ Py_buffer& JPBuffer::getView() return m_Buffer; } -bool JPBuffer::isValid() +bool JPBuffer::isValid() const { return m_Capacity != -1; } From f4e9b8088ef11ebbdbdb357958269ef5138ed774 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 22:28:49 +0200 Subject: [PATCH 053/128] jparray: initialize all fields --- native/common/include/jp_array.h | 16 ++++++++-------- native/common/jp_array.cpp | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/native/common/include/jp_array.h b/native/common/include/jp_array.h index b82618af5..f7bbfbe08 100644 --- a/native/common/include/jp_array.h +++ b/native/common/include/jp_array.h @@ -28,16 +28,16 @@ class JPArrayView ~JPArrayView(); void reference(); bool unreference(); - JPContext *getContext(); + JPContext *getContext() const; public: JPArray *m_Array; - void *m_Memory; - Py_buffer m_Buffer; + void *m_Memory{}; + Py_buffer m_Buffer{}; int m_RefCount; - Py_ssize_t m_Shape[5]; - Py_ssize_t m_Strides[5]; - jboolean m_IsCopy; - jboolean m_Owned; + Py_ssize_t m_Shape[50]{}; + Py_ssize_t m_Strides[5]{}; + jboolean m_IsCopy{}; + jboolean m_Owned{}; } ; /** @@ -56,7 +56,7 @@ class JPArray return m_Class; } - jsize getLength(); + jsize getLength() const; void setRange(jsize start, jsize length, jsize step, PyObject* val); JPPyObject getItem(jsize ndx); void setItem(jsize ndx, PyObject*); diff --git a/native/common/jp_array.cpp b/native/common/jp_array.cpp index 5f14dbb9a..f265710a0 100644 --- a/native/common/jp_array.cpp +++ b/native/common/jp_array.cpp @@ -66,7 +66,7 @@ JPArray::JPArray(JPArray* instance, jsize start, jsize stop, jsize step) JPArray::~JPArray() = default; -jsize JPArray::getLength() +jsize JPArray::getLength() const { return m_Length; } @@ -236,7 +236,7 @@ JPArrayView::~JPArrayView() delete [] (char*) m_Memory; } -JPContext *JPArrayView::getContext() +JPContext *JPArrayView::getContext() const { return m_Array->getClass()->getContext(); } From 485482709c479a7d30087b86a40fc5b7141a5370 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 22:29:26 +0200 Subject: [PATCH 054/128] no const cast --- native/python/pyjp_array.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/python/pyjp_array.cpp b/native/python/pyjp_array.cpp index 6a75add1f..1d9f56421 100644 --- a/native/python/pyjp_array.cpp +++ b/native/python/pyjp_array.cpp @@ -414,7 +414,7 @@ static PyMethodDef arrayMethods[] = { }; static PyGetSetDef arrayGetSets[] = { - {"length", (getter) (&PyJPArray_length), nullptr, const_cast (length_doc)}, + {"length", (getter) (&PyJPArray_length), nullptr, (length_doc)}, {nullptr} }; From f53e98f1297ab4e2fd76017dd933967c10af085c Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Mon, 30 May 2022 11:28:39 +0200 Subject: [PATCH 055/128] jpexception cpy ctor --- native/common/jp_exception.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index a0dadf26c..a8a9bf399 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -65,10 +65,9 @@ JPypeException::JPypeException(int type, const string& msn, int errType, const } JPypeException::JPypeException(const JPypeException &ex) noexcept - : runtime_error(ex), m_Context(ex.m_Context), m_Trace(ex.m_Trace), m_Throwable(ex.m_Throwable) + : runtime_error(ex.what()), m_Context(ex.m_Context), m_Trace(ex.m_Trace), + m_Throwable(ex.m_Throwable), m_Type(ex.m_Type), m_Error(ex.m_Error) { - m_Type = ex.m_Type; - m_Error = ex.m_Error; } JPypeException& JPypeException::operator = (const JPypeException& ex) From 6741b2feb2144db6eb6218d777eccc6df03ce079 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 16:59:21 +0200 Subject: [PATCH 056/128] jpexception: use enum --- jpype/_core.py | 5 ++--- native/common/include/jp_exception.h | 16 ++++++++-------- native/common/jp_exception.cpp | 9 +-------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/jpype/_core.py b/jpype/_core.py index 0fcfba7de..27503d522 100644 --- a/jpype/_core.py +++ b/jpype/_core.py @@ -47,9 +47,8 @@ class JVMNotRunning(RuntimeError): # Activate jedi tab completion try: import jedi as _jedi - _jedi.evaluate.compiled.access.ALLOWED_DESCRIPTOR_ACCESS += \ - (_jpype._JMethod, _jpype._JField) -except Exception: + _jedi.evaluate.compiled.access.ALLOWED_DESCRIPTOR_ACCESS += _jpype._JMethod, _jpype._JField +except ModuleNotFoundError: pass diff --git a/native/common/include/jp_exception.h b/native/common/include/jp_exception.h index 5a31e04dc..ad9596366 100644 --- a/native/common/include/jp_exception.h +++ b/native/common/include/jp_exception.h @@ -51,15 +51,15 @@ /** * This is the type of the exception to issue. */ -namespace JPError +enum JPError { -extern int _java_error; -extern int _python_error; -extern int _python_exc; -extern int _os_error_unix; -extern int _os_error_windows; -extern int _method_not_found; -} +_java_error, +_python_error, +_python_exc, +_os_error_unix, +_os_error_windows, +_method_not_found, +}; // Create a stackinfo for a particular location in the code that can then // be passed to the handler routine for auditing. diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index a8a9bf399..605e36c7f 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -242,13 +242,6 @@ void JPypeException::convertPythonToJava(JPContext* context) JP_TRACE_OUT; // GCOVR_EXCL_LINE } -int JPError::_java_error = 1; -int JPError::_python_error = 2; -int JPError::_python_exc = 3; -int JPError::_os_error_unix = 10; -int JPError::_os_error_windows = 11; -int JPError::_method_not_found = 20; - void JPypeException::toPython() { const char* mesg = nullptr; @@ -358,7 +351,7 @@ void JPypeException::toPython() { JPPyErrFrame eframe; JPTracer::trace("Inner Python:", ((PyTypeObject*) eframe.m_ExceptionClass.get())->tp_name); - return; // Let these go to Python so we can see the error + return; // Let these go to Python, so we can see the error } else if (ex.m_Type == JPError::_java_error) JPTracer::trace("Inner Java:", ex.what()); else From fded35e3c870405b725f8176b25ab76de74f97c0 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 17:01:35 +0200 Subject: [PATCH 057/128] added info --- native/common/include/jpype.h | 1 + 1 file changed, 1 insertion(+) diff --git a/native/common/include/jpype.h b/native/common/include/jpype.h index a9614cfbd..406e4b67f 100644 --- a/native/common/include/jpype.h +++ b/native/common/include/jpype.h @@ -43,6 +43,7 @@ #if defined(_MSC_VER) // Visual Studio C++ does not seem have changed __cplusplus since 1997 +// see: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170&viewFallbackFrom=vs-2019 #if (_MSVC_LAND >= 201402) #define NO_EXCEPT_FALSE noexcept(false) #else From 38772965f24a750e232141270b428c11237013ae Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 17:02:17 +0200 Subject: [PATCH 058/128] jp_encoding: minor change --- native/common/jp_encoding.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/common/jp_encoding.cpp b/native/common/jp_encoding.cpp index e7914b62a..bb3af6ccd 100644 --- a/native/common/jp_encoding.cpp +++ b/native/common/jp_encoding.cpp @@ -15,8 +15,8 @@ *****************************************************************************/ #include "jp_encoding.h" -// These encoders handle all of the codes expected to be passed between -// Java and Python assuming they both generate complient codings. However, +// These encoders handle all the codes expected to be passed between +// Java and Python assuming they both generate compliant codings. However, // this code does not handle miscodings very well. The current behavior // is to simply terminate the string at the bad code without producing // a warning. I can add errors, but I am not sure how I would test it @@ -33,7 +33,7 @@ // handling. And the last thing we want to do is throw an exception // while trying to convert an exception string while reporting. That // would completely redirect the user. Thus truncation seems like -// a sane policy unless we can verify all of the potential edge cases. +// a sane policy unless we can verify all the potential edge cases. // // Alternatively we could make them a bit more permissive and // try to automatically correct bad encodings by recognizing @@ -76,7 +76,7 @@ std::string transcribe(const char* in, size_t len, } if (ascii) { - return std::string(in, len); + return {in, len}; } // Convert input to istream source From 32021d6127b1136d21a9c9e13e9a1ab8fd61f825 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 17:04:32 +0200 Subject: [PATCH 059/128] jp_pythontypes: use actual type (PyThreadState) and avoid casting to void*. initialize pointer of m_PyObject --- native/python/include/jp_pythontypes.h | 16 +++++++--------- native/python/jp_pythontypes.cpp | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/native/python/include/jp_pythontypes.h b/native/python/include/jp_pythontypes.h index f174d69d9..b69ebd690 100755 --- a/native/python/include/jp_pythontypes.h +++ b/native/python/include/jp_pythontypes.h @@ -171,7 +171,7 @@ class JPPyObject void decref(); protected: - PyObject* m_PyObject; + PyObject* m_PyObject{nullptr}; } ; /**************************************************************************** @@ -208,7 +208,7 @@ class JPPyString : public JPPyObject */ static string asStringUTF8(PyObject* obj); - static JPPyObject fromCharUTF16(const jchar c); + static JPPyObject fromCharUTF16(jchar c); static bool checkCharUTF16(PyObject* obj); static jchar asCharUTF16(PyObject* obj); @@ -236,9 +236,7 @@ class JPPySequence /** Needed for named constructor. */ - JPPySequence(const JPPySequence& seq) - - = default; + JPPySequence(const JPPySequence& seq) = default; /** Use an existing Python sequence in C++. */ @@ -355,7 +353,7 @@ class JPPyCallRelease /** Reacquire the lock. */ ~JPPyCallRelease(); private: - void* m_State1; + PyThreadState* m_State1; } ; class JPPyBuffer @@ -374,20 +372,20 @@ class JPPyBuffer JPPyBuffer(PyObject* obj, int flags); ~JPPyBuffer(); - char *getBufferPtr(std::vector& indices); + char *getBufferPtr(std::vector& indices) const; Py_buffer& getView() { return m_View; } - bool valid() + bool valid() const { return m_Valid; } private: - Py_buffer m_View; + Py_buffer m_View{}; bool m_Valid; } ; diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index 7779af235..788332841 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -311,20 +311,20 @@ string JPPyString::asStringUTF8(PyObject* pyobj) PyBytes_AsStringAndSize(val.get(), &buffer, &size); JP_PY_CHECK(); if (buffer != nullptr) - return string(buffer, size); + return {buffer, static_cast(size)}; else - return string(); + return {}; } else if (PyBytes_Check(pyobj)) { Py_ssize_t size = 0; char *buffer = nullptr; PyBytes_AsStringAndSize(pyobj, &buffer, &size); JP_PY_CHECK(); - return string(buffer, size); + return {buffer, static_cast(size)}; } // GCOVR_EXCL_START JP_RAISE(PyExc_TypeError, "Failed to convert to string."); - return string(); + return {}; JP_TRACE_OUT; // GCOVR_EXCL_STOP } @@ -346,9 +346,9 @@ JPPyObject JPPySequence::operator[](jlong i) JPPyObjectVector::JPPyObjectVector(PyObject* sequence) { m_Sequence = JPPyObject::use(sequence); - size_t n = PySequence_Size(m_Sequence.get()); + auto n = PySequence_Size(m_Sequence.get()); m_Contents.resize(n); - for (size_t i = 0; i < n; ++i) + for (auto i = 0; i < n; ++i) { m_Contents[i] = JPPyObject::call(PySequence_GetItem(m_Sequence.get(), i)); } @@ -386,8 +386,6 @@ void JPPyErr::restore(JPPyObject& exceptionClass, JPPyObject& exceptionValue, JP PyErr_Restore(exceptionClass.keepNull(), exceptionValue.keepNull(), exceptionTrace.keepNull()); } -int m_count = 0; - JPPyCallAcquire::JPPyCallAcquire() { m_State = (long) PyGILState_Ensure(); @@ -403,14 +401,13 @@ JPPyCallAcquire::~JPPyCallAcquire() JPPyCallRelease::JPPyCallRelease() { // Release the lock and set the thread state to NULL - m_State1 = (void*) PyEval_SaveThread(); + m_State1 = PyEval_SaveThread(); } JPPyCallRelease::~JPPyCallRelease() { - // Reaquire the lock - auto *save = (PyThreadState *) m_State1; - PyEval_RestoreThread(save); + // Re-acquire the lock + PyEval_RestoreThread(m_State1); } JPPyBuffer::JPPyBuffer(PyObject* obj, int flags) @@ -425,7 +422,7 @@ JPPyBuffer::~JPPyBuffer() PyBuffer_Release(&m_View); } -char *JPPyBuffer::getBufferPtr(std::vector& indices) +char *JPPyBuffer::getBufferPtr(std::vector& indices) const { char *pointer = (char*) m_View.buf; // No shape is just a 1D array From dd83cc3e4490eab05916b63330ed9244b5d49790 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 17:09:10 +0200 Subject: [PATCH 060/128] jp_pythontypes: use Py_ssize_t --- native/python/jp_pythontypes.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index 788332841..497666c1b 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -291,7 +291,7 @@ bool JPPyString::check(PyObject* obj) */ JPPyObject JPPyString::fromStringUTF8(const string& str) { - size_t len = str.size(); + auto len = static_cast(str.size()); // Python 3 is always unicode JPPyObject bytes = JPPyObject::call(PyBytes_FromStringAndSize(str.c_str(), len)); @@ -358,11 +358,11 @@ JPPyObjectVector::JPPyObjectVector(PyObject* inst, PyObject* sequence) { m_Instance = JPPyObject::use(inst); m_Sequence = JPPyObject::use(sequence); - size_t n = 0; + Py_ssize_t n = 0; if (sequence != nullptr) n = PySequence_Size(m_Sequence.get()); m_Contents.resize(n + 1); - for (size_t i = 0; i < n; ++i) + for (auto i = 0; i < n; ++i) { m_Contents[i + 1] = JPPyObject::call(PySequence_GetItem(m_Sequence.get(), i)); } From 172dc475423246448b7e3a3f4014cd3ae100c1ff Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 17:16:15 +0200 Subject: [PATCH 061/128] [core] fix bug in jedi autocomplete allowed descriptors --- jpype/_core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jpype/_core.py b/jpype/_core.py index 27503d522..c2fc080e7 100644 --- a/jpype/_core.py +++ b/jpype/_core.py @@ -46,10 +46,14 @@ class JVMNotRunning(RuntimeError): # Activate jedi tab completion try: - import jedi as _jedi - _jedi.evaluate.compiled.access.ALLOWED_DESCRIPTOR_ACCESS += _jpype._JMethod, _jpype._JField + from jedi import __version__ as _jedi_version + import jedi.access as _jedi_access + _jedi_access.ALLOWED_DESCRIPTOR_ACCESS += _jpype._JMethod, _jpype._JField except ModuleNotFoundError: pass +except AttributeError: + import warnings as _w + _w.warn(f"provided Jedi seems out of date. Version is {_jedi_version}.") # See http://scottlobdell.me/2015/04/decorators-arguments-python/ From e9958eda7c4ca897d0c6f882a681335e436c6e94 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 18:42:01 +0200 Subject: [PATCH 062/128] fix uninitialized members variables. use generators --- native/common/include/jp_buffertype.h | 2 +- native/common/include/jp_chartype.h | 2 +- native/common/include/jp_class.h | 4 ++-- native/common/include/jp_javaframe.h | 4 ---- native/common/include/jp_match.h | 4 ++-- native/common/include/jp_method.h | 8 ++++---- native/common/include/jp_methoddispatch.h | 10 +++++----- native/common/include/jp_primitive_accessor.h | 2 +- native/common/include/jp_proxy.h | 2 +- native/common/include/jp_stringtype.h | 2 +- native/common/include/jp_typemanager.h | 2 +- native/common/include/jp_value.h | 11 +---------- native/common/jp_classhints.cpp | 7 +++---- native/common/jp_exception.cpp | 2 +- native/common/jp_javaframe.cpp | 2 +- native/common/jp_methoddispatch.cpp | 17 ++++++----------- native/common/jp_platform.cpp | 6 +++--- native/python/include/pyjp.h | 2 +- native/python/pyjp_class.cpp | 19 ++++++++----------- native/python/pyjp_method.cpp | 8 ++++---- native/python/pyjp_package.cpp | 2 +- native/python/pyjp_value.cpp | 2 +- 22 files changed, 49 insertions(+), 71 deletions(-) diff --git a/native/common/include/jp_buffertype.h b/native/common/include/jp_buffertype.h index e93393e5f..dc6820cc2 100644 --- a/native/common/include/jp_buffertype.h +++ b/native/common/include/jp_buffertype.h @@ -42,4 +42,4 @@ class JPBufferType : public JPClass int m_Size; } ; -#endif // _JPBUFFERCLASS_H_ \ No newline at end of file +#endif // _JPBUFFERTYPE_H_ \ No newline at end of file diff --git a/native/common/include/jp_chartype.h b/native/common/include/jp_chartype.h index 0b7f17e8a..4dfc297ab 100755 --- a/native/common/include/jp_chartype.h +++ b/native/common/include/jp_chartype.h @@ -90,4 +90,4 @@ class JPCharType : public JPPrimitiveType } ; -#endif // _JP-CHAR_TYPE_H_ +#endif // _JP_CHAR_TYPE_H_ diff --git a/native/common/include/jp_class.h b/native/common/include/jp_class.h index dfeaa3000..30985b5ca 100644 --- a/native/common/include/jp_class.h +++ b/native/common/include/jp_class.h @@ -208,7 +208,7 @@ class JPClass : public JPResource JPClassRef m_Class; JPClass* m_SuperClass; JPClassList m_Interfaces; - JPMethodDispatch* m_Constructors; + JPMethodDispatch* m_Constructors{}; JPMethodDispatchList m_Methods; JPFieldList m_Fields; string m_CanonicalName; @@ -217,4 +217,4 @@ class JPClass : public JPResource JPPyObject m_Hints; } ; -#endif // _JPPOBJECTTYPE_H_ \ No newline at end of file +#endif // _JP_CLASS_H_ \ No newline at end of file diff --git a/native/common/include/jp_javaframe.h b/native/common/include/jp_javaframe.h index a2ebbe25f..830ee8e1b 100644 --- a/native/common/include/jp_javaframe.h +++ b/native/common/include/jp_javaframe.h @@ -197,10 +197,6 @@ class JPJavaFrame // not implemented JPJavaFrame& operator= (const JPJavaFrame& frame) = delete; -private: - jint PushLocalFrame(jint); - jobject PopLocalFrame(jobject); - public: bool ExceptionCheck(); diff --git a/native/common/include/jp_match.h b/native/common/include/jp_match.h index ce9367ae4..239defb68 100644 --- a/native/common/include/jp_match.h +++ b/native/common/include/jp_match.h @@ -64,8 +64,8 @@ class JPMatch class JPMethodCache { public: - long m_Hash; - JPMethod* m_Overload; + long m_Hash{}; + JPMethod* m_Overload{}; } ; class JPMethodMatch : public JPMethodCache diff --git a/native/common/include/jp_method.h b/native/common/include/jp_method.h index ab6789ee0..e24f1e99c 100644 --- a/native/common/include/jp_method.h +++ b/native/common/include/jp_method.h @@ -107,12 +107,12 @@ class JPMethod : public JPResource private: JPClass* m_Class{}; - string m_Name; - JPObjectRef m_Method; + string m_Name{}; + JPObjectRef m_Method{}; jmethodID m_MethodID{}; JPClass* m_ReturnType{}; - JPClassList m_ParameterTypes; - JPMethodList m_MoreSpecificOverloads; + JPClassList m_ParameterTypes{}; + JPMethodList m_MoreSpecificOverloads{}; jint m_Modifiers{}; } ; diff --git a/native/common/include/jp_methoddispatch.h b/native/common/include/jp_methoddispatch.h index 3fd6f98a5..5c981c8d6 100644 --- a/native/common/include/jp_methoddispatch.h +++ b/native/common/include/jp_methoddispatch.h @@ -82,11 +82,11 @@ class JPMethodDispatch : public JPResource */ bool findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch, JPPyObjectVector& vargs, bool searchInstance, bool raise); - JPClass* m_Class; - string m_Name; - JPMethodList m_Overloads; - jlong m_Modifiers; - JPMethodCache m_LastCache; + JPClass* m_Class{}; + string m_Name{}; + JPMethodList m_Overloads{}; + jlong m_Modifiers{}; + JPMethodCache m_LastCache{}; } ; #endif // _JPMETHODDISPATCH_H_ \ No newline at end of file diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index 130179b7b..bb55ecd90 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -30,7 +30,7 @@ class JPPrimitiveArrayAccessor array_t _array; ptr_t _elem; releaseFnc _release; - jboolean _iscopy; + jboolean _iscopy{}; public: diff --git a/native/common/include/jp_proxy.h b/native/common/include/jp_proxy.h index 6739be12f..2235c766f 100644 --- a/native/common/include/jp_proxy.h +++ b/native/common/include/jp_proxy.h @@ -98,4 +98,4 @@ class JPProxyType : public JPClass jfieldID m_InstanceID; } ; -#endif // JPPROXY_H \ No newline at end of file +#endif // _JPPROXY_H_ \ No newline at end of file diff --git a/native/common/include/jp_stringtype.h b/native/common/include/jp_stringtype.h index ce634d17e..6029950e2 100644 --- a/native/common/include/jp_stringtype.h +++ b/native/common/include/jp_stringtype.h @@ -35,4 +35,4 @@ class JPStringType : public JPClass JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; } ; -#endif /* JP_STRINGTYPE_H */ \ No newline at end of file +#endif /* JP_STRINGCLASS_H */ \ No newline at end of file diff --git a/native/common/include/jp_typemanager.h b/native/common/include/jp_typemanager.h index abb34e2e6..2e2dbd780 100644 --- a/native/common/include/jp_typemanager.h +++ b/native/common/include/jp_typemanager.h @@ -54,4 +54,4 @@ class JPTypeManager jmethodID m_InterfaceParameterCount; } ; -#endif // _JPCLASS_H_ \ No newline at end of file +#endif // _JPTYPE_MANAGER_H_ \ No newline at end of file diff --git a/native/common/include/jp_value.h b/native/common/include/jp_value.h index 4a3b994ee..16f754c6d 100644 --- a/native/common/include/jp_value.h +++ b/native/common/include/jp_value.h @@ -62,8 +62,7 @@ class JPValue jobject getJavaObject() const; - // Cast operators to jvalue. - // TODO: these could be explicit too, right? + // Cast operators to jvalue. Implicit casting is desired. operator jvalue&() { return m_Value; @@ -73,14 +72,6 @@ class JPValue { return m_Value; } - - // TODO: never used. - JPValue& global(JPJavaFrame& frame) - { - m_Value.l = frame.NewGlobalRef(m_Value.l); - return *this; - } - private: JPClass* m_Class{}; jvalue m_Value{}; diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index 3fb50102c..947c54bb7 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -60,7 +60,7 @@ jvalue JPMatch::convert() } JPMethodMatch::JPMethodMatch(JPJavaFrame &frame, JPPyObjectVector& args, bool callInstance) -: m_Arguments(args.size()) +: JPMethodCache(), m_Arguments(args.size()) { m_Type = JPMatch::_none; m_IsVarIndirect = false; @@ -311,10 +311,9 @@ void JPClassHints::excludeConversion(PyObject *type) void JPClassHints::getInfo(JPClass *cls, JPConversionInfo &info) { - for (auto iter = conversions.begin(); - iter != conversions.end(); ++iter) + for (auto & conversion : conversions) { - (*iter)->getInfo(cls, info); + conversion->getInfo(cls, info); } } diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 605e36c7f..de3375471 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -558,7 +558,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab for (jsize i = 0; i < sz; i += 4) { string filename, method; - auto jclassname = static_cast(frame.GetObjectArrayElement(obj, i)); + auto jclassname = (jstring) frame.GetObjectArrayElement(obj, i); auto jmethodname = (jstring) frame.GetObjectArrayElement(obj, i + 1); auto jfilename = (jstring) frame.GetObjectArrayElement(obj, i + 2); if (jfilename != nullptr) diff --git a/native/common/jp_javaframe.cpp b/native/common/jp_javaframe.cpp index 16fde4c2f..0c7b30ae0 100644 --- a/native/common/jp_javaframe.cpp +++ b/native/common/jp_javaframe.cpp @@ -1045,7 +1045,7 @@ jclass JPJavaFrame::getClass(jobject obj) class JPStringAccessor { JPJavaFrame& frame_; - jboolean isCopy; + jboolean isCopy{}; public: const char* cstr; diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index acf2adc69..b344fc1fa 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -72,10 +72,8 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch // Check each overload in order (the TypeManager orders them by priority // according to Java overload rules). - for (auto it = m_Overloads.begin(); it != m_Overloads.end(); ++it) + for (auto current : m_Overloads) { - JPMethod* current = *it; - JP_TRACE("Trying to match", current->toString()); current->matches(frame, match, callInstance, arg); @@ -120,7 +118,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch JP_TRACE("Adding to ambiguous list"); // Keep trace of ambiguous overloads for the error report. - ambiguous.push_back(*it); + ambiguous.push_back(current); } } @@ -145,9 +143,9 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << " between:" << std::endl; - for (auto it = ambiguous.begin(); it != ambiguous.end(); ++it) + for (auto pMethod : ambiguous) { - ss << "\t" << (*it)->toString() << std::endl; + ss << "\t" << pMethod->toString() << std::endl; } JP_RAISE(PyExc_TypeError, ss.str()); JP_TRACE(ss.str()); @@ -176,12 +174,9 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << ", options are:" << std::endl; - for (auto it = m_Overloads.begin(); - it != m_Overloads.end(); - ++it) + for (auto pMethod : m_Overloads) { - JPMethod* current = *it; - ss << "\t" << current->toString(); + ss << "\t" << pMethod->toString(); ss << std::endl; } JP_RAISE(PyExc_TypeError, ss.str()); diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index ea7b0cd4e..2394168d4 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -99,7 +99,7 @@ class Win32PlatformAdapter : public JPPlatformAdapter #else #include #endif // HPUX -#include +#include // The code in this modules is mostly excluded from coverage as it is only // possible to execute during a fatal error. @@ -107,7 +107,7 @@ class Win32PlatformAdapter : public JPPlatformAdapter class LinuxPlatformAdapter : public JPPlatformAdapter { private: - void* jvmLibrary; + void* jvmLibrary{}; public: @@ -161,7 +161,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter JP_TRACE("errno", errno); std::stringstream msg; msg << "Unable to load symbol [" << name << "], error = " << dlerror(); - JP_RAISE(PyExc_RuntimeError, msg.str().c_str()); + JP_RAISE(PyExc_RuntimeError, msg.str()); } // GCOVR_EXCL_STOP return res; diff --git a/native/python/include/pyjp.h b/native/python/include/pyjp.h index c9645843d..b82edbc02 100755 --- a/native/python/include/pyjp.h +++ b/native/python/include/pyjp.h @@ -201,7 +201,7 @@ bool PyJPValue_isSetJavaSlot(PyObject* self); JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowable prev); void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, jthrowable enclosing); -#define _ASSERT_JVM_RUNNING(context) assertJVMRunning((JPContext*)context, JP_STACKINFO()) +#define _ASSERT_JVM_RUNNING(context) assertJVMRunning((JPContext*)(context), JP_STACKINFO()) /** * Use this when getting the context where the context must be running. diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index 47d2ba683..d4d239fc7 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -354,10 +354,9 @@ PyObject* PyJPClass_mro(PyTypeObject *self) // Merge together all bases std::list out; - for (auto iter = bases.begin(); - iter != bases.end(); ++iter) + for (auto b : bases) { - PyObject *l = ((PyTypeObject*) * iter)->tp_bases; + PyObject *l = ((PyTypeObject*) b)->tp_bases; sz = PySequence_Size(l); for (Py_ssize_t i = 0; i < sz; ++i) { @@ -374,10 +373,9 @@ PyObject* PyJPClass_mro(PyTypeObject *self) { PyObject* front = bases.front(); bases.pop_front(); - for (auto iter = bases.begin(); - iter != bases.end(); ++iter) + for (auto b : bases) { - if (PySequence_Contains(((PyTypeObject*) * iter)->tp_bases, front)) + if (PySequence_Contains(((PyTypeObject*) b)->tp_bases, front)) { bases.push_back(front); front = nullptr; @@ -397,12 +395,11 @@ PyObject* PyJPClass_mro(PyTypeObject *self) } PyObject *obj = PyTuple_New(out.size()); - int j = 0; - for (auto iter = out.begin(); - iter != out.end(); ++iter) + Py_ssize_t j = 0; + for (auto obj2 : out) { - Py_INCREF(*iter); - PyTuple_SetItem(obj, j++, *iter); + Py_INCREF(obj2); + PyTuple_SetItem(obj, j++, obj); } return obj; } diff --git a/native/python/pyjp_method.cpp b/native/python/pyjp_method.cpp index 9edc7e835..9ee551f0f 100644 --- a/native/python/pyjp_method.cpp +++ b/native/python/pyjp_method.cpp @@ -201,11 +201,11 @@ static PyObject *PyJPMethod_getDoc(PyJPMethod *self, void *ctxt) JPPyObject ov = JPPyObject::call(PyTuple_New(overloads.size())); int i = 0; JPClass* methodClass = frame.findClassByName("java.lang.reflect.Method"); - for (auto iter = overloads.begin(); iter != overloads.end(); ++iter) + for (auto pMethod: overloads) { JP_TRACE("Set overload", i); jvalue v; - v.l = (*iter)->getJava(); + v.l = pMethod->getJava(); JPPyObject obj(methodClass->convertToPythonObject(frame, v, true)); PyTuple_SetItem(ov.get(), i++, obj.keep()); } @@ -253,11 +253,11 @@ PyObject *PyJPMethod_getAnnotations(PyJPMethod *self, void *ctxt) JPPyObject ov = JPPyObject::call(PyTuple_New(overloads.size())); int i = 0; JPClass* methodClass = frame.findClassByName("java.lang.reflect.Method"); - for (auto iter = overloads.begin(); iter != overloads.end(); ++iter) + for (auto pMethod : overloads) { JP_TRACE("Set overload", i); jvalue v; - v.l = (*iter)->getJava(); + v.l = pMethod->getJava(); JPPyObject obj(methodClass->convertToPythonObject(frame, v, true)); PyTuple_SetItem(ov.get(), i++, obj.keep()); } diff --git a/native/python/pyjp_package.cpp b/native/python/pyjp_package.cpp index 67cd17e3a..b722cd760 100644 --- a/native/python/pyjp_package.cpp +++ b/native/python/pyjp_package.cpp @@ -130,7 +130,7 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) } } - string attrName = JPPyString::asStringUTF8(attr).c_str(); + string attrName = JPPyString::asStringUTF8(attr); // Check for private attribute if (attrName.compare(0, 2, "__") == 0) return PyObject_GenericGetAttr((PyObject*) self, attr); diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index b8d4273b6..d4e7172e1 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -275,7 +275,7 @@ void PyJPValue_assignJavaSlot(JPJavaFrame &frame, PyObject* self, const JPValue& { std::stringstream ss; ss << "Missing Java slot on `" << Py_TYPE(self)->tp_name << "`"; - JP_RAISE(PyExc_SystemError, ss.str().c_str()); + JP_RAISE(PyExc_SystemError, ss.str()); } // GCOVR_EXCL_STOP From 41a62c7635476e40891842f2e178f0d6438f12d1 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 19:14:58 +0200 Subject: [PATCH 063/128] Revert "fix uninitialized members variables. use generators" This reverts commit e9958eda7c4ca897d0c6f882a681335e436c6e94. --- native/common/include/jp_buffertype.h | 2 +- native/common/include/jp_chartype.h | 2 +- native/common/include/jp_class.h | 4 ++-- native/common/include/jp_javaframe.h | 4 ++++ native/common/include/jp_match.h | 4 ++-- native/common/include/jp_method.h | 8 ++++---- native/common/include/jp_methoddispatch.h | 10 +++++----- native/common/include/jp_primitive_accessor.h | 2 +- native/common/include/jp_proxy.h | 2 +- native/common/include/jp_stringtype.h | 2 +- native/common/include/jp_typemanager.h | 2 +- native/common/include/jp_value.h | 11 ++++++++++- native/common/jp_classhints.cpp | 7 ++++--- native/common/jp_exception.cpp | 2 +- native/common/jp_javaframe.cpp | 2 +- native/common/jp_methoddispatch.cpp | 17 +++++++++++------ native/common/jp_platform.cpp | 6 +++--- native/python/include/pyjp.h | 2 +- native/python/pyjp_class.cpp | 19 +++++++++++-------- native/python/pyjp_method.cpp | 8 ++++---- native/python/pyjp_package.cpp | 2 +- native/python/pyjp_value.cpp | 2 +- 22 files changed, 71 insertions(+), 49 deletions(-) diff --git a/native/common/include/jp_buffertype.h b/native/common/include/jp_buffertype.h index dc6820cc2..e93393e5f 100644 --- a/native/common/include/jp_buffertype.h +++ b/native/common/include/jp_buffertype.h @@ -42,4 +42,4 @@ class JPBufferType : public JPClass int m_Size; } ; -#endif // _JPBUFFERTYPE_H_ \ No newline at end of file +#endif // _JPBUFFERCLASS_H_ \ No newline at end of file diff --git a/native/common/include/jp_chartype.h b/native/common/include/jp_chartype.h index 4dfc297ab..0b7f17e8a 100755 --- a/native/common/include/jp_chartype.h +++ b/native/common/include/jp_chartype.h @@ -90,4 +90,4 @@ class JPCharType : public JPPrimitiveType } ; -#endif // _JP_CHAR_TYPE_H_ +#endif // _JP-CHAR_TYPE_H_ diff --git a/native/common/include/jp_class.h b/native/common/include/jp_class.h index 30985b5ca..dfeaa3000 100644 --- a/native/common/include/jp_class.h +++ b/native/common/include/jp_class.h @@ -208,7 +208,7 @@ class JPClass : public JPResource JPClassRef m_Class; JPClass* m_SuperClass; JPClassList m_Interfaces; - JPMethodDispatch* m_Constructors{}; + JPMethodDispatch* m_Constructors; JPMethodDispatchList m_Methods; JPFieldList m_Fields; string m_CanonicalName; @@ -217,4 +217,4 @@ class JPClass : public JPResource JPPyObject m_Hints; } ; -#endif // _JP_CLASS_H_ \ No newline at end of file +#endif // _JPPOBJECTTYPE_H_ \ No newline at end of file diff --git a/native/common/include/jp_javaframe.h b/native/common/include/jp_javaframe.h index 830ee8e1b..a2ebbe25f 100644 --- a/native/common/include/jp_javaframe.h +++ b/native/common/include/jp_javaframe.h @@ -197,6 +197,10 @@ class JPJavaFrame // not implemented JPJavaFrame& operator= (const JPJavaFrame& frame) = delete; +private: + jint PushLocalFrame(jint); + jobject PopLocalFrame(jobject); + public: bool ExceptionCheck(); diff --git a/native/common/include/jp_match.h b/native/common/include/jp_match.h index 239defb68..ce9367ae4 100644 --- a/native/common/include/jp_match.h +++ b/native/common/include/jp_match.h @@ -64,8 +64,8 @@ class JPMatch class JPMethodCache { public: - long m_Hash{}; - JPMethod* m_Overload{}; + long m_Hash; + JPMethod* m_Overload; } ; class JPMethodMatch : public JPMethodCache diff --git a/native/common/include/jp_method.h b/native/common/include/jp_method.h index e24f1e99c..ab6789ee0 100644 --- a/native/common/include/jp_method.h +++ b/native/common/include/jp_method.h @@ -107,12 +107,12 @@ class JPMethod : public JPResource private: JPClass* m_Class{}; - string m_Name{}; - JPObjectRef m_Method{}; + string m_Name; + JPObjectRef m_Method; jmethodID m_MethodID{}; JPClass* m_ReturnType{}; - JPClassList m_ParameterTypes{}; - JPMethodList m_MoreSpecificOverloads{}; + JPClassList m_ParameterTypes; + JPMethodList m_MoreSpecificOverloads; jint m_Modifiers{}; } ; diff --git a/native/common/include/jp_methoddispatch.h b/native/common/include/jp_methoddispatch.h index 5c981c8d6..3fd6f98a5 100644 --- a/native/common/include/jp_methoddispatch.h +++ b/native/common/include/jp_methoddispatch.h @@ -82,11 +82,11 @@ class JPMethodDispatch : public JPResource */ bool findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch, JPPyObjectVector& vargs, bool searchInstance, bool raise); - JPClass* m_Class{}; - string m_Name{}; - JPMethodList m_Overloads{}; - jlong m_Modifiers{}; - JPMethodCache m_LastCache{}; + JPClass* m_Class; + string m_Name; + JPMethodList m_Overloads; + jlong m_Modifiers; + JPMethodCache m_LastCache; } ; #endif // _JPMETHODDISPATCH_H_ \ No newline at end of file diff --git a/native/common/include/jp_primitive_accessor.h b/native/common/include/jp_primitive_accessor.h index bb55ecd90..130179b7b 100644 --- a/native/common/include/jp_primitive_accessor.h +++ b/native/common/include/jp_primitive_accessor.h @@ -30,7 +30,7 @@ class JPPrimitiveArrayAccessor array_t _array; ptr_t _elem; releaseFnc _release; - jboolean _iscopy{}; + jboolean _iscopy; public: diff --git a/native/common/include/jp_proxy.h b/native/common/include/jp_proxy.h index 2235c766f..6739be12f 100644 --- a/native/common/include/jp_proxy.h +++ b/native/common/include/jp_proxy.h @@ -98,4 +98,4 @@ class JPProxyType : public JPClass jfieldID m_InstanceID; } ; -#endif // _JPPROXY_H_ \ No newline at end of file +#endif // JPPROXY_H \ No newline at end of file diff --git a/native/common/include/jp_stringtype.h b/native/common/include/jp_stringtype.h index 6029950e2..ce634d17e 100644 --- a/native/common/include/jp_stringtype.h +++ b/native/common/include/jp_stringtype.h @@ -35,4 +35,4 @@ class JPStringType : public JPClass JPValue newInstance(JPJavaFrame& frame, JPPyObjectVector& args) override; } ; -#endif /* JP_STRINGCLASS_H */ \ No newline at end of file +#endif /* JP_STRINGTYPE_H */ \ No newline at end of file diff --git a/native/common/include/jp_typemanager.h b/native/common/include/jp_typemanager.h index 2e2dbd780..abb34e2e6 100644 --- a/native/common/include/jp_typemanager.h +++ b/native/common/include/jp_typemanager.h @@ -54,4 +54,4 @@ class JPTypeManager jmethodID m_InterfaceParameterCount; } ; -#endif // _JPTYPE_MANAGER_H_ \ No newline at end of file +#endif // _JPCLASS_H_ \ No newline at end of file diff --git a/native/common/include/jp_value.h b/native/common/include/jp_value.h index 16f754c6d..4a3b994ee 100644 --- a/native/common/include/jp_value.h +++ b/native/common/include/jp_value.h @@ -62,7 +62,8 @@ class JPValue jobject getJavaObject() const; - // Cast operators to jvalue. Implicit casting is desired. + // Cast operators to jvalue. + // TODO: these could be explicit too, right? operator jvalue&() { return m_Value; @@ -72,6 +73,14 @@ class JPValue { return m_Value; } + + // TODO: never used. + JPValue& global(JPJavaFrame& frame) + { + m_Value.l = frame.NewGlobalRef(m_Value.l); + return *this; + } + private: JPClass* m_Class{}; jvalue m_Value{}; diff --git a/native/common/jp_classhints.cpp b/native/common/jp_classhints.cpp index 947c54bb7..3fb50102c 100644 --- a/native/common/jp_classhints.cpp +++ b/native/common/jp_classhints.cpp @@ -60,7 +60,7 @@ jvalue JPMatch::convert() } JPMethodMatch::JPMethodMatch(JPJavaFrame &frame, JPPyObjectVector& args, bool callInstance) -: JPMethodCache(), m_Arguments(args.size()) +: m_Arguments(args.size()) { m_Type = JPMatch::_none; m_IsVarIndirect = false; @@ -311,9 +311,10 @@ void JPClassHints::excludeConversion(PyObject *type) void JPClassHints::getInfo(JPClass *cls, JPConversionInfo &info) { - for (auto & conversion : conversions) + for (auto iter = conversions.begin(); + iter != conversions.end(); ++iter) { - conversion->getInfo(cls, info); + (*iter)->getInfo(cls, info); } } diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index de3375471..605e36c7f 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -558,7 +558,7 @@ JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowab for (jsize i = 0; i < sz; i += 4) { string filename, method; - auto jclassname = (jstring) frame.GetObjectArrayElement(obj, i); + auto jclassname = static_cast(frame.GetObjectArrayElement(obj, i)); auto jmethodname = (jstring) frame.GetObjectArrayElement(obj, i + 1); auto jfilename = (jstring) frame.GetObjectArrayElement(obj, i + 2); if (jfilename != nullptr) diff --git a/native/common/jp_javaframe.cpp b/native/common/jp_javaframe.cpp index 0c7b30ae0..16fde4c2f 100644 --- a/native/common/jp_javaframe.cpp +++ b/native/common/jp_javaframe.cpp @@ -1045,7 +1045,7 @@ jclass JPJavaFrame::getClass(jobject obj) class JPStringAccessor { JPJavaFrame& frame_; - jboolean isCopy{}; + jboolean isCopy; public: const char* cstr; diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index b344fc1fa..acf2adc69 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -72,8 +72,10 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch // Check each overload in order (the TypeManager orders them by priority // according to Java overload rules). - for (auto current : m_Overloads) + for (auto it = m_Overloads.begin(); it != m_Overloads.end(); ++it) { + JPMethod* current = *it; + JP_TRACE("Trying to match", current->toString()); current->matches(frame, match, callInstance, arg); @@ -118,7 +120,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch JP_TRACE("Adding to ambiguous list"); // Keep trace of ambiguous overloads for the error report. - ambiguous.push_back(current); + ambiguous.push_back(*it); } } @@ -143,9 +145,9 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << " between:" << std::endl; - for (auto pMethod : ambiguous) + for (auto it = ambiguous.begin(); it != ambiguous.end(); ++it) { - ss << "\t" << pMethod->toString() << std::endl; + ss << "\t" << (*it)->toString() << std::endl; } JP_RAISE(PyExc_TypeError, ss.str()); JP_TRACE(ss.str()); @@ -174,9 +176,12 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << ", options are:" << std::endl; - for (auto pMethod : m_Overloads) + for (auto it = m_Overloads.begin(); + it != m_Overloads.end(); + ++it) { - ss << "\t" << pMethod->toString(); + JPMethod* current = *it; + ss << "\t" << current->toString(); ss << std::endl; } JP_RAISE(PyExc_TypeError, ss.str()); diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index 2394168d4..ea7b0cd4e 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -99,7 +99,7 @@ class Win32PlatformAdapter : public JPPlatformAdapter #else #include #endif // HPUX -#include +#include // The code in this modules is mostly excluded from coverage as it is only // possible to execute during a fatal error. @@ -107,7 +107,7 @@ class Win32PlatformAdapter : public JPPlatformAdapter class LinuxPlatformAdapter : public JPPlatformAdapter { private: - void* jvmLibrary{}; + void* jvmLibrary; public: @@ -161,7 +161,7 @@ class LinuxPlatformAdapter : public JPPlatformAdapter JP_TRACE("errno", errno); std::stringstream msg; msg << "Unable to load symbol [" << name << "], error = " << dlerror(); - JP_RAISE(PyExc_RuntimeError, msg.str()); + JP_RAISE(PyExc_RuntimeError, msg.str().c_str()); } // GCOVR_EXCL_STOP return res; diff --git a/native/python/include/pyjp.h b/native/python/include/pyjp.h index b82edbc02..c9645843d 100755 --- a/native/python/include/pyjp.h +++ b/native/python/include/pyjp.h @@ -201,7 +201,7 @@ bool PyJPValue_isSetJavaSlot(PyObject* self); JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowable prev); void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, jthrowable enclosing); -#define _ASSERT_JVM_RUNNING(context) assertJVMRunning((JPContext*)(context), JP_STACKINFO()) +#define _ASSERT_JVM_RUNNING(context) assertJVMRunning((JPContext*)context, JP_STACKINFO()) /** * Use this when getting the context where the context must be running. diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index d4d239fc7..47d2ba683 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -354,9 +354,10 @@ PyObject* PyJPClass_mro(PyTypeObject *self) // Merge together all bases std::list out; - for (auto b : bases) + for (auto iter = bases.begin(); + iter != bases.end(); ++iter) { - PyObject *l = ((PyTypeObject*) b)->tp_bases; + PyObject *l = ((PyTypeObject*) * iter)->tp_bases; sz = PySequence_Size(l); for (Py_ssize_t i = 0; i < sz; ++i) { @@ -373,9 +374,10 @@ PyObject* PyJPClass_mro(PyTypeObject *self) { PyObject* front = bases.front(); bases.pop_front(); - for (auto b : bases) + for (auto iter = bases.begin(); + iter != bases.end(); ++iter) { - if (PySequence_Contains(((PyTypeObject*) b)->tp_bases, front)) + if (PySequence_Contains(((PyTypeObject*) * iter)->tp_bases, front)) { bases.push_back(front); front = nullptr; @@ -395,11 +397,12 @@ PyObject* PyJPClass_mro(PyTypeObject *self) } PyObject *obj = PyTuple_New(out.size()); - Py_ssize_t j = 0; - for (auto obj2 : out) + int j = 0; + for (auto iter = out.begin(); + iter != out.end(); ++iter) { - Py_INCREF(obj2); - PyTuple_SetItem(obj, j++, obj); + Py_INCREF(*iter); + PyTuple_SetItem(obj, j++, *iter); } return obj; } diff --git a/native/python/pyjp_method.cpp b/native/python/pyjp_method.cpp index 9ee551f0f..9edc7e835 100644 --- a/native/python/pyjp_method.cpp +++ b/native/python/pyjp_method.cpp @@ -201,11 +201,11 @@ static PyObject *PyJPMethod_getDoc(PyJPMethod *self, void *ctxt) JPPyObject ov = JPPyObject::call(PyTuple_New(overloads.size())); int i = 0; JPClass* methodClass = frame.findClassByName("java.lang.reflect.Method"); - for (auto pMethod: overloads) + for (auto iter = overloads.begin(); iter != overloads.end(); ++iter) { JP_TRACE("Set overload", i); jvalue v; - v.l = pMethod->getJava(); + v.l = (*iter)->getJava(); JPPyObject obj(methodClass->convertToPythonObject(frame, v, true)); PyTuple_SetItem(ov.get(), i++, obj.keep()); } @@ -253,11 +253,11 @@ PyObject *PyJPMethod_getAnnotations(PyJPMethod *self, void *ctxt) JPPyObject ov = JPPyObject::call(PyTuple_New(overloads.size())); int i = 0; JPClass* methodClass = frame.findClassByName("java.lang.reflect.Method"); - for (auto pMethod : overloads) + for (auto iter = overloads.begin(); iter != overloads.end(); ++iter) { JP_TRACE("Set overload", i); jvalue v; - v.l = pMethod->getJava(); + v.l = (*iter)->getJava(); JPPyObject obj(methodClass->convertToPythonObject(frame, v, true)); PyTuple_SetItem(ov.get(), i++, obj.keep()); } diff --git a/native/python/pyjp_package.cpp b/native/python/pyjp_package.cpp index b722cd760..67cd17e3a 100644 --- a/native/python/pyjp_package.cpp +++ b/native/python/pyjp_package.cpp @@ -130,7 +130,7 @@ static PyObject *PyJPPackage_getattro(PyObject *self, PyObject *attr) } } - string attrName = JPPyString::asStringUTF8(attr); + string attrName = JPPyString::asStringUTF8(attr).c_str(); // Check for private attribute if (attrName.compare(0, 2, "__") == 0) return PyObject_GenericGetAttr((PyObject*) self, attr); diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index d4e7172e1..b8d4273b6 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -275,7 +275,7 @@ void PyJPValue_assignJavaSlot(JPJavaFrame &frame, PyObject* self, const JPValue& { std::stringstream ss; ss << "Missing Java slot on `" << Py_TYPE(self)->tp_name << "`"; - JP_RAISE(PyExc_SystemError, ss.str()); + JP_RAISE(PyExc_SystemError, ss.str().c_str()); } // GCOVR_EXCL_STOP From 43854b913f412833400c87224302c6ffb9097301 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 19:29:54 +0200 Subject: [PATCH 064/128] replace auto i = 0; with decltype to be explicit --- native/python/jp_pythontypes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index 497666c1b..e532955cc 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -348,7 +348,7 @@ JPPyObjectVector::JPPyObjectVector(PyObject* sequence) m_Sequence = JPPyObject::use(sequence); auto n = PySequence_Size(m_Sequence.get()); m_Contents.resize(n); - for (auto i = 0; i < n; ++i) + for (decltype(n) i = 0; i < n; ++i) { m_Contents[i] = JPPyObject::call(PySequence_GetItem(m_Sequence.get(), i)); } @@ -362,7 +362,7 @@ JPPyObjectVector::JPPyObjectVector(PyObject* inst, PyObject* sequence) if (sequence != nullptr) n = PySequence_Size(m_Sequence.get()); m_Contents.resize(n + 1); - for (auto i = 0; i < n; ++i) + for (decltype(n) i = 0; i < n; ++i) { m_Contents[i + 1] = JPPyObject::call(PySequence_GetItem(m_Sequence.get(), i)); } From 3e9d4eb6319f9c4e960d2fb3d7c3f64b69d741a4 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 19:46:04 +0200 Subject: [PATCH 065/128] use c++11 for clang/gcc like compilers, c++14 on msvc (like for version 1.4.0 backwards) --- setupext/platform.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setupext/platform.py b/setupext/platform.py index 5ea17ea48..28ebd85ec 100644 --- a/setupext/platform.py +++ b/setupext/platform.py @@ -59,7 +59,7 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): platform_specific['extra_link_args'] = [] distutils.log.info("Configure platform to", platform) - cpp_std = "c++14" + cpp_std = "c++11" gcc_like_cflags = ['-g0', f'-std={cpp_std}', '-O2'] if platform == 'win32': @@ -67,7 +67,7 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): platform_specific['define_macros'] = [('WIN32', 1)] if sys.version > '3': platform_specific['extra_compile_args'] = [ - '/Zi', '/EHsc', f'/std:{cpp_std}'] + '/Zi', '/EHsc', f'/std:c++14'] else: platform_specific['extra_compile_args'] = ['/Zi', '/EHsc'] jni_md_platform = 'win32' From c0fa927fd10babc88b30192a31615d38262b427d Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 19:47:38 +0200 Subject: [PATCH 066/128] jpexception: reorder init --- native/common/jp_exception.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 605e36c7f..39a2d3700 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -65,8 +65,8 @@ JPypeException::JPypeException(int type, const string& msn, int errType, const } JPypeException::JPypeException(const JPypeException &ex) noexcept - : runtime_error(ex.what()), m_Context(ex.m_Context), m_Trace(ex.m_Trace), - m_Throwable(ex.m_Throwable), m_Type(ex.m_Type), m_Error(ex.m_Error) + : runtime_error(ex.what()), m_Context(ex.m_Context), m_Type(ex.m_Type), m_Error(ex.m_Error), + m_Trace(ex.m_Trace), m_Throwable(ex.m_Throwable) { } From 5d093bb3a8a8ae926ce7f3dbd981376b551ff9ea Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 1 Jun 2022 19:58:26 +0200 Subject: [PATCH 067/128] pass string by const-ref --- native/common/include/jp_methoddispatch.h | 4 ++-- native/common/jp_methoddispatch.cpp | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/native/common/include/jp_methoddispatch.h b/native/common/include/jp_methoddispatch.h index 3fd6f98a5..db524f62b 100644 --- a/native/common/include/jp_methoddispatch.h +++ b/native/common/include/jp_methoddispatch.h @@ -26,7 +26,7 @@ class JPMethodDispatch : public JPResource * Create a new method based on class and a name; */ JPMethodDispatch(JPClass *clazz, - string name, + const string& name, JPMethodList& overloads, jint modifiers); @@ -86,7 +86,7 @@ class JPMethodDispatch : public JPResource string m_Name; JPMethodList m_Overloads; jlong m_Modifiers; - JPMethodCache m_LastCache; + JPMethodCache m_LastCache{}; } ; #endif // _JPMETHODDISPATCH_H_ \ No newline at end of file diff --git a/native/common/jp_methoddispatch.cpp b/native/common/jp_methoddispatch.cpp index acf2adc69..6e4df40fb 100644 --- a/native/common/jp_methoddispatch.cpp +++ b/native/common/jp_methoddispatch.cpp @@ -20,10 +20,10 @@ #include "jp_methoddispatch.h" JPMethodDispatch::JPMethodDispatch(JPClass* clazz, - string name, + const string& name, JPMethodList& overloads, jint modifiers) -: m_Name(std::move(name)) +: m_Name(name) { m_Class = clazz; m_Overloads = overloads; @@ -72,10 +72,8 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch // Check each overload in order (the TypeManager orders them by priority // according to Java overload rules). - for (auto it = m_Overloads.begin(); it != m_Overloads.end(); ++it) + for (auto & current : m_Overloads) { - JPMethod* current = *it; - JP_TRACE("Trying to match", current->toString()); current->matches(frame, match, callInstance, arg); @@ -120,7 +118,7 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch JP_TRACE("Adding to ambiguous list"); // Keep trace of ambiguous overloads for the error report. - ambiguous.push_back(*it); + ambiguous.push_back(current); } } @@ -145,9 +143,9 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << " between:" << std::endl; - for (auto it = ambiguous.begin(); it != ambiguous.end(); ++it) + for (auto & ambiguous_mthd : ambiguous) { - ss << "\t" << (*it)->toString() << std::endl; + ss << "\t" << ambiguous_mthd->toString() << std::endl; } JP_RAISE(PyExc_TypeError, ss.str()); JP_TRACE(ss.str()); @@ -176,12 +174,9 @@ bool JPMethodDispatch::findOverload(JPJavaFrame& frame, JPMethodMatch &bestMatch ss << Py_TYPE(arg[i])->tp_name; } ss << ")" << ", options are:" << std::endl; - for (auto it = m_Overloads.begin(); - it != m_Overloads.end(); - ++it) + for (auto current : m_Overloads) { - JPMethod* current = *it; - ss << "\t" << current->toString(); + ss << "\t" << current->toString(); ss << std::endl; } JP_RAISE(PyExc_TypeError, ss.str()); From 24b23a4c51f72e07b0e2351cdea498f1c519b5aa Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 2 Jun 2022 14:58:21 +0200 Subject: [PATCH 068/128] jp_array use nullptr, removed unused include --- native/common/jp_array.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/native/common/jp_array.cpp b/native/common/jp_array.cpp index f265710a0..165cb1f15 100644 --- a/native/common/jp_array.cpp +++ b/native/common/jp_array.cpp @@ -16,7 +16,6 @@ #include "jpype.h" #include "pyjp.h" #include "jp_array.h" -#include "jp_buffer.h" #include "jp_arrayclass.h" #include "jp_primitive_accessor.h" @@ -34,7 +33,7 @@ JPArray::JPArray(const JPValue &value) JP_TRACE(m_Class->toString()); // We will use this during range checks, so cache it - if (m_Object.get() == NULL) + if (m_Object.get() == nullptr) m_Length = 0; // GCOVR_EXCL_LINE else m_Length = frame.GetArrayLength(m_Object.get()); From e8a5e86fe40dcb35c56a37c14c34d8ca90ebdd39 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Fri, 3 Jun 2022 10:49:44 +0200 Subject: [PATCH 069/128] fix array size --- native/common/include/jp_array.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/common/include/jp_array.h b/native/common/include/jp_array.h index f7bbfbe08..2e654f7e4 100644 --- a/native/common/include/jp_array.h +++ b/native/common/include/jp_array.h @@ -34,7 +34,7 @@ class JPArrayView void *m_Memory{}; Py_buffer m_Buffer{}; int m_RefCount; - Py_ssize_t m_Shape[50]{}; + Py_ssize_t m_Shape[5]{}; Py_ssize_t m_Strides[5]{}; jboolean m_IsCopy{}; jboolean m_Owned{}; From 5bc12ce056abe3193afba6ad0736e0ee878f42b5 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 9 Nov 2022 22:59:40 +0100 Subject: [PATCH 070/128] merged jp_exception (broken) --- native/common/jp_exception.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index c6b8c13bb..c636b0d25 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -480,18 +480,18 @@ void JPypeException::toJava(JPContext *context) JP_TRACE_OUT; // GCOVR_EXCL_LINE } -PyObject *tb_create( - PyObject *last_traceback, +PyTracebackObject *tb_create( + PyTracebackObject *last_traceback, PyObject *dict, const char* filename, const char* funcname, int linenum) { // Create a code for this frame. (ref count is 1) - JPPyObject* code = JPPyObject::accept((PyObject*)PyCode_NewEmpty(filename, funcname, linenum)); + JPPyObject code = JPPyObject::accept((PyObject*)PyCode_NewEmpty(filename, funcname, linenum)); // If we don't get the code object there is no point - if (code == nullptr) + if (code.get() == nullptr) return nullptr; // Create a frame for the traceback. @@ -516,7 +516,7 @@ PyObject *tb_create( // We could fail in process if (traceback.get() == nullptr) { - Py_DECREF(frame); + Py_DECREF(frame.get()); return nullptr; } From 6bf4871d46f5670a528f582858bff4fe3ea19521 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 9 Nov 2022 23:05:06 +0100 Subject: [PATCH 071/128] fix --- native/common/jp_exception.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index c636b0d25..088f4721b 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -480,8 +480,8 @@ void JPypeException::toJava(JPContext *context) JP_TRACE_OUT; // GCOVR_EXCL_LINE } -PyTracebackObject *tb_create( - PyTracebackObject *last_traceback, +PyObject *tb_create( + PyObject *last_traceback, PyObject *dict, const char* filename, const char* funcname, @@ -516,7 +516,6 @@ PyTracebackObject *tb_create( // We could fail in process if (traceback.get() == nullptr) { - Py_DECREF(frame.get()); return nullptr; } @@ -539,7 +538,7 @@ PyObject* PyTrace_FromJPStackTrace(JPStackTrace& trace) JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowable prev) { - PyTracebackObject *last_traceback = nullptr; + PyObject *last_traceback = NULL; JPContext *context = frame.getContext(); jvalue args[2]; args[0].l = th; From 053dbd5be1e522df20d26c0ea0757de58129fa96 Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Mon, 3 Apr 2023 13:20:27 -0700 Subject: [PATCH 072/128] Change to use .equals --- doc/CHANGELOG.rst | 3 +++ native/python/pyjp_object.cpp | 4 ++-- test/jpypetest/test_comparable.py | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 123970f5c..79be55859 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -6,6 +6,9 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o Latest Changes: - **1.4.2_dev0 - 2022-10-26** + - Switched ``__eq__`` and ``__ne__`` operator to use ``.equals`` for comparable objects to + avoid exception when comparing object of different types. + - Fixed crash when calling subscript on JArray. - Fixed direct byte buffers not reporting nbytes correctly when cast to memoryview. diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index 494175f12..735cdf1e1 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -164,14 +164,14 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) Py_RETURN_TRUE; if (null0 || null1) Py_RETURN_FALSE; - return PyBool_FromLong(frame.compareTo(obj0, obj1) == 0); + return PyBool_FromLong(frame.equals(obj0, obj1)); case Py_NE: if (null0 && null1) Py_RETURN_FALSE; if (null0 || null1) Py_RETURN_TRUE; - return PyBool_FromLong(frame.compareTo(obj0, obj1) != 0); + return PyBool_FromLong(!frame.equals(obj0, obj1)); case Py_LT: if (null0 || null1) break; diff --git a/test/jpypetest/test_comparable.py b/test/jpypetest/test_comparable.py index 273bdc2de..c6eeb197f 100644 --- a/test/jpypetest/test_comparable.py +++ b/test/jpypetest/test_comparable.py @@ -79,3 +79,9 @@ def testComparableNull(self): print(i3 > i3) with self.assertRaises(ValueError): print(i3 >= i3) + + def testComparableObj(self): + O1 = jpype.JClass("java.time.temporal.ChronoUnit").SECONDS + O2 = jpype.JClass("java.util.concurrent.TimeUnit").SECONDS + self.assertTrue(O1 != O2) + self.assertFalse(O1 == O2) From a358ca3e14b0820679a68ad0b0457c9f4074d2d2 Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Mon, 3 Apr 2023 14:01:54 -0700 Subject: [PATCH 073/128] Fixed segfault found in coverage test. --- native/python/pyjp_object.cpp | 2 +- test/jpypetest/test_comparable.py | 21 +++++++++++++++++-- test/jpypetest/test_objectwrapper.py | 31 ++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index 735cdf1e1..c47429733 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -154,7 +154,7 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) return out; } obj1 = match.convert().l; - } else if (!null1 && javaSlot1 != NULL) + } else if (!null1 && javaSlot1 != NULL && !javaSlot1->getClass()->isPrimitive()) obj1 = javaSlot1->getValue().l; switch (op) diff --git a/test/jpypetest/test_comparable.py b/test/jpypetest/test_comparable.py index c6eeb197f..4b91107da 100644 --- a/test/jpypetest/test_comparable.py +++ b/test/jpypetest/test_comparable.py @@ -81,7 +81,24 @@ def testComparableNull(self): print(i3 >= i3) def testComparableObj(self): - O1 = jpype.JClass("java.time.temporal.ChronoUnit").SECONDS - O2 = jpype.JClass("java.util.concurrent.TimeUnit").SECONDS + C1 = jpype.JClass("java.time.temporal.ChronoUnit") + C2 = jpype.JClass("java.util.concurrent.TimeUnit") + O1 = C1.SECONDS + O2 = C2.SECONDS + N1 = jpype.JObject(None, C1) + N2 = jpype.JObject(None, C2) + V = jpype.JInt(1) + # Test dissimilar objects self.assertTrue(O1 != O2) self.assertFalse(O1 == O2) + # test Nulls + self.assertTrue(N1 == N2) + self.assertFalse(N1 != N2) + self.assertTrue(N1 == None) + self.assertFalse(N1 != None) + # test primitives + self.assertFalse(O1 == V) + self.assertFalse(V == O1) + # test null to primitives + self.assertFalse(N1 == V) + self.assertFalse(V == N1) diff --git a/test/jpypetest/test_objectwrapper.py b/test/jpypetest/test_objectwrapper.py index 80f18c7eb..f6a64cf85 100644 --- a/test/jpypetest/test_objectwrapper.py +++ b/test/jpypetest/test_objectwrapper.py @@ -113,6 +113,37 @@ class Fred(object): with self.assertRaises(TypeError): jpype.JObject(Fred()) + def testObjectEq(self): + C1 = jpype.JClass("java.lang.StringBuffer") + C2 = jpype.JClass("java.lang.Exception") + O1 = C1() + O2 = C2() + N1 = jpype.JObject(None, C1) + N2 = jpype.JObject(None, C2) + V = jpype.JInt(1) + # Test dissimilar objects + self.assertTrue(O1 != O2) + self.assertFalse(O1 == O2) + self.assertTrue(O2 != O1) + self.assertFalse(O2 == O1) + # test Nulls + self.assertTrue(N1 == N2) + self.assertFalse(N1 != N2) + self.assertTrue(N1 == None) + self.assertFalse(N1 != None) + self.assertTrue(None == N1) + self.assertFalse(None != N1) + # test primitives + self.assertFalse(O1 == V) + self.assertFalse(V == O1) + self.assertFalse(O2 == V) + self.assertFalse(V == O2) + # test null to primitives + self.assertFalse(N1 == V) + self.assertFalse(V == N1) + self.assertFalse(N2 == V) + self.assertFalse(V == N2) + # def testMakeSureWeCanLoadAllClasses(self): # def get_system_jars(): From 77f74c03d3e8c0109c345fb2e88eb8d96f21e3be Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Mon, 3 Apr 2023 14:53:57 -0700 Subject: [PATCH 074/128] Edge cases --- native/common/jp_javaframe.cpp | 8 +- native/python/pyjp_object.cpp | 13 +++- test/harness/java8/jpype/method/Caller.java | 81 +++++++++++++++++++++ test/jpypetest/test_comparable.py | 17 +++++ 4 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 test/harness/java8/jpype/method/Caller.java diff --git a/native/common/jp_javaframe.cpp b/native/common/jp_javaframe.cpp index d05b0480a..42d5739e9 100644 --- a/native/common/jp_javaframe.cpp +++ b/native/common/jp_javaframe.cpp @@ -1194,7 +1194,13 @@ jint JPJavaFrame::compareTo(jobject obj, jobject obj2) { jvalue v; v.l = obj2; - return CallIntMethodA(obj, m_Context->m_CompareToID, &v); + jint ret = m_Env->CallIntMethodA(obj, m_Context->m_CompareToID, &v); + if (m_Env->ExceptionOccurred()) + { + m_Env->ExceptionClear(); + JP_RAISE(PyExc_TypeError, "Unable to compare") + } + return ret; } jthrowable JPJavaFrame::getCause(jthrowable th) diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index c47429733..0e47f4fb6 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -55,8 +55,6 @@ static PyObject *PyJPObject_compare(PyObject *self, PyObject *other, int op) if (op == Py_NE) { PyObject *ret = PyJPObject_compare(self, other, Py_EQ); - if (ret == NULL) - return NULL; int rc = (ret == Py_False); Py_DECREF(ret); return PyBool_FromLong(rc); @@ -120,7 +118,7 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) bool null1 = false; // First slot is Null - if (self == Py_None || javaSlot0 == NULL || + if (javaSlot0 == NULL || (!javaSlot0->getClass()->isPrimitive() && javaSlot0->getValue().l == NULL)) null0 = true; if (other == Py_None || (javaSlot1 != NULL && @@ -153,6 +151,14 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) Py_INCREF(out); return out; } + if (match.type < JPMatch::Type::_implicit) + { + if (op == Py_EQ || op == Py_NE) + return PyBool_FromLong(op == Py_NE); + PyObject *out = Py_NotImplemented; + Py_INCREF(out); + return out; + } obj1 = match.convert().l; } else if (!null1 && javaSlot1 != NULL && !javaSlot1->getClass()->isPrimitive()) obj1 = javaSlot1->getValue().l; @@ -165,7 +171,6 @@ static PyObject *PyJPComparable_compare(PyObject *self, PyObject *other, int op) if (null0 || null1) Py_RETURN_FALSE; return PyBool_FromLong(frame.equals(obj0, obj1)); - case Py_NE: if (null0 && null1) Py_RETURN_FALSE; diff --git a/test/harness/java8/jpype/method/Caller.java b/test/harness/java8/jpype/method/Caller.java new file mode 100644 index 000000000..d6c986395 --- /dev/null +++ b/test/harness/java8/jpype/method/Caller.java @@ -0,0 +1,81 @@ +/* **************************************************************************** + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + See NOTICE file for details. +**************************************************************************** */ +package jpype.method; + +/** + * Caller sensitive methods need special handling. + * + * So we need to test each possible path (different return types and arguments). + * + * We will pretend our methods are also CallerSensitive. + */ +public class Caller +{ + + public static Object callObjectStatic() + { + return new Caller(); + } + + public Object callObjectMember() + { + return new Caller(); + } + + public static void callVoidStatic() + { + } + + public void callVoidMember() + { + } + + public static int callIntegerStatic() + { + return 123; + } + + public int callIntegerMember() + { + return 123; + } + + public Object callArgs(Object a, Object b) + { + return b; + } + + public int callArg1(int a) + { + return a; + } + + public Object callVarArgs(Object a, Object... b) + { + return b; + } + + public Class callStackWalker1() + { + return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass(); + } + + public Class callStackWalker2() + { + return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass(); + } + +}; diff --git a/test/jpypetest/test_comparable.py b/test/jpypetest/test_comparable.py index 4b91107da..ce54b223f 100644 --- a/test/jpypetest/test_comparable.py +++ b/test/jpypetest/test_comparable.py @@ -102,3 +102,20 @@ def testComparableObj(self): # test null to primitives self.assertFalse(N1 == V) self.assertFalse(V == N1) + + self.assertFalse(1 == O1) + self.assertFalse("M" == O1) + self.assertFalse(O1 == 1) + self.assertFalse(O1 == "M") + + self.assertTrue(1 != O1) + self.assertTrue("M" != O1) + self.assertTrue(O1 != 1) + self.assertTrue(O1 != "M") + + with self.assertRaises(TypeError): + self.assertTrue(O1 > 1) + with self.assertRaises(TypeError): + self.assertTrue(1 > O1) + with self.assertRaises(TypeError): + self.assertTrue(O1 > O2) From d3c171727b5d38308243b84aa9a4f3f534fb684b Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Mon, 3 Apr 2023 14:56:50 -0700 Subject: [PATCH 075/128] Remove out of date file --- test/harness/java8/jpype/method/Caller.java | 81 --------------------- 1 file changed, 81 deletions(-) delete mode 100644 test/harness/java8/jpype/method/Caller.java diff --git a/test/harness/java8/jpype/method/Caller.java b/test/harness/java8/jpype/method/Caller.java deleted file mode 100644 index d6c986395..000000000 --- a/test/harness/java8/jpype/method/Caller.java +++ /dev/null @@ -1,81 +0,0 @@ -/* **************************************************************************** - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - See NOTICE file for details. -**************************************************************************** */ -package jpype.method; - -/** - * Caller sensitive methods need special handling. - * - * So we need to test each possible path (different return types and arguments). - * - * We will pretend our methods are also CallerSensitive. - */ -public class Caller -{ - - public static Object callObjectStatic() - { - return new Caller(); - } - - public Object callObjectMember() - { - return new Caller(); - } - - public static void callVoidStatic() - { - } - - public void callVoidMember() - { - } - - public static int callIntegerStatic() - { - return 123; - } - - public int callIntegerMember() - { - return 123; - } - - public Object callArgs(Object a, Object b) - { - return b; - } - - public int callArg1(int a) - { - return a; - } - - public Object callVarArgs(Object a, Object... b) - { - return b; - } - - public Class callStackWalker1() - { - return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass(); - } - - public Class callStackWalker2() - { - return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass(); - } - -}; From 6fc67a49341e826da250d1a609f6dbf05789438a Mon Sep 17 00:00:00 2001 From: "Karl E. Nelson" Date: Tue, 4 Apr 2023 09:08:00 -0700 Subject: [PATCH 076/128] Changed documentation --- doc/CHANGELOG.rst | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 79be55859..7ca44c7e5 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -6,13 +6,21 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o Latest Changes: - **1.4.2_dev0 - 2022-10-26** - - Switched ``__eq__`` and ``__ne__`` operator to use ``.equals`` for comparable objects to - avoid exception when comparing object of different types. + - Switched ``__eq__`` and ``__ne__`` operator to use ``equals`` rather than + ``compareTo`` for comparable objects to avoid exception when comparing + object of different types. + + - Fixed segmentation fault when comparing Java Comparable to primitives. + + - Java exceptions that occur in inequality comparisons now map to Python + TypeError. - Fixed crash when calling subscript on JArray. - - Fixed direct byte buffers not reporting nbytes correctly when cast to memoryview. - - Expand the defintion for Functional interface to include classes without + - Fixed direct byte buffers not reporting nbytes correctly when cast to + memoryview. + + - Expand the defintion for Functional interface to include classes without FunctionInterface annotation. - **1.4.1 - 2022-10-26** From df7d2e40a49126aecc2e7be6e7d2373d813e796e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 12:41:38 +0200 Subject: [PATCH 077/128] use proper workaround --- native/python/pyjp_value.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index e8d4e84cc..93dba9505 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -43,8 +43,28 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) JP_PY_TRY("PyJPValue_alloc"); // Modification from Python to add size elements const size_t size = _PyObject_VAR_SIZE(type, nitems + 1) + sizeof (JPValue); - PyObject *obj = (PyType_IS_GC(type)) ? _PyObject_GC_Malloc(size) - : (PyObject *) PyObject_MALLOC(size); + PyObject *obj = NULL; + if (PyType_IS_GC(type)) + { + // Horrible kludge because python lacks an API for allocating a GC type with extra memory + // The private method _PyObject_GC_Alloc is no longer visible, so we are forced to allocate + // a different type with the extra memory and then hot swap the type to the real one. + PyTypeObject type2; + type2.tp_basicsize = size; + type2.tp_itemsize = 0; + type2.tp_name = NULL; + type2.tp_flags = type->tp_flags; + type2.tp_traverse = type->tp_traverse; + + // Allocate the fake type + obj = PyObject_GC_New(PyObject, &type2); + + // Note the object will be inited twice which should not leak. (fingers crossed) + } + else + { + obj = (PyObject*) PyObject_MALLOC(size); + } if (obj == NULL) return PyErr_NoMemory(); // GCOVR_EXCL_LINE memset(obj, 0, size); From 5647a3a616c535ec5a6b023de80101c2ece4e514 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 12:46:40 +0200 Subject: [PATCH 078/128] use proper workaround PyJPValue_alloc from current master applied clang-tidy --- native/python/pyjp_value.cpp | 71 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index 93dba9505..510c2e12c 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -15,7 +15,6 @@ *****************************************************************************/ #include "jpype.h" #include "pyjp.h" -#include "jp_boxedtype.h" #include "jp_stringtype.h" #ifdef __cplusplus @@ -38,12 +37,12 @@ extern "C" * the alloc and finalize slot to recognize which objects have this * extra slot appended. */ -PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) +PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems) { JP_PY_TRY("PyJPValue_alloc"); // Modification from Python to add size elements const size_t size = _PyObject_VAR_SIZE(type, nitems + 1) + sizeof (JPValue); - PyObject *obj = NULL; + PyObject *obj = nullptr; if (PyType_IS_GC(type)) { // Horrible kludge because python lacks an API for allocating a GC type with extra memory @@ -52,7 +51,7 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) PyTypeObject type2; type2.tp_basicsize = size; type2.tp_itemsize = 0; - type2.tp_name = NULL; + type2.tp_name = nullptr; type2.tp_flags = type->tp_flags; type2.tp_traverse = type->tp_traverse; @@ -65,7 +64,7 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) { obj = (PyObject*) PyObject_MALLOC(size); } - if (obj == NULL) + if (obj == nullptr) return PyErr_NoMemory(); // GCOVR_EXCL_LINE memset(obj, 0, size); @@ -87,12 +86,12 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) } JP_TRACE("alloc", type->tp_name, obj); return obj; - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } bool PyJPValue_hasJavaSlot(PyTypeObject* type) { - if (type == NULL + if (type == nullptr || type->tp_alloc != (allocfunc) PyJPValue_alloc || type->tp_finalize != (destructor) PyJPValue_finalize) return false; // GCOVR_EXCL_LINE @@ -102,7 +101,7 @@ bool PyJPValue_hasJavaSlot(PyTypeObject* type) Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self) { PyTypeObject *type = Py_TYPE(self); - if (type == NULL + if (type == nullptr || type->tp_alloc != (allocfunc) PyJPValue_alloc || type->tp_finalize != (destructor) PyJPValue_finalize) return 0; @@ -121,7 +120,7 @@ Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self) /** * Get the Java value if attached. * - * The Java class is guaranteed not to be null on success. + * The Java class is guaranteed not to be nullptr on success. * * @param obj * @return the Java value or 0 if not found. @@ -130,10 +129,10 @@ JPValue* PyJPValue_getJavaSlot(PyObject* self) { Py_ssize_t offset = PyJPValue_getJavaSlotOffset(self); if (offset == 0) - return NULL; - JPValue* value = (JPValue*) (((char*) self) + offset); - if (value->getClass() == NULL) - return NULL; + return nullptr; + auto value = (JPValue*) (((char*) self) + offset); + if (value->getClass() == nullptr) + return nullptr; return value; } @@ -142,7 +141,7 @@ void PyJPValue_free(void* obj) JP_PY_TRY("PyJPValue_free", obj); // Normally finalize is not run on simple classes. PyTypeObject *type = Py_TYPE(obj); - if (type->tp_finalize != NULL) + if (type->tp_finalize != nullptr) type->tp_finalize((PyObject*) obj); if (type->tp_flags & Py_TPFLAGS_HAVE_GC) PyObject_GC_Del(obj); @@ -156,16 +155,16 @@ void PyJPValue_finalize(void* obj) JP_PY_TRY("PyJPValue_finalize", obj); JP_TRACE("type", Py_TYPE(obj)->tp_name); JPValue* value = PyJPValue_getJavaSlot((PyObject*) obj); - if (value == NULL) + if (value == nullptr) return; JPContext *context = JPContext_global; - if (context == NULL || !context->isRunning()) + if (context == nullptr || !context->isRunning()) return; JPJavaFrame frame = JPJavaFrame::outer(context); JPClass* cls = value->getClass(); // This one can't check for initialized because we may need to delete a stale // resource after shutdown. - if (cls != NULL && context->isRunning() && !cls->isPrimitive()) + if (cls != nullptr && context->isRunning() && !cls->isPrimitive()) { JP_TRACE("Value", cls->getCanonicalName(), &(value->getValue())); JP_TRACE("Dereference object"); @@ -182,26 +181,26 @@ PyObject* PyJPValue_str(PyObject* self) JPContext *context = PyJPModule_getContext(); JPJavaFrame frame = JPJavaFrame::outer(context); JPValue* value = PyJPValue_getJavaSlot(self); - if (value == NULL) + if (value == nullptr) { PyErr_SetString(PyExc_TypeError, "Not a Java value"); - return NULL; + return nullptr; } JPClass* cls = value->getClass(); if (cls->isPrimitive()) { PyErr_SetString(PyExc_TypeError, "toString requires a Java object"); - return NULL; + return nullptr; } - if (value->getValue().l == NULL) + if (value->getValue().l == nullptr) return JPPyString::fromStringUTF8("null").keep(); if (cls == context->_java_lang_String) { PyObject *cache; - JPPyObject dict = JPPyObject::accept(PyObject_GenericGetDict(self, NULL)); + JPPyObject dict = JPPyObject::accept(PyObject_GenericGetDict(self, nullptr)); if (!dict.isNull()) { cache = PyDict_GetItemString(dict.get(), "_jstr"); @@ -210,7 +209,7 @@ PyObject* PyJPValue_str(PyObject* self) Py_INCREF(cache); return cache; } - jstring jstr = (jstring) value->getValue().l; + auto jstr = (jstring) value->getValue().l; string str; str = frame.toStringUTF8(jstr); cache = JPPyString::fromStringUTF8(str).keep(); @@ -221,7 +220,7 @@ PyObject* PyJPValue_str(PyObject* self) // In general toString is not immutable, so we won't cache it. return JPPyString::fromStringUTF8(frame.toString(value->getValue().l)).keep(); - JP_PY_CATCH(NULL); + JP_PY_CATCH(nullptr); } PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name) @@ -232,13 +231,13 @@ PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name) PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", Py_TYPE(name)->tp_name); - return NULL; + return nullptr; } // Private members are accessed directly PyObject* pyattr = PyBaseObject_Type.tp_getattro(obj, name); - if (pyattr == NULL) - return NULL; + if (pyattr == nullptr) + return nullptr; JPPyObject attr = JPPyObject::accept(pyattr); // Private members go regardless @@ -254,8 +253,8 @@ PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name) return attr.keep(); PyErr_Format(PyExc_AttributeError, "Field '%U' is static", name); - return NULL; - JP_PY_CATCH(NULL); + return nullptr; + JP_PY_CATCH(nullptr); } int PyJPValue_setattro(PyObject *self, PyObject *name, PyObject *value) @@ -272,7 +271,7 @@ int PyJPValue_setattro(PyObject *self, PyObject *name, PyObject *value) return -1; } descrsetfunc desc = Py_TYPE(f.get())->tp_descr_set; - if (desc != NULL) + if (desc != nullptr) return desc(f.get(), self, value); // Not a descriptor @@ -296,20 +295,20 @@ void PyJPValue_assignJavaSlot(JPJavaFrame &frame, PyObject* self, const JPValue& { std::stringstream ss; ss << "Missing Java slot on `" << Py_TYPE(self)->tp_name << "`"; - JP_RAISE(PyExc_SystemError, ss.str().c_str()); + JP_RAISE(PyExc_SystemError, ss.str()); } // GCOVR_EXCL_STOP - JPValue* slot = (JPValue*) (((char*) self) + offset); + auto* slot = (JPValue*) (((char*) self) + offset); // GCOVR_EXCL_START // This is a sanity check that should never trigger in normal operations. - if (slot->getClass() != NULL) + if (slot->getClass() != nullptr) { JP_RAISE(PyExc_SystemError, "Slot assigned twice"); } // GCOVR_EXCL_STOP JPClass* cls = value.getClass(); - if (cls != NULL && !cls->isPrimitive()) + if (cls != nullptr && !cls->isPrimitive()) { jvalue q; q.l = frame.NewGlobalRef(value.getValue().l); @@ -323,6 +322,6 @@ bool PyJPValue_isSetJavaSlot(PyObject* self) Py_ssize_t offset = PyJPValue_getJavaSlotOffset(self); if (offset == 0) return false; // GCOVR_EXCL_LINE - JPValue* slot = (JPValue*) (((char*) self) + offset); - return slot->getClass() != NULL; + auto* slot = (JPValue*) (((char*) self) + offset); + return slot->getClass() != nullptr; } From 4aeed19d6d0e4af51e9fed78cdbe7fa8d9e6e9d6 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Wed, 3 May 2023 10:27:09 +0200 Subject: [PATCH 079/128] Systematically run mypy --- .github/workflows/mypy.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/mypy.yml diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml new file mode 100644 index 000000000..98de3b062 --- /dev/null +++ b/.github/workflows/mypy.yml @@ -0,0 +1,20 @@ +name: Mypy + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + name: mypy + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.11 + uses: actions/setup-python@v1 + with: + python-version: 3.11 + - name: Install Dependencies + run: | + pip install mypy + - name: mypy + run: | + mypy ./jpype/ ./test/jpypetest/ From 348f5ec94f5de65070ca0ecdd1c38b8f1c27f547 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Wed, 3 May 2023 11:57:14 +0200 Subject: [PATCH 080/128] Add pyproject config --- .github/workflows/mypy.yml | 2 +- pyproject.toml | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 98de3b062..f63b3b6c4 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -14,7 +14,7 @@ jobs: python-version: 3.11 - name: Install Dependencies run: | - pip install mypy + pip install mypy numpy types-pyinstaller pytest packaging - name: mypy run: | mypy ./jpype/ ./test/jpypetest/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..ca01bd7eb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[[tool.mypy.overrides]] +module = [ + "_jpype", + "commonx", + "brokenx", + "java.*", + "jpypex.common", + "jedi", +] +ignore_missing_imports = true + From b24a242fabf8a675adbc303f88368aa206b14850 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Wed, 3 May 2023 11:55:37 +0200 Subject: [PATCH 081/128] Get mypy passing for the whole of the codebase --- jpype/__init__.py | 17 ++++---- jpype/_core.pyi | 2 - jpype/_gui.py | 4 +- jpype/_jarray.py | 2 +- jpype/_jclass.py | 2 +- jpype/_jcollection.py | 2 +- jpype/_jcollection.pyi | 62 ++++------------------------- jpype/_jexception.py | 2 +- jpype/_jmethod.py | 5 ++- jpype/_jobject.py | 2 +- jpype/_jstring.py | 22 +++++----- jpype/_jstring.pyi | 13 ------ jpype/_jthread.py | 10 ++--- jpype/_jthread.pyi | 12 ------ jpype/_jvmfinder.py | 4 +- jpype/dbapi2.py | 8 ++-- jpype/types.py | 16 ++++---- test/jpypetest/common.py | 2 +- test/jpypetest/importstar.py | 8 ++-- test/jpypetest/subrun.py | 2 +- test/jpypetest/test_boxed.py | 4 +- test/jpypetest/test_coverage.py | 28 +++++++------ test/jpypetest/test_exc.py | 5 +-- test/jpypetest/test_fault.py | 16 ++++---- test/jpypetest/test_imports.py | 10 ++--- test/jpypetest/test_javacoverage.py | 2 +- test/jpypetest/test_jchar.py | 2 +- test/jpypetest/test_jclass.py | 4 +- test/jpypetest/test_jint.py | 2 +- test/jpypetest/test_jlong.py | 6 +-- test/jpypetest/test_jmethod.py | 8 +--- test/jpypetest/test_jobject.py | 2 +- test/jpypetest/test_jstring.py | 4 ++ test/jpypetest/test_jvmfinder.py | 4 +- test/jpypetest/test_leak.py | 8 ++-- test/jpypetest/test_map.py | 2 +- test/jpypetest/test_sql_generic.py | 7 ---- test/jpypetest/test_sql_h2.py | 8 ++-- test/jpypetest/test_sql_hsqldb.py | 7 +++- test/jpypetest/test_sql_sqlite.py | 18 ++++----- 40 files changed, 137 insertions(+), 207 deletions(-) delete mode 100644 jpype/_core.pyi delete mode 100644 jpype/_jstring.pyi delete mode 100644 jpype/_jthread.pyi diff --git a/jpype/__init__.py b/jpype/__init__.py index 9922a6635..aa7071ae9 100644 --- a/jpype/__init__.py +++ b/jpype/__init__.py @@ -20,6 +20,7 @@ from ._jpackage import * from ._jproxy import * from ._core import * +from . import _core from ._gui import * from ._classpath import * from ._jclass import * @@ -41,15 +42,15 @@ from . import _jthread # lgtm [py/import-own-module] __all__ = ['java', 'javax'] -__all__.extend(_jinit.__all__) +__all__.extend(_jinit.__all__) # type: ignore[name-defined] __all__.extend(_core.__all__) -__all__.extend(_classpath.__all__) -__all__.extend(types.__all__) -__all__.extend(_jproxy.__all__) -__all__.extend(_jpackage.__all__) -__all__.extend(_jclass.__all__) -__all__.extend(_jcustomizer.__all__) -__all__.extend(_gui.__all__) +__all__.extend(_classpath.__all__) # type: ignore[name-defined] +__all__.extend(types.__all__) # type: ignore[name-defined] +__all__.extend(_jproxy.__all__) # type: ignore[name-defined] +__all__.extend(_jpackage.__all__) # type: ignore[name-defined] +__all__.extend(_jclass.__all__) # type: ignore[name-defined] +__all__.extend(_jcustomizer.__all__) # type: ignore[name-defined] +__all__.extend(_gui.__all__) # type: ignore[name-defined] __version__ = "1.5.0_dev0" __version_info__ = __version__.split('.') diff --git a/jpype/_core.pyi b/jpype/_core.pyi deleted file mode 100644 index f4eb32c79..000000000 --- a/jpype/_core.pyi +++ /dev/null @@ -1,2 +0,0 @@ -class _JRuntime: - pass diff --git a/jpype/_gui.py b/jpype/_gui.py index ca5f96b39..245c1b5bd 100644 --- a/jpype/_gui.py +++ b/jpype/_gui.py @@ -28,7 +28,7 @@ def setupGuiEnvironment(cb): if _sys.platform == 'darwin': - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore m = {'run': cb} proxy = _jproxy.JProxy('java.lang.Runnable', m) cbthread = _jclass.JClass("java.lang.Thread")(proxy) @@ -40,5 +40,5 @@ def setupGuiEnvironment(cb): def shutdownGuiEnvironment(): if _sys.platform == 'darwin': - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore AppHelper.stopEventLoop() diff --git a/jpype/_jarray.py b/jpype/_jarray.py index 082aba204..34ce2bd86 100644 --- a/jpype/_jarray.py +++ b/jpype/_jarray.py @@ -22,7 +22,7 @@ __all__ = ['JArray'] -class JArray(_jpype._JObject, internal=True): +class JArray(_jpype._JObject, internal=True): # type: ignore[call-arg] """ Creates a Java array class for a Java type of a given dimension. This serves as a base type and factory for all Java array classes. diff --git a/jpype/_jclass.py b/jpype/_jclass.py index 9c33622d0..faa905f24 100644 --- a/jpype/_jclass.py +++ b/jpype/_jclass.py @@ -99,7 +99,7 @@ def __new__(cls, jc, loader=None, initialize=True): return _jpype._getClass(jc) -class JInterface(_jpype._JObject, internal=True): +class JInterface(_jpype._JObject, internal=True): # type: ignore[call-arg] """A meta class for all Java Interfaces. ``JInterface`` is serves as the base class for any Java class that is diff --git a/jpype/_jcollection.py b/jpype/_jcollection.py index 7f7270c3f..a31a6e53c 100644 --- a/jpype/_jcollection.py +++ b/jpype/_jcollection.py @@ -41,7 +41,7 @@ class _JCollection(object): """ Customizer for ``java.util.Collection`` This customizer adds the Python functions ``len()`` and ``del`` to - Java Collions to allow for Python syntax. + Java Collisions to allow for Python syntax. """ def __len__(self): diff --git a/jpype/_jcollection.pyi b/jpype/_jcollection.pyi index 7e811332f..07417b58b 100644 --- a/jpype/_jcollection.pyi +++ b/jpype/_jcollection.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, Collection, List, Set, Mapping, Tuple, TypeVar, Iterator, Generator, Union, overload +from typing import Any, Iterable, Collection, List, Set, Mapping, Tuple, TypeVar, Iterator, Generator, Union, overload, Dict E = TypeVar('E') K = TypeVar('K') @@ -14,80 +14,34 @@ class _JCollection(Collection[E]): def __delitem__(self, i: E) -> None: ... - def __contains__(self, i: E) -> bool: ... + def __contains__(self, i: Any) -> bool: ... + def __iter__(self) -> Iterator[E]: ... -class _JList(List[E]): - @overload - def __getitem__(self, ndx: int) -> E: ... - - @overload - def __getitem__(self, ndx: slice) -> E: ... - - def __setitem__(self, ndx: int, v: E) -> None: ... - - def __delitem__(self, ndx: int) -> E: ... - - def __reversed__(self) -> Generator[E, None, None]: ... - - def index(self, obj: E) -> int: ... - - def count(self, obj: E) -> int: ... - - def insert(self, idx: int, obj: E) -> '_JList'[E]: ... - - def append(self, obj: E) -> '_JList'[E]: ... - - def reverse(self) -> None: ... - - def extend(self, lst: Iterable[E]) -> None: ... - - def pop(self, idx: int = ...) -> E: ... - - def __iadd__(self, obj: List[E]) -> '_JList'[E]: ... - - def __add__(self, obj: List[E]) -> '_JList'[E]: ... - def remove(self, obj: E) -> None: ... +class _JList(List[E]): + pass -class _JMap(Mapping[K, V]): +class _JMap(Dict[K, V]): def __len__(self) -> int: ... def __iter__(self) -> Iterator[K]: ... - def __delitem__(self, i: K) -> V: ... - def __getitem__(self, ndx: K) -> V: ... - def __setitem__(self, ndx: K, v: V) -> None: ... - - def items(self) -> Set['_JMapEntry'[K, V]]: ... - - def keys(self) -> Set[K]: ... - - def __contains__(self, item: V) -> bool: ... - class _JSet(Set[E]): - def __delitem__(self, i: E): ... + pass class _JMapEntry(Tuple[K, V]): - def __len__(self) -> int: ... - - def __getitem__(self, x: int) -> Union[K, V]: ... + pass class _JIterator(Iterator[E]): def __next__(self) -> E: ... - def __iter__(self) -> Iterator[E]: ... - class _JEnumeration(Iterator[E]): def __next__(self) -> E: ... - - def __iter__(self) -> Iterator[E]: ... - - def next(self) -> E: ... diff --git a/jpype/_jexception.py b/jpype/_jexception.py index 7f179446e..f6280c8b7 100644 --- a/jpype/_jexception.py +++ b/jpype/_jexception.py @@ -22,7 +22,7 @@ @_jcustomizer.JImplementationFor("java.lang.Throwable", base=True) -class JException(_jpype._JException, internal=True): +class JException(_jpype._JException, internal=True): # type: ignore[call-arg] """ Base class for all ``java.lang.Throwable`` objects. Use ``issubclass(cls, JException)`` to test if a class is derived diff --git a/jpype/_jmethod.py b/jpype/_jmethod.py index 35a71622b..366a2287f 100644 --- a/jpype/_jmethod.py +++ b/jpype/_jmethod.py @@ -15,11 +15,12 @@ # See NOTICE file for details. # # ***************************************************************************** -import _jpype -__all__ = [] + import _jpype from . import _jclass +__all__ = [] # type: ignore[var-annotated] + def _jmethodGetDoc(method, cls, overloads): """Generator for _JMethod.__doc__ property diff --git a/jpype/_jobject.py b/jpype/_jobject.py index 6917561de..e199300b4 100644 --- a/jpype/_jobject.py +++ b/jpype/_jobject.py @@ -20,7 +20,7 @@ __all__ = ['JObject'] -class JObject(_jpype._JObject, internal=True): +class JObject(_jpype._JObject, internal=True): # type: ignore[call-arg] """ Base class for all object instances. It can be used to test if an object is a Java object instance with diff --git a/jpype/_jstring.py b/jpype/_jstring.py index 0f8d8cfa2..2785576a3 100644 --- a/jpype/_jstring.py +++ b/jpype/_jstring.py @@ -15,13 +15,15 @@ # See NOTICE file for details. # # ***************************************************************************** +import typing + import _jpype from . import _jcustomizer __all__ = ['JString'] -class JString(_jpype._JObject, internal=True): +class JString(_jpype._JObject, internal=True): # type: ignore[call-arg] """ Base class for ``java.lang.String`` objects When called as a function, this class will produce a ``java.lang.String`` @@ -37,14 +39,14 @@ def __new__(cls, *args, **kwargs): @_jcustomizer.JImplementationFor("java.lang.String") -class _JStringProto(object): - def __add__(self, other): - return self.concat(other) +class _JStringProto: + def __add__(self, other: str) -> str: + return self.concat(other) # type: ignore[attr-defined] - def __len__(self): - return self.length() + def __len__(self) -> int: + return self.length() # type: ignore[attr-defined] - def __getitem__(self, i): + def __getitem__(self, i: typing.Union[slice, int]): if isinstance(i, slice): return str(self)[i] @@ -54,10 +56,10 @@ def __getitem__(self, i): raise IndexError("Array index is negative") if i >= len(self): raise IndexError("Array index exceeds length") - return self.charAt(i) + return self.charAt(i) # type: ignore[attr-defined] - def __contains__(self, other): - return self.contains(other) + def __contains__(self, other: str) -> bool: + return self.contains(other) # type: ignore[attr-defined] def __hash__(self): if self == None: # lgtm [py/test-equals-none] diff --git a/jpype/_jstring.pyi b/jpype/_jstring.pyi deleted file mode 100644 index bd2d5160a..000000000 --- a/jpype/_jstring.pyi +++ /dev/null @@ -1,13 +0,0 @@ -from typing import Any, Text - - -class _JStringProto(Text): - def __add__(self, other: Text) -> Text: ... - - def __len__(self) -> int: ... - - def __getitem__(self, i: int) -> Text: ... - - def __contains__(self, other: Text) -> bool: ... - - def __hash__(self) -> Any: ... diff --git a/jpype/_jthread.py b/jpype/_jthread.py index 4c329ffec..a52089589 100644 --- a/jpype/_jthread.py +++ b/jpype/_jthread.py @@ -20,7 +20,7 @@ @_jcustomizer.JImplementationFor('java.lang.Thread') -class _JThread(object): +class _JThread: """ Customizer for ``java.land.Thread`` This adds addition JPype methods to java.lang.Thread to support @@ -28,7 +28,7 @@ class _JThread(object): """ @staticmethod - def isAttached(): + def isAttached() -> bool: """ Checks if a thread is attached to the JVM. Python automatically attaches as daemon threads when a Java method is @@ -44,7 +44,7 @@ def isAttached(): return _jpype.isThreadAttachedToJVM() @staticmethod - def attach(): + def attach() -> None: """ Attaches the current thread to the JVM as a user thread. User threads that are attached to the JVM will prevent the JVM from @@ -57,7 +57,7 @@ def attach(): return _jpype.attachThreadToJVM() @staticmethod - def attachAsDaemon(): + def attachAsDaemon() -> None: """ Attaches the current thread to the JVM as a daemon. Daemon threads act as background tasks and do not prevent the JVM from @@ -71,7 +71,7 @@ def attachAsDaemon(): return _jpype.attachThreadAsDaemon() @staticmethod - def detach(): + def detach() -> None: """ Detaches a thread from the JVM. This function detaches the thread and frees the associated resource in diff --git a/jpype/_jthread.pyi b/jpype/_jthread.pyi deleted file mode 100644 index fbb828d3f..000000000 --- a/jpype/_jthread.pyi +++ /dev/null @@ -1,12 +0,0 @@ -class _JThread: - @staticmethod - def isAttached() -> bool: ... - - @staticmethod - def attach() -> None: ... - - @staticmethod - def attachAsDaemon() -> None: ... - - @staticmethod - def detach() -> None: ... diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index 64b656c2b..299d76f32 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -26,7 +26,7 @@ try: import winreg except ImportError: - winreg = None + winreg = None # type: ignore[assignment] class JVMNotFoundException(ValueError): @@ -45,7 +45,7 @@ class JVMNotSupportedException(ValueError): This exception is raised after a search found a valid Java home directory was found, but the JVM shared library found is not supported. Typically - this occures when the JVM does not match the architecture of Python + this occurs when the JVM does not match the architecture of Python 32 vs 64 bit, or the JVM is older than the version used to compile JPype. """ diff --git a/jpype/dbapi2.py b/jpype/dbapi2.py index 0541fe02d..e391e3af8 100644 --- a/jpype/dbapi2.py +++ b/jpype/dbapi2.py @@ -232,11 +232,11 @@ def _asPython(x): LONGNVARCHAR: STRING, DOUBLE: DOUBLE, OTHER: OBJECT } -_default_setters = {} +_default_setters = {} # type: ignore[var-annotated] -_default_converters = {} +_default_converters = {} # type: ignore[var-annotated] -_default_adapters = {} +_default_adapters = {} # type: ignore[var-annotated] # Setters take (connection, meta, col, type) -> JDBCTYPE @@ -251,7 +251,7 @@ def SETTERS_BY_META(cx, meta, col, ptype): return _default_map[_registry[meta.getParameterType(col + 1)]] -SETTERS_BY_META._cachable = True +SETTERS_BY_META._cachable = True # type: ignore[attr-defined] def SETTERS_BY_TYPE(cx, meta, col, ptype): diff --git a/jpype/types.py b/jpype/types.py index 0d42f773f..bcebce92d 100644 --- a/jpype/types.py +++ b/jpype/types.py @@ -56,35 +56,35 @@ ] -class JBoolean(_jpype._JBoolean, internal=True): +class JBoolean(_jpype._JBoolean, internal=True): # type: ignore[call-arg] pass -class JByte(_jpype._JNumberLong, internal=True): +class JByte(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JChar(_jpype._JChar, internal=True): +class JChar(_jpype._JChar, internal=True): # type: ignore[call-arg] pass -class JInt(_jpype._JNumberLong, internal=True): +class JInt(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JShort(_jpype._JNumberLong, internal=True): +class JShort(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JLong(_jpype._JNumberLong, internal=True): +class JLong(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JFloat(_jpype._JNumberFloat, internal=True): +class JFloat(_jpype._JNumberFloat, internal=True): # type: ignore[call-arg] pass -class JDouble(_jpype._JNumberFloat, internal=True): +class JDouble(_jpype._JNumberFloat, internal=True): # type: ignore[call-arg] pass diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 1177eaeb2..757c81d9c 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -22,7 +22,7 @@ import logging from os import path import sys -import unittest +import unittest # Extensively used as common.unittest. CLASSPATH = None fast = False diff --git a/test/jpypetest/importstar.py b/test/jpypetest/importstar.py index 5c257c02e..1b112bcfc 100644 --- a/test/jpypetest/importstar.py +++ b/test/jpypetest/importstar.py @@ -8,11 +8,11 @@ import jpype # import with star the first time -from org.jpype import * +from org.jpype import * # type: ignore try: # This should not be found - late2.Test() + late2.Test() # type: ignore[name-defined] raise ImportError("late was already found") except NameError: pass @@ -22,7 +22,7 @@ # Second import if True: - from org.jpype import * + from org.jpype import * # type: ignore[name-defined] # This time it should work -t = late2.Test() +t = late2.Test() # type: ignore[name-defined] diff --git a/test/jpypetest/subrun.py b/test/jpypetest/subrun.py index a07508d3d..f0a24f787 100644 --- a/test/jpypetest/subrun.py +++ b/test/jpypetest/subrun.py @@ -24,7 +24,7 @@ import unittest import common -_modules = {} +_modules = {} # type: ignore[var-annotated] def _import(filename): diff --git a/test/jpypetest/test_boxed.py b/test/jpypetest/test_boxed.py index ba1035eb7..a55b7aae8 100644 --- a/test/jpypetest/test_boxed.py +++ b/test/jpypetest/test_boxed.py @@ -289,12 +289,12 @@ def testLongBoxOps(self): self.assertIsInstance(u, jpype.java.lang.Long) self.compareTest(u, 81) - def testIntBoxOps(self): + def testIntBoxOps_2(self): u = JObject(81, JFloat) self.assertIsInstance(u, jpype.java.lang.Float) self.compareTest(u, 81) - def testLongBoxOps(self): + def testLongBoxOps_2(self): u = JObject(81, JDouble) self.assertIsInstance(u, jpype.java.lang.Double) self.compareTest(u, 81) diff --git a/test/jpypetest/test_coverage.py b/test/jpypetest/test_coverage.py index 78f6322ce..f981caa95 100644 --- a/test/jpypetest/test_coverage.py +++ b/test/jpypetest/test_coverage.py @@ -76,9 +76,8 @@ def testJArrayLength(self): self.assertEqual(ja.length, len(ja)) def testJArrayGetItemSlice(self): - with self.assertRaises(NotImplementedError): - ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja[0:2:-1] + ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) + assert list(ja[0:2:-1]) == [1, 2, 3, 4][0:2:-1] def testJArraySetItemSlice(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4, 5, 6]) @@ -87,22 +86,27 @@ def testJArraySetItemSlice(self): # FIXME ja[0:-1:2] = [-1] works but should not # FIXME ja[0:-1:2] = 1 gives wierd error - def testJArrayGetItemSlice(self): + def testJArrayGetItemSlice_2(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja[1:] + assert list(ja[1:]) == [2, 3, 4] - def testJArraySetItemSlice(self): + def testJArraySetItemSlice_2(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) ja[1:] = [3, 4, 5] self.assertEqual(list(ja[:]), [1, 3, 4, 5]) def testJArrayEQ(self): - ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja == [1, 2] + ja1 = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) + ja2 = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) + ja1 == ja2 + # FIXME: This test is failing, but shouldn't be. + # assert ja1 == ja2 + assert (ja1 == [1, 2]) is False def testJArrayNE(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja != [1, 2] + assert ja != [1, 2] + assert (ja != ja) is False def testJArrayIter(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) @@ -257,14 +261,14 @@ def foo(): pass # this is executed in a thread which may start later magic = mock.MagicMock() with mock.patch("sys.platform", "other"), mock.patch.dict('sys.modules', {'PyObjCTools': magic}): - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore self.assertEqual(sys.platform, "other") jpype.setupGuiEnvironment(foo) self.assertFalse(magic.AppHelper.runConsoleEventLoop.called) jpype.shutdownGuiEnvironment() self.assertFalse(magic.AppHelper.stopEventLoop.called) with mock.patch("sys.platform", "darwin"), mock.patch.dict('sys.modules', {'PyObjCTools': magic}): - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore self.assertEqual(sys.platform, "darwin") jpype.setupGuiEnvironment(foo) self.assertTrue(magic.AppHelper.runConsoleEventLoop.called) @@ -281,4 +285,4 @@ def testImportNotStarted(self): with mock.patch('_jpype.isStarted') as func: func.return_value = False with self.assertRaisesRegex(ImportError, "jvm"): - import mil.spec + import mil.spec # type: ignore diff --git a/test/jpypetest/test_exc.py b/test/jpypetest/test_exc.py index f1c68a645..02700d690 100644 --- a/test/jpypetest/test_exc.py +++ b/test/jpypetest/test_exc.py @@ -16,9 +16,8 @@ # # ***************************************************************************** import jpype -from jpype import JException, java, JProxy, JClass +from jpype import java, JProxy from jpype.types import * -import traceback import common @@ -133,7 +132,7 @@ def testExcCtor(self): def testExcCauseChained1(self): import jpype.imports try: - from org.jpype.fail import BadInitializer + from org.jpype.fail import BadInitializer # type: ignore except Exception as ex: ex1 = ex self.assertIsInstance(ex1, ImportError) diff --git a/test/jpypetest/test_fault.py b/test/jpypetest/test_fault.py index 5713fd2ae..441aa5466 100644 --- a/test/jpypetest/test_fault.py +++ b/test/jpypetest/test_fault.py @@ -15,6 +15,8 @@ # See NOTICE file for details. # # ***************************************************************************** +import unittest + import _jpype import jpype from jpype import * @@ -66,7 +68,7 @@ def testJPArray_new(self): # FIXME investigate why the release is not happening # may indicate a leak. Disabling for now - @common.unittest.SkipTest + @common.unittest.SkipTest # type: ignore def testJPArray_releaseBuffer(self): _jpype.fault("PyJPArray_releaseBuffer") @@ -363,7 +365,7 @@ def testJPProxy_new(self): # FIXME this needs special treatment. It should call __str__() # if toString is not defined. Disable for now. - @common.unittest.SkipTest + @common.unittest.SkipTest # type: ignore[arg-type] def testJPProxy_str(self): # Java has a hidden requirement that toString be available @JImplements("java.util.function.DoubleUnaryOperator") @@ -408,7 +410,7 @@ def accept(self, d): jo.accept(None) @common.requireInstrumentation - def testJPProxy_void(self): + def testJPProxy_void_2(self): @JImplements("java.util.function.Consumer") class f(object): @JOverride @@ -550,7 +552,7 @@ def testJPObject(self): # indicates a problem in the exception handling path. # AssertionError: "fault" does not match "NULL context in JPRef() # Disabling for now. - @common.unittest.SkipTest + @common.unittest.SkipTest # type: ignore[arg-type] @common.requireInstrumentation def testJPTypeManagerFindClass(self): ja = JArray(JInt, 2)([[1, 1], [1, 1]]) @@ -930,15 +932,15 @@ def testJPJavaFrameMonitor(self): jo = JClass("java.lang.Object")() _jpype.fault("JPJavaFrame::MonitorEnter") with self.assertRaisesRegex(SystemError, "fault"): - with syncronized(jo): + with jpype.synchronized(jo): pass _jpype.fault("JPJavaFrame::MonitorExit") with self.assertRaisesRegex(SystemError, "fault"): - with syncronized(jo): + with jpype.synchronized(jo): pass @common.requireInstrumentation - def testJPJavaFrameMonitor(self): + def testJPJavaFrameMonitor_2(self): _jpype.fault("JPJavaFrame::FromReflectedMethod") with self.assertRaisesRegex(SystemError, "fault"): raise SystemError("fault") diff --git a/test/jpypetest/test_imports.py b/test/jpypetest/test_imports.py index a6d5974f3..e0828be71 100644 --- a/test/jpypetest/test_imports.py +++ b/test/jpypetest/test_imports.py @@ -88,18 +88,18 @@ def testImportFail(self): def testAlias1(self): jpype.imports.registerDomain("jpypex", alias="jpype") - from jpypex.common import Fixture + from jpypex.common import Fixture # type: ignore self.assertEqual(Fixture, jpype.JClass("jpype.common.Fixture")) def testAlias2(self): jpype.imports.registerDomain("commonx", alias="jpype.common") - from commonx import Fixture as Fixture2 + from commonx import Fixture as Fixture2 # type: ignore self.assertEqual(Fixture2, jpype.JClass("jpype.common.Fixture")) def testAliasBad(self): jpype.imports.registerDomain("brokenx", alias="jpype.broken") with self.assertRaises(ImportError): - from brokenx import Fixture as Fixture2 + from brokenx import Fixture as Fixture2 # type: ignore def testIsPackage(self): import java.lang @@ -109,7 +109,7 @@ def testIsPackage(self): self.assertTrue(issubclass(type(java.lang), jpype.JPackage)) def testMRJar(self): - import org.jpype.mrjar as mrjar + import org.jpype.mrjar as mrjar # type: ignore u = dir(mrjar) self.assertTrue("A" in u) self.assertTrue("B" in u) @@ -120,7 +120,7 @@ def testAddClassPath(self): import org.jpype as ojp self.assertFalse("late" in dir(ojp)) with self.assertRaises(ImportError): - import org.jpype.late as late + import org.jpype.late as late # type: ignore jpype.addClassPath(pathlib.Path("test/jar/late/late.jar").absolute()) import org.jpype.late as late diff --git a/test/jpypetest/test_javacoverage.py b/test/jpypetest/test_javacoverage.py index 477830b0b..fbffb9c90 100644 --- a/test/jpypetest/test_javacoverage.py +++ b/test/jpypetest/test_javacoverage.py @@ -54,7 +54,7 @@ def testModifiers(self): cls = JClass('org.jpype.manager.ModifierCode') self.assertEqual(cls.get(cls.decode(1171)), 1171) - def testTypeFactory(self): + def testTypeFactory_2(self): TypeFactory = JClass("org.jpype.manager.TypeFactory") TypeManager = JClass("org.jpype.manager.TypeManager") @JImplements(TypeFactory) diff --git a/test/jpypetest/test_jchar.py b/test/jpypetest/test_jchar.py index 410dbc7a5..32dc9bdfa 100644 --- a/test/jpypetest/test_jchar.py +++ b/test/jpypetest/test_jchar.py @@ -474,7 +474,7 @@ def testPass(self): self.assertEqual(fixture.callObject(self.nc), None) -class JCharTestCase(common.JPypeTestCase): +class JCharTestCase_2(common.JPypeTestCase): def testOps(self): self.assertEqual(JChar("x") + "test", "xtest") diff --git a/test/jpypetest/test_jclass.py b/test/jpypetest/test_jclass.py index 107a19b4e..9907062cd 100644 --- a/test/jpypetest/test_jclass.py +++ b/test/jpypetest/test_jclass.py @@ -85,12 +85,12 @@ def testSetAttrProperty(self): with self.assertRaises(AttributeError): cls.args = 1 - def testGetAttrStaticField(self): + def testGetAttrStaticField_2(self): cls = JClass('jpype.common.Fixture') cls.static_object_field = "fred" self.assertEqual(cls.static_object_field, "fred") - def testSetAttrStaticField(self): + def testSetAttrStaticField_3(self): cls = JClass('jpype.common.Fixture') cls.static_object_field = "fred" diff --git a/test/jpypetest/test_jint.py b/test/jpypetest/test_jint.py index 5f09d208e..b9511b84a 100644 --- a/test/jpypetest/test_jint.py +++ b/test/jpypetest/test_jint.py @@ -153,7 +153,7 @@ def testFromJIntWiden(self): self.assertEqual(JInt(JInt(12345678)), 12345678) self.assertEqual(JInt(JLong(12345678)), 12345678) - def testFromJIntWiden(self): + def testFromJIntWiden_2(self): self.assertEqual(JInt(JDouble(12345678)), 12345678) def testFromNone(self): diff --git a/test/jpypetest/test_jlong.py b/test/jpypetest/test_jlong.py index cd4483bcc..5f4178f08 100644 --- a/test/jpypetest/test_jlong.py +++ b/test/jpypetest/test_jlong.py @@ -147,13 +147,13 @@ def f(): with self.assertRaisesRegex(SystemError, "fault"): ja[1:3] = [0, 0] - def testFromJLongWiden(self): + def testFromJLongWiden_2(self): self.assertEqual(JLong(JByte(123)), 123) self.assertEqual(JLong(JShort(12345)), 12345) self.assertEqual(JLong(JInt(12345678)), 12345678) self.assertEqual(JLong(JLong(12345678)), 12345678) - def testFromJLongWiden(self): + def testFromJLongWiden_3(self): self.assertEqual(JLong(JDouble(12345678)), 12345678) def testFromNone(self): @@ -278,7 +278,7 @@ def testCheckJLong(self): self.checkType(JLong(-2**31 + 1)) self.checkType(JLong(2**31 - 1)) - def testCheckJLong(self): + def testCheckJLong_2(self): self.checkType(JLong(-2**63 + 1)) self.checkType(JLong(2**63 - 1)) diff --git a/test/jpypetest/test_jmethod.py b/test/jpypetest/test_jmethod.py index 8fe663568..8216a67ab 100644 --- a/test/jpypetest/test_jmethod.py +++ b/test/jpypetest/test_jmethod.py @@ -145,10 +145,6 @@ def testMethodClone(self): a = copy_func(self.obj.substring) self.assertEqual(a(1), "oo") - def testMethodDump(self): - # This is replaced by doc, should be removed - self.assertIsInstance(jpype.JString("foo").substring.dump(), str) - def testMethodDump(self): # This is replaced by doc, should be removed (or do something useful) self.assertIsInstance(jpype.JString( @@ -180,7 +176,7 @@ def testJMethod_str(self): str(fixture.callInt) @common.requireInstrumentation - def testJMethod_str(self): + def testJMethod_str_2(self): Fixture = JClass("jpype.common.Fixture") fixture = Fixture() _jpype.fault("PyJPMethod_get") @@ -228,7 +224,7 @@ def testJMethod_docFault(self): fixture.callInt.__doc__ = None @common.requireInstrumentation - def testJMethod_docFault(self): + def testJMethod_docFault_2(self): fixture = JClass("jpype.common.Fixture")() _jpype.fault("PyJPMethod_getCodeAttr") with self.assertRaisesRegex(SystemError, "fault"): diff --git a/test/jpypetest/test_jobject.py b/test/jpypetest/test_jobject.py index 7ed920bae..b6fcd87c2 100644 --- a/test/jpypetest/test_jobject.py +++ b/test/jpypetest/test_jobject.py @@ -302,7 +302,7 @@ def testGetSetBad(self): with self.assertRaises(TypeError): setattr(js, object(), 1) - def testGetSetBad(self): + def testGetSetBad_2(self): jo = JClass("java.lang.Object")() self.assertTrue(jo != JInt(0)) self.assertFalse(jo == JInt(0)) diff --git a/test/jpypetest/test_jstring.py b/test/jpypetest/test_jstring.py index 4c6b46190..8328990be 100644 --- a/test/jpypetest/test_jstring.py +++ b/test/jpypetest/test_jstring.py @@ -169,6 +169,10 @@ def testNullHash(self): jsn = JObject(None, JString) self.assertEqual(hash(jsn), hash(None)) + def testEmptyHash(self): + jsn = JObject('', JString) + self.assertEqual(hash(jsn), hash('')) + def testSlice(self): s = 'abcdefghijklmnop' s2 = JString(s) diff --git a/test/jpypetest/test_jvmfinder.py b/test/jpypetest/test_jvmfinder.py index 7994612d2..4e16a7b2e 100644 --- a/test/jpypetest/test_jvmfinder.py +++ b/test/jpypetest/test_jvmfinder.py @@ -111,7 +111,7 @@ def testDarwinBinary(self, mock_mac_ver): # it is included only for coverage purposes. Revise this to be a more meaningful test # next time it breaks. # FIXME this test does passes locally but not in the CI. Disabling for now. - @common.unittest.skip + @common.unittest.skip # type: ignore def testPlatform(self): with mock.patch('jpype._jvmfinder.sys') as mocksys, mock.patch('jpype._jvmfinder.WindowsJVMFinder') as finder: mocksys.platform = 'win32' @@ -147,7 +147,7 @@ def f(s): # FIXME this test is faking files using the mock system. Replace it with stub # files so that we have a more accurate test rather than just testing the implementation. # FIXME this fails in the CI but works locally. Disabling this for now. - @common.unittest.skip + @common.unittest.skip # type: ignore def testCheckArch(self): import struct with mock.patch("builtins.open", mock.mock_open(read_data="data")) as mock_file, \ diff --git a/test/jpypetest/test_leak.py b/test/jpypetest/test_leak.py index f2ed4854f..76ec31524 100644 --- a/test/jpypetest/test_leak.py +++ b/test/jpypetest/test_leak.py @@ -19,7 +19,6 @@ import jpype import gc import sys -import os from os import path import subrun import unittest @@ -27,12 +26,11 @@ try: import resource except ImportError: - resource = None - pass + resource = None # type: ignore[assignment] def haveResource(): - return bool(resource) + return resource is not None def hasRefCount(): @@ -43,7 +41,7 @@ def hasRefCount(): return False -class LeakChecker(): +class LeakChecker: def __init__(self): self.runtime = jpype.java.lang.Runtime.getRuntime() diff --git a/test/jpypetest/test_map.py b/test/jpypetest/test_map.py index bdadcb8d7..b0365d895 100644 --- a/test/jpypetest/test_map.py +++ b/test/jpypetest/test_map.py @@ -59,7 +59,7 @@ def testSetItem(self): obj['b'] = 5 self.assertEqual(obj['b'], 5) - def testSetItem(self): + def testSetItem_2(self): cls = jpype.JClass('java.util.TreeMap') obj = cls() obj.put("a", 1) diff --git a/test/jpypetest/test_sql_generic.py b/test/jpypetest/test_sql_generic.py index 14d637f84..d2381a2ec 100644 --- a/test/jpypetest/test_sql_generic.py +++ b/test/jpypetest/test_sql_generic.py @@ -1,16 +1,9 @@ # This file is Public Domain and may be used without restrictions. -import _jpype -import jpype from jpype.types import * -from jpype import java import jpype.dbapi2 as dbapi2 import common import time -try: - import zlib -except ImportError: - zlib = None class SQLModuleTestCase(common.JPypeTestCase): diff --git a/test/jpypetest/test_sql_h2.py b/test/jpypetest/test_sql_h2.py index e173c0463..e8471ca73 100644 --- a/test/jpypetest/test_sql_h2.py +++ b/test/jpypetest/test_sql_h2.py @@ -1,12 +1,10 @@ # This file is Public Domain and may be used without restrictions, -# because noone should have to waste their lives typing this again. -import _jpype +# because nobody should have to waste their lives typing this again. import jpype from jpype.types import * from jpype import java import jpype.dbapi2 as dbapi2 import common -import time import datetime import decimal import threading @@ -16,7 +14,7 @@ try: import zlib except ImportError: - zlib = None + zlib = None # type: ignore[assignment] db_name = "jdbc:h2:mem:testdb" @@ -795,6 +793,7 @@ def mygen(ls): cu.execute("insert into booze(name,price) values(?,?)", object()) +@common.unittest.skipUnless(zlib, "requires zlib") class AdapterTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -907,6 +906,7 @@ def testTypesPositionalBAD(self): f = cu.fetchone(types=[]) +@common.unittest.skipUnless(zlib, "requires zlib") class GettersTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) diff --git a/test/jpypetest/test_sql_hsqldb.py b/test/jpypetest/test_sql_hsqldb.py index 41b2913fc..231a3a8a0 100644 --- a/test/jpypetest/test_sql_hsqldb.py +++ b/test/jpypetest/test_sql_hsqldb.py @@ -16,7 +16,7 @@ try: import zlib except ImportError: - zlib = None + zlib = None # type: ignore[assignment] db_name = "jdbc:hsqldb:mem:myDb" @@ -24,6 +24,7 @@ #first = "jdbc:derby:memory:myDb;create=True" +@common.unittest.skipUnless(zlib, "requires zlib") class ConnectTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -793,6 +794,7 @@ def mygen(ls): cu.execute("insert into booze(name,price) values(?,?)", object()) +@common.unittest.skipUnless(zlib, "requires zlib") class AdapterTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -905,6 +907,7 @@ def testTypesPositionalBAD(self): f = cu.fetchone(types=[]) +@common.unittest.skipUnless(zlib, "requires zlib") class GettersTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -921,7 +924,7 @@ def tearDown(self): pass -@common.unittest.skip +@common.unittest.skip # type: ignore class TransactionsTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index 182dd515e..a63b4e02c 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -1,12 +1,10 @@ # This file is Public Domain and may be used without restrictions, -# because noone should have to waste their lives typing this again. -import _jpype +# because nobody should have to waste their lives typing this again. import jpype from jpype.types import * from jpype import java import jpype.dbapi2 as dbapi2 import common -import time import datetime import decimal import threading @@ -16,7 +14,7 @@ try: import zlib except ImportError: - zlib = None + zlib = None # type: ignore[assignment] db_name = "jdbc:sqlite::memory:" @@ -657,7 +655,7 @@ def test_nextset(self): if nxt: self.assertEqual(cu.fetchone(), booze) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_lastrowid(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: cu.execute("create table booze(id INTEGER IDENTITY PRIMARY KEY, name varchar(255))") @@ -677,7 +675,7 @@ def test_lastrowid(self): self.assertEqual(f[0][0], id0) self.assertEqual(f[1][0], id2) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_lastrowidMany(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: cu.execute("create table booze(id INTEGER IDENTITY PRIMARY KEY, name varchar(255))") @@ -721,7 +719,7 @@ def test_callproc(self): with self.assertRaises(dbapi2.ProgrammingError): r = cu.callproc("lower", ("FOO",)) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_callprocBad(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: with self.assertRaises(dbapi2.ProgrammingError): @@ -793,6 +791,7 @@ def mygen(ls): cu.execute("insert into booze(name,price) values(?,?)", object()) +@common.unittest.skipUnless(zlib, "requires zlib") class AdapterTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -905,6 +904,7 @@ def testTypesPositionalBAD(self): f = cu.fetchone(types=[]) +@common.unittest.skipUnless(zlib, "requires zlib") class GettersTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -921,7 +921,7 @@ def tearDown(self): pass -@common.unittest.skip +@common.unittest.skip # type: ignore class TransactionsTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -1327,7 +1327,7 @@ def test_close(self): cu.execute("insert into test(name) values('a')") self._testThread(cu, cu.close, (), dbapi2.ProgrammingError) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_callproc(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: cu.execute("create table test(name VARCHAR(10))") From 8da01ad86b3237346384a5d4d93e5a17d4844524 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:12:56 +0000 Subject: [PATCH 082/128] Bump pygments from 2.7.4 to 2.15.0 in /.azure Bumps [pygments](https://github.com/pygments/pygments) from 2.7.4 to 2.15.0. - [Release notes](https://github.com/pygments/pygments/releases) - [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES) - [Commits](https://github.com/pygments/pygments/compare/2.7.4...2.15.0) --- updated-dependencies: - dependency-name: pygments dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- .azure/doc-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/doc-requirements.txt b/.azure/doc-requirements.txt index 5b2b51d90..c6e277493 100644 --- a/.azure/doc-requirements.txt +++ b/.azure/doc-requirements.txt @@ -1,6 +1,6 @@ # TODO: consider unpinning these? -Pygments==2.7.4 +Pygments==2.15.0 docutils==0.14 commonmark==0.8.1 recommonmark==0.5.0 From 35de3e1772bd2b61de052381f61a1aae8cd2fb03 Mon Sep 17 00:00:00 2001 From: wenfer Date: Wed, 30 Aug 2023 17:37:31 +0800 Subject: [PATCH 083/128] fix get_hook_dirs error pyinstall:4.5.1 pyinstaller-hooks-contrib 2023.7 discover_hook_directories: Failed to process hook entry point 'hook-dirs = jpype._pyinstaller.entry_points:get_hook_dirs': expected str, bytes or os.PathLike object, not PosixPath --- jpype/_pyinstaller/entry_points.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpype/_pyinstaller/entry_points.py b/jpype/_pyinstaller/entry_points.py index ab8251679..aae4219f7 100644 --- a/jpype/_pyinstaller/entry_points.py +++ b/jpype/_pyinstaller/entry_points.py @@ -9,7 +9,7 @@ def get_hook_dirs(): - return [fspath(_pyinstaller_path)] + return [fspath(str(_pyinstaller_path))] def get_PyInstaller_tests(): From 1be22fcbaa0ec03da338c26c3eb7328bbc90eadd Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Oct 2023 18:07:19 +0100 Subject: [PATCH 084/128] findjvm.py: print() is a function in Python 3 --- examples/linux/findjvm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/linux/findjvm.py b/examples/linux/findjvm.py index 95fe73e0d..1865a3515 100644 --- a/examples/linux/findjvm.py +++ b/examples/linux/findjvm.py @@ -18,4 +18,4 @@ import os.path jvmlib = jpype.getDefaultJVMPath() -print os.path.dirname(os.path.dirname(jvmlib)) +print(os.path.dirname(os.path.dirname(jvmlib))) From db7ccbcc89b9c1f65605e8477998707521bf3fc2 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Oct 2023 19:05:06 +0100 Subject: [PATCH 085/128] .azure/build.yml: Add Python 3.12 to the build --- .azure/build.yml | 6 ++++++ .azure/scripts/test.yml | 1 + 2 files changed, 7 insertions(+) diff --git a/.azure/build.yml b/.azure/build.yml index 4b16e8e04..a4a01b625 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -65,6 +65,9 @@ jobs: linux-3.11: imageName: "ubuntu-latest" python.version: '3.11' + linux-3.12: + imageName: "ubuntu-latest" + python.version: '3.12' windows-3.7: imageName: "windows-2019" python.version: '3.7' @@ -81,6 +84,9 @@ jobs: windows-3.11: imageName: "windows-2019" python.version: '3.11' + windows-3.12: + imageName: "windows-2019" + python.version: '3.12' mac-3.9: imageName: "macos-11" python.version: '3.9' diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index 3177c59ab..c67cdcc2a 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -9,6 +9,7 @@ steps: version: 11 - script: | + python -m pip install --upgrade pytest setuptools python setup.py build_ext --inplace displayName: 'Build module' From 88107df0ae5e4886adb6a1ce74ccf768ede7ed66 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Oct 2023 23:40:51 +0100 Subject: [PATCH 086/128] print() is a function in Python 3 --- examples/jms/testJpypePublisher.py | 2 +- examples/jms/testJpypeSubscriber.py | 6 +++--- examples/rmi.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/jms/testJpypePublisher.py b/examples/jms/testJpypePublisher.py index 8e0bf92eb..b658fd4cd 100644 --- a/examples/jms/testJpypePublisher.py +++ b/examples/jms/testJpypePublisher.py @@ -27,7 +27,7 @@ def pyPublisher(javaNamingFactory="weblogic.jndi.WLInitialContextFactory", t0 = time.time() for i in range(NUMMSGS): publisher.publish("Hello World! %s" % i) -print "MessageRate =", float(NUMMSGS) / (time.time() - t0) +print("MessageRate =", float(NUMMSGS) / (time.time() - t0)) # The "Stop" message signals the subscriber to stop timing message receipts publisher.publish("Stop") diff --git a/examples/jms/testJpypeSubscriber.py b/examples/jms/testJpypeSubscriber.py index df682b757..2737df680 100644 --- a/examples/jms/testJpypeSubscriber.py +++ b/examples/jms/testJpypeSubscriber.py @@ -24,12 +24,12 @@ class pyCallback: count = 0 def onMessage(self, text): - print text + print(text) if text == 'Start': pyCallback.startTime = time.time() pyCallback.count = 0 elif text == 'Stop': - print "Message Rate =", float(pyCallback.count) / (time.time() - pyCallback.startTime) + print("Message Rate =", float(pyCallback.count) / (time.time() - pyCallback.startTime)) else: pyCallback.count += 1 @@ -39,7 +39,7 @@ def onMessage(self, text): # Get a subscriber sub = pySubscriber(proxy) -print "Listening..." +print("Listening...") # Prevent this thread from exiting time.sleep(1000) diff --git a/examples/rmi.py b/examples/rmi.py index b9dd38634..4955df8e7 100644 --- a/examples/rmi.py +++ b/examples/rmi.py @@ -25,7 +25,7 @@ p = java.rmi.Naming.lookup("rmi://localhost:2004/server") -print p, p.__class__ +print(p, p.__class__) p.callRemote() From a261138a85f7ba1b5a3db1d0c7be29177ac832d3 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 3 Dec 2023 19:46:37 +0100 Subject: [PATCH 087/128] [doc] config renamed to proper file ending. --- .readthedocs.yml => .readthedocs.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .readthedocs.yml => .readthedocs.yaml (100%) diff --git a/.readthedocs.yml b/.readthedocs.yaml similarity index 100% rename from .readthedocs.yml rename to .readthedocs.yaml From 7c5f31af800dfce1e4ce6f00c03280f586f952a5 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 3 Dec 2023 20:06:31 +0100 Subject: [PATCH 088/128] fix missing os error --- .readthedocs.yaml => .readthedocs.yml | 1 + 1 file changed, 1 insertion(+) rename .readthedocs.yaml => .readthedocs.yml (96%) diff --git a/.readthedocs.yaml b/.readthedocs.yml similarity index 96% rename from .readthedocs.yaml rename to .readthedocs.yml index 4b12f640c..85a378c3b 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yml @@ -13,6 +13,7 @@ sphinx: # Optionally set the version of Python and requirements required to build your docs python: + os: ubuntu-20.04 version: "3.8" install: - method: pip From c6c525639493b6de987e66ccb7a03086170584ba Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 3 Dec 2023 20:13:10 +0100 Subject: [PATCH 089/128] f --- .readthedocs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 85a378c3b..2eb5de467 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -13,8 +13,6 @@ sphinx: # Optionally set the version of Python and requirements required to build your docs python: - os: ubuntu-20.04 - version: "3.8" install: - method: pip path: . @@ -22,7 +20,9 @@ python: - docs build: - image: latest + os: ubuntu-22.04 + python: + version: "3.8" apt_packages: - openjdk-8-jdk From 543c9c74b1aecee04b6f285591388188d3e859a4 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 3 Dec 2023 20:28:31 +0100 Subject: [PATCH 090/128] ff --- .readthedocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 2eb5de467..a8902a067 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -20,9 +20,9 @@ python: - docs build: + tools: python os: ubuntu-22.04 - python: - version: "3.8" + python: 3.8 apt_packages: - openjdk-8-jdk From d50e47066313460f9206f340ffa978eb96c67260 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 3 Dec 2023 20:30:02 +0100 Subject: [PATCH 091/128] fff --- .readthedocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index a8902a067..253f5707c 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -20,9 +20,9 @@ python: - docs build: - tools: python + tools: + python: "3.8" os: ubuntu-22.04 - python: 3.8 apt_packages: - openjdk-8-jdk From 0af425d49954dccfbffbc909edc6f199d8c0a1fd Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 3 Dec 2023 14:36:09 -0800 Subject: [PATCH 092/128] Work on py12 --- native/common/jp_primitivetype.cpp | 12 ++++++++++- native/python/pyjp_char.cpp | 33 +++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index a530f04dd..fbc4f2d0f 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -45,9 +45,19 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) return NULL; ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp); +#warning PY_VERSION_HEX +#if PY_VERSION_HEX<0x030c0000 + char *p1 = (char*)&(newobj->ob_digit); + char *p2 = (char*)&(tmp->ob_digit); +#else + char *p1 = (char*)&(newobj->long_value); + char *p2 = (char*)&(tmp->long_value); +#endif for (Py_ssize_t i = 0; i < n; i++) { - newobj->ob_digit[i] = tmp->ob_digit[i]; + *p1 = *p2; + p1++; + p2++; } return (PyObject*) newobj; } diff --git a/native/python/pyjp_char.cpp b/native/python/pyjp_char.cpp index 5b4ab19da..2200bcdbb 100644 --- a/native/python/pyjp_char.cpp +++ b/native/python/pyjp_char.cpp @@ -79,46 +79,63 @@ static int assertNotNull(JPValue *javaSlot) PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) { + // Allocate a new string type (derived from UNICODE) PyJPChar *self = (PyJPChar*) PyJPValue_alloc(type, 0); if (self == 0) return 0; + + // Set up a wide char with value of zero self->m_Data[0] = 0; self->m_Data[1] = 0; self->m_Data[2] = 0; self->m_Data[3] = 0; + // Values taken from internal/cpython/unicode.h + + // Mark the type in unicode _PyUnicode_LENGTH(self) = 1; _PyUnicode_HASH(self) = -1; - _PyUnicode_STATE(self).kind = PyUnicode_1BYTE_KIND; - _PyUnicode_STATE(self).ascii = 0; - _PyUnicode_STATE(self).ready = 1; - _PyUnicode_STATE(self).interned = 0; _PyUnicode_STATE(self).compact = 1; + _PyUnicode_STATE(self).interned = 0; +#if PY_VERSION_HEX < 0x030c0000 + _PyUnicode_STATE(self).ready = 1; +#endif + + // Copy the value based on the length if (p < 128) { _PyUnicode_STATE(self).ascii = 1; + _PyUnicode_STATE(self).kind = PyUnicode_1BYTE_KIND; + char *data = (char*) (((PyASCIIObject*) self) + 1); data[0] = p; data[1] = 0; - } else - if (p < 256) + } else if (p < 256) { + _PyUnicode_STATE(self).ascii = 0; + _PyUnicode_STATE(self).kind = PyUnicode_1BYTE_KIND; + char *data = (char*) ( ((PyCompactUnicodeObject*) self) + 1); data[0] = p; data[1] = 0; + +#if PY_VERSION_HEX < 0x030c0000 _PyUnicode_WSTR_LENGTH(self) = 0; _PyUnicode_WSTR(self) = NULL; +#endif self->m_Obj.utf8 = NULL; self->m_Obj.utf8_length = 0; } else { + _PyUnicode_STATE(self).ascii = 0; + _PyUnicode_STATE(self).kind = PyUnicode_2BYTE_KIND; Py_UCS2 *data = (Py_UCS2*) ( ((PyCompactUnicodeObject*) self) + 1); data[0] = p; data[1] = 0; - _PyUnicode_STATE(self).kind = PyUnicode_2BYTE_KIND; +#if PY_VERSION_HEX < 0x030c0000 if (sizeof (wchar_t) == 2) { _PyUnicode_WSTR_LENGTH(self) = 1; @@ -128,9 +145,11 @@ PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) _PyUnicode_WSTR_LENGTH(self) = 0; _PyUnicode_WSTR(self) = NULL; } +#endif self->m_Obj.utf8 = NULL; self->m_Obj.utf8_length = 0; } + return (PyObject*) self; } From 5c49b8e15262e53efd0fe4f2d93f18322b54bd38 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 3 Dec 2023 15:21:48 -0800 Subject: [PATCH 093/128] Work of starting jvm --- native/common/jp_primitivetype.cpp | 14 +++++++++----- native/python/pyjp_module.cpp | 10 ++++++++++ test/jpypetest/test_javadoc.py | 4 +++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index fbc4f2d0f..616faa44e 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -36,6 +36,8 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) { if (wrapper == NULL) JP_RAISE(PyExc_SystemError, "bad wrapper"); + + // Determine number of bytes to copy Py_ssize_t n = Py_SIZE(tmp); if (n < 0) n = -n; @@ -44,14 +46,16 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) if (newobj == NULL) return NULL; + // Size is in units of digits + ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp); -#warning PY_VERSION_HEX #if PY_VERSION_HEX<0x030c0000 - char *p1 = (char*)&(newobj->ob_digit); - char *p2 = (char*)&(tmp->ob_digit); + digit *p1 = (digit*)&(newobj->ob_digit); + digit *p2 = (digit*)&(tmp->ob_digit); #else - char *p1 = (char*)&(newobj->long_value); - char *p2 = (char*)&(tmp->long_value); + newobj->long_value.lv_tag = tmp->long_value.lv_tag; + digit *p1 = (digit*)&(newobj->long_value.ob_digit); + digit *p2 = (digit*)&(tmp->long_value.ob_digit); #endif for (Py_ssize_t i = 0; i < n; i++) { diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 9dcfdfdf5..695bc5c70 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -169,11 +169,21 @@ PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name) if (type->tp_mro == NULL) return NULL; // GCOVR_EXCL_LINE + // Grab the mro PyObject *mro = type->tp_mro; + + // mco should be a tuple Py_ssize_t n = PyTuple_Size(mro); + + // Search the tuple for the attribute for (Py_ssize_t i = 0; i < n; ++i) { PyTypeObject *type2 = (PyTypeObject*) PyTuple_GetItem(mro, i); + + // Skip objects without a functioning dictionary + if (type2->tp_dict == NULL) + continue; + PyObject *res = PyDict_GetItem(type2->tp_dict, attr_name); if (res) { diff --git a/test/jpypetest/test_javadoc.py b/test/jpypetest/test_javadoc.py index 0f5f93171..a17f11d03 100644 --- a/test/jpypetest/test_javadoc.py +++ b/test/jpypetest/test_javadoc.py @@ -38,7 +38,9 @@ def testClass(self): JC = jpype.JClass("jpype.doc.Test") jd = JC.__doc__ self.assertIsInstance(jd, str) - self.assertRegex(jd, "random stuff") + # Disabled this test for now. Java needs a better API for accessing Java doc. + # It is hard to deal with random changes every version. + #self.assertRegex(jd, "random stuff") def testMethod(self): JC = jpype.JClass("jpype.doc.Test") From 485de7f0b980a27f19b9b7cf9b17a1adaf177d8c Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 3 Dec 2023 20:45:58 -0800 Subject: [PATCH 094/128] Work on int types --- native/common/jp_primitivetype.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index 616faa44e..343a4a621 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -46,23 +46,23 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) if (newobj == NULL) return NULL; - // Size is in units of digits - ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp); #if PY_VERSION_HEX<0x030c0000 digit *p1 = (digit*)&(newobj->ob_digit); digit *p2 = (digit*)&(tmp->ob_digit); -#else - newobj->long_value.lv_tag = tmp->long_value.lv_tag; - digit *p1 = (digit*)&(newobj->long_value.ob_digit); - digit *p2 = (digit*)&(tmp->long_value.ob_digit); -#endif + + // Size is in units of digits for (Py_ssize_t i = 0; i < n; i++) { *p1 = *p2; p1++; p2++; } + +#else + // Size is in units of bytes + tag size + memcpy(&newobj->long_value, &tmp->long_value, n+sizeof(uintptr_t)); +#endif return (PyObject*) newobj; } From 737ae0e5d3987be409ae656bcc7e7be8db029b7c Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 3 Dec 2023 22:58:36 -0800 Subject: [PATCH 095/128] Fix broken PyLong... no more ob_size so now need lots of kludges. --- native/common/jp_primitivetype.cpp | 26 +++++++++++++++----------- native/python/pyjp_value.cpp | 12 ++++++++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index 343a4a621..499ae3da4 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -29,6 +29,7 @@ bool JPPrimitiveType::isPrimitive() const return true; } +extern "C" Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self); // equivalent of long_subtype_new as it isn't exposed @@ -37,7 +38,8 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) if (wrapper == NULL) JP_RAISE(PyExc_SystemError, "bad wrapper"); - // Determine number of bytes to copy +#if PY_VERSION_HEX<0x030c0000 + // Determine number of digits to copy Py_ssize_t n = Py_SIZE(tmp); if (n < 0) n = -n; @@ -46,22 +48,24 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) if (newobj == NULL) return NULL; - ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp); -#if PY_VERSION_HEX<0x030c0000 - digit *p1 = (digit*)&(newobj->ob_digit); - digit *p2 = (digit*)&(tmp->ob_digit); - // Size is in units of digits for (Py_ssize_t i = 0; i < n; i++) { - *p1 = *p2; - p1++; - p2++; + newobj->ob_digit[i] = tmp->ob_digit[i]; } #else - // Size is in units of bytes + tag size - memcpy(&newobj->long_value, &tmp->long_value, n+sizeof(uintptr_t)); + // 3.12 completely does away with ob_size field and repurposes it + + // Determine the number of digits to copy + int n = (tmp->long_value.lv_tag >> 3); + + PyLongObject *newobj = (PyLongObject *) wrapper->tp_alloc(wrapper, n); + if (newobj == NULL) + return NULL; + + newobj->long_value.lv_tag = tmp->long_value.lv_tag; + memcpy(&newobj->long_value.ob_digit, &tmp->long_value.ob_digit, n*sizeof(digit)); #endif return (PyObject*) newobj; } diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index 93dba9505..140f1bbc3 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -69,7 +69,10 @@ PyObject* PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ) return PyErr_NoMemory(); // GCOVR_EXCL_LINE memset(obj, 0, size); + Py_ssize_t refcnt = ((PyObject*) type)->ob_refcnt; + obj->ob_type = type; + if (type->tp_itemsize == 0) PyObject_Init(obj, type); else @@ -107,8 +110,13 @@ Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self) || type->tp_finalize != (destructor) PyJPValue_finalize) return 0; Py_ssize_t offset; - Py_ssize_t sz = Py_SIZE(self); - // I have no clue what negative sizes mean + Py_ssize_t sz = 0; + // starting in 3.12 there is no longer ob_size in PyLong + if (PyType_HasFeature(self->ob_type, Py_TPFLAGS_LONG_SUBCLASS)) + sz = (((PyLongObject*)self)->long_value.lv_tag) >> 3; // Private NON_SIZE_BITS + else if (type->tp_itemsize != 0) + sz = Py_SIZE(self); + // PyLong abuses ob_size with negative values prior to 3.12 if (sz < 0) sz = -sz; if (type->tp_itemsize == 0) From 9f4a286b844c2c45a96dfda95616c01976288ff5 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Mon, 4 Dec 2023 19:42:22 -0800 Subject: [PATCH 096/128] Works with py12 --- native/python/pyjp_array.cpp | 18 ++++++------------ native/python/pyjp_buffer.cpp | 7 ++----- native/python/pyjp_class.cpp | 6 ++++++ test/jpypetest/test_bytebuffer.py | 2 +- test/jpypetest/test_classhints.py | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/native/python/pyjp_array.cpp b/native/python/pyjp_array.cpp index 9dc53774c..f3e100e29 100644 --- a/native/python/pyjp_array.cpp +++ b/native/python/pyjp_array.cpp @@ -428,14 +428,11 @@ static PyType_Slot arraySlots[] = { { Py_sq_length, (void*) &PyJPArray_len}, { Py_tp_getset, (void*) &arrayGetSets}, { Py_mp_ass_subscript, (void*) &PyJPArray_assignSubscript}, + { Py_bf_getbuffer, (void*) &PyJPArray_getBuffer}, + { Py_bf_releasebuffer, (void*) &PyJPArray_releaseBuffer}, {0} }; -static PyBufferProcs arrayBuffer = { - (getbufferproc) & PyJPArray_getBuffer, - (releasebufferproc) & PyJPArray_releaseBuffer -}; - PyTypeObject *PyJPArray_Type = NULL; static PyType_Spec arraySpec = { "_jpype._JArray", @@ -445,12 +442,9 @@ static PyType_Spec arraySpec = { arraySlots }; -static PyBufferProcs arrayPrimBuffer = { - (getbufferproc) & PyJPArrayPrimitive_getBuffer, - (releasebufferproc) & PyJPArray_releaseBuffer -}; - static PyType_Slot arrayPrimSlots[] = { + { Py_bf_getbuffer, (void*) &PyJPArrayPrimitive_getBuffer}, + { Py_bf_releasebuffer, (void*) &PyJPArray_releaseBuffer}, {0} }; @@ -472,14 +466,14 @@ void PyJPArray_initType(PyObject * module) JPPyObject tuple = JPPyObject::call(PyTuple_Pack(1, PyJPObject_Type)); PyJPArray_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&arraySpec, tuple.get()); JP_PY_CHECK(); - PyJPArray_Type->tp_as_buffer = &arrayBuffer; + //PyJPArray_Type->tp_as_buffer = &arrayBuffer; PyModule_AddObject(module, "_JArray", (PyObject*) PyJPArray_Type); JP_PY_CHECK(); tuple = JPPyObject::call(PyTuple_Pack(1, PyJPArray_Type)); PyJPArrayPrimitive_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&arrayPrimSpec, tuple.get()); - PyJPArrayPrimitive_Type->tp_as_buffer = &arrayPrimBuffer; + //PyJPArrayPrimitive_Type->tp_as_buffer = &arrayPrimBuffer; JP_PY_CHECK(); PyModule_AddObject(module, "_JArrayPrimitive", (PyObject*) PyJPArrayPrimitive_Type); diff --git a/native/python/pyjp_buffer.cpp b/native/python/pyjp_buffer.cpp index e2f56e1f6..a3c58d418 100644 --- a/native/python/pyjp_buffer.cpp +++ b/native/python/pyjp_buffer.cpp @@ -113,13 +113,11 @@ int PyJPBuffer_getBuffer(PyJPBuffer *self, Py_buffer *view, int flags) static PyType_Slot bufferSlots[] = { { Py_tp_dealloc, (void*) PyJPBuffer_dealloc}, { Py_tp_repr, (void*) PyJPBuffer_repr}, + { Py_bf_getbuffer, (void*) PyJPBuffer_getBuffer}, + { Py_bf_releasebuffer, (void*) PyJPBuffer_releaseBuffer}, {0} }; -static PyBufferProcs directBuffer = { - (getbufferproc) & PyJPBuffer_getBuffer, - (releasebufferproc) & PyJPBuffer_releaseBuffer -}; PyTypeObject *PyJPBuffer_Type = NULL; static PyType_Spec bufferSpec = { @@ -138,7 +136,6 @@ void PyJPBuffer_initType(PyObject * module) { JPPyObject tuple = JPPyObject::call(PyTuple_Pack(1, PyJPObject_Type)); PyJPBuffer_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&bufferSpec, tuple.get()); - PyJPBuffer_Type->tp_as_buffer = &directBuffer; JP_PY_CHECK(); PyModule_AddObject(module, "_JBuffer", (PyObject*) PyJPBuffer_Type); JP_PY_CHECK(); diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index 0fb283959..b4ea05809 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -276,6 +276,12 @@ PyObject* PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) case Py_tp_getset: type->tp_getset = (PyGetSetDef*) slot->pfunc; break; + case Py_bf_getbuffer: + type->tp_as_buffer->bf_getbuffer = (getbufferproc) slot->pfunc; + break; + case Py_bf_releasebuffer: + type->tp_as_buffer->bf_releasebuffer = (releasebufferproc) slot->pfunc; + break; // GCOVR_EXCL_START default: PyErr_Format(PyExc_TypeError, "slot %d not implemented", slot->slot); diff --git a/test/jpypetest/test_bytebuffer.py b/test/jpypetest/test_bytebuffer.py index b4c7e4757..d81ed3dd8 100644 --- a/test/jpypetest/test_bytebuffer.py +++ b/test/jpypetest/test_bytebuffer.py @@ -48,4 +48,4 @@ def testRepr(self): self.assertEqual(repr(bb), "") def testMemoryView(self): - self.assertEquals(memoryview(jpype.java.nio.ByteBuffer.allocateDirect(100)).nbytes, 100) + self.assertEqual(memoryview(jpype.java.nio.ByteBuffer.allocateDirect(100)).nbytes, 100) diff --git a/test/jpypetest/test_classhints.py b/test/jpypetest/test_classhints.py index bcf895622..08c1187a9 100644 --- a/test/jpypetest/test_classhints.py +++ b/test/jpypetest/test_classhints.py @@ -59,7 +59,7 @@ def testCharSequence(self): def testInstant(self): import datetime - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.UTC) Instant = jpype.JClass("java.time.Instant") self.assertIsInstance(jpype.JObject(now, Instant), Instant) From c61d75c2957f32fb349b40445fc2b1d5bdd9d5e0 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Mon, 4 Dec 2023 19:54:55 -0800 Subject: [PATCH 097/128] Runs on Python 3.10 --- native/common/jp_primitivetype.cpp | 1 + native/python/pyjp_value.cpp | 6 +++++- test/jpypetest/test_classhints.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/native/common/jp_primitivetype.cpp b/native/common/jp_primitivetype.cpp index 499ae3da4..a07975a86 100644 --- a/native/common/jp_primitivetype.cpp +++ b/native/common/jp_primitivetype.cpp @@ -49,6 +49,7 @@ PyObject *JPPrimitiveType::convertLong(PyTypeObject* wrapper, PyLongObject* tmp) return NULL; // Size is in units of digits + ((PyVarObject*) newobj)->ob_size = Py_SIZE(tmp); for (Py_ssize_t i = 0; i < n; i++) { newobj->ob_digit[i] = tmp->ob_digit[i]; diff --git a/native/python/pyjp_value.cpp b/native/python/pyjp_value.cpp index 140f1bbc3..4546c6d36 100644 --- a/native/python/pyjp_value.cpp +++ b/native/python/pyjp_value.cpp @@ -111,10 +111,14 @@ Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self) return 0; Py_ssize_t offset; Py_ssize_t sz = 0; + +#if PY_VERSION_HEX>=0x030c0000 // starting in 3.12 there is no longer ob_size in PyLong if (PyType_HasFeature(self->ob_type, Py_TPFLAGS_LONG_SUBCLASS)) sz = (((PyLongObject*)self)->long_value.lv_tag) >> 3; // Private NON_SIZE_BITS - else if (type->tp_itemsize != 0) + else +#endif + if (type->tp_itemsize != 0) sz = Py_SIZE(self); // PyLong abuses ob_size with negative values prior to 3.12 if (sz < 0) diff --git a/test/jpypetest/test_classhints.py b/test/jpypetest/test_classhints.py index 08c1187a9..d200d798a 100644 --- a/test/jpypetest/test_classhints.py +++ b/test/jpypetest/test_classhints.py @@ -17,6 +17,7 @@ # ***************************************************************************** import jpype import common +import sys class MyImpl(object): @@ -59,7 +60,10 @@ def testCharSequence(self): def testInstant(self): import datetime - now = datetime.datetime.now(datetime.UTC) + if sys.version_info.major == 3 and sys.version_info.minor < 12: + now = datetime.datetime.utcnow() + else: + now = datetime.datetime.now(datetime.UTC) Instant = jpype.JClass("java.time.Instant") self.assertIsInstance(jpype.JObject(now, Instant), Instant) From c28a6a66bbb350060ebd5514ead6e3a0aac52fe1 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Mon, 4 Dec 2023 20:05:51 -0800 Subject: [PATCH 098/128] Remove deprecated call --- native/common/jp_gc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/jp_gc.cpp b/native/common/jp_gc.cpp index 8b711f997..795300788 100644 --- a/native/common/jp_gc.cpp +++ b/native/common/jp_gc.cpp @@ -85,8 +85,8 @@ size_t getWorkingSize() return sz * page_size; #elif defined(USE_MALLINFO) - struct mallinfo mi; - mi = mallinfo(); + struct mallinfo2 mi; + mi = mallinfo2(); current = (size_t) mi.uordblks; #endif From 5343c950c4d4c7d93f4d81402fc0ea835cf447c9 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Mon, 4 Dec 2023 22:36:37 -0800 Subject: [PATCH 099/128] Works for 3.9 --- native/python/pyjp_array.cpp | 26 ++++++++++++++++++++++++-- native/python/pyjp_buffer.cpp | 11 +++++++++++ native/python/pyjp_class.cpp | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/native/python/pyjp_array.cpp b/native/python/pyjp_array.cpp index f3e100e29..17bba6292 100644 --- a/native/python/pyjp_array.cpp +++ b/native/python/pyjp_array.cpp @@ -428,11 +428,20 @@ static PyType_Slot arraySlots[] = { { Py_sq_length, (void*) &PyJPArray_len}, { Py_tp_getset, (void*) &arrayGetSets}, { Py_mp_ass_subscript, (void*) &PyJPArray_assignSubscript}, +#if PY_VERSION_HEX >= 0x03090000 { Py_bf_getbuffer, (void*) &PyJPArray_getBuffer}, { Py_bf_releasebuffer, (void*) &PyJPArray_releaseBuffer}, +#endif {0} }; +#if PY_VERSION_HEX < 0x03090000 +static PyBufferProcs arrayBuffer = { + (getbufferproc) & PyJPArray_getBuffer, + (releasebufferproc) & PyJPArray_releaseBuffer +}; +#endif + PyTypeObject *PyJPArray_Type = NULL; static PyType_Spec arraySpec = { "_jpype._JArray", @@ -442,9 +451,18 @@ static PyType_Spec arraySpec = { arraySlots }; +#if PY_VERSION_HEX < 0x03090000 +static PyBufferProcs arrayPrimBuffer = { + (getbufferproc) & PyJPArrayPrimitive_getBuffer, + (releasebufferproc) & PyJPArray_releaseBuffer +}; +#endif + static PyType_Slot arrayPrimSlots[] = { +#if PY_VERSION_HEX >= 0x03090000 { Py_bf_getbuffer, (void*) &PyJPArrayPrimitive_getBuffer}, { Py_bf_releasebuffer, (void*) &PyJPArray_releaseBuffer}, +#endif {0} }; @@ -466,14 +484,18 @@ void PyJPArray_initType(PyObject * module) JPPyObject tuple = JPPyObject::call(PyTuple_Pack(1, PyJPObject_Type)); PyJPArray_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&arraySpec, tuple.get()); JP_PY_CHECK(); - //PyJPArray_Type->tp_as_buffer = &arrayBuffer; +#if PY_VERSION_HEX < 0x03090000 + PyJPArray_Type->tp_as_buffer = &arrayBuffer; +#endif PyModule_AddObject(module, "_JArray", (PyObject*) PyJPArray_Type); JP_PY_CHECK(); tuple = JPPyObject::call(PyTuple_Pack(1, PyJPArray_Type)); PyJPArrayPrimitive_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&arrayPrimSpec, tuple.get()); - //PyJPArrayPrimitive_Type->tp_as_buffer = &arrayPrimBuffer; +#if PY_VERSION_HEX < 0x03090000 + PyJPArrayPrimitive_Type->tp_as_buffer = &arrayPrimBuffer; +#endif JP_PY_CHECK(); PyModule_AddObject(module, "_JArrayPrimitive", (PyObject*) PyJPArrayPrimitive_Type); diff --git a/native/python/pyjp_buffer.cpp b/native/python/pyjp_buffer.cpp index a3c58d418..0dc95ac11 100644 --- a/native/python/pyjp_buffer.cpp +++ b/native/python/pyjp_buffer.cpp @@ -113,11 +113,19 @@ int PyJPBuffer_getBuffer(PyJPBuffer *self, Py_buffer *view, int flags) static PyType_Slot bufferSlots[] = { { Py_tp_dealloc, (void*) PyJPBuffer_dealloc}, { Py_tp_repr, (void*) PyJPBuffer_repr}, +#if PY_VERSION_HEX >= 0x03090000 { Py_bf_getbuffer, (void*) PyJPBuffer_getBuffer}, { Py_bf_releasebuffer, (void*) PyJPBuffer_releaseBuffer}, +#endif {0} }; +#if PY_VERSION_HEX < 0x03090000 +static PyBufferProcs directBuffer = { + (getbufferproc) & PyJPBuffer_getBuffer, + (releasebufferproc) & PyJPBuffer_releaseBuffer +}; +#endif PyTypeObject *PyJPBuffer_Type = NULL; static PyType_Spec bufferSpec = { @@ -136,6 +144,9 @@ void PyJPBuffer_initType(PyObject * module) { JPPyObject tuple = JPPyObject::call(PyTuple_Pack(1, PyJPObject_Type)); PyJPBuffer_Type = (PyTypeObject*) PyJPClass_FromSpecWithBases(&bufferSpec, tuple.get()); +#if PY_VERSION_HEX < 0x03090000 + PyJPBuffer_Type->tp_as_buffer = &directBuffer; +#endif JP_PY_CHECK(); PyModule_AddObject(module, "_JBuffer", (PyObject*) PyJPBuffer_Type); JP_PY_CHECK(); diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp index b4ea05809..dc6f28229 100644 --- a/native/python/pyjp_class.cpp +++ b/native/python/pyjp_class.cpp @@ -276,12 +276,14 @@ PyObject* PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) case Py_tp_getset: type->tp_getset = (PyGetSetDef*) slot->pfunc; break; +#if PY_VERSION_HEX >= 0x03090000 case Py_bf_getbuffer: type->tp_as_buffer->bf_getbuffer = (getbufferproc) slot->pfunc; break; case Py_bf_releasebuffer: type->tp_as_buffer->bf_releasebuffer = (releasebufferproc) slot->pfunc; break; +#endif // GCOVR_EXCL_START default: PyErr_Format(PyExc_TypeError, "slot %d not implemented", slot->slot); From 2e15660f15ae0a5f29d451fffca6d8d522e22036 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Tue, 5 Dec 2023 08:43:51 -0800 Subject: [PATCH 100/128] Typo --- native/python/pyjp_module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 695bc5c70..d0d42cc10 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -172,7 +172,7 @@ PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name) // Grab the mro PyObject *mro = type->tp_mro; - // mco should be a tuple + // mro should be a tuple Py_ssize_t n = PyTuple_Size(mro); // Search the tuple for the attribute From bec73f78c2afa6fedf99de535172d4d69838c3ce Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 11:23:29 -0800 Subject: [PATCH 101/128] Change back to broken mallinfo for now --- native/common/jp_gc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/common/jp_gc.cpp b/native/common/jp_gc.cpp index 029d673dd..505373580 100644 --- a/native/common/jp_gc.cpp +++ b/native/common/jp_gc.cpp @@ -85,8 +85,8 @@ size_t getWorkingSize() return sz * page_size; #elif defined(USE_MALLINFO) - struct mallinfo2 mi; - mi = mallinfo2(); + struct mallinfo mi; + mi = mallinfo(); current = (size_t) mi.uordblks; #endif From 832dcbd3e81d61e9c923af82b3e694ad5a18baaa Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 12:21:43 -0800 Subject: [PATCH 102/128] Attempt at fix --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index ca01bd7eb..bc88e6a35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ module = [ "java.*", "jpypex.common", "jedi", + "jedi.access", ] ignore_missing_imports = true From 60e68fec3455ab9f73ce9b79434c12f67b3c96f0 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 12:26:00 -0800 Subject: [PATCH 103/128] Another attempt --- jpype/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpype/_core.py b/jpype/_core.py index 3e2db229e..072e9ad85 100644 --- a/jpype/_core.py +++ b/jpype/_core.py @@ -163,7 +163,7 @@ def interactive(): def startJVM( *jvmargs: str, jvmpath: typing.Optional[_PathOrStr] = None, - classpath: typing.Optional[typing.Sequence[_PathOrStr], _PathOrStr] = None, + classpath: typing.Union[typing.Sequence[_PathOrStr], _PathOrStr, None] = None, ignoreUnrecognized: bool = False, convertStrings: bool = False, interrupt: bool = not interactive(), From a0bc7c6ec324f23c8d8e7ece430dda32df98e742 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 12:28:29 -0800 Subject: [PATCH 104/128] Not sure --- jpype/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpype/_core.py b/jpype/_core.py index 072e9ad85..424b416ec 100644 --- a/jpype/_core.py +++ b/jpype/_core.py @@ -108,7 +108,7 @@ def isJVMStarted(): return _jpype.isStarted() -def _hasClassPath(args: typing.Tuple[_PathOrStr, ...]) -> bool: +def _hasClassPath(args) -> bool: for i in args: if isinstance(i, str) and i.startswith('-Djava.class.path'): return True From 700ec37a9fb54db9b1f3a444a5e21b95a985c2e3 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 12:35:05 -0800 Subject: [PATCH 105/128] Another attempt --- jpype/_core.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/jpype/_core.py b/jpype/_core.py index 424b416ec..ca1191d01 100644 --- a/jpype/_core.py +++ b/jpype/_core.py @@ -115,12 +115,7 @@ def _hasClassPath(args) -> bool: return False -def _handleClassPath( - classpath: typing.Union[ - _PathOrStr, - typing.Tuple[_PathOrStr, ...] - ], -) -> str: +def _handleClassPath(classpath) -> str: """ Return a classpath which represents the given tuple of classpath specifications """ From ca292742532850b135ced6d164df1890174c0f10 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 13:31:00 -0800 Subject: [PATCH 106/128] Corrent warnings in GCC and VC --- native/common/jp_context.cpp | 1 + native/common/jp_exception.cpp | 1 + native/common/jp_proxy.cpp | 4 ++++ native/python/jp_pythontypes.cpp | 2 +- native/python/pyjp_array.cpp | 3 +++ native/python/pyjp_buffer.cpp | 1 + native/python/pyjp_char.cpp | 4 ++-- native/python/pyjp_module.cpp | 12 ++++++------ 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/native/common/jp_context.cpp b/native/common/jp_context.cpp index c304fe4b2..fc2baa8d2 100644 --- a/native/common/jp_context.cpp +++ b/native/common/jp_context.cpp @@ -103,6 +103,7 @@ void JPContext::startJVM(const string& vmPath, const StringVector& args, loadEntryPoints(vmPath); } catch (JPypeException& ex) { + (void) ex; throw; } diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 088f4721b..10cc9c9ec 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -224,6 +224,7 @@ void JPypeException::convertJavaToPython() PyException_SetCause(pyvalue.get(), cause.keep()); } catch (JPypeException& ex) { + (void) ex; JP_TRACE("FAILURE IN CAUSE"); // Any failures in this optional action should be ignored. // worst case we don't print as much diagnostics. diff --git a/native/common/jp_proxy.cpp b/native/common/jp_proxy.cpp index a9d83de2d..8ad3f464d 100644 --- a/native/common/jp_proxy.cpp +++ b/native/common/jp_proxy.cpp @@ -59,6 +59,7 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( // We need the resources to be held for the full duration of the proxy. JPPyCallAcquire callback; + try { JP_TRACE_IN("JPype_InvocationHandler_hostInvoke"); JP_TRACE("context", context); @@ -151,6 +152,9 @@ extern "C" JNIEXPORT jobject JNICALL Java_org_jpype_proxy_JPypeProxy_hostInvoke( return nullptr; JP_TRACE_OUT; // GCOVR_EXCL_LINE } + catch (...) // JP_TRACE_OUT implies a throw but that is not allowed. + {} + return NULL; } JPProxy::JPProxy(JPContext* context, PyJPProxy* inst, JPClassList& intf) diff --git a/native/python/jp_pythontypes.cpp b/native/python/jp_pythontypes.cpp index e532955cc..01178cb93 100644 --- a/native/python/jp_pythontypes.cpp +++ b/native/python/jp_pythontypes.cpp @@ -340,7 +340,7 @@ jlong JPPySequence::size() JPPyObject JPPySequence::operator[](jlong i) { - return JPPyObject::call(PySequence_GetItem(m_Sequence.get(), i)); // new reference + return JPPyObject::call(PySequence_GetItem(m_Sequence.get(), (Py_ssize_t) i)); // new reference } JPPyObjectVector::JPPyObjectVector(PyObject* sequence) diff --git a/native/python/pyjp_array.cpp b/native/python/pyjp_array.cpp index 3a3b0d043..17066531c 100644 --- a/native/python/pyjp_array.cpp +++ b/native/python/pyjp_array.cpp @@ -295,6 +295,7 @@ int PyJPArray_getBuffer(PyJPArray *self, Py_buffer *view, int flags) } catch (JPypeException &ex) { // No matter what happens we are only allowed to throw BufferError + (void) ex; PyErr_SetString(PyExc_BufferError, "Problem in Java buffer extraction"); return -1; } @@ -332,6 +333,7 @@ int PyJPArray_getBuffer(PyJPArray *self, Py_buffer *view, int flags) return 0; } catch (JPypeException &ex) // GCOVR_EXCL_LINE { + (void) ex; // GCOVR_EXCL_START // Release the partial buffer so we don't leak PyJPArray_releaseBuffer(self, view); @@ -393,6 +395,7 @@ int PyJPArrayPrimitive_getBuffer(PyJPArray *self, Py_buffer *view, int flags) return 0; } catch (JPypeException &ex) { + (void) ex; PyJPArray_releaseBuffer(self, view); // We are only allowed to raise BufferError diff --git a/native/python/pyjp_buffer.cpp b/native/python/pyjp_buffer.cpp index 14e7fb49e..fdf6dc56b 100644 --- a/native/python/pyjp_buffer.cpp +++ b/native/python/pyjp_buffer.cpp @@ -99,6 +99,7 @@ int PyJPBuffer_getBuffer(PyJPBuffer *self, Py_buffer *view, int flags) return 0; } catch (JPypeException &ex) // GCOVR_EXCL_LINE { + (void) ex; // GCOVR_EXCL_START PyJPBuffer_releaseBuffer(self, view); diff --git a/native/python/pyjp_char.cpp b/native/python/pyjp_char.cpp index a867d69ab..d6d21dcf0 100644 --- a/native/python/pyjp_char.cpp +++ b/native/python/pyjp_char.cpp @@ -110,7 +110,7 @@ PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) _PyUnicode_STATE(self).kind = PyUnicode_1BYTE_KIND; char *data = (char*) (((PyASCIIObject*) self) + 1); - data[0] = p; + data[0] = (char) p; data[1] = 0; } else if (p < 256) { @@ -118,7 +118,7 @@ PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p) _PyUnicode_STATE(self).kind = PyUnicode_1BYTE_KIND; char *data = (char*) ( ((PyCompactUnicodeObject*) self) + 1); - data[0] = p; + data[0] = (char) p; data[1] = 0; #if PY_VERSION_HEX < 0x030c0000 diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 628694b69..9caa0d437 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -545,17 +545,17 @@ PyObject *PyJPModule_gcStats(PyObject* module, PyObject *obj) context->m_GC->getStats(stats); PyObject *out = PyDict_New(); PyObject *res; - PyDict_SetItemString(out, "current", res = PyLong_FromSsize_t(stats.current_rss)); + PyDict_SetItemString(out, "current", res = PyLong_FromSsize_t((Py_ssize_t)(stats.current_rss))); Py_DECREF(res); - PyDict_SetItemString(out, "java", res = PyLong_FromSsize_t(stats.java_rss)); + PyDict_SetItemString(out, "java", res = PyLong_FromSsize_t((Py_ssize_t)(stats.java_rss))); Py_DECREF(res); - PyDict_SetItemString(out, "python", res = PyLong_FromSsize_t(stats.python_rss)); + PyDict_SetItemString(out, "python", res = PyLong_FromSsize_t((Py_ssize_t)(stats.python_rss))); Py_DECREF(res); - PyDict_SetItemString(out, "max", res = PyLong_FromSsize_t(stats.max_rss)); + PyDict_SetItemString(out, "max", res = PyLong_FromSsize_t((Py_ssize_t)(stats.max_rss))); Py_DECREF(res); - PyDict_SetItemString(out, "min", res = PyLong_FromSsize_t(stats.min_rss)); + PyDict_SetItemString(out, "min", res = PyLong_FromSsize_t((Py_ssize_t)(stats.min_rss))); Py_DECREF(res); - PyDict_SetItemString(out, "triggered", res = PyLong_FromSsize_t(stats.python_triggered)); + PyDict_SetItemString(out, "triggered", res = PyLong_FromSsize_t((Py_ssize_t)(stats.python_triggered))); Py_DECREF(res); return out; } From 756687280284d44545f07ba0ecaf1bb618a53eae Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 16:21:45 -0800 Subject: [PATCH 107/128] =?UTF-8?q?Bump=20version:=201.5.0=5Fdev0=20?= =?UTF-8?q?=E2=86=92=201.5.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- doc/CHANGELOG.rst | 1 + jpype/__init__.py | 2 +- native/java/org/jpype/JPypeContext.java | 2 +- native/python/pyjp_module.cpp | 2 +- setup.py | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 83750a368..3d5870b0e 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.5.0_dev0 +current_version = 1.5.0 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\_(?P[a-z]+)(?P\d+))? diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index c4e08c0ab..52df3ca75 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -4,6 +4,7 @@ Changelog This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards. Latest Changes: +- **1.5.0 - 2023-12-10** - **1.5.0_dev0 - 2023-04-03** - Switched ``__eq__`` and ``__ne__`` operator to use ``equals`` rather than diff --git a/jpype/__init__.py b/jpype/__init__.py index aa7071ae9..7bf5c016a 100644 --- a/jpype/__init__.py +++ b/jpype/__init__.py @@ -52,7 +52,7 @@ __all__.extend(_jcustomizer.__all__) # type: ignore[name-defined] __all__.extend(_gui.__all__) # type: ignore[name-defined] -__version__ = "1.5.0_dev0" +__version__ = "1.5.0" __version_info__ = __version__.split('.') diff --git a/native/java/org/jpype/JPypeContext.java b/native/java/org/jpype/JPypeContext.java index 59396d1e9..8470c2bc4 100644 --- a/native/java/org/jpype/JPypeContext.java +++ b/native/java/org/jpype/JPypeContext.java @@ -73,7 +73,7 @@ public class JPypeContext { - public final String VERSION = "1.5.0_dev0"; + public final String VERSION = "1.5.0"; private static JPypeContext INSTANCE = new JPypeContext(); // This is the C++ portion of the context. diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 9caa0d437..0bd9d86c3 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -729,7 +729,7 @@ PyMODINIT_FUNC PyInit__jpype() // PyJPModule = module; Py_INCREF(module); PyJPModule = module; - PyModule_AddStringConstant(module, "__version__", "1.5.0_dev0"); + PyModule_AddStringConstant(module, "__version__", "1.5.0"); // Our module will be used for PyFrame object and it is a requirement that // we have a builtins in our dictionary. diff --git a/setup.py b/setup.py index c48875b49..f35d8f937 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ setup( name='JPype1', - version='1.5.0_dev0', + version='1.5.0', description='A Python to Java bridge.', long_description=open('README.rst').read(), license='License :: OSI Approved :: Apache Software License', From 80485d8b6dcd0e1d3021b3b08b6a118317b88b1a Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 17:14:06 -0800 Subject: [PATCH 108/128] Trying to fix build --- .azure/scripts/osx-python.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/scripts/osx-python.sh b/.azure/scripts/osx-python.sh index 292ce31c2..743284bc1 100755 --- a/.azure/scripts/osx-python.sh +++ b/.azure/scripts/osx-python.sh @@ -35,7 +35,7 @@ curl $URL > $INSTALLER_NAME sudo installer -pkg $INSTALLER_NAME -target / -sudo rm /usr/local/bin/python +sudo rm -f /usr/local/bin/python sudo ln -s /usr/local/bin/python$PYTHON_VERSION /usr/local/bin/python which python From dad8cbec2e8ffd1e6b28b0e41e7600d21c428e33 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 10 Dec 2023 17:25:17 -0800 Subject: [PATCH 109/128] Update dists --- .azure/release.yml | 5 +++++ .azure/scripts/osx-python.sh | 7 +++++-- doc/CHANGELOG.rst | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.azure/release.yml b/.azure/release.yml index 6c83ec4c9..2d3b4f014 100644 --- a/.azure/release.yml +++ b/.azure/release.yml @@ -71,6 +71,9 @@ stages: Python311: python.version: '3.11' python.architecture: 'x64' + Python312: + python.version: '3.12' + python.architecture: 'x64' pool: vmImage: "windows-2019" steps: @@ -101,6 +104,8 @@ stages: python.version: '3.10' Python311: python.version: '3.11' + Python312: + python.version: '3.12' pool: vmImage: "macos-11" steps: diff --git a/.azure/scripts/osx-python.sh b/.azure/scripts/osx-python.sh index 743284bc1..43f251559 100755 --- a/.azure/scripts/osx-python.sh +++ b/.azure/scripts/osx-python.sh @@ -16,13 +16,16 @@ case $PYTHON_VERSION in INSTALLER_NAME=python-$FULL_VERSION-macosx10.9.pkg ;; 3.10) - FULL_VERSION=3.10.4 + FULL_VERSION=3.10.11 INSTALLER_NAME=python-$FULL_VERSION-macos11.pkg ;; 3.11) - FULL_VERSION=3.11.0 + FULL_VERSION=3.11.7 INSTALLER_NAME=python-$FULL_VERSION-macos11.pkg ;; +3.12) + FULL_VERSION=3.12.0 + INSTALLER_NAME=python-$FULL_VERSION-macos11.pkg esac URL=https://www.python.org/ftp/python/$FULL_VERSION/$INSTALLER_NAME diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 52df3ca75..ef9b51982 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -4,8 +4,9 @@ Changelog This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards. Latest Changes: -- **1.5.0 - 2023-12-10** -- **1.5.0_dev0 - 2023-04-03** +- **1.5.0 - 2023-04-03** + + - Support for Python 3.12 - Switched ``__eq__`` and ``__ne__`` operator to use ``equals`` rather than ``compareTo`` for comparable objects to avoid exception when comparing From ae01064fe982b027a8fa84a22eb7f743c3cafe15 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Fri, 15 Dec 2023 12:23:54 -0800 Subject: [PATCH 110/128] Update the image --- .azure/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure/release.yml b/.azure/release.yml index 2d3b4f014..276446d2c 100644 --- a/.azure/release.yml +++ b/.azure/release.yml @@ -37,12 +37,12 @@ stages: # python.architecture: aarch64 64Bit: arch: x86_64 - plat: manylinux2010_x86_64 + plat: manylinux2014_x86_64 image: quay.io/pypa/manylinux2010_x86_64 python.architecture: x64 32Bit: arch: i686 - plat: manylinux2010_i686 + plat: manylinux2014_i686 image: quay.io/pypa/manylinux2010_i686 python.architecture: x86 pool: From 27b607da779031d7f898146df0289a447b8f515d Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Fri, 15 Dec 2023 12:29:55 -0800 Subject: [PATCH 111/128] Update versions --- .azure/build.yml | 6 ------ .azure/release.yml | 5 ----- doc/release.rst | 5 +++++ 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index a4a01b625..ae8f53c4e 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -50,9 +50,6 @@ jobs: dependsOn: Deps strategy: matrix: - linux-3.7: - imageName: "ubuntu-latest" - python.version: '3.7' linux-3.8: imageName: "ubuntu-latest" python.version: '3.8' @@ -68,9 +65,6 @@ jobs: linux-3.12: imageName: "ubuntu-latest" python.version: '3.12' - windows-3.7: - imageName: "windows-2019" - python.version: '3.7' windows-3.8: imageName: "windows-2019" python.version: '3.8' diff --git a/.azure/release.yml b/.azure/release.yml index 276446d2c..ebf1daeff 100644 --- a/.azure/release.yml +++ b/.azure/release.yml @@ -56,9 +56,6 @@ stages: condition: eq(1,1) strategy: matrix: - Python37: - python.version: '3.7' - python.architecture: 'x64' Python38: python.version: '3.8' python.architecture: 'x64' @@ -94,8 +91,6 @@ stages: python.architecture: 'x64' strategy: matrix: - Python37: - python.version: '3.7' Python38: python.version: '3.8' Python39: diff --git a/doc/release.rst b/doc/release.rst index 7d63ad300..be1400525 100644 --- a/doc/release.rst +++ b/doc/release.rst @@ -22,6 +22,11 @@ Full process: ``git checkout release`` - [ ] Make a new branch for the release cycle ``git checkout -b releases/{version}`` +- [ ] Check the .azure scripts to see if they are up to date. + Look on https://devguide.python.org/versions/ to see what versions can be dropped + Check Python versions for Windows + Check Python versions for OSX + Check the manylinux image for Linux - [ ] Merge the current master with the release ``git pull origin master`` - [ ] Start a release From edf15a7ee8b1839c593a6bea80d7bedd14d92830 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Fri, 15 Dec 2023 12:32:44 -0800 Subject: [PATCH 112/128] Change image --- .azure/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure/release.yml b/.azure/release.yml index ebf1daeff..b43d59fda 100644 --- a/.azure/release.yml +++ b/.azure/release.yml @@ -38,12 +38,12 @@ stages: 64Bit: arch: x86_64 plat: manylinux2014_x86_64 - image: quay.io/pypa/manylinux2010_x86_64 + image: quay.io/pypa/manylinux2014_x86_64 python.architecture: x64 32Bit: arch: i686 plat: manylinux2014_i686 - image: quay.io/pypa/manylinux2010_i686 + image: quay.io/pypa/manylinux2014_i686 python.architecture: x86 pool: vmImage: "ubuntu-latest" From 725a4268c32a69c412a449b0b2bba979893aeac0 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Fri, 15 Dec 2023 13:12:04 -0800 Subject: [PATCH 113/128] =?UTF-8?q?Bump=20version:=201.5.0=20=E2=86=92=201?= =?UTF-8?q?.5.1=5Fdev0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- doc/CHANGELOG.rst | 1 + jpype/__init__.py | 2 +- native/java/org/jpype/JPypeContext.java | 2 +- native/python/pyjp_module.cpp | 2 +- setup.py | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 3d5870b0e..456d45728 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.5.0 +current_version = 1.5.1_dev0 commit = True tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\_(?P[a-z]+)(?P\d+))? diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index ef9b51982..e448dadb3 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -4,6 +4,7 @@ Changelog This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards. Latest Changes: +- **1.5.1_dev0 - 2023-12-15** - **1.5.0 - 2023-04-03** - Support for Python 3.12 diff --git a/jpype/__init__.py b/jpype/__init__.py index 7bf5c016a..c17f43065 100644 --- a/jpype/__init__.py +++ b/jpype/__init__.py @@ -52,7 +52,7 @@ __all__.extend(_jcustomizer.__all__) # type: ignore[name-defined] __all__.extend(_gui.__all__) # type: ignore[name-defined] -__version__ = "1.5.0" +__version__ = "1.5.1_dev0" __version_info__ = __version__.split('.') diff --git a/native/java/org/jpype/JPypeContext.java b/native/java/org/jpype/JPypeContext.java index 8470c2bc4..708e81b62 100644 --- a/native/java/org/jpype/JPypeContext.java +++ b/native/java/org/jpype/JPypeContext.java @@ -73,7 +73,7 @@ public class JPypeContext { - public final String VERSION = "1.5.0"; + public final String VERSION = "1.5.1_dev0"; private static JPypeContext INSTANCE = new JPypeContext(); // This is the C++ portion of the context. diff --git a/native/python/pyjp_module.cpp b/native/python/pyjp_module.cpp index 0bd9d86c3..a2110efea 100644 --- a/native/python/pyjp_module.cpp +++ b/native/python/pyjp_module.cpp @@ -729,7 +729,7 @@ PyMODINIT_FUNC PyInit__jpype() // PyJPModule = module; Py_INCREF(module); PyJPModule = module; - PyModule_AddStringConstant(module, "__version__", "1.5.0"); + PyModule_AddStringConstant(module, "__version__", "1.5.1_dev0"); // Our module will be used for PyFrame object and it is a requirement that // we have a builtins in our dictionary. diff --git a/setup.py b/setup.py index f35d8f937..7aa052c3c 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ setup( name='JPype1', - version='1.5.0', + version='1.5.1_dev0', description='A Python to Java bridge.', long_description=open('README.rst').read(), license='License :: OSI Approved :: Apache Software License', From 288acd2b1598461b1f2c6136502ba62762a72db4 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 2 Feb 2024 17:38:19 +0100 Subject: [PATCH 114/128] Minor typos in the user guide --- doc/userguide.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/userguide.rst b/doc/userguide.rst index bd7874158..385e23607 100644 --- a/doc/userguide.rst +++ b/doc/userguide.rst @@ -166,7 +166,7 @@ you can use the casting operators. print(type(d)) # prints double[] Great. Now you just need to figure out how to convert from a Java array into -our something our visualization code can deal with. As nothing indicates that +something our visualization code can deal with. As nothing indicates that you need to convert the array, you just copy out of the visualization tool example and watch what happens. @@ -189,7 +189,7 @@ Laboratory. (For the purpose of this exercise we will ignore the fact that Hawkins was shut down in 1984 and Java was created in 1995). You have the test subject strapped in and you just need to start the experiment. So you pull up Jupyter notebook your boss gave you and run through the cells. You need to -added some heart wave monitor to the list of graphed results. +add some heart wave monitor to the list of graphed results. The relevant section of the API for the Experiment appears to be @@ -268,7 +268,7 @@ in a window. Job well done, so you set the runtime back to one hour. Looks like you still have time to make the intern woodlands hike and forest picnic. Though you wonder if maybe next year you should sign up for another laboratory. Maybe next year, you will try to sign up for those orbital lasers the President -was talking about in the March. That sounds like real fun. +was talking about back in March. That sounds like real fun. (This advanced demonstration utilized the concept of Proxies_ and `Code completion`_) @@ -330,7 +330,7 @@ in Python. However, the Java Virtual Machine (JVM) is used for many popular languages such a Kotlin and Scala. As such JPype can be used for any language which used the JVM. -That said each language has its own special properties that tend to be +That said, each language has its own special properties that tend to be represented in different ways. If you would like JPype fully to operate on your particular language the following is required. @@ -382,7 +382,7 @@ costs to share data structures between Java and Python and potentially much higher level of integration. Noted downsides of Jython are that it has lagged well behind the state of the art in Python; it has a limited selection of modules that can be used; and the Python object thrashing is not particularly -well fit in Java virtual machine leading to some known performance issues. +well suited for the Java virtual machine, leading to some known performance issues. `Py4J `_ --------------------------- From 583a3041194d6d73184f94506cac847d98d5a604 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Tue, 2 May 2023 15:31:27 +0200 Subject: [PATCH 115/128] Make use of pyproject.toml for static project metadata --- pyproject.toml | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- setup.py | 44 ++++----------------------------------- 2 files changed, 59 insertions(+), 41 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bc88e6a35..6d094ae71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,58 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + + +[project] +name = "JPype1" +version = '1.5.0.dev0' +authors = [ + {name = "Steve Menard", email = "devilwolf@users.sourceforge.net"}, +] +maintainers = [ + {name = "Luis Nell", email = "cooperate@originell.org"}, +] +description = "A Python to Java bridge" +readme = "README.rst" +requires-python = ">=3.7" +license = {text = "License :: OSI Approved :: Apache Software License"} +classifiers = [ + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Topic :: Software Development', + 'Topic :: Scientific/Engineering', +] +dependencies = [ + 'packaging', + 'typing_extensions ; python_version< "3.8"', +] + + +[project.optional-dependencies] + +docs = [ + 'readthedocs-sphinx-ext', + 'sphinx', + 'sphinx-rtd-theme', +] +tests = [ + "pytest", +] + + +[project.entry-points.pyinstaller40] +"hook-dirs" = "jpype._pyinstaller.entry_points:get_hook_dirs" +"tests" = "jpype._pyinstaller.entry_points:get_PyInstaller_tests" + + +[project.urls] +homepage = "https://github.com/jpype-project/jpype" + + [[tool.mypy.overrides]] module = [ "_jpype", @@ -9,4 +64,3 @@ module = [ "jedi.access", ] ignore_missing_imports = true - diff --git a/setup.py b/setup.py index 7aa052c3c..a95d36b0c 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,8 @@ from setuptools import Extension from setuptools import setup +# Add our setupext package to the path, and import it. +sys.path.append(str(Path(__file__).parent)) import setupext if '--android' in sys.argv: @@ -48,48 +50,17 @@ setup( - name='JPype1', - version='1.5.1_dev0', - description='A Python to Java bridge.', - long_description=open('README.rst').read(), - license='License :: OSI Approved :: Apache Software License', - author='Steve Menard', - author_email='devilwolf@users.sourceforge.net', - maintainer='Luis Nell', - maintainer_email='cooperate@originell.org', - python_requires=">=3.7", - url='https://github.com/jpype-project/jpype', + # Non-standard, and extension behaviour. See also: + # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration platforms=[ 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Operating System :: Unix', 'Operating System :: MacOS', ], - classifiers=[ - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Topic :: Software Development', - 'Topic :: Scientific/Engineering', - ], packages=['jpype', 'jpype._pyinstaller'], package_dir={'jpype': 'jpype', }, package_data={'jpype': ['*.pyi']}, - install_requires=['typing_extensions ; python_version< "3.8"', - 'packaging'], - tests_require=['pytest'], - extras_require={ - 'tests': [ - 'pytest', - ], - 'docs': [ - 'readthedocs-sphinx-ext', - 'sphinx', - 'sphinx-rtd-theme', - ], - }, cmdclass={ 'build_ext': setupext.build_ext.BuildExtCommand, 'test_java': setupext.test_java.TestJavaCommand, @@ -98,11 +69,4 @@ }, zip_safe=False, ext_modules=[jpypeJar, jpypeLib, ], - distclass=setupext.dist.Distribution, - entry_points={ - 'pyinstaller40': [ - 'hook-dirs = jpype._pyinstaller.entry_points:get_hook_dirs', - 'tests = jpype._pyinstaller.entry_points:get_PyInstaller_tests', - ], - }, ) From 3d1e9512262e15f2d8f52a86b4d0d8208db4c3f8 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Wed, 3 May 2023 17:07:37 +0200 Subject: [PATCH 116/128] Move fully to the modern packaging stack, and avoid setting the deprecated global-options --- .azure/scripts/coverage.yml | 8 +++---- .azure/scripts/debug.yml | 3 +-- .azure/scripts/sdist.yml | 4 ++-- .azure/scripts/tracing.yml | 2 +- doc/CHANGELOG.rst | 10 +++++++++ doc/develguide.rst | 10 ++++++++- doc/install.rst | 23 ++++++++++++-------- setup.py | 10 ++++++--- setupext/__init__.py | 3 +-- setupext/build_ext.py | 34 +++++++++++++++--------------- setupext/{dist.py => develop.py} | 22 ++++++++++++------- setupext/platform.py | 36 +++++++++----------------------- setupext/test_java.py | 1 - setupext/utils.py | 34 ------------------------------ 14 files changed, 90 insertions(+), 110 deletions(-) rename setupext/{dist.py => develop.py} (62%) delete mode 100644 setupext/utils.py diff --git a/.azure/scripts/coverage.yml b/.azure/scripts/coverage.yml index 0e47ce961..43bb89bce 100644 --- a/.azure/scripts/coverage.yml +++ b/.azure/scripts/coverage.yml @@ -10,13 +10,13 @@ steps: - script: | python setup.py test_java - pip install gcovr pytest-cov jedi - pip install -r test-requirements.txt - pip install numpy typing_extensions + pip install -U pip + pip install gcovr pytest-cov -r test-requirements.txt + pip install numpy displayName: 'Install requirements' - script: | - python setup.py --enable-coverage --enable-build-jar build_ext --inplace + pip install -e .[tests] --install-option="--enable-coverage" --install-option="--enable-build-jar" displayName: 'Build' - script: | diff --git a/.azure/scripts/debug.yml b/.azure/scripts/debug.yml index a06f2cd06..ebbdba021 100644 --- a/.azure/scripts/debug.yml +++ b/.azure/scripts/debug.yml @@ -7,8 +7,7 @@ steps: - script: | sudo apt install gdb - python setup.py sdist - pip install dist/* + pip install ./ # --install-option="--enable-tracing" displayName: 'Build module' - script: python -c "import jpype" diff --git a/.azure/scripts/sdist.yml b/.azure/scripts/sdist.yml index e00785093..ecf1fbe37 100644 --- a/.azure/scripts/sdist.yml +++ b/.azure/scripts/sdist.yml @@ -3,8 +3,8 @@ steps: inputs: versionSpec: '3.8' - script: | - python -m pip install setuptools - python setup.py sdist + python -m pip install build + python -m build ./ --sdist displayName: Build sdist - task: PublishPipelineArtifact@0 inputs: diff --git a/.azure/scripts/tracing.yml b/.azure/scripts/tracing.yml index 82f471c2b..d278ca1db 100644 --- a/.azure/scripts/tracing.yml +++ b/.azure/scripts/tracing.yml @@ -4,6 +4,6 @@ steps: inputs: versionSpec: '3.8' - script: | - python setup.py --enable-tracing --enable-build-jar build_ext --inplace + pip install -e . --install-option="--enable-coverage" --install-option="--enable-build-jar" displayName: 'Build' diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index e448dadb3..1815bc107 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -4,7 +4,15 @@ Changelog This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards. Latest Changes: + - **1.5.1_dev0 - 2023-12-15** + - Use PEP-518 and PEP-660 configuration for the package, allowing editable and + configurable builds using modern Python packaging tooling. + Where before ``python setup.py --enable-tracing develop``, now can be done with + ``pip install --editable ./ --install-option="--enable-tracing"``. + The old setup.py usage remains, but is discouraged, and the arguments are now passed + after the command (previously they were specified before). + - **1.5.0 - 2023-04-03** - Support for Python 3.12 @@ -18,6 +26,8 @@ Latest Changes: - Java exceptions that occur in inequality comparisons now map to Python TypeError. +- **1.4.2_dev0 - 2022-10-26** + - Fixed crash when calling subscript on JArray. - Fixed direct byte buffers not reporting nbytes correctly when cast to diff --git a/doc/develguide.rst b/doc/develguide.rst index 7537ac6ca..01aec6de6 100644 --- a/doc/develguide.rst +++ b/doc/develguide.rst @@ -943,7 +943,7 @@ must be enabled with a compiler switch to activate. To active the logger, touch one of the cpp files in the native directory to mark the build as dirty, then compile the ``jpype`` module with: :: - python setup.py --enable-tracing develop + pip install -e . --install-option="--enable-tracing" Once built run a short test program that demonstrates the problem and capture the output of the terminal to a file. This should allow the developer to isolate @@ -959,6 +959,14 @@ To use the Python tracing, start Python with... :: python -m trace --trace myscript.py +Coverage +-------- +Some of the tests require additional instrumentation to run, this can be enabled +with the ``enable-coverage`` option:: + + pip install -e . --install-option="--enable-coverage" + + Debugging issues ---------------- diff --git a/doc/install.rst b/doc/install.rst index e5453dce8..6e1ef71b1 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -83,27 +83,32 @@ from `PyPi `__. **2. Build the source with desired options** -Compile JPype using the included ``setup.py`` script: :: +Compile JPype using the `build ` module (this will produce a wheel): :: - python setup.py build + python -m build /path/to/source -The setup script recognizes several arguments. +A number of additional argument may be provided. --enable-build-jar Force setup to recreate the jar from scratch. --enable-tracing Build a verison of JPype with full logging to the console. This can be used to diagnose tricky JNI issues. +For example:: + + python -m build /path/to/source -C--global-option=build_ext -C--global-option="--enable-tracing" + After building, JPype can be tested using the test bench. The test bench requires JDK to build. -**3. Test JPype with (optional):** :: +**3. Install the built wheel with:** :: - python setup.py test + pip install /path/to/wheel -**4. Install JPype with:** :: +**4. Test JPype with (optional):** :: + + python setup.py test - python setup.py install If it fails... @@ -116,7 +121,7 @@ happens, preform the following steps: 1. Identify the location of your systems JDK installation and explicitly passing it to setup.py. :: - JAVA_HOME=/usr/lib/java/jdk1.8.0/ python setup.py install + JAVA_HOME=/usr/lib/java/jdk1.8.0/ python -m build . 2. If that setup.py still fails please create an Issue `on github `__ and @@ -138,7 +143,7 @@ Debian/Ubuntu Debian/Ubuntu users will have to install ``g++`` and ``python-dev``. Use: - sudo apt-get install g++ python-dev python3-dev + sudo apt-get install g++ python3-dev Windows ::::::: diff --git a/setup.py b/setup.py index a95d36b0c..9f68e86c4 100644 --- a/setup.py +++ b/setup.py @@ -38,9 +38,12 @@ include_dirs=[Path('native', 'common', 'include'), Path('native', 'python', 'include'), Path('native', 'embedded', 'include')], - sources=sorted(map(str, list(Path('native', 'common').glob('*.cpp')) + - list(Path('native', 'python').glob('*.cpp')) + - list(Path('native', 'embedded').glob('*.cpp')))), platform=platform, + sources=sorted( + list(Path('native', 'common').glob('*.cpp')) + + list(Path('native', 'python').glob('*.cpp')) + + list(Path('native', 'embedded').glob('*.cpp')) + ), + platform=platform, )) jpypeJar = Extension(name="org.jpype", sources=sorted(map(str, Path("native", "java").glob("**/*.java"))), @@ -63,6 +66,7 @@ package_data={'jpype': ['*.pyi']}, cmdclass={ 'build_ext': setupext.build_ext.BuildExtCommand, + 'develop': setupext.develop.Develop, 'test_java': setupext.test_java.TestJavaCommand, 'sdist': setupext.sdist.BuildSourceDistribution, 'test': setupext.pytester.PyTest, diff --git a/setupext/__init__.py b/setupext/__init__.py index 39e85b481..d4f70098f 100644 --- a/setupext/__init__.py +++ b/setupext/__init__.py @@ -16,10 +16,9 @@ # # ***************************************************************************** -from . import utils -from . import dist from . import platform from . import build_ext +from . import develop from . import test_java from . import sdist from . import pytester diff --git a/setupext/build_ext.py b/setupext/build_ext.py index 7d42e9960..80514bb93 100644 --- a/setupext/build_ext.py +++ b/setupext/build_ext.py @@ -16,6 +16,7 @@ # See NOTICE file for details. # # ***************************************************************************** + import distutils.cmd import distutils.log import glob @@ -43,7 +44,7 @@ class FeatureNotice(Warning): """ indicate notices about features """ -class Makefile(object): +class Makefile: compiler_type = "unix" def __init__(self, actual): @@ -172,6 +173,10 @@ class BuildExtCommand(build_ext): """ user_options = build_ext.user_options + [ + ('enable-build-jar', None, 'Build the java jar portion'), + ('enable-tracing', None, 'Set for tracing for debugging'), + ('enable-coverage', None, 'Instrument c++ code for code coverage measuring'), + ('android', None, 'configure for android'), ('makefile', None, 'Build a makefile for extensions'), ('jar', None, 'Build the jar only'), @@ -179,6 +184,10 @@ class BuildExtCommand(build_ext): def initialize_options(self, *args): """omit -Wstrict-prototypes from CFLAGS since its only valid for C code.""" + self.enable_tracing = False + self.enable_build_jar = False + self.enable_coverage = False + self.android = False self.makefile = False self.jar = False @@ -195,8 +204,7 @@ def initialize_options(self, *args): continue args = v.split() - for r in remove_args: - args = list(filter(r.__ne__, args)) + args = [arg for arg in args if arg not in remove_args] cfg_vars[k] = " ".join(args) super().initialize_options() @@ -205,12 +213,12 @@ def _set_cflags(self): # set compiler flags c = self.compiler.compiler_type jpypeLib = [i for i in self.extensions if i.name == '_jpype'][0] - if c == 'unix' and self.distribution.enable_coverage: + if c == 'unix' and self.enable_coverage: jpypeLib.extra_compile_args.extend( ['-ggdb', '--coverage', '-ftest-coverage']) jpypeLib.extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib.extra_compile_args] jpypeLib.extra_link_args.extend(['--coverage']) - if c == 'unix' and self.distribution.enable_tracing: + if c == 'unix' and self.enable_tracing: jpypeLib.extra_compile_args = ['-O0' if x == '-O2' else x for x in jpypeLib.extra_compile_args] def build_extensions(self): @@ -219,16 +227,12 @@ def build_extensions(self): self.force = True jpypeLib = [i for i in self.extensions if i.name == '_jpype'][0] - tracing = self.distribution.enable_tracing self._set_cflags() - if tracing: + if self.enable_tracing: jpypeLib.define_macros.append(('JP_TRACING_ENABLE', 1)) - coverage = self.distribution.enable_coverage - if coverage: + if self.enable_coverage: jpypeLib.define_macros.append(('JP_INSTRUMENTATION', 1)) - # has to be last call - print("Call build extensions") super().build_extensions() def build_extension(self, ext): @@ -266,7 +270,7 @@ def copy_extensions_to_source(self): def build_java_ext(self, ext): """Run command.""" - java = self.distribution.enable_build_jar + java = self.enable_build_jar javac = "javac" try: @@ -296,8 +300,6 @@ def build_java_ext(self, ext): distutils.log.info( "Jar cache is missing, using --enable-build-jar to recreate it.") - coverage = self.distribution.enable_coverage - target_version = "1.8" # build the jar try: @@ -309,9 +311,7 @@ def build_java_ext(self, ext): cmd1 = shlex.split('%s -cp "%s" -d "%s" -g:none -source %s -target %s -encoding UTF-8' % (javac, classpath, build_dir, target_version, target_version)) cmd1.extend(ext.sources) - debug = "-g:none" - if coverage: - debug = "-g:lines,vars,source" + os.makedirs("build/classes", exist_ok=True) self.announce(" %s" % " ".join(cmd1), level=distutils.log.INFO) subprocess.check_call(cmd1) diff --git a/setupext/dist.py b/setupext/develop.py similarity index 62% rename from setupext/dist.py rename to setupext/develop.py index 0c48f18c3..91f34c7c6 100644 --- a/setupext/dist.py +++ b/setupext/develop.py @@ -16,21 +16,27 @@ # See NOTICE file for details. # # ***************************************************************************** -from setuptools.dist import Distribution as _Distribution -# Add a new global option to the setup.py script. +from setuptools.command.develop import develop as develop_cmd -class Distribution(_Distribution): - global_options = [ +class Develop(develop_cmd): + user_options = develop_cmd.user_options + [ ('enable-build-jar', None, 'Build the java jar portion'), ('enable-tracing', None, 'Set for tracing for debugging'), ('enable-coverage', None, 'Instrument c++ code for code coverage measuring'), + ] - ] + _Distribution.global_options - - def parse_command_line(self): + def initialize_options(self, *args): self.enable_tracing = False self.enable_build_jar = False self.enable_coverage = False - return _Distribution.parse_command_line(self) + super().initialize_options() + + def reinitialize_command(self, command, reinit_subcommands=0, **kw): + cmd = super().reinitialize_command(command, reinit_subcommands=reinit_subcommands, **kw) + build_ext_command = self.distribution.get_command_obj("build_ext") + build_ext_command.enable_tracing = self.enable_tracing + build_ext_command.enable_build_jar = self.enable_build_jar + build_ext_command.enable_coverage = self.enable_coverage + return cmd \ No newline at end of file diff --git a/setupext/platform.py b/setupext/platform.py index 28ebd85ec..d633f1908 100644 --- a/setupext/platform.py +++ b/setupext/platform.py @@ -18,22 +18,20 @@ # ***************************************************************************** import setupext import os +from pathlib import Path import sys import sysconfig +import typing import distutils.log -# This handles all of the work to make our platform specific extension options. +# This handles all the work to make our platform specific extension options. -def Platform(include_dirs=None, sources=None, platform=sys.platform): - if include_dirs is None: - include_dirs = [] - if sources is None: - sources = [] - +def Platform(*, include_dirs: typing.Sequence[Path], sources: typing.Sequence[Path], platform: str): + sources = [str(pth) for pth in sources] platform_specific = { 'include_dirs': include_dirs, - 'sources': setupext.utils.find_sources(sources), + 'sources': sources, } fallback_jni = os.path.join('native', 'jni_include') @@ -120,27 +118,13 @@ def Platform(include_dirs=None, sources=None, platform=sys.platform): distutils.log.warn("Your platform '%s' is not being handled explicitly." " It may work or not!", platform) -# This code is used to include python library in the build when starting Python from -# within Java. It will be used in the future, but is not currently required. -# if static and sysconfig.get_config_var('BLDLIBRARY') is not None: -# platform_specific['extra_link_args'].append(sysconfig.get_config_var('BLDLIBRARY')) + # This code is used to include python library in the build when starting Python from + # within Java. It will be used in the future, but is not currently required. + # if static and sysconfig.get_config_var('BLDLIBRARY') is not None: + # platform_specific['extra_link_args'].append(sysconfig.get_config_var('BLDLIBRARY')) if found_jni: distutils.log.info("Add JNI directory %s" % os.path.join(java_home, 'include', jni_md_platform)) platform_specific['include_dirs'] += \ [os.path.join(java_home, 'include', jni_md_platform)] return platform_specific - - -# include this stolen from FindJNI.cmake -""" -FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h -${JAVA_INCLUDE_PATH} -${JAVA_INCLUDE_PATH}/win32 -${JAVA_INCLUDE_PATH}/linux -${JAVA_INCLUDE_PATH}/freebsd -${JAVA_INCLUDE_PATH}/openbsd -${JAVA_INCLUDE_PATH}/solaris -${JAVA_INCLUDE_PATH}/hp-ux -${JAVA_INCLUDE_PATH}/alpha -)""" diff --git a/setupext/test_java.py b/setupext/test_java.py index 5e8383a36..ea6d21eab 100644 --- a/setupext/test_java.py +++ b/setupext/test_java.py @@ -16,7 +16,6 @@ # See NOTICE file for details. # # ***************************************************************************** -import sys import os import subprocess import distutils.cmd diff --git a/setupext/utils.py b/setupext/utils.py deleted file mode 100644 index 48eda99db..000000000 --- a/setupext/utils.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# ***************************************************************************** -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# See NOTICE file for details. -# -# ***************************************************************************** -import os -import codecs -import glob - - -def read_utf8(path, *parts): - filename = os.path.join(os.path.dirname(path), *parts) - return codecs.open(filename, encoding='utf-8').read() - - -def find_sources(roots=[]): - cpp_files = [] - for root in roots: - for filename in glob.iglob(str(root)): - cpp_files.append(filename) - return cpp_files From 3de98dcb49308e7efc40185b477025dc7fcd87e0 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Wed, 3 May 2023 21:51:09 +0200 Subject: [PATCH 117/128] Add edtiable_wheel support for full pip install --editable support --- .azure/scripts/coverage.yml | 1 - pyproject.toml | 4 +++- setup.py | 2 ++ setupext/__init__.py | 1 + setupext/editable_wheel.py | 42 +++++++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 setupext/editable_wheel.py diff --git a/.azure/scripts/coverage.yml b/.azure/scripts/coverage.yml index 43bb89bce..2c676e3b5 100644 --- a/.azure/scripts/coverage.yml +++ b/.azure/scripts/coverage.yml @@ -10,7 +10,6 @@ steps: - script: | python setup.py test_java - pip install -U pip pip install gcovr pytest-cov -r test-requirements.txt pip install numpy displayName: 'Install requirements' diff --git a/pyproject.toml b/pyproject.toml index 6d094ae71..ef1947fc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,7 @@ [build-system] -requires = ["setuptools"] +requires = [ + "setuptools>=65.*", # For editable_wheel command. +] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 9f68e86c4..c8fcec027 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,8 @@ cmdclass={ 'build_ext': setupext.build_ext.BuildExtCommand, 'develop': setupext.develop.Develop, + # The command for pip --editable. + 'editable_wheel': setupext.editable_wheel.EditableWheel, 'test_java': setupext.test_java.TestJavaCommand, 'sdist': setupext.sdist.BuildSourceDistribution, 'test': setupext.pytester.PyTest, diff --git a/setupext/__init__.py b/setupext/__init__.py index d4f70098f..ae12537f4 100644 --- a/setupext/__init__.py +++ b/setupext/__init__.py @@ -19,6 +19,7 @@ from . import platform from . import build_ext from . import develop +from . import editable_wheel from . import test_java from . import sdist from . import pytester diff --git a/setupext/editable_wheel.py b/setupext/editable_wheel.py new file mode 100644 index 000000000..a3329fbe4 --- /dev/null +++ b/setupext/editable_wheel.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# ***************************************************************************** +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# See NOTICE file for details. +# +# ***************************************************************************** + +from setuptools.command.editable_wheel import editable_wheel as editable_wheel_cmd + + +class EditableWheel(editable_wheel_cmd): + user_options = editable_wheel_cmd.user_options + [ + ('enable-build-jar', None, 'Build the java jar portion'), + ('enable-tracing', None, 'Set for tracing for debugging'), + ('enable-coverage', None, 'Instrument c++ code for code coverage measuring'), + ] + + def initialize_options(self, *args): + self.enable_tracing = False + self.enable_build_jar = False + self.enable_coverage = False + super().initialize_options() + + def reinitialize_command(self, command, reinit_subcommands=0, **kw): + cmd = super().reinitialize_command(command, reinit_subcommands=reinit_subcommands, **kw) + build_ext_command = self.distribution.get_command_obj("build_ext") + build_ext_command.enable_tracing = self.enable_tracing + build_ext_command.enable_build_jar = self.enable_build_jar + build_ext_command.enable_coverage = self.enable_coverage + return cmd From b9472a388980eaedcc9f060b99abc3365e7f4421 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Wed, 3 May 2023 22:02:36 +0200 Subject: [PATCH 118/128] Roll back all the editable install behaviour - it is not necessary just yet. --- .azure/scripts/coverage.yml | 2 +- .azure/scripts/debug.yml | 2 +- .azure/scripts/tracing.yml | 2 +- doc/CHANGELOG.rst | 7 ++++++- doc/develguide.rst | 4 ++-- pyproject.toml | 2 +- setup.py | 5 ++--- setupext/__init__.py | 1 - setupext/editable_wheel.py | 42 ------------------------------------- 9 files changed, 14 insertions(+), 53 deletions(-) delete mode 100644 setupext/editable_wheel.py diff --git a/.azure/scripts/coverage.yml b/.azure/scripts/coverage.yml index 2c676e3b5..77c8ae1d8 100644 --- a/.azure/scripts/coverage.yml +++ b/.azure/scripts/coverage.yml @@ -15,7 +15,7 @@ steps: displayName: 'Install requirements' - script: | - pip install -e .[tests] --install-option="--enable-coverage" --install-option="--enable-build-jar" + python setup.py develop --enable-coverage --enable-build-jar displayName: 'Build' - script: | diff --git a/.azure/scripts/debug.yml b/.azure/scripts/debug.yml index ebbdba021..4f8d9ca08 100644 --- a/.azure/scripts/debug.yml +++ b/.azure/scripts/debug.yml @@ -7,7 +7,7 @@ steps: - script: | sudo apt install gdb - pip install ./ # --install-option="--enable-tracing" + pip install ./ displayName: 'Build module' - script: python -c "import jpype" diff --git a/.azure/scripts/tracing.yml b/.azure/scripts/tracing.yml index d278ca1db..9f6fc0c3d 100644 --- a/.azure/scripts/tracing.yml +++ b/.azure/scripts/tracing.yml @@ -4,6 +4,6 @@ steps: inputs: versionSpec: '3.8' - script: | - pip install -e . --install-option="--enable-coverage" --install-option="--enable-build-jar" + python setup.py develop --enable-tracing --enable-build-jar displayName: 'Build' diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 1815bc107..74451c308 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -9,10 +9,15 @@ Latest Changes: - Use PEP-518 and PEP-660 configuration for the package, allowing editable and configurable builds using modern Python packaging tooling. Where before ``python setup.py --enable-tracing develop``, now can be done with - ``pip install --editable ./ --install-option="--enable-tracing"``. + ``pip install --editable ./ --config-setting="--install-option=--enable-tracing"``. The old setup.py usage remains, but is discouraged, and the arguments are now passed after the command (previously they were specified before). + - Use PEP-518 configuration for the package, allowing + configurable builds using more up-to-date Python packaging tooling. + For editable installs, ``python setup.py --enable-tracing develop`` + must now be done with ``python setup.py develop --enable-tracing``. + - **1.5.0 - 2023-04-03** - Support for Python 3.12 diff --git a/doc/develguide.rst b/doc/develguide.rst index 01aec6de6..7ee92e934 100644 --- a/doc/develguide.rst +++ b/doc/develguide.rst @@ -943,7 +943,7 @@ must be enabled with a compiler switch to activate. To active the logger, touch one of the cpp files in the native directory to mark the build as dirty, then compile the ``jpype`` module with: :: - pip install -e . --install-option="--enable-tracing" + python setup.py develop --enable-tracing Once built run a short test program that demonstrates the problem and capture the output of the terminal to a file. This should allow the developer to isolate @@ -964,7 +964,7 @@ Coverage Some of the tests require additional instrumentation to run, this can be enabled with the ``enable-coverage`` option:: - pip install -e . --install-option="--enable-coverage" + python setup.py develop --enable-coverage Debugging issues diff --git a/pyproject.toml b/pyproject.toml index ef1947fc6..f35392751 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "setuptools>=65.*", # For editable_wheel command. + "setuptools", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index c8fcec027..06f8c2064 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,8 @@ setup( - # Non-standard, and extension behaviour. See also: + # Non-standard, and extension behaviour of setup() - project information + # should be put in pyproject.toml wherever possible. See also: # https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#setuptools-specific-configuration platforms=[ 'Operating System :: Microsoft :: Windows', @@ -67,8 +68,6 @@ cmdclass={ 'build_ext': setupext.build_ext.BuildExtCommand, 'develop': setupext.develop.Develop, - # The command for pip --editable. - 'editable_wheel': setupext.editable_wheel.EditableWheel, 'test_java': setupext.test_java.TestJavaCommand, 'sdist': setupext.sdist.BuildSourceDistribution, 'test': setupext.pytester.PyTest, diff --git a/setupext/__init__.py b/setupext/__init__.py index ae12537f4..d4f70098f 100644 --- a/setupext/__init__.py +++ b/setupext/__init__.py @@ -19,7 +19,6 @@ from . import platform from . import build_ext from . import develop -from . import editable_wheel from . import test_java from . import sdist from . import pytester diff --git a/setupext/editable_wheel.py b/setupext/editable_wheel.py deleted file mode 100644 index a3329fbe4..000000000 --- a/setupext/editable_wheel.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 -*- -# ***************************************************************************** -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# See NOTICE file for details. -# -# ***************************************************************************** - -from setuptools.command.editable_wheel import editable_wheel as editable_wheel_cmd - - -class EditableWheel(editable_wheel_cmd): - user_options = editable_wheel_cmd.user_options + [ - ('enable-build-jar', None, 'Build the java jar portion'), - ('enable-tracing', None, 'Set for tracing for debugging'), - ('enable-coverage', None, 'Instrument c++ code for code coverage measuring'), - ] - - def initialize_options(self, *args): - self.enable_tracing = False - self.enable_build_jar = False - self.enable_coverage = False - super().initialize_options() - - def reinitialize_command(self, command, reinit_subcommands=0, **kw): - cmd = super().reinitialize_command(command, reinit_subcommands=reinit_subcommands, **kw) - build_ext_command = self.distribution.get_command_obj("build_ext") - build_ext_command.enable_tracing = self.enable_tracing - build_ext_command.enable_build_jar = self.enable_build_jar - build_ext_command.enable_coverage = self.enable_coverage - return cmd From bab84f03da6dcd5af6b9263df721e41643533649 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sat, 24 Feb 2024 10:11:30 -0800 Subject: [PATCH 119/128] Change to use wstring for Windows --- native/common/jp_platform.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index ea7b0cd4e..005144b21 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -64,7 +64,13 @@ class Win32PlatformAdapter : public JPPlatformAdapter virtual void loadLibrary(const char* path) override { JP_TRACE_IN("Win32PlatformAdapter::loadLibrary"); - jvmLibrary = LoadLibrary(path); + wchar_t *wpath = Py_DecodeLocale(path, NULL); + if (wpath == NULL) + { + JP_RAISE(PyExc_SystemError, "Unable to get JVM path with locale."); + } + jvmLibrary = LoadLibraryW(wpath); + PyMem_RawFree(wpath); if (jvmLibrary == NULL) { JP_RAISE_OS_ERROR_WINDOWS( GetLastError(), path); From 2c0420edfe1328636e2621f0dd1231a1ea7318d0 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sat, 24 Feb 2024 10:18:10 -0800 Subject: [PATCH 120/128] Fix tabs --- native/common/jp_platform.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/native/common/jp_platform.cpp b/native/common/jp_platform.cpp index 005144b21..1501e1fbf 100644 --- a/native/common/jp_platform.cpp +++ b/native/common/jp_platform.cpp @@ -64,13 +64,13 @@ class Win32PlatformAdapter : public JPPlatformAdapter virtual void loadLibrary(const char* path) override { JP_TRACE_IN("Win32PlatformAdapter::loadLibrary"); - wchar_t *wpath = Py_DecodeLocale(path, NULL); - if (wpath == NULL) - { - JP_RAISE(PyExc_SystemError, "Unable to get JVM path with locale."); - } + wchar_t *wpath = Py_DecodeLocale(path, NULL); + if (wpath == NULL) + { + JP_RAISE(PyExc_SystemError, "Unable to get JVM path with locale."); + } jvmLibrary = LoadLibraryW(wpath); - PyMem_RawFree(wpath); + PyMem_RawFree(wpath); if (jvmLibrary == NULL) { JP_RAISE_OS_ERROR_WINDOWS( GetLastError(), path); From 67a3eab281a5f4e0f1e74c4fd8a76cbbad516467 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Thu, 28 Mar 2024 13:53:40 -0400 Subject: [PATCH 121/128] Fixing typo in userguide.rst --- doc/userguide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/userguide.rst b/doc/userguide.rst index 385e23607..3ab818d4c 100644 --- a/doc/userguide.rst +++ b/doc/userguide.rst @@ -111,7 +111,7 @@ project has suffered a nasty data structure problem in one of the threads. You managed to capture the data structure in a serialized form but if you could just make graph and call a few functions this would be so much easier. But the interactive Java shell that you are using doesn't really have much in the way of -visualization and your don't have time to write a whole graphing applet just to +visualization and you don't have time to write a whole graphing applet just to display this dataset. So poking around on the internet you find that Python has exactly the From 8f5590cb9fab063d75e15fe2ea4f787b5b124659 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 31 Mar 2024 13:02:06 -0700 Subject: [PATCH 122/128] Fix error in 3.12 during Pytest --- doc/CHANGELOG.rst | 1 + native/python/pyjp_object.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 74451c308..5848e7d66 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -6,6 +6,7 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o Latest Changes: - **1.5.1_dev0 - 2023-12-15** + - Fixed uncaught exception while setting traceback causing issues in Python 3.11/3.12. - Use PEP-518 and PEP-660 configuration for the package, allowing editable and configurable builds using modern Python packaging tooling. Where before ``python setup.py --enable-tracing develop``, now can be done with diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index 0de9f9f2c..c059eb376 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -390,7 +390,8 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j { // Attach the frame to first JPPyObject trace = PyTrace_FromJavaException(frame, th, enclosing); - PyException_SetTraceback(exc.get(), trace.get()); + if (trace.get()!=nullptr) + PyException_SetTraceback(exc.get(), trace.get()); // Check for the next in the cause list enclosing = th; From faaaca428dd906a84b259250042e22ff6a6a7df7 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Mon, 1 Apr 2024 17:04:14 -0700 Subject: [PATCH 123/128] Fix second uncaught exception --- native/common/jp_exception.cpp | 3 ++- native/python/pyjp_object.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 10cc9c9ec..a99964c69 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -220,7 +220,8 @@ void JPypeException::convertJavaToPython() PyJPException_normalize(frame, prev, jcause, th); PyException_SetCause(cause.get(), prev.keep()); } - PyException_SetTraceback(cause.get(), trace.get()); + if (trace.get() != nullptr) + PyException_SetTraceback(cause.get(), trace.get()); PyException_SetCause(pyvalue.get(), cause.keep()); } catch (JPypeException& ex) { diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index c059eb376..ae2ffbe0d 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -390,7 +390,7 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j { // Attach the frame to first JPPyObject trace = PyTrace_FromJavaException(frame, th, enclosing); - if (trace.get()!=nullptr) + if (trace.get() != nullptr) PyException_SetTraceback(exc.get(), trace.get()); // Check for the next in the cause list From dcba813681a34584f567821f6d240af6fc9eaf45 Mon Sep 17 00:00:00 2001 From: Ken Dombeck Date: Mon, 3 Jun 2024 10:07:02 -0500 Subject: [PATCH 124/128] Fix misspelling in documentation --- doc/userguide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/userguide.rst b/doc/userguide.rst index 3ab818d4c..abd9b17b8 100644 --- a/doc/userguide.rst +++ b/doc/userguide.rst @@ -8,7 +8,7 @@ JPype User Guide JPype Introduction ****************** JPype is a Python module to provide full access to Java from within Python. -Unlike Jython, JPype does not achive this by re-implementing Python, but +Unlike Jython, JPype does not achieve this by re-implementing Python, but instead by interfacing both virtual machines at the native level. This shared memory based approach achieves good computing performance, while providing the access to the entirety of CPython and Java libraries. From d487b32774805d14249a15fc030aeac148025b67 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 16 Jun 2024 21:47:03 -0700 Subject: [PATCH 125/128] Changes for numpy 2.0 to fix test matrix. --- doc/CHANGELOG.rst | 5 ++ native/common/jp_convert.cpp | 76 ++++++++++++++++++++++++++ test/jpypetest/test_conversionInt.py | 4 +- test/jpypetest/test_conversionLong.py | 4 +- test/jpypetest/test_conversionShort.py | 4 +- test/jpypetest/test_jboolean.py | 4 +- test/jpypetest/test_jbyte.py | 4 +- test/jpypetest/test_jdouble.py | 16 +++++- test/jpypetest/test_jfloat.py | 16 +++++- 9 files changed, 119 insertions(+), 14 deletions(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 5848e7d66..217dd8320 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -19,6 +19,11 @@ Latest Changes: For editable installs, ``python setup.py --enable-tracing develop`` must now be done with ``python setup.py develop --enable-tracing``. + - Update for tests for numpy 2.0. + + - Support of np.float16 conversion with arrays. + + - **1.5.0 - 2023-04-03** - Support for Python 3.12 diff --git a/native/common/jp_convert.cpp b/native/common/jp_convert.cpp index 919417461..5d288e044 100644 --- a/native/common/jp_convert.cpp +++ b/native/common/jp_convert.cpp @@ -14,10 +14,61 @@ See NOTICE file for details. *****************************************************************************/ #include "jpype.h" +#include +#include namespace { +template +class Half +{ +public: + static jvalue convert(void* c) + { + uint16_t i = *(uint16_t*) c; + uint32_t sign = (i&0x8000)>>15; + uint32_t man = (i&0x7C00)>>10; + uint32_t frac = (i&0x03ff); + uint32_t k = sign<<31; + + if (man == 0) + { + // subnormal numbers + if (frac != 0) + { + frac = frac | (frac >> 1); + frac = frac | (frac >> 2); + frac = frac | (frac >> 4); + frac = frac | (frac >> 8); + int zeros = std::bitset<32>(~frac).count(); + man = 127-zeros+7; + man <<= 23; + frac <<= zeros-8; + frac &= 0x7fffff; + k |= man | frac; + } + } + else if (man < 31) + { + // normal numbers + man = man-15+127; + man <<= 23; + frac <<= 13; + k |= man | frac; + } + else + { + // to infinity and beyond! + if (frac == 0) + k |= 0x7f800000; + else + k |= 0x7f800001 | ((frac&0x200)<<12); + } + return func(&k); + } +}; + template class Convert { @@ -385,6 +436,31 @@ jconverter getConverter(const char* from, int itemsize, const char* to) case 'd': return &Convert::toD; } break; + case 'e': + if (reverse) switch (to[0]) + { + case 'z': return &Reverse::toZ>::convert>::call4; + case 'b': return &Reverse::toB>::convert>::call4; + case 'c': return &Reverse::toC>::convert>::call4; + case 's': return &Reverse::toS>::convert>::call4; + case 'i': return &Reverse::toI>::convert>::call4; + case 'j': return &Reverse::toJ>::convert>::call4; + case 'f': return &Reverse::toF>::convert>::call4; + case 'd': return &Reverse::toD>::convert>::call4; + } + else switch (to[0]) + { + case 'z': return &Half::toZ>::convert; + case 'b': return &Half::toB>::convert; + case 'c': return &Half::toC>::convert; + case 's': return &Half::toS>::convert; + case 'i': return &Half::toI>::convert; + case 'j': return &Half::toJ>::convert; + case 'f': return &Half::toF>::convert; + case 'd': return &Half::toD>::convert; + } + break; + case 'n': if (reverse) switch (to[0]) { diff --git a/test/jpypetest/test_conversionInt.py b/test/jpypetest/test_conversionInt.py index bb94ca025..8c9721c51 100644 --- a/test/jpypetest/test_conversionInt.py +++ b/test/jpypetest/test_conversionInt.py @@ -73,10 +73,10 @@ def testIntFromFloat(self): self.Test.callInt(float(2)) @common.unittest.skipUnless(haveNumpy(), "numpy not available") - def testIntFromNPFloat(self): + def testIntFromNPFloat16(self): import numpy as np with self.assertRaises(TypeError): - self.Test.callInt(np.float_(2)) + self.Test.callInt(np.float16(2)) @common.unittest.skipUnless(haveNumpy(), "numpy not available") def testIntFromNPFloat32(self): diff --git a/test/jpypetest/test_conversionLong.py b/test/jpypetest/test_conversionLong.py index ae3f31313..256b4ed0c 100644 --- a/test/jpypetest/test_conversionLong.py +++ b/test/jpypetest/test_conversionLong.py @@ -73,10 +73,10 @@ def testLongFromFloat(self): self.Test.callLong(float(2)) @common.unittest.skipUnless(haveNumpy(), "numpy not available") - def testLongFromNPFloat(self): + def testLongFromNPFloat16(self): import numpy as np with self.assertRaises(TypeError): - self.Test.callLong(np.float_(2)) + self.Test.callLong(np.float16(2)) @common.unittest.skipUnless(haveNumpy(), "numpy not available") def testLongFromNPFloat32(self): diff --git a/test/jpypetest/test_conversionShort.py b/test/jpypetest/test_conversionShort.py index d3fd81ffa..0c3d072c8 100644 --- a/test/jpypetest/test_conversionShort.py +++ b/test/jpypetest/test_conversionShort.py @@ -73,10 +73,10 @@ def testShortFromFloat(self): self.Test.callShort(float(2)) @common.unittest.skipUnless(haveNumpy(), "numpy not available") - def testShortFromNPFloat(self): + def testShortFromNPFloat16(self): import numpy as np with self.assertRaises(TypeError): - self.Test.callShort(np.float_(2)) + self.Test.callShort(np.float16(2)) @common.unittest.skipUnless(haveNumpy(), "numpy not available") def testShortFromNPFloat32(self): diff --git a/test/jpypetest/test_jboolean.py b/test/jpypetest/test_jboolean.py index ed0f6bd99..b27c63fd0 100644 --- a/test/jpypetest/test_jboolean.py +++ b/test/jpypetest/test_jboolean.py @@ -100,10 +100,10 @@ def testBooleanFromFloat(self): self.Test.callBoolean(float(2)) @common.requireNumpy - def testBooleanFromNPFloat(self): + def testBooleanFromNPFloat16(self): import numpy as np with self.assertRaises(TypeError): - self.Test.callBoolean(np.float_(2)) + self.Test.callBoolean(np.float16(2)) @common.requireNumpy def testBooleanFromNPFloat32(self): diff --git a/test/jpypetest/test_jbyte.py b/test/jpypetest/test_jbyte.py index 55bfd4ec8..a4b995c9b 100644 --- a/test/jpypetest/test_jbyte.py +++ b/test/jpypetest/test_jbyte.py @@ -108,10 +108,10 @@ def testByteFromFloat(self): self.fixture.callByte(float(2)) @common.requireNumpy - def testByteFromNPFloat(self): + def testByteFromNPFloat16(self): import numpy as np with self.assertRaises(TypeError): - self.fixture.callByte(np.float_(2)) + self.fixture.callByte(np.float16(2)) @common.requireNumpy def testByteFromNPFloat32(self): diff --git a/test/jpypetest/test_jdouble.py b/test/jpypetest/test_jdouble.py index 09c03351b..cf3b89799 100644 --- a/test/jpypetest/test_jdouble.py +++ b/test/jpypetest/test_jdouble.py @@ -374,8 +374,8 @@ def testArraySetFromNPDouble(self): self.assertElementsAlmostEqual(a, jarr) @common.requireNumpy - def testArrayInitFromNPFloat(self): - a = np.random.random(100).astype(np.float_) + def testArrayInitFromNPFloat16(self): + a = np.random.random(100).astype(np.float16) jarr = JArray(JDouble)(a) self.assertElementsAlmostEqual(a, jarr) @@ -436,3 +436,15 @@ def __len__(self): def testCastBoolean(self): self.assertEqual(JDouble._canConvertToJava(JBoolean(True)), "none") + + @common.requireNumpy + def testNPFloat16(self): + v= [0.000000e+00, 5.960464e-08, 1.788139e-07, 1.788139e-07, 4.172325e-07, 8.940697e-07, 1.847744e-06, 3.755093e-06, 7.569790e-06, 1.519918e-05, 3.045797e-05, 6.097555e-05, 6.103516e-05, 3.332520e-01, 1.000000e+00, 6.550400e+04, np.inf, -np.inf] + a = np.array(v, dtype=np.float16) + jarr = JArray(JDouble)(a) + for v1,v2 in zip(a, jarr): + self.assertEqual(v1,v2) + a = np.array([np.nan], dtype=np.float16) + jarr = JArray(JDouble)(a) + self.assertTrue(np.isnan(jarr[0])) + diff --git a/test/jpypetest/test_jfloat.py b/test/jpypetest/test_jfloat.py index 4fbce3591..eb63fe168 100644 --- a/test/jpypetest/test_jfloat.py +++ b/test/jpypetest/test_jfloat.py @@ -382,8 +382,8 @@ def testArraySetFromNPDouble(self): self.assertElementsAlmostEqual(a, jarr) @common.requireNumpy - def testArrayInitFromNPFloat(self): - a = np.random.random(100).astype(np.float_) + def testArrayInitFromNPFloat16(self): + a = np.random.random(100).astype(np.float16) jarr = JArray(JFloat)(a) self.assertElementsAlmostEqual(a, jarr) @@ -441,3 +441,15 @@ def __len__(self): ja[:] = [1, 2, 3] with self.assertRaisesRegex(ValueError, "mismatch"): ja[:] = a + + @common.requireNumpy + def testNPFloat16(self): + v= [0.000000e+00, 5.960464e-08, 1.788139e-07, 1.788139e-07, 4.172325e-07, 8.940697e-07, 1.847744e-06, 3.755093e-06, 7.569790e-06, 1.519918e-05, 3.045797e-05, 6.097555e-05, 6.103516e-05, 3.332520e-01, 1.000000e+00, 6.550400e+04, np.inf, -np.inf] + a = np.array(v, dtype=np.float16) + jarr = JArray(JFloat)(a) + for v1,v2 in zip(a, jarr): + self.assertEqual(v1,v2) + a = np.array([np.nan], dtype=np.float16) + jarr = JArray(JFloat)(a) + self.assertTrue(np.isnan(jarr[0])) + From f6849c5412d506e10a89e49aad42d13cc70f350c Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 23 Jun 2024 09:21:59 -0700 Subject: [PATCH 126/128] Trying to test tests working --- test/jpypetest/test_buffer.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/test/jpypetest/test_buffer.py b/test/jpypetest/test_buffer.py index 0da865232..3882511df 100644 --- a/test/jpypetest/test_buffer.py +++ b/test/jpypetest/test_buffer.py @@ -315,11 +315,11 @@ def testMemoryByte(self): jtype = jpype.JByte[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -328,11 +328,12 @@ def testMemoryInt(self): jtype = jpype.JInt[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": + print(dtype) jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -341,11 +342,11 @@ def testMemoryShort(self): jtype = jpype.JShort[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -354,11 +355,11 @@ def testMemoryLong(self): jtype = jpype.JLong[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -367,11 +368,11 @@ def testMemoryFloat(self): jtype = jpype.JFloat[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -380,11 +381,11 @@ def testMemoryDouble(self): jtype = jpype.JDouble[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -393,11 +394,11 @@ def testMemoryBoolean(self): jtype = jpype.JBoolean[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "f", "d", "n", "N"): + for dtype in "c?bBhHiIlLqQfdnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) - for dtype in ("s", "p", "P", "e"): + for dtype in "spP": with self.assertRaises(Exception): jtype(mv.cast(dtype)) @@ -406,7 +407,7 @@ def testMemoryChar(self): jtype = jpype.JChar[:] # Simple checks - for dtype in ("c", "?", "b", "B", "h", "H", "i", "I", "l", "L", "q", "Q", "n", "N"): + for dtype in "c?bBhHiIlLqQnN": jtype(mv.cast(dtype)) jtype(mv.cast("@" + dtype)) From 2ef11689f233d366b86d6df7c0393fe42937525f Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Thu, 27 Jun 2024 14:50:11 -0700 Subject: [PATCH 127/128] Fixes #1198 --- native/python/include/pyjp.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/python/include/pyjp.h b/native/python/include/pyjp.h index c9645843d..df6983af3 100755 --- a/native/python/include/pyjp.h +++ b/native/python/include/pyjp.h @@ -178,13 +178,14 @@ JPValue *PyJPValue_getJavaSlot(PyObject* obj); PyObject *PyJPModule_getClass(PyObject* module, PyObject *obj); PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name); int PyJPValue_setattro(PyObject *self, PyObject *name, PyObject *value); -void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls); PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p); #ifdef __cplusplus } #endif +void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls); + // C++ methods JPPyObject PyJPArray_create(JPJavaFrame &frame, PyTypeObject* wrapper, const JPValue& value); JPPyObject PyJPBuffer_create(JPJavaFrame &frame, PyTypeObject *type, const JPValue & value); From 31339e37e61a6a4df224cae98a806cebf948ec4d Mon Sep 17 00:00:00 2001 From: Alexander Rashed Date: Mon, 29 Jul 2024 11:47:35 +0200 Subject: [PATCH 128/128] remove usage of setuptools.command.test --- doc/install.rst | 2 +- setup.cfg | 3 --- setup.py | 1 - setupext/__init__.py | 1 - setupext/pytester.py | 39 --------------------------------------- 5 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 setupext/pytester.py diff --git a/doc/install.rst b/doc/install.rst index 6e1ef71b1..4e1ae14e8 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -107,7 +107,7 @@ bench requires JDK to build. **4. Test JPype with (optional):** :: - python setup.py test + python -m pytest diff --git a/setup.cfg b/setup.cfg index 44c5ddbe5..acc5cf1af 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,3 @@ -[alias] -test=pytest - [tool:pytest] addopts = --verbose testpaths = diff --git a/setup.py b/setup.py index 06f8c2064..83c263f39 100644 --- a/setup.py +++ b/setup.py @@ -70,7 +70,6 @@ 'develop': setupext.develop.Develop, 'test_java': setupext.test_java.TestJavaCommand, 'sdist': setupext.sdist.BuildSourceDistribution, - 'test': setupext.pytester.PyTest, }, zip_safe=False, ext_modules=[jpypeJar, jpypeLib, ], diff --git a/setupext/__init__.py b/setupext/__init__.py index d4f70098f..f47d0bc5a 100644 --- a/setupext/__init__.py +++ b/setupext/__init__.py @@ -21,4 +21,3 @@ from . import develop from . import test_java from . import sdist -from . import pytester diff --git a/setupext/pytester.py b/setupext/pytester.py deleted file mode 100644 index a19a3fa7d..000000000 --- a/setupext/pytester.py +++ /dev/null @@ -1,39 +0,0 @@ -# ***************************************************************************** -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# See NOTICE file for details. -# -# ***************************************************************************** -import sys - -from setuptools.command.test import test as TestCommand - - -class PyTest(TestCommand): - user_options = [("pytest-args=", "a", "Arguments to pass to pytest")] - - def initialize_options(self): - TestCommand.initialize_options(self) - self.pytest_args = "" - - def run_tests(self): - self.run_command("test_java") - - import shlex - - # import here, cause outside the eggs aren't loaded - import pytest - - errno = pytest.main(shlex.split(self.pytest_args)) - sys.exit(errno)