From c4d52524ccddaa664d8a597b7e67fee15c88ea19 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sun, 29 May 2022 13:51:25 +0200 Subject: [PATCH 01/71] 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 02/71] 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 03/71] 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 04/71] 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 05/71] 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 06/71] 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 07/71] 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 08/71] 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 09/71] 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 10/71] 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 11/71] 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 12/71] 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 13/71] 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 14/71] 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 15/71] 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 16/71] 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 17/71] 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 18/71] 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 19/71] 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 20/71] 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 21/71] 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 22/71] 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 23/71] 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 24/71] 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 25/71] 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 26/71] 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 27/71] 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 28/71] 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 29/71] 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 30/71] 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 31/71] 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 32/71] 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 33/71] 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 34/71] 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 35/71] 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 36/71] 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 37/71] 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 38/71] 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 39/71] 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 40/71] 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 41/71] 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 42/71] 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 43/71] 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 44/71] 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 45/71] 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 46/71] 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 47/71] 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 48/71] 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 49/71] 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 50/71] 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 51/71] 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 52/71] 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 53/71] 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 54/71] 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 55/71] 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 56/71] 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 57/71] 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 58/71] 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 59/71] [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 60/71] 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 61/71] 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 62/71] 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 63/71] 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 64/71] 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 65/71] 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 66/71] 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 67/71] 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 68/71] 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 69/71] 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 df7d2e40a49126aecc2e7be6e7d2373d813e796e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 12:41:38 +0200 Subject: [PATCH 70/71] 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 71/71] 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; }