jpype-0.6.2+dfsg/0000775000175000017500000000000013036015411013053 5ustar takakitakakijpype-0.6.2+dfsg/.bumpversion.cfg0000664000175000017500000000057713036015411016174 0ustar takakitakaki[bumpversion] current_version = 0.6.2 commit = True tag = True [bumpversion:file:setup.py] [bumpversion:file:jpype/__init__.py] serialize = {major}, {minor}, {patch} parse = (?P\d+), (?P\d+), (?P\d+) [bumpversion:file:doc/CHANGELOG.rst] search = - **Next version - unreleased** replace = - **Next version - unreleased** - **{new_version} - {now:%Y-%m-%d}** jpype-0.6.2+dfsg/.gitignore0000664000175000017500000000127613036015411015051 0ustar takakitakakiMANIFEST *~ /test/classes/ */build*/ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .cache nosetests.xml coverage.xml # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ jpype-0.6.2+dfsg/.travis.yml0000664000175000017500000000133313036015411015164 0ustar takakitakakios: - linux language: python python: - '2.6' - '2.7' - '3.3' - '3.4' - '3.5' - 'pypy' - 'pypy3' - "nightly" sudo: false addons: apt: packages: - ant env: # one build with and without numpy support (opt numpy out) - NUMPY="--install-option=--disable-numpy" - NUMPY="" matrix: allow_failures: - python: 'pypy' env: NUMPY="--install-option=--disable-numpy" - python: 'pypy3' env: NUMPY="--install-option=--disable-numpy" - python: 'pypy' env: NUMPY="" - python: 'pypy3' env: NUMPY="" install: - pip install . $NUMPY - pip install -r test-requirements.txt - ant -f test/build.xml script: - python -c "import jpype" - python test/testsuite.py jpype-0.6.2+dfsg/AUTHORS.rst0000664000175000017500000000051613036015411014734 0ustar takakitakakiAuthors ------- The original author: Steve Menard Current Maintainer: Luis Nell Huge thanks to these CONTRIBUTORS: * lazerscience * Koblaid * Michael Willis (michaelwillis) * awesomescot * Joe Quant (joequant) * Mario Rodas * David Moss * Stepan Kolesnik * Philip Smith * Bastian Bowe * Kristi * Martin K. Scherer * Dongwon Shin jpype-0.6.2+dfsg/LICENSE0000664000175000017500000002167013036015411014066 0ustar takakitakakiApache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS jpype-0.6.2+dfsg/MANIFEST.in0000664000175000017500000000025313036015411014611 0ustar takakitakakirecursive-include native *.h recursive-include examples * include *.rst doc/* LICENSE # include everything under test/ graft test global-exclude *.pyc prune test/classes jpype-0.6.2+dfsg/README.rst0000664000175000017500000000116213036015411014542 0ustar takakitakakiJPype ===== .. image:: https://travis-ci.org/originell/jpype.png?branch=master :target: https://travis-ci.org/originell/jpype .. image:: https://ci.appveyor.com/api/projects/status/7x9aqpsbcdnl96wt/branch/master :target: https://ci.appveyor.com/project/marscher/jpype-555 JPype is an effort to allow python programs full access to java class libraries. Find the `documentation at Read the Docs `__. Current development is done in `the github project `__. The work on this project began on `Sourceforge `__. jpype-0.6.2+dfsg/appveyor.yml0000664000175000017500000000367713036015411015460 0ustar takakitakakienvironment: global: # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the # /E:ON and /V:ON options are not enabled in the batch script intepreter # See: http://stackoverflow.com/a/13751649/163740 CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd" ANT_HOME: C:\ant matrix: - PYTHON: "C:\\Miniconda" JAVA_HOME: "C:\\Program Files (x86)\\Java\\jdk1.8.0" - PYTHON: "C:\\Miniconda-x64" JAVA_HOME: "C:\\Program Files\\Java\\jdk1.8.0" - PYTHON: "C:\\Miniconda3" JAVA_HOME: "C:\\Program Files (x86)\\Java\\jdk1.8.0" - PYTHON: "C:\\Miniconda3-x64" JAVA_HOME: "C:\\Program Files\\Java\\jdk1.8.0" install: # Install Python (from the official .msi of http://python.org) and pip when # not already installed. - "powershell ./appveyor/install.ps1" # Prepend newly installed Python to the PATH of this build (this cannot be # done from inside the powershell script as it would require to restart # the parent CMD process). - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;C:\\ant\\bin;%PATH%" # Check that we have the expected version and architecture for Python - "python --version" - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" # Install the build dependencies of the project. If some dependencies contain # compiled extensions and are not provided as pre-built wheel packages, # pip will build them from source using the MSVC compiler matching the # target Python version and architecture - "conda update --all -y" - "conda install nose setuptools -y" - "pip install -r test-requirements.txt" # -r dev-requirements.txt - "ant -f test\\build.xml" # Build the compiled extension and run the project tests - "python setup.py install" build: false # Not a C# project, build stuff at the test step instead. test_script: # run testsuite and upload test results to AppVeyor; return exit code of testsuite - "powershell ./appveyor/runTestsuite.ps1" jpype-0.6.2+dfsg/appveyor/0000775000175000017500000000000013036015411014720 5ustar takakitakakijpype-0.6.2+dfsg/appveyor/install.ps10000664000175000017500000000453513036015411017022 0ustar takakitakaki# install apache ant $ANT_VERSION = "1.9.7" function RunCommand ($command, $command_args) { Write-Host $command $command_args Start-Process -FilePath $command -ArgumentList $command_args -Wait -Passthru } function unzipAnt($file, $destination) { if (-Not (Test-Path $file)) { Write-Host "File " $file "does not exist!" return } if (-Not (Test-Path $destination)) { mkdir $destination } Write-Host "extract " $file " to " $destination $shell_app = new-object -com shell.application $zip_file = $shell_app.namespace($file) $dir = $shell_app.namespace($destination) $dir.Copyhere($zip_file.items()) # this should return the only folder name contained in ant.zip #$foldername = "" $zip_file.items() | foreach { $foldername = $_.name Write-Host "current foldername" $foldername } return $foldername } function DownloadAnt() { $url = "http://www.us.apache.org/dist/ant/binaries/apache-ant-$ANT_VERSION-bin.zip" $webclient = New-Object System.Net.WebClient $filepath = "C:\ant.zip" if (Test-Path $filepath) { Write-Host "Reusing" $filepath return $filepath } # Download and retry up to 3 times in case of network transient errors. Write-Host "Downloading" $filename "from" $url $retry_attempts = 2 for($i=0; $i -lt $retry_attempts; $i++){ try { $webclient.DownloadFile($url, $filepath) break } Catch [Exception]{ Start-Sleep 1 } } if (Test-Path $filepath) { Write-Host "File saved at" $filepath } else { # Retry once to get the error message if any at the last try $webclient.DownloadFile($url, $filepath) } return $filepath } function InstallAnt() { if (Test-Path "c:\apache-ant-$ANT_VERSION") { Write-Host "ant already exists" return $false } $filepath = DownloadAnt # extract to C: (will result in something like C:\apache-ant-1.9.4 $folder = unzipAnt $filepath "C:" $ant_path = "C:\apache-ant-$ANT_VERSION\bin" if (-not (Test-Path $ant_path)) { Throw "unpacked folder '" + $ant_path + "' does not exist!" } # create link to default ant binary dir, so we can rely on it. cmd.exe /c mklink /d C:\ant $folder } function main () { InstallAnt } main jpype-0.6.2+dfsg/appveyor/runTestsuite.ps10000664000175000017500000000175613036015411020074 0ustar takakitakakifunction xslt_transform($xml, $xsl, $output) { trap [Exception] { Write-Host $_.Exception } $xslt = New-Object System.Xml.Xsl.XslCompiledTransform $xslt.Load($xsl) $xslt.Transform($xml, $output) } function upload($file) { trap [Exception] { Write-Host $_.Exception } $wc = New-Object 'System.Net.WebClient' $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", $file) } function run { cd $env:APPVEYOR_BUILD_FOLDER $stylesheet = "test/transform_xunit_to_appveyor.xsl" $input = "nosetests.xml" $output = "test/transformed.xml" nosetests test/jpypetest --all-modules --with-xunit $success = $? Write-Host "result code of nosetests:" $success xslt_transform $input $stylesheet $output upload $output Push-AppveyorArtifact $input Push-AppveyorArtifact $output # return exit code of testsuite if ( -not $success) { throw "testsuite not successful" } } runjpype-0.6.2+dfsg/appveyor/run_with_env.cmd0000664000175000017500000000373013036015411020117 0ustar takakitakaki:: To build extensions for 64 bit Python 3, we need to configure environment :: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: :: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1) :: :: To build extensions for 64 bit Python 2, we need to configure environment :: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of: :: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0) :: :: 32 bit builds do not require specific environment configurations. :: :: Note: this script needs to be run with the /E:ON and /V:ON flags for the :: cmd interpreter, at least for (SDK v7.0) :: :: More details at: :: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows :: http://stackoverflow.com/a/13751649/163740 :: :: Author: Olivier Grisel :: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ @ECHO OFF SET COMMAND_TO_RUN=%* SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%" IF %MAJOR_PYTHON_VERSION% == "2" ( SET WINDOWS_SDK_VERSION="v7.0" ) ELSE IF %MAJOR_PYTHON_VERSION% == "3" ( SET WINDOWS_SDK_VERSION="v7.1" ) ELSE ( ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%" EXIT 1 ) IF NOT "%PYTHON_ARCH%"=="64" SET NO_SPECIFIC_SDK=1 IF NOT "%MAJOR_PYTHON_VERSION%" == "2" SET NO_SPECIFIC_SDK=1 IF NOT DEFINED NO_SPECIFIC_SDK ( ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture SET DISTUTILS_USE_SDK=1 SET MSSdk=1 "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release ECHO Executing: %COMMAND_TO_RUN% call %COMMAND_TO_RUN% || EXIT 1 ) ELSE ( ECHO Using default MSVC build environment on a %PYTHON_ARCH% bit architecture for Python %MAJOR_PYTHON_VERSION% ECHO Executing: %COMMAND_TO_RUN% call %COMMAND_TO_RUN% || EXIT 1 ) jpype-0.6.2+dfsg/dev-requirements.txt0000664000175000017500000000007113036015411017111 0ustar takakitakakiSphinx==1.2.1 sphinx-rtd-theme==0.1.5 bumpversion==0.5.1 jpype-0.6.2+dfsg/doc/0000775000175000017500000000000013036015411013620 5ustar takakitakakijpype-0.6.2+dfsg/doc/CHANGELOG.rst0000664000175000017500000000751513036015411015651 0ustar takakitakakiChangelog ========= This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards. - **Next version - unreleased** - **0.6.2 - 2017-01-13** - Fix JVM location for OSX. - Fix a method overload bug. - Add support for synthetic methods - **0.6.1 - 2015-08-05** - Fix proxy with arguments issue. - Fix Python 3 support for Windows failing to import winreg. - Fix non matching overloads on iterating java collections. - **0.6.0 - 2015-04-13** - Python3 support. - Fix OutOfMemoryError. - **0.5.7 - 2014-10-29** - No JDK/JRE is required to build anymore due to provided jni.h. To override this, one needs to set a JAVA_HOME pointing to a JDK during setup. - Better support for various platforms and compilers (MinGW, Cygwin, Windows) - **0.5.6 - 2014-09-27** - *Note*: In this release we returned to the three point number versioning scheme. - Fix #63: 'property' object has no attribute 'isBeanMutator' - Fix #70: python setup.py develop does now work as expected - Fix #79, Fix #85: missing declaration of 'uint' - Fix #80: opt out NumPy code dependency by '--disable-numpy' parameter to setup. To opt out with pip append --install-option="--disable-numpy". - Use JVMFinder method of @tcalmant to locate a Java runtime - **0.5.5.4 - 2014-08-12** - Fix: compile issue, if numpy is not available (NPY_BOOL n/a). Closes #77 - **0.5.5.3 - 2014-08-11** - Optional support for NumPy arrays in handling of Java arrays. Both set and get slice operators are supported. Speed improvement of factor 10 for setting and factor 6 for getting. The returned arrays are typed with the matching NumPy type. - Fix: add missing wrapper type 'JShort' - Fix: Conversion check for unsigned types did not work in array setters (tautological compare) - **0.5.5.2 - 2014-04-29** - Fix: array setter memory leak (ISSUE: #64) - **0.5.5.1 - 2014-04-11** - Fix: setup.py now runs under MacOSX with Python 2.6 (referred to missing subprocess function) - **0.5.5 - 2014-04-11** - *Note* that this release is *not* compatible with Python 2.5 anymore! - Added AHL changes * replaced Python set type usage with new 2.6.x and higher * fixed broken Python slicing semantics on JArray objects * fixed a memory leak in the JVM when passing Python lists to JArray constructors * prevent ctrl+c seg faulting * corrected new[]/delete pairs to stop valgrind complaining * ship basic PyMemoryView implementation (based on numpy's) for Python 2.6 compatibility - Fast sliced access for primitive datatype arrays (factor of 10) - Use setter for Java bean property assignment even if not having a getter by @baztian - Fix public methods not being accessible if a Java bean property with the same name exists by @baztian (*Warning*: In rare cases this change is incompatibile to previous releases. If you are accessing a bean property without using the get/set method and the bean has a public method with the property's name you have to change the code to use the get/set methods.) - Make jpype.JException catch exceptions from subclasses by @baztian - Make more complex overloaded Java methods accessible (fixes https://sourceforge.net/p/jpype/bugs/69/) by @baztian and anonymous - Some minor improvements inferring unnecessary copies in extension code - Some JNI cleanups related to memory - Fix memory leak in array setters - Fix memory leak in typemanager - Add userguide from sourceforge project by @baztian - **0.5.4.5 - 2013-08-25** - Added support for OSX 10.9 Mavericks by @rmangino (#16) - **0.5.4.4 - 2013-08-10** - Rewritten Java Home directory Search by @marsam (#13, #12 and #7) - Stylistic cleanups of setup.py - **0.5.4.3 - 2013-07-27** - Initial pypi release with most fixes for easier installation jpype-0.6.2+dfsg/doc/CHANGELOG.rst.orig0000664000175000017500000000763713036015411016615 0ustar takakitakakiChangelog ========= This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards. <<<<<<< Updated upstream - **Next version - unreleased** - **0.6.2 - 2017-01-13** ======= - **0.6.2 - 2017-01-13** - Fix JVM location for OSX. - Fix a method overload bug. - Add support for synthetic methods >>>>>>> Stashed changes - **0.6.1 - 2015-08-05** - Fix proxy with arguments issue. - Fix Python 3 support for Windows failing to import winreg. - Fix non matching overloads on iterating java collections. - **0.6.0 - 2015-04-13** - Python3 support. - Fix OutOfMemoryError. - **0.5.7 - 2014-10-29** - No JDK/JRE is required to build anymore due to provided jni.h. To override this, one needs to set a JAVA_HOME pointing to a JDK during setup. - Better support for various platforms and compilers (MinGW, Cygwin, Windows) - **0.5.6 - 2014-09-27** - *Note*: In this release we returned to the three point number versioning scheme. - Fix #63: 'property' object has no attribute 'isBeanMutator' - Fix #70: python setup.py develop does now work as expected - Fix #79, Fix #85: missing declaration of 'uint' - Fix #80: opt out NumPy code dependency by '--disable-numpy' parameter to setup. To opt out with pip append --install-option="--disable-numpy". - Use JVMFinder method of @tcalmant to locate a Java runtime - **0.5.5.4 - 2014-08-12** - Fix: compile issue, if numpy is not available (NPY_BOOL n/a). Closes #77 - **0.5.5.3 - 2014-08-11** - Optional support for NumPy arrays in handling of Java arrays. Both set and get slice operators are supported. Speed improvement of factor 10 for setting and factor 6 for getting. The returned arrays are typed with the matching NumPy type. - Fix: add missing wrapper type 'JShort' - Fix: Conversion check for unsigned types did not work in array setters (tautological compare) - **0.5.5.2 - 2014-04-29** - Fix: array setter memory leak (ISSUE: #64) - **0.5.5.1 - 2014-04-11** - Fix: setup.py now runs under MacOSX with Python 2.6 (referred to missing subprocess function) - **0.5.5 - 2014-04-11** - *Note* that this release is *not* compatible with Python 2.5 anymore! - Added AHL changes * replaced Python set type usage with new 2.6.x and higher * fixed broken Python slicing semantics on JArray objects * fixed a memory leak in the JVM when passing Python lists to JArray constructors * prevent ctrl+c seg faulting * corrected new[]/delete pairs to stop valgrind complaining * ship basic PyMemoryView implementation (based on numpy's) for Python 2.6 compatibility - Fast sliced access for primitive datatype arrays (factor of 10) - Use setter for Java bean property assignment even if not having a getter by @baztian - Fix public methods not being accessible if a Java bean property with the same name exists by @baztian (*Warning*: In rare cases this change is incompatibile to previous releases. If you are accessing a bean property without using the get/set method and the bean has a public method with the property's name you have to change the code to use the get/set methods.) - Make jpype.JException catch exceptions from subclasses by @baztian - Make more complex overloaded Java methods accessible (fixes https://sourceforge.net/p/jpype/bugs/69/) by @baztian and anonymous - Some minor improvements inferring unnecessary copies in extension code - Some JNI cleanups related to memory - Fix memory leak in array setters - Fix memory leak in typemanager - Add userguide from sourceforge project by @baztian - **0.5.4.5 - 2013-08-25** - Added support for OSX 10.9 Mavericks by @rmangino (#16) - **0.5.4.4 - 2013-08-10** - Rewritten Java Home directory Search by @marsam (#13, #12 and #7) - Stylistic cleanups of setup.py - **0.5.4.3 - 2013-07-27** - Initial pypi release with most fixes for easier installation jpype-0.6.2+dfsg/doc/Makefile0000664000175000017500000001514613036015411015267 0ustar takakitakaki# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/JPype.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/JPype.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/JPype" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/JPype" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." jpype-0.6.2+dfsg/doc/conf.py0000664000175000017500000002076213036015411015126 0ustar takakitakaki# -*- coding: utf-8 -*- # # JPype documentation build configuration file, created by # sphinx-quickstart on Wed Feb 26 20:16:40 2014. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'JPype' copyright = u'2014, Steve Menard, Luis Nell and others' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. import jpype version = jpype.__version__ # The full version, including alpha/beta/rc tags. release = jpype.__version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if not on_rtd: # only import and set the theme if we're building docs locally import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # otherwise, readthedocs.org uses their theme by default, so no need to specify it # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'JPypedoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'JPype.tex', u'JPype Documentation', u'Steve Menard, Luis Nell and others', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'jpype', u'JPype Documentation', [u'Steve Menard, Luis Nell and others'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'JPype', u'JPype Documentation', u'Steve Menard, Luis Nell and others', 'JPype', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False jpype-0.6.2+dfsg/doc/index.rst0000664000175000017500000000122313036015411015457 0ustar takakitakakiJPype documentation =================== JPype is an effort to allow python programs full access to java class libraries. This is achieved not through re-implementing Python, as Jython/JPython has done, but rather through interfacing at the native level in both virtual machines. Eventually, it should be possible to replace Java with python in many, though not all, situations. JSP, Servlets, RMI servers and IDE plugins are good candidates. Parts of the documentation ========================== .. toctree:: :maxdepth: 2 install userguide CHANGELOG Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` jpype-0.6.2+dfsg/doc/install.rst0000664000175000017500000000436713036015411016032 0ustar takakitakakiInstallation ============ Get JPype from the `github `__ or from `PyPi `__. If you are using `Anaconda `_ Python stack, you can install pre-compiled binaries from conda-forge for Linux, OSX and Windows. Binary Install -------------- 1. Ensure you have installed Anaconda/Miniconda. Instructions can be found `here `_. 2. Install from the conda-forge software channel:: conda install -c conda-forge jpype1 From source - Requirements -------------------------- Either the Sun/Oracle JDK/JRE Variant or OpenJDK. Python 2.6+ (including Python 3+). Debian/Ubuntu ~~~~~~~~~~~~~ Debian/Ubuntu users will have to install ``g++`` and ``python-dev`` first: :: sudo apt-get install g++ python-dev Install ------- Should be easy as :: python setup.py install If it fails... ~~~~~~~~~~~~~~ This happens mostly due to the setup not being able to find your ``JAVA_HOME``. In case this happens, please do two things: 1. You can continue the installation by finding the ``JAVA_HOME`` on your own ( the place where the headers etc. are) and explicitly setting it for the installation: ``JAVA\_HOME=/usr/lib/java/jdk1.6.0/ python setup.py install`` 2. Please create an Issue `on github `__ and post all the information you have. Tested on --------- - OS X 10.7.4 with Sun/Oracle JDK 1.6.0 - OSX 10.8.1-10.8.4 with Sun/Oracle JDK 1.6.0 - OSX 10.9 DP5 - Debian 6.0.4/6.0.5 with Sun/Oracle JDK 1.6.0 - Debian 7.1 with OpenJDK 1.6.0 - Ubuntu 12.04 with Sun/Oracle JDK 1.6.0 Known Bugs/Limitations ---------------------- - Java classes outside of a package (in the ````) cannot be imported. - unable to access a field or method if it conflicts with a python keyword. - Because of lack of JVM support, you cannot shutdown the JVM and then restart it. - Some methods rely on the "current" class/caller. Since calls coming directly from python code do not have a current class, these methods do not work. The User Manual lists all the known methods like that. - Mixing 64 bit Python with 32 bit Java and vice versa crashes on import jpype. jpype-0.6.2+dfsg/doc/make.bat0000664000175000017500000001447113036015411015234 0ustar takakitakaki@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. xml to make Docutils-native XML files echo. pseudoxml to make pseudoxml-XML files for display purposes echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) %SPHINXBUILD% 2> nul if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\JPype.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\JPype.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdf" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf cd %BUILDDIR%/.. echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "latexpdfja" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex cd %BUILDDIR%/latex make all-pdf-ja cd %BUILDDIR%/.. echo. echo.Build finished; the PDF files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) if "%1" == "xml" ( %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml if errorlevel 1 exit /b 1 echo. echo.Build finished. The XML files are in %BUILDDIR%/xml. goto end ) if "%1" == "pseudoxml" ( %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml if errorlevel 1 exit /b 1 echo. echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. goto end ) :end jpype-0.6.2+dfsg/doc/userguide.rst0000664000175000017500000006172213036015411016356 0ustar takakitakakiUser Guide ========== Overview -------- JPype is an effort to allow Python programs full access to Java class libraries. This is achieved not through re-implementing Python, as Jython/JPython has done, but rather through interfacing at the native level in both virtual machines. Eventually, it should be possible to replace Java with Python in many, though not all, situations. JSP, Servlets, RMI servers and IDE plugins are all good candidates. Once this integration is achieved, a second phase will be started to separate the Java logic from the Python logic, eventually allowing the bridging technology to be used in other environments, i.e. Ruby, Perl, COM, etc ... Why such a project? ~~~~~~~~~~~~~~~~~~~ As much as I enjoy programming in Python, there is no denying that Java has the bulk of the mindshare. Just look on Sourceforge, at the time of creation of this project, there were 3267 Python-related projects, and 12126 Java- related projects. And that's not counting commercial interests. Server-side Python is also pretty weak. Zope may be a great application server, but I have never been able to figure it out. Java, on the other hand, shines on the server. So in order to both enjoy the language, and have access to the most popular libraries, I have started this project. What about Jython? ~~~~~~~~~~~~~~~~~~ Jython (formerly known as JPython) is a great idea. However, it suffers from a large number of drawbacks, i.e. it always lags behind CPython, it is slow and it does not allow access to most Python extensions. My idea allows using both kinds of libraries in tandem, so the developer is free to pick and choose. Using JPype ~~~~~~~~~~~ Here is a sample program to demonstrate how to use JPype: :: from jpype import * startJVM(getDefaultJVMPath(), "-ea") java.lang.System.out.println("hello world") shutdownJVM() This is of course a simple **hello world** type of application. Yet it shows the 2 most important calls: **startupJVM** and **shutdownJVM**. The rest will be explained in more detail in the next sections. Core Ideas ---------- Threading --------- Any non-trivial application will have need of threading. Be it implicitly by using a GUI, or because you're writing a multi-user server. Or explicitly for performance reason. The only real problem here is making sure Java threads and Python threads cooperate correctly. Thankfully, this is pretty easy to do. Python Threads ~~~~~~~~~~~~~~ For the most part, Python threads based on OS level threads (i.e. posix threads) will work without problem. The only thing to remember is to call **jpype.attachThreadToJVM()** in the thread body to make the JVM usable from that thread. For threads that you do not start yourself, you can call **isThreadAttachedToJVM()** to check. Java Threads ~~~~~~~~~~~~ At the moment, it is not possible to use threads created from Java, since there is no **callback** available. Other Threads ~~~~~~~~~~~~~ Some Python libraries offer other kinds of thread, (i.e. microthreads). How they interact with Java depends on their nature. As stated earlier, any OS- level threads will work without problem. Emulated threads, like microthreads, will appear as a single thread to Java, so special care will have to be taken for synchronization. Synchronization ~~~~~~~~~~~~~~~ Java synchronization support can be split into 2 categories. The first is the **synchronized** keyword, both as prefix on a method and as a block inside a method. The second are the different methods available on the Object class (**notify, notifyAll, wait**). To support the **synchronized** functionality, JPype defines a method called synchronized(O). O has to be a Java object or Java class, or a Java wrapper that corresponds to an object (JString and JObject). The return value is a monitor object that will keep the synchronization on as long as the object is kept alive. The lock will be broken as soon as the monitor is GCd. So make sure to hang on to it as long as you need it. The other methods are available as-is on any _JavaObject. For synchronization that does not have to be shared with Java code, I suggest using Python's support instead of Java's, as it'll be more natural and easier. Performance ----------- JPype uses JNI, which is well known in the Java world as not being the most efficient of interfaces. Further, JPype bridges two very different runtime environments, performing conversion back and forth as needed. Both of these can impose rather large performance bottlenecks. JNI is the standard native interface for most, if not all, JVMs, so there is no getting around it. Down the road, it is possible that interfacing with CNI (GCC's java native interface) may be used. The only way to minimize the JNI cost is to move some code over to Java. Follow the regular Python philosophy : **Write it all in Python, then write only those parts that need it in C.** Except this time, it's write the parts that need it in Java. For the conversion costs, again, nothing much can be done. In cases where a given object (be it a string, an object, an array, etc ...) is passed often into Java, you can pre-convert it once using the wrappers, and then pass in the wrappers. For most situations, this should solve the problem. As a final note, while a JPype program will likely be slower than its pure Java counterpart, it has a good chance of being faster than the pure Python version of it. The JVM is a memory hog, but does a good job of optimizing code execution speeds. Inner Classes ------------- For the most part, inner classes can be used like normal classes, with the following differences: - Inner classes in Java natively use $ to separate the outer class from the inner class. For example, inner class Foo defined inside class Bar is called Bar.Foo in Java, but its real native name is Bar$Foo. - Because of this name mangling, you cannot use the standard package access method to get them. Use the method __getclass__ in JPackage to load them. - Non-static inner classes cannot be instantiated from Python code. Instances received from Java code that can be used without problem. Arrays ------ JPype has full support for receiving Java arrays and passing them to Java methods. Java arrays, wrapped in the JArray wrapper class, behave like Python lists, except that their size is fixed, and that the contents are of a specific type. Multi-dimensional arrays (array of arrays) also work without problem. As of version 0.5.5.3 we use NumPy arrays to interchange data with Java. This is much faster than using lists, since we do not need to handle every single array element but can process all data at once. If you do not want this optional feature, because eg. it depends on NumPy, you can opt it out in the installation process by passing *"--disable-numpy"* to *setup.py*. To opt out with pip you need to append the additional argument *"--install-option='--disable-numpy'*. This possibility exists since version 0.5.6. Creating Java arrays from Python ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The JArray wrapper is used to create Arrays from Python code. The code to create an array is like this: :: JArray(type, num_dims)(sz or sequence) Type is either a Java Class (as a String or a JavaClass object) or a Wrapper type. num_dims is the number of dimensions to build the array and defaults to 1. sz is the actual number of elements in the arrays, and sequence is a sequence to initialize the array with. The logic behind this is that JArray(type, ndims) returns an Array Class, which can then be called like any other class to create an instance. Type conversion --------------- One of the most complex parts of a bridge system like JPype is finding a way to seamlessly translate between Python types and Java types. The following table will show what implicit conversions occur, both Python to Java and Java to Python. Explicit conversion, which happens when a Python object is wrapped, is converted in each wrapper. Conversion from Python to Java ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This type of conversion happens when a Python object is used either as a parameter to a Java method or to set the value of a Java field. Type Matching ~~~~~~~~~~~~~ JPype defines different levels of "match" between Python objects and Java types. These levels are: - **none**, There is no way to convert. - **explicit (E)**, JPype can convert the desired type, but only explicitly via the wrapper classes. This means the proper wrapper class will access this type as argument. - **implicit (I)**, JPype will convert as needed. - **exact> (X)**, Like implicit, but when deciding with method overload to use, one where all the parameters match "exact" will take precedence over "implicit" matches. ============ ========== ========= =========== ========= ========== ========== =========== ========= ========== ========== =========== ========= Python\\Java byte short int long float double boolean char String Array Object Class ============ ========== ========= =========== ========= ========== ========== =========== ========= ========== ========== =========== ========= int I [1]_ I [1]_ X I X [10]_ long I [1]_ I [1]_ I [1]_ X float I [1]_ X sequence dictionary string I [2]_ X unicode I [2]_ X JByte X JShort X JInt X JLong X JFloat X JDouble X JBoolean X JString X I [3]_ JChar X JArray I/X [4]_ I [5]_ JObject I/X [6]_ I/X [7]_ JavaObject I [8]_ JavaClass I [9]_ X ============ ========== ========= =========== ========= ========== ========== =========== ========= ========== ========== =========== ========= .. [1] Conversion will occur if the Python value fits in the Java native type. .. [2] Conversion occurs if the Python string or unicode is of length 1. .. [3] The required object must be of a type compatible with ``java.lang.String(java.lang.Object, java.util.Comparable)``. .. [4] Number of dimensions must match, and the types must be compatible. .. [5] Only when the required type is ``java.lang.Object``. .. [6] Only if the JObject wrapper's specified type is an compatible array class. .. [7] Only if the required type is compatible with the wrappers's specified type. The actual type of the Java object is not considered. .. [8] Only if the required type is compatible with the Java Object actual type. .. [9] Only when the required type is ``java.lang.Object`` or ``java.lang.Class``. .. [10] Only the values True and False are implicitly converted to booleans. Converting from Java to Python ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The rules here are much simpler. Java **byte, short and int** are converted to Python **int**. Java **long** is converted to Python **long**. Java **float and double** are converted to Python **float**. Java **boolean** is converted to Python **int** of value 1 or 0. Java **char** is converted to Python **unicode** of length 1. Java **String** is converted to Python **unicode**. Java **arrays** are converted to **JArray**. All other Java objects are converted to **JavaObject**s. Java **Class** is converted to **JavaClass**. Java array **Class** is converted to **JavaArrayClass**. JProxy ------ The JProxy allows Python code to "implement" any number of Java interfaces, so as to receive callbacks through them. Using JProxy is simple. The constructor takes 2 arguments. The first is one or a sequence of string of JClass objects, defining the interfaces to be "implemented". The second must be a keyword argument, and be either **dict** or **inst**. If **dict** is specified, then the 2nd argument must be a dictionary, with the keys the method names as defined in the interface(s), and the values callable objects. If **inst** an object instance must be given, with methods defined for the methods declared in the interface(s). Either way, when Java calls the interface method, the corresponding Python callable is looked up and called. Of course, this is not the same as subclassing Java classes in Python. However, most Java APIs are built so that subclassing is not needed. Good examples of this are AWT and SWING. Except for relatively advanced features, it is possible to build complete UIs without creating a single subclass. For those cases where subclassing is absolutely necessary (i.e. using Java's SAXP classes), it is generally easy to create an interface and a simple subclass that delegates the calls to that interface. Sample code : ~~~~~~~~~~~~~ Assume a Java interface like: :: public interface ITestInterface2 { int testMethod(); String testMethod2(); } You can create a proxy *implementing* this interface in 2 ways. First, with a class: :: class C : def testMethod(self) : return 42 def testMethod2(self) : return "Bar" c = C() proxy = JProxy("ITestInterface2", inst=c) or you can do it with a dictionary :: def _testMethod() : return 32 def _testMethod2() : return "Fooo!" d = { 'testMethod' : _testMethod, 'testMethod2' : _testMethod2, } proxy = JProxy("ITestInterface2", dict=d) Java Exceptions --------------- Error handling is a very important part of any non-trivial program. So bridging Java's exception mechanism and Python's is very important. Java exception classes are regular classes that extend, directly or indirectly, the java.lang.Throwable class. Python exceptions are classes that extend, directly or indirectly, the Exception class. On the surface they are similar, at the C-API level, Python exceptions are completely different from regular Python classes. This contributes to the fact that it is not possible to catch Java exceptions in a completely straightforward way. All Java exceptions thrown end up throwing the jpype.JavaException exception. You can then use the message(), stackTrace() and javaClass() to access extended information. Here is an example: :: try : # Code that throws a java.lang.RuntimeException except JavaException, ex : if JavaException.javaClass() is java.lang.RuntimeException : print "Caught the runtime exception : ", JavaException.message() print JavaException.stackTrace() Alternately, you can catch the REAL Java exception directly by using the JException wrapper. :: try : # Code that throws a java.lang.RuntimeException except jpype.JException(java.lang.RuntimeException), ex : print "Caught the runtime exception : ", JavaException.message() print JavaException.stackTrace() Known limitations ----------------- This section lists those limitations that are unlikely to change, as they come from external sources. Unloading the JVM ~~~~~~~~~~~~~~~~~ The JNI API defines a method called destroyJVM(). However, this method does not work. That is, Sun's JVMs do not allow unloading. For this reason, after calling shutdownJVM(), if you attempt calling startupJVM() again you will get a non-specific exception. There is nothing wrong (that I can see) in JPype. So if Sun gets around to supporting its own properly, or if you use JPype with a non-SUN JVM that does (I believe IBM's JVMs support JNI invocation, but I do not know if their destroyJVM works properly), JPype will be able to take advantage of it. As the time of writing, the latest stable Sun JVM was 1.4.2_04. Methods dependent on "current" class ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are a few methods in the Java libraries that rely on finding information on the calling class. So these methods, if called directly from Python code, will fail because there is no calling Java class, and the JNI API does not provide methods to simulate one. At the moment, the methods known to fail are : java.lang.Class.forName(String classname) ::::::::::::::::::::::::::::::::::::::::: This method relies on the current class's classloader to do its loading. It can easily be replaced with **Class.forName(classname, True, ClassLoader.getSystemClassLoader())**. java.sql.DriverManager.getConnection(...) ::::::::::::::::::::::::::::::::::::::::: For some reason, this class verifies that the driver class as loaded in the "current" classloader is the same as previously registered. Since there is no "current" classloader, it defaults to the internal classloader, which typically does not find the driver. To remedy, simply instantiate the driver yourself and call its connect(...) method. Unsupported Java virtual machines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The open JVM implementations *Cacao* and *JamVM* are known not to work with JPype. Module Reference ---------------- getDefaultJVMPath method ~~~~~~~~~~~~~~~~~~~~~~~~~~~ This method tries to automatically obtain the path to a Java runtime installation. This path is needed as argument for startupJVM method and should be used in favour of hardcoded paths to make your scripts more portable. There are several methods under the hood to search for a JVM. If none of them succeeds, the method will raise a JVMNotFoundException. Arguments ::::::::: None Return value :::::::::::: valid path to a Java virtual machine library (jvm.dll, jvm.so, jvm.dylib) Exceptions :::::::::: JVMNotFoundException, if none of the provided methods returned a valid JVM path. startupJVM method ~~~~~~~~~~~~~~~~~ This method MUST be called before any other JPype features can be used. It will initialize the specified JVM. Arguments ::::::::: - vmPath - Must be the path to the jvm.dll (or jvm.so, depending on platform) - misc arguments - All arguments after the first are optional, and are given as it to the JVM. Pretty much any command-line argument you can give the JVM can be passed here. A caveat, multi-part arguments (like -classpath) do not seem to work, and must e passed in as a -D option. Option **-classpath a;b;c** becomes **-Djava.class.path=a;b;c** Return value :::::::::::: None Exceptions :::::::::: On failure, a RuntimeException is raised. shutdownJVM method ~~~~~~~~~~~~~~~~~~ For the most part, this method does not have to be called. It will be automatically executed when the jpype module is unloaded at Python's exit. Arguments ::::::::: None Return value :::::::::::: None Exceptions :::::::::: On failure, a RuntimeException is raised. attachThreadToJVM method ~~~~~~~~~~~~~~~~~~~~~~~~ For the most part, this method does not have to be called. It will be automatically executed when the jpype module is unloaded at Python's exit. Arguments ::::::::: None Return value :::::::::::: None Exceptions :::::::::: On failure, a RuntimeException is raised. isThreadAttachedToJVM method ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For the most part, this method does not have to be called. It will be automatically executed when the jpype module is unloaded at Python's exit. Arguments ::::::::: None Return value :::::::::::: None Exceptions :::::::::: On failure, a RuntimeException is raised. detachThreadFromJVM method ~~~~~~~~~~~~~~~~~~~~~~~~~~ For the most part, this method does not have to be called. It will be automatically executed when the jpype module is unloaded at Python's exit. Arguments ::::::::: None Return value :::::::::::: None Exceptions :::::::::: On failure, a RuntimeException is raised. synchronized method ~~~~~~~~~~~~~~~~~~~ For the most part, this method does not have to be called. It will be automatically executed when the jpype module is unloaded at Python's exit. Arguments ::::::::: None Return value :::::::::::: None Exceptions :::::::::: On failure, a RuntimeException is raised. JPackage class ~~~~~~~~~~~~~~ This class allows structured access to Java packages and classes. It is very similar to a Python import statement. Only the root of the package tree need be declared with the JPackage constructor. Sub-packages will be created on demand. For example, to import the w3c DOM package: :: Document = JPackage('org').w3c.dom.Document Predefined Java packages :::::::::::::::::::::::: For convenience, the jpype module predefines the following JPackages : **java, javax** They can be used as-is, without needing to resort to the JPackage class. Wrapper classes ~~~~~~~~~~~~~~~ The main problem with exposing Java classes and methods to Python, is that Java allows overloading a method. That is, 2 methods can have the same name as long as they have different parameters. Python does not allow that. Most of the time, this is not a problem. Most overloaded methods have very different parameters and no confusion takes place. When JPype is unable to decide with overload of a method to call, the user must resolve the ambiguity. That's where the wrapper classes come in. Take for example the java.io.PrintStream class. This class has a variant of the print and println methods! So for the following code: :: from jpype import * startJVM(getDefaultJVMPath(), "-ea") java.lang.System.out.println(1) shutdownJVM() JPype will automatically choose the println(int) method, because the Python int matches exactly with the Java int, while all the other integral types are only "implicit" matches. However, if that is not the version you wanted to call ... Changing the line thus: :: from jpype import * startJVM(getDefaultJVMPath(), "-ea") java.lang.System.out.println(JByte(1)) # <--- wrap the 1 in a JByte shutdownJVM() tells JPype to choose the byte version. Note that wrapped object will only match to a method which takes EXACTLY that type, even if the type is compatible. Using a JByte wrapper to call a method requiring an int will fail. One other area where wrappers help is performance. Native types convert quite fast, but strings, and later tuples, maps, etc ... conversions can be very costly. If you're going to make many Java calls with a complex object, wrapping it once and then using the wrapper will make a huge difference. Lastly, wrappers allow you to pass in a structure to Java to have it modified. An implicitly converted tuple will not come back modified, even if the Java method HAS changed the contents. An explicitly wrapped tuple will be modified, so that those modifications are visible to the Python program. The available native wrappers are: **JChar, JByte, JShort, JInt, JLong, JFloat, JDouble, JBoolean and JString.** JObject wrapper ::::::::::::::: The JObject wrapper serves a few additional purposes on top of what the other wrappers do. While the native wrappers help to resolve ambiguities between native types, it is impossible to create one JObject wrapper for each Java Class to do the same thing. So, the JObject wrapper accepts 2 parameters. The first is any convertible object. The second is the class to convert it to. It can be the name of the class in a string or a JavaClass object. If omitted, the second parameter will be deduced from the first. Like other wrappers, the method called will only match EXACTLY. A JObject wrapper of type java.lang.Int will not work when calling a method requiring a java.lang.Number. jpype-0.6.2+dfsg/examples/0000775000175000017500000000000013036015411014671 5ustar takakitakakijpype-0.6.2+dfsg/examples/jms/0000775000175000017500000000000013036015411015462 5ustar takakitakakijpype-0.6.2+dfsg/examples/jms/README.TXT0000664000175000017500000000374413036015411017030 0ustar takakitakakiThis example of using JPype and JMS contributed by David Morgenthaler Here is the message that accompanied it when he posted it on comp.lang.python : ============================================================================= Your question intrigued me, so I gave it a try. And the anwer (at least for JMS Publish/Subscribe TextMessages) is YES. It includes: - Java classes for a publisher (src/messaging/JpypePublisher) and a subscriber (src/messaging/JpypeSubscriber). These Java classes, which do most of the dirty work of connecting to the JMS server, are used from python via jpype. - Java classes that test the publisher and subscriber (src/messaging/testJpepePublisher, src/messaging/testJpypeSubscriber) - A Java interface that is used by python for the JProxy - python scripts for publishing and subscribing - An build.xml for ant to build and run the Java classes The Java and python publishers and subscribers work in any reasonable combination (J pub/J sub, J pub/p sub, p pub/p sub, p pub/J sub, and even with multiple subscribers) Copy conveniently located folder. You'll find a build.xml for ant to build the Java. You'll have to edit (in the testers and in the python scripts) the naming and connection factory stuff for your situation. You'll also have to edit the python scripts to correctly locate your jvm and other classpath information. Once you're correctly configured, you can use ant to build and/or execute the Java (type "ant help"). And once the Java is built, you can try the python versions. I can't imagine that this approach wouldn't work for JMS Queues. And while I haven't tested it, I don't see anything preventing the use of other message types (BinaryMessage, ObjectMessage,...). BTW, I don't detect any noticable slowdown in the python versions from the Java versions (probably because of the strightforward conversion of python strings to Java Strings). =============================================================================jpype-0.6.2+dfsg/examples/jms/testJpypePublisher.py0000664000175000017500000000227113036015411021703 0ustar takakitakakifrom jpype import * import time NUMMSGS = 10 def pyPublisher (javaNamingFactory="weblogic.jndi.WLInitialContextFactory", javaNamingProvider="t3://158.188.40.21:7001", connectionFactory="weblogic.jms.ConnectionFactory", topicName="defaultTopic"): return messaging.JpypePublisher(javaNamingFactory,javaNamingProvider, connectionFactory,topicName) ## Startup Jpype and import the messaging java package startJVM("C:\\program files\\Java\\j2re1.4.2_02\\bin\\client\\jvm.dll", "-Djava.class.path=D:/jIRAD/JpypeJMS/src;D:/jIRAD/JpypeJMS/classes;C:/bea/weblogic81/server/lib/weblogic.jar") messaging = JPackage('messaging') # Get a publisher publisher = pyPublisher() ## Timing test # The "Start" message signals the subscriber to start timing message receipts publisher.publish("Start") t0 = time.time() for i in range(NUMMSGS): publisher.publish("Hello World! %s"%i) print "MessageRate =",float(NUMMSGS)/(time.time()-t0) # The "Stop" message signals the subscriber to stop timing message receipts publisher.publish("Stop") # Close and quit publisher.close() shutdownJVM() jpype-0.6.2+dfsg/examples/jms/testJpypeSubscriber.py0000664000175000017500000000264113036015411022052 0ustar takakitakakifrom jpype import * import time def pySubscriber (proxy, javaNamingFactory="weblogic.jndi.WLInitialContextFactory", javaNamingProvider="t3://158.188.40.21:7001", connectionFactory="weblogic.jms.ConnectionFactory", topicName="defaultTopic"): return messaging.JpypeSubscriber(proxy,javaNamingFactory,javaNamingProvider, connectionFactory,topicName) ## Startup Jpype and import the messaging java package startJVM("C:\\program files\\Java\\j2re1.4.2_02\\bin\\client\\jvm.dll", "-Djava.class.path=D:/jIRAD/JpypeJMS/src;D:/jIRAD/JpypeJMS/classes;C:/bea/weblogic81/server/lib/weblogic.jar") messaging = JPackage('messaging') # Setup the JProxy for the messaging.JpypeSubscriberCallback interface class pyCallback: startTime = 0 count = 0 def onMessage (self,text): print text if text=='Start': pyCallback.startTime=time.time() pyCallback.count = 0 elif text=='Stop': print "Message Rate =",float(pyCallback.count)/(time.time()-pyCallback.startTime) else: pyCallback.count += 1 c = pyCallback() proxy = JProxy(messaging.JpypeSubscriberCallback,inst=c) # Get a subscriber sub = pySubscriber(proxy) print "Listening..." # Prevent this thread from exiting time.sleep(1000) # exit shutdownJVM() jpype-0.6.2+dfsg/examples/linux/0000775000175000017500000000000013036015411016030 5ustar takakitakakijpype-0.6.2+dfsg/examples/linux/README.TXT0000664000175000017500000000163113036015411017367 0ustar takakitakakiThe 2 scripts in this derectory are here to resolve a weakness in the linux implementation. Since the JVM is loaded dynamically, the LD_LIBRARY_PATH may not contain the proper directories. Unfortunately, dlopen() will ignore any changes made to the LD_LIBRARY_PATH in the current process. The jpype.sh is meant as an example for people redistributing apps using jpype. Instead of having users launch python script.py directly, have then launch script.sh. The companion finjvm.py can be delivered along your app, but is also present in the ptyhon distribution of jpype. Developpers are encouraged to make their lives simpler by adding the correct directories to their LD_LIBRARY_PATH directly. To learn more about the dlopen problem, you can look at : http://forum.java.sun.com/thread.jsp?forum=52&thread=303583&message=1210441 and http://www.nathanr.net/diary/index.php?year=2004&month=05 jpype-0.6.2+dfsg/examples/linux/findjvm.py0000664000175000017500000000156613036015411020047 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype, os.path jvmlib = jpype.getDefaultJVMPath() print os.path.dirname(os.path.dirname(jvmlib)) jpype-0.6.2+dfsg/examples/linux/jpype.sh0000664000175000017500000000174613036015411017523 0ustar takakitakaki#!/bin/sh #***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** # # this script contributed by Dave Kuhlman, and modified By Steve menard # export JAVA_LIB_PATH=`python findjvm.py` export LD_LIBRARY_PATH=LD_LIBRARY_PATH:$JAVA_LIB_PATH:$JAVA_LIB_PATH/client python $*jpype-0.6.2+dfsg/examples/rmi.py0000664000175000017500000000227413036015411016037 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** #the hava classes used are defined the the test harness. the class jpype.rmi.ServerImpl must be started before this script can be run. from jpype import * import os.path root = os.path.abspath(os.path.dirname(__file__)) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=%s/../test/classes" % root) p = java.rmi.Naming.lookup("rmi://localhost:2004/server") print p, p.__class__ p.callRemote() shutdownJVM() jpype-0.6.2+dfsg/jpype/0000775000175000017500000000000013036015411014202 5ustar takakitakakijpype-0.6.2+dfsg/jpype/JClassUtil.py0000664000175000017500000000165213036015411016575 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from . import _jclass def isInterface(t): if not isinstance(t, _jclass._JavaClass): return False return t.__javaclass__.isInterface() jpype-0.6.2+dfsg/jpype/__init__.py0000664000175000017500000000226313036015411016316 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from ._jpackage import * from ._jclass import * from ._jarray import * from ._jwrapper import * from ._jproxy import * from ._jexception import * from ._core import * from ._gui import * from . import JClassUtil __version_info__ = (0, 6, 2) __version__ = ".".join(str(i) for i in __version_info__) def JIterator(it): """Deprecated""" return it java = JPackage("java") javax = JPackage("javax") jpype-0.6.2+dfsg/jpype/_core.py0000664000175000017500000000706513036015411015653 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import sys import _jpype from . import _jclass from . import _jarray from . import _jwrapper from . import _jproxy from . import _jexception from . import _jcollection from . import _jobject from . import _properties from . import nio from . import reflect from . import _refdaemon _usePythonThreadForDaemon = False def setUsePythonThreadForDeamon(v): global _usePythonThreadForDaemon _usePythonThreadForDaemon = v def isJVMStarted() : return _jpype.isStarted() def startJVM(jvm, *args): """ Starts a Java Virtual Machine :param jvm: Path to the jvm library file (libjvm.so, jvm.dll, ...) :param args: Arguments to give to the JVM """ _jpype.startup(jvm, tuple(args), True) _jclass._initialize() _jarray._initialize() _jwrapper._initialize() _jproxy._initialize() _jexception._initialize() _jcollection._initialize() _jobject._initialize() _properties._initialize() nio._initialize() reflect._initialize() # start the reference daemon thread if _usePythonThreadForDaemon: _refdaemon.startPython() else: _refdaemon.startJava() def attachToJVM(jvm): _jpype.attach(jvm) _jclass._initialize() _jarray._initialize() _jwrapper._initialize() _jproxy._initialize() _jexception._initialize() _jcollection._initialize() _jobject._initialize() _properties._initialize() def shutdownJVM(): _refdaemon.stop() _jpype.shutdown() def isThreadAttachedToJVM(): return _jpype.isThreadAttachedToJVM() def attachThreadToJVM(): _jpype.attachThreadToJVM() def detachThreadFromJVM(): _jpype.detachThreadFromJVM() def get_default_jvm_path(): """ Retrieves the path to the default or first found JVM library :return: The path to the JVM shared library file :raise ValueError: No JVM library found """ if sys.platform in ("win32", "cygwin"): # Windows or Cygwin from ._windows import WindowsJVMFinder finder = WindowsJVMFinder() elif sys.platform == "darwin": # Mac OS X from ._darwin import DarwinJVMFinder finder = DarwinJVMFinder() else: # Use the Linux way for other systems from ._linux import LinuxJVMFinder finder = LinuxJVMFinder() return finder.get_jvm_path() # Naming compatibility getDefaultJVMPath = get_default_jvm_path class ConversionConfigClass(object): def __init__(self): self._convertString = 1 def _getConvertString(self): return self._convertString def _setConvertString(self, value): if value: self._convertString = 1 else: self._convertString = 0 _jpype.setConvertStringObjects(self._convertString) string = property(_getConvertString, _setConvertString, None) ConversionConfig = ConversionConfigClass() jpype-0.6.2+dfsg/jpype/_darwin.py0000664000175000017500000000514013036015411016177 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** # Reuse the Linux code from ._linux import LinuxJVMFinder # ------------------------------------------------------------------------------ class DarwinJVMFinder(LinuxJVMFinder): """ Mac OS X JVM library finder class """ def __init__(self): """ Sets up members """ # Call the parent constructor LinuxJVMFinder.__init__(self) # Library file name self._libfile = "libjli.dylib" self._methods = list(self._methods) self._methods.append(self._pre_vm7_path) self._methods.append(self._javahome_binary) # Predefined locations self._locations = ('/Library/Java/JavaVirtualMachines',) def _pre_vm7_path(self): """ Returns the previous constant JVM library path: '/System/Library/Frameworks/JavaVM.framework/JavaVM' """ return '/System/Library/Frameworks/JavaVM.framework/JavaVM' def _javahome_binary(self): """ for osx > 10.5 we have the nice util /usr/libexec/java_home available. Invoke it and return its output. It seems this tool has been removed in osx 10.9. """ import platform import subprocess from distutils.version import StrictVersion current = StrictVersion(platform.mac_ver()[0][:4]) if current >= StrictVersion('10.6') and current < StrictVersion('10.9'): if hasattr(subprocess, 'check_output'): java_home = subprocess.check_output(['/usr/libexec/java_home']).strip() else: java_home = subprocess.Popen(['/usr/libexec/java_home'], stdout=subprocess.PIPE).communicate()[0] return java_home # ------------------------------------------------------------------------------ # Alias JVMFinder = DarwinJVMFinder jpype-0.6.2+dfsg/jpype/_gui.py0000664000175000017500000000245713036015411015507 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import sys from . import _jproxy from . import _jclass def setupGuiEnvironment(cb): if sys.platform == 'darwin': from PyObjCTools import AppHelper m = {'run': cb} proxy = _jproxy.JProxy('java.lang.Runnable', m) cbthread = _jclass.JClass("java.lang.Thread")(proxy) cbthread.start() AppHelper.runConsoleEventLoop() else: cb() def shutdownGuiEnvironment(): if sys.platform == 'darwin': from PyObjCTools import AppHelper AppHelper.stopEventLoop() jpype-0.6.2+dfsg/jpype/_jarray.py0000664000175000017500000001314613036015411016210 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import collections import sys import _jpype from . import _jclass from . import _jwrapper if sys.version > '3': unicode = str irange = range _CLASSES = {} _CUSTOMIZERS = [] def _initialize(): _jpype.setJavaArrayClass(_JavaArrayClass) _jpype.setGetJavaArrayClassMethod(_getClassFor) registerArrayCustomizer(CharArrayCustomizer()) registerArrayCustomizer(ByteArrayCustomizer()) def registerArrayCustomizer(c): _CUSTOMIZERS.append(c) class _JavaArrayClass(object): def __init__(self, jo): self.__javaobject__ = jo def __str__(self): return str(tuple(self)) def __len__(self): return _jpype.getArrayLength(self.__javaobject__) def __iter__(self): return _JavaArrayIter(self) def __getitem__(self, ndx): if isinstance(ndx, slice): start, stop, step = ndx.indices(len(self)) if step != 1: raise RuntimeError("Slicing with step unimplemented") return self.__getslice__(start, stop) return _jpype.getArrayItem(self.__javaobject__, ndx) def __setitem__(self, ndx, val): if isinstance(ndx, slice): start, stop, step = ndx.indices(len(self)) if step != 1: # Iterate in python if we need to step indices = irange(start, stop, step) for index, value in zip(indices, val): self[index] = value else: self.__setslice__(start, stop, val) return _jpype.setArrayItem(self.__javaobject__, ndx, val) def __getslice__(self, i, j): if j == sys.maxsize: j = _jpype.getArrayLength(self.__javaobject__) return _jpype.getArraySlice(self.__javaobject__, i, j) def __setslice__(self, i, j, v): if j == sys.maxsize: j = _jpype.getArrayLength(self.__javaobject__) _jpype.setArraySlice(self.__javaobject__, i, j, v) def _jarrayInit(self, *args): if len(args) == 2 and args[0] == _jclass._SPECIAL_CONSTRUCTOR_KEY: _JavaArrayClass.__init__(self, args[1]) elif len(args) != 1: raise TypeError( "Array classes only take 2 parameters, {0} given" .format(len(args) + 1)) else: values = None if isinstance(args[0], collections.Sequence): sz = len(args[0]) values = args[0] else: sz = args[0] _JavaArrayClass.__init__( self, _jpype.newArray(self.__class__.__javaclass__, sz)) if values is not None: _jpype.setArraySlice(self.__javaobject__, 0, sz, values) class _JavaArrayIter(object): def __init__(self, a): self._array = a self._ndx = -1 def __iter__(self): return self def __next__(self): self._ndx += 1 if self._ndx >= len(self._array): raise StopIteration return self._array[self._ndx] next = __next__ class _JavaArray(type): pass def _defineArrayClass(name, jt): members = { "__init__": _jarrayInit, "__javaclass__": jt, } bases = [_JavaArrayClass] for i in _CUSTOMIZERS: if i.canCustomize(name, jt): i.customize(name, jt, bases, members) return _JavaArray(name, tuple(bases), members) def _getClassFor(name): if name not in _CLASSES: jc = _jpype.findArrayClass(name) _CLASSES[name] = _defineArrayClass(name, jc) return _CLASSES[name] def JArray(t, ndims=1): if issubclass(t, _jwrapper._JWrapper): t = t.typeName elif isinstance(t, _JavaArray): t = t.typeName elif issubclass(t, _jclass._JAVAOBJECT): t = t.__name__ elif not isinstance(t, str) and not isinstance(t, unicode): raise TypeError("Argument must be a java class, java array class, " "java wrapper or string representing a java class") arrayTypeName = t + ('[]' * ndims) return _getClassFor(arrayTypeName) def _charArrayStr(self): return ''.join(self) def _charArrayUnicode(self): return u''.join(self) class CharArrayCustomizer(object): def canCustomize(self, name, jc): if name == 'char[]': return True return False def customize(self, name, jc, bases, members): members['__str__'] = _charArrayStr members['__unicode__'] = _charArrayUnicode def _byteArrayStr(self): s = _jclass.JClass('java.lang.String')(self) return s.toString() class ByteArrayCustomizer(object): def canCustomize(self, name, jc): if name == 'byte[]': return True return False def customize(self, name, jc, bases, members): members['__str__'] = _byteArrayStr jpype-0.6.2+dfsg/jpype/_jclass.py0000664000175000017500000001465713036015411016207 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import _jpype from ._pykeywords import KEYWORDS _CLASSES = {} _SPECIAL_CONSTRUCTOR_KEY = "This is the special constructor key" _JAVAOBJECT = None _JAVATHROWABLE = None _COMPARABLE = None _RUNTIMEEXCEPTION = None _CUSTOMIZERS = [] _COMPARABLE_METHODS = { "__cmp__": lambda self, o: self.compareTo(o) } def _initialize(): global _COMPARABLE, _JAVAOBJECT, _JAVATHROWABLE, _RUNTIMEEXCEPTION _JAVAOBJECT = JClass("java.lang.Object") _JAVATHROWABLE = JClass("java.lang.Throwable") _RUNTIMEEXCEPTION = JClass("java.lang.RuntimeException") _jpype.setJavaLangObjectClass(_JAVAOBJECT) _jpype.setGetClassMethod(_getClassFor) _jpype.setSpecialConstructorKey(_SPECIAL_CONSTRUCTOR_KEY) def registerClassCustomizer(c): _CUSTOMIZERS.append(c) def JClass(name): jc = _jpype.findClass(name) if jc is None: raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) return _getClassFor(jc) def _getClassFor(javaClass): name = javaClass.getName() if name in _CLASSES: return _CLASSES[name] pyJavaClass = _JavaClass(javaClass) _CLASSES[name] = pyJavaClass return pyJavaClass def _javaNew(self, *args): return object.__new__(self) def _javaExceptionNew(self, *args): return Exception.__new__(self) def _javaInit(self, *args): object.__init__(self) if len(args) == 1 and isinstance(args[0], tuple) \ and args[0][0] is _SPECIAL_CONSTRUCTOR_KEY: self.__javaobject__ = args[0][1] else: self.__javaobject__ = self.__class__.__javaclass__.newClassInstance( *args) def _javaGetAttr(self, name): try: r = object.__getattribute__(self, name) except AttributeError as ex: if name in dir(self.__class__.__metaclass__): r = object.__getattribute__(self.__class__, name) else: raise ex if isinstance(r, _jpype._JavaMethod): return _jpype._JavaBoundMethod(r, self) return r def _mro_override_topsort(cls): # here we run a topological sort to get a linear ordering of the inheritance graph. parents = set().union(*[x.__mro__ for x in cls.__bases__]) numsubs = dict() for cls1 in parents: numsubs[cls1] = len([cls2 for cls2 in parents if cls1 != cls2 and issubclass(cls2,cls1)]) mergedmro = [cls] while numsubs: for k1,v1 in numsubs.items(): if v1 != 0: continue mergedmro.append(k1) for k2,v2 in numsubs.items(): if issubclass(k1,k2): numsubs[k2] = v2-1 del numsubs[k1] break return mergedmro class _MetaClassForMroOverride(type): def mro(cls): return _mro_override_topsort(cls) class _JavaClass(type): def __new__(cls, jc): bases = [] name = jc.getName() static_fields = {} members = { "__javaclass__": jc, "__init__": _javaInit, "__str__": lambda self: self.toString(), "__hash__": lambda self: self.hashCode(), "__eq__": lambda self, o: self.equals(o), "__ne__": lambda self, o: not self.equals(o), "__getattribute__": _javaGetAttr, } if name == 'java.lang.Object' or jc.isPrimitive(): bases.append(object) elif not jc.isInterface(): bjc = jc.getBaseClass() bases.append(_getClassFor(bjc)) if _JAVATHROWABLE is not None and jc.isSubclass("java.lang.Throwable"): from . import _jexception members["PYEXC"] = _jexception._makePythonException(name, bjc) itf = jc.getBaseInterfaces() for ic in itf: bases.append(_getClassFor(ic)) if len(bases) == 0: bases.append(_JAVAOBJECT) # add the fields fields = jc.getClassFields() for i in fields: fname = i.getName() if fname in KEYWORDS: fname += "_" if i.isStatic(): g = lambda self, fld=i: fld.getStaticAttribute() s = None if not i.isFinal(): s = lambda self, v, fld=i: fld.setStaticAttribute(v) static_fields[fname] = property(g, s) else: g = lambda self, fld=i: fld.getInstanceAttribute( self.__javaobject__) s = None if not i.isFinal(): s = lambda self, v, fld=i: fld.setInstanceAttribute( self.__javaobject__, v) members[fname] = property(g, s) # methods methods = jc.getClassMethods() # Return tuple of tuple (name, method). for jm in methods: mname = jm.getName() if mname in KEYWORDS: mname += "_" members[mname] = jm for i in _CUSTOMIZERS: if i.canCustomize(name, jc): i.customize(name, jc, bases, members) # Prepare the meta-metaclass meta_bases = [] for i in bases: if i is object: meta_bases.append(cls) else: meta_bases.append(i.__metaclass__) static_fields['mro'] = _mro_override_topsort metaclass = type.__new__(_MetaClassForMroOverride, name + "$$Static", tuple(meta_bases), static_fields) members['__metaclass__'] = metaclass result = type.__new__(metaclass, name, tuple(bases), members) return result jpype-0.6.2+dfsg/jpype/_jcollection.py0000664000175000017500000002013413036015411017220 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import collections from . import _jclass class _WrappedIterator(object): """ Wraps a Java iterator to respect the Python 3 iterator API """ def __init__(self, iterator): self.iterator = iterator def __iter__(self): return self.iterator def __next__(self): return next(self.iterator) # Compatibility name next = __next__ def _initialize(): _jclass.registerClassCustomizer(CollectionCustomizer()) _jclass.registerClassCustomizer(ListCustomizer()) _jclass.registerClassCustomizer(MapCustomizer()) _jclass.registerClassCustomizer(IteratorCustomizer()) _jclass.registerClassCustomizer(EnumerationCustomizer()) def isPythonSequence(v): if isinstance(v, collections.Sequence): if not hasattr(v.__class__, '__metaclass__') \ or v.__class__.__metaclass__ is _jclass._JavaClass: return True return False def _colLength(self): return self.size() def _colIter(self): return _WrappedIterator(self.iterator()) def _colDelItem(self, i): return self.remove(i) def _colAddAll(self, v): if isPythonSequence(v): r = False for i in v: r = self.add(i) or r return r else: return self._addAll(v) def _colRemoveAll(self, v): if isPythonSequence(v): r = False for i in v: r = self.remove(i) or r return r else: return self._removeAll(v) def _colRetainAll(self, v): if isPythonSequence(v): r = _jclass.JClass("java.util.ArrayList")(len(v)) for i in v: r.add(i) else: r = v return self._retainAll(r) class CollectionCustomizer(object): _METHODS = { '__len__': _colLength, '__iter__': _colIter, '__delitem__': _colDelItem, } def canCustomize(self, name, jc): if name == 'java.util.Collection': return True return jc.isSubclass('java.util.Collection') def customize(self, name, jc, bases, members): if name == 'java.util.Collection': members.update(CollectionCustomizer._METHODS) else: # AddAll is handled by List if (not jc.isSubclass("java.util.List")) and 'addAll' in members: members['_addAll'] = members['addAll'] members['addAll'] = _colAddAll if 'removeAll' in members: members['_removeAll'] = members['removeAll'] members['removeAll'] = _colRemoveAll if 'retainAll' in members: members['_retainAll'] = members['retainAll'] members['retainAll'] = _colRetainAll def _listGetItem(self, ndx): if isinstance(ndx, slice): start = ndx.start stop = ndx.stop if start < 0: start = self.size() + start if stop < 0: stop = self.size() + stop return self.subList(start, stop) else: if ndx < 0: ndx = self.size() + ndx return self.get(ndx) def _listSetItem(self, ndx, v): if isinstance(ndx, slice): start = ndx.start stop = ndx.stop if start < 0: start = self.size() + start if stop < 0: stop = self.size() + stop for i in range(start, stop): self.remove(start) if isinstance(v, collections.Sequence): ndx = start for i in v: self.add(ndx, i) ndx += 1 else: if ndx < 0: ndx = self.size() + ndx self.set(ndx, v) def _listAddAll(self, v, v2=None): if isPythonSequence(v): r = False if v2 is not None: # assume form (int, values) for i in range(len(v2)): r = r or self.add(v + i, v2[i]) else: for i in v: r = self.add(i) or r return r else: return self._addAll(v) class ListCustomizer(object): _METHODS = { '__setitem__': _listSetItem, '__getitem__': _listGetItem, } def canCustomize(self, name, jc): if name == 'java.util.List': return True return jc.isSubclass('java.util.List') def customize(self, name, jc, bases, members): if name == 'java.util.List': members.update(ListCustomizer._METHODS) else: if 'addAll' in members: members['_addAll'] = members['addAll'] members['addAll'] = _listAddAll def isPythonMapping(v): if isinstance(v, collections.Mapping): if not hasattr(v.__class__, '__metaclass__') or \ v.__class__.__metaclass__ is _jclass._JavaClass: return True return False def _mapLength(self): return self.size() def _mapIter(self): return _WrappedIterator(self.keySet().iterator()) def _mapDelItem(self, i): return self.remove(i) def _mapGetItem(self, ndx): return self.get(ndx) def _mapSetItem(self, ndx, v): self.put(ndx, v) def _mapPutAll(self, v): if isPythonMapping(v): for i in v: self.put(i, v[i]) else: # do the regular method ... self._putAll(v) class MapCustomizer(object): _METHODS = { '__len__': _mapLength, '__iter__': _mapIter, '__delitem__': _mapDelItem, '__getitem__': _mapGetItem, '__setitem__': _mapSetItem, } def canCustomize(self, name, jc): if name == 'java.util.Map': return True return jc.isSubclass('java.util.Map') def customize(self, name, jc, bases, members): if name == 'java.util.Map': members.update(MapCustomizer._METHODS) else: if "putAll" in members: members["_putAll"] = members["putAll"] members["putAll"] = _mapPutAll def _iterCustomNext(self): if self.hasNext(): return self._next() raise StopIteration def _iterIteratorNext(self): if self.hasNext(): return next(self) raise StopIteration def _iterIter(self): return self class IteratorCustomizer(object): _METHODS = { '__iter__': _iterIter, '__next__': _iterCustomNext, } def canCustomize(self, name, jc): if name == 'java.util.Iterator': return True return jc.isSubclass('java.util.Iterator') def customize(self, name, jc, bases, members): if name == 'java.util.Iterator': members.update(IteratorCustomizer._METHODS) elif jc.isSubclass('java.util.Iterator'): __next__ = 'next' if 'next' in members else '__next__' members['_next'] = members[__next__] members[__next__] = _iterCustomNext def _enumNext(self): if self.hasMoreElements(): return self.nextElement() raise StopIteration def _enumIter(self): return self class EnumerationCustomizer(object): _METHODS = { 'next': _enumNext, '__next__': _enumNext, '__iter__': _enumIter, } def canCustomize(self, name, jc): return name == 'java.util.Enumeration' def customize(self, name, jc, bases, members): members.update(EnumerationCustomizer._METHODS) jpype-0.6.2+dfsg/jpype/_jexception.py0000664000175000017500000000454013036015411017066 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import _jpype from . import _jclass _CLASSES = {} def JException(t): return t.PYEXC class JavaException(Exception): def __init__(self, *data): if isinstance(data[0], tuple) \ and data[0][0] is _jclass._SPECIAL_CONSTRUCTOR_KEY: # this is wrapped: self.__javaobject__ = data[0][1] self.__javaclass__ = self.__javaobject__.__class__ else: self.__javaclass__ = _jclass.JClass(self.__class__.JAVACLASSNAME) self.__javaobject__ = self.__javaclass__(*data) Exception.__init__(self, self.__javaobject__) def javaClass(self): return self.__javaclass__ def message(self): return self.__javaobject__.getMessage() def stacktrace(self): StringWriter = _jclass.JClass("java.io.StringWriter") PrintWriter = _jclass.JClass("java.io.PrintWriter") sw = StringWriter() pw = PrintWriter(sw) self.__javaobject__.printStackTrace(pw) pw.flush() r = sw.toString() sw.close() return r def __str__(self): return self.__javaobject__.toString() def _initialize(): _jpype.setJavaExceptionClass(JavaException) def _makePythonException(name, bc): if name in _CLASSES: return _CLASSES[name] if name == 'java.lang.Throwable': bases = (JavaException,) else: bases = (_makePythonException(bc.getName(), bc.getBaseClass()) ,) ec = type(name+"PyRaisable", bases, {'JAVACLASSNAME': name}) _CLASSES[name] = ec return ec jpype-0.6.2+dfsg/jpype/_jobject.py0000664000175000017500000000226513036015411016340 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from . import _jclass def _initialize(): _jclass.registerClassCustomizer(ComparableCustomizer()) class ComparableCustomizer(object): _METHODS = { "__cmp__": lambda self, o: self.compareTo(o) } def canCustomize(self, name, jc): return name == 'java.lang.Comparable' def customize(self, name, jc, bases, members): members.update(ComparableCustomizer._METHODS) jpype-0.6.2+dfsg/jpype/_jpackage.py0000664000175000017500000000424313036015411016463 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import _jpype from . import _jclass class JPackage(object): def __init__(self, name): self.__name = name def __getattribute__(self, n): try: return object.__getattribute__(self, n) except: # not found ... # perhaps it is a class? subname = "{0}.{1}".format(self.__name, n) from jpype import isJVMStarted if not isJVMStarted(): import warnings warnings.warn("JVM not started yet, can not inspect JPackage contents") return n cc = _jpype.findClass(subname) if cc is None: # can only assume it is a sub-package then ... cc = JPackage(subname) else: cc = _jclass._getClassFor(cc) self.__setattr__(n, cc, True) return cc def __setattr__(self, n, v, intern=False): if not n[:len('_JPackage')] == '_JPackage' \ and not intern: # NOTE this shadows name mangling raise RuntimeError("Cannot set attributes in a package {0}" .format(n)) object.__setattr__(self, n, v) def __str__(self): return "".format(self.__name) def __call__(self, *arg, **kwarg): raise TypeError("Package {0} is not Callable".format(self.__name)) jpype-0.6.2+dfsg/jpype/_jproxy.py0000664000175000017500000000513613036015411016253 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import collections import sys import _jpype from . import _jclass from . import JClassUtil if sys.version > '3': unicode = str def _initialize(): _jpype.setProxyClass(JProxy) class JProxy(object): def __init__(self, intf, dict=None, inst=None): actualIntf = None if isinstance(intf, str) or isinstance(intf, unicode): actualIntf = [_jclass.JClass(intf)] elif isinstance(intf, _jclass._JavaClass): actualIntf = [intf] elif isinstance(intf, collections.Sequence): actualIntf = [] for i in intf: if isinstance(i, str) or isinstance(i, unicode): actualIntf.append(_jclass.JClass(i)) elif isinstance(i, _jclass._JavaClass): actualIntf.append(i) else: raise TypeError("JProxy requires java interface classes " "or the names of java interfaces classes") else: raise TypeError("JProxy requires java interface classes " "or the names of java interfaces classes") for i in actualIntf: if not JClassUtil.isInterface(i): raise TypeError("JProxy requires java interface classes " "or the names of java interfaces classes: {0}" .format(i.__name__)) if dict is not None and inst is not None: raise RuntimeError("Specify only one of dict and inst") self._dict = dict self._inst = inst self._proxy = _jpype.createProxy(self, actualIntf) def getCallable(self, name): if self._dict is not None: return self._dict[name] else: return getattr(self._inst, name) jpype-0.6.2+dfsg/jpype/_jvmfinder.py0000664000175000017500000001374513036015411016711 0ustar takakitakaki#***************************************************************************** # Copyright 2013 Thomas Calmant # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import os # ------------------------------------------------------------------------------ class JVMNotFoundException(RuntimeError): pass class JVMNotSupportedException(RuntimeError): pass class JVMFinder(object): """ JVM library finder base class """ def __init__(self): """ Sets up members """ # Library file name self._libfile = "libjvm.so" # Predefined locations self._locations = ("/usr/lib/jvm", "/usr/java") # Search methods self._methods = (self._get_from_java_home, self._get_from_known_locations) def find_libjvm(self, java_home): """ Recursively looks for the given file :param java_home: A Java home folder :param filename: Name of the file to find :return: The first found file path, or None """ found_jamvm = False non_supported_jvm = ('cacao', 'jamvm') found_non_supported_jvm = False # Look for the file for root, _, names in os.walk(java_home): if self._libfile in names: # Found it, but check for non supported jvms candidate = os.path.split(root)[1] if candidate in non_supported_jvm: found_non_supported_jvm = True continue # maybe we will find another one? return os.path.join(root, self._libfile) else: if found_non_supported_jvm: raise JVMNotSupportedException("Sorry '{0}' is known to be " "broken. Please ensure your " "JAVA_HOME contains at least " "another JVM implementation " "(eg. server)" .format(candidate)) # File not found raise JVMNotFoundException("Sorry no JVM could be found. " "Please ensure your JAVA_HOME " "environment variable is pointing " "to correct installation.") def find_possible_homes(self, parents): """ Generator that looks for the first-level children folders that could be Java installations, according to their name :param parents: A list of parent directories :return: The possible JVM installation folders """ homes = [] java_names = ('jre', 'jdk', 'java') for parent in parents: for childname in sorted(os.listdir(parent)): # Compute the real path path = os.path.realpath(os.path.join(parent, childname)) if path in homes or not os.path.isdir(path): # Already known path, or not a directory -> ignore continue # Check if the path seems OK real_name = os.path.basename(path).lower() for java_name in java_names: if java_name in real_name: # Correct JVM folder name homes.append(path) yield path break def get_jvm_path(self): """ Retrieves the path to the default or first found JVM library :return: The path to the JVM shared library file :raise ValueError: No JVM library found """ for method in self._methods: try: jvm = method() except NotImplementedError: # Ignore missing implementations pass except JVMNotFoundException: # Ignore not successful methods pass else: if jvm is not None: return jvm else: raise JVMNotFoundException("No JVM shared library file ({0}) " "found. Try setting up the JAVA_HOME " "environment variable properly." .format(self._libfile)) def _get_from_java_home(self): """ Retrieves the Java library path according to the JAVA_HOME environment variable :return: The path to the JVM library, or None """ # Get the environment variable java_home = os.getenv("JAVA_HOME") if java_home and os.path.exists(java_home): # Get the real installation path java_home = os.path.realpath(java_home) # Look for the library file return self.find_libjvm(java_home) def _get_from_known_locations(self): """ Retrieves the first existing Java library path in the predefined known locations :return: The path to the JVM library, or None """ for home in self.find_possible_homes(self._locations): jvm = self.find_libjvm(home) if jvm is not None: return jvm jpype-0.6.2+dfsg/jpype/_jwrapper.py0000664000175000017500000000533313036015411016551 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import sys import _jpype from . import _jclass from ._jpackage import JPackage if sys.version > '3': unicode = str long = int def _initialize(): _jpype.setWrapperClass(_JWrapper) _jpype.setStringWrapperClass(JString) class _JWrapper(object): def __init__(self, v): if v is not None: self._value = _jpype.convertToJValue(self.typeName, v) else: self._value = None class JByte(_JWrapper): typeName = "byte" class JShort(_JWrapper): typeName = "short" class JInt(_JWrapper): typeName = "int" class JLong(_JWrapper): typeName = "long" class JFloat(_JWrapper): typeName = "float" class JDouble(_JWrapper): typeName = "double" class JChar(_JWrapper): typeName = "char" class JBoolean(_JWrapper): typeName = "boolean" class JString(_JWrapper): typeName = "java.lang.String" def _getDefaultTypeName(obj): if obj is True or obj is False: return 'java.lang.Boolean' if isinstance(obj, str) or isinstance(obj, unicode): return "java.lang.String" if isinstance(obj, int): return "java.lang.Integer" if isinstance(obj, long): return "java.lang.Long" if isinstance(obj, float): return "java.lang.Double" if isinstance(obj, _jclass._JavaClass): return obj.__javaclassname__ if isinstance(obj, JPackage("java").lang.Class): return obj.__class__.__javaclass__.getName() if isinstance(obj, _JWrapper): return obj.typeName raise TypeError( "Unable to determine the default type of {0}".format(obj.__class__)) class JObject(_JWrapper): def __init__(self, v, tp=None): if tp is None: tp = _getDefaultTypeName(v) if isinstance(tp, _jclass._JavaClass): tp = tp.__javaclass__.getName() self.typeName = tp self._value = _jpype.convertToJValue(tp, v) jpype-0.6.2+dfsg/jpype/_linux.py0000664000175000017500000000425213036015411016055 0ustar takakitakaki#***************************************************************************** # Copyright 2013 Thomas Calmant # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import os from . import _jvmfinder # ------------------------------------------------------------------------------ class LinuxJVMFinder(_jvmfinder.JVMFinder): """ Linux JVM library finder class """ def __init__(self): """ Sets up members """ # Call the parent constructor _jvmfinder.JVMFinder.__init__(self) # Java bin file self._java = "/usr/bin/java" # Library file name self._libfile = "libjvm.so" # Predefined locations self._locations = ("/usr/lib/jvm", "/usr/java", "/opt/sun") # Search methods self._methods = (self._get_from_java_home, self._get_from_bin, self._get_from_known_locations) def _get_from_bin(self): """ Retrieves the Java library path according to the real installation of the java executable :return: The path to the JVM library, or None """ # Find the real interpreter installation path java_bin = os.path.realpath(self._java) if os.path.exists(java_bin): # Get to the home directory java_home = os.path.abspath(os.path.join(os.path.dirname(java_bin), '..')) # Look for the JVM library return self.find_libjvm(java_home) jpype-0.6.2+dfsg/jpype/_properties.py0000664000175000017500000000636313036015411017117 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import _jpype from . import _jclass _PROPERTY_ACCESSOR_PREFIX_LEN = 3 def _initialize() : _jclass.registerClassCustomizer(PropertiesCustomizer()) def _extract_accessor_pairs(members): """Extract pairs of corresponding property access methods (getter and setter) from a Java class's members (attributes). If a public method with a property's name exists no pair for that property will be extracted. Returns a dictionary with the property name as key and a tuple of (getter method, setter method) as value. A tuple element value might be `None` if only a getter or only a setter exists. """ accessor_pairs = {} for name, member in members.items(): if not (len(name) > _PROPERTY_ACCESSOR_PREFIX_LEN \ and _is_java_method(member)): continue access, rest = ( name[:_PROPERTY_ACCESSOR_PREFIX_LEN], name[_PROPERTY_ACCESSOR_PREFIX_LEN:] ) property_name = rest[:1].lower() + rest[1:] if property_name in members: if _is_java_method(members[property_name]): continue if access == 'get' and member.isBeanAccessor(): try: pair = accessor_pairs[property_name] pair[0] = member except KeyError: accessor_pairs[property_name] = [member, None] elif access == 'set' and member.isBeanMutator(): try: pair = accessor_pairs[property_name] pair[1] = member except KeyError: accessor_pairs[property_name] = [None, member] return accessor_pairs def _is_java_method(attribute): return isinstance(attribute, _jpype._JavaMethod) class PropertiesCustomizer(object) : def canCustomize(self, name, jc) : return True def customize(self, class_name, jc, bases, members) : accessor_pairs = _extract_accessor_pairs(members) for attr_name, (getter, setter) in accessor_pairs.items(): if attr_name in members: if not getter: # add default getter if we # only have a setter getter = members[attr_name].fget elif not setter: # add default setter if we # only have a getter setter = members[attr_name].fset members[attr_name] = property(getter, setter) jpype-0.6.2+dfsg/jpype/_pykeywords.py0000664000175000017500000000206613036015411017137 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** KEYWORDS = set(( "del", "for", "is", "raise", "assert", "elif", "from", "lambda", "return", "break", "else", "global", "not", "try", "class", "except", "if", "or", "while", "continue", "exec", "import", "pass", "yield", "def", "finally", "in", "print", "as", "None" )) jpype-0.6.2+dfsg/jpype/_refdaemon.py0000664000175000017500000000206613036015411016657 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import threading import _jpype def startJava(): _jpype.startReferenceQueue(1) def startPython(): def _run(): _jpype.attachThreadToJVM() _jpype.startReferenceQueue(0) threading.Thread(target=_run).start() def stop(): _jpype.stopReferenceQueue() jpype-0.6.2+dfsg/jpype/_windows.py0000664000175000017500000000422013036015411016403 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from . import _jvmfinder try: import _winreg as winreg except ImportError: import winreg # in Py3, winreg has been moved # ------------------------------------------------------------------------------ class WindowsJVMFinder(_jvmfinder.JVMFinder): """ Linux JVM library finder class """ def __init__(self): """ Sets up members """ # Call the parent constructor _jvmfinder.JVMFinder.__init__(self) # Library file name self._libfile = "jvm.dll" # Search methods self._methods = (self._get_from_java_home, self._get_from_registry) def _get_from_registry(self): """ Retrieves the path to the default Java installation stored in the Windows registry :return: The path found in the registry, or None """ try : jreKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Runtime Environment") cv = winreg.QueryValueEx(jreKey, "CurrentVersion") versionKey = winreg.OpenKey(jreKey, cv[0]) winreg.CloseKey(jreKey) cv = winreg.QueryValueEx(versionKey, "RuntimeLib") winreg.CloseKey(versionKey) return cv[0] except WindowsError: return None jpype-0.6.2+dfsg/jpype/awt/0000775000175000017500000000000013036015411014775 5ustar takakitakakijpype-0.6.2+dfsg/jpype/awt/__init__.py0000664000175000017500000000143613036015411017112 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from . import event jpype-0.6.2+dfsg/jpype/awt/event/0000775000175000017500000000000013036015411016116 5ustar takakitakakijpype-0.6.2+dfsg/jpype/awt/event/WindowAdapter.py0000664000175000017500000000102713036015411021240 0ustar takakitakakiclass WindowAdapter(object) : def __init__(self, *mth, **kw) : object.__init__(self) for i, j in kw.items() : setattr(self, i, j) def windowActivated(self, e) : pass def windowClosed(self, e) : pass def windowClosing(self, e) : pass def windowDeactivated(self, e) : pass def windowDeiconified(self, e) : pass def windowIconified(self, e) : pass def windowOpened(self, e) : pass jpype-0.6.2+dfsg/jpype/awt/event/__init__.py0000664000175000017500000000144713036015411020235 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from .WindowAdapter import * jpype-0.6.2+dfsg/jpype/nio.py0000664000175000017500000000253413036015411015345 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import sys import _jpype if sys.version_info < (2, 7): _mem_view = _jpype.memoryview # own memoryview implementation else: _mem_view = memoryview def _initialize() : pass def convertToDirectBuffer(obj): __doc__ = '''Efficiently convert all array.array and numpy ndarray types, string and unicode to java.nio.Buffer objects.''' memoryview_of_obj = _mem_view(obj) if memoryview_of_obj.readonly: raise ValueError("Memoryview must be writable for wrapping in a byte buffer") return _jpype.convertToDirectBuffer(memoryview_of_obj) jpype-0.6.2+dfsg/jpype/reflect.py0000664000175000017500000000420413036015411016200 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import _jpype def _initialize() : pass def getConstructors(clas): return clas.__javaclass__.getConstructors() def getDeclaredConstructors(clas): return clas.__javaclass__.getDeclaredConstructors() def getDeclaredFields(clas) : '''Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object.''' return clas.__javaclass__.getDeclaredFields() def getDeclaredMethods(clas): '''Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object.''' return clas.__javaclass__.getDeclaredMethods() def getFields(clas): '''Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object.''' return clas.__javaclass__.getFields() def getMethods(clas): '''Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.''' return clas.__javaclass__.getMethods() def getModifiers(clas): '''Returns the Java language modifiers for this class or interface, encoded in an integer.''' return clas.__javaclass__.getModifiers() jpype-0.6.2+dfsg/jpypex/0000775000175000017500000000000013036015411014372 5ustar takakitakakijpype-0.6.2+dfsg/jpypex/__init__.py0000664000175000017500000000143613036015411016507 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from . import swing jpype-0.6.2+dfsg/jpypex/swing/0000775000175000017500000000000013036015411015521 5ustar takakitakakijpype-0.6.2+dfsg/jpypex/swing/AbstractAction.py0000664000175000017500000000407713036015411021004 0ustar takakitakakifrom jpype import java, javax, JProxy class AbstractAction(object): ACCELERATOR_KEY = javax.swing.Action.ACCELERATOR_KEY ACTION_COMMAND_KEY = javax.swing.Action.ACTION_COMMAND_KEY DEFAULT = javax.swing.Action.DEFAULT LONG_DESCRIPTION = javax.swing.Action.LONG_DESCRIPTION MNEMONIC_KEY = javax.swing.Action.MNEMONIC_KEY NAME = javax.swing.Action.NAME SHORT_DESCRIPTION = javax.swing.Action.SHORT_DESCRIPTION SMALL_ICON = javax.swing.Action.SMALL_ICON def __init__(self, cb, name=None, icon=None): object.__init__(self) self.__proxy = JProxy(javax.swing.Action, inst=self) self.__values = {} self.__cb = cb self.__listeners = [] self.__enabled = True if name is not None: self.putValue(AbstractAction.NAME, name) if icon is not None: self.putValue(AbstractAction.SMALL_ICON, icon) proxy = property(lambda self: self.__proxy) def addPropertyChangeListener(self, listener): self.__listeners.append(listener) def getValue(self, key): return self.__values.get(key, None) def isEnabled(self): if self.__enabled: return True return False def putValue(self, key, value): oldVal = self.__values.get(key, None) if oldVal != value: self.__values[key] = value self.__notify(key, oldVal, value) def removePropertyChangeListener(self, listener): self.__listeners.remove(listener) def setEnabled(self, b): if (b and not self.__enabled) or (not b and self.__enabled): self.__enabled = b self.__notify("enabled", java.lang.Boolean(not b), java.lang.Boolean(b)) def actionPerformed(self, ev): self.__cb(ev) def __notify(self, k, oldVal, newVal): ev = java.beans.PropertyChangeEvent(self.__proxy, k, oldVal, newVal) for i in self.__listeners: i.propertyChange(ev) jpype-0.6.2+dfsg/jpypex/swing/__init__.py0000664000175000017500000000145013036015411017632 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from .AbstractAction import * jpype-0.6.2+dfsg/jpypex/swing/pyutils.py0000664000175000017500000000113313036015411017602 0ustar takakitakakiimport sys from jpype import javax, JObject __JMenuBar = javax.swing.JMenuBar __JMenu = javax.swing.JMenu def buildMenuBar(menuDef): mb = __JMenuBar() for i in menuDef: jm = buildMenu(i[0], i[1]) mb.add(JObject(jm, __JMenu)) return mb def buildMenu(name, menuDef): jm = __JMenu(name) for i in menuDef: if i is None: jm.addSeparator() elif isinstance(i, list) or isinstance(i, tuple): jm2 = buildMenu(i[0], i[1]) jm.add(jm2) else: jm.add(i.proxy) return jm jpype-0.6.2+dfsg/native/0000775000175000017500000000000013036015411014341 5ustar takakitakakijpype-0.6.2+dfsg/native/common/0000775000175000017500000000000013036015411015631 5ustar takakitakakijpype-0.6.2+dfsg/native/common/include/0000775000175000017500000000000013036015411017254 5ustar takakitakakijpype-0.6.2+dfsg/native/common/include/jp_array.h0000664000175000017500000000357213036015411021243 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPARRAY_H_ #define _JPARRAY_H_ #ifndef PyObject_HEAD struct _object; typedef _object PyObject; #endif /** * Class to wrap Java Class and provide low-level behavior */ class JPArray : public JPObjectBase { public : JPArray(const JPTypeName& name, jarray inst); virtual~ JPArray(); public : JPArrayClass* getClass() { return m_Class; } int getLength(); vector getRange(int start, int stop); // return Python Sequence from underlying jarray PyObject* getSequenceFromRange(int start, int stop); void setRange(int start, int stop, vector& val); void setRange(int start, int stop, PyObject* sequence); void setItem(int ndx, HostRef*); HostRef* getItem(int ndx); void setContent(vector& data) { setRange(0, getLength(), data); } jobject getObject() { return JPEnv::getJava()->NewLocalRef(m_Object); } public : // Wrapper virtual JPType* getType(); virtual jvalue getValue(); virtual JCharString toString(); private : JPArrayClass* m_Class; jarray m_Object; }; #endif // _JPARRAY_H_ jpype-0.6.2+dfsg/native/common/include/jp_arrayclass.h0000664000175000017500000000256713036015411022274 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPARRAYCLASS_H_ #define _JPARRAYCLASS_H_ /** * Class to wrap Java Class and provide low-level behavior */ class JPArrayClass : public JPClassBase { public : JPArrayClass(const JPTypeName& tname, jclass c); virtual~ JPArrayClass(); public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual JPType* getComponentType() { return m_ComponentType; } JPArray* newInstance(int length); public : JPType* m_ComponentType; }; #endif // _JPARRAYCLASS_H_ jpype-0.6.2+dfsg/native/common/include/jp_class.h0000664000175000017500000000555413036015411021234 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPCLASS_H_ #define _JPCLASS_H_ /** * Class to wrap Java Class and provide low-level behavior */ class JPClass : public JPClassBase { public : JPClass(const JPTypeName& tname, jclass c); virtual~ JPClass(); public : /** * Called to fully load base classes and members */ void postLoad(); HostRef* getStaticAttribute(const string& attr_name); void setStaticAttribute(const string& attr_name, HostRef* val); JPObject* newInstance(vector& args); JPField* getInstanceField(const string& name); JPField* getStaticField(const string& name); JPMethod* getMethod(const string& name); vector getMethods() const { vector res; res.reserve(m_Methods.size()); for (map::const_iterator cur = m_Methods.begin(); cur != m_Methods.end(); cur++) { res.push_back(cur->second); } return res; } jclass getClass() { return (jclass)JPEnv::getJava()->NewGlobalRef(m_Class); } map& getStaticFields() { return m_StaticFields; } map& getInstanceFields() { return m_InstanceFields; } bool isFinal(); bool isAbstract(); bool isInterface() { return m_IsInterface; } JPClass* getSuperClass(); const vector& getInterfaces() const; bool isSubclass(JPClass*); string describe(); public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); private : void loadSuperClass(); void loadSuperInterfaces(); void loadFields(); void loadMethods(); void loadConstructors(); jvalue buildObjectWrapper(HostRef* obj); private : bool m_IsInterface; JPClass* m_SuperClass; vector m_SuperInterfaces; map m_StaticFields; map m_InstanceFields; map m_Methods; JPMethod* m_Constructors; }; #endif // _JPCLASS_H_ jpype-0.6.2+dfsg/native/common/include/jp_classbase.h0000664000175000017500000000257713036015411022071 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPCLASS_BASE_H_ #define _JPCLASS_BASE_H_ /** * Base class for Java Class based types */ class JPClassBase : public JPObjectType { protected : JPClassBase(const JPTypeName& tname, jclass c); virtual ~JPClassBase(); public : // JPType implementation virtual const JPTypeName& getName() const { return m_Name; } virtual const JPTypeName& getObjectType() const { return m_Name; } virtual jclass getClass() const { return (jclass)JPEnv::getJava()->NewLocalRef(m_Class); } protected : JPTypeName m_Name; jclass m_Class; }; #endif // _JPCLASS_BASE_H_ jpype-0.6.2+dfsg/native/common/include/jp_env.h0000664000175000017500000000503513036015411020711 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPENV_H_ #define _JPENV_H_ /** * Simple tample class for managing local java references. */ class JPCleaner { public : JPCleaner(); virtual ~JPCleaner(); void addGlobal(jobject r); void removeGlobal(jobject r); void addAllGlobal(vector& r); void addAllGlobal(vector& r); void removeAllGlobal(vector& r); void addLocal(jobject r); void removeLocal(jobject r); void addAllLocal(vector& r); void addAllLocal(vector& r); void removeAllLocal(vector& r); void add(HostRef* r); void addAll(vector& r); void remove(HostRef* r); void removeAll(vector& r); private : vector m_GlobalJavaObjects; vector m_LocalJavaObjects; vector m_HostObjects; }; template class JPMallocCleaner { public : JPMallocCleaner(size_t size) { mData = (T*)malloc(sizeof(T)*size); } ~JPMallocCleaner() { free(mData); } T& operator[](size_t ndx) { return mData[ndx]; } T* borrow() { return mData; } private : T* mData; }; namespace JPEnv { /** * Initialize the JPype subs-system. Does NOT load the JVM */ void init(HostEnvironment* hostEnv); /** * Load the JVM * TODO : add the non-string parameters, for possible callbacks */ void loadJVM(const string& vmPath, char ignoreUnrecognized, const StringVector& args); void attachJVM(const string& vmPath); void attachCurrentThread(); void attachCurrentThreadAsDaemon(); bool isThreadAttached(); JPJavaEnv* getJava(); HostEnvironment* getHost(); /** * Check if the JPype environment has been initialized */ bool isInitialized(); void registerRef(HostRef*, HostRef* targetRef); } #endif // _JPENV_H_ jpype-0.6.2+dfsg/native/common/include/jp_field.h0000664000175000017500000000334113036015411021202 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPFIELD_H_ #define _JPFIELD_H_ /** * Field object */ class JPField { public : /** * default constructor */ JPField(); /** * Create a new field based on class and java.lang.Field object */ JPField(JPClass* clazz, jobject fld); JPField(const JPField&); /** * destructor */ virtual ~JPField(); public : bool isStatic() const; const string& getName() const; const JPTypeName& getType() const { return m_Type; } HostRef* getStaticAttribute(); void setStaticAttribute(HostRef* val); HostRef* getAttribute(jobject inst); void setAttribute(jobject inst, HostRef* val); bool isFinal() const { return m_IsFinal; } private : string m_Name; JPClass* m_Class; bool m_IsStatic; bool m_IsFinal; jobject m_Field; jfieldID m_FieldID; JPTypeName m_Type; }; #endif // _JPFIELD_H_ jpype-0.6.2+dfsg/native/common/include/jp_hostenv.h0000664000175000017500000001223713036015411021611 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPHOSTENV_H_ #define _JPHOSTENV_H_ class HostRef { public : HostRef(void* data, bool acquire); HostRef(void* data); virtual ~HostRef(); HostRef(const HostRef&); HostRef& operator=(const HostRef&); public : HostRef* copy(); void release(); bool isNull(); void* data(); private : void* m_HostData; }; // Pre-declare those required types class JPArray; class JPArrayClass; class JPClass; class JPMethod; class JPObject; class JPProxy; class HostEnvironment { public : virtual ~HostEnvironment() {} virtual void* acquireRef(void*) = 0; virtual void releaseRef(void*) = 0; virtual bool isRefNull(void*) = 0; virtual string describeRef(HostRef*) = 0; virtual void* gotoExternal() = 0; virtual void returnExternal(void*) = 0; virtual void setRuntimeException(const char* msg) = 0; virtual void setAttributeError(const char* msg) = 0; virtual void setTypeError(const char* msg) = 0; virtual void raise(const char* msg) = 0; virtual HostRef* getNone() = 0; virtual bool isNone(HostRef*) = 0; virtual bool isBoolean(HostRef*) = 0; virtual jboolean booleanAsBoolean(HostRef*) = 0; virtual HostRef* getTrue() = 0; virtual HostRef* getFalse() = 0; virtual bool isSequence(HostRef*) = 0; virtual HostRef* newMutableSequence(jsize) = 0; virtual HostRef* newImmutableSequence(jsize) = 0; virtual jsize getSequenceLength(HostRef*) = 0; virtual HostRef* getSequenceItem(HostRef*, jsize) = 0; virtual void setSequenceItem(HostRef*, jsize, HostRef*) = 0; virtual bool isInt(HostRef*) = 0; virtual HostRef* newInt(jint) = 0; virtual jint intAsInt(HostRef*) = 0; virtual bool isLong(HostRef*) = 0; virtual HostRef* newLong(jlong) = 0; virtual jlong longAsLong(HostRef*) = 0; virtual bool isFloat(HostRef*) = 0; virtual HostRef* newFloat(jdouble) = 0; virtual jdouble floatAsDouble(HostRef*) = 0; virtual bool isMethod(HostRef*) = 0; virtual HostRef* newMethod(JPMethod*) = 0; virtual JPMethod* asMethod(HostRef*) = 0; virtual bool isObject(HostRef*) = 0; virtual JPObject* asObject(HostRef*) = 0; virtual HostRef* newObject(JPObject*) = 0; virtual bool isClass(HostRef*) = 0; virtual HostRef* newClass(JPClass*) = 0; virtual JPClass* asClass(HostRef*) = 0; virtual bool isArrayClass(HostRef*) = 0; virtual HostRef* newArrayClass(JPArrayClass*) = 0; virtual JPArrayClass* asArrayClass(HostRef*) = 0; virtual bool isArray(HostRef*) = 0; virtual HostRef* newArray(JPArray*) = 0; virtual JPArray* asArray(HostRef*) = 0; virtual bool isProxy(HostRef*) = 0; virtual JPProxy* asProxy(HostRef*) = 0; virtual HostRef* getCallableFrom(HostRef*, string&) = 0; virtual bool isWrapper(HostRef*) = 0; virtual JPTypeName getWrapperTypeName(HostRef*) = 0; virtual jvalue getWrapperValue(HostRef*) = 0; virtual HostRef* newStringWrapper(jstring) = 0; virtual bool isString(HostRef*) = 0; virtual jsize getStringLength(HostRef*) = 0; virtual string stringAsString(HostRef*) = 0; virtual JCharString stringAsJCharString(HostRef*) = 0; virtual HostRef* newStringFromUnicode(const jchar*, unsigned int) = 0; virtual HostRef* newStringFromASCII(const char*, unsigned int) = 0; virtual bool isByteString(HostRef*) = 0; virtual bool isUnicodeString(HostRef*) = 0; virtual void getRawByteString(HostRef*, char**, long&) = 0; virtual void getRawUnicodeString(HostRef*, jchar**, long&) = 0; virtual size_t getUnicodeSize() = 0; virtual void* prepareCallbackBegin() = 0; virtual void prepareCallbackFinish(void* state) = 0; virtual HostRef* callObject(HostRef* callable, vector& args) = 0; virtual bool mapContains(HostRef* map, HostRef* key) = 0; virtual HostRef* getMapItem(HostRef* map, HostRef* key) = 0; virtual bool objectHasAttribute(HostRef* obj, HostRef* key) = 0; virtual HostRef* getObjectAttribute(HostRef* obj, HostRef* key) = 0; virtual bool isJavaException(HostException*) = 0; virtual HostRef* getJavaException(HostException*) = 0; virtual void printError() = 0; virtual void clearError() = 0; virtual void printReferenceInfo(HostRef* obj) = 0; virtual bool isByteBuffer(HostRef*) = 0; virtual void getByteBufferPtr(HostRef*, char**, long&) = 0; }; #endif // _JPHOSTENV_H_ jpype-0.6.2+dfsg/native/common/include/jp_invocationhandler.h0000664000175000017500000000166513036015411023635 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPINVOCATIONHANDLER_H_ #define _JPINVOCATIONHANDLER_H_ extern jbyte JPypeInvocationHandler[]; jsize getJPypeInvocationHandlerLength(); #endif // JPINVOCATIONHANDLER_H jpype-0.6.2+dfsg/native/common/include/jp_javaenv.h0000664000175000017500000000744713036015411021564 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JAVA_ENV_H_ #define _JAVA_ENV_H_ /** * Simple exception class to wrap java-sourced exceptions */ class JavaException { public : JavaException(const char* msg, const char* f, int l) : file(f), line(l) {message = msg;} JavaException(const JavaException& ex) : file(ex.file), line(ex.line) {message = ex.message;} virtual ~JavaException() {} const char* file; int line; string message; }; class HostException { public : HostException() {} virtual ~HostException() {} virtual const char* getFile() { return "";} virtual int getLine() {return 0;} virtual string getMessage() { return ""; } }; /** * the platform adapter's implementation is chosen by the JPYPE_??? macros */ class JPPlatformAdapter { public : virtual ~JPPlatformAdapter() {}; virtual void loadLibrary(const char* path) = 0; virtual void unloadLibrary() = 0; virtual void* getSymbol(const char* name)= 0; }; /** * Wrap all the needed parts of JNI to provide centralized error detection and dynamic loading */ class JPJavaEnv { public : JPJavaEnv(JavaVM* vm) : jvm(vm), referenceQueue(NULL), convertStringObjects(true) { } virtual ~JPJavaEnv() {} private : static JPPlatformAdapter* GetAdapter(); // static JPPlatformAdapter* adapter; static jint (JNICALL *CreateJVM_Method)(JavaVM **pvm, void **penv, void *args); static jint (JNICALL *GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize* nVms); JavaVM* jvm; jobject referenceQueue; bool convertStringObjects; JNIEnv* getJNIEnv(); public : static void load(const string& path); static JPJavaEnv* CreateJavaVM(void* arg); static JPJavaEnv* GetCreatedJavaVM(); jint AttachCurrentThread(); jint AttachCurrentThreadAsDaemon(); static bool isThreadAttached(); void setConvertStringObjects(bool flag) { convertStringObjects = flag; } bool getConvertStringObjects() { return convertStringObjects; } void setReferenceQueue(jobject obj) { referenceQueue = NewGlobalRef(obj); } jobject getReferenceQueue() { return referenceQueue; } void shutdown(); void checkInitialized(); int DestroyJavaVM(); jobject NewGlobalRef(jobject obj); void DeleteGlobalRef(jobject obj); jobject NewLocalRef(jobject obj); void DeleteLocalRef(jobject obj); bool ExceptionCheck(); void ExceptionDescribe(); void ExceptionClear(); jthrowable ExceptionOccurred(); jint DetachCurrentThread(); jint GetEnv(JNIEnv** env); jint ThrowNew(jclass clazz, const char* msg); jint Throw(jthrowable th); jobject NewDirectByteBuffer(void* address, jlong capacity); /** NewObjectA */ jobject NewObjectA(jclass a0, jmethodID a1, jvalue* a2); /** NewObject */ jobject NewObject(jclass a0, jmethodID a1); /** get/release primitive arrays critical (direct pointer access) */ void* GetPrimitiveArrayCritical(jarray array, jboolean *isCopy); void ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode); #include "jp_javaenv_autogen.h" }; #endif // _JAVA_ENV_H_ jpype-0.6.2+dfsg/native/common/include/jp_javaenv_autogen.h0000664000175000017500000004047713036015411023306 0ustar takakitakaki /***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ // This code has been automatically generated ... No not edit /** GetStaticByteField */ jbyte GetStaticByteField(jclass clazz, jfieldID fid); /** GetByteField */ jbyte GetByteField(jobject clazz, jfieldID fid); /** SetStaticByteField */ void SetStaticByteField(jclass clazz, jfieldID fid, jbyte val); /** SetByteField */ void SetByteField(jobject clazz, jfieldID fid, jbyte val); /** CallStaticByteMethodA */ jbyte CallStaticByteMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticByteMethod */ jbyte CallStaticByteMethod(jclass clazz, jmethodID mid); /** CallByteMethodA */ jbyte CallByteMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallByteMethod */ jbyte CallByteMethod(jobject obj, jmethodID mid); /** CallByteMethodA */ jbyte CallNonvirtualByteMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallByteMethod */ jbyte CallNonvirtualByteMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticShortField */ jshort GetStaticShortField(jclass clazz, jfieldID fid); /** GetShortField */ jshort GetShortField(jobject clazz, jfieldID fid); /** SetStaticShortField */ void SetStaticShortField(jclass clazz, jfieldID fid, jshort val); /** SetShortField */ void SetShortField(jobject clazz, jfieldID fid, jshort val); /** CallStaticShortMethodA */ jshort CallStaticShortMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticShortMethod */ jshort CallStaticShortMethod(jclass clazz, jmethodID mid); /** CallShortMethodA */ jshort CallShortMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallShortMethod */ jshort CallShortMethod(jobject obj, jmethodID mid); /** CallShortMethodA */ jshort CallNonvirtualShortMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallShortMethod */ jshort CallNonvirtualShortMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticIntField */ jint GetStaticIntField(jclass clazz, jfieldID fid); /** GetIntField */ jint GetIntField(jobject clazz, jfieldID fid); /** SetStaticIntField */ void SetStaticIntField(jclass clazz, jfieldID fid, jint val); /** SetIntField */ void SetIntField(jobject clazz, jfieldID fid, jint val); /** CallStaticIntMethodA */ jint CallStaticIntMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticIntMethod */ jint CallStaticIntMethod(jclass clazz, jmethodID mid); /** CallIntMethodA */ jint CallIntMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallIntMethod */ jint CallIntMethod(jobject obj, jmethodID mid); /** CallIntMethodA */ jint CallNonvirtualIntMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallIntMethod */ jint CallNonvirtualIntMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticLongField */ jlong GetStaticLongField(jclass clazz, jfieldID fid); /** GetLongField */ jlong GetLongField(jobject clazz, jfieldID fid); /** SetStaticLongField */ void SetStaticLongField(jclass clazz, jfieldID fid, jlong val); /** SetLongField */ void SetLongField(jobject clazz, jfieldID fid, jlong val); /** CallStaticLongMethodA */ jlong CallStaticLongMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticLongMethod */ jlong CallStaticLongMethod(jclass clazz, jmethodID mid); /** CallLongMethodA */ jlong CallLongMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallLongMethod */ jlong CallLongMethod(jobject obj, jmethodID mid); /** CallLongMethodA */ jlong CallNonvirtualLongMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallLongMethod */ jlong CallNonvirtualLongMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticFloatField */ jfloat GetStaticFloatField(jclass clazz, jfieldID fid); /** GetFloatField */ jfloat GetFloatField(jobject clazz, jfieldID fid); /** SetStaticFloatField */ void SetStaticFloatField(jclass clazz, jfieldID fid, jfloat val); /** SetFloatField */ void SetFloatField(jobject clazz, jfieldID fid, jfloat val); /** CallStaticFloatMethodA */ jfloat CallStaticFloatMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticFloatMethod */ jfloat CallStaticFloatMethod(jclass clazz, jmethodID mid); /** CallFloatMethodA */ jfloat CallFloatMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallFloatMethod */ jfloat CallFloatMethod(jobject obj, jmethodID mid); /** CallFloatMethodA */ jfloat CallNonvirtualFloatMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallFloatMethod */ jfloat CallNonvirtualFloatMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticDoubleField */ jdouble GetStaticDoubleField(jclass clazz, jfieldID fid); /** GetDoubleField */ jdouble GetDoubleField(jobject clazz, jfieldID fid); /** SetStaticDoubleField */ void SetStaticDoubleField(jclass clazz, jfieldID fid, jdouble val); /** SetDoubleField */ void SetDoubleField(jobject clazz, jfieldID fid, jdouble val); /** CallStaticDoubleMethodA */ jdouble CallStaticDoubleMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticDoubleMethod */ jdouble CallStaticDoubleMethod(jclass clazz, jmethodID mid); /** CallDoubleMethodA */ jdouble CallDoubleMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallDoubleMethod */ jdouble CallDoubleMethod(jobject obj, jmethodID mid); /** CallDoubleMethodA */ jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallDoubleMethod */ jdouble CallNonvirtualDoubleMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticCharField */ jchar GetStaticCharField(jclass clazz, jfieldID fid); /** GetCharField */ jchar GetCharField(jobject clazz, jfieldID fid); /** SetStaticCharField */ void SetStaticCharField(jclass clazz, jfieldID fid, jchar val); /** SetCharField */ void SetCharField(jobject clazz, jfieldID fid, jchar val); /** CallStaticCharMethodA */ jchar CallStaticCharMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticCharMethod */ jchar CallStaticCharMethod(jclass clazz, jmethodID mid); /** CallCharMethodA */ jchar CallCharMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallCharMethod */ jchar CallCharMethod(jobject obj, jmethodID mid); /** CallCharMethodA */ jchar CallNonvirtualCharMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallCharMethod */ jchar CallNonvirtualCharMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticBooleanField */ jboolean GetStaticBooleanField(jclass clazz, jfieldID fid); /** GetBooleanField */ jboolean GetBooleanField(jobject clazz, jfieldID fid); /** SetStaticBooleanField */ void SetStaticBooleanField(jclass clazz, jfieldID fid, jboolean val); /** SetBooleanField */ void SetBooleanField(jobject clazz, jfieldID fid, jboolean val); /** CallStaticBooleanMethodA */ jboolean CallStaticBooleanMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticBooleanMethod */ jboolean CallStaticBooleanMethod(jclass clazz, jmethodID mid); /** CallBooleanMethodA */ jboolean CallBooleanMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallBooleanMethod */ jboolean CallBooleanMethod(jobject obj, jmethodID mid); /** CallBooleanMethodA */ jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallBooleanMethod */ jboolean CallNonvirtualBooleanMethod(jobject obj, jclass claz, jmethodID mid); /** GetStaticObjectField */ jobject GetStaticObjectField(jclass clazz, jfieldID fid); /** GetObjectField */ jobject GetObjectField(jobject clazz, jfieldID fid); /** SetStaticObjectField */ void SetStaticObjectField(jclass clazz, jfieldID fid, jobject val); /** SetObjectField */ void SetObjectField(jobject clazz, jfieldID fid, jobject val); /** CallStaticObjectMethodA */ jobject CallStaticObjectMethodA(jclass clazz, jmethodID mid, jvalue* val); /** CallStaticObjectMethod */ jobject CallStaticObjectMethod(jclass clazz, jmethodID mid); /** CallObjectMethodA */ jobject CallObjectMethodA(jobject obj, jmethodID mid, jvalue* val); /** CallObjectMethod */ jobject CallObjectMethod(jobject obj, jmethodID mid); /** CallObjectMethodA */ jobject CallNonvirtualObjectMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val); /** CallObjectMethod */ jobject CallNonvirtualObjectMethod(jobject obj, jclass claz, jmethodID mid); /** NewByteArray */ jbyteArray NewByteArray(jint len); /** SetByteArrayRegion */ void SetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals); /** GetByteArrayRegion */ void GetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals); /** GetByteArrayElements */ jbyte* GetByteArrayElements(jbyteArray array, jboolean* isCopy); /** ReleaseByteArrayElements */ void ReleaseByteArrayElements(jbyteArray, jbyte* v, jint mode); /** NewShortArray */ jshortArray NewShortArray(jint len); /** SetShortArrayRegion */ void SetShortArrayRegion(jshortArray array, int start, int len, jshort* vals); /** GetShortArrayRegion */ void GetShortArrayRegion(jshortArray array, int start, int len, jshort* vals); /** GetShortArrayElements */ jshort* GetShortArrayElements(jshortArray array, jboolean* isCopy); /** ReleaseShortArrayElements */ void ReleaseShortArrayElements(jshortArray, jshort* v, jint mode); /** NewIntArray */ jintArray NewIntArray(jint len); /** SetIntArrayRegion */ void SetIntArrayRegion(jintArray array, int start, int len, jint* vals); /** GetIntArrayRegion */ void GetIntArrayRegion(jintArray array, int start, int len, jint* vals); /** GetIntArrayElements */ jint* GetIntArrayElements(jintArray array, jboolean* isCopy); /** ReleaseIntArrayElements */ void ReleaseIntArrayElements(jintArray, jint* v, jint mode); /** NewLongArray */ jlongArray NewLongArray(jint len); /** SetLongArrayRegion */ void SetLongArrayRegion(jlongArray array, int start, int len, jlong* vals); /** GetLongArrayRegion */ void GetLongArrayRegion(jlongArray array, int start, int len, jlong* vals); /** GetLongArrayElements */ jlong* GetLongArrayElements(jlongArray array, jboolean* isCopy); /** ReleaseLongArrayElements */ void ReleaseLongArrayElements(jlongArray, jlong* v, jint mode); /** NewFloatArray */ jfloatArray NewFloatArray(jint len); /** SetFloatArrayRegion */ void SetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals); /** GetFloatArrayRegion */ void GetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals); /** GetFloatArrayElements */ jfloat* GetFloatArrayElements(jfloatArray array, jboolean* isCopy); /** ReleaseFloatArrayElements */ void ReleaseFloatArrayElements(jfloatArray, jfloat* v, jint mode); /** NewDoubleArray */ jdoubleArray NewDoubleArray(jint len); /** SetDoubleArrayRegion */ void SetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals); /** GetDoubleArrayRegion */ void GetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals); /** GetDoubleArrayElements */ jdouble* GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy); /** ReleaseDoubleArrayElements */ void ReleaseDoubleArrayElements(jdoubleArray, jdouble* v, jint mode); /** NewCharArray */ jcharArray NewCharArray(jint len); /** SetCharArrayRegion */ void SetCharArrayRegion(jcharArray array, int start, int len, jchar* vals); /** GetCharArrayRegion */ void GetCharArrayRegion(jcharArray array, int start, int len, jchar* vals); /** GetCharArrayElements */ jchar* GetCharArrayElements(jcharArray array, jboolean* isCopy); /** ReleaseCharArrayElements */ void ReleaseCharArrayElements(jcharArray, jchar* v, jint mode); /** NewBooleanArray */ jbooleanArray NewBooleanArray(jint len); /** SetBooleanArrayRegion */ void SetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals); /** GetBooleanArrayRegion */ void GetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals); /** GetBooleanArrayElements */ jboolean* GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy); /** ReleaseBooleanArrayElements */ void ReleaseBooleanArrayElements(jbooleanArray, jboolean* v, jint mode); /** MonitorEnter */ int MonitorEnter(jobject a0); /** MonitorExit */ int MonitorExit(jobject a0); /** FromReflectedMethod */ jmethodID FromReflectedMethod(jobject a0); /** FromReflectedField */ jfieldID FromReflectedField(jobject a0); /** FindClass */ jclass FindClass(const char* a0); /** IsInstanceOf */ jboolean IsInstanceOf(jobject a0, jclass a1); /** NewObjectArray */ jobjectArray NewObjectArray(int a0, jclass a1, jobject a2); /** SetObjectArrayElement */ void SetObjectArrayElement(jobjectArray a0, int a1, jobject a2); /** CallStaticVoidMethodA */ void CallStaticVoidMethodA(jclass a0, jmethodID a1, jvalue* a2); /** CallVoidMethodA */ void CallVoidMethodA(jobject a0, jmethodID a1, jvalue* a2); /** CallVoidMethod */ void CallVoidMethod(jobject a0, jmethodID a1); /** IsAssignableFrom */ jboolean IsAssignableFrom(jclass a0, jclass a1); /** NewString */ jstring NewString(const jchar* a0, int a1); /** GetSuperclass */ jclass GetSuperclass(jclass a0); /** GetStringUTFChars */ const char* GetStringUTFChars(jstring a0, jboolean* a1); /** ReleaseStringUTFChars */ void ReleaseStringUTFChars(jstring a0, const char* a1); /** GetArrayLength */ jsize GetArrayLength(jarray a0); /** GetObjectArrayElement */ jobject GetObjectArrayElement(jobjectArray a0, int a1); /** GetObjectClass */ jclass GetObjectClass(jobject a0); /** GetMethodID */ jmethodID GetMethodID(jclass a0, const char* a1, const char* a2); /** GetStaticMethodID */ jmethodID GetStaticMethodID(jclass a0, const char* a1, const char* a2); /** GetFieldID */ jfieldID GetFieldID(jclass a0, const char* a1, const char* a2); /** GetStaticFieldID */ jfieldID GetStaticFieldID(jclass a0, const char* a1, const char* a2); /** GetStringChars */ const jchar* GetStringChars(jstring a0, jboolean* a1); /** ReleaseStringChars */ void ReleaseStringChars(jstring a0, const jchar* a1); /** GetStringLength */ jsize GetStringLength(jstring a0); /** DefineClass */ jclass DefineClass(const char* a0, jobject a1, const jbyte* a2, jsize a3); /** RegisterNatives */ jint RegisterNatives(jclass a0, const JNINativeMethod* a1, jint a2); jpype-0.6.2+dfsg/native/common/include/jp_jniutil.h0000664000175000017500000001061113036015411021573 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPJNIUTIL_H_ #define _JPJNIUTIL_H_ namespace JPJni { extern jclass s_ClassClass; extern jclass s_StringClass; extern jclass s_NoSuchMethodErrorClass; extern jclass s_RuntimeExceptionClass; extern jclass s_ProxyClass; extern jmethodID s_NewProxyInstanceID; extern jlong s_minByte; extern jlong s_maxByte; extern jlong s_minShort; extern jlong s_maxShort; extern jlong s_minInt; extern jlong s_maxInt; extern jfloat s_minFloat; extern jfloat s_maxFloat; void init(); void startJPypeReferenceQueue(bool); void stopJPypeReferenceQueue(); void registerRef(jobject refQueue, jobject obj, jlong hostRef); string asciiFromJava(jstring str); JCharString unicodeFromJava(jstring str); jstring javaStringFromJCharString(JCharString& str); JPTypeName getClassName(jobject obj); jclass getClass(jobject obj); jstring toString(jobject obj); /** * java.lang.Class.isInterface() */ bool isInterface(jclass); /** * java.lang.reflect.Modifier.isAbstract(java.lang.Class.getModifiers() */ bool isAbstract(jclass); /** * java.lang.reflect.Modifier.isFinal(java.lang.Class.getModifiers() */ bool isFinal(jclass); /** * java.lang.Class.getName() */ JPTypeName getName(jclass); /** * java.lang.Class.getInterfaces() */ vector getInterfaces(jclass); /** * java.lang.Class.getDeclaredFields() */ vector getDeclaredFields(jclass); /** * java.lang.Class.getConstructors() */ vector getConstructors(jclass); /** * java.lang.Class.getFields() */ vector getFields(jclass); /** * java.lang.Class.getDeclaredMethods() */ vector getDeclaredMethods(jclass); /** * java.lang.Class.getDeclaredMethods() */ vector getMethods(jclass); /** * java.lang.Class.getDeclaredMethods() */ vector getDeclaredConstructors(jclass); /** * java.lang.Class.getModifiers() */ long getClassModifiers(jclass); jobject getSystemClassLoader(); /** * java.lang.reflect.Member.getName() */ string getMemberName(jobject); /** * java.lang.reflect.Modifier.isPublic(java.lang.reflect.member.getModifiers()) */ bool isMemberPublic(jobject); /** * java.lang.reflect.Modifier.is(java.lang.reflect.member.getModifiers()) */ bool isMemberStatic(jobject); /** * java.lang.reflect.Modifier.isFinal(java.lang.reflect.member.getModifiers()) */ bool isMemberFinal(jobject); /** * java.lang.reflect.Modifier.isAbstract(java.lang.reflect.member.getModifiers()) */ bool isMemberAbstract(jobject); /** * java.lang.reflect.Field.getType */ JPTypeName getType(jobject fld); /** * java.lang.reflect.Method.getReturnType */ JPTypeName getReturnType(jobject); /** * java.lang.reflect.Method.isSynthetic() */ bool isMethodSynthetic(jobject); /** * java.lang.reflect.Method.isSynthetic() */ bool isVarArgsMethod(jobject); jint hashCode(jobject); /** * java.lang.reflect.Method.getParameterTypes */ vector getParameterTypes(jobject, bool); bool isConstructor(jobject); string getStackTrace(jthrowable th); string getMessage(jthrowable th); bool isThrowable(jclass c); long intValue(jobject); jlong longValue(jobject); double doubleValue(jobject); bool booleanValue(jobject); jchar charValue(jobject); jclass getByteClass(); jclass getShortClass(); jclass getIntegerClass(); jclass getLongClass(); jclass getFloatClass(); jclass getDoubleClass(); jclass getCharacterClass(); jclass getBooleanClass(); jclass getVoidClass(); }; #endif // _JPJNIUTIL_H_ jpype-0.6.2+dfsg/native/common/include/jp_method.h0000664000175000017500000000425213036015411021401 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPMETHOD_H_ #define _JPMETHOD_H_ class JPObject; class JPMethod { public : /** * Create a new method based on class and a name; */ JPMethod(jclass clazz, const string& name, bool isConstructor); virtual ~JPMethod() { JPEnv::getJava()->DeleteGlobalRef(m_Class); } public : const string& getName() const; string getClassName() const; void addOverload(JPClass* clazz, jobject mth); void addOverloads(JPMethod* o); bool hasStatic(); size_t getCount() { return m_Overloads.size(); } bool isBeanMutator(); bool isBeanAccessor(); HostRef* invoke(vector&); HostRef* invokeStatic(vector&); HostRef* invokeInstance(vector&); JPObject* invokeConstructor(vector& args); string describe(string prefix); string matchReport(vector&); void ensureOverloadOrderCache(); private : JPMethodOverload* findOverload(vector& arg, bool needStatic); jclass m_Class; string m_Name; map m_Overloads; struct OverloadData { OverloadData(JPMethodOverload* o) : m_Overload(o) {} JPMethodOverload* m_Overload; std::vector m_MoreSpecificOverloads; }; std::vector m_OverloadOrderCache; bool m_IsConstructor; }; #endif // _JPMETHOD_H_ jpype-0.6.2+dfsg/native/common/include/jp_methodoverload.h0000664000175000017500000000442713036015411023141 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPMETHODOVERLOAD_H_ #define _JPMETHODOVERLOAD_H_ class JPObject; class JPMethodOverload { public : JPMethodOverload(); JPMethodOverload(const JPMethodOverload& o); JPMethodOverload(JPClass* claz, jobject mth); virtual ~JPMethodOverload(); EMatchType matches(bool ignoreFirst, vector& args) ; HostRef* invokeInstance(vector& arg); HostRef* invokeStatic(vector& arg); JPObject* invokeConstructor(jclass, vector& arg); public : string getSignature(); bool isStatic() const { return m_IsStatic; } bool isFinal() const { return m_IsFinal; } const JPTypeName& getReturnType() const { return m_ReturnType; } unsigned char getArgumentCount() const { return (unsigned char)m_Arguments.size(); } string getArgumentString(); bool isSameOverload(JPMethodOverload& o); string matchReport(vector& args); bool isMoreSpecificThan(JPMethodOverload& other) const; private: void ensureTypeCache() const; private : JPClass* m_Class; jobject m_Method; jmethodID m_MethodID; JPTypeName m_ReturnType; vector m_Arguments; bool m_IsStatic; bool m_IsFinal; bool m_IsConstructor; mutable vector m_ArgumentsTypeCache; mutable JPType* m_ReturnTypeCache; }; #endif // _JPMETHODOVERLOAD_H_ jpype-0.6.2+dfsg/native/common/include/jp_monitor.h0000664000175000017500000000167513036015411021616 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPMONITOR_H_ #define _JPMONITOR_H_ class JPMonitor { public : JPMonitor(jobject obj); virtual ~JPMonitor(); private : jobject m_Object; }; #endif // _JPMONITOR_H_ jpype-0.6.2+dfsg/native/common/include/jp_object.h0000664000175000017500000000246713036015411021375 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPOBJECT_H_ #define _JPOBJECT_H_ class JPObject : public JPObjectBase { public : JPObject(JPClass* clazz, jobject inst); JPObject(JPTypeName& clazz, jobject inst); virtual ~JPObject(); JPClass* getClass() { return m_Class; } jobject getObject() { return JPEnv::getJava()->NewLocalRef(m_Object); } JCharString toString(); HostRef* getAttribute(const string& name); void setAttribute(const string& name, HostRef* value); private : JPClass* m_Class; jobject m_Object; }; #endif // _JPOBJECT_H_ jpype-0.6.2+dfsg/native/common/include/jp_objectbase.h0000664000175000017500000000165113036015411022222 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPOBJECTBASE_H_ #define _JPOBJECTBASE_H_ class JPObjectBase { protected : JPObjectBase() {} virtual ~JPObjectBase() {} }; #endif // _JPOBJECTBASE_H_ jpype-0.6.2+dfsg/native/common/include/jp_objecttypes.h0000664000175000017500000000702413036015411022454 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPPOBJECTTYPE_H_ #define _JPPOBJECTTYPE_H_ class JPObjectType : public JPType { protected : JPObjectType(JPTypeName::ETypes type, const JPTypeName& objectType) : m_Type(JPTypeName::fromType(type)), m_ObjectTypeName(objectType) { } virtual ~JPObjectType() { } public : virtual const JPTypeName& getName() const { return m_Type; } virtual const JPTypeName& getObjectType() const { return m_ObjectTypeName; } virtual bool isObjectType() const { return true; } virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual jobject convertToJavaObject(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass clazz, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length) { RAISE(JPypeException, "not impled for void*"); } virtual void setArrayRange(jarray, int start, int len, PyObject*) { RAISE(JPypeException, "not impled for void*"); } virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const; protected : virtual jclass getClass() const = 0; private : JPTypeName m_Type; JPTypeName m_ObjectTypeName; }; class JPStringType : public JPObjectType { public : JPStringType() : JPObjectType(JPTypeName::_string, JPTypeName::fromSimple("java.lang.String")) { } virtual ~JPStringType() { } protected : virtual jclass getClass() const; public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); }; class JPClassType : public JPObjectType { public : JPClassType() : JPObjectType(JPTypeName::_class, JPTypeName::fromSimple("java.lang.Class")) { } virtual ~JPClassType() { } protected : virtual jclass getClass() const; public : // JPType implementation virtual HostRef* asHostObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); }; #endif // _JPPOBJECTTYPE_H_ jpype-0.6.2+dfsg/native/common/include/jp_platform_linux.h0000664000175000017500000000370613036015411023167 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PLATFORM_LINUX_H_ #define _PLATFORM_LINUX_H_ //AT's comments on porting: // this file should be better called jp_platform_unix.h #if defined(_HPUX) && !defined(_IA64) #include #else #include #endif // HPUX class LinuxPlatformAdapter : public JPPlatformAdapter { private : void* jvmLibrary; public : virtual void loadLibrary(const char* path) { #if defined(_HPUX) && !defined(_IA64) jvmLibrary = shl_load(path, BIND_DEFERRED|BIND_VERBOSE, 0L); #else jvmLibrary = dlopen(path, RTLD_LAZY|RTLD_GLOBAL); #endif // HPUX if (jvmLibrary == NULL) { std::stringstream msg; msg << "Unable to load DLL [" << path << "], error = " << dlerror(); RAISE(JPypeException, msg.str().c_str()); } } virtual void unloadLibrary() { int r = dlclose(jvmLibrary); if (r != 0) // error { cerr << dlerror() << endl; } } virtual void* getSymbol(const char* name) { void* res = dlsym(jvmLibrary, name); if (res == NULL) { std::stringstream msg; msg << "Unable to load symbol [" << name << "], error = " << dlerror(); RAISE(JPypeException, msg.str().c_str()); } return res; } }; #endif // _PLATFORM_LINUX_H_ jpype-0.6.2+dfsg/native/common/include/jp_platform_win32.h0000664000175000017500000000411713036015411022767 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PLATFORM_WIN32_H_ #define _PLATFORM_WIN32_H_ #include /** * Windows-specific platform adapter */ class Win32PlatformAdapter : public JPPlatformAdapter { private : HINSTANCE jvmLibrary; std::string formatMessage(DWORD msgCode) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, msgCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); std::string res((LPTSTR)lpMsgBuf); LocalFree(lpMsgBuf); return res; } public : virtual void loadLibrary(const char* path) { jvmLibrary = LoadLibrary(path); if (jvmLibrary == NULL) { std::stringstream msg; msg << "Unable to load DLL [" << path << "], error = " << formatMessage(GetLastError()); RAISE(JPypeException, msg.str()); } } virtual void unloadLibrary() { // on success return code is nonzero, TODO: handle error? FreeLibrary(jvmLibrary); } virtual void* getSymbol(const char* name) { void* res = (void*)GetProcAddress(jvmLibrary, name); if (res == NULL) { std::stringstream msg; msg << "Unable to load symbol [" << name << "], error = " << formatMessage(GetLastError()); RAISE(JPypeException, msg.str().c_str()); } return res; } }; #endif // _PLATFORM_WIN32_H_ jpype-0.6.2+dfsg/native/common/include/jp_primitivetypes.h0000664000175000017500000004136313036015411023222 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPPRIMITIVETYPE_H_ #define _JPPRIMITIVETYPE_H_ class JPPrimitiveType : public JPType { protected : JPPrimitiveType(JPTypeName::ETypes type, bool isObject, const JPTypeName& objectType) : m_Type(JPTypeName::fromType(type)), m_IsObject(isObject), m_ObjectTypeName(objectType) { } virtual ~JPPrimitiveType() { } private : JPTypeName m_Type; bool m_IsObject; JPTypeName m_ObjectTypeName; public : virtual bool isObjectType() const { return m_IsObject; } virtual const JPTypeName& getName() const { return m_Type; } virtual const JPTypeName& getObjectType() const { return m_ObjectTypeName; } virtual jobject convertToJavaObject(HostRef* obj); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length) = 0; virtual void setArrayRange(jarray, int, int, PyObject*) = 0; }; class JPVoidType : public JPPrimitiveType { public : JPVoidType() : JPPrimitiveType(JPTypeName::_void, false, JPTypeName::fromSimple("java.lang.Void")) { } virtual ~JPVoidType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length) { RAISE(JPypeException, "not impled for void*"); } virtual void setArrayRange(jarray, int start, int length, PyObject* seq) { RAISE(JPypeException, "not impled for void*"); } virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { return other.getName().getType() == JPTypeName::_void; } }; class JPByteType : public JPPrimitiveType { public : JPByteType() : JPPrimitiveType(JPTypeName::_byte, false, JPTypeName::fromSimple("java.lang.Byte")) { } virtual ~JPByteType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); // this returns tuple instead of list, for performance reasons virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_byte || otherType == JPTypeName::_short || otherType == JPTypeName::_int || otherType == JPTypeName::_long || otherType == JPTypeName::_float || otherType == JPTypeName::_double; } }; class JPShortType : public JPPrimitiveType { public : JPShortType() : JPPrimitiveType(JPTypeName::_short, false, JPTypeName::fromSimple("java.lang.Short")) { } virtual ~JPShortType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_short || otherType == JPTypeName::_int || otherType == JPTypeName::_long || otherType == JPTypeName::_float || otherType == JPTypeName::_double; } }; class JPIntType : public JPPrimitiveType { public : JPIntType(): JPPrimitiveType(JPTypeName::_int, false, JPTypeName::fromSimple("java.lang.Integer")) { } virtual ~JPIntType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int, int, PyObject*); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_int || otherType == JPTypeName::_long || otherType == JPTypeName::_float || otherType == JPTypeName::_double; } }; class JPLongType : public JPPrimitiveType { public : JPLongType() : JPPrimitiveType(JPTypeName::_long, false, JPTypeName::fromSimple("java.lang.Long")) { } virtual ~JPLongType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_long || otherType == JPTypeName::_float || otherType == JPTypeName::_double; } }; class JPFloatType : public JPPrimitiveType { public : JPFloatType() : JPPrimitiveType(JPTypeName::_float, false, JPTypeName::fromSimple("java.lang.Float")) { } virtual ~JPFloatType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_float || otherType == JPTypeName::_double; } }; class JPDoubleType : public JPPrimitiveType { public : JPDoubleType() : JPPrimitiveType(JPTypeName::_double, false, JPTypeName::fromSimple("java.lang.Double")) { } virtual ~JPDoubleType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_double; } }; class JPCharType : public JPPrimitiveType { public : JPCharType() : JPPrimitiveType(JPTypeName::_char, false, JPTypeName::fromSimple("java.lang.Character")) { } virtual ~JPCharType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_char || otherType == JPTypeName::_int || otherType == JPTypeName::_long || otherType == JPTypeName::_float || otherType == JPTypeName::_double; } }; class JPBooleanType : public JPPrimitiveType { public : JPBooleanType() : JPPrimitiveType(JPTypeName::_boolean, false, JPTypeName::fromSimple("java.lang.Boolean")) { } virtual ~JPBooleanType() { } public : // JPType implementation virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType); virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val); virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType); virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val); virtual HostRef* asHostObject(jvalue val); virtual HostRef* asHostObjectFromObject(jvalue val); virtual EMatchType canConvertToJava(HostRef* obj); virtual jvalue convertToJava(HostRef* obj); virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*); virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*); virtual jarray newArrayInstance(int size); virtual vector getArrayRange(jarray, int start, int length); virtual void setArrayRange(jarray, int start, int length, vector& vals); virtual void setArrayRange(jarray, int start, int length, PyObject* sequence); virtual HostRef* getArrayItem(jarray, int ndx); virtual void setArrayItem(jarray, int ndx, HostRef* val); virtual PyObject* getArrayRangeToSequence(jarray, int start, int length); virtual HostRef* convertToDirectBuffer(HostRef* src); virtual bool isSubTypeOf(const JPType& other) const { JPTypeName::ETypes otherType = other.getName().getType(); return otherType == JPTypeName::_boolean; } }; #endif // _JPPRIMITIVETYPE_H_ jpype-0.6.2+dfsg/native/common/include/jp_proxy.h0000664000175000017500000000303213036015411021275 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPPROXY_H_ #define _JPPROXY_H_ class JPProxy { public: JPProxy(HostRef* inst, vector& intf); virtual ~JPProxy() { if (m_Instance != NULL) { m_Instance->release(); } JPEnv::getJava()->DeleteGlobalRef(m_Handler); for (unsigned int i = 0; i < m_InterfaceClasses.size(); i++) { JPEnv::getJava()->DeleteGlobalRef(m_InterfaceClasses[i]); } } static void init(); const vector& getInterfaces() const { return m_InterfaceClasses; } // jobject getHandler() // { // return JPEnv::getJava()->NewGlobalRef(m_Handler); // } jobject getProxy(); private : vector m_InterfaceClasses; jobjectArray m_Interfaces; jobject m_Handler; HostRef* m_Instance; }; #endif // JPPROXY_H jpype-0.6.2+dfsg/native/common/include/jp_reference.h0000664000175000017500000000161713036015411022061 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPREFERENCE_H_ #define _JPREFERENCE_H_ extern jbyte JPypeReference[]; jsize getJPypeReferenceLength(); #endif // _JPREFERENCE_H_ jpype-0.6.2+dfsg/native/common/include/jp_referencequeue.h0000664000175000017500000000165013036015411023123 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPREFERENCEQUEUE_H_ #define _JPREFERENCEQUEUE_H_ extern jbyte JPypeReferenceQueue[]; jsize getJPypeReferenceQueueLength(); #endif // _JPREFERENCEQUEUE_H_ jpype-0.6.2+dfsg/native/common/include/jp_type.h0000664000175000017500000000545013036015411021103 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPTYPE_H_ #define _JPTYPE_H_ enum EMatchType { _none, _explicit, _implicit, _exact }; // predeclaration of PyObject #ifndef PyObject_HEAD struct _object; typedef _object PyObject; #endif /** * Base class for all JPype Types, be it primitive, class or array */ class JPType { protected : JPType() { } public : virtual HostRef* getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) = 0 ; virtual void setStaticValue(jclass c, jfieldID fid, HostRef* val) = 0 ; virtual HostRef* getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) = 0 ; virtual void setInstanceValue(jobject c, jfieldID fid, HostRef* val) = 0 ; virtual HostRef* asHostObject(jvalue val) = 0 ; virtual HostRef* asHostObjectFromObject(jvalue val) = 0; virtual const JPTypeName& getName() const = 0; virtual EMatchType canConvertToJava(HostRef* obj) = 0; virtual jvalue convertToJava(HostRef* obj) = 0; virtual jobject convertToJavaObject(HostRef* obj) = 0; virtual bool isObjectType() const = 0; virtual const JPTypeName& getObjectType() const = 0; virtual HostRef* invokeStatic(jclass, jmethodID, jvalue*) = 0; virtual HostRef* invoke(jobject, jclass, jmethodID, jvalue*) = 0; virtual jarray newArrayInstance(int size) = 0; virtual vector getArrayRange(jarray, int start, int length) = 0; virtual void setArrayRange(jarray, int start, int length, vector& vals) = 0; virtual void setArrayRange(jarray, int start, int length, PyObject* seq) = 0; virtual HostRef* getArrayItem(jarray, int ndx) = 0; virtual void setArrayItem(jarray, int ndx, HostRef* val) = 0; virtual PyObject* getArrayRangeToSequence(jarray, int start, int length) = 0; virtual HostRef* convertToDirectBuffer(HostRef* src) = 0; // in the sense of // http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.10 virtual bool isSubTypeOf(const JPType& other) const = 0; virtual ~JPType() { } }; #endif // _JPTYPE_H_ jpype-0.6.2+dfsg/native/common/include/jp_typemanager.h0000664000175000017500000000314213036015411022432 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPTYPE_MANAGER_H_ #define _JPTYPE_MANAGER_H_ /** * These functions will manage the cache of found type, be it primitive types, class types or the "magic" types. */ namespace JPTypeManager { /** * Initialize the type manager caches */ void init(); /** * delete allocated typenames, should only be called at program termination */ void shutdown(); JPType* getType(const JPTypeName& name); /** * The pointer returned is NOT owned by the caller */ JPClass* findClass(const JPTypeName&); /** * The pointer returned is NOT owned by the caller */ JPArrayClass* findArrayClass(const JPTypeName&); void flushCache(); int getLoadedClasses(); } #endif // _JPCLASS_H_ jpype-0.6.2+dfsg/native/common/include/jp_typename.h0000664000175000017500000000526613036015411021751 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPTYPENAME_H_ #define _JPTYPENAME_H_ /** * Enum for all kinds of well-known types. */ /** * Since types have multiple name representation (simple, native) and a type, this class encapsulates it all. */ class JPTypeName { public: enum ETypes { _unknown, _void, _byte, _short, _int, _long, _float, _double, _char, _boolean, _object, _class, _string, _array }; JPTypeName() : m_SimpleName(""), m_NativeName(""), m_Type(_unknown) { } private : JPTypeName(const string& simple, const string& native, ETypes t): m_SimpleName(simple), m_NativeName(native), m_Type(t) { } public : /** Copy Constructor */ JPTypeName(const JPTypeName& tn) : m_SimpleName(tn.m_SimpleName), m_NativeName(tn.m_NativeName), m_Type(tn.m_Type) { } JPTypeName& operator=(const JPTypeName& other) { this->m_SimpleName = other.getSimpleName(); this->m_NativeName = other.getNativeName(); this->m_Type = other.getType(); return *this; } public : /** * Initialize the cache of type-name to ETypes */ static void init(); /** Factory method from a simple, human-readable name */ static JPTypeName fromSimple(const char* name); static JPTypeName fromType(ETypes t); const string& getSimpleName() const { return m_SimpleName; } const string& getNativeName() const { return m_NativeName; } JPTypeName getComponentName() const; ETypes getType() const { return m_Type; } bool isObjectType() const { return m_Type >= _object; } private : string m_SimpleName; string m_NativeName; ETypes m_Type; typedef map NativeNamesMap; typedef map DefinedTypesMap; typedef map NativeTypesMap; static NativeNamesMap nativeNames; static DefinedTypesMap definedTypes; static NativeTypesMap nativeTypes; }; #endif // _JPTYPENAME_H_ jpype-0.6.2+dfsg/native/common/include/jp_utility.h0000664000175000017500000000740213036015411021624 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPYPE_UTILITY_H_ #define _JPYPE_UTILITY_H_ #include #define RAISE(exClass, msg) { throw exClass(msg, __FILE__, __LINE__); } /** Support Exception for JPype-generated exception */ class JPypeException { public : JPypeException(const char* msn, const char* f, int l) { file=f, line=l; std::stringstream str; str << msn << " at " << f << ":" << l; this->msg = str.str(); } JPypeException(const string& msn, const char* f, int l) { file=f, line=l; std::stringstream str; str << msn << " at " << f << ":" << l; this->msg = str.str(); } JPypeException(const JPypeException& ex) : file(ex.file), line(ex.line) { this->msg = ex.msg;} virtual ~JPypeException() {} const char* getMsg() { return msg.c_str(); } const char* file; int line; private : string msg; }; /* #define STANDARD_CATCH \ catch(JavaException EXCEPTION_PTR ex) \ { \ JPEnv::getJava()->ExceptionDescribe(); \ JPEnv::getJava()->ExceptionClear(); \ stringstream msg; \ msg << "Java Exception Occured at " << ex EXCEPTION_DEREF file << ":" << ex EXCEPTION_DEREF line << ":" << ex EXCEPTION_DEREF message; \ JPEnv::getHost()->setRuntimeException(msg.str().c_str());\ EXCEPTION_CLEANUP(ex); \ }\ catch(JPypeException EXCEPTION_PTR ex)\ {\ JPEnv::getHost()->setRuntimeException(ex EXCEPTION_DEREF getMsg()); \ EXCEPTION_CLEANUP(ex); \ }\ catch(...) \ {\ JPEnv::getHost()->setRuntimeException("Unknown Exception"); \ } \ */ #define RETHROW_CATCH(cleanup) \ catch(...) \ { \ cleanup ; \ throw; \ } class JPypeTracer { private : string m_Name; bool m_Error; public : JPypeTracer(const char* name) : m_Name(name) { traceIn(name); m_Error = false; } virtual ~JPypeTracer() { traceOut(m_Name.c_str(), m_Error); } void gotError() { m_Error = true; } template void trace(T msg) { #ifdef TRACING stringstream str; str << msg; trace1(m_Name.c_str(), str.str()); #endif } template void trace(T msg1, U msg2) { #ifdef TRACING stringstream str; str << msg1 << " " << msg2; trace1(m_Name.c_str(), str.str()); #endif } template void trace(T msg1, U msg2, V msg3) { #ifdef TRACING stringstream str; str << msg1 << " " << msg2 << " " << msg3; trace1(m_Name.c_str(), str.str()); #endif } private : static void traceIn(const char* msg); static void traceOut(const char* msg, bool error); static void trace1(const char* name, const string& msg); }; /** Use this class instewad of basic_string because compiler support is not great cross-platform */ class JCharString { public : JCharString(const jchar*); JCharString(const JCharString&); JCharString(size_t); virtual ~JCharString(); const jchar* c_str(); size_t length() { return m_Length; } jchar& operator[](size_t ndx) { return m_Value[ndx]; } private : jchar* m_Value; size_t m_Length; }; #endif // _JPYPE_UTILITY_H_ jpype-0.6.2+dfsg/native/common/include/jpype.h0000664000175000017500000000643513036015411020564 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPYPE_H_ #define _JPYPE_H_ // Define this to generate the trace calls // Define this to make the trace calls do their output. If you change this only the core.cpp needs to be recompiled //#define TRACING #ifdef TRACING #define JPYPE_TRACING_INTERNAL #endif #define JPYPE_TRACING_OUTPUT cerr #define TRACE_IN(n) JPypeTracer _trace(n); try { #define TRACE_OUT } catch(...) { _trace.gotError(); throw; } #define TRACE1(m) _trace.trace(m) #define TRACE2(m,n) _trace.trace(m,n) #define TRACE3(m,n,o) _trace.trace(m,n,o) #ifdef WIN32 #define JPYPE_WIN32 #ifndef __GNUC__ // Then this must mean a variant of GCC on win32 ... #define JPYPE_WIN32_VCPP #pragma warning (disable:4786) #else #endif #else #define JPYPE_LINUX #endif #ifdef WIN32 #ifdef __GNUC__ // JNICALL causes problem for function prototypes .. since I am not defining any JNI methods there is no need for it #undef JNICALL #define JNICALL #endif #endif #if PY_MAJOR_VERSION >= 3 // Python 3 #define PyInt_FromLong PyLong_FromLong #define PyInt_AsLong PyLong_AsLong #define PyInt_AS_LONG PyLong_AS_LONG #define PyInt_Check PyLong_Check #define PyInt_FromSsize_t PyLong_FromSsize_t #else #define PyUnicode_FromFormat PyString_FromFormat #endif #include #include #include #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; /** The following functions are delcared here but actually defined in the platform_specific file */ void longToHexString(long value, char* outStr); /** Definition of commonly used template types */ typedef vector StringVector; // Base utility headers #include "jp_typename.h" #include "jp_utility.h" #include "jp_javaenv.h" #include "jp_jniutil.h" #include "jp_hostenv.h" #include "jp_env.h" // Other header files #include "jp_type.h" #include "jp_primitivetypes.h" #include "jp_objecttypes.h" #include "jp_field.h" #include "jp_methodoverload.h" #include "jp_method.h" #include "jp_classbase.h" #include "jp_class.h" #include "jp_arrayclass.h" #include "jp_typemanager.h" #include "jp_objectbase.h" #include "jp_object.h" #include "jp_array.h" #include "jp_invocationhandler.h" #include "jp_reference.h" #include "jp_referencequeue.h" #include "jp_proxy.h" #include "jp_monitor.h" #include "jp_env.h" #endif // _JPYPE_H_ jpype-0.6.2+dfsg/native/common/jp_array.cpp0000664000175000017500000000717413036015411020155 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPArray::JPArray(const JPTypeName& name, jarray inst) { m_Class = JPTypeManager::findArrayClass(name); m_Object = (jarray)JPEnv::getJava()->NewGlobalRef(inst); } JPArray::~JPArray() { JPEnv::getJava()->DeleteGlobalRef(m_Object); } int JPArray::getLength() { return JPEnv::getJava()->GetArrayLength(m_Object); } vector JPArray::getRange(int start, int stop) { TRACE_IN("JPArray::getRange"); JPType* compType = m_Class->getComponentType(); TRACE2("Compoennt type", compType->getName().getSimpleName()); vector res = compType->getArrayRange(m_Object, start, stop-start); return res; TRACE_OUT; } PyObject* JPArray::getSequenceFromRange(int start, int stop) { // TRACE_IN("JPArray::getSequenceFromRange"); JPType* compType = m_Class->getComponentType(); // TRACE2("Component type", compType->getName().getSimpleName()); return compType->getArrayRangeToSequence(m_Object, start, stop); // TRACE_OUT } void JPArray::setRange(int start, int stop, vector& val) { JPType* compType = m_Class->getComponentType(); unsigned int len = stop-start; size_t plength = val.size(); if (len != plength) { std::stringstream out; out << "Slice assignment must be of equal lengths : " << len << " != " << plength; RAISE(JPypeException, out.str()); } for (size_t i = 0; i < plength; i++) { HostRef* v = val[i]; if ( compType->canConvertToJava(v)<= _explicit) { RAISE(JPypeException, "Unable to convert."); } } compType->setArrayRange(m_Object, start, stop-start, val); } void JPArray::setRange(int start, int stop, PyObject* sequence) { JPType* compType = m_Class->getComponentType(); unsigned int len = stop-start; // check bounds of sequence which is to be assigned HostRef h(sequence); unsigned int plength = JPEnv::getHost()->getSequenceLength(&h); if (len != plength) { std::stringstream out; out << "Slice assignment must be of equal lengths : " << len << " != " << plength; RAISE(JPypeException, out.str()); } compType->setArrayRange(m_Object, start, len, sequence); } void JPArray::setItem(int ndx, HostRef* val) { JPType* compType = m_Class->getComponentType(); if (compType->canConvertToJava(val) <= _explicit) { RAISE(JPypeException, "Unable to convert."); } compType->setArrayItem(m_Object, ndx, val); } HostRef* JPArray::getItem(int ndx) { JPType* compType = m_Class->getComponentType(); return compType->getArrayItem(m_Object, ndx); } JPType* JPArray::getType() { return m_Class; } jvalue JPArray::getValue() { jvalue val; val.l = JPEnv::getJava()->NewLocalRef(m_Object); return val; } JCharString JPArray::toString() { static const char* value = "Array wrapper"; jchar res[14]; res[13] = 0; for (int i = 0; value[i] != 0; i++) { res[i] = value[i]; } return res; } jpype-0.6.2+dfsg/native/common/jp_arrayclass.cpp0000664000175000017500000001105513036015411021174 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPArrayClass::JPArrayClass(const JPTypeName& tname, jclass c) : JPClassBase(tname, c) { JPTypeName compname = m_Name.getComponentName(); m_ComponentType = JPTypeManager::getType(compname); } JPArrayClass::~JPArrayClass() { } EMatchType JPArrayClass::canConvertToJava(HostRef* o) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(o)) { return _implicit; } if (JPEnv::getHost()->isArray(o)) { JPArray* a = JPEnv::getHost()->asArray(o); JPArrayClass* ca = a->getClass(); if (ca == this) { return _exact; } if (JPEnv::getJava()->IsAssignableFrom(ca->m_Class, m_Class)) { return _implicit; } } else if (JPEnv::getHost()->isUnicodeString(o) && m_ComponentType->getName().getType() ==JPTypeName::_char) { // Strings are also char[] return _implicit; } else if (JPEnv::getHost()->isByteString(o) && m_ComponentType->getName().getType() ==JPTypeName::_byte) { // Strings are also char[] return _implicit; } else if (JPEnv::getHost()->isSequence(o) && !JPEnv::getHost()->isObject(o)) { EMatchType match = _implicit; int length = JPEnv::getHost()->getSequenceLength(o); for (int i = 0; i < length && match > _none; i++) { HostRef* obj = JPEnv::getHost()->getSequenceItem(o, i); cleaner.add(obj); EMatchType newMatch = m_ComponentType->canConvertToJava(obj); if (newMatch < match) { match = newMatch; } } return match; } return _none; } HostRef* JPArrayClass::asHostObject(jvalue val) { if (val.l == NULL) { return JPEnv::getHost()->getNone(); } return JPEnv::getHost()->newArray(new JPArray(m_Name, (jarray)val.l)); } jvalue JPArrayClass::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; res.l = NULL; if (JPEnv::getHost()->isArray(obj)) { JPArray* a = JPEnv::getHost()->asArray(obj); res = a->getValue(); } else if (JPEnv::getHost()->isByteString(obj) && m_ComponentType->getName().getType() == JPTypeName::_byte && sizeof(char) == sizeof(jbyte)) { char* rawData; long size; JPEnv::getHost()->getRawByteString(obj, &rawData, size); jbyteArray array = JPEnv::getJava()->NewByteArray(size); cleaner.addLocal(array); res.l = array; jboolean isCopy; jbyte* contents = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); memcpy(contents, rawData, size*sizeof(jbyte)); JPEnv::getJava()->ReleaseByteArrayElements(array, contents, 0); cleaner.removeLocal(array); } else if (JPEnv::getHost()->isUnicodeString(obj) && m_ComponentType->getName().getType() == JPTypeName::_char && JPEnv::getHost()->getUnicodeSize() == sizeof(jchar)) { jchar* rawData; long size; JPEnv::getHost()->getRawUnicodeString(obj, &rawData, size); jcharArray array = JPEnv::getJava()->NewCharArray(size); cleaner.addLocal(array); res.l = array; jboolean isCopy; jchar* contents = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); memcpy(contents, rawData, size*sizeof(jchar)); JPEnv::getJava()->ReleaseCharArrayElements(array, contents, 0); cleaner.removeLocal(array); } else if (JPEnv::getHost()->isSequence(obj)) { int length = JPEnv::getHost()->getSequenceLength(obj); jarray array = m_ComponentType->newArrayInstance(length); cleaner.addLocal(array); res.l = array; for (int i = 0; i < length ; i++) { HostRef* obj2 = JPEnv::getHost()->getSequenceItem(obj, i); cleaner.add(obj2); m_ComponentType->setArrayItem(array, i, obj2); } cleaner.removeLocal(array); } return res; } JPArray* JPArrayClass::newInstance(int length) { JPCleaner cleaner; jarray array = m_ComponentType->newArrayInstance(length); cleaner.addLocal(array); JPArray* res = new JPArray(getName(), array); return res; } jpype-0.6.2+dfsg/native/common/jp_class.cpp0000664000175000017500000003225313036015411020140 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPClass::JPClass(const JPTypeName& n, jclass c) : JPClassBase(n, c), m_SuperClass(NULL), m_Constructors(NULL) { } JPClass::~JPClass() { delete m_Constructors; // interfaces of this cannot be simply deleted here, since they may be also // super types of other classes, which would be invalidated by doing so. for (map::iterator mthit = m_Methods.begin(); mthit != m_Methods.end(); mthit ++) { delete mthit->second; } for (map::iterator fldit = m_InstanceFields.begin(); fldit != m_InstanceFields.end(); fldit++) { delete fldit->second; } for (map::iterator fldit2 = m_StaticFields.begin(); fldit2 != m_StaticFields.end(); fldit2++) { delete fldit2->second; } } void JPClass::postLoad() { // Is this an interface? m_IsInterface = JPJni::isInterface(m_Class); loadSuperClass(); loadSuperInterfaces(); loadFields(); loadMethods(); loadConstructors(); } void JPClass::loadSuperClass() { JPCleaner cleaner; // base class .. if any if (!m_IsInterface && m_Name.getSimpleName() != "java.lang.Object") { jclass baseClass = JPEnv::getJava()->GetSuperclass(m_Class); cleaner.addLocal(baseClass); if (baseClass != NULL) { JPTypeName baseClassName = JPJni::getName(baseClass); m_SuperClass = JPTypeManager::findClass(baseClassName); } } } void JPClass::loadSuperInterfaces() { JPCleaner cleaner; // Super interfaces vector intf = JPJni::getInterfaces(m_Class); cleaner.addAllLocal(intf); for (vector::iterator it = intf.begin(); it != intf.end(); it++) { JPTypeName intfName = JPJni::getName(*it); JPClass* interface = JPTypeManager::findClass(intfName); m_SuperInterfaces.push_back(interface); } } void JPClass::loadFields() { JPCleaner cleaner; // fields vector fields = JPJni::getDeclaredFields(m_Class); cleaner.addAllLocal(fields); for (vector::iterator it = fields.begin(); it != fields.end(); it++) { JPField* field = new JPField(this, *it); if (field->isStatic()) { m_StaticFields[field->getName()] = field; } else { m_InstanceFields[field->getName()] = field; } } } void JPClass::loadMethods() { JPCleaner cleaner; JPCleaner pcleaner; // methods vector methods = JPJni::getMethods(m_Class); cleaner.addAllLocal(methods); for (vector::iterator it = methods.begin(); it != methods.end(); it++) { const string& name = JPJni::getMemberName(*it); JPMethod* method = getMethod(name); if (method == NULL) { method = new JPMethod(m_Class, name, false); m_Methods[name] = method; } method->addOverload(this, *it); } } void JPClass::loadConstructors() { JPCleaner cleaner; m_Constructors = new JPMethod(m_Class, "[init", true); if (JPJni::isAbstract(m_Class)) { // NO constructor ... return; } vector methods = JPJni::getDeclaredConstructors(m_Class); cleaner.addAllLocal(methods); for (vector::iterator it = methods.begin(); it != methods.end(); it++) { if (JPJni::isMemberPublic(*it)) { m_Constructors->addOverload(this, *it); } } } JPField* JPClass::getInstanceField(const string& name) { map::iterator it = m_InstanceFields.find(name); if (it == m_InstanceFields.end()) { return NULL; } return it->second; } JPField* JPClass::getStaticField(const string& name) { map::iterator it = m_StaticFields.find(name); if (it == m_StaticFields.end()) { return NULL; } return it->second; } JPMethod* JPClass::getMethod(const string& name) { map::iterator it = m_Methods.find(name); if (it == m_Methods.end()) { return NULL; } return it->second; } HostRef* JPClass::getStaticAttribute(const string& name) { // static fields map::iterator fld = m_StaticFields.find(name); if (fld != m_StaticFields.end()) { return fld->second->getStaticAttribute(); } JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("getAttribute"); return NULL; // never reached } HostRef* JPClass::asHostObject(jvalue obj) { TRACE_IN("JPClass::asPyObject"); if (obj.l == NULL) { return JPEnv::getHost()->getNone(); } JPTypeName name = JPJni::getClassName(obj.l); if (name.getType() ==JPTypeName::_array) { JPType* arrayType = JPTypeManager::getType(name); return arrayType->asHostObject(obj); } return JPEnv::getHost()->newObject(new JPObject(name, obj.l)); TRACE_OUT; } EMatchType JPClass::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _implicit; } JPCleaner cleaner; const string& simpleName = m_Name.getSimpleName(); if (simpleName == "java.lang.Byte" || simpleName == "java.lang.Short" || simpleName == "java.lang.Integer") { if (JPEnv::getHost()->isInt(obj)) { return _explicit; } } if (simpleName == "java.lang.Long" && JPEnv::getHost()->isLong(obj)) { return _explicit; } if (simpleName == "java.lang.Float" || simpleName == "java.lang.Double") { if (JPEnv::getHost()->isFloat(obj)) { return _explicit; } } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc == this) { // hey, this is me! :) return _exact; } if (JPEnv::getJava()->IsAssignableFrom(oc->m_Class, m_Class)) { return _implicit; } } if (JPEnv::getHost()->isProxy(obj)) { JPProxy* proxy = JPEnv::getHost()->asProxy(obj); // Check if any of the interfaces matches ... vector itf = proxy->getInterfaces(); for (unsigned int i = 0; i < itf.size(); i++) { if (JPEnv::getJava()->IsAssignableFrom(itf[i], m_Class)) { return _implicit; } } } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName o = JPEnv::getHost()->getWrapperTypeName(obj); if (o.getSimpleName() == m_Name.getSimpleName()) { return _exact; } } if (m_Name.getSimpleName() == "java.lang.Object") { // arrays are objects if (JPEnv::getHost()->isArray(obj)) { return _implicit; } // Strings are objects too if (JPEnv::getHost()->isString(obj)) { return _implicit; } // Class are objects too if (JPEnv::getHost()->isClass(obj) || JPEnv::getHost()->isArrayClass(obj)) { return _implicit; } // Let'a allow primitives (int, long, float and boolean) to convert implicitly too ... if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isFloat(obj)) { return _implicit; } if (JPEnv::getHost()->isBoolean(obj)) { return _implicit; } } return _none; } jvalue JPClass::buildObjectWrapper(HostRef* obj) { jvalue res; JPCleaner cleaner; vector args(1); args.push_back(obj); JPObject* pobj = newInstance(args); res.l = pobj->getObject(); delete pobj; return res; } jvalue JPClass::convertToJava(HostRef* obj) { jvalue res; JPCleaner cleaner; res.l = NULL; // assume it is convertible; if (JPEnv::getHost()->isNone(obj)) { res.l = NULL; } const string& simpleName = m_Name.getSimpleName(); if (JPEnv::getHost()->isInt(obj) && (simpleName == "java.lang.Byte" || simpleName == "java.lang.Short" || simpleName == "java.lang.Integer")) { return buildObjectWrapper(obj); } if ((JPEnv::getHost()->isInt(obj) || JPEnv::getHost()->isLong(obj)) && simpleName == "java.lang.Long" && JPEnv::getHost()->isLong(obj)) { return buildObjectWrapper(obj); } if (JPEnv::getHost()->isFloat(obj) && (simpleName == "java.lang.Float" || simpleName == "java.lang.Double")) { if (JPEnv::getHost()->isFloat(obj)) { return buildObjectWrapper(obj); } } if (JPEnv::getHost()->isString(obj)) { JPTypeName name = JPTypeName::fromSimple("java.lang.String"); JPType* type = JPTypeManager::getType(name); return type->convertToJava(obj); } if (JPEnv::getHost()->isObject(obj)) { JPObject* ref = JPEnv::getHost()->asObject(obj); res.l = ref->getObject(); } if (JPEnv::getHost()->isProxy(obj)) { JPProxy* proxy = JPEnv::getHost()->asProxy(obj); res.l = proxy->getProxy(); } if (JPEnv::getHost()->isWrapper(obj)) { res = JPEnv::getHost()->getWrapperValue(obj); } if (JPEnv::getHost()->isInt(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_int); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isLong(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_long); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isFloat(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_double); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isBoolean(obj)) { JPTypeName tname = JPTypeName::fromType(JPTypeName::_boolean); JPType* t = JPTypeManager::getType(tname); res.l = t->convertToJavaObject(obj); } if (JPEnv::getHost()->isArray(obj) && simpleName == "java.lang.Object") { JPArray* a = JPEnv::getHost()->asArray(obj); res = a->getValue(); } if (JPEnv::getHost()->isClass(obj)) { JPTypeName name = JPTypeName::fromSimple("java.lang.Class"); JPType* type = JPTypeManager::getType(name); res.l = type->convertToJavaObject(obj); } return res; } JPObject* JPClass::newInstance(vector& args) { return m_Constructors->invokeConstructor(args); } void JPClass::setStaticAttribute(const string& name, HostRef* val) { map::iterator it = m_StaticFields.find(name); if (it == m_StaticFields.end()) { JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("__setattr__"); } it->second->setStaticAttribute(val); } string JPClass::describe() { stringstream out; JPCleaner cleaner; out << "public "; if (isAbstract()) { out << "abstract "; } if (isFinal()) { out << "final "; } out << "class " << m_Name.getSimpleName(); if (m_SuperClass != NULL) { out << " extends " << m_SuperClass->getName().getSimpleName(); } if (m_SuperInterfaces.size() > 0) { out << " implements"; bool first = true; for (vector::iterator itf = m_SuperInterfaces.begin(); itf != m_SuperInterfaces.end(); itf++) { if (!first) { out << ","; } else { first = false; } JPClass* pc = *itf; out << " " << pc->getName().getSimpleName(); } } out << endl << "{" << endl; // Fields out << " // Accessible Static Fields" << endl; for (map::iterator curField = m_StaticFields.begin(); curField != m_StaticFields.end(); curField++) { JPField* f = curField->second; out << " public static "; if (f->isFinal()) { out << "final "; } out << f->getType().getSimpleName() << " " << f->getName() << ";" << endl; } out << endl; out << " // Accessible Instance Fields" << endl; for (map::iterator curInstField = m_InstanceFields.begin(); curInstField != m_InstanceFields.end(); curInstField++) { JPField* f = curInstField->second; out << " public "; if (f->isFinal()) { out << "final "; } out << f->getType().getSimpleName() << " " << f->getName() << ";" << endl; } out << endl; // Constructors out << " // Accessible Constructors" << endl; out << m_Constructors->describe(" ") << endl; out << " // Accessible Methods" << endl; for (map::iterator curMethod = m_Methods.begin(); curMethod != m_Methods.end(); curMethod++) { JPMethod* f = curMethod->second; out << f->describe(" "); out << endl; } out << "}"; return out.str(); } bool JPClass::isAbstract() { return JPJni::isAbstract(m_Class); } bool JPClass::isFinal() { return JPJni::isFinal(m_Class); } JPClass* JPClass::getSuperClass() { return m_SuperClass; } const vector& JPClass::getInterfaces() const { return m_SuperInterfaces; } bool JPClass::isSubclass(JPClass* o) { JPCleaner cleaner; jclass jo = o->getClass(); cleaner.addLocal(jo); if (JPEnv::getJava()->IsAssignableFrom(m_Class, jo)) { return true; } return false; } jpype-0.6.2+dfsg/native/common/jp_classbase.cpp0000664000175000017500000000210113036015411020760 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPClassBase::JPClassBase(const JPTypeName& tname, jclass c) : JPObjectType(JPTypeName::_unknown, JPTypeName::fromType(JPTypeName::_void)), m_Name(tname) { m_Class = (jclass)JPEnv::getJava()->NewGlobalRef(c); } JPClassBase::~JPClassBase() { JPEnv::getJava()->DeleteGlobalRef(m_Class); } jpype-0.6.2+dfsg/native/common/jp_env.cpp0000664000175000017500000002120213036015411017613 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include /* * FIXME: use a less coupled way to call PyGILState_Ensure/Release() * in JPCleaner::~JPCleaner() if we wan't to target a non Python * implementation. */ #include namespace { // impl details HostEnvironment* s_Host = NULL; JPJavaEnv* s_Java = NULL; } JPJavaEnv* JPEnv::getJava() { return s_Java; } HostEnvironment* JPEnv::getHost() { return s_Host; } bool JPEnv::isInitialized() { return getJava() != NULL && getHost() != NULL; } void JPEnv::init(HostEnvironment* hostEnv) { s_Host = hostEnv; JPTypeName::init(); } void JPEnv::loadJVM(const string& vmPath, char ignoreUnrecognized, const StringVector& args) { TRACE_IN("JPEnv::loadJVM"); JavaVMInitArgs jniArgs; jniArgs.options = NULL; JPJavaEnv::load(vmPath); // prepare this ... jniArgs.version = JNI_VERSION_1_4; jniArgs.ignoreUnrecognized = ignoreUnrecognized; jniArgs.nOptions = (jint)args.size(); jniArgs.options = (JavaVMOption*)malloc(sizeof(JavaVMOption)*jniArgs.nOptions); memset(jniArgs.options, 0, sizeof(JavaVMOption)*jniArgs.nOptions); for (int i = 0; i < jniArgs.nOptions; i++) { jniArgs.options[i].optionString = (char*)args[i].c_str(); } s_Java = JPJavaEnv::CreateJavaVM((void*)&jniArgs); free(jniArgs.options); if (s_Java == NULL) { RAISE(JPypeException, "Unable to start JVM"); } JPTypeManager::init(); JPJni::init(); JPProxy::init(); TRACE_OUT; } void JPEnv::attachJVM(const string& vmPath) { TRACE_IN("JPEnv::attachJVM"); JPJavaEnv::load(vmPath); s_Java = JPJavaEnv::GetCreatedJavaVM(); if (s_Java == NULL) { RAISE(JPypeException, "Unable to attach to JVM"); } JPTypeManager::init(); JPJni::init(); JPProxy::init(); TRACE_OUT; } void JPEnv::attachCurrentThread() { s_Java->AttachCurrentThread(); } void JPEnv::attachCurrentThreadAsDaemon() { s_Java->AttachCurrentThreadAsDaemon(); } bool JPEnv::isThreadAttached() { return s_Java->isThreadAttached(); } void JPEnv::registerRef(HostRef* ref, HostRef* targetRef) { TRACE_IN("JPEnv::registerRef"); JPObject* objRef = s_Host->asObject(ref); JPCleaner cleaner; TRACE1("A"); jobject srcObject = objRef->getObject(); cleaner.addLocal(srcObject); JPJni::registerRef(s_Java->getReferenceQueue(), srcObject, (jlong)targetRef->copy()); TRACE_OUT; TRACE1("B"); } static int jpype_traceLevel = 0; #ifdef JPYPE_TRACING_INTERNAL static const bool trace_internal = true; #else static const bool trace_internal = false; #endif void JPypeTracer::traceIn(const char* msg) { if (trace_internal) { for (int i = 0; i < jpype_traceLevel; i++) { JPYPE_TRACING_OUTPUT << " "; } JPYPE_TRACING_OUTPUT << "" << endl; JPYPE_TRACING_OUTPUT.flush(); jpype_traceLevel ++; } } void JPypeTracer::traceOut(const char* msg, bool error) { if (trace_internal) { jpype_traceLevel --; for (int i = 0; i < jpype_traceLevel; i++) { JPYPE_TRACING_OUTPUT << " "; } if (error) { JPYPE_TRACING_OUTPUT << " " << endl; } else { JPYPE_TRACING_OUTPUT << " " << endl; } JPYPE_TRACING_OUTPUT.flush(); } } void JPypeTracer::trace1(const char* name, const string& msg) { if (trace_internal) { for (int i = 0; i < jpype_traceLevel; i++) { JPYPE_TRACING_OUTPUT << " "; } JPYPE_TRACING_OUTPUT << "" << name << " : " << msg << "" << endl; JPYPE_TRACING_OUTPUT.flush(); } } JPCleaner::JPCleaner() { } JPCleaner::~JPCleaner() { PyGILState_STATE state = PyGILState_Ensure(); //AT's comments on porting: // A variety of Unix compilers do not allow redefinition of the same variable in "for" cycles vector::iterator cur; for (cur = m_GlobalJavaObjects.begin(); cur != m_GlobalJavaObjects.end(); cur++) { JPEnv::getJava()->DeleteGlobalRef(*cur); } for (cur = m_LocalJavaObjects.begin(); cur != m_LocalJavaObjects.end(); cur++) { JPEnv::getJava()->DeleteLocalRef(*cur); } for (vector::iterator cur2 = m_HostObjects.begin(); cur2 != m_HostObjects.end(); cur2++) { (*cur2)->release(); } PyGILState_Release(state); } void JPCleaner::addGlobal(jobject obj) { m_GlobalJavaObjects.push_back(obj); } void JPCleaner::addLocal(jobject obj) { m_LocalJavaObjects.push_back(obj); } void JPCleaner::add(HostRef* obj) { m_HostObjects.push_back(obj); } void JPCleaner::removeGlobal(jobject obj) { for (vector::iterator cur = m_GlobalJavaObjects.begin(); cur != m_GlobalJavaObjects.end(); cur++) { if (*cur == obj) { m_GlobalJavaObjects.erase(cur); return; } } } void JPCleaner::removeLocal(jobject obj) { for (vector::iterator cur = m_LocalJavaObjects.begin(); cur != m_LocalJavaObjects.end(); cur++) { if (*cur == obj) { m_LocalJavaObjects.erase(cur); return; } } } void JPCleaner::remove(HostRef* obj) { for (vector::iterator cur2 = m_HostObjects.begin(); cur2 != m_HostObjects.end(); cur2++) { if (*cur2 == obj) { m_HostObjects.erase(cur2); return; } } } void JPCleaner::addAllGlobal(vector& r) { m_GlobalJavaObjects.insert(m_GlobalJavaObjects.end(), r.begin(), r.end()); } void JPCleaner::addAllGlobal(vector& r) { m_GlobalJavaObjects.insert(m_GlobalJavaObjects.end(), r.begin(), r.end()); } void JPCleaner::addAllLocal(vector& r) { m_LocalJavaObjects.insert(m_LocalJavaObjects.end(), r.begin(), r.end()); } void JPCleaner::addAllLocal(vector& r) { m_LocalJavaObjects.insert(m_LocalJavaObjects.end(), r.begin(), r.end()); } void JPCleaner::addAll(vector& r) { m_HostObjects.insert(m_HostObjects.end(), r.begin(), r.end()); } void JPCleaner::removeAllGlobal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { removeGlobal(*cur); } } void JPCleaner::removeAllLocal(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { removeLocal(*cur); } } void JPCleaner::removeAll(vector& r) { for (vector::iterator cur = r.begin(); cur != r.end(); cur++) { remove(*cur); } } HostRef::HostRef(void* data, bool acquire) { if (acquire) { m_HostData = JPEnv::getHost()->acquireRef(data); } else { m_HostData = data; } } HostRef::HostRef(void* data) { m_HostData = JPEnv::getHost()->acquireRef(data); } HostRef::~HostRef() { JPEnv::getHost()->releaseRef(m_HostData); } HostRef::HostRef(const HostRef& h) { m_HostData = JPEnv::getHost()->acquireRef(h.m_HostData); } HostRef& HostRef::operator=(const HostRef& h) { m_HostData = JPEnv::getHost()->acquireRef(h.m_HostData); return *this; } HostRef* HostRef::copy() { return new HostRef(m_HostData); } void HostRef::release() { delete this; } bool HostRef::isNull() { return JPEnv::getHost()->isRefNull(m_HostData); } void* HostRef::data() { return m_HostData; } JCharString::JCharString(const jchar* c) { m_Length = 0; while (c[m_Length] != 0) { m_Length ++; } m_Value = new jchar[m_Length+1]; m_Value[m_Length] = 0; for (unsigned int i = 0; i < m_Length; i++) { m_Value[i] = c[i]; } } JCharString::JCharString(const JCharString& c) { m_Length = c.m_Length; m_Value = new jchar[m_Length+1]; m_Value[m_Length] = 0; for (unsigned int i = 0; i < m_Length; i++) { m_Value[i] = c.m_Value[i]; } } JCharString::JCharString(size_t len) { m_Length = len; m_Value = new jchar[len+1]; for (size_t i = 0; i <= len; i++) { m_Value[i] = 0; } } JCharString::~JCharString() { if (m_Value != NULL) { delete[] m_Value; } } const jchar* JCharString::c_str() { return m_Value; } jpype-0.6.2+dfsg/native/common/jp_field.cpp0000664000175000017500000000721013036015411020111 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPField::JPField() : m_Name(""), m_Class(NULL), m_IsStatic(false), m_IsFinal(false), m_Field(), m_FieldID(NULL), m_Type() { } JPField::JPField(JPClass* clazz, jobject fld) { TRACE_IN("JPField::JPField1"); m_Class = clazz; m_Field = JPEnv::getJava()->NewGlobalRef(fld); m_Name = JPJni::getMemberName(fld); m_IsStatic = JPJni::isMemberStatic(fld); m_IsFinal = JPJni::isMemberFinal(fld); m_FieldID = JPEnv::getJava()->FromReflectedField(fld); m_Type = JPJni::getType(m_Field); TRACE2("field type", m_Type.getSimpleName()); TRACE_OUT } JPField::JPField(const JPField& fld) { TRACE_IN("JPField::JPField2"); m_Name = fld.m_Name; m_IsStatic = fld.m_IsStatic; m_IsFinal = fld.m_IsFinal; m_FieldID = fld.m_FieldID; m_Type = fld.m_Type; m_Class = fld.m_Class; m_Field = JPEnv::getJava()->NewGlobalRef(fld.m_Field); TRACE_OUT; } JPField::~JPField() { TRACE_IN("JPField::~JPField"); JPEnv::getJava()->DeleteGlobalRef(m_Field); TRACE_OUT; } bool JPField::isStatic() const { return m_IsStatic; } const string& JPField::getName() const { return m_Name; } HostRef* JPField::getStaticAttribute() { TRACE_IN("JPField::getStaticAttribute"); JPType* type = JPTypeManager::getType(m_Type); JPCleaner cleaner; jclass claz = m_Class->getClass(); cleaner.addLocal(claz); return type->getStaticValue(claz, m_FieldID, m_Type); TRACE_OUT; } void JPField::setStaticAttribute(HostRef* val) { TRACE_IN("JPField::setStaticAttribute"); if (m_IsFinal) { stringstream err; err << "Field " << m_Name << " is read-only"; RAISE(JPypeException, err.str().c_str()); } JPType* type = JPTypeManager::getType(m_Type); if (type->canConvertToJava(val) <= _explicit) { stringstream err; err << "unable to convert to " << type->getName().getSimpleName(); RAISE(JPypeException, err.str().c_str()); } JPCleaner cleaner; jclass claz = m_Class->getClass(); cleaner.addLocal(claz); type->setStaticValue(claz, m_FieldID, val); TRACE_OUT; } HostRef* JPField::getAttribute(jobject inst) { TRACE_IN("JPField::getAttribute"); TRACE2("field type", m_Type.getSimpleName()); JPType* type = JPTypeManager::getType(m_Type); return type->getInstanceValue(inst, m_FieldID, m_Type); TRACE_OUT; } void JPField::setAttribute(jobject inst, HostRef* val) { TRACE_IN("JPField::setAttribute"); if (m_IsFinal) { stringstream err; err << "Field " << m_Name << " is read-only"; RAISE(JPypeException, err.str().c_str()); } JPType* type = JPTypeManager::getType(m_Type); if (type->canConvertToJava(val) <= _explicit) { stringstream err; err << "unable to convert to " << type->getName().getSimpleName(); RAISE(JPypeException, err.str().c_str()); } type->setInstanceValue(inst, m_FieldID, val); TRACE_OUT; } jpype-0.6.2+dfsg/native/common/jp_invocationhandler.cpp0000664000175000017500000002762013036015411022544 0ustar takakitakaki#include jbyte JPypeInvocationHandler[] = { (jbyte)0xCA,(jbyte)0xFE,(jbyte)0xBA,(jbyte)0xBE,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x30,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x4A ,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65 ,(jbyte)0x72,(jbyte)0x07,(jbyte)0x00,(jbyte)0x01,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A ,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01,(jbyte)0x00,(jbyte)0x23,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x72,(jbyte)0x07,(jbyte)0x00,(jbyte)0x05,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x4A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x3C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x69,(jbyte)0x74,(jbyte)0x3E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x56,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x04,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x4C ,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x65,(jbyte)0x4E,(jbyte)0x75,(jbyte)0x6D,(jbyte)0x62,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6F,(jbyte)0x63 ,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x56,(jbyte)0x61,(jbyte)0x72,(jbyte)0x69,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x74,(jbyte)0x68 ,(jbyte)0x69,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76 ,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x72,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x69,(jbyte)0x6E ,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x6B,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x53,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F ,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66 ,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x4D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x3B,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C ,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x4D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x07,(jbyte)0x00,(jbyte)0x14 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x07,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x4E,(jbyte)0x61,(jbyte)0x6D,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x14,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61 ,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x74,(jbyte)0x72,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x17,(jbyte)0x0A,(jbyte)0x00 ,(jbyte)0x15,(jbyte)0x00,(jbyte)0x18,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x50 ,(jbyte)0x61,(jbyte)0x72,(jbyte)0x61,(jbyte)0x6D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x14,(jbyte)0x28,(jbyte)0x29,(jbyte)0x5B,(jbyte)0x4C ,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00 ,(jbyte)0x1D,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x74,(jbyte)0x75,(jbyte)0x72,(jbyte)0x6E,(jbyte)0x54,(jbyte)0x79 ,(jbyte)0x70,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x13,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C ,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x21,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x22,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x73 ,(jbyte)0x74,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x6B,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x74,(jbyte)0x72,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x3B,(jbyte)0x4A,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67 ,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x43,(jbyte)0x6C ,(jbyte)0x61,(jbyte)0x73,(jbyte)0x73,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65 ,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x25,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x26,(jbyte)0x01,(jbyte)0x00,(jbyte)0x05,(jbyte)0x70,(jbyte)0x72,(jbyte)0x6F,(jbyte)0x78 ,(jbyte)0x79,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63 ,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x6D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F ,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x2F,(jbyte)0x4D,(jbyte)0x65,(jbyte)0x74,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x3B ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x61,(jbyte)0x72,(jbyte)0x67,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x13,(jbyte)0x5B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x53,(jbyte)0x6F,(jbyte)0x75,(jbyte)0x72,(jbyte)0x63,(jbyte)0x65,(jbyte)0x46,(jbyte)0x69 ,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x76,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E ,(jbyte)0x48,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x64,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x72,(jbyte)0x2E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A ,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x2A,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x0D ,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x00 ,(jbyte)0x13,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x2C,(jbyte)0xB6,(jbyte)0x00 ,(jbyte)0x19,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x2D,(jbyte)0x2C,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x2C,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x23,(jbyte)0xB8,(jbyte)0x00,(jbyte)0x27,(jbyte)0xB0,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2A ,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x28,(jbyte)0x00,(jbyte)0x29 ,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x2A,(jbyte)0x00,(jbyte)0x2B,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x2C,(jbyte)0x00,(jbyte)0x2D ,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x2F }; jsize getJPypeInvocationHandlerLength() { return 980; } jpype-0.6.2+dfsg/native/common/jp_javaenv.cpp0000664000175000017500000002016513036015411020464 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include //AT's on porting: // 1) the original definition of global static object leads to crashing //on HP-UX platform. Cause: it is suspected to be an undefined order of initialization of static objects // // 2) TODO: in any case, use of static objects may impose problems in multi-threaded environment. //Therefore, they must be guarded with a mutex. #ifdef WIN32 #include "jp_platform_win32.h" #define PLATFORM_ADAPTER Win32PlatformAdapter #else #include "jp_platform_linux.h" #define PLATFORM_ADAPTER LinuxPlatformAdapter #endif JPPlatformAdapter* JPJavaEnv::GetAdapter() { static JPPlatformAdapter* adapter = new PLATFORM_ADAPTER(); return adapter; } #define JAVA_CHECK(msg) \ if (JPEnv::getJava()->ExceptionCheck()) \ { \ RAISE(JavaException, msg); \ } \ jint (JNICALL *JPJavaEnv::CreateJVM_Method)(JavaVM **pvm, void **penv, void *args); jint (JNICALL *JPJavaEnv::GetCreatedJVMs_Method)(JavaVM **pvm, jsize size, jsize* nVms); JNIEnv* JPJavaEnv::getJNIEnv() { JNIEnv* env; GetEnv(&env); return env; } void JPJavaEnv::load(const string& path) { TRACE_IN("JPJavaEnv::load"); // WIN32 GetAdapter()->loadLibrary((char*)path.c_str()); CreateJVM_Method = (jint (JNICALL *)(JavaVM ** ,void ** ,void *))GetAdapter()->getSymbol("JNI_CreateJavaVM"); GetCreatedJVMs_Method = (jint (JNICALL *)(JavaVM ** , jsize, jsize*))GetAdapter()->getSymbol("JNI_GetCreatedJavaVMs"); // No idea why I can't find this symbol .... no matter, it does not work anyway. //JNI_DestroyJavaVM = (jint (__stdcall *)(struct JavaVM_ *))GetAdapter()->getSymbol("DestroyJavaVM"); TRACE_OUT; } void JPJavaEnv::shutdown() { jvm = NULL; // unload the jvm library GetAdapter()->unloadLibrary(); } /** throw a JPypeException if the JVM is not started */ void JPJavaEnv::checkInitialized() { if (! JPEnv::isInitialized()) { RAISE( JPypeException, "Java Subsystem not started"); } } JPJavaEnv* JPJavaEnv::GetCreatedJavaVM() { // TODO: because we're returning NULL, jpype.attach() wont work. /* TRACE_IN("JPJavaEnv::GetCreatedJavaVM"); JavaVM* vm = NULL; jsize numVms; jint ret = GetCreatedJVMs_Method(&vm, 1, &numVms); if (ret < 0) { return NULL; } return new JPJavaEnv(vm); TRACE_OUT; */ return NULL; } JPJavaEnv* JPJavaEnv::CreateJavaVM(void* arg) { TRACE_IN("JPJavaEnv::CreateJavaVM"); JavaVM* vm = NULL; void* env; CreateJVM_Method(&vm, &env, arg); if (vm == NULL) { return NULL; } TRACE1("A"); return new JPJavaEnv(vm); TRACE_OUT; } int JPJavaEnv::DestroyJavaVM() { if (jvm != NULL) { int res = jvm->functions->DestroyJavaVM(jvm); if (res == 0) { jvm = NULL; } } return 0; } void JPJavaEnv::DeleteLocalRef(jobject obj) { TRACE_IN("JPJavaEnv::DeleteLocalRef"); TRACE1((long)obj); JNIEnv* env = getJNIEnv(); if (env != NULL) { env->functions->DeleteLocalRef(env, obj); } TRACE_OUT; } void JPJavaEnv::DeleteGlobalRef(jobject obj) { TRACE_IN("JPJavaEnv::DeleteGlobalRef"); TRACE1((long)obj); JNIEnv* env = getJNIEnv(); if (env != NULL) { env->functions->DeleteGlobalRef(env, obj); } TRACE_OUT; } jobject JPJavaEnv::NewLocalRef(jobject a0) { TRACE_IN("JPJavaEnv::NewLocalRef"); TRACE1((long)a0); jobject res; JNIEnv* env = getJNIEnv(); res = env->functions->NewLocalRef(env, a0); TRACE1((long)res); //, JPJni::getClassName(a0).getSimpleName()); return res; TRACE_OUT; } jobject JPJavaEnv::NewGlobalRef(jobject a0) { TRACE_IN("JPJavaEnv::NewGlobalRef"); TRACE1((long)a0); jobject res; JNIEnv* env = getJNIEnv(); res = env->functions->NewGlobalRef(env, a0); TRACE1((long)res); //, JPJni::getClassName(a0).getSimpleName()); return res; TRACE_OUT; } bool JPJavaEnv::ExceptionCheck() { JNIEnv* env = getJNIEnv(); if (env != NULL) { return (env->functions->ExceptionCheck(env) ? true : false); } return false; } void JPJavaEnv::ExceptionDescribe() { JNIEnv* env = getJNIEnv(); env->functions->ExceptionDescribe(env); } void JPJavaEnv::ExceptionClear() { JNIEnv* env = getJNIEnv(); if (env != NULL) { env->functions->ExceptionClear(env); } } jint JPJavaEnv::AttachCurrentThread() { // TODO find a way to get A JVM once JPJavaEnv is not a singleton anymore ... JNIEnv* env; jint res = jvm->functions->AttachCurrentThread(jvm, (void**)&env, NULL); JAVA_CHECK("AttachCurrentThread"); return res; } jint JPJavaEnv::AttachCurrentThreadAsDaemon() { // TODO find a way to get A JVM once JPJavaEnv is not a singleton anymore ... JNIEnv* env; jint res = jvm->functions->AttachCurrentThreadAsDaemon(jvm, (void**)&env, NULL); JAVA_CHECK("AttachCurrentThreadAsDaemon"); return res; } bool JPJavaEnv::isThreadAttached() { return JPEnv::getJava()->getJNIEnv() != NULL; } jint JPJavaEnv::DetachCurrentThread() { return jvm->functions->DetachCurrentThread(jvm); } jint JPJavaEnv::GetEnv(JNIEnv** env) { if (jvm == NULL) { *env = NULL; return JNI_EDETACHED; } // This function must not be put in GOTO_EXTERNAL/RETURN_EXTERNAL because it is called from WITHIN such a block already jint res; res = jvm->functions->GetEnv(jvm, (void**)env, JNI_VERSION_1_2); return res; } jint JPJavaEnv::ThrowNew(jclass clazz, const char* msg) { JNIEnv* env = getJNIEnv(); return env->functions->ThrowNew(env, clazz, msg); } jint JPJavaEnv::Throw(jthrowable th) { JNIEnv* env = getJNIEnv(); return env->functions->Throw(env, th); } jthrowable JPJavaEnv::ExceptionOccurred() { jthrowable res; JNIEnv* env = getJNIEnv(); res = env->functions->ExceptionOccurred(env); return res; } jobject JPJavaEnv::NewDirectByteBuffer(void* address, jlong capacity) { TRACE_IN("JPJavaEnv::NewDirectByteBuffer"); JNIEnv* env = getJNIEnv(); jobject res = env->functions->NewDirectByteBuffer(env, address, capacity); JAVA_CHECK("NewDirectByteBuffer"); TRACE1((long)res); return res; TRACE_OUT; } jobject JPJavaEnv::NewObjectA(jclass a0, jmethodID a1, jvalue* a2) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->AllocObject(env, a0); JAVA_CHECK("NewObjectA"); env->functions->CallVoidMethodA(env, res, a1, a2); if (ExceptionCheck()) { DeleteLocalRef(res); } JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObjectA"); return res; } jobject JPJavaEnv::NewObject(jclass a0, jmethodID a1) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->AllocObject(env, a0); JAVA_CHECK("NewObject"); env->functions->CallVoidMethod(env, res, a1); if (ExceptionCheck()) { DeleteLocalRef(res); } JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObject"); return res; } void* JPJavaEnv::GetPrimitiveArrayCritical(jarray array, jboolean *isCopy) { JNIEnv* env = getJNIEnv(); void* res = env->functions->GetPrimitiveArrayCritical(env, array, isCopy); JAVA_CHECK("GetPrimitiveArrayCritical"); return res; } void JPJavaEnv::ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleasePrimitiveArrayCritical(env, array,carray,mode); JAVA_CHECK("ReleasePrimitiveArrayCritical"); } jpype-0.6.2+dfsg/native/common/jp_javaenv_autogen.cpp0000664000175000017500000013360513036015411022212 0ustar takakitakaki /***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ // This code has been automatically generated ... No not edit #include #define JAVA_CHECK(msg) \ if (JPEnv::getJava()->ExceptionCheck()) \ { \ RAISE(JavaException, msg); \ } \ jbyte JPJavaEnv::GetStaticByteField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jbyte res = env->functions->GetStaticByteField(env, clazz, fid); JAVA_CHECK("GetStaticByteField"); return res; } jbyte JPJavaEnv::GetByteField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jbyte res = env->functions->GetByteField(env, clazz, fid); JAVA_CHECK("GetByteField"); return res; } void JPJavaEnv::SetStaticByteField(jclass clazz, jfieldID fid, jbyte val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticByteField(env, clazz, fid, val); JAVA_CHECK("SetStaticByteField"); } void JPJavaEnv::SetByteField(jobject clazz, jfieldID fid, jbyte val) { JNIEnv* env = getJNIEnv(); env->functions->SetByteField(env, clazz, fid, val); JAVA_CHECK("SetByteField"); } jbyte JPJavaEnv::CallStaticByteMethodA(jclass clazz, jmethodID mid, jvalue* val) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticByteMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallStaticByteMethod(jclass clazz, jmethodID mid) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticByteMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallByteMethodA(jobject obj, jmethodID mid, jvalue* val) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallByteMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallByteMethod(jobject obj, jmethodID mid) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallByteMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallNonvirtualByteMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualByteMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jbyte JPJavaEnv::CallNonvirtualByteMethod(jobject obj, jclass claz, jmethodID mid) { jbyte res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualByteMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Byte"); return res; } jshort JPJavaEnv::GetStaticShortField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jshort res = env->functions->GetStaticShortField(env, clazz, fid); JAVA_CHECK("GetStaticShortField"); return res; } jshort JPJavaEnv::GetShortField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jshort res = env->functions->GetShortField(env, clazz, fid); JAVA_CHECK("GetShortField"); return res; } void JPJavaEnv::SetStaticShortField(jclass clazz, jfieldID fid, jshort val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticShortField(env, clazz, fid, val); JAVA_CHECK("SetStaticShortField"); } void JPJavaEnv::SetShortField(jobject clazz, jfieldID fid, jshort val) { JNIEnv* env = getJNIEnv(); env->functions->SetShortField(env, clazz, fid, val); JAVA_CHECK("SetShortField"); } jshort JPJavaEnv::CallStaticShortMethodA(jclass clazz, jmethodID mid, jvalue* val) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticShortMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallStaticShortMethod(jclass clazz, jmethodID mid) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticShortMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallShortMethodA(jobject obj, jmethodID mid, jvalue* val) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallShortMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallShortMethod(jobject obj, jmethodID mid) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallShortMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallNonvirtualShortMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualShortMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jshort JPJavaEnv::CallNonvirtualShortMethod(jobject obj, jclass claz, jmethodID mid) { jshort res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualShortMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Short"); return res; } jint JPJavaEnv::GetStaticIntField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jint res = env->functions->GetStaticIntField(env, clazz, fid); JAVA_CHECK("GetStaticIntField"); return res; } jint JPJavaEnv::GetIntField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jint res = env->functions->GetIntField(env, clazz, fid); JAVA_CHECK("GetIntField"); return res; } void JPJavaEnv::SetStaticIntField(jclass clazz, jfieldID fid, jint val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticIntField(env, clazz, fid, val); JAVA_CHECK("SetStaticIntField"); } void JPJavaEnv::SetIntField(jobject clazz, jfieldID fid, jint val) { JNIEnv* env = getJNIEnv(); env->functions->SetIntField(env, clazz, fid, val); JAVA_CHECK("SetIntField"); } jint JPJavaEnv::CallStaticIntMethodA(jclass clazz, jmethodID mid, jvalue* val) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticIntMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallStaticIntMethod(jclass clazz, jmethodID mid) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticIntMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallIntMethodA(jobject obj, jmethodID mid, jvalue* val) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallIntMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallIntMethod(jobject obj, jmethodID mid) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallIntMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallNonvirtualIntMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualIntMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jint JPJavaEnv::CallNonvirtualIntMethod(jobject obj, jclass claz, jmethodID mid) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualIntMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Int"); return res; } jlong JPJavaEnv::GetStaticLongField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jlong res = env->functions->GetStaticLongField(env, clazz, fid); JAVA_CHECK("GetStaticLongField"); return res; } jlong JPJavaEnv::GetLongField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jlong res = env->functions->GetLongField(env, clazz, fid); JAVA_CHECK("GetLongField"); return res; } void JPJavaEnv::SetStaticLongField(jclass clazz, jfieldID fid, jlong val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticLongField(env, clazz, fid, val); JAVA_CHECK("SetStaticLongField"); } void JPJavaEnv::SetLongField(jobject clazz, jfieldID fid, jlong val) { JNIEnv* env = getJNIEnv(); env->functions->SetLongField(env, clazz, fid, val); JAVA_CHECK("SetLongField"); } jlong JPJavaEnv::CallStaticLongMethodA(jclass clazz, jmethodID mid, jvalue* val) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticLongMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallStaticLongMethod(jclass clazz, jmethodID mid) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticLongMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallLongMethodA(jobject obj, jmethodID mid, jvalue* val) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallLongMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallLongMethod(jobject obj, jmethodID mid) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallLongMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallNonvirtualLongMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualLongMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jlong JPJavaEnv::CallNonvirtualLongMethod(jobject obj, jclass claz, jmethodID mid) { jlong res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualLongMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Long"); return res; } jfloat JPJavaEnv::GetStaticFloatField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jfloat res = env->functions->GetStaticFloatField(env, clazz, fid); JAVA_CHECK("GetStaticFloatField"); return res; } jfloat JPJavaEnv::GetFloatField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jfloat res = env->functions->GetFloatField(env, clazz, fid); JAVA_CHECK("GetFloatField"); return res; } void JPJavaEnv::SetStaticFloatField(jclass clazz, jfieldID fid, jfloat val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticFloatField(env, clazz, fid, val); JAVA_CHECK("SetStaticFloatField"); } void JPJavaEnv::SetFloatField(jobject clazz, jfieldID fid, jfloat val) { JNIEnv* env = getJNIEnv(); env->functions->SetFloatField(env, clazz, fid, val); JAVA_CHECK("SetFloatField"); } jfloat JPJavaEnv::CallStaticFloatMethodA(jclass clazz, jmethodID mid, jvalue* val) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticFloatMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallStaticFloatMethod(jclass clazz, jmethodID mid) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticFloatMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallFloatMethodA(jobject obj, jmethodID mid, jvalue* val) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallFloatMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallFloatMethod(jobject obj, jmethodID mid) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallFloatMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallNonvirtualFloatMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualFloatMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jfloat JPJavaEnv::CallNonvirtualFloatMethod(jobject obj, jclass claz, jmethodID mid) { jfloat res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualFloatMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Float"); return res; } jdouble JPJavaEnv::GetStaticDoubleField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jdouble res = env->functions->GetStaticDoubleField(env, clazz, fid); JAVA_CHECK("GetStaticDoubleField"); return res; } jdouble JPJavaEnv::GetDoubleField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jdouble res = env->functions->GetDoubleField(env, clazz, fid); JAVA_CHECK("GetDoubleField"); return res; } void JPJavaEnv::SetStaticDoubleField(jclass clazz, jfieldID fid, jdouble val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticDoubleField(env, clazz, fid, val); JAVA_CHECK("SetStaticDoubleField"); } void JPJavaEnv::SetDoubleField(jobject clazz, jfieldID fid, jdouble val) { JNIEnv* env = getJNIEnv(); env->functions->SetDoubleField(env, clazz, fid, val); JAVA_CHECK("SetDoubleField"); } jdouble JPJavaEnv::CallStaticDoubleMethodA(jclass clazz, jmethodID mid, jvalue* val) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticDoubleMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallStaticDoubleMethod(jclass clazz, jmethodID mid) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticDoubleMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallDoubleMethodA(jobject obj, jmethodID mid, jvalue* val) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallDoubleMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallDoubleMethod(jobject obj, jmethodID mid) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallDoubleMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallNonvirtualDoubleMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualDoubleMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jdouble JPJavaEnv::CallNonvirtualDoubleMethod(jobject obj, jclass claz, jmethodID mid) { jdouble res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualDoubleMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Double"); return res; } jchar JPJavaEnv::GetStaticCharField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jchar res = env->functions->GetStaticCharField(env, clazz, fid); JAVA_CHECK("GetStaticCharField"); return res; } jchar JPJavaEnv::GetCharField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jchar res = env->functions->GetCharField(env, clazz, fid); JAVA_CHECK("GetCharField"); return res; } void JPJavaEnv::SetStaticCharField(jclass clazz, jfieldID fid, jchar val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticCharField(env, clazz, fid, val); JAVA_CHECK("SetStaticCharField"); } void JPJavaEnv::SetCharField(jobject clazz, jfieldID fid, jchar val) { JNIEnv* env = getJNIEnv(); env->functions->SetCharField(env, clazz, fid, val); JAVA_CHECK("SetCharField"); } jchar JPJavaEnv::CallStaticCharMethodA(jclass clazz, jmethodID mid, jvalue* val) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticCharMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallStaticCharMethod(jclass clazz, jmethodID mid) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticCharMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallCharMethodA(jobject obj, jmethodID mid, jvalue* val) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallCharMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallCharMethod(jobject obj, jmethodID mid) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallCharMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallNonvirtualCharMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualCharMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jchar JPJavaEnv::CallNonvirtualCharMethod(jobject obj, jclass claz, jmethodID mid) { jchar res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualCharMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Char"); return res; } jboolean JPJavaEnv::GetStaticBooleanField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jboolean res = env->functions->GetStaticBooleanField(env, clazz, fid); JAVA_CHECK("GetStaticBooleanField"); return res; } jboolean JPJavaEnv::GetBooleanField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jboolean res = env->functions->GetBooleanField(env, clazz, fid); JAVA_CHECK("GetBooleanField"); return res; } void JPJavaEnv::SetStaticBooleanField(jclass clazz, jfieldID fid, jboolean val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticBooleanField(env, clazz, fid, val); JAVA_CHECK("SetStaticBooleanField"); } void JPJavaEnv::SetBooleanField(jobject clazz, jfieldID fid, jboolean val) { JNIEnv* env = getJNIEnv(); env->functions->SetBooleanField(env, clazz, fid, val); JAVA_CHECK("SetBooleanField"); } jboolean JPJavaEnv::CallStaticBooleanMethodA(jclass clazz, jmethodID mid, jvalue* val) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticBooleanMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallStaticBooleanMethod(jclass clazz, jmethodID mid) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticBooleanMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallBooleanMethodA(jobject obj, jmethodID mid, jvalue* val) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallBooleanMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallBooleanMethod(jobject obj, jmethodID mid) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallBooleanMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallNonvirtualBooleanMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualBooleanMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jboolean JPJavaEnv::CallNonvirtualBooleanMethod(jobject obj, jclass claz, jmethodID mid) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualBooleanMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Boolean"); return res; } jobject JPJavaEnv::GetStaticObjectField(jclass clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jobject res = env->functions->GetStaticObjectField(env, clazz, fid); JAVA_CHECK("GetStaticObjectField"); return res; } jobject JPJavaEnv::GetObjectField(jobject clazz, jfieldID fid) { JNIEnv* env = getJNIEnv(); jobject res = env->functions->GetObjectField(env, clazz, fid); JAVA_CHECK("GetObjectField"); return res; } void JPJavaEnv::SetStaticObjectField(jclass clazz, jfieldID fid, jobject val) { JNIEnv* env = getJNIEnv(); env->functions->SetStaticObjectField(env, clazz, fid, val); JAVA_CHECK("SetStaticObjectField"); } void JPJavaEnv::SetObjectField(jobject clazz, jfieldID fid, jobject val) { JNIEnv* env = getJNIEnv(); env->functions->SetObjectField(env, clazz, fid, val); JAVA_CHECK("SetObjectField"); } jobject JPJavaEnv::CallStaticObjectMethodA(jclass clazz, jmethodID mid, jvalue* val) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticObjectMethodA(env, clazz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallStaticObjectMethod(jclass clazz, jmethodID mid) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallStaticObjectMethod(env, clazz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallObjectMethodA(jobject obj, jmethodID mid, jvalue* val) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallObjectMethodA(env, obj, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallObjectMethod(jobject obj, jmethodID mid) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallObjectMethod(env, obj, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallNonvirtualObjectMethodA(jobject obj, jclass claz, jmethodID mid, jvalue* val) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualObjectMethodA(env, obj, claz, mid, val); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jobject JPJavaEnv::CallNonvirtualObjectMethod(jobject obj, jclass claz, jmethodID mid) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->CallNonvirtualObjectMethod(env, obj, claz, mid); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("Object"); return res; } jbyteArray JPJavaEnv::NewByteArray(jint len) { JNIEnv* env = getJNIEnv(); jbyteArray res = env->functions->NewByteArray(env, len); JAVA_CHECK("NewByteArray"); return res; } void JPJavaEnv::SetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetByteArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetByteArrayRegion"); } void JPJavaEnv::GetByteArrayRegion(jbyteArray array, int start, int len, jbyte* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetByteArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetByteArrayRegion"); } jbyte* JPJavaEnv::GetByteArrayElements(jbyteArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jbyte* res = env->functions->GetByteArrayElements(env, array, isCopy); JAVA_CHECK("GetByteArrayElements"); return res; } void JPJavaEnv::ReleaseByteArrayElements(jbyteArray array, jbyte* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseByteArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseByteArrayElements"); } jshortArray JPJavaEnv::NewShortArray(jint len) { JNIEnv* env = getJNIEnv(); jshortArray res = env->functions->NewShortArray(env, len); JAVA_CHECK("NewShortArray"); return res; } void JPJavaEnv::SetShortArrayRegion(jshortArray array, int start, int len, jshort* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetShortArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetShortArrayRegion"); } void JPJavaEnv::GetShortArrayRegion(jshortArray array, int start, int len, jshort* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetShortArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetShortArrayRegion"); } jshort* JPJavaEnv::GetShortArrayElements(jshortArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jshort* res = env->functions->GetShortArrayElements(env, array, isCopy); JAVA_CHECK("GetShortArrayElements"); return res; } void JPJavaEnv::ReleaseShortArrayElements(jshortArray array, jshort* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseShortArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseShortArrayElements"); } jintArray JPJavaEnv::NewIntArray(jint len) { JNIEnv* env = getJNIEnv(); jintArray res = env->functions->NewIntArray(env, len); JAVA_CHECK("NewIntArray"); return res; } void JPJavaEnv::SetIntArrayRegion(jintArray array, int start, int len, jint* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetIntArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetIntArrayRegion"); } void JPJavaEnv::GetIntArrayRegion(jintArray array, int start, int len, jint* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetIntArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetIntArrayRegion"); } jint* JPJavaEnv::GetIntArrayElements(jintArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jint* res = env->functions->GetIntArrayElements(env, array, isCopy); JAVA_CHECK("GetIntArrayElements"); return res; } void JPJavaEnv::ReleaseIntArrayElements(jintArray array, jint* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseIntArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseIntArrayElements"); } jlongArray JPJavaEnv::NewLongArray(jint len) { JNIEnv* env = getJNIEnv(); jlongArray res = env->functions->NewLongArray(env, len); JAVA_CHECK("NewLongArray"); return res; } void JPJavaEnv::SetLongArrayRegion(jlongArray array, int start, int len, jlong* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetLongArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetLongArrayRegion"); } void JPJavaEnv::GetLongArrayRegion(jlongArray array, int start, int len, jlong* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetLongArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetLongArrayRegion"); } jlong* JPJavaEnv::GetLongArrayElements(jlongArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jlong* res = env->functions->GetLongArrayElements(env, array, isCopy); JAVA_CHECK("GetLongArrayElements"); return res; } void JPJavaEnv::ReleaseLongArrayElements(jlongArray array, jlong* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseLongArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseLongArrayElements"); } jfloatArray JPJavaEnv::NewFloatArray(jint len) { JNIEnv* env = getJNIEnv(); jfloatArray res = env->functions->NewFloatArray(env, len); JAVA_CHECK("NewFloatArray"); return res; } void JPJavaEnv::SetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetFloatArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetFloatArrayRegion"); } void JPJavaEnv::GetFloatArrayRegion(jfloatArray array, int start, int len, jfloat* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetFloatArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetFloatArrayRegion"); } jfloat* JPJavaEnv::GetFloatArrayElements(jfloatArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jfloat* res = env->functions->GetFloatArrayElements(env, array, isCopy); JAVA_CHECK("GetFloatArrayElements"); return res; } void JPJavaEnv::ReleaseFloatArrayElements(jfloatArray array, jfloat* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseFloatArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseFloatArrayElements"); } jdoubleArray JPJavaEnv::NewDoubleArray(jint len) { JNIEnv* env = getJNIEnv(); jdoubleArray res = env->functions->NewDoubleArray(env, len); JAVA_CHECK("NewDoubleArray"); return res; } void JPJavaEnv::SetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetDoubleArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetDoubleArrayRegion"); } void JPJavaEnv::GetDoubleArrayRegion(jdoubleArray array, int start, int len, jdouble* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetDoubleArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetDoubleArrayRegion"); } jdouble* JPJavaEnv::GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jdouble* res = env->functions->GetDoubleArrayElements(env, array, isCopy); JAVA_CHECK("GetDoubleArrayElements"); return res; } void JPJavaEnv::ReleaseDoubleArrayElements(jdoubleArray array, jdouble* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseDoubleArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseDoubleArrayElements"); } jcharArray JPJavaEnv::NewCharArray(jint len) { JNIEnv* env = getJNIEnv(); jcharArray res = env->functions->NewCharArray(env, len); JAVA_CHECK("NewCharArray"); return res; } void JPJavaEnv::SetCharArrayRegion(jcharArray array, int start, int len, jchar* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetCharArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetCharArrayRegion"); } void JPJavaEnv::GetCharArrayRegion(jcharArray array, int start, int len, jchar* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetCharArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetCharArrayRegion"); } jchar* JPJavaEnv::GetCharArrayElements(jcharArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jchar* res = env->functions->GetCharArrayElements(env, array, isCopy); JAVA_CHECK("GetCharArrayElements"); return res; } void JPJavaEnv::ReleaseCharArrayElements(jcharArray array, jchar* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseCharArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseCharArrayElements"); } jbooleanArray JPJavaEnv::NewBooleanArray(jint len) { JNIEnv* env = getJNIEnv(); jbooleanArray res = env->functions->NewBooleanArray(env, len); JAVA_CHECK("NewBooleanArray"); return res; } void JPJavaEnv::SetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals) { JNIEnv* env = getJNIEnv(); env->functions->SetBooleanArrayRegion(env, array, start, len, vals); JAVA_CHECK("SetBooleanArrayRegion"); } void JPJavaEnv::GetBooleanArrayRegion(jbooleanArray array, int start, int len, jboolean* vals) { JNIEnv* env = getJNIEnv(); env->functions->GetBooleanArrayRegion(env, array, start, len, vals); JAVA_CHECK("GetBooleanArrayRegion"); } jboolean* JPJavaEnv::GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy) { JNIEnv* env = getJNIEnv(); jboolean* res = env->functions->GetBooleanArrayElements(env, array, isCopy); JAVA_CHECK("GetBooleanArrayElements"); return res; } void JPJavaEnv::ReleaseBooleanArrayElements(jbooleanArray array, jboolean* v, jint mode) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseBooleanArrayElements(env, array, v, mode); JAVA_CHECK("ReleaseBooleanArrayElements"); } int JPJavaEnv::MonitorEnter(jobject a0) { int res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->MonitorEnter(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("MonitorEnter"); return res; } int JPJavaEnv::MonitorExit(jobject a0) { int res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->MonitorExit(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("MonitorExit"); return res; } jmethodID JPJavaEnv::FromReflectedMethod(jobject a0) { jmethodID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->FromReflectedMethod(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("FromReflectedMethod"); return res; } jfieldID JPJavaEnv::FromReflectedField(jobject a0) { jfieldID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->FromReflectedField(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("FromReflectedField"); return res; } jclass JPJavaEnv::FindClass(const char* a0) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->FindClass(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("FindClass"); return res; } jboolean JPJavaEnv::IsInstanceOf(jobject a0, jclass a1) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->IsInstanceOf(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("IsInstanceOf"); return res; } jobjectArray JPJavaEnv::NewObjectArray(int a0, jclass a1, jobject a2) { jobjectArray res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->NewObjectArray(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewObjectArray"); return res; } void JPJavaEnv::SetObjectArrayElement(jobjectArray a0, int a1, jobject a2) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->SetObjectArrayElement(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("SetObjectArrayElement"); } void JPJavaEnv::CallStaticVoidMethodA(jclass a0, jmethodID a1, jvalue* a2) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->CallStaticVoidMethodA(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("CallStaticVoidMethodA"); } void JPJavaEnv::CallVoidMethodA(jobject a0, jmethodID a1, jvalue* a2) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->CallVoidMethodA(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("CallVoidMethodA"); } void JPJavaEnv::CallVoidMethod(jobject a0, jmethodID a1) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->CallVoidMethod(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("CallVoidMethod"); } jboolean JPJavaEnv::IsAssignableFrom(jclass a0, jclass a1) { jboolean res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->IsAssignableFrom(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("IsAssignableFrom"); return res; } jstring JPJavaEnv::NewString(const jchar* a0, int a1) { jstring res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->NewString(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("NewString"); return res; } jclass JPJavaEnv::GetSuperclass(jclass a0) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetSuperclass(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetSuperclass"); return res; } const char* JPJavaEnv::GetStringUTFChars(jstring a0, jboolean* a1) { const char* res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetStringUTFChars(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetStringUTFChars"); return res; } void JPJavaEnv::ReleaseStringUTFChars(jstring a0, const char* a1) { JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); env->functions->ReleaseStringUTFChars(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("ReleaseStringUTFChars"); } jsize JPJavaEnv::GetArrayLength(jarray a0) { jsize res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetArrayLength(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetArrayLength"); return res; } jobject JPJavaEnv::GetObjectArrayElement(jobjectArray a0, int a1) { jobject res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetObjectArrayElement(env, a0, a1); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetObjectArrayElement"); return res; } jclass JPJavaEnv::GetObjectClass(jobject a0) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetObjectClass(env, a0); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetObjectClass"); return res; } jmethodID JPJavaEnv::GetMethodID(jclass a0, const char* a1, const char* a2) { jmethodID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetMethodID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetMethodID"); return res; } jmethodID JPJavaEnv::GetStaticMethodID(jclass a0, const char* a1, const char* a2) { jmethodID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetStaticMethodID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetStaticMethodID"); return res; } jfieldID JPJavaEnv::GetFieldID(jclass a0, const char* a1, const char* a2) { jfieldID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetFieldID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetFieldID"); return res; } jfieldID JPJavaEnv::GetStaticFieldID(jclass a0, const char* a1, const char* a2) { jfieldID res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->GetStaticFieldID(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("GetStaticFieldID"); return res; } const jchar* JPJavaEnv::GetStringChars(jstring a0, jboolean* a1) { const jchar* res; JNIEnv* env = getJNIEnv(); res = env->functions->GetStringChars(env, a0, a1); JAVA_CHECK("GetStringChars"); return res; } void JPJavaEnv::ReleaseStringChars(jstring a0, const jchar* a1) { JNIEnv* env = getJNIEnv(); env->functions->ReleaseStringChars(env, a0, a1); JAVA_CHECK("ReleaseStringChars"); } jsize JPJavaEnv::GetStringLength(jstring a0) { jsize res; JNIEnv* env = getJNIEnv(); res = env->functions->GetStringLength(env, a0); JAVA_CHECK("GetStringLength"); return res; } jclass JPJavaEnv::DefineClass(const char* a0, jobject a1, const jbyte* a2, jsize a3) { jclass res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->DefineClass(env, a0, a1, a2, a3); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("DefineClass"); return res; } jint JPJavaEnv::RegisterNatives(jclass a0, const JNINativeMethod* a1, jint a2) { jint res; JNIEnv* env = getJNIEnv(); void* _save = JPEnv::getHost()->gotoExternal(); res = env->functions->RegisterNatives(env, a0, a1, a2); JPEnv::getHost()->returnExternal(_save); JAVA_CHECK("RegisterNatives"); return res; } jpype-0.6.2+dfsg/native/common/jp_jniutil.cpp0000664000175000017500000006436113036015411020516 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include namespace { // impl detail jclass objectClass; jmethodID getClassID; jmethodID toStringID; jmethodID hashCodeID; jmethodID getNameID; jmethodID getDeclaredFieldsID; jmethodID getDeclaredMethodsID; jmethodID getInterfacesID; jmethodID getFieldsID; jmethodID getMethodsID; jmethodID getDeclaredConstructorsID; jmethodID getConstructorsID; jmethodID isInterfaceID; jmethodID getClassModifiersID; jclass modifierClass; jmethodID isStaticID; jmethodID isPublicID; jmethodID isAbstractID; jmethodID isFinalID; jclass classLoaderClass; jmethodID getSystemClassLoaderID; jclass memberClass; jmethodID getModifiersID; jmethodID getMemberNameID; jclass fieldClass; jmethodID getTypeID; jclass methodClass; jclass constructorClass; jmethodID getReturnTypeID; jmethodID isSyntheticMethodID; jmethodID isVarArgsMethodID; jmethodID getParameterTypesID; jmethodID getConstructorParameterTypesID; jclass throwableClass; jmethodID getMessageID; jmethodID printStackTraceID; jclass stringWriterClass; jclass printWriterClass; jmethodID stringWriterID; jmethodID printWriterID; jmethodID flushID; jclass numberClass; jclass booleanClass; jclass charClass; jclass byteClass; jclass shortClass; jclass intClass; jclass floatClass; jmethodID intValueID; jmethodID longValueID; jmethodID doubleValueID; jmethodID booleanValueID; jmethodID charValueID; jclass JPypeReferenceClass; jmethodID JPypeReferenceConstructorMethod; jclass JPypeReferenceQueueClass; jmethodID JPypeReferenceQueueConstructorMethod; jmethodID JPypeReferenceQueueRegisterMethod; jmethodID JPypeReferenceQueueStartMethod; jmethodID JPypeReferenceQueueRunMethod; jmethodID JPypeReferenceQueueStopMethod; } namespace JPJni { jclass s_ClassClass; jclass s_StringClass; jclass s_NoSuchMethodErrorClass; jclass s_RuntimeExceptionClass; jclass s_ProxyClass = 0; jmethodID s_NewProxyInstanceID; jlong s_minByte; jlong s_maxByte; jlong s_minShort; jlong s_maxShort; jlong s_minInt; jlong s_maxInt; jfloat s_minFloat; jfloat s_maxFloat; void init() { objectClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Object")); s_StringClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/String")); getClassID = JPEnv::getJava()->GetMethodID(objectClass, "getClass", "()Ljava/lang/Class;"); toStringID = JPEnv::getJava()->GetMethodID(objectClass, "toString", "()Ljava/lang/String;"); hashCodeID = JPEnv::getJava()->GetMethodID(objectClass, "hashCode", "()I"); s_ClassClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Class")); getNameID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getName", "()Ljava/lang/String;"); getDeclaredFieldsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getDeclaredFields", "()[Ljava/lang/reflect/Field;"); getDeclaredMethodsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;"); getMethodsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getMethods", "()[Ljava/lang/reflect/Method;"); getFieldsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getFields", "()[Ljava/lang/reflect/Field;"); getDeclaredConstructorsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getDeclaredConstructors", "()[Ljava/lang/reflect/Constructor;"); getConstructorsID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;"); isInterfaceID = JPEnv::getJava()->GetMethodID(s_ClassClass, "isInterface", "()Z"); getClassModifiersID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getModifiers", "()I"); getInterfacesID = JPEnv::getJava()->GetMethodID(s_ClassClass, "getInterfaces", "()[Ljava/lang/Class;"); modifierClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/reflect/Modifier")); isStaticID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isStatic", "(I)Z"); isPublicID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isPublic", "(I)Z"); isAbstractID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isAbstract", "(I)Z"); isFinalID = JPEnv::getJava()->GetStaticMethodID(modifierClass, "isFinal", "(I)Z"); classLoaderClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/ClassLoader")); getSystemClassLoaderID = JPEnv::getJava()->GetStaticMethodID(classLoaderClass, "getSystemClassLoader", "()Ljava/lang/ClassLoader;"); s_NoSuchMethodErrorClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/NoSuchMethodError") ); s_RuntimeExceptionClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/RuntimeException") ); s_ProxyClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/reflect/Proxy") ); s_NewProxyInstanceID = JPEnv::getJava()->GetStaticMethodID(s_ProxyClass, "newProxyInstance", "(Ljava/lang/ClassLoader;[Ljava/lang/Class;Ljava/lang/reflect/InvocationHandler;)Ljava/lang/Object;"); memberClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/reflect/Member")); getModifiersID = JPEnv::getJava()->GetMethodID(memberClass, "getModifiers", "()I"); getMemberNameID = JPEnv::getJava()->GetMethodID(memberClass, "getName", "()Ljava/lang/String;"); fieldClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/reflect/Field")); getTypeID = JPEnv::getJava()->GetMethodID(fieldClass, "getType", "()Ljava/lang/Class;"); methodClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/reflect/Method")); constructorClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/reflect/Constructor")); getReturnTypeID = JPEnv::getJava()->GetMethodID(methodClass, "getReturnType", "()Ljava/lang/Class;"); getParameterTypesID = JPEnv::getJava()->GetMethodID(methodClass, "getParameterTypes", "()[Ljava/lang/Class;"); isSyntheticMethodID = JPEnv::getJava()->GetMethodID(methodClass, "isSynthetic", "()Z"); isVarArgsMethodID = JPEnv::getJava()->GetMethodID(methodClass, "isVarArgs", "()Z"); getConstructorParameterTypesID = JPEnv::getJava()->GetMethodID(constructorClass, "getParameterTypes", "()[Ljava/lang/Class;"); throwableClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Throwable")); getMessageID = JPEnv::getJava()->GetMethodID(throwableClass, "getMessage", "()Ljava/lang/String;"); printStackTraceID = JPEnv::getJava()->GetMethodID(throwableClass, "printStackTrace", "(Ljava/io/PrintWriter;)V"); stringWriterClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/io/StringWriter")); printWriterClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/io/PrintWriter")); stringWriterID = JPEnv::getJava()->GetMethodID(stringWriterClass, "", "()V"); printWriterID = JPEnv::getJava()->GetMethodID(printWriterClass, "", "(Ljava/io/Writer;)V"); flushID = JPEnv::getJava()->GetMethodID(printWriterClass, "flush", "()V"); numberClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Number")); booleanClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Boolean")); charClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Character")); intValueID = JPEnv::getJava()->GetMethodID(numberClass, "intValue", "()I"); longValueID = JPEnv::getJava()->GetMethodID(numberClass, "longValue", "()J"); doubleValueID = JPEnv::getJava()->GetMethodID(numberClass, "doubleValue", "()D"); booleanValueID = JPEnv::getJava()->GetMethodID(booleanClass, "booleanValue", "()Z"); charValueID = JPEnv::getJava()->GetMethodID(charClass, "charValue", "()C"); byteClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Byte")); shortClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Short")); intClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Integer")); floatClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Float")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(byteClass, "MIN_VALUE", "B"); s_minByte = JPEnv::getJava()->GetStaticByteField(byteClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(byteClass, "MAX_VALUE", "B"); s_maxByte = JPEnv::getJava()->GetStaticByteField(byteClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(shortClass, "MIN_VALUE", "S"); s_minShort = JPEnv::getJava()->GetStaticShortField(shortClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(shortClass, "MAX_VALUE", "S"); s_maxShort = JPEnv::getJava()->GetStaticShortField(shortClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(intClass, "MIN_VALUE", "I"); s_minInt = JPEnv::getJava()->GetStaticIntField(intClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(intClass, "MAX_VALUE", "I"); s_maxInt = JPEnv::getJava()->GetStaticIntField(intClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(floatClass, "MIN_VALUE", "F"); s_minFloat = JPEnv::getJava()->GetStaticFloatField(floatClass, fid); fid = JPEnv::getJava()->GetStaticFieldID(floatClass, "MAX_VALUE", "F"); s_maxFloat = JPEnv::getJava()->GetStaticFloatField(floatClass, fid); } string asciiFromJava(jstring str) { const char* cstr = NULL; jboolean isCopy; cstr = JPEnv::getJava()->GetStringUTFChars(str, &isCopy); int length = JPEnv::getJava()->GetStringLength(str); string res; for (int i = 0; i < length; i++) { res += (char)cstr[i]; } JPEnv::getJava()->ReleaseStringUTFChars(str, cstr); return res; } JCharString unicodeFromJava(jstring str) { const jchar* cstr = NULL; jboolean isCopy; cstr = JPEnv::getJava()->GetStringChars(str, &isCopy); JCharString res = cstr; JPEnv::getJava()->ReleaseStringChars(str, cstr); return res; } jstring javaStringFromJCharString(JCharString& wstr) { jstring result = JPEnv::getJava()->NewString(wstr.c_str(), (jint)wstr.length()); return result; } JPTypeName getClassName(jobject o) { if (o == NULL) { return JPTypeName::fromSimple("java.lang.Object"); } JPCleaner cleaner; jclass c = getClass(o); cleaner.addLocal(c); return getName(c); } jclass getClass(jobject o) { return (jclass)JPEnv::getJava()->CallObjectMethod(o, getClassID); } jstring toString(jobject o) { jstring str = (jstring)JPEnv::getJava()->CallObjectMethod(o, toStringID); return str; } static string convertToSimpleName(jclass c) { JPCleaner cleaner; jstring jname = (jstring)JPEnv::getJava()->CallObjectMethod(c, getNameID); cleaner.addLocal(jname); string name = asciiFromJava(jname); // Class.getName returns something weird for arrays ... if (name[0] == '[') { // perform a little cleanup of the name ... unsigned int arrayCount = 0; for (unsigned int i = 0; i < name.length(); i++) { if (name[i] == '[') { arrayCount++; } } name = name.substr(arrayCount, name.length()-(arrayCount)); // Now, let's convert the "native" part switch(name[0]) { case 'B' : name = "byte"; break; case 'S' : name = "short"; break; case 'I' : name = "int"; break; case 'J' : name = "long"; break; case 'F' : name = "float"; break; case 'D' : name = "double"; break; case 'C' : name = "char"; break; case 'Z' : name = "boolean"; break; case 'L' : name = name.substr(1, name.length()-2); for (unsigned int i = 0; i < name.length(); i++) { if (name[i] == '/') { name[i] = '.'; } } break; } for (unsigned int j = 0; j < arrayCount; j++) { name = name + "[]"; } } return name; } bool isInterface(jclass clazz) { jboolean b = JPEnv::getJava()->CallBooleanMethod(clazz, isInterfaceID); return (b ? true : false); } bool isAbstract(jclass clazz) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(clazz, getClassModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isAbstractID, &modif); return (res ? true : false); } long getClassModifiers(jclass clazz) { long res = JPEnv::getJava()->CallIntMethod(clazz, getClassModifiersID); return res; } bool isFinal(jclass clazz) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(clazz, getClassModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isFinalID, &modif); return (res ? true : false); } JPTypeName getName(jclass clazz) { string simpleName = convertToSimpleName(clazz); return JPTypeName::fromSimple(simpleName.c_str()); } vector getInterfaces(jclass clazz) { JPCleaner cleaner; jobjectArray interfaces = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getInterfacesID); cleaner.addLocal(interfaces); int len = JPEnv::getJava()->GetArrayLength(interfaces); vector res; for (int i = 0; i < len; i++) { jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(interfaces, i); res.push_back(c); } return res; } vector getDeclaredFields(jclass clazz) { JPCleaner cleaner; jobjectArray fields = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getDeclaredFieldsID); cleaner.addLocal(fields); int len = JPEnv::getJava()->GetArrayLength(fields); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(fields, i); res.push_back(c); } return res; } vector getFields(jclass clazz) { JPCleaner cleaner; jobjectArray fields = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getFieldsID); cleaner.addLocal(fields); int len = JPEnv::getJava()->GetArrayLength(fields); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(fields, i); res.push_back(c); } return res; } vector getDeclaredMethods(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getDeclaredMethodsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } vector getDeclaredConstructors(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getDeclaredConstructorsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } vector getConstructors(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getConstructorsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } vector getMethods(jclass clazz) { JPCleaner cleaner; jobjectArray methods = (jobjectArray)JPEnv::getJava()->CallObjectMethod(clazz, getMethodsID); cleaner.addLocal(methods); int len = JPEnv::getJava()->GetArrayLength(methods); vector res; for (int i = 0; i < len; i++) { jobject c = JPEnv::getJava()->GetObjectArrayElement(methods, i); res.push_back(c); } return res; } jobject getSystemClassLoader() { return JPEnv::getJava()->CallStaticObjectMethod(classLoaderClass, getSystemClassLoaderID) ; } string getMemberName(jobject o) { JPCleaner cleaner; jstring name = (jstring)JPEnv::getJava()->CallObjectMethod(o, getMemberNameID); cleaner.addLocal(name); string simpleName = asciiFromJava(name); return simpleName; } bool isMemberPublic(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isPublicID, &modif); return (res ? true : false); } bool isMemberStatic(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isStaticID, &modif); return (res ? true : false); } bool isMemberFinal(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isFinalID, &modif); return (res ? true : false); } bool isMemberAbstract(jobject o) { jvalue modif; modif.i = JPEnv::getJava()->CallIntMethod(o, getModifiersID); jboolean res = JPEnv::getJava()->CallStaticBooleanMethodA(modifierClass, isAbstractID, &modif); return (res ? true : false); } jint hashCode(jobject obj) { jint res = JPEnv::getJava()->CallIntMethod(obj, hashCodeID); return res; } JPTypeName getType(jobject fld) { TRACE_IN("getType"); JPCleaner cleaner; jclass c = (jclass)JPEnv::getJava()->CallObjectMethod(fld, getTypeID); cleaner.addLocal(c); return getName(c); TRACE_OUT; } JPTypeName getReturnType(jobject o) { JPCleaner cleaner; jclass c = (jclass)JPEnv::getJava()->CallObjectMethod(o, getReturnTypeID); cleaner.addLocal(c); return getName(c); } bool isMethodSynthetic(jobject o) { jboolean res = JPEnv::getJava()->CallBooleanMethod(o, isSyntheticMethodID); return (res ? true : false); } bool isVarArgsMethod(jobject o) { jboolean res = JPEnv::getJava()->CallBooleanMethod(o, isVarArgsMethodID); return (res ? true : false); } vector getParameterTypes(jobject o, bool isConstructor) { JPCleaner cleaner; vector args; jobjectArray types ; if (isConstructor) { types = (jobjectArray)JPEnv::getJava()->CallObjectMethod(o, getConstructorParameterTypesID); } else { types = (jobjectArray)JPEnv::getJava()->CallObjectMethod(o, getParameterTypesID); } cleaner.addLocal(types); int len = JPEnv::getJava()->GetArrayLength(types); for (int i = 0; i < len; i++) { jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(types, i); cleaner.addLocal(c); JPTypeName name = getName(c); args.push_back(name); } return args; } bool isConstructor(jobject obj) { jboolean r = JPEnv::getJava()->IsInstanceOf(obj, constructorClass); if (r) { return true; } return false; } string getStackTrace(jthrowable th) { JPCleaner cleaner; jobject strWriter = JPEnv::getJava()->NewObject(stringWriterClass, stringWriterID); cleaner.addLocal(strWriter); jvalue v; v.l = strWriter; jobject printWriter = JPEnv::getJava()->NewObjectA(printWriterClass, printWriterID, &v); cleaner.addLocal(printWriter); v.l = printWriter; JPEnv::getJava()->CallVoidMethodA(th, printStackTraceID, &v); JPEnv::getJava()->CallVoidMethod(printWriter, flushID); jstring res = toString(strWriter); cleaner.addLocal(res); return asciiFromJava(res); } string getMessage(jthrowable th) { JPCleaner cleaner; jstring jstr = (jstring)JPEnv::getJava()->CallObjectMethod(th, getMessageID); cleaner.addLocal(jstr); return asciiFromJava(jstr); } bool isThrowable(jclass c) { jboolean res = JPEnv::getJava()->IsAssignableFrom(c, throwableClass); if (res) { return true; } return false; } long intValue(jobject obj) { return JPEnv::getJava()->CallIntMethod(obj, intValueID); } jlong longValue(jobject obj) { return JPEnv::getJava()->CallLongMethod(obj, longValueID); } double doubleValue(jobject obj) { return JPEnv::getJava()->CallDoubleMethod(obj, doubleValueID); } bool booleanValue(jobject obj) { return JPEnv::getJava()->CallBooleanMethod(obj, booleanValueID) ? true : false; } jchar charValue(jobject obj) { return JPEnv::getJava()->CallCharMethod(obj, charValueID); } jclass getByteClass() { jclass byteClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Byte")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(byteClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(byteClass, fid); JPEnv::getJava()->DeleteGlobalRef(byteClass); return res; } jclass getShortClass() { jclass shortClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Short")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(shortClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(shortClass, fid); JPEnv::getJava()->DeleteGlobalRef(shortClass); return res; } jclass getIntegerClass() { jclass intClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Integer")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(intClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(intClass, fid); JPEnv::getJava()->DeleteGlobalRef(intClass); return res; } jclass getLongClass() { jclass longClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Long")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(longClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(longClass, fid); JPEnv::getJava()->DeleteGlobalRef(longClass); return res; } jclass getFloatClass() { jclass floatClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Float")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(floatClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(floatClass, fid); JPEnv::getJava()->DeleteGlobalRef(floatClass); return res; } jclass getDoubleClass() { jclass doubleClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Double")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(doubleClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(doubleClass, fid); JPEnv::getJava()->DeleteGlobalRef(doubleClass); return res; } jclass getCharacterClass() { jclass charClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Character")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(charClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(charClass, fid); JPEnv::getJava()->DeleteGlobalRef(charClass); return res; } jclass getBooleanClass() { jclass booleanClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Boolean")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(booleanClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(booleanClass, fid); JPEnv::getJava()->DeleteGlobalRef(booleanClass); return res; } jclass getVoidClass() { jclass voidClass= (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("java/lang/Void")); jfieldID fid = JPEnv::getJava()->GetStaticFieldID(voidClass, "TYPE", "Ljava/lang/Class;"); jclass res = (jclass)JPEnv::getJava()->GetStaticObjectField(voidClass, fid); JPEnv::getJava()->DeleteGlobalRef(voidClass); return res; } void startJPypeReferenceQueue(bool useJavaThread) { JPCleaner cleaner; JPypeReferenceQueueClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("jpype/ref/JPypeReferenceQueue")); JPypeReferenceQueueConstructorMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "", "()V"); JPypeReferenceQueueRegisterMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "registerRef", "(Ljpype/ref/JPypeReference;J)V"); JPypeReferenceQueueStartMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "startManaging", "()V"); JPypeReferenceQueueRunMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "run", "()V"); JPypeReferenceQueueStopMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceQueueClass, "stop", "()V"); JPypeReferenceClass = (jclass)JPEnv::getJava()->NewGlobalRef(JPEnv::getJava()->FindClass("jpype/ref/JPypeReference")); JPypeReferenceConstructorMethod = JPEnv::getJava()->GetMethodID(JPypeReferenceClass, "", "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V"); jobject obj = JPEnv::getJava()->NewObject(JPypeReferenceQueueClass, JPypeReferenceQueueConstructorMethod); cleaner.addLocal(obj); JPEnv::getJava()->setReferenceQueue(obj); if (useJavaThread) { JPEnv::getJava()->CallVoidMethod(obj, JPypeReferenceQueueStartMethod); } else { JPEnv::getJava()->CallVoidMethod(obj, JPypeReferenceQueueRunMethod); } } void stopJPypeReferenceQueue() { JPEnv::getJava()->CallVoidMethod(JPEnv::getJava()->getReferenceQueue(), JPypeReferenceQueueStopMethod); } void registerRef(jobject refQueue, jobject obj, jlong hostRef) { TRACE_IN("registerRef"); // create the ref ... jvalue args[2]; args[0].l = obj; args[1].l = refQueue; JPCleaner cleaner; jobject refObj = JPEnv::getJava()->NewObjectA(JPypeReferenceClass, JPypeReferenceConstructorMethod, args); cleaner.addLocal(refObj); args[0].l = refObj; args[1].j = hostRef; JPEnv::getJava()->CallVoidMethodA(refQueue, JPypeReferenceQueueRegisterMethod, args); TRACE_OUT; } } // end of namespace JNIEnv jpype-0.6.2+dfsg/native/common/jp_method.cpp0000664000175000017500000001720413036015411020312 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include #include #include #include JPMethod::JPMethod(jclass clazz, const string& name, bool isConstructor) : m_Name(name), m_IsConstructor(isConstructor) { m_Class = (jclass)JPEnv::getJava()->NewGlobalRef(clazz); } const string& JPMethod::getName() const { return m_Name; } string JPMethod::getClassName() const { JPTypeName name = JPJni::getClassName(m_Class); return name.getSimpleName(); } bool JPMethod::hasStatic() { for (map::iterator it = m_Overloads.begin(); it != m_Overloads.end(); it++) { if (it->second.isStatic()) { return true; } } return false; } void JPMethod::addOverload(JPClass* claz, jobject mth) { JPMethodOverload over(claz, mth); m_Overloads[over.getSignature()] = over; } void JPMethod::addOverloads(JPMethod* o) { TRACE_IN("JPMethod::addOverloads"); for (map::iterator it = o->m_Overloads.begin(); it != o->m_Overloads.end(); it++) { bool found = false; for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { if (cur->second.isSameOverload(it->second)) { found = true; break; } } if (! found) { // Add it only if we do not already overload it ... m_Overloads[it->first] = it->second; } } TRACE_OUT; } JPMethodOverload* JPMethod::findOverload(vector& arg, bool needStatic) { TRACE_IN("JPMethod::findOverload"); TRACE2("Checking overload", m_Name); TRACE2("Got overloads to check", m_Overloads.size()); ensureOverloadOrderCache(); JPMethodOverload* maximallySpecificOverload = 0; for (std::vector::iterator it = m_OverloadOrderCache.begin(); it != m_OverloadOrderCache.end(); ++it) { if ((! needStatic) || it->m_Overload->isStatic()) { TRACE2("Trying to match", it->m_Overload->getSignature()); EMatchType match = it->m_Overload->matches(false, arg); TRACE2(" match ended", match); if(match == _exact) { return it->m_Overload; } if (match >= _implicit) { if(!maximallySpecificOverload) { maximallySpecificOverload = it->m_Overload; } else { bool isAmbiguous = std::find(it->m_MoreSpecificOverloads.begin(), it->m_MoreSpecificOverloads.end(), maximallySpecificOverload) == it->m_MoreSpecificOverloads.end(); if(isAmbiguous) { TRACE3("ambiguous overload", maximallySpecificOverload->getSignature(), it->m_Overload->getSignature()); RAISE(JPypeException, "Ambiguous overloads found: " + maximallySpecificOverload->getSignature() + " vs " + it->m_Overload->getSignature()); } } } } } if (!maximallySpecificOverload) { RAISE(JPypeException, "No matching overloads found."); } return maximallySpecificOverload; TRACE_OUT; } void JPMethod::ensureOverloadOrderCache() { if(m_Overloads.size() == m_OverloadOrderCache.size()) { return; } m_OverloadOrderCache.clear(); std::vector overloads; for (std::map::iterator it = m_Overloads.begin(); it != m_Overloads.end(); ++it) { overloads.push_back(&it->second); } std::vector seen(overloads.size(), false); for (size_t i = 0; i < overloads.size(); ++i) { if (seen[i]) { continue; } std::stack st; st.push(i); while(!st.empty()) { size_t curr = st.top(); for (size_t j = 0; j < overloads.size(); ++j) { if (j != curr && !seen[j] && overloads[j]->isMoreSpecificThan(*overloads[curr])) { seen[j] = true; st.push(j); } } if (curr == st.top()) { st.pop(); m_OverloadOrderCache.push_back(OverloadData(overloads[curr])); } } } // std::cout << "overload order for " << m_Name << std::endl; // for (std::vector::iterator it = m_OverloadOrderCache.begin(); it != m_OverloadOrderCache.end(); ++it) { // std::cout << it->m_Overload->getSignature() << std::endl; // } for (std::vector::iterator it = m_OverloadOrderCache.begin(); it != m_OverloadOrderCache.end(); ++it) { for (std::vector::iterator jt = m_OverloadOrderCache.begin(); jt != m_OverloadOrderCache.end(); ++jt) { if (jt != it && jt->m_Overload->isMoreSpecificThan(*it->m_Overload)) { it->m_MoreSpecificOverloads.push_back(jt->m_Overload); } } } } HostRef* JPMethod::invoke(vector& args) { JPMethodOverload* currentMatch = findOverload(args, false); HostRef* res; if (currentMatch->isStatic()) { res = currentMatch->invokeStatic(args); } else { res = currentMatch->invokeInstance(args); } return res; } HostRef* JPMethod::invokeInstance(vector& args) { JPMethodOverload* currentMatch = findOverload(args, false); if (currentMatch->isStatic()) { RAISE(JPypeException, "No matching overloads found."); } else { return currentMatch->invokeInstance(args); } } HostRef* JPMethod::invokeStatic(vector& args) { JPMethodOverload* currentMatch = findOverload(args, true); return currentMatch->invokeStatic(args); } JPObject* JPMethod::invokeConstructor(vector& arg) { JPMethodOverload* currentMatch = findOverload(arg, false); return currentMatch->invokeConstructor(m_Class, arg); } string JPMethod::describe(string prefix) { string name = m_Name; if (name == "[init") { name = "__init__"; } stringstream str; for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { str << prefix << "public "; if (! m_IsConstructor) { if (cur->second.isStatic()) { str << "static "; } else if (cur->second.isFinal()) { str << "final "; } str << cur->second.getReturnType().getSimpleName() << " "; } str << name << cur->second.getArgumentString() << ";" << endl; } return str.str(); } bool JPMethod::isBeanMutator() { for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { if ( (! cur->second.isStatic()) && cur->second.getReturnType().getSimpleName() == "void" && cur->second.getArgumentCount() == 2) { return true; } } return false; } bool JPMethod::isBeanAccessor() { for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { if ( (! cur->second.isStatic()) && cur->second.getReturnType().getSimpleName() != "void" && cur->second.getArgumentCount() == 1) { return true; } } return false; } string JPMethod::matchReport(vector& args) { stringstream res; res << "Match report for method " << m_Name << ", has " << m_Overloads.size() << " overloads." << endl; for (map::iterator cur = m_Overloads.begin(); cur != m_Overloads.end(); cur++) { res << " " << cur->second.matchReport(args); } return res.str(); } jpype-0.6.2+dfsg/native/common/jp_methodoverload.cpp0000664000175000017500000002040213036015411022040 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPMethodOverload::JPMethodOverload() { m_Method = NULL; m_ReturnTypeCache = NULL; } JPMethodOverload::JPMethodOverload(const JPMethodOverload& o) : m_Class(o.m_Class), m_MethodID(o.m_MethodID), m_ReturnType(o.m_ReturnType), m_Arguments(o.m_Arguments), m_IsStatic(o.m_IsStatic), m_IsFinal(o.m_IsFinal), m_IsConstructor(o.m_IsConstructor) { m_Method = JPEnv::getJava()->NewGlobalRef(o.m_Method); m_ReturnTypeCache = NULL; } JPMethodOverload::JPMethodOverload(JPClass* claz, jobject mth) { m_Class = claz; m_Method = JPEnv::getJava()->NewGlobalRef(mth); m_ReturnTypeCache = NULL; // static m_IsStatic = JPJni::isMemberStatic(m_Method); m_IsFinal = JPJni::isMemberFinal(m_Method); // Method ID m_MethodID = JPEnv::getJava()->FromReflectedMethod(m_Method); m_IsConstructor = JPJni::isConstructor(m_Method); // return type if (! m_IsConstructor) { m_ReturnType = JPJni::getReturnType(m_Method); } // arguments m_Arguments = JPJni::getParameterTypes(mth, m_IsConstructor); // Add the implicit "this" argument if (! m_IsStatic && ! m_IsConstructor) { m_Arguments.insert(m_Arguments.begin(), 1, claz->getName()); } } JPMethodOverload::~JPMethodOverload() { JPEnv::getJava()->DeleteGlobalRef(m_Method); } string JPMethodOverload::getSignature() { stringstream res; res << "("; for (vector::iterator it = m_Arguments.begin(); it != m_Arguments.end(); it++) { res << it->getNativeName(); } res << ")" ; return res.str(); } string JPMethodOverload::getArgumentString() { stringstream res; res << "("; bool first = true; for (vector::iterator it = m_Arguments.begin(); it != m_Arguments.end(); it++) { if (! first) { res << ", "; } else { first = false; } res << it->getSimpleName(); } res << ")"; return res.str(); } bool JPMethodOverload::isSameOverload(JPMethodOverload& o) { if (isStatic() != o.isStatic()) { return false; } if (m_Arguments.size() != o.m_Arguments.size()) { return false; } TRACE_IN("JPMethodOverload::isSameOverload"); TRACE2("My sig", getSignature()); TRACE2("It's sig", o.getSignature()); int start = 0; if (! isStatic()) { start = 1; } for (unsigned int i = start; i < m_Arguments.size() && i < o.m_Arguments.size(); i++) { JPTypeName& mine = m_Arguments[i]; JPTypeName& his = o.m_Arguments[i]; const string& mineSimple = mine.getSimpleName(); const string& hisSimple = his.getSimpleName(); if (mineSimple != hisSimple) { return false; } } return true; TRACE_OUT; } EMatchType JPMethodOverload::matches(bool ignoreFirst, vector& arg) { TRACE_IN("JPMethodOverload::matches"); ensureTypeCache(); size_t len = arg.size(); if (len != m_Arguments.size()) { return _none; } EMatchType lastMatch = _exact; for (unsigned int i = 0; i < len; i++) { if (i == 0 && ignoreFirst) { continue; } HostRef* obj = arg[i]; JPType* type = m_ArgumentsTypeCache[i]; EMatchType match = type->canConvertToJava(obj); if (match < _implicit) { return _none; } if (match < lastMatch) { lastMatch = match; } } return lastMatch; TRACE_OUT; } HostRef* JPMethodOverload::invokeStatic(vector& arg) { TRACE_IN("JPMethodOverload::invokeStatic"); ensureTypeCache(); JPCleaner cleaner; size_t len = arg.size(); JPMallocCleaner v(len); JPMallocCleaner types(len); for (unsigned int i = 0; i < len; i++) { HostRef* obj = arg[i]; types[i] = m_ArgumentsTypeCache[i]; v[i] = types[i]->convertToJava(obj); if (types[i]->isObjectType()) { cleaner.addLocal(v[i].l); } } jclass claz = m_Class->getClass(); cleaner.addLocal(claz); JPType* retType = m_ReturnTypeCache; return retType->invokeStatic(claz, m_MethodID, v.borrow()); TRACE_OUT; } HostRef* JPMethodOverload::invokeInstance(vector& args) { TRACE_IN("JPMethodOverload::invokeInstance"); ensureTypeCache(); HostRef* res; { JPCleaner cleaner; // Arg 0 is "this" HostRef* self = args[0]; JPObject* selfObj = JPEnv::getHost()->asObject(self); size_t len = args.size(); JPMallocCleaner v(len-1); for (unsigned int i = 1; i < len; i++) { HostRef* obj = args[i]; JPType* type = m_ArgumentsTypeCache[i]; v[i-1] = type->convertToJava(obj); if (type->isObjectType()) { cleaner.addLocal(v[i-1].l); } } JPType* retType = m_ReturnTypeCache; jobject c = selfObj->getObject(); cleaner.addLocal(c); jclass clazz = m_Class->getClass(); cleaner.addLocal(clazz); res = retType->invoke(c, clazz, m_MethodID, v.borrow()); TRACE1("Call finished"); } TRACE1("Call successfull"); return res; TRACE_OUT; } JPObject* JPMethodOverload::invokeConstructor(jclass claz, vector& arg) { TRACE_IN("JPMethodOverload::invokeConstructor"); ensureTypeCache(); size_t len = arg.size(); JPCleaner cleaner; JPMallocCleaner v(len); for (unsigned int i = 0; i < len; i++) { HostRef* obj = arg[i]; JPType* t = m_ArgumentsTypeCache[i]; v[i] = t->convertToJava(obj); if (t->isObjectType()) { cleaner.addLocal(v[i].l); } } jvalue val; val.l = JPEnv::getJava()->NewObjectA(claz, m_MethodID, v.borrow()); cleaner.addLocal(val.l); TRACE1("Object created"); JPTypeName name = JPJni::getName(claz); return new JPObject(name, val.l); TRACE_OUT; } string JPMethodOverload::matchReport(vector& args) { stringstream res; res << m_ReturnType.getNativeName() << " ("; bool isFirst = true; for (vector::iterator it = m_Arguments.begin(); it != m_Arguments.end(); it++) { if (isFirst && ! isStatic()) { isFirst = false; continue; } isFirst = false; res << it->getNativeName(); } res << ") ==> "; EMatchType match = matches(! isStatic(), args); switch(match) { case _none : res << "NONE"; break; case _explicit : res << "EXPLICIT"; break; case _implicit : res << "IMPLICIT"; break; case _exact : res << "EXACT"; break; default : res << "UNKNOWN"; break; } res << endl; return res.str(); } bool JPMethodOverload::isMoreSpecificThan(JPMethodOverload& other) const { ensureTypeCache(); other.ensureTypeCache(); // see http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.5 // fixed-arity methods size_t startThis = isStatic() || m_IsConstructor ? 0 : 1; size_t startOther = other.isStatic() || m_IsConstructor ? 0 : 1; size_t numParametersThis = m_Arguments.size() - startThis; size_t numParametersOther = other.m_Arguments.size() - startOther; if(numParametersOther != numParametersThis) { return false; } for (size_t i = 0; i < numParametersThis; ++i) { const JPType* thisArgType = m_ArgumentsTypeCache[startThis + i]; const JPType* otherArgType = other.m_ArgumentsTypeCache[startOther + i]; if (!thisArgType->isSubTypeOf(*otherArgType)) { return false; } } return true; } void JPMethodOverload::ensureTypeCache() const { if (m_Arguments.size() == m_ArgumentsTypeCache.size() && m_ReturnTypeCache) { return; } for (size_t i = 0; i < m_Arguments.size(); ++i) { m_ArgumentsTypeCache.push_back(JPTypeManager::getType(m_Arguments[i])); } if (!m_IsConstructor) { m_ReturnTypeCache = JPTypeManager::getType(m_ReturnType); } } jpype-0.6.2+dfsg/native/common/jp_monitor.cpp0000664000175000017500000000201313036015411020511 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPMonitor::JPMonitor(jobject o) { JPEnv::getJava()->MonitorEnter(o); m_Object = JPEnv::getJava()->NewGlobalRef(o); } JPMonitor::~JPMonitor() { JPEnv::getJava()->MonitorExit(m_Object); JPEnv::getJava()->DeleteGlobalRef(m_Object); } jpype-0.6.2+dfsg/native/common/jp_object.cpp0000664000175000017500000000477313036015411020307 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JPObject::JPObject(JPTypeName& c, jobject o) { m_Class = JPTypeManager::findClass(c); m_Object = JPEnv::getJava()->NewGlobalRef(o); } JPObject::JPObject(JPClass* c, jobject o) { m_Class = c; m_Object = JPEnv::getJava()->NewGlobalRef(o); } JPObject::~JPObject() { JPEnv::getJava()->DeleteGlobalRef(m_Object); } JCharString JPObject::toString() { if (m_Object == NULL) { static const char* value = "null"; jchar res[5]; res[4] = 0; for (int i = 0; value[i] != 0; i++) { res[i] = value[i]; } return res; } JPCleaner cleaner; jstring jval = JPJni::toString(m_Object); cleaner.addLocal(jval); JCharString result = JPJni::unicodeFromJava(jval); return result; } HostRef* JPObject::getAttribute(const string& name) { TRACE_IN("JPObject::getAttribute"); TRACE1(name); JPCleaner cleaner; // instance fields ... JPField* fld = m_Class->getInstanceField(name); if (fld != NULL) { return fld->getAttribute(m_Object); } // static fields ... fld = m_Class->getStaticField(name); if (fld != NULL) { return fld->getStaticAttribute(); } JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("getAttribute"); return NULL; // never reached ... TRACE_OUT; } void JPObject::setAttribute(const string& name, HostRef* val) { // instance fields ... JPField* fld = m_Class->getInstanceField(name); if (fld != NULL) { fld->setAttribute(m_Object, val); return; } // static fields ... fld = m_Class->getStaticField(name); if (fld != NULL) { fld->setStaticAttribute(val); return; } JPEnv::getHost()->setAttributeError(name.c_str()); JPEnv::getHost()->raise("setAttribute"); } jpype-0.6.2+dfsg/native/common/jp_objecttypes.cpp0000664000175000017500000002314013036015411021361 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include HostRef* JPObjectType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { TRACE_IN("JPObjectType::getStaticValue"); JPCleaner cleaner; jobject r = JPEnv::getJava()->GetStaticObjectField(c, fid); cleaner.addLocal(r); jvalue v; v.l = r; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); TRACE_OUT; } HostRef* JPObjectType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { TRACE_IN("JPObjectType::getInstanceValue"); JPCleaner cleaner; jobject r = JPEnv::getJava()->GetObjectField(c, fid); cleaner.addLocal(r); jvalue v; v.l = r; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); TRACE_OUT; } HostRef* JPObjectType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { TRACE_IN("JPObjectType::invokeStatic"); JPCleaner cleaner; jobject res = JPEnv::getJava()->CallStaticObjectMethodA(claz, mth, val); cleaner.addLocal(res); jvalue v; v.l = res; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); TRACE_OUT; } HostRef* JPObjectType::invoke(jobject claz, jclass clazz, jmethodID mth, jvalue* val) { TRACE_IN("JPObjectType::invoke"); JPCleaner cleaner; jobject res = JPEnv::getJava()->CallNonvirtualObjectMethodA(claz, clazz, mth, val); cleaner.addLocal(res); jvalue v; v.l = res; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); HostRef* ref = type->asHostObject(v); TRACE1("Successfully converted to host reference"); return ref; TRACE_OUT; } void JPObjectType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { TRACE_IN("JPObjectType::setStaticValue"); JPCleaner cleaner; jobject val = convertToJava(obj).l; cleaner.addLocal(val); JPEnv::getJava()->SetStaticObjectField(c, fid, val); TRACE_OUT; } void JPObjectType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { TRACE_IN("JPObjectType::setInstanceValue"); JPCleaner cleaner; jobject val = convertToJava(obj).l; cleaner.addLocal(val); JPEnv::getJava()->SetObjectField(c, fid, val); TRACE_OUT; } jarray JPObjectType::newArrayInstance(int sz) { JPCleaner cleaner; jclass c = getClass(); cleaner.addLocal(c); return JPEnv::getJava()->NewObjectArray(sz, c, NULL); } vector JPObjectType::getArrayRange(jarray a, int start, int length) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; vector res; jvalue v; for (int i = 0; i < length; i++) { v.l = JPEnv::getJava()->GetObjectArrayElement(array, i+start); cleaner.addLocal(v.l); JPTypeName name = JPJni::getClassName(v.l); JPType* t = JPTypeManager::getType(name); HostRef* pv = t->asHostObject(v); res.push_back(pv); } return res; } void JPObjectType::setArrayRange(jarray a, int start, int length, vector& vals) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; jvalue v; for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; v = convertToJava(pv); cleaner.addLocal(v.l); JPEnv::getJava()->SetObjectArrayElement(array, i+start, v.l); } } void JPObjectType::setArrayItem(jarray a, int ndx, HostRef* val) { jobjectArray array = (jobjectArray)a; JPCleaner cleaner; jvalue v = convertToJava(val); cleaner.addLocal(v.l); JPEnv::getJava()->SetObjectArrayElement(array, ndx, v.l); } HostRef* JPObjectType::getArrayItem(jarray a, int ndx) { TRACE_IN("JPObjectType::getArrayItem"); jobjectArray array = (jobjectArray)a; JPCleaner cleaner; jobject obj = JPEnv::getJava()->GetObjectArrayElement(array, ndx); cleaner.addLocal(obj); if (obj == NULL) { return JPEnv::getHost()->getNone(); } jvalue v; v.l = obj; JPTypeName name = JPJni::getClassName(v.l); JPType* t = JPTypeManager::getType(name); return t->asHostObject(v); TRACE_OUT; } jobject JPObjectType::convertToJavaObject(HostRef* obj) { jvalue v = convertToJava(obj); return v.l; } HostRef* JPObjectType::asHostObjectFromObject(jvalue val) { return asHostObject(val); } HostRef* JPObjectType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } bool JPObjectType::isSubTypeOf(const JPType& other) const { const JPObjectType* otherObjectType = dynamic_cast(&other); if (!otherObjectType) { return false; } JPCleaner cleaner; jclass ourClass = getClass(); cleaner.addLocal(ourClass); jclass otherClass = otherObjectType->getClass(); cleaner.addLocal(otherClass); // IsAssignableFrom is a jni method and the order of parameters is counterintuitive bool otherIsSuperType = JPEnv::getJava()->IsAssignableFrom(ourClass, otherClass); //std::cout << other.getName().getSimpleName() << " isSuperType of " << getName().getSimpleName() << " " << otherIsSuperType << std::endl; return otherIsSuperType; } //------------------------------------------------------------------------------- HostRef* JPStringType::asHostObject(jvalue val) { TRACE_IN("JPStringType::asHostObject"); if (val.l == NULL) { return JPEnv::getHost()->getNone(); } jstring v = (jstring)val.l; if (JPEnv::getJava()->getConvertStringObjects()) { TRACE1(" Performing conversion"); jsize len = JPEnv::getJava()->GetStringLength(v); jboolean isCopy; const jchar* str = JPEnv::getJava()->GetStringChars(v, &isCopy); HostRef* res = JPEnv::getHost()->newStringFromUnicode(str, len); JPEnv::getJava()->ReleaseStringChars(v, str); return res; } else { TRACE1(" Performing wrapping"); HostRef* res = JPEnv::getHost()->newStringWrapper(v); TRACE1(" Wrapping successfull"); return res; } TRACE_OUT; } EMatchType JPStringType::canConvertToJava(HostRef* obj) { TRACE_IN("JPStringType::canConvertToJava"); JPCleaner cleaner; if (obj == NULL || JPEnv::getHost()->isNone(obj)) { return _implicit; } if (JPEnv::getHost()->isString(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_string) { return _exact; } } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { return _exact; } } return _none; TRACE_OUT; } jvalue JPStringType::convertToJava(HostRef* obj) { TRACE_IN("JPStringType::convertToJava"); JPCleaner cleaner; jvalue v; if (JPEnv::getHost()->isNone(obj)) { v.l = NULL; return v; } if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } if (JPEnv::getHost()->isObject(obj)) { JPObject* o = JPEnv::getHost()->asObject(obj); JPClass* oc = o->getClass(); if (oc->getName().getSimpleName() == "java.lang.String") { v.l = o->getObject(); return v; } } JCharString wstr = JPEnv::getHost()->stringAsJCharString(obj); jchar* jstr = new jchar[wstr.length()+1]; jstr[wstr.length()] = 0; for (size_t i = 0; i < wstr.length(); i++) { jstr[i] = (jchar)wstr[i]; } jstring res = JPEnv::getJava()->NewString(jstr, (jint)wstr.length()); delete[] jstr; v.l = res; return v; TRACE_OUT; } jclass JPStringType::getClass() const { return (jclass)JPEnv::getJava()->NewGlobalRef(JPJni::s_StringClass); } //------------------------------------------------------------------------------- HostRef* JPClassType::asHostObject(jvalue val) { jclass lclass = (jclass)val.l; JPTypeName name = JPJni::getName(lclass); JPClass* res = JPTypeManager::findClass(name); return JPEnv::getHost()->newClass(res); } EMatchType JPClassType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _implicit; } if (JPEnv::getHost()->isClass(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_class) { return _exact; } } return _none; } jvalue JPClassType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue v; if (JPEnv::getHost()->isNone(obj)) { v.l = NULL; return v; } else if (JPEnv::getHost()->isWrapper(obj)) { v = JPEnv::getHost()->getWrapperValue(obj); } else { JPClass* w = JPEnv::getHost()->asClass(obj); jclass lr = w->getClass(); v.l = lr; } return v; } jclass JPClassType::getClass() const { return (jclass)JPEnv::getJava()->NewGlobalRef(JPJni::s_ClassClass); } jpype-0.6.2+dfsg/native/common/jp_platform_linux.cpp0000664000175000017500000000156713036015411022102 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifdef JPYPE_LINUX void longToHexString(long value, char* outStr) { sprintf(outStr, "%lx", value); } #endif jpype-0.6.2+dfsg/native/common/jp_platform_win32.cpp0000664000175000017500000000155713036015411021704 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifdef JPYPE_WIN32 void longToHexString(long value, char* outStr) { ltoa(value, outStr, 16); } #endif jpype-0.6.2+dfsg/native/common/jp_primitivetypes.cpp0000664000175000017500000003255413036015411022134 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include jobject JPPrimitiveType::convertToJavaObject(HostRef* obj) { JPCleaner cleaner; JPTypeName tname = getObjectType(); JPClass* c = JPTypeManager::findClass(tname); jclass jc = c->getClass(); cleaner.addLocal(jc); vector args(1); args[0] = obj; JPObject* o = c->newInstance(args); jobject res = o->getObject(); delete o; return res; } HostRef* JPByteType::asHostObject(jvalue val) { return JPEnv::getHost()->newInt(val.b); } HostRef* JPByteType::asHostObjectFromObject(jvalue val) { long v = JPJni::intValue(val.l); return JPEnv::getHost()->newInt(v); } EMatchType JPByteType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_byte) { return _exact; } } return _none; } jvalue JPByteType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isInt(obj)) { jint l = JPEnv::getHost()->intAsInt(obj);; if (l < JPJni::s_minByte || l > JPJni::s_maxByte) { JPEnv::getHost()->setTypeError("Cannot convert value to Java byte"); JPEnv::getHost()->raise("JPByteType::convertToJava"); } res.b = (jbyte)l; } else if (JPEnv::getHost()->isLong(obj)) { jlong l = JPEnv::getHost()->longAsLong(obj); if (l < JPJni::s_minByte || l > JPJni::s_maxByte) { JPEnv::getHost()->setTypeError("Cannot convert value to Java byte"); JPEnv::getHost()->raise("JPByteType::convertToJava"); } res.b = (jbyte)l; } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPByteType::convertToDirectBuffer(HostRef* src) { TRACE_IN("JPByteType::convertToDirectBuffer"); JPCleaner cleaner; if (JPEnv::getHost()->isByteBuffer(src)) { char* rawData; long size; JPEnv::getHost()->getByteBufferPtr(src, &rawData, size); jobject obj = JPEnv::getJava()->NewDirectByteBuffer(rawData, size); cleaner.addLocal(obj); jvalue v; v.l = obj; JPTypeName name = JPJni::getClassName(v.l); JPType* type = JPTypeManager::getType(name); return type->asHostObject(v); } RAISE(JPypeException, "Unable to convert to Direct Buffer"); TRACE_OUT; } //---------------------------------------------------------------------------- HostRef* JPShortType::asHostObject(jvalue val) { return JPEnv::getHost()->newInt(val.s); } HostRef* JPShortType::asHostObjectFromObject(jvalue val) { long v = JPJni::intValue(val.l); return JPEnv::getHost()->newInt(v); } EMatchType JPShortType::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_short) { return _exact; } } return _none; } jvalue JPShortType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isInt(obj)) { jint l = JPEnv::getHost()->intAsInt(obj);; if (l < JPJni::s_minShort || l > JPJni::s_maxShort) { JPEnv::getHost()->setTypeError("Cannot convert value to Java short"); JPEnv::getHost()->raise("JPShortType::convertToJava"); } res.s = (jshort)l; } else if (JPEnv::getHost()->isLong(obj)) { jlong l = JPEnv::getHost()->longAsLong(obj);; if (l < JPJni::s_minShort || l > JPJni::s_maxShort) { JPEnv::getHost()->setTypeError("Cannot convert value to Java short"); JPEnv::getHost()->raise("JPShortType::convertToJava"); } res.s = (jshort)l; } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPShortType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //------------------------------------------------------------------------------- HostRef* JPIntType::asHostObject(jvalue val) { return JPEnv::getHost()->newInt(val.i); } HostRef* JPIntType::asHostObjectFromObject(jvalue val) { long v = JPJni::intValue(val.l); return JPEnv::getHost()->newInt(v); } EMatchType JPIntType::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _exact; } if (JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_int) { return _exact; } } return _none; } jvalue JPIntType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isInt(obj)) { jint l = JPEnv::getHost()->intAsInt(obj);; if (l < JPJni::s_minInt || l > JPJni::s_maxInt) { JPEnv::getHost()->setTypeError("Cannot convert value to Java int"); JPEnv::getHost()->raise("JPIntType::convertToJava"); } res.i = (jint)l; } else if (JPEnv::getHost()->isLong(obj)) { jlong l = JPEnv::getHost()->longAsLong(obj);; if (l < JPJni::s_minInt || l > JPJni::s_maxInt) { JPEnv::getHost()->setTypeError("Cannot convert value to Java int"); JPEnv::getHost()->raise("JPIntType::convertToJava"); } res.i = (jint)l; } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } return res; } HostRef* JPIntType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //------------------------------------------------------------------------------- HostRef* JPLongType::asHostObject(jvalue val) { TRACE_IN("JPLongType::asHostObject"); return JPEnv::getHost()->newLong(val.j); TRACE_OUT; } HostRef* JPLongType::asHostObjectFromObject(jvalue val) { jlong v = JPJni::longValue(val.l); return JPEnv::getHost()->newLong(v); } EMatchType JPLongType::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isInt(obj)) { return _implicit; } if (JPEnv::getHost()->isLong(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_long) { return _exact; } } return _none; } jvalue JPLongType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isInt(obj)) { res.j = (jlong)JPEnv::getHost()->intAsInt(obj); } else if (JPEnv::getHost()->isLong(obj)) { res.j = (jlong)JPEnv::getHost()->longAsLong(obj); } else if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { JPEnv::getHost()->setTypeError("Cannot convert value to Java long"); JPEnv::getHost()->raise("JPLongType::convertToJava"); res.j = 0; // never reached } return res; } HostRef* JPLongType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //------------------------------------------------------------------------------- HostRef* JPFloatType::asHostObject(jvalue val) { return JPEnv::getHost()->newFloat(val.f); } HostRef* JPFloatType::asHostObjectFromObject(jvalue val) { double v = JPJni::doubleValue(val.l); return JPEnv::getHost()->newFloat(v); } EMatchType JPFloatType::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isFloat(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_float) { return _exact; } } return _none; } jvalue JPFloatType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { double l = JPEnv::getHost()->floatAsDouble(obj); if (l > 0 && (l < JPJni::s_minFloat || l > JPJni::s_maxFloat)) { JPEnv::getHost()->setTypeError("Cannot convert value to Java float"); JPEnv::getHost()->raise("JPFloatType::convertToJava"); } else if (l < 0 && (l > -JPJni::s_minFloat || l < -JPJni::s_maxFloat)) { JPEnv::getHost()->setTypeError("Cannot convert value to Java float"); JPEnv::getHost()->raise("JPFloatType::convertToJava"); } res.f = (jfloat)l; } return res; } HostRef* JPFloatType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //--------------------------------------------------------------------------- HostRef* JPDoubleType::asHostObject(jvalue val) { HostRef* res = JPEnv::getHost()->newFloat(val.d); return res; } HostRef* JPDoubleType::asHostObjectFromObject(jvalue val) { double v = JPJni::doubleValue(val.l); return JPEnv::getHost()->newFloat(v); } EMatchType JPDoubleType::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isFloat(obj)) { return _exact; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_double) { return _exact; } } return _none; } jvalue JPDoubleType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { res.d = (jdouble)JPEnv::getHost()->floatAsDouble(obj); } return res; } HostRef* JPDoubleType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //---------------------------------------------------------------- HostRef* JPCharType::asHostObject(jvalue val) { jchar str[2]; str[0] = val.c; str[1] = 0; return JPEnv::getHost()->newStringFromUnicode(str, 1); } HostRef* JPCharType::asHostObjectFromObject(jvalue val) { jchar str[2]; str[0] = JPJni::charValue(val.l); str[1] = 0; return JPEnv::getHost()->newStringFromUnicode(str, 1); } EMatchType JPCharType::canConvertToJava(HostRef* obj) { JPCleaner cleaner; if (JPEnv::getHost()->isNone(obj)) { return _none; } if (JPEnv::getHost()->isString(obj) && JPEnv::getHost()->getStringLength(obj) == 1) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_char) { return _exact; } } return _none; } jvalue JPCharType::convertToJava(HostRef* obj) { JPCleaner cleaner; jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else { JCharString str = JPEnv::getHost()->stringAsJCharString(obj); res.c = str[0]; } return res; } HostRef* JPCharType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } //---------------------------------------------------------------------------------------- HostRef* JPBooleanType::asHostObject(jvalue val) { if (val.z) { return JPEnv::getHost()->getTrue(); } return JPEnv::getHost()->getFalse(); } HostRef* JPBooleanType::asHostObjectFromObject(jvalue val) { bool z = JPJni::booleanValue(val.l); if (z) { return JPEnv::getHost()->getTrue(); } return JPEnv::getHost()->getFalse(); } EMatchType JPBooleanType::canConvertToJava(HostRef* obj) { if (JPEnv::getHost()->isInt(obj) || JPEnv::getHost()->isLong(obj)) { return _implicit; } if (JPEnv::getHost()->isWrapper(obj)) { JPTypeName name = JPEnv::getHost()->getWrapperTypeName(obj); if (name.getType() == JPTypeName::_boolean) { return _exact; } } return _none; } jvalue JPBooleanType::convertToJava(HostRef* obj) { jvalue res; if (JPEnv::getHost()->isWrapper(obj)) { return JPEnv::getHost()->getWrapperValue(obj); } else if (JPEnv::getHost()->isLong(obj)) { res.z = (jboolean)JPEnv::getHost()->longAsLong(obj); } else { res.z = (jboolean)JPEnv::getHost()->intAsInt(obj); } return res; } HostRef* JPBooleanType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } jpype-0.6.2+dfsg/native/common/jp_primitivetypes_autogen.cpp0000664000175000017500000011652613036015411023660 0ustar takakitakaki /***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ // This code has been automatically generated ... No not edit // but has been edited already a lot, maybe we should change the name of this unit? #include #include typedef unsigned int uint; #ifdef HAVE_NUMPY #define PY_ARRAY_UNIQUE_SYMBOL jpype_ARRAY_API #define NO_IMPORT_ARRAY #include #else #define NPY_BOOL 0 #define NPY_BYTE 0 #define NPY_SHORT 0 #define NPY_INT 0 #define NPY_LONG 0 #define NPY_FLOAT32 0 #define NPY_FLOAT64 0 #endif #define CONVERSION_ERROR_HANDLE \ PyObject* exe = PyErr_Occurred(); \ if(exe != NULL) \ {\ stringstream ss;\ ss << "unable to convert element: " << PyUnicode_FromFormat("%R",o) <<\ " at index: " << i;\ RAISE(JPypeException, ss.str());\ } #if (PY_VERSION_HEX >= 0x02070000) // for python 2.6 we have also memory view available, but it does not contain the needed functions. #include template inline bool setViaBuffer(jarray array, int start, uint length, PyObject* sequence, setFnc setter) { //creates a PyMemoryView from sequence check for typeError, // if no underlying py_buff exists. if(! PyObject_CheckBuffer(sequence)) { return false; } // ensure memory is contiguous and 'C' ordered, this may involve a copy. PyObject* memview = PyMemoryView_GetContiguous(sequence, PyBUF_READ, 'C'); // this function is defined in jpype_memory_view, but unusable?! // PyObject* memview = PyMemoryView_FromObject(sequence); // check for TypeError, if no underlying py_buff exists. PyObject* err = PyErr_Occurred(); if (err) { PyErr_Clear(); return false; } // create a memory view Py_buffer* py_buff = PyMemoryView_GET_BUFFER(memview); // ensure length of buffer contains enough elements somehow. if ((py_buff->len / sizeof(jelementtype)) != length) { std::stringstream ss; ss << "Underlying buffer does not contain requested number of elements! Has " << py_buff->len << ", but " << length <<" are requested. Element size is " << sizeof(jelementtype); RAISE(JPypeException, ss.str()); } jarraytype a = (jarraytype)array; jelementtype* buffer = (jelementtype*) py_buff->buf; JPJavaEnv* env = JPEnv::getJava(); try { (env->*setter)(a, start, length, buffer); } RETHROW_CATCH( /*cleanup*/ Py_DECREF(py_buff); Py_DECREF(memview); ); // deallocate py_buff and memview Py_DECREF(py_buff); Py_DECREF(memview); return true; } #else template bool setViaBuffer(jarray, int, uint, PyObject*, c) { return false; } #endif /** * gets either a numpy ndarray or a python list with a copy of the underling java array, * containing the range [lo, hi]. * * Parameters: * ----------- * lo = low index * hi = high index * npy_type = e.g NPY_FLOAT64 * jtype = eg. jdouble * convert = function to convert elements to python types. Eg: PyInt_FromLong */ template inline PyObject* getSlice(jarray array, int lo, int hi, int npy_type, py_wrapper_func convert) { jtype* val = NULL; jboolean isCopy; PyObject* res = NULL; uint len = hi - lo; try { #ifdef HAVE_NUMPY npy_intp dims[] = {len}; res = PyArray_SimpleNew(1, dims, npy_type); #else res = PyList_New(len); #endif if (len > 0) { val = (jtype*) JPEnv::getJava()->GetPrimitiveArrayCritical(array, &isCopy); #ifdef HAVE_NUMPY // use typed numpy arrays for results memcpy(((PyArrayObject*) res)->data, &val[lo], len * sizeof(jtype)); #else // use python lists for results for (Py_ssize_t i = lo; i < hi; i++) PyList_SET_ITEM(res, i - lo, convert(val[i])); #endif // unpin array JPEnv::getJava()->ReleasePrimitiveArrayCritical(array, val, JNI_ABORT); } return res; } RETHROW_CATCH(if (val != NULL) { JPEnv::getJava()->ReleasePrimitiveArrayCritical(array, val, JNI_ABORT); }); } jarray JPByteType::newArrayInstance(int sz) { return JPEnv::getJava()->NewByteArray(sz); } HostRef* JPByteType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.b = JPEnv::getJava()->GetStaticByteField(c, fid); return asHostObject(v); } HostRef* JPByteType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.b = JPEnv::getJava()->GetByteField(c, fid); return asHostObject(v); } HostRef* JPByteType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.b = JPEnv::getJava()->CallStaticByteMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPByteType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.b = JPEnv::getJava()->CallNonvirtualByteMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPByteType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jbyte val = convertToJava(obj).b; JPEnv::getJava()->SetStaticByteField(c, fid, val); } void JPByteType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jbyte val = convertToJava(obj).b; JPEnv::getJava()->SetByteField(c, fid, val); } vector JPByteType::getArrayRange(jarray a, int start, int length) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.b = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } void JPByteType::setArrayRange(jarray a, int start, int length, vector& vals) { jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).b; } JPEnv::getJava()->ReleaseByteArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } void JPByteType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetByteArrayRegion)) return; jbyteArray array = (jbyteArray)a; jbyte* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetByteArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); jbyte l = (jbyte) PyInt_AS_LONG(o); Py_DECREF(o); if(l == -1) { CONVERSION_ERROR_HANDLE; } val[start+i] = l; } JPEnv::getJava()->ReleaseByteArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseByteArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPByteType::getArrayItem(jarray a, int ndx) { jbyteArray array = (jbyteArray)a; jbyte val; try { jvalue v; JPEnv::getJava()->GetByteArrayRegion(array, ndx, 1, &val); v.b = val; return asHostObject(v); } RETHROW_CATCH(); } void JPByteType::setArrayItem(jarray a, int ndx, HostRef* obj) { jbyteArray array = (jbyteArray)a; try { jbyte val = convertToJava(obj).b; JPEnv::getJava()->SetByteArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPByteType::getArrayRangeToSequence(jarray a, int lo, int hi) { return getSlice(a, lo, hi, NPY_BYTE, PyInt_FromLong); } //---------------------------------------------------------- jarray JPShortType::newArrayInstance(int sz) { return JPEnv::getJava()->NewShortArray(sz); } HostRef* JPShortType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.s = JPEnv::getJava()->GetStaticShortField(c, fid); return asHostObject(v); } HostRef* JPShortType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.s = JPEnv::getJava()->GetShortField(c, fid); return asHostObject(v); } HostRef* JPShortType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.s = JPEnv::getJava()->CallStaticShortMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPShortType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.s = JPEnv::getJava()->CallNonvirtualShortMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPShortType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jshort val = convertToJava(obj).s; JPEnv::getJava()->SetStaticShortField(c, fid, val); } void JPShortType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jshort val = convertToJava(obj).s; JPEnv::getJava()->SetShortField(c, fid, val); } vector JPShortType::getArrayRange(jarray a, int start, int length) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.s = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } void JPShortType::setArrayRange(jarray a, int start, int length, vector& vals) { jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).s; } JPEnv::getJava()->ReleaseShortArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } void JPShortType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetShortArrayRegion)) return; jshortArray array = (jshortArray)a; jshort* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetShortArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); jshort l = (jshort) PyInt_AsLong(o); Py_DECREF(o); if(l == -1) { CONVERSION_ERROR_HANDLE; } val[start+i] = l; } JPEnv::getJava()->ReleaseShortArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseShortArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPShortType::getArrayItem(jarray a, int ndx) { jshortArray array = (jshortArray)a; jshort val; try { JPEnv::getJava()->GetShortArrayRegion(array, ndx, 1, &val); jvalue v; v.s = val; return asHostObject(v); } RETHROW_CATCH(); } void JPShortType::setArrayItem(jarray a, int ndx , HostRef* obj) { jshortArray array = (jshortArray)a; try { jshort val = convertToJava(obj).s; JPEnv::getJava()->SetShortArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPShortType::getArrayRangeToSequence(jarray a, int lo, int hi) { return getSlice(a, lo, hi, NPY_SHORT, PyInt_FromLong); } //---------------------------------------------------------- jarray JPIntType::newArrayInstance(int sz) { return JPEnv::getJava()->NewIntArray(sz); } HostRef* JPIntType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.i = JPEnv::getJava()->GetStaticIntField(c, fid); return asHostObject(v); } HostRef* JPIntType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.i = JPEnv::getJava()->GetIntField(c, fid); return asHostObject(v); } HostRef* JPIntType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.i = JPEnv::getJava()->CallStaticIntMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPIntType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.i = JPEnv::getJava()->CallNonvirtualIntMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPIntType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jint val = convertToJava(obj).i; JPEnv::getJava()->SetStaticIntField(c, fid, val); } void JPIntType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jint val = convertToJava(obj).i; JPEnv::getJava()->SetIntField(c, fid, val); } vector JPIntType::getArrayRange(jarray a, int start, int length) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.i = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } void JPIntType::setArrayRange(jarray a, int start, int length, vector& vals) { jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).i; } JPEnv::getJava()->ReleaseIntArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } void JPIntType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetIntArrayRegion)) return; jintArray array = (jintArray)a; jint* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetIntArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); jint v = (jint) PyInt_AsLong(o); Py_DecRef(o); if (v == -1) { CONVERSION_ERROR_HANDLE } val[start+i] = v; } JPEnv::getJava()->ReleaseIntArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseIntArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPIntType::getArrayItem(jarray a, int ndx) { jintArray array = (jintArray)a; jint val; try { JPEnv::getJava()->GetIntArrayRegion(array, ndx, 1, &val); jvalue v; v.i = val; return asHostObject(v); } RETHROW_CATCH(); } void JPIntType::setArrayItem(jarray a, int ndx , HostRef* obj) { jintArray array = (jintArray)a; jint val; try { val = convertToJava(obj).i; JPEnv::getJava()->SetIntArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPIntType::getArrayRangeToSequence(jarray a, int lo, int hi) { return getSlice(a, lo, hi, NPY_INT, PyInt_FromLong); } //---------------------------------------------------------- jarray JPLongType::newArrayInstance(int sz) { return JPEnv::getJava()->NewLongArray(sz); } HostRef* JPLongType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.j = JPEnv::getJava()->GetStaticLongField(c, fid); return asHostObject(v); } HostRef* JPLongType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.j = JPEnv::getJava()->GetLongField(c, fid); return asHostObject(v); } HostRef* JPLongType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.j = JPEnv::getJava()->CallStaticLongMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPLongType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.j = JPEnv::getJava()->CallNonvirtualLongMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPLongType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jlong val = convertToJava(obj).j; JPEnv::getJava()->SetStaticLongField(c, fid, val); } void JPLongType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jlong val = convertToJava(obj).j; JPEnv::getJava()->SetLongField(c, fid, val); } vector JPLongType::getArrayRange(jarray a, int start, int length) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.j = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } void JPLongType::setArrayRange(jarray a, int start, int length, vector& vals) { jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).j; } JPEnv::getJava()->ReleaseLongArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } void JPLongType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetLongArrayRegion)) return; jlongArray array = (jlongArray)a; jlong* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetLongArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); jlong l = (jlong) PyLong_AsLong(o); Py_DECREF(o); if(l == -1) { CONVERSION_ERROR_HANDLE; } val[start+i] = l; } JPEnv::getJava()->ReleaseLongArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseLongArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPLongType::getArrayItem(jarray a, int ndx) { jlongArray array = (jlongArray)a; jlong val; try { JPEnv::getJava()->GetLongArrayRegion(array, ndx, 1, &val); jvalue v; v.j = val; return asHostObject(v); } RETHROW_CATCH(); } void JPLongType::setArrayItem(jarray a, int ndx , HostRef* obj) { jlongArray array = (jlongArray)a; jlong val; try { val = convertToJava(obj).j; JPEnv::getJava()->SetLongArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPLongType::getArrayRangeToSequence(jarray a, int lo, int hi) { return getSlice(a, lo, hi, NPY_LONG, PyLong_FromLong); } //---------------------------------------------------------- jarray JPFloatType::newArrayInstance(int sz) { return JPEnv::getJava()->NewFloatArray(sz); } HostRef* JPFloatType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.f = JPEnv::getJava()->GetStaticFloatField(c, fid); return asHostObject(v); } HostRef* JPFloatType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.f = JPEnv::getJava()->GetFloatField(c, fid); return asHostObject(v); } HostRef* JPFloatType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.f = JPEnv::getJava()->CallStaticFloatMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPFloatType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.f = JPEnv::getJava()->CallNonvirtualFloatMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPFloatType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jfloat val = convertToJava(obj).f; JPEnv::getJava()->SetStaticFloatField(c, fid, val); } void JPFloatType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jfloat val = convertToJava(obj).f; JPEnv::getJava()->SetFloatField(c, fid, val); } vector JPFloatType::getArrayRange(jarray a, int start, int length) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.f = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } void JPFloatType::setArrayRange(jarray a, int start, int length, vector& vals) { jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).f; } JPEnv::getJava()->ReleaseFloatArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } void JPFloatType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetFloatArrayRegion)) return; jfloatArray array = (jfloatArray)a; jfloat* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetFloatArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); jfloat v = (jfloat) PyFloat_AsDouble(o); Py_DecRef(o); if (v == -1.) { CONVERSION_ERROR_HANDLE; } val[start+i] = v; } JPEnv::getJava()->ReleaseFloatArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseFloatArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPFloatType::getArrayItem(jarray a, int ndx) { jfloatArray array = (jfloatArray)a; jfloat val; try { JPEnv::getJava()->GetFloatArrayRegion(array, ndx, 1, &val); jvalue v; v.f = val; return asHostObject(v); } RETHROW_CATCH(); } void JPFloatType::setArrayItem(jarray a, int ndx , HostRef* obj) { jfloatArray array = (jfloatArray)a; jfloat val; try { val = convertToJava(obj).f; JPEnv::getJava()->SetFloatArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPFloatType::getArrayRangeToSequence(jarray a, int lo, int hi) { return getSlice(a, lo, hi, NPY_FLOAT32, PyFloat_FromDouble); } //---------------------------------------------------------- jarray JPDoubleType::newArrayInstance(int sz) { return JPEnv::getJava()->NewDoubleArray(sz); } HostRef* JPDoubleType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.d = JPEnv::getJava()->GetStaticDoubleField(c, fid); return asHostObject(v); } HostRef* JPDoubleType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.d = JPEnv::getJava()->GetDoubleField(c, fid); return asHostObject(v); } HostRef* JPDoubleType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.d = JPEnv::getJava()->CallStaticDoubleMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPDoubleType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.d = JPEnv::getJava()->CallNonvirtualDoubleMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPDoubleType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jdouble val = convertToJava(obj).d; JPEnv::getJava()->SetStaticDoubleField(c, fid, val); } void JPDoubleType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jdouble val = convertToJava(obj).d; JPEnv::getJava()->SetDoubleField(c, fid, val); } vector JPDoubleType::getArrayRange(jarray a, int start, int length) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.d = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); } ); } void JPDoubleType::setArrayRange(jarray a, int start, int length, vector& vals) { jdoubleArray array = (jdoubleArray)a; jdouble* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetDoubleArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).f; } JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseDoubleArrayElements(array, val, JNI_ABORT); }) } void JPDoubleType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetDoubleArrayRegion)) return; jdoubleArray array = (jdoubleArray)a; vector val; val.resize(length); // fill temporary array for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); jdouble d = (jdouble) PyFloat_AsDouble(o); Py_DecRef(o); if (d == -1.) { CONVERSION_ERROR_HANDLE; } val[i] = d; } // set java array try { JPEnv::getJava()->SetDoubleArrayRegion(array, start, length, &val.front()); } RETHROW_CATCH(); } HostRef* JPDoubleType::getArrayItem(jarray a, int ndx) { jdoubleArray array = (jdoubleArray)a; jdouble val; try { JPEnv::getJava()->GetDoubleArrayRegion(array,ndx, 1, &val); jvalue v; v.d = val; return asHostObject(v); } RETHROW_CATCH(); } void JPDoubleType::setArrayItem(jarray a, int ndx , HostRef* obj) { jdoubleArray array = (jdoubleArray)a; jdouble val; try { val = convertToJava(obj).d; JPEnv::getJava()->SetDoubleArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPDoubleType::getArrayRangeToSequence(jarray a, int lo, int hi) { return getSlice(a, lo, hi, NPY_FLOAT64, PyFloat_FromDouble); } //---------------------------------------------------------- jarray JPCharType::newArrayInstance(int sz) { return JPEnv::getJava()->NewCharArray(sz); } HostRef* JPCharType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.c = JPEnv::getJava()->GetStaticCharField(c, fid); return asHostObject(v); } HostRef* JPCharType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.c = JPEnv::getJava()->GetCharField(c, fid); return asHostObject(v); } HostRef* JPCharType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.c = JPEnv::getJava()->CallStaticCharMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPCharType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.c = JPEnv::getJava()->CallNonvirtualCharMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPCharType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jchar val = convertToJava(obj).c; JPEnv::getJava()->SetStaticCharField(c, fid, val); } void JPCharType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jchar val = convertToJava(obj).c; JPEnv::getJava()->SetCharField(c, fid, val); } vector JPCharType::getArrayRange(jarray a, int start, int length) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.c = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } void JPCharType::setArrayRange(jarray a, int start, int length, vector& vals) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).c; } JPEnv::getJava()->ReleaseCharArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } void JPCharType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetCharArrayRegion)) return; jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; long c; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); c = PyInt_AsLong(o); Py_DecRef(o); if(c == -1) { CONVERSION_ERROR_HANDLE; } val[start+i] = (jchar) c; } JPEnv::getJava()->ReleaseCharArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPCharType::getArrayItem(jarray a, int ndx) { jcharArray array = (jcharArray)a; jchar val; try { JPEnv::getJava()->GetCharArrayRegion(array, ndx, 1, &val); jvalue v; v.c = val; return asHostObject(v); } RETHROW_CATCH(); } void JPCharType::setArrayItem(jarray a, int ndx , HostRef* obj) { jcharArray array = (jcharArray)a; jchar val; try { val = convertToJava(obj).c; JPEnv::getJava()->SetCharArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPCharType::getArrayRangeToSequence(jarray a, int start, int length) { jcharArray array = (jcharArray)a; jchar* val = NULL; jboolean isCopy; PyObject* res = NULL; try { val = JPEnv::getJava()->GetCharArrayElements(array, &isCopy); if (sizeof(Py_UNICODE) == sizeof(jchar)) { res = PyUnicode_FromUnicode((const Py_UNICODE *) val + start, length); } else { res = PyUnicode_FromUnicode(NULL, length); Py_UNICODE *pchars = PyUnicode_AS_UNICODE(res); for (Py_ssize_t i = start; i < length; i++) pchars[i] = (Py_UNICODE) val[i]; } JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseCharArrayElements(array, val, JNI_ABORT); } ); } //---------------------------------------------------------- jarray JPBooleanType::newArrayInstance(int sz) { return JPEnv::getJava()->NewBooleanArray(sz); } HostRef* JPBooleanType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.z = JPEnv::getJava()->GetStaticBooleanField(c, fid); return asHostObject(v); } HostRef* JPBooleanType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { jvalue v; v.z = JPEnv::getJava()->GetBooleanField(c, fid); return asHostObject(v); } HostRef* JPBooleanType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { jvalue v; v.z = JPEnv::getJava()->CallStaticBooleanMethodA(claz, mth, val); return asHostObject(v); } HostRef* JPBooleanType::invoke(jobject obj, jclass clazz, jmethodID mth, jvalue* val) { jvalue v; v.z = JPEnv::getJava()->CallNonvirtualBooleanMethodA(obj, clazz, mth, val); return asHostObject(v); } void JPBooleanType::setStaticValue(jclass c, jfieldID fid, HostRef* obj) { jboolean val = convertToJava(obj).z; JPEnv::getJava()->SetStaticBooleanField(c, fid, val); } void JPBooleanType::setInstanceValue(jobject c, jfieldID fid, HostRef* obj) { jboolean val = convertToJava(obj).z; JPEnv::getJava()->SetBooleanField(c, fid, val); } vector JPBooleanType::getArrayRange(jarray a, int start, int length) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); vector res; jvalue v; for (int i = 0; i < length; i++) { v.z = val[i+start]; HostRef* pv = asHostObject(v); res.push_back(pv); } JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); return res; } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } void JPBooleanType::setArrayRange(jarray a, int start, int length, vector& vals) { jbooleanArray array = (jbooleanArray)a; jboolean* val = NULL; jboolean isCopy; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); for (int i = 0; i < length; i++) { HostRef* pv = vals[i]; val[start+i] = convertToJava(pv).z; } JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } void JPBooleanType::setArrayRange(jarray a, int start, int length, PyObject* sequence) { if (setViaBuffer(a, start, length, sequence, &JPJavaEnv::SetBooleanArrayRegion)) return; jbooleanArray array = (jbooleanArray) a; jboolean isCopy; jboolean* val = NULL; long c; try { val = JPEnv::getJava()->GetBooleanArrayElements(array, &isCopy); for (Py_ssize_t i = 0; i < length; ++i) { PyObject* o = PySequence_GetItem(sequence, i); c = PyInt_AsLong(o); Py_DecRef(o); if(c == -1) { CONVERSION_ERROR_HANDLE; } val[start+i] = (jboolean) c; } JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, 0); } RETHROW_CATCH( if (val != NULL) { JPEnv::getJava()->ReleaseBooleanArrayElements(array, val, JNI_ABORT); } ); } HostRef* JPBooleanType::getArrayItem(jarray a, int ndx) { jbooleanArray array = (jbooleanArray)a; jboolean val; try { JPEnv::getJava()->GetBooleanArrayRegion(array, ndx, 1, &val); jvalue v; v.z = val; return asHostObject(v); } RETHROW_CATCH(); } void JPBooleanType::setArrayItem(jarray a, int ndx , HostRef* obj) { jbooleanArray array = (jbooleanArray)a; try { jboolean val = convertToJava(obj).z; JPEnv::getJava()->SetBooleanArrayRegion(array, ndx, 1, &val); } RETHROW_CATCH(); } PyObject* JPBooleanType::getArrayRangeToSequence(jarray a, int start, int length) { return getSlice(a, start, length, NPY_BOOL, PyBool_FromLong); } //---------------------------------------------------------- jpype-0.6.2+dfsg/native/common/jp_proxy.cpp0000664000175000017500000002001413036015411020204 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include JNIEXPORT jobject JNICALL Java_jpype_JPypeInvocationHandler_hostInvoke( JNIEnv *env, jclass clazz, jstring name, jlong hostObj, jobjectArray args, jobjectArray types, jclass returnType) { TRACE_IN("Java_jpype_JPypeInvocationHandler_hostInvoke"); void* callbackState = JPEnv::getHost()->prepareCallbackBegin(); JPCleaner cleaner; try { string cname = JPJni::asciiFromJava(name); HostRef* hostObjRef = (HostRef*)hostObj; HostRef* callable = JPEnv::getHost()->getCallableFrom(hostObjRef, cname); cleaner.add(callable); if (callable == NULL || callable->isNull() || JPEnv::getHost()->isNone(callable)) { JPEnv::getJava()->ThrowNew(JPJni::s_NoSuchMethodErrorClass, cname.c_str()); JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } // convert the arguments into a python list jsize argLen = JPEnv::getJava()->GetArrayLength(types); vector hostArgs; std::vector argTypes; for (jsize j = 0; j < argLen; j++) { jclass c = (jclass)JPEnv::getJava()->GetObjectArrayElement(types, j); cleaner.addLocal(c); JPTypeName tn = JPJni::getName(c); argTypes.push_back(tn); } for (int i = 0; i < argLen; i++) { jobject obj = JPEnv::getJava()->GetObjectArrayElement(args, i); cleaner.addLocal(obj); JPTypeName t = argTypes[i]; jvalue v; v.l = obj; HostRef* o = JPTypeManager::getType(t)->asHostObjectFromObject(v); cleaner.add(o); hostArgs.push_back(o); } HostRef* returnValue = JPEnv::getHost()->callObject(callable, hostArgs); cleaner.add(returnValue); JPTypeName returnT = JPJni::getName(returnType); if (returnValue == NULL || returnValue->isNull() || JPEnv::getHost()->isNone(returnValue)) { if (returnT.getType() != JPTypeName::_void && returnT.getType() < JPTypeName::_object) { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Return value is None when it cannot be"); JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } } if (returnT.getType() == JPTypeName::_void) { JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } JPType* rt = JPTypeManager::getType(returnT); if (rt->canConvertToJava(returnValue) == _none) { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, "Return value is not compatible with required type."); JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; } jobject returnObj = rt->convertToJavaObject(returnValue); JPEnv::getHost()->prepareCallbackFinish(callbackState); return returnObj; } catch(HostException& ex) { JPEnv::getHost()->clearError(); if (JPEnv::getHost()->isJavaException(&ex)) { JPCleaner cleaner; HostRef* javaExcRef = JPEnv::getHost()->getJavaException(&ex); JPObject* javaExc = JPEnv::getHost()->asObject(javaExcRef); cleaner.add(javaExcRef); jobject obj = javaExc->getObject(); cleaner.addLocal(obj); JPEnv::getJava()->Throw((jthrowable)obj); } else { // Prepare a message string message = "Python exception thrown: "; message += ex.getMessage(); JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, message.c_str()); } } catch(JavaException&) { cerr << "Java exception at " << __FILE__ << ":" << __LINE__ << endl; } catch(JPypeException& ex) { JPEnv::getJava()->ThrowNew(JPJni::s_RuntimeExceptionClass, ex.getMsg()); } JPEnv::getHost()->prepareCallbackFinish(callbackState); return NULL; TRACE_OUT; } JNIEXPORT void JNICALL Java_jpype_ref_JPypeReferenceQueue_removeHostReference( JNIEnv *env, jclass clazz, jlong hostObj) { TRACE_IN("Java_jpype_ref_JPypeReferenceQueue_removeHostReference"); void* callbackState = JPEnv::getHost()->prepareCallbackBegin(); if (hostObj >0) { HostRef* hostObjRef = (HostRef*)hostObj; //JPEnv::getHost()->printReferenceInfo(hostObjRef); delete hostObjRef; } JPEnv::getHost()->prepareCallbackFinish(callbackState); //return NULL; TRACE_OUT; } namespace { // impl detail, gets initialized by JPProxy::init() jclass handlerClass; jclass referenceClass; jclass referenceQueueClass; jmethodID invocationHandlerConstructorID; jfieldID hostObjectID; } void JPProxy::init() { TRACE_IN("JPProxy::init"); // build the proxy class ... jobject cl = JPJni::getSystemClassLoader(); JPCleaner cleaner; jclass handler = JPEnv::getJava()->DefineClass("jpype/JPypeInvocationHandler", cl, JPypeInvocationHandler, getJPypeInvocationHandlerLength()); handlerClass = (jclass)JPEnv::getJava()->NewGlobalRef(handler); cleaner.addLocal(handler); JNINativeMethod method[1]; method[0].name = (char*) "hostInvoke"; method[0].signature =(char*) "(Ljava/lang/String;J[Ljava/lang/Object;[Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;"; method[0].fnPtr = (void*) &Java_jpype_JPypeInvocationHandler_hostInvoke; hostObjectID = JPEnv::getJava()->GetFieldID(handler, "hostObject", "J"); invocationHandlerConstructorID = JPEnv::getJava()->GetMethodID(handler, "", "()V"); JPEnv::getJava()->RegisterNatives(handlerClass, method, 1); // Not quite the right area ... but I;m doing similar here already so let's register the other classes too jclass reference = JPEnv::getJava()->DefineClass("jpype/ref/JPypeReference", cl, JPypeReference, getJPypeReferenceLength()); jclass referenceQueue = JPEnv::getJava()->DefineClass("jpype/ref/JPypeReferenceQueue", cl, JPypeReferenceQueue, getJPypeReferenceQueueLength()); referenceClass = (jclass)JPEnv::getJava()->NewGlobalRef(reference); referenceQueueClass = (jclass)JPEnv::getJava()->NewGlobalRef(referenceQueue); //Required due to bug in jvm //See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6493522 JPEnv::getJava()->GetMethodID(referenceQueue, "", "()V"); cleaner.addLocal(reference); cleaner.addLocal(referenceQueue); JNINativeMethod method2[1]; method2[0].name = (char*) "removeHostReference"; method2[0].signature = (char*) "(J)V"; method2[0].fnPtr = (void*)&Java_jpype_ref_JPypeReferenceQueue_removeHostReference; JPEnv::getJava()->RegisterNatives(referenceQueueClass, method2, 1); TRACE_OUT; } JPProxy::JPProxy(HostRef* inst, vector& intf) { m_Instance = inst->copy(); jobjectArray ar = JPEnv::getJava()->NewObjectArray((int)intf.size(), JPJni::s_ClassClass, NULL); m_Interfaces = (jobjectArray)JPEnv::getJava()->NewGlobalRef(ar); JPEnv::getJava()->DeleteLocalRef(ar); for (unsigned int i = 0; i < intf.size(); i++) { m_InterfaceClasses.push_back((jclass)JPEnv::getJava()->NewGlobalRef(intf[i])); JPEnv::getJava()->SetObjectArrayElement(m_Interfaces, i, m_InterfaceClasses[i]); } m_Handler = JPEnv::getJava()->NewObject(handlerClass, invocationHandlerConstructorID); JPEnv::getJava()->SetLongField(m_Handler, hostObjectID, (jlong)inst->copy()); } jobject JPProxy::getProxy() { JPCleaner cleaner; jobject cl = JPJni::getSystemClassLoader(); cleaner.addLocal(cl); jvalue v[3]; v[0].l = cl; v[1].l = m_Interfaces; v[2].l = m_Handler; jobject res = JPEnv::getJava()->CallStaticObjectMethodA(JPJni::s_ProxyClass, JPJni::s_NewProxyInstanceID, v); return res; } jpype-0.6.2+dfsg/native/common/jp_reference.cpp0000664000175000017500000002566413036015411021001 0ustar takakitakaki#include jbyte JPypeReference[] = { (jbyte)0xCA,(jbyte)0xFE,(jbyte)0xBA,(jbyte)0xBE,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x21,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x50,(jbyte)0x68,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x6D,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x6D ,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x4A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06 ,(jbyte)0x3C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x69,(jbyte)0x74,(jbyte)0x3E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x33,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67 ,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x56 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F ,(jbyte)0x4C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x65,(jbyte)0x4E,(jbyte)0x75,(jbyte)0x6D,(jbyte)0x62,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6F ,(jbyte)0x63,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x56,(jbyte)0x61,(jbyte)0x72,(jbyte)0x69,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x74 ,(jbyte)0x68,(jbyte)0x69,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79 ,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x61,(jbyte)0x72,(jbyte)0x67,(jbyte)0x30,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x61,(jbyte)0x72,(jbyte)0x67,(jbyte)0x31,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67 ,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x3B ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x06,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x16,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x73,(jbyte)0x65 ,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x28,(jbyte)0x4A,(jbyte)0x29 ,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x61,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x08,(jbyte)0x68,(jbyte)0x61,(jbyte)0x73,(jbyte)0x68,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x49,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x65,(jbyte)0x71 ,(jbyte)0x75,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x15,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F ,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x5A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x53,(jbyte)0x6F,(jbyte)0x75,(jbyte)0x72,(jbyte)0x63,(jbyte)0x65,(jbyte)0x46,(jbyte)0x69,(jbyte)0x6C ,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x13,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x2E,(jbyte)0x6A ,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x49,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x2A,(jbyte)0x2B,(jbyte)0x2C,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x0B,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x03 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x12,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x14,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0xAD,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x18,(jbyte)0x00,(jbyte)0x19,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x09,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2A,(jbyte)0x1F,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x17,(jbyte)0xB1,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x17,(jbyte)0x00 ,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x06,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x30,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0x88,(jbyte)0xAC,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00 ,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1D,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x58,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x2B,(jbyte)0xC1,(jbyte)0x00,(jbyte)0x02,(jbyte)0x9A,(jbyte)0x00,(jbyte)0x05,(jbyte)0x03,(jbyte)0xAC ,(jbyte)0x2B,(jbyte)0xC0,(jbyte)0x00,(jbyte)0x02,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x17,(jbyte)0x94,(jbyte)0x9A,(jbyte)0x00,(jbyte)0x05,(jbyte)0x04,(jbyte)0xAC,(jbyte)0x03,(jbyte)0xAC,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00 ,(jbyte)0x09,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00 ,(jbyte)0x20 }; jsize getJPypeReferenceLength() { return 901; } jpype-0.6.2+dfsg/native/common/jp_referencequeue.cpp0000664000175000017500000005531113036015411022036 0ustar takakitakaki#include jbyte JPypeReferenceQueue[] = { (jbyte)0xCA,(jbyte)0xFE,(jbyte)0xBA,(jbyte)0xBE,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x62,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1D,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72 ,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65 ,(jbyte)0x75,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x01,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x07,(jbyte)0x00,(jbyte)0x03,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x12,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x75,(jbyte)0x6E,(jbyte)0x6E,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65 ,(jbyte)0x07,(jbyte)0x00,(jbyte)0x05,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x6D,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x75,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x65,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x08,(jbyte)0x6D,(jbyte)0x53,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x70,(jbyte)0x70,(jbyte)0x65,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x5A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x6D,(jbyte)0x51,(jbyte)0x75 ,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x54,(jbyte)0x68,(jbyte)0x72,(jbyte)0x65,(jbyte)0x61,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61 ,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x54,(jbyte)0x68,(jbyte)0x72,(jbyte)0x65,(jbyte)0x61,(jbyte)0x64,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x6D,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x53 ,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x70,(jbyte)0x4D,(jbyte)0x75,(jbyte)0x74,(jbyte)0x65,(jbyte)0x78,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x3C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x69,(jbyte)0x74,(jbyte)0x3E,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x43,(jbyte)0x6F,(jbyte)0x64,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x10,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00 ,(jbyte)0x12,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x75,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x2F,(jbyte)0x48,(jbyte)0x61,(jbyte)0x73,(jbyte)0x68,(jbyte)0x53,(jbyte)0x65 ,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x14,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x15,(jbyte)0x00,(jbyte)0x12,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x17,(jbyte)0x0C ,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x19,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E ,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x12,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00 ,(jbyte)0x0E,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x4C,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x65,(jbyte)0x4E,(jbyte)0x75,(jbyte)0x6D,(jbyte)0x62,(jbyte)0x65,(jbyte)0x72,(jbyte)0x54 ,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x12,(jbyte)0x4C,(jbyte)0x6F,(jbyte)0x63,(jbyte)0x61,(jbyte)0x6C,(jbyte)0x56,(jbyte)0x61,(jbyte)0x72,(jbyte)0x69,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65 ,(jbyte)0x54,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x74,(jbyte)0x68,(jbyte)0x69,(jbyte)0x73,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70 ,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x72,(jbyte)0x65,(jbyte)0x67,(jbyte)0x69,(jbyte)0x73,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66 ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65 ,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x4A,(jbyte)0x29,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70 ,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x07,(jbyte)0x00,(jbyte)0x26,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x73,(jbyte)0x65,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E ,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x28,(jbyte)0x4A,(jbyte)0x29,(jbyte)0x56,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x28,(jbyte)0x00,(jbyte)0x29,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x27,(jbyte)0x00,(jbyte)0x2A,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x75,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x2F,(jbyte)0x53,(jbyte)0x65,(jbyte)0x74,(jbyte)0x07,(jbyte)0x00,(jbyte)0x2C,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x61,(jbyte)0x64,(jbyte)0x64,(jbyte)0x01,(jbyte)0x00,(jbyte)0x15,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x4F ,(jbyte)0x62,(jbyte)0x6A,(jbyte)0x65,(jbyte)0x63,(jbyte)0x74,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x5A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x2E,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x2D,(jbyte)0x00,(jbyte)0x30,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x03,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x70,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x4A,(jbyte)0x50 ,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x07,(jbyte)0x68,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74 ,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x4A,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x73,(jbyte)0x74,(jbyte)0x61,(jbyte)0x72,(jbyte)0x74,(jbyte)0x4D,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x61,(jbyte)0x67 ,(jbyte)0x69,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x54,(jbyte)0x68,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x61,(jbyte)0x64,(jbyte)0x07,(jbyte)0x00,(jbyte)0x37,(jbyte)0x01,(jbyte)0x00,(jbyte)0x17,(jbyte)0x28,(jbyte)0x4C,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F ,(jbyte)0x52,(jbyte)0x75,(jbyte)0x6E,(jbyte)0x6E,(jbyte)0x61,(jbyte)0x62,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x29,(jbyte)0x56,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x39,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x38,(jbyte)0x00 ,(jbyte)0x3A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x09,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x3C,(jbyte)0x01,(jbyte)0x00,(jbyte)0x05,(jbyte)0x73,(jbyte)0x74,(jbyte)0x61,(jbyte)0x72,(jbyte)0x74,(jbyte)0x0C ,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x10,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x38,(jbyte)0x00,(jbyte)0x3F,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x72,(jbyte)0x75,(jbyte)0x6E,(jbyte)0x05,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0xFA,(jbyte)0x01,(jbyte)0x00,(jbyte)0x06,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6D,(jbyte)0x6F,(jbyte)0x76,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x28,(jbyte)0x4A,(jbyte)0x29,(jbyte)0x4C ,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x72,(jbyte)0x65,(jbyte)0x66,(jbyte)0x2F,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x3B,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x44,(jbyte)0x00,(jbyte)0x45,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x46,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x44,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x0B ,(jbyte)0x00,(jbyte)0x2D,(jbyte)0x00,(jbyte)0x48,(jbyte)0x01,(jbyte)0x00,(jbyte)0x10,(jbyte)0x67,(jbyte)0x65,(jbyte)0x74,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65 ,(jbyte)0x6E,(jbyte)0x63,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x03,(jbyte)0x28,(jbyte)0x29,(jbyte)0x4A,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x4A,(jbyte)0x00,(jbyte)0x4B,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x27,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x13,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6D,(jbyte)0x6F,(jbyte)0x76,(jbyte)0x65,(jbyte)0x48,(jbyte)0x6F,(jbyte)0x73,(jbyte)0x74,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63 ,(jbyte)0x65,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x4E,(jbyte)0x00,(jbyte)0x29,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x4F,(jbyte)0x05,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF,(jbyte)0xFF ,(jbyte)0x01,(jbyte)0x00,(jbyte)0x09,(jbyte)0x6E,(jbyte)0x6F,(jbyte)0x74,(jbyte)0x69,(jbyte)0x66,(jbyte)0x79,(jbyte)0x41,(jbyte)0x6C,(jbyte)0x6C,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x53,(jbyte)0x00,(jbyte)0x10,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x1C ,(jbyte)0x00,(jbyte)0x54,(jbyte)0x01,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72 ,(jbyte)0x72,(jbyte)0x75,(jbyte)0x70,(jbyte)0x74,(jbyte)0x65,(jbyte)0x64,(jbyte)0x45,(jbyte)0x78,(jbyte)0x63,(jbyte)0x65,(jbyte)0x70,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x07,(jbyte)0x00,(jbyte)0x56,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x04,(jbyte)0x73,(jbyte)0x74,(jbyte)0x6F,(jbyte)0x70,(jbyte)0x05,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x13,(jbyte)0x88,(jbyte)0x01,(jbyte)0x00,(jbyte)0x04,(jbyte)0x77,(jbyte)0x61,(jbyte)0x69 ,(jbyte)0x74,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x5B,(jbyte)0x00,(jbyte)0x29,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x00,(jbyte)0x5C,(jbyte)0x01,(jbyte)0x00,(jbyte)0x02,(jbyte)0x65,(jbyte)0x78,(jbyte)0x01,(jbyte)0x00,(jbyte)0x20,(jbyte)0x4C ,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x2F,(jbyte)0x6C,(jbyte)0x61,(jbyte)0x6E,(jbyte)0x67,(jbyte)0x2F,(jbyte)0x49,(jbyte)0x6E,(jbyte)0x74,(jbyte)0x65,(jbyte)0x72,(jbyte)0x72,(jbyte)0x75,(jbyte)0x70,(jbyte)0x74,(jbyte)0x65 ,(jbyte)0x64,(jbyte)0x45,(jbyte)0x78,(jbyte)0x63,(jbyte)0x65,(jbyte)0x70,(jbyte)0x74,(jbyte)0x69,(jbyte)0x6F,(jbyte)0x6E,(jbyte)0x3B,(jbyte)0x01,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x53,(jbyte)0x6F,(jbyte)0x75,(jbyte)0x72,(jbyte)0x63,(jbyte)0x65 ,(jbyte)0x46,(jbyte)0x69,(jbyte)0x6C,(jbyte)0x65,(jbyte)0x01,(jbyte)0x00,(jbyte)0x18,(jbyte)0x4A,(jbyte)0x50,(jbyte)0x79,(jbyte)0x70,(jbyte)0x65,(jbyte)0x52,(jbyte)0x65,(jbyte)0x66,(jbyte)0x65,(jbyte)0x72,(jbyte)0x65,(jbyte)0x6E,(jbyte)0x63 ,(jbyte)0x65,(jbyte)0x51,(jbyte)0x75,(jbyte)0x65,(jbyte)0x75,(jbyte)0x65,(jbyte)0x2E,(jbyte)0x6A,(jbyte)0x61,(jbyte)0x76,(jbyte)0x61,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x06,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x08,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x09,(jbyte)0x00,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0B,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x06,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00 ,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x5A,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x2A ,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x13,(jbyte)0x2A,(jbyte)0xBB,(jbyte)0x00,(jbyte)0x15,(jbyte)0x59,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x16,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2A,(jbyte)0x03,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x2A ,(jbyte)0xBB,(jbyte)0x00,(jbyte)0x1C,(jbyte)0x59,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x1D,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x1F,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x16,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x0F,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x14,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00 ,(jbyte)0x1F,(jbyte)0x00,(jbyte)0x0D,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x2B,(jbyte)0x20,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x2B,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2B,(jbyte)0xB9,(jbyte)0x00,(jbyte)0x31,(jbyte)0x02,(jbyte)0x00,(jbyte)0x57,(jbyte)0xB1 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x18,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x19 ,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x32,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x34,(jbyte)0x00,(jbyte)0x35 ,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x46,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x14,(jbyte)0x2A,(jbyte)0xBB,(jbyte)0x00,(jbyte)0x38,(jbyte)0x59,(jbyte)0x2A,(jbyte)0xB7,(jbyte)0x00,(jbyte)0x3B,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x3D,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x3D ,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x40,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x23 ,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00,(jbyte)0x25,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x14 ,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x41,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x24 ,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x04,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x70,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x4D,(jbyte)0x2A,(jbyte)0x14,(jbyte)0x00,(jbyte)0x42,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x47,(jbyte)0xC0,(jbyte)0x00 ,(jbyte)0x27,(jbyte)0x4C,(jbyte)0x2B,(jbyte)0xC6,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x18,(jbyte)0x59,(jbyte)0x4D,(jbyte)0xC2,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2B,(jbyte)0xB9,(jbyte)0x00 ,(jbyte)0x49,(jbyte)0x02,(jbyte)0x00,(jbyte)0x57,(jbyte)0x2C,(jbyte)0xC3,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2C,(jbyte)0xC3,(jbyte)0xBF,(jbyte)0x2B,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x4D,(jbyte)0xB8,(jbyte)0x00,(jbyte)0x50,(jbyte)0xA7 ,(jbyte)0x00,(jbyte)0x13,(jbyte)0x4E,(jbyte)0xA8,(jbyte)0x00,(jbyte)0x05,(jbyte)0x2D,(jbyte)0xBF,(jbyte)0x4D,(jbyte)0x2B,(jbyte)0x14,(jbyte)0x00,(jbyte)0x51,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x2B,(jbyte)0xA9,(jbyte)0x02,(jbyte)0xA8,(jbyte)0xFF ,(jbyte)0xF6,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x04,(jbyte)0x4C,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x99,(jbyte)0xFF,(jbyte)0xB2,(jbyte)0x2A,(jbyte)0x01,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x18,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00 ,(jbyte)0x1F,(jbyte)0x59,(jbyte)0x4C,(jbyte)0xC2,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1F,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x55,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x06,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xBF,(jbyte)0xB1 ,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x19,(jbyte)0x00,(jbyte)0x26,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x2B,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x2C ,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x46,(jbyte)0x00,(jbyte)0x49,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x00,(jbyte)0x4C ,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x60,(jbyte)0x00,(jbyte)0x69,(jbyte)0x00,(jbyte)0x6C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x6C,(jbyte)0x00,(jbyte)0x6E,(jbyte)0x00,(jbyte)0x6C,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02 ,(jbyte)0x00,(jbyte)0x20,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x4E,(jbyte)0x00,(jbyte)0x13,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x2F,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x30 ,(jbyte)0x00,(jbyte)0x12,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x19,(jbyte)0x00,(jbyte)0x35,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x2C,(jbyte)0x00,(jbyte)0x39,(jbyte)0x00,(jbyte)0x36,(jbyte)0x00,(jbyte)0x3C ,(jbyte)0x00,(jbyte)0x3A,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x3C,(jbyte)0x00,(jbyte)0x3C,(jbyte)0x00,(jbyte)0x3D,(jbyte)0x00,(jbyte)0x3D,(jbyte)0x00,(jbyte)0x44,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x00,(jbyte)0x41 ,(jbyte)0x00,(jbyte)0x4D,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x54,(jbyte)0x00,(jbyte)0x46,(jbyte)0x00,(jbyte)0x59,(jbyte)0x00,(jbyte)0x48,(jbyte)0x00,(jbyte)0x60,(jbyte)0x00,(jbyte)0x4A,(jbyte)0x00,(jbyte)0x67,(jbyte)0x00,(jbyte)0x48 ,(jbyte)0x00,(jbyte)0x6F,(jbyte)0x00,(jbyte)0x4C,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x70,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x0E,(jbyte)0x00,(jbyte)0x3E,(jbyte)0x00,(jbyte)0x32,(jbyte)0x00,(jbyte)0x33,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x58,(jbyte)0x00,(jbyte)0x10,(jbyte)0x00,(jbyte)0x01 ,(jbyte)0x00,(jbyte)0x11,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x88,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x24,(jbyte)0x2A,(jbyte)0x04,(jbyte)0xB5,(jbyte)0x00,(jbyte)0x1A,(jbyte)0x2A ,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x59,(jbyte)0x4C,(jbyte)0xC2,(jbyte)0x2A,(jbyte)0xB4,(jbyte)0x00,(jbyte)0x1F,(jbyte)0x14,(jbyte)0x00,(jbyte)0x59,(jbyte)0xB6,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xA7,(jbyte)0x00 ,(jbyte)0x0B,(jbyte)0x2B,(jbyte)0xC3,(jbyte)0xBF,(jbyte)0xA7,(jbyte)0x00,(jbyte)0x05,(jbyte)0x4C,(jbyte)0xB1,(jbyte)0xB1,(jbyte)0x00,(jbyte)0x03,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x18,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x00 ,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x1D,(jbyte)0x00,(jbyte)0x1B,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x20 ,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x1E,(jbyte)0x00,(jbyte)0x07,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x51,(jbyte)0x00,(jbyte)0x05,(jbyte)0x00,(jbyte)0x55,(jbyte)0x00,(jbyte)0x0C,(jbyte)0x00,(jbyte)0x57,(jbyte)0x00,(jbyte)0x16 ,(jbyte)0x00,(jbyte)0x55,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x5A,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x5D,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00,(jbyte)0x5F,(jbyte)0x00,(jbyte)0x21,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x16 ,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x24,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x23,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x22,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x5E,(jbyte)0x00,(jbyte)0x5F ,(jbyte)0x00,(jbyte)0x01,(jbyte)0x01,(jbyte)0x0A,(jbyte)0x00,(jbyte)0x4E,(jbyte)0x00,(jbyte)0x29,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x01,(jbyte)0x00,(jbyte)0x60,(jbyte)0x00,(jbyte)0x00,(jbyte)0x00,(jbyte)0x02,(jbyte)0x00,(jbyte)0x61 }; jsize getJPypeReferenceQueueLength() { return 1880; } jpype-0.6.2+dfsg/native/common/jp_typemanager.cpp0000664000175000017500000001222613036015411021345 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include namespace { //AT's on porting: // 1) TODO: test on HP-UX platform. Cause: it is suspected to be an undefined order of initialization of static objects // // 2) TODO: in any case, use of static objects may impose problems in multi-threaded environment. typedef map TypeMap; typedef map JavaClassMap; typedef map JavaArrayClassMap; TypeMap typeMap; JavaClassMap javaClassMap; JavaArrayClassMap javaArrayClassMap; // TypeMap typeMap; // JavaClassMap javaClassMap; // JavaArrayClassMap javaArrayClassMap; } namespace JPTypeManager { void init() { typeMap[JPTypeName::_void] = new JPVoidType(); typeMap[JPTypeName::_byte] = new JPByteType(); typeMap[JPTypeName::_short] = new JPShortType(); typeMap[JPTypeName::_int] = new JPIntType(); typeMap[JPTypeName::_long] = new JPLongType(); typeMap[JPTypeName::_float] = new JPFloatType(); typeMap[JPTypeName::_double] = new JPDoubleType(); typeMap[JPTypeName::_char] = new JPCharType(); typeMap[JPTypeName::_boolean] = new JPBooleanType(); typeMap[JPTypeName::_string] = new JPStringType(); typeMap[JPTypeName::_class] = new JPClassType(); // Preload the "primitive" types javaClassMap["byte"] = new JPClass(JPTypeName::fromSimple("byte"), JPJni::getByteClass()); javaClassMap["short"] = new JPClass(JPTypeName::fromSimple("short"), JPJni::getShortClass()); javaClassMap["int"] = new JPClass(JPTypeName::fromSimple("int"), JPJni::getIntegerClass()); javaClassMap["long"] = new JPClass(JPTypeName::fromSimple("long"), JPJni::getLongClass()); javaClassMap["float"] = new JPClass(JPTypeName::fromSimple("float"), JPJni::getFloatClass()); javaClassMap["double"] = new JPClass(JPTypeName::fromSimple("double"), JPJni::getDoubleClass()); javaClassMap["char"] = new JPClass(JPTypeName::fromSimple("char"), JPJni::getCharacterClass()); javaClassMap["boolean"] = new JPClass(JPTypeName::fromSimple("boolean"), JPJni::getBooleanClass()); javaClassMap["void"] = new JPClass(JPTypeName::fromSimple("void"), JPJni::getVoidClass()); } JPClass* findClass(const JPTypeName& name) { // Fist check in the map ... JavaClassMap::iterator cur = javaClassMap.find(name.getSimpleName()); if (cur != javaClassMap.end()) { return cur->second; } TRACE_IN("JPTypeManager::findClass"); TRACE1(name.getSimpleName()); // No we havent got it .. lets load it!!! JPCleaner cleaner; jclass cls = JPEnv::getJava()->FindClass(name.getNativeName().c_str()); cleaner.addLocal(cls); JPClass* res = new JPClass(name, cls); // Register it here before we do anything else javaClassMap[name.getSimpleName()] = res; // Finish loading it res->postLoad(); return res; TRACE_OUT; } JPArrayClass* findArrayClass(const JPTypeName& name) { // Fist check in the map ... JavaArrayClassMap::iterator cur = javaArrayClassMap.find(name.getSimpleName()); if (cur != javaArrayClassMap.end()) { return cur->second; } // No we havent got it .. lets load it!!! JPCleaner cleaner; jclass cls = JPEnv::getJava()->FindClass(name.getNativeName().c_str()); cleaner.addLocal(cls); JPArrayClass* res = new JPArrayClass(name, cls); // Register it here before we do anything else javaArrayClassMap[name.getSimpleName()] = res; return res; } JPType* getType(const JPTypeName& t) { TRACE_IN("JPTypeManager::getType"); map::iterator it = typeMap.find(t.getType()); if (it != typeMap.end()) { return it->second; } if (t.getType() == JPTypeName::_array) { JPArrayClass* c = findArrayClass(t); return c; } else { JPClass* c = findClass(t); return c; } TRACE_OUT; } void shutdown() { flushCache(); // delete primitive types for(TypeMap::iterator i = typeMap.begin(); i != typeMap.end(); ++i) { delete i->second; } } void flushCache() { for(JavaClassMap::iterator i = javaClassMap.begin(); i != javaClassMap.end(); ++i) { delete i->second; } for(JavaArrayClassMap::iterator i = javaArrayClassMap.begin(); i != javaArrayClassMap.end(); ++i) { delete i->second; } javaClassMap.clear(); javaArrayClassMap.clear(); } int getLoadedClasses() { // dignostic tools ... unlikely to load more classes than int can hold ... return (int)(javaClassMap.size() + javaArrayClassMap.size()); } } // end of namespace JPTypeManager jpype-0.6.2+dfsg/native/common/jp_typename.cpp0000664000175000017500000000736413036015411020662 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include #undef JPYPE_TRACING_INTERNAL JPTypeName::NativeNamesMap JPTypeName::nativeNames; JPTypeName::DefinedTypesMap JPTypeName::definedTypes; JPTypeName::NativeTypesMap JPTypeName::nativeTypes; static string convertToNativeClassName(const string& str) { // simple names are of the form : // a.c.d.E // native names are of the form : // La/c/d/E; string name = str; string result = string("L")+name+";"; for (unsigned int j = 0; j < result.length(); j++) { if (result[j] == '.') { result[j] = '/'; } } return result; } void JPTypeName::init() { nativeNames["void"] = "V"; nativeNames["byte"] = "B"; nativeNames["short"] = "S"; nativeNames["int"] = "I"; nativeNames["long"] = "J"; nativeNames["float"] = "F"; nativeNames["double"] = "D"; nativeNames["boolean"] = "Z"; nativeNames["char"] = "C"; definedTypes["void"] = _void; definedTypes["byte"] = _byte; definedTypes["short"] = _short; definedTypes["int"] = _int; definedTypes["long"] = _long; definedTypes["float"] = _float; definedTypes["double"] = _double; definedTypes["boolean"] = _boolean; definedTypes["char"] = _char; definedTypes["java.lang.String"] = _string; definedTypes["java.lang.Class"] = _class; for (DefinedTypesMap::iterator it = definedTypes.begin(); it != definedTypes.end(); ++it) { nativeTypes[it->second] = it->first; } } JPTypeName JPTypeName::fromType(JPTypeName::ETypes t) { return fromSimple(nativeTypes[t].c_str()); } JPTypeName JPTypeName::fromSimple(const char* name) { string simple = name; string componentName = simple; string nativeComponent; ETypes t; // is it an array? size_t arrayDimCount = 0; if (simple.length() > 0 && simple[simple.length()-1] == ']') { size_t i = simple.length()-1; while (simple[i] == ']' || simple[i] == '[') { i--; } componentName = simple.substr(0, i+1); arrayDimCount = (simple.length() - componentName.length())/2; } NativeNamesMap::iterator nativeIt = nativeNames.find(componentName); if (nativeIt == nativeNames.end()) { nativeComponent = convertToNativeClassName(componentName); } else { nativeComponent = nativeIt->second; } string native; if (arrayDimCount > 0) { stringstream str; for (unsigned int i = 0; i < arrayDimCount; i++) { str << "["; } str << nativeComponent; native = str.str(); } else { native = nativeComponent; } DefinedTypesMap::iterator typeIt = definedTypes.find(name); if (typeIt == definedTypes.end()) { if (native[0] == '[') { t = _array; } else { t = _object; } } else { t = typeIt->second; } return JPTypeName(simple, native, t); } JPTypeName JPTypeName::getComponentName() const { if (m_Type != _array) { RAISE(JPypeException, "Not an array type"); } string sname = m_SimpleName.substr(0,m_SimpleName.length()-2); JPTypeName compName = fromSimple(sname.c_str()); return compName; } jpype-0.6.2+dfsg/native/common/jp_voidtype.cpp0000664000175000017500000000553213036015411020676 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include HostRef* JPVoidType::getStaticValue(jclass c, jfieldID fid, JPTypeName& tgtType) { RAISE(JPypeException, "void cannot be the type of a static field."); } HostRef* JPVoidType::getInstanceValue(jobject c, jfieldID fid, JPTypeName& tgtType) { RAISE(JPypeException, "void cannot be the type of a field."); } HostRef* JPVoidType::asHostObject(jvalue val) { return JPEnv::getHost()->getNone(); } HostRef* JPVoidType::asHostObjectFromObject(jvalue val) { return JPEnv::getHost()->getNone(); } EMatchType JPVoidType::canConvertToJava(HostRef* obj) { return _none; } jvalue JPVoidType::convertToJava(HostRef* obj) { jvalue res; res.l = NULL; return res; } HostRef* JPVoidType::invokeStatic(jclass claz, jmethodID mth, jvalue* val) { JPEnv::getJava()->CallStaticVoidMethodA(claz, mth, val); return JPEnv::getHost()->getNone(); } HostRef* JPVoidType::invoke(jobject claz, jclass clazz, jmethodID mth, jvalue* val) { JPEnv::getJava()->CallVoidMethodA(claz, mth, val); return JPEnv::getHost()->getNone(); } void JPVoidType::setStaticValue(jclass c, jfieldID fid, HostRef*) { RAISE(JPypeException, "void cannot be the type of a static field."); } void JPVoidType::setInstanceValue(jobject c, jfieldID fid, HostRef*) { RAISE(JPypeException, "void cannot be the type of a field."); } vector JPVoidType::getArrayRange(jarray, int, int) { RAISE(JPypeException, "void cannot be the type of an array."); } void JPVoidType::setArrayRange(jarray, int, int, vector&) { RAISE(JPypeException, "void cannot be the type of an array."); } HostRef* JPVoidType::getArrayItem(jarray, int) { RAISE(JPypeException, "void cannot be the type of an array."); } void JPVoidType::setArrayItem(jarray, int, HostRef*) { RAISE(JPypeException, "void cannot be the type of an array."); } jarray JPVoidType::newArrayInstance(int) { RAISE(JPypeException, "void cannot be the type of an array."); } HostRef* JPVoidType::convertToDirectBuffer(HostRef* src) { RAISE(JPypeException, "Unable to convert to Direct Buffer"); } jpype-0.6.2+dfsg/native/jni_include/0000775000175000017500000000000013036015411016624 5ustar takakitakakijpype-0.6.2+dfsg/native/jni_include/jni.h0000664000175000017500000015004313036015411017560 0ustar takakitakaki/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * JNI specification, as defined by Sun: * http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html * * Everything here is expected to be VM-neutral. */ #ifndef JNI_H_ #define JNI_H_ #include #ifdef _MSC_VER // broken m$ compiler does not have c99 std header #if _MSC_VER >= 1600 #include #else typedef __int8 int8_t; typedef __int16 int16_t; typedef __int32 int32_t; typedef __int64 int64_t; typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; #endif #else #include #endif #include /* Primitive types that match up with Java equivalents. */ typedef uint8_t jboolean; /* unsigned 8 bits */ typedef int8_t jbyte; /* signed 8 bits */ typedef uint16_t jchar; /* unsigned 16 bits */ typedef int16_t jshort; /* signed 16 bits */ #if defined(_WIN32) typedef long jint; #else typedef int32_t jint; /* signed 32 bits */ #endif // define jlong #ifdef _LP64 /* 64-bit build */ typedef int64_t jlong; /* signed 64 bits */ // typedef long jlong; #else typedef long long jlong; #endif typedef float jfloat; /* 32-bit IEEE 754 */ typedef double jdouble; /* 64-bit IEEE 754 */ /* "cardinal indices and sizes" */ typedef jint jsize; #ifndef __has_attribute #define __has_attribute(x) 0 #endif #if defined(_WIN32) #define JNIEXPORT __declspec(dllexport) #define JNIIMPORT __declspec(dllimport) #define JNICALL __stdcall #elif (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility) #define JNIEXPORT __attribute__((visibility("default"))) #define JNIIMPORT __attribute__((visibility("default"))) #define JNICALL #else #define JNICALL #define JNIEXPORT #define JNIIMPORT #endif #ifdef __cplusplus /* * Reference types, in C++ */ class _jobject {}; class _jclass : public _jobject {}; class _jstring : public _jobject {}; class _jarray : public _jobject {}; class _jobjectArray : public _jarray {}; class _jbooleanArray : public _jarray {}; class _jbyteArray : public _jarray {}; class _jcharArray : public _jarray {}; class _jshortArray : public _jarray {}; class _jintArray : public _jarray {}; class _jlongArray : public _jarray {}; class _jfloatArray : public _jarray {}; class _jdoubleArray : public _jarray {}; class _jthrowable : public _jobject {}; typedef _jobject* jobject; typedef _jclass* jclass; typedef _jstring* jstring; typedef _jarray* jarray; typedef _jobjectArray* jobjectArray; typedef _jbooleanArray* jbooleanArray; typedef _jbyteArray* jbyteArray; typedef _jcharArray* jcharArray; typedef _jshortArray* jshortArray; typedef _jintArray* jintArray; typedef _jlongArray* jlongArray; typedef _jfloatArray* jfloatArray; typedef _jdoubleArray* jdoubleArray; typedef _jthrowable* jthrowable; typedef _jobject* jweak; #else /* not __cplusplus */ /* * Reference types, in C. */ typedef void* jobject; typedef jobject jclass; typedef jobject jstring; typedef jobject jarray; typedef jarray jobjectArray; typedef jarray jbooleanArray; typedef jarray jbyteArray; typedef jarray jcharArray; typedef jarray jshortArray; typedef jarray jintArray; typedef jarray jlongArray; typedef jarray jfloatArray; typedef jarray jdoubleArray; typedef jobject jthrowable; typedef jobject jweak; #endif /* not __cplusplus */ struct _jfieldID; /* opaque structure */ typedef struct _jfieldID* jfieldID; /* field IDs */ struct _jmethodID; /* opaque structure */ typedef struct _jmethodID* jmethodID; /* method IDs */ struct JNIInvokeInterface; typedef union jvalue { jboolean z; jbyte b; jchar c; jshort s; jint i; jlong j; jfloat f; jdouble d; jobject l; } jvalue; typedef enum jobjectRefType { JNIInvalidRefType = 0, JNILocalRefType = 1, JNIGlobalRefType = 2, JNIWeakGlobalRefType = 3 } jobjectRefType; typedef struct { const char* name; const char* signature; void* fnPtr; } JNINativeMethod; struct _JNIEnv; struct _JavaVM; typedef const struct JNINativeInterface* C_JNIEnv; #if defined(__cplusplus) typedef _JNIEnv JNIEnv; typedef _JavaVM JavaVM; #else typedef const struct JNINativeInterface* JNIEnv; typedef const struct JNIInvokeInterface* JavaVM; #endif /* * Table of interface function pointers. */ struct JNINativeInterface { void* reserved0; void* reserved1; void* reserved2; void* reserved3; jint (*GetVersion)(JNIEnv *); jclass (*DefineClass)(JNIEnv*, const char*, jobject, const jbyte*, jsize); jclass (*FindClass)(JNIEnv*, const char*); jmethodID (*FromReflectedMethod)(JNIEnv*, jobject); jfieldID (*FromReflectedField)(JNIEnv*, jobject); /* spec doesn't show jboolean parameter */ jobject (*ToReflectedMethod)(JNIEnv*, jclass, jmethodID, jboolean); jclass (*GetSuperclass)(JNIEnv*, jclass); jboolean (*IsAssignableFrom)(JNIEnv*, jclass, jclass); /* spec doesn't show jboolean parameter */ jobject (*ToReflectedField)(JNIEnv*, jclass, jfieldID, jboolean); jint (*Throw)(JNIEnv*, jthrowable); jint (*ThrowNew)(JNIEnv *, jclass, const char *); jthrowable (*ExceptionOccurred)(JNIEnv*); void (*ExceptionDescribe)(JNIEnv*); void (*ExceptionClear)(JNIEnv*); void (*FatalError)(JNIEnv*, const char*); jint (*PushLocalFrame)(JNIEnv*, jint); jobject (*PopLocalFrame)(JNIEnv*, jobject); jobject (*NewGlobalRef)(JNIEnv*, jobject); void (*DeleteGlobalRef)(JNIEnv*, jobject); void (*DeleteLocalRef)(JNIEnv*, jobject); jboolean (*IsSameObject)(JNIEnv*, jobject, jobject); jobject (*NewLocalRef)(JNIEnv*, jobject); jint (*EnsureLocalCapacity)(JNIEnv*, jint); jobject (*AllocObject)(JNIEnv*, jclass); jobject (*NewObject)(JNIEnv*, jclass, jmethodID, ...); jobject (*NewObjectV)(JNIEnv*, jclass, jmethodID, va_list); jobject (*NewObjectA)(JNIEnv*, jclass, jmethodID, jvalue*); jclass (*GetObjectClass)(JNIEnv*, jobject); jboolean (*IsInstanceOf)(JNIEnv*, jobject, jclass); jmethodID (*GetMethodID)(JNIEnv*, jclass, const char*, const char*); jobject (*CallObjectMethod)(JNIEnv*, jobject, jmethodID, ...); jobject (*CallObjectMethodV)(JNIEnv*, jobject, jmethodID, va_list); jobject (*CallObjectMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jboolean (*CallBooleanMethod)(JNIEnv*, jobject, jmethodID, ...); jboolean (*CallBooleanMethodV)(JNIEnv*, jobject, jmethodID, va_list); jboolean (*CallBooleanMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jbyte (*CallByteMethod)(JNIEnv*, jobject, jmethodID, ...); jbyte (*CallByteMethodV)(JNIEnv*, jobject, jmethodID, va_list); jbyte (*CallByteMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jchar (*CallCharMethod)(JNIEnv*, jobject, jmethodID, ...); jchar (*CallCharMethodV)(JNIEnv*, jobject, jmethodID, va_list); jchar (*CallCharMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jshort (*CallShortMethod)(JNIEnv*, jobject, jmethodID, ...); jshort (*CallShortMethodV)(JNIEnv*, jobject, jmethodID, va_list); jshort (*CallShortMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jint (*CallIntMethod)(JNIEnv*, jobject, jmethodID, ...); jint (*CallIntMethodV)(JNIEnv*, jobject, jmethodID, va_list); jint (*CallIntMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jlong (*CallLongMethod)(JNIEnv*, jobject, jmethodID, ...); jlong (*CallLongMethodV)(JNIEnv*, jobject, jmethodID, va_list); jlong (*CallLongMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jfloat (*CallFloatMethod)(JNIEnv*, jobject, jmethodID, ...); jfloat (*CallFloatMethodV)(JNIEnv*, jobject, jmethodID, va_list); jfloat (*CallFloatMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jdouble (*CallDoubleMethod)(JNIEnv*, jobject, jmethodID, ...); jdouble (*CallDoubleMethodV)(JNIEnv*, jobject, jmethodID, va_list); jdouble (*CallDoubleMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); void (*CallVoidMethod)(JNIEnv*, jobject, jmethodID, ...); void (*CallVoidMethodV)(JNIEnv*, jobject, jmethodID, va_list); void (*CallVoidMethodA)(JNIEnv*, jobject, jmethodID, jvalue*); jobject (*CallNonvirtualObjectMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jobject (*CallNonvirtualObjectMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jobject (*CallNonvirtualObjectMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jboolean (*CallNonvirtualBooleanMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jboolean (*CallNonvirtualBooleanMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jboolean (*CallNonvirtualBooleanMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jbyte (*CallNonvirtualByteMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jbyte (*CallNonvirtualByteMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jbyte (*CallNonvirtualByteMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jchar (*CallNonvirtualCharMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jchar (*CallNonvirtualCharMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jchar (*CallNonvirtualCharMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jshort (*CallNonvirtualShortMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jshort (*CallNonvirtualShortMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jshort (*CallNonvirtualShortMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jint (*CallNonvirtualIntMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jint (*CallNonvirtualIntMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jint (*CallNonvirtualIntMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jlong (*CallNonvirtualLongMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jlong (*CallNonvirtualLongMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jlong (*CallNonvirtualLongMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jfloat (*CallNonvirtualFloatMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jfloat (*CallNonvirtualFloatMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jfloat (*CallNonvirtualFloatMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jdouble (*CallNonvirtualDoubleMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); jdouble (*CallNonvirtualDoubleMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); jdouble (*CallNonvirtualDoubleMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); void (*CallNonvirtualVoidMethod)(JNIEnv*, jobject, jclass, jmethodID, ...); void (*CallNonvirtualVoidMethodV)(JNIEnv*, jobject, jclass, jmethodID, va_list); void (*CallNonvirtualVoidMethodA)(JNIEnv*, jobject, jclass, jmethodID, jvalue*); jfieldID (*GetFieldID)(JNIEnv*, jclass, const char*, const char*); jobject (*GetObjectField)(JNIEnv*, jobject, jfieldID); jboolean (*GetBooleanField)(JNIEnv*, jobject, jfieldID); jbyte (*GetByteField)(JNIEnv*, jobject, jfieldID); jchar (*GetCharField)(JNIEnv*, jobject, jfieldID); jshort (*GetShortField)(JNIEnv*, jobject, jfieldID); jint (*GetIntField)(JNIEnv*, jobject, jfieldID); jlong (*GetLongField)(JNIEnv*, jobject, jfieldID); jfloat (*GetFloatField)(JNIEnv*, jobject, jfieldID); jdouble (*GetDoubleField)(JNIEnv*, jobject, jfieldID); void (*SetObjectField)(JNIEnv*, jobject, jfieldID, jobject); void (*SetBooleanField)(JNIEnv*, jobject, jfieldID, jboolean); void (*SetByteField)(JNIEnv*, jobject, jfieldID, jbyte); void (*SetCharField)(JNIEnv*, jobject, jfieldID, jchar); void (*SetShortField)(JNIEnv*, jobject, jfieldID, jshort); void (*SetIntField)(JNIEnv*, jobject, jfieldID, jint); void (*SetLongField)(JNIEnv*, jobject, jfieldID, jlong); void (*SetFloatField)(JNIEnv*, jobject, jfieldID, jfloat); void (*SetDoubleField)(JNIEnv*, jobject, jfieldID, jdouble); jmethodID (*GetStaticMethodID)(JNIEnv*, jclass, const char*, const char*); jobject (*CallStaticObjectMethod)(JNIEnv*, jclass, jmethodID, ...); jobject (*CallStaticObjectMethodV)(JNIEnv*, jclass, jmethodID, va_list); jobject (*CallStaticObjectMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jboolean (*CallStaticBooleanMethod)(JNIEnv*, jclass, jmethodID, ...); jboolean (*CallStaticBooleanMethodV)(JNIEnv*, jclass, jmethodID, va_list); jboolean (*CallStaticBooleanMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jbyte (*CallStaticByteMethod)(JNIEnv*, jclass, jmethodID, ...); jbyte (*CallStaticByteMethodV)(JNIEnv*, jclass, jmethodID, va_list); jbyte (*CallStaticByteMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jchar (*CallStaticCharMethod)(JNIEnv*, jclass, jmethodID, ...); jchar (*CallStaticCharMethodV)(JNIEnv*, jclass, jmethodID, va_list); jchar (*CallStaticCharMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jshort (*CallStaticShortMethod)(JNIEnv*, jclass, jmethodID, ...); jshort (*CallStaticShortMethodV)(JNIEnv*, jclass, jmethodID, va_list); jshort (*CallStaticShortMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jint (*CallStaticIntMethod)(JNIEnv*, jclass, jmethodID, ...); jint (*CallStaticIntMethodV)(JNIEnv*, jclass, jmethodID, va_list); jint (*CallStaticIntMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jlong (*CallStaticLongMethod)(JNIEnv*, jclass, jmethodID, ...); jlong (*CallStaticLongMethodV)(JNIEnv*, jclass, jmethodID, va_list); jlong (*CallStaticLongMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jfloat (*CallStaticFloatMethod)(JNIEnv*, jclass, jmethodID, ...); jfloat (*CallStaticFloatMethodV)(JNIEnv*, jclass, jmethodID, va_list); jfloat (*CallStaticFloatMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jdouble (*CallStaticDoubleMethod)(JNIEnv*, jclass, jmethodID, ...); jdouble (*CallStaticDoubleMethodV)(JNIEnv*, jclass, jmethodID, va_list); jdouble (*CallStaticDoubleMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); void (*CallStaticVoidMethod)(JNIEnv*, jclass, jmethodID, ...); void (*CallStaticVoidMethodV)(JNIEnv*, jclass, jmethodID, va_list); void (*CallStaticVoidMethodA)(JNIEnv*, jclass, jmethodID, jvalue*); jfieldID (*GetStaticFieldID)(JNIEnv*, jclass, const char*, const char*); jobject (*GetStaticObjectField)(JNIEnv*, jclass, jfieldID); jboolean (*GetStaticBooleanField)(JNIEnv*, jclass, jfieldID); jbyte (*GetStaticByteField)(JNIEnv*, jclass, jfieldID); jchar (*GetStaticCharField)(JNIEnv*, jclass, jfieldID); jshort (*GetStaticShortField)(JNIEnv*, jclass, jfieldID); jint (*GetStaticIntField)(JNIEnv*, jclass, jfieldID); jlong (*GetStaticLongField)(JNIEnv*, jclass, jfieldID); jfloat (*GetStaticFloatField)(JNIEnv*, jclass, jfieldID); jdouble (*GetStaticDoubleField)(JNIEnv*, jclass, jfieldID); void (*SetStaticObjectField)(JNIEnv*, jclass, jfieldID, jobject); void (*SetStaticBooleanField)(JNIEnv*, jclass, jfieldID, jboolean); void (*SetStaticByteField)(JNIEnv*, jclass, jfieldID, jbyte); void (*SetStaticCharField)(JNIEnv*, jclass, jfieldID, jchar); void (*SetStaticShortField)(JNIEnv*, jclass, jfieldID, jshort); void (*SetStaticIntField)(JNIEnv*, jclass, jfieldID, jint); void (*SetStaticLongField)(JNIEnv*, jclass, jfieldID, jlong); void (*SetStaticFloatField)(JNIEnv*, jclass, jfieldID, jfloat); void (*SetStaticDoubleField)(JNIEnv*, jclass, jfieldID, jdouble); jstring (*NewString)(JNIEnv*, const jchar*, jsize); jsize (*GetStringLength)(JNIEnv*, jstring); const jchar* (*GetStringChars)(JNIEnv*, jstring, jboolean*); void (*ReleaseStringChars)(JNIEnv*, jstring, const jchar*); jstring (*NewStringUTF)(JNIEnv*, const char*); jsize (*GetStringUTFLength)(JNIEnv*, jstring); /* JNI spec says this returns const jbyte*, but that's inconsistent */ const char* (*GetStringUTFChars)(JNIEnv*, jstring, jboolean*); void (*ReleaseStringUTFChars)(JNIEnv*, jstring, const char*); jsize (*GetArrayLength)(JNIEnv*, jarray); jobjectArray (*NewObjectArray)(JNIEnv*, jsize, jclass, jobject); jobject (*GetObjectArrayElement)(JNIEnv*, jobjectArray, jsize); void (*SetObjectArrayElement)(JNIEnv*, jobjectArray, jsize, jobject); jbooleanArray (*NewBooleanArray)(JNIEnv*, jsize); jbyteArray (*NewByteArray)(JNIEnv*, jsize); jcharArray (*NewCharArray)(JNIEnv*, jsize); jshortArray (*NewShortArray)(JNIEnv*, jsize); jintArray (*NewIntArray)(JNIEnv*, jsize); jlongArray (*NewLongArray)(JNIEnv*, jsize); jfloatArray (*NewFloatArray)(JNIEnv*, jsize); jdoubleArray (*NewDoubleArray)(JNIEnv*, jsize); jboolean* (*GetBooleanArrayElements)(JNIEnv*, jbooleanArray, jboolean*); jbyte* (*GetByteArrayElements)(JNIEnv*, jbyteArray, jboolean*); jchar* (*GetCharArrayElements)(JNIEnv*, jcharArray, jboolean*); jshort* (*GetShortArrayElements)(JNIEnv*, jshortArray, jboolean*); jint* (*GetIntArrayElements)(JNIEnv*, jintArray, jboolean*); jlong* (*GetLongArrayElements)(JNIEnv*, jlongArray, jboolean*); jfloat* (*GetFloatArrayElements)(JNIEnv*, jfloatArray, jboolean*); jdouble* (*GetDoubleArrayElements)(JNIEnv*, jdoubleArray, jboolean*); void (*ReleaseBooleanArrayElements)(JNIEnv*, jbooleanArray, jboolean*, jint); void (*ReleaseByteArrayElements)(JNIEnv*, jbyteArray, jbyte*, jint); void (*ReleaseCharArrayElements)(JNIEnv*, jcharArray, jchar*, jint); void (*ReleaseShortArrayElements)(JNIEnv*, jshortArray, jshort*, jint); void (*ReleaseIntArrayElements)(JNIEnv*, jintArray, jint*, jint); void (*ReleaseLongArrayElements)(JNIEnv*, jlongArray, jlong*, jint); void (*ReleaseFloatArrayElements)(JNIEnv*, jfloatArray, jfloat*, jint); void (*ReleaseDoubleArrayElements)(JNIEnv*, jdoubleArray, jdouble*, jint); void (*GetBooleanArrayRegion)(JNIEnv*, jbooleanArray, jsize, jsize, jboolean*); void (*GetByteArrayRegion)(JNIEnv*, jbyteArray, jsize, jsize, jbyte*); void (*GetCharArrayRegion)(JNIEnv*, jcharArray, jsize, jsize, jchar*); void (*GetShortArrayRegion)(JNIEnv*, jshortArray, jsize, jsize, jshort*); void (*GetIntArrayRegion)(JNIEnv*, jintArray, jsize, jsize, jint*); void (*GetLongArrayRegion)(JNIEnv*, jlongArray, jsize, jsize, jlong*); void (*GetFloatArrayRegion)(JNIEnv*, jfloatArray, jsize, jsize, jfloat*); void (*GetDoubleArrayRegion)(JNIEnv*, jdoubleArray, jsize, jsize, jdouble*); /* spec shows these without const; some jni.h do, some don't */ void (*SetBooleanArrayRegion)(JNIEnv*, jbooleanArray, jsize, jsize, const jboolean*); void (*SetByteArrayRegion)(JNIEnv*, jbyteArray, jsize, jsize, const jbyte*); void (*SetCharArrayRegion)(JNIEnv*, jcharArray, jsize, jsize, const jchar*); void (*SetShortArrayRegion)(JNIEnv*, jshortArray, jsize, jsize, const jshort*); void (*SetIntArrayRegion)(JNIEnv*, jintArray, jsize, jsize, const jint*); void (*SetLongArrayRegion)(JNIEnv*, jlongArray, jsize, jsize, const jlong*); void (*SetFloatArrayRegion)(JNIEnv*, jfloatArray, jsize, jsize, const jfloat*); void (*SetDoubleArrayRegion)(JNIEnv*, jdoubleArray, jsize, jsize, const jdouble*); jint (*RegisterNatives)(JNIEnv*, jclass, const JNINativeMethod*, jint); jint (*UnregisterNatives)(JNIEnv*, jclass); jint (*MonitorEnter)(JNIEnv*, jobject); jint (*MonitorExit)(JNIEnv*, jobject); jint (*GetJavaVM)(JNIEnv*, JavaVM**); void (*GetStringRegion)(JNIEnv*, jstring, jsize, jsize, jchar*); void (*GetStringUTFRegion)(JNIEnv*, jstring, jsize, jsize, char*); void* (*GetPrimitiveArrayCritical)(JNIEnv*, jarray, jboolean*); void (*ReleasePrimitiveArrayCritical)(JNIEnv*, jarray, void*, jint); const jchar* (*GetStringCritical)(JNIEnv*, jstring, jboolean*); void (*ReleaseStringCritical)(JNIEnv*, jstring, const jchar*); jweak (*NewWeakGlobalRef)(JNIEnv*, jobject); void (*DeleteWeakGlobalRef)(JNIEnv*, jweak); jboolean (*ExceptionCheck)(JNIEnv*); jobject (*NewDirectByteBuffer)(JNIEnv*, void*, jlong); void* (*GetDirectBufferAddress)(JNIEnv*, jobject); jlong (*GetDirectBufferCapacity)(JNIEnv*, jobject); /* added in JNI 1.6 */ jobjectRefType (*GetObjectRefType)(JNIEnv*, jobject); }; /* * C++ object wrapper. * * This is usually overlaid on a C struct whose first element is a * JNINativeInterface*. We rely somewhat on compiler behavior. */ struct _JNIEnv { /* do not rename this; it does not seem to be entirely opaque */ const struct JNINativeInterface* functions; #if defined(__cplusplus) jint GetVersion() { return functions->GetVersion(this); } jclass DefineClass(const char *name, jobject loader, const jbyte* buf, jsize bufLen) { return functions->DefineClass(this, name, loader, buf, bufLen); } jclass FindClass(const char* name) { return functions->FindClass(this, name); } jmethodID FromReflectedMethod(jobject method) { return functions->FromReflectedMethod(this, method); } jfieldID FromReflectedField(jobject field) { return functions->FromReflectedField(this, field); } jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) { return functions->ToReflectedMethod(this, cls, methodID, isStatic); } jclass GetSuperclass(jclass clazz) { return functions->GetSuperclass(this, clazz); } jboolean IsAssignableFrom(jclass clazz1, jclass clazz2) { return functions->IsAssignableFrom(this, clazz1, clazz2); } jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) { return functions->ToReflectedField(this, cls, fieldID, isStatic); } jint Throw(jthrowable obj) { return functions->Throw(this, obj); } jint ThrowNew(jclass clazz, const char* message) { return functions->ThrowNew(this, clazz, message); } jthrowable ExceptionOccurred() { return functions->ExceptionOccurred(this); } void ExceptionDescribe() { functions->ExceptionDescribe(this); } void ExceptionClear() { functions->ExceptionClear(this); } void FatalError(const char* msg) { functions->FatalError(this, msg); } jint PushLocalFrame(jint capacity) { return functions->PushLocalFrame(this, capacity); } jobject PopLocalFrame(jobject result) { return functions->PopLocalFrame(this, result); } jobject NewGlobalRef(jobject obj) { return functions->NewGlobalRef(this, obj); } void DeleteGlobalRef(jobject globalRef) { functions->DeleteGlobalRef(this, globalRef); } void DeleteLocalRef(jobject localRef) { functions->DeleteLocalRef(this, localRef); } jboolean IsSameObject(jobject ref1, jobject ref2) { return functions->IsSameObject(this, ref1, ref2); } jobject NewLocalRef(jobject ref) { return functions->NewLocalRef(this, ref); } jint EnsureLocalCapacity(jint capacity) { return functions->EnsureLocalCapacity(this, capacity); } jobject AllocObject(jclass clazz) { return functions->AllocObject(this, clazz); } jobject NewObject(jclass clazz, jmethodID methodID, ...) { va_list args; va_start(args, methodID); jobject result = functions->NewObjectV(this, clazz, methodID, args); va_end(args); return result; } jobject NewObjectV(jclass clazz, jmethodID methodID, va_list args) { return functions->NewObjectV(this, clazz, methodID, args); } jobject NewObjectA(jclass clazz, jmethodID methodID, jvalue* args) { return functions->NewObjectA(this, clazz, methodID, args); } jclass GetObjectClass(jobject obj) { return functions->GetObjectClass(this, obj); } jboolean IsInstanceOf(jobject obj, jclass clazz) { return functions->IsInstanceOf(this, obj, clazz); } jmethodID GetMethodID(jclass clazz, const char* name, const char* sig) { return functions->GetMethodID(this, clazz, name, sig); } #define CALL_TYPE_METHOD(_jtype, _jname) \ _jtype Call##_jname##Method(jobject obj, jmethodID methodID, ...) \ { \ _jtype result; \ va_list args; \ va_start(args, methodID); \ result = functions->Call##_jname##MethodV(this, obj, methodID, \ args); \ va_end(args); \ return result; \ } #define CALL_TYPE_METHODV(_jtype, _jname) \ _jtype Call##_jname##MethodV(jobject obj, jmethodID methodID, \ va_list args) \ { return functions->Call##_jname##MethodV(this, obj, methodID, args); } #define CALL_TYPE_METHODA(_jtype, _jname) \ _jtype Call##_jname##MethodA(jobject obj, jmethodID methodID, \ jvalue* args) \ { return functions->Call##_jname##MethodA(this, obj, methodID, args); } #define CALL_TYPE(_jtype, _jname) \ CALL_TYPE_METHOD(_jtype, _jname) \ CALL_TYPE_METHODV(_jtype, _jname) \ CALL_TYPE_METHODA(_jtype, _jname) CALL_TYPE(jobject, Object) CALL_TYPE(jboolean, Boolean) CALL_TYPE(jbyte, Byte) CALL_TYPE(jchar, Char) CALL_TYPE(jshort, Short) CALL_TYPE(jint, Int) CALL_TYPE(jlong, Long) CALL_TYPE(jfloat, Float) CALL_TYPE(jdouble, Double) void CallVoidMethod(jobject obj, jmethodID methodID, ...) { va_list args; va_start(args, methodID); functions->CallVoidMethodV(this, obj, methodID, args); va_end(args); } void CallVoidMethodV(jobject obj, jmethodID methodID, va_list args) { functions->CallVoidMethodV(this, obj, methodID, args); } void CallVoidMethodA(jobject obj, jmethodID methodID, jvalue* args) { functions->CallVoidMethodA(this, obj, methodID, args); } #define CALL_NONVIRT_TYPE_METHOD(_jtype, _jname) \ _jtype CallNonvirtual##_jname##Method(jobject obj, jclass clazz, \ jmethodID methodID, ...) \ { \ _jtype result; \ va_list args; \ va_start(args, methodID); \ result = functions->CallNonvirtual##_jname##MethodV(this, obj, \ clazz, methodID, args); \ va_end(args); \ return result; \ } #define CALL_NONVIRT_TYPE_METHODV(_jtype, _jname) \ _jtype CallNonvirtual##_jname##MethodV(jobject obj, jclass clazz, \ jmethodID methodID, va_list args) \ { return functions->CallNonvirtual##_jname##MethodV(this, obj, clazz, \ methodID, args); } #define CALL_NONVIRT_TYPE_METHODA(_jtype, _jname) \ _jtype CallNonvirtual##_jname##MethodA(jobject obj, jclass clazz, \ jmethodID methodID, jvalue* args) \ { return functions->CallNonvirtual##_jname##MethodA(this, obj, clazz, \ methodID, args); } #define CALL_NONVIRT_TYPE(_jtype, _jname) \ CALL_NONVIRT_TYPE_METHOD(_jtype, _jname) \ CALL_NONVIRT_TYPE_METHODV(_jtype, _jname) \ CALL_NONVIRT_TYPE_METHODA(_jtype, _jname) CALL_NONVIRT_TYPE(jobject, Object) CALL_NONVIRT_TYPE(jboolean, Boolean) CALL_NONVIRT_TYPE(jbyte, Byte) CALL_NONVIRT_TYPE(jchar, Char) CALL_NONVIRT_TYPE(jshort, Short) CALL_NONVIRT_TYPE(jint, Int) CALL_NONVIRT_TYPE(jlong, Long) CALL_NONVIRT_TYPE(jfloat, Float) CALL_NONVIRT_TYPE(jdouble, Double) void CallNonvirtualVoidMethod(jobject obj, jclass clazz, jmethodID methodID, ...) { va_list args; va_start(args, methodID); functions->CallNonvirtualVoidMethodV(this, obj, clazz, methodID, args); va_end(args); } void CallNonvirtualVoidMethodV(jobject obj, jclass clazz, jmethodID methodID, va_list args) { functions->CallNonvirtualVoidMethodV(this, obj, clazz, methodID, args); } void CallNonvirtualVoidMethodA(jobject obj, jclass clazz, jmethodID methodID, jvalue* args) { functions->CallNonvirtualVoidMethodA(this, obj, clazz, methodID, args); } jfieldID GetFieldID(jclass clazz, const char* name, const char* sig) { return functions->GetFieldID(this, clazz, name, sig); } jobject GetObjectField(jobject obj, jfieldID fieldID) { return functions->GetObjectField(this, obj, fieldID); } jboolean GetBooleanField(jobject obj, jfieldID fieldID) { return functions->GetBooleanField(this, obj, fieldID); } jbyte GetByteField(jobject obj, jfieldID fieldID) { return functions->GetByteField(this, obj, fieldID); } jchar GetCharField(jobject obj, jfieldID fieldID) { return functions->GetCharField(this, obj, fieldID); } jshort GetShortField(jobject obj, jfieldID fieldID) { return functions->GetShortField(this, obj, fieldID); } jint GetIntField(jobject obj, jfieldID fieldID) { return functions->GetIntField(this, obj, fieldID); } jlong GetLongField(jobject obj, jfieldID fieldID) { return functions->GetLongField(this, obj, fieldID); } jfloat GetFloatField(jobject obj, jfieldID fieldID) { return functions->GetFloatField(this, obj, fieldID); } jdouble GetDoubleField(jobject obj, jfieldID fieldID) { return functions->GetDoubleField(this, obj, fieldID); } void SetObjectField(jobject obj, jfieldID fieldID, jobject value) { functions->SetObjectField(this, obj, fieldID, value); } void SetBooleanField(jobject obj, jfieldID fieldID, jboolean value) { functions->SetBooleanField(this, obj, fieldID, value); } void SetByteField(jobject obj, jfieldID fieldID, jbyte value) { functions->SetByteField(this, obj, fieldID, value); } void SetCharField(jobject obj, jfieldID fieldID, jchar value) { functions->SetCharField(this, obj, fieldID, value); } void SetShortField(jobject obj, jfieldID fieldID, jshort value) { functions->SetShortField(this, obj, fieldID, value); } void SetIntField(jobject obj, jfieldID fieldID, jint value) { functions->SetIntField(this, obj, fieldID, value); } void SetLongField(jobject obj, jfieldID fieldID, jlong value) { functions->SetLongField(this, obj, fieldID, value); } void SetFloatField(jobject obj, jfieldID fieldID, jfloat value) { functions->SetFloatField(this, obj, fieldID, value); } void SetDoubleField(jobject obj, jfieldID fieldID, jdouble value) { functions->SetDoubleField(this, obj, fieldID, value); } jmethodID GetStaticMethodID(jclass clazz, const char* name, const char* sig) { return functions->GetStaticMethodID(this, clazz, name, sig); } #define CALL_STATIC_TYPE_METHOD(_jtype, _jname) \ _jtype CallStatic##_jname##Method(jclass clazz, jmethodID methodID, \ ...) \ { \ _jtype result; \ va_list args; \ va_start(args, methodID); \ result = functions->CallStatic##_jname##MethodV(this, clazz, \ methodID, args); \ va_end(args); \ return result; \ } #define CALL_STATIC_TYPE_METHODV(_jtype, _jname) \ _jtype CallStatic##_jname##MethodV(jclass clazz, jmethodID methodID, \ va_list args) \ { return functions->CallStatic##_jname##MethodV(this, clazz, methodID, \ args); } #define CALL_STATIC_TYPE_METHODA(_jtype, _jname) \ _jtype CallStatic##_jname##MethodA(jclass clazz, jmethodID methodID, \ jvalue* args) \ { return functions->CallStatic##_jname##MethodA(this, clazz, methodID, \ args); } #define CALL_STATIC_TYPE(_jtype, _jname) \ CALL_STATIC_TYPE_METHOD(_jtype, _jname) \ CALL_STATIC_TYPE_METHODV(_jtype, _jname) \ CALL_STATIC_TYPE_METHODA(_jtype, _jname) CALL_STATIC_TYPE(jobject, Object) CALL_STATIC_TYPE(jboolean, Boolean) CALL_STATIC_TYPE(jbyte, Byte) CALL_STATIC_TYPE(jchar, Char) CALL_STATIC_TYPE(jshort, Short) CALL_STATIC_TYPE(jint, Int) CALL_STATIC_TYPE(jlong, Long) CALL_STATIC_TYPE(jfloat, Float) CALL_STATIC_TYPE(jdouble, Double) void CallStaticVoidMethod(jclass clazz, jmethodID methodID, ...) { va_list args; va_start(args, methodID); functions->CallStaticVoidMethodV(this, clazz, methodID, args); va_end(args); } void CallStaticVoidMethodV(jclass clazz, jmethodID methodID, va_list args) { functions->CallStaticVoidMethodV(this, clazz, methodID, args); } void CallStaticVoidMethodA(jclass clazz, jmethodID methodID, jvalue* args) { functions->CallStaticVoidMethodA(this, clazz, methodID, args); } jfieldID GetStaticFieldID(jclass clazz, const char* name, const char* sig) { return functions->GetStaticFieldID(this, clazz, name, sig); } jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) { return functions->GetStaticObjectField(this, clazz, fieldID); } jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) { return functions->GetStaticBooleanField(this, clazz, fieldID); } jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) { return functions->GetStaticByteField(this, clazz, fieldID); } jchar GetStaticCharField(jclass clazz, jfieldID fieldID) { return functions->GetStaticCharField(this, clazz, fieldID); } jshort GetStaticShortField(jclass clazz, jfieldID fieldID) { return functions->GetStaticShortField(this, clazz, fieldID); } jint GetStaticIntField(jclass clazz, jfieldID fieldID) { return functions->GetStaticIntField(this, clazz, fieldID); } jlong GetStaticLongField(jclass clazz, jfieldID fieldID) { return functions->GetStaticLongField(this, clazz, fieldID); } jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) { return functions->GetStaticFloatField(this, clazz, fieldID); } jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) { return functions->GetStaticDoubleField(this, clazz, fieldID); } void SetStaticObjectField(jclass clazz, jfieldID fieldID, jobject value) { functions->SetStaticObjectField(this, clazz, fieldID, value); } void SetStaticBooleanField(jclass clazz, jfieldID fieldID, jboolean value) { functions->SetStaticBooleanField(this, clazz, fieldID, value); } void SetStaticByteField(jclass clazz, jfieldID fieldID, jbyte value) { functions->SetStaticByteField(this, clazz, fieldID, value); } void SetStaticCharField(jclass clazz, jfieldID fieldID, jchar value) { functions->SetStaticCharField(this, clazz, fieldID, value); } void SetStaticShortField(jclass clazz, jfieldID fieldID, jshort value) { functions->SetStaticShortField(this, clazz, fieldID, value); } void SetStaticIntField(jclass clazz, jfieldID fieldID, jint value) { functions->SetStaticIntField(this, clazz, fieldID, value); } void SetStaticLongField(jclass clazz, jfieldID fieldID, jlong value) { functions->SetStaticLongField(this, clazz, fieldID, value); } void SetStaticFloatField(jclass clazz, jfieldID fieldID, jfloat value) { functions->SetStaticFloatField(this, clazz, fieldID, value); } void SetStaticDoubleField(jclass clazz, jfieldID fieldID, jdouble value) { functions->SetStaticDoubleField(this, clazz, fieldID, value); } jstring NewString(const jchar* unicodeChars, jsize len) { return functions->NewString(this, unicodeChars, len); } jsize GetStringLength(jstring string) { return functions->GetStringLength(this, string); } const jchar* GetStringChars(jstring string, jboolean* isCopy) { return functions->GetStringChars(this, string, isCopy); } void ReleaseStringChars(jstring string, const jchar* chars) { functions->ReleaseStringChars(this, string, chars); } jstring NewStringUTF(const char* bytes) { return functions->NewStringUTF(this, bytes); } jsize GetStringUTFLength(jstring string) { return functions->GetStringUTFLength(this, string); } const char* GetStringUTFChars(jstring string, jboolean* isCopy) { return functions->GetStringUTFChars(this, string, isCopy); } void ReleaseStringUTFChars(jstring string, const char* utf) { functions->ReleaseStringUTFChars(this, string, utf); } jsize GetArrayLength(jarray array) { return functions->GetArrayLength(this, array); } jobjectArray NewObjectArray(jsize length, jclass elementClass, jobject initialElement) { return functions->NewObjectArray(this, length, elementClass, initialElement); } jobject GetObjectArrayElement(jobjectArray array, jsize index) { return functions->GetObjectArrayElement(this, array, index); } void SetObjectArrayElement(jobjectArray array, jsize index, jobject value) { functions->SetObjectArrayElement(this, array, index, value); } jbooleanArray NewBooleanArray(jsize length) { return functions->NewBooleanArray(this, length); } jbyteArray NewByteArray(jsize length) { return functions->NewByteArray(this, length); } jcharArray NewCharArray(jsize length) { return functions->NewCharArray(this, length); } jshortArray NewShortArray(jsize length) { return functions->NewShortArray(this, length); } jintArray NewIntArray(jsize length) { return functions->NewIntArray(this, length); } jlongArray NewLongArray(jsize length) { return functions->NewLongArray(this, length); } jfloatArray NewFloatArray(jsize length) { return functions->NewFloatArray(this, length); } jdoubleArray NewDoubleArray(jsize length) { return functions->NewDoubleArray(this, length); } jboolean* GetBooleanArrayElements(jbooleanArray array, jboolean* isCopy) { return functions->GetBooleanArrayElements(this, array, isCopy); } jbyte* GetByteArrayElements(jbyteArray array, jboolean* isCopy) { return functions->GetByteArrayElements(this, array, isCopy); } jchar* GetCharArrayElements(jcharArray array, jboolean* isCopy) { return functions->GetCharArrayElements(this, array, isCopy); } jshort* GetShortArrayElements(jshortArray array, jboolean* isCopy) { return functions->GetShortArrayElements(this, array, isCopy); } jint* GetIntArrayElements(jintArray array, jboolean* isCopy) { return functions->GetIntArrayElements(this, array, isCopy); } jlong* GetLongArrayElements(jlongArray array, jboolean* isCopy) { return functions->GetLongArrayElements(this, array, isCopy); } jfloat* GetFloatArrayElements(jfloatArray array, jboolean* isCopy) { return functions->GetFloatArrayElements(this, array, isCopy); } jdouble* GetDoubleArrayElements(jdoubleArray array, jboolean* isCopy) { return functions->GetDoubleArrayElements(this, array, isCopy); } void ReleaseBooleanArrayElements(jbooleanArray array, jboolean* elems, jint mode) { functions->ReleaseBooleanArrayElements(this, array, elems, mode); } void ReleaseByteArrayElements(jbyteArray array, jbyte* elems, jint mode) { functions->ReleaseByteArrayElements(this, array, elems, mode); } void ReleaseCharArrayElements(jcharArray array, jchar* elems, jint mode) { functions->ReleaseCharArrayElements(this, array, elems, mode); } void ReleaseShortArrayElements(jshortArray array, jshort* elems, jint mode) { functions->ReleaseShortArrayElements(this, array, elems, mode); } void ReleaseIntArrayElements(jintArray array, jint* elems, jint mode) { functions->ReleaseIntArrayElements(this, array, elems, mode); } void ReleaseLongArrayElements(jlongArray array, jlong* elems, jint mode) { functions->ReleaseLongArrayElements(this, array, elems, mode); } void ReleaseFloatArrayElements(jfloatArray array, jfloat* elems, jint mode) { functions->ReleaseFloatArrayElements(this, array, elems, mode); } void ReleaseDoubleArrayElements(jdoubleArray array, jdouble* elems, jint mode) { functions->ReleaseDoubleArrayElements(this, array, elems, mode); } void GetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len, jboolean* buf) { functions->GetBooleanArrayRegion(this, array, start, len, buf); } void GetByteArrayRegion(jbyteArray array, jsize start, jsize len, jbyte* buf) { functions->GetByteArrayRegion(this, array, start, len, buf); } void GetCharArrayRegion(jcharArray array, jsize start, jsize len, jchar* buf) { functions->GetCharArrayRegion(this, array, start, len, buf); } void GetShortArrayRegion(jshortArray array, jsize start, jsize len, jshort* buf) { functions->GetShortArrayRegion(this, array, start, len, buf); } void GetIntArrayRegion(jintArray array, jsize start, jsize len, jint* buf) { functions->GetIntArrayRegion(this, array, start, len, buf); } void GetLongArrayRegion(jlongArray array, jsize start, jsize len, jlong* buf) { functions->GetLongArrayRegion(this, array, start, len, buf); } void GetFloatArrayRegion(jfloatArray array, jsize start, jsize len, jfloat* buf) { functions->GetFloatArrayRegion(this, array, start, len, buf); } void GetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len, jdouble* buf) { functions->GetDoubleArrayRegion(this, array, start, len, buf); } void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len, const jboolean* buf) { functions->SetBooleanArrayRegion(this, array, start, len, buf); } void SetByteArrayRegion(jbyteArray array, jsize start, jsize len, const jbyte* buf) { functions->SetByteArrayRegion(this, array, start, len, buf); } void SetCharArrayRegion(jcharArray array, jsize start, jsize len, const jchar* buf) { functions->SetCharArrayRegion(this, array, start, len, buf); } void SetShortArrayRegion(jshortArray array, jsize start, jsize len, const jshort* buf) { functions->SetShortArrayRegion(this, array, start, len, buf); } void SetIntArrayRegion(jintArray array, jsize start, jsize len, const jint* buf) { functions->SetIntArrayRegion(this, array, start, len, buf); } void SetLongArrayRegion(jlongArray array, jsize start, jsize len, const jlong* buf) { functions->SetLongArrayRegion(this, array, start, len, buf); } void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len, const jfloat* buf) { functions->SetFloatArrayRegion(this, array, start, len, buf); } void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len, const jdouble* buf) { functions->SetDoubleArrayRegion(this, array, start, len, buf); } jint RegisterNatives(jclass clazz, const JNINativeMethod* methods, jint nMethods) { return functions->RegisterNatives(this, clazz, methods, nMethods); } jint UnregisterNatives(jclass clazz) { return functions->UnregisterNatives(this, clazz); } jint MonitorEnter(jobject obj) { return functions->MonitorEnter(this, obj); } jint MonitorExit(jobject obj) { return functions->MonitorExit(this, obj); } jint GetJavaVM(JavaVM** vm) { return functions->GetJavaVM(this, vm); } void GetStringRegion(jstring str, jsize start, jsize len, jchar* buf) { functions->GetStringRegion(this, str, start, len, buf); } void GetStringUTFRegion(jstring str, jsize start, jsize len, char* buf) { return functions->GetStringUTFRegion(this, str, start, len, buf); } void* GetPrimitiveArrayCritical(jarray array, jboolean* isCopy) { return functions->GetPrimitiveArrayCritical(this, array, isCopy); } void ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode) { functions->ReleasePrimitiveArrayCritical(this, array, carray, mode); } const jchar* GetStringCritical(jstring string, jboolean* isCopy) { return functions->GetStringCritical(this, string, isCopy); } void ReleaseStringCritical(jstring string, const jchar* carray) { functions->ReleaseStringCritical(this, string, carray); } jweak NewWeakGlobalRef(jobject obj) { return functions->NewWeakGlobalRef(this, obj); } void DeleteWeakGlobalRef(jweak obj) { functions->DeleteWeakGlobalRef(this, obj); } jboolean ExceptionCheck() { return functions->ExceptionCheck(this); } jobject NewDirectByteBuffer(void* address, jlong capacity) { return functions->NewDirectByteBuffer(this, address, capacity); } void* GetDirectBufferAddress(jobject buf) { return functions->GetDirectBufferAddress(this, buf); } jlong GetDirectBufferCapacity(jobject buf) { return functions->GetDirectBufferCapacity(this, buf); } /* added in JNI 1.6 */ jobjectRefType GetObjectRefType(jobject obj) { return functions->GetObjectRefType(this, obj); } #endif /*__cplusplus*/ }; /* * JNI invocation interface. */ struct JNIInvokeInterface { void* reserved0; void* reserved1; void* reserved2; jint (*DestroyJavaVM)(JavaVM*); jint (*AttachCurrentThread)(JavaVM*, void**, void*); jint (*DetachCurrentThread)(JavaVM*); jint (*GetEnv)(JavaVM*, void**, jint); jint (*AttachCurrentThreadAsDaemon)(JavaVM*, void**, void*); }; /* * C++ version. */ struct _JavaVM { const struct JNIInvokeInterface* functions; #if defined(__cplusplus) jint DestroyJavaVM() { return functions->DestroyJavaVM(this); } jint AttachCurrentThread(void** p_env, void* thr_args) { return functions->AttachCurrentThread(this, p_env, thr_args); } jint DetachCurrentThread() { return functions->DetachCurrentThread(this); } jint GetEnv(void** env, jint version) { return functions->GetEnv(this, env, version); } jint AttachCurrentThreadAsDaemon(void** p_env, void* thr_args) { return functions->AttachCurrentThreadAsDaemon(this, p_env, thr_args); } #endif /*__cplusplus*/ }; struct JavaVMAttachArgs { jint version; /* must be >= JNI_VERSION_1_2 */ const char* name; /* NULL or name of thread as modified UTF-8 str */ jobject group; /* global ref of a ThreadGroup object, or NULL */ }; typedef struct JavaVMAttachArgs JavaVMAttachArgs; /* * JNI 1.2+ initialization. (As of 1.6, the pre-1.2 structures are no * longer supported.) */ typedef struct JavaVMOption { const char* optionString; void* extraInfo; } JavaVMOption; typedef struct JavaVMInitArgs { jint version; /* use JNI_VERSION_1_2 or later */ jint nOptions; JavaVMOption* options; jboolean ignoreUnrecognized; } JavaVMInitArgs; #ifdef __cplusplus extern "C" { #endif /* * VM initialization functions. * * Note these are the only symbols exported for JNI by the VM. */ jint JNI_GetDefaultJavaVMInitArgs(void*); jint JNI_CreateJavaVM(JavaVM**, JNIEnv**, void*); jint JNI_GetCreatedJavaVMs(JavaVM**, jsize, jsize*); // commented out by marscher //#define JNIIMPORT //#define JNIEXPORT __attribute__ ((visibility ("default"))) //#define JNICALL /* * Prototypes for functions exported by loadable shared libs. These are * called by JNI, not provided by JNI. */ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved); JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved); #ifdef __cplusplus } #endif /* * Manifest constants. */ #define JNI_FALSE 0 #define JNI_TRUE 1 #define JNI_VERSION_1_1 0x00010001 #define JNI_VERSION_1_2 0x00010002 #define JNI_VERSION_1_4 0x00010004 #define JNI_VERSION_1_6 0x00010006 #define JNI_VERSION_1_7 0x00010007 #define JNI_VERSION_1_8 0x00010008 #define JNI_OK (0) /* no error */ #define JNI_ERR (-1) /* generic error */ #define JNI_EDETACHED (-2) /* thread detached from the VM */ #define JNI_EVERSION (-3) /* JNI version error */ #define JNI_COMMIT 1 /* copy content, do not free buffer */ #define JNI_ABORT 2 /* free buffer w/o copying back */ #endif /* JNI_H_ */ jpype-0.6.2+dfsg/native/python/0000775000175000017500000000000013036015411015662 5ustar takakitakakijpype-0.6.2+dfsg/native/python/include/0000775000175000017500000000000013036015411017305 5ustar takakitakakijpype-0.6.2+dfsg/native/python/include/capsulethunk.h0000664000175000017500000000700613036015411022167 0ustar takakitakaki// Simulates Capsules using CObjects // For supporting Python 2.7 // // See https://docs.python.org/3/howto/cporting.html // // Code from https://hg.python.org/cpython/file/3.4/Doc/includes/capsulethunk.h #ifndef __CAPSULETHUNK_H #define __CAPSULETHUNK_H #if ( (PY_VERSION_HEX < 0x02070000) \ || ((PY_VERSION_HEX >= 0x03000000) \ && (PY_VERSION_HEX < 0x03010000)) ) #define __PyCapsule_GetField(capsule, field, default_value) \ ( PyCapsule_CheckExact(capsule) \ ? (((PyCObject *)capsule)->field) \ : (default_value) \ ) \ #define __PyCapsule_SetField(capsule, field, value) \ ( PyCapsule_CheckExact(capsule) \ ? (((PyCObject *)capsule)->field = value), 1 \ : 0 \ ) \ #define PyCapsule_Type PyCObject_Type #define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule)) #define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule)) #define PyCapsule_New(pointer, name, destructor) \ (PyCObject_FromVoidPtr(pointer, destructor)) #define PyCapsule_GetPointer(capsule, name) \ (PyCObject_AsVoidPtr(capsule)) /* Don't call PyCObject_SetPointer here, it fails if there's a destructor */ #define PyCapsule_SetPointer(capsule, pointer) \ __PyCapsule_SetField(capsule, cobject, pointer) #define PyCapsule_GetDestructor(capsule) \ __PyCapsule_GetField(capsule, destructor) #define PyCapsule_SetDestructor(capsule, dtor) \ __PyCapsule_SetField(capsule, destructor, dtor) /* * Sorry, there's simply no place * to store a Capsule "name" in a CObject. */ #define PyCapsule_GetName(capsule) NULL static int PyCapsule_SetName(PyObject *capsule, const char *unused) { unused = unused; PyErr_SetString(PyExc_NotImplementedError, "can't use PyCapsule_SetName with CObjects"); return 1; } #define PyCapsule_GetContext(capsule) \ __PyCapsule_GetField(capsule, descr) #define PyCapsule_SetContext(capsule, context) \ __PyCapsule_SetField(capsule, descr, context) static void * PyCapsule_Import(const char *name, int no_block) { PyObject *object = NULL; void *return_value = NULL; char *trace; size_t name_length = (strlen(name) + 1) * sizeof(char); char *name_dup = (char *)PyMem_MALLOC(name_length); if (!name_dup) { return NULL; } memcpy(name_dup, name, name_length); trace = name_dup; while (trace) { char *dot = strchr(trace, '.'); if (dot) { *dot++ = '\0'; } if (object == NULL) { if (no_block) { object = PyImport_ImportModuleNoBlock(trace); } else { object = PyImport_ImportModule(trace); if (!object) { PyErr_Format(PyExc_ImportError, "PyCapsule_Import could not " "import module \"%s\"", trace); } } } else { PyObject *object2 = PyObject_GetAttrString(object, trace); Py_DECREF(object); object = object2; } if (!object) { goto EXIT; } trace = dot; } if (PyCObject_Check(object)) { PyCObject *cobject = (PyCObject *)object; return_value = cobject->cobject; } else { PyErr_Format(PyExc_AttributeError, "PyCapsule_Import \"%s\" is not valid", name); } EXIT: Py_XDECREF(object); if (name_dup) { PyMem_FREE(name_dup); } return return_value; } #endif /* #if PY_VERSION_HEX < 0x02070000 */ #endif /* __CAPSULETHUNK_H */ jpype-0.6.2+dfsg/native/python/include/jp_cocoatools.h0000664000175000017500000000004113036015411022307 0ustar takakitakaki void JPRunConsoleEventLoop(); jpype-0.6.2+dfsg/native/python/include/jp_runloopstopper.h0000664000175000017500000000060313036015411023261 0ustar takakitakaki#import @interface JPRunLoopStopper : NSObject { BOOL shouldStop; } + currentRunLoopStopper; - init; - (BOOL) shouldRun; + (void) addRunLoopStopper:(JPRunLoopStopper *) runLoopStopper toRunLoop:(NSRunLoop *) runLoop; + (void) removeRunLoopStopperFromRunLoop:(NSRunLoop *) runLoop; - (void) stop; - (void) performStop:(id) sender; @end jpype-0.6.2+dfsg/native/python/include/jpype_memory_view.h0000664000175000017500000000163313036015411023232 0ustar takakitakaki#ifdef __cplusplus extern "C" { #endif #ifndef _JPYPE_PRIVATE_JPYPEMEMORYVIEW_H_ #define _JPYPE_PRIVATE_JPYPEMEMORYVIEW_H_ /* * Memoryview is introduced to 2.x series only in 2.7, so for supporting 2.6, * we need to have a minimal implementation here. */ #if (PY_VERSION_HEX < 0x02070000) typedef struct { PyObject_HEAD PyObject *base; Py_buffer view; } PyMemorySimpleViewObject; extern PyTypeObject PyMemorySimpleView_Type; #define PyMemorySimpleView_CheckExact(op) (((PyObject*)(op))->ob_type == &PyMemorySimpleView_Type) #define PyMemorySimpleView_GET_BUFFER(op) (&((PyMemorySimpleViewObject *)(op))->view) #define PyMemoryView_FromObject PyMemorySimpleView_FromObject #define PyMemoryView_GET_BUFFER PyMemorySimpleView_GET_BUFFER #define PyMemoryView_Check PyMemorySimpleView_CheckExact #endif void jpype_memoryview_init(PyObject* module /*PyObject **typeobject*/); #endif #ifdef __cplusplus } #endif jpype-0.6.2+dfsg/native/python/include/jpype_python.h0000664000175000017500000000714413036015411022214 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _JPYPE_PYTHON_H_ #define _JPYPE_PYTHON_H_ // This file defines the _jpype module's interface and initializes it #include #include // TODO figure a better way to do this .. Python dependencies should not be in common code #include #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN #endif #include "pythonenv.h" namespace JPypeModule { PyObject* startup(PyObject* obj, PyObject* args); PyObject* attach(PyObject* obj, PyObject* args); PyObject* dumpJVMStats(PyObject* obj); PyObject* shutdown(PyObject* obj); PyObject* synchronized(PyObject* obj, PyObject* args); PyObject* isStarted(PyObject* obj); PyObject* attachThread(PyObject* obj); PyObject* detachThread(PyObject* obj); PyObject* isThreadAttached(PyObject* obj); PyObject* getJException(PyObject* obj, PyObject* args); PyObject* raiseJava(PyObject* obj, PyObject* args); PyObject* attachThreadAsDaemon(PyObject* obj); PyObject* startReferenceQueue(PyObject* obj, PyObject* args); PyObject* stopReferenceQueue(PyObject* obj); PyObject* setConvertStringObjects(PyObject* obj, PyObject* args); } namespace JPypeJavaClass { PyObject* findClass(PyObject* obj, PyObject* args); PyObject* setJavaLangObjectClass(PyObject* self, PyObject* arg); PyObject* setGetClassMethod(PyObject* self, PyObject* arg); PyObject* setSpecialConstructorKey(PyObject* self, PyObject* arg); }; namespace JPypeJavaProxy { PyObject* setProxyClass(PyObject* self, PyObject* arg); PyObject* createProxy(PyObject*, PyObject* arg); }; namespace JPypeJavaArray { PyObject* findArrayClass(PyObject* obj, PyObject* args); PyObject* getArrayLength(PyObject* self, PyObject* arg); PyObject* getArrayItem(PyObject* self, PyObject* arg); PyObject* getArraySlice(PyObject* self, PyObject* arg); PyObject* setArraySlice(PyObject* self, PyObject* arg); PyObject* newArray(PyObject* self, PyObject* arg); PyObject* setArrayItem(PyObject* self, PyObject* arg); PyObject* setGetJavaArrayClassMethod(PyObject* self, PyObject* arg); PyObject* setJavaArrayClass(PyObject* self, PyObject* arg); PyObject* setArrayValues(PyObject* self, PyObject* arg); }; namespace JPypeJavaNio { PyObject* convertToDirectBuffer(PyObject* self, PyObject* arg); }; namespace JPypeJavaWrapper { PyObject* setWrapperClass(PyObject* self, PyObject* arg); PyObject* setStringWrapperClass(PyObject* self, PyObject* arg); }; namespace JPypeJavaException { void errorOccurred(); }; #include "py_monitor.h" #include "py_method.h" #include "py_class.h" #include "py_field.h" #include "py_hostenv.h" #include "jpype_memory_view.h" extern PythonHostEnvironment* hostEnv; // Utility method PyObject* detachRef(HostRef* ref); #endif // _JPYPE_PYTHON_H_ jpype-0.6.2+dfsg/native/python/include/py_class.h0000664000175000017500000000450013036015411021272 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PYCLASS_H_ #define _PYCLASS_H_ struct PyJPClass { //AT's comments on porting: // 1) Some Unix compilers do not tolerate the semicolumn after PyObject_HEAD //PyObject_HEAD; PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPClass* alloc(JPClass* cls); static bool check(PyObject* o); static void __dealloc__(PyObject* o); static PyObject* getName(PyObject* self, PyObject* arg); static PyObject* getBaseClass(PyObject* self, PyObject* arg); static PyObject* getBaseInterfaces(PyObject* self, PyObject* arg); static PyObject* getClassMethods(PyObject* self, PyObject* arg); static PyObject* getClassFields(PyObject* self, PyObject* arg); static PyObject* newClassInstance(PyObject* self, PyObject* arg); static PyObject* isInterface(PyObject* self, PyObject* arg); static PyObject* isPrimitive(PyObject* self, PyObject* arg); static PyObject* isSubclass(PyObject* self, PyObject* arg); static PyObject* isException(PyObject* self, PyObject* arg); static PyObject* isArray(PyObject* self, PyObject* arg); static PyObject* isAbstract(PyObject* self, PyObject* arg); static PyObject* getConstructors(PyObject* self); static PyObject* getDeclaredConstructors(PyObject* self); static PyObject* getDeclaredFields(PyObject* self); static PyObject* getDeclaredMethods(PyObject* self); static PyObject* getFields(PyObject* self); static PyObject* getMethods(PyObject* self); static PyObject* getModifiers(PyObject* self); JPClass* m_Class; }; #endif // _PYCLASS_H_ jpype-0.6.2+dfsg/native/python/include/py_field.h0000664000175000017500000000300113036015411021243 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PYFIELD_H_ #define _PYFIELD_H_ struct PyJPField { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPField* alloc(JPField* mth); static void __dealloc__(PyObject* o); static PyObject* getName(PyObject* self, PyObject* arg); static PyObject* getStaticAttribute(PyObject* self, PyObject* arg); static PyObject* setStaticAttribute(PyObject* self, PyObject* arg); static PyObject* setInstanceAttribute(PyObject* self, PyObject* arg); static PyObject* getInstanceAttribute(PyObject* self, PyObject* arg); static PyObject* isStatic(PyObject* self, PyObject* arg); static PyObject* isFinal(PyObject* self, PyObject* arg); JPField* m_Field; }; #endif // _PYFIELD_H_ jpype-0.6.2+dfsg/native/python/include/py_hostenv.h0000664000175000017500000001510613036015411021657 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PYHOSTENV_H_ #define _PYHOSTENV_H_ class PythonHostEnvironment : public HostEnvironment { public : PythonHostEnvironment() { } virtual ~PythonHostEnvironment() { } public : void setJavaLangObjectClass(PyObject* obj) { m_JavaLangObject = obj; } PyObject* getJavaLangObjectClass() { return m_JavaLangObject; } void setJavaArrayClass(PyObject* obj) { m_JavaArrayClass = obj; } void setWrapperClass(PyObject* obj) { m_WrapperClass = obj; } void setStringWrapperClass(PyObject* obj) { m_StringWrapperClass = obj; } void setProxyClass(PyObject* obj) { m_ProxyClass = obj; } void setGetJavaClassMethod(PyObject* obj) { m_GetClassMethod = obj; Py_INCREF(obj); } void setGetJavaArrayClassMethod(PyObject* obj) { m_GetArrayClassMethod = obj; Py_INCREF(obj); } void setSpecialConstructorKey(PyObject* obj) { m_SpecialConstructorKey = obj; Py_INCREF(obj); } PyObject* getSpecialConstructorKey() { return m_SpecialConstructorKey; } void setJavaExceptionClass(PyObject* obj) { m_JavaExceptionClass = obj; } static void deleteJPObjectDestructor(CAPSULE_DESTRUCTOR_ARG_TYPE data) { delete (JPObject*)CAPSULE_EXTRACT(data); } static void deleteJPArrayDestructor(CAPSULE_DESTRUCTOR_ARG_TYPE data) { delete (JPArray*)CAPSULE_EXTRACT(data); } static void deleteObjectJValueDestructor(CAPSULE_DESTRUCTOR_ARG_TYPE data) { jvalue* pv = (jvalue*)CAPSULE_EXTRACT(data); JPEnv::getJava()->DeleteGlobalRef(pv->l); delete pv; } static void deleteJValueDestructor(CAPSULE_DESTRUCTOR_ARG_TYPE data) { jvalue* pv = (jvalue*)CAPSULE_EXTRACT(data); delete pv; } static void deleteJPProxyDestructor(CAPSULE_DESTRUCTOR_ARG_TYPE data) { JPProxy* pv = (JPProxy*)CAPSULE_EXTRACT(data); delete pv; } PyObject* getJavaShadowClass(JPClass* jc); private : PyObject* m_JavaLangObject; PyObject* m_JavaArrayClass; PyObject* m_WrapperClass; PyObject* m_StringWrapperClass; PyObject* m_ProxyClass; map m_ClassMap; PyObject* m_GetClassMethod; PyObject* m_GetArrayClassMethod; public : PyObject* m_SpecialConstructorKey; PyObject* m_JavaExceptionClass; public : virtual void* acquireRef(void*); virtual void releaseRef(void*); virtual bool isRefNull(void*); virtual string describeRef(HostRef*); virtual void* gotoExternal(); virtual void returnExternal(void* state); virtual void setRuntimeException(const char* msg); virtual void setAttributeError(const char* msg); virtual void setTypeError(const char* msg); virtual void raise(const char* msg); virtual HostRef* getNone(); virtual bool isNone(HostRef*); virtual bool isBoolean(HostRef*); virtual jboolean booleanAsBoolean(HostRef*); virtual HostRef* getTrue(); virtual HostRef* getFalse(); virtual bool isSequence(HostRef*); virtual HostRef* newMutableSequence(jsize); virtual HostRef* newImmutableSequence(jsize); virtual jsize getSequenceLength(HostRef*); virtual HostRef* getSequenceItem(HostRef*, jsize); virtual void setSequenceItem(HostRef*, jsize, HostRef*); virtual bool isInt(HostRef*); virtual HostRef* newInt(jint); virtual jint intAsInt(HostRef*); virtual bool isLong(HostRef*); virtual HostRef* newLong(jlong); virtual jlong longAsLong(HostRef*); virtual bool isFloat(HostRef*); virtual HostRef* newFloat(jdouble); virtual jdouble floatAsDouble(HostRef*); virtual bool isMethod(HostRef*); virtual HostRef* newMethod(JPMethod*); virtual JPMethod* asMethod(HostRef*); virtual bool isObject(HostRef*); virtual HostRef* newObject(JPObject*); virtual JPObject* asObject(HostRef*); virtual bool isClass(HostRef*); virtual HostRef* newClass(JPClass*); virtual JPClass* asClass(HostRef*); virtual bool isArrayClass(HostRef*); virtual HostRef* newArrayClass(JPArrayClass*); virtual JPArrayClass* asArrayClass(HostRef*); virtual bool isArray(HostRef*); virtual HostRef* newArray(JPArray*); virtual JPArray* asArray(HostRef*); virtual bool isProxy(HostRef*); virtual JPProxy* asProxy(HostRef*); virtual HostRef* getCallableFrom(HostRef*, string&); virtual bool isWrapper(PyObject*) ; virtual JPTypeName getWrapperTypeName(PyObject*); virtual jvalue getWrapperValue(PyObject*); virtual bool isWrapper(HostRef*); virtual JPTypeName getWrapperTypeName(HostRef*); virtual jvalue getWrapperValue(HostRef*); virtual HostRef* newStringWrapper(jstring); virtual bool isString(HostRef*); virtual jsize getStringLength(HostRef*); virtual string stringAsString(HostRef*); virtual JCharString stringAsJCharString(HostRef*); virtual HostRef* newStringFromUnicode(const jchar*, unsigned int); virtual HostRef* newStringFromASCII(const char*, unsigned int); virtual bool isByteString(HostRef*); virtual bool isUnicodeString(HostRef* ref); virtual void getRawByteString(HostRef*, char**, long&); virtual void getRawUnicodeString(HostRef*, jchar**, long&); virtual size_t getUnicodeSize(); virtual void* prepareCallbackBegin(); virtual void prepareCallbackFinish(void* state); virtual HostRef* callObject(HostRef* callable, vector& args); virtual void printError(); virtual bool mapContains(HostRef* map, HostRef* key); virtual HostRef* getMapItem(HostRef* map, HostRef* key); virtual bool objectHasAttribute(HostRef* obj, HostRef* key); virtual HostRef* getObjectAttribute(HostRef* obj, HostRef* key); virtual bool isJavaException(HostException*); virtual HostRef* getJavaException(HostException*); virtual void clearError(); virtual void printReferenceInfo(HostRef* obj); virtual bool isByteBuffer(HostRef*); virtual void getByteBufferPtr(HostRef*, char**, long&); }; #endif // _PYHOSTENV_H_ jpype-0.6.2+dfsg/native/python/include/py_method.h0000664000175000017500000000365213036015411021454 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PYMETHOD_H_ #define _PYMETHOD_H_ struct PyJPMethod { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPMethod* alloc(JPMethod* mth); static void __dealloc__(PyObject* o); static PyObject* __str__(PyObject* o); static PyObject* __call__(PyObject* self, PyObject* args, PyObject* kwargs); static PyObject* isBeanMutator(PyObject* self, PyObject* arg); static PyObject* isBeanAccessor(PyObject* self, PyObject* arg); static PyObject* getName(PyObject* self, PyObject* arg); static PyObject* matchReport(PyObject* self, PyObject* arg); JPMethod* m_Method; }; struct PyJPBoundMethod { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static int __init__(PyObject* self, PyObject* args, PyObject* kwargs); static void __dealloc__(PyObject* o); static PyObject* __str__(PyObject* o); static PyObject* __call__(PyObject* self, PyObject* args, PyObject* kwargs); static PyObject* matchReport(PyObject* self, PyObject* arg); PyObject* m_Instance; PyJPMethod* m_Method; }; #endif // _PYMETHOD_H_ jpype-0.6.2+dfsg/native/python/include/py_monitor.h0000664000175000017500000000217013036015411021655 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PYMONITOR_H_ #define _PYMONITOR_H_ #include "object.h" struct PyJPMonitor { PyObject_HEAD // Python-visible methods static void initType(PyObject* module); static PyJPMonitor* alloc(JPMonitor*); static void __dealloc__(PyObject* o); static PyObject* __str__(PyObject* o); JPMonitor* state; }; #endif // _PYMONITOR_H_ jpype-0.6.2+dfsg/native/python/include/pythonenv.h0000664000175000017500000001751213036015411021516 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #ifndef _PYTHON_ENV_H_ #define _PYTHON_ENV_H_ #define PY_CHECK(op) op; { \ PyObject* __ex = PyErr_Occurred(); \ if (__ex) { \ throw PythonException(); \ }\ }; #if ( (PY_VERSION_HEX < 0x02070000) \ || ((PY_VERSION_HEX >= 0x03000000) \ && (PY_VERSION_HEX < 0x03010000)) ) #include "capsulethunk.h" #define USE_CAPSULE 1 typedef void* CAPSULE_DESTRUCTOR_ARG_TYPE; typedef void (*PyCapsule_Destructor)(void*); #define CAPSULE_EXTRACT(obj) (obj) #else typedef PyObject* CAPSULE_DESTRUCTOR_ARG_TYPE; #define CAPSULE_EXTRACT(obj) (PyCapsule_GetPointer(obj, PyCapsule_GetName(obj))) #endif /** * Exception wrapper for python-generated exceptions */ class PythonException : public HostException { public : PythonException(); PythonException(const PythonException& ex); virtual ~PythonException(); virtual string getMessage(); bool isJavaException(); PyObject* getJavaException(); public : PyObject* m_ExceptionClass; PyObject* m_ExceptionValue; }; /** * JPythonEnvHelper */ class JPythonEnvHelper { }; /** * JPyErr */ class JPyErr : public JPythonEnvHelper { public : static void setString(PyObject*exClass, const char* str); static void setObject(PyObject*exClass, PyObject* obj); static void check() { PY_CHECK(;); } }; /** * JPyArg */ class JPyArg : public JPythonEnvHelper { public : template static void parseTuple(PyObject* arg, const char* pattern, T1 a1) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1) ); } template static void parseTuple(PyObject* arg, const char* pattern, T1 a1, T2 a2) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2) ); } template static void parseTuple(PyObject* arg, const char* pattern, T1 a1, T2 a2, T3 a3) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2, a3) ); } template static void parseTuple(PyObject* arg, const char* pattern, T1 a1, T2 a2, T3 a3, T4 a4) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2, a3, a4)) ; } template static void parseTuple(PyObject* arg, const char* pattern, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { PY_CHECK( PyArg_ParseTuple(arg, pattern, a1, a2, a3, a4, a5)) ; } private : static void check_exception(); }; /** * JPyString */ class JPyString : public JPythonEnvHelper { public : static bool check(PyObject* obj); static bool checkStrict(PyObject*); static bool checkUnicode(PyObject*); static string asString(PyObject* obj); static JCharString asJCharString(PyObject* obj); static Py_ssize_t AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *); static Py_UNICODE* AsUnicode(PyObject *obj); static PyObject* fromUnicode(const jchar*, int); static PyObject* fromString(const char*); }; /** * JPyTuple */ class JPySequence : public JPythonEnvHelper { public : static bool check(PyObject* obj); static PyObject* newTuple(Py_ssize_t ndx); static PyObject* newList(Py_ssize_t ndx); static PyObject* getItem(PyObject* tuple, Py_ssize_t ndx); static void setItem(PyObject* tuple, Py_ssize_t ndx, PyObject* val); }; /** * JPyObject */ class JPyObject : public JPythonEnvHelper { public : static Py_ssize_t length(PyObject* obj); static bool hasAttr(PyObject*, PyObject*); static PyObject* getAttr(PyObject*, PyObject*); static PyObject* call(PyObject*, PyObject*, PyObject*); static PyObject* getAttrString(PyObject*, const char*); static void setAttrString(PyObject*, const char*, PyObject *); static bool isInstance(PyObject* obj, PyObject* t); static bool isSubclass(PyObject* obj, PyObject* t); static bool isMemoryView(PyObject* obj); static void AsPtrAndSize(PyObject *obj, char **buffer, Py_ssize_t *); }; class JPyInt : public JPythonEnvHelper { public : static PyObject* fromLong(long l); static bool check(PyObject*); static long asLong(PyObject*); }; class JPyLong : public JPythonEnvHelper { public : static PyObject* fromLongLong(PY_LONG_LONG l); static bool check(PyObject*); static PY_LONG_LONG asLongLong(PyObject*); }; class JPyBoolean : public JPythonEnvHelper { public : static bool isTrue(PyObject* o) { return o == Py_True; } static bool isFalse(PyObject* o) { return o == Py_False; } static PyObject* getTrue(); static PyObject* getFalse(); }; class JPyFloat : public JPythonEnvHelper { public : static PyObject* fromDouble(double l); static bool check(PyObject*); static double asDouble(PyObject*); }; class JPyDict : public JPythonEnvHelper { public : static bool check(PyObject* obj); static bool contains(PyObject*, PyObject*); static PyObject* getItem(PyObject*, PyObject*); static PyObject* getKeys(PyObject*); static PyObject* copy(PyObject*); static PyObject* newInstance(); static void setItemString(PyObject*, PyObject*, const char*); }; class JPyCObject : public JPythonEnvHelper { public : static bool check(PyObject* obj); static PyObject* fromVoid(void* data, PyCapsule_Destructor destr); static PyObject* fromVoidAndDesc(void* data, const char* desc, PyCapsule_Destructor destr); static void* asVoidPtr(PyObject*); static void* getDesc(PyObject*); }; class JPyType : public JPythonEnvHelper { public : static bool check(PyObject* obj); static bool isSubclass(PyObject*, PyObject*); }; class JPyHelper : public JPythonEnvHelper { public : static void dumpSequenceRefs(PyObject* seq, const char* comment); }; #undef PY_CHECK #define PY_STANDARD_CATCH \ catch(JavaException& ex) \ { \ try { \ JPypeJavaException::errorOccurred(); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a Java Exception"); \ }\ }\ catch(JPypeException& ex)\ {\ try { \ JPEnv::getHost()->setRuntimeException(ex.getMsg()); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a JPype Exception"); \ }\ }\ catch(PythonException& ex) \ { \ } \ catch(...) \ {\ JPEnv::getHost()->setRuntimeException("Unknown Exception"); \ } \ #define PY_LOGGING_CATCH \ catch(JavaException& ex) \ { \ try { \ cout << "Java error occured : " << ex.message << endl; \ JPypeJavaException::errorOccurred(); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a Java Exception"); \ }\ }\ catch(JPypeException& ex)\ {\ try { \ cout << "JPype error occured" << endl; \ JPEnv::getHost()->setRuntimeException(ex.getMsg()); \ } \ catch(...) \ { \ JPEnv::getHost()->setRuntimeException("An unknown error occured while handling a JPype Exception"); \ }\ }\ catch(PythonException& ex) \ { \ cout << "Pyhton error occured" << endl; \ } \ catch(...) \ {\ cout << "Unknown error occured" << endl; \ JPEnv::getHost()->setRuntimeException("Unknown Exception"); \ } \ #endif // _PYTHON_ENV_H_ jpype-0.6.2+dfsg/native/python/jpype_javaarray.cpp0000664000175000017500000001425413036015411021563 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include namespace { // impl detail inline bool is_primitive(char t) { switch(t) { case 'B': case 'S': case 'I': case 'J': case 'F': case 'D': case 'Z': case 'C': return true; default: return false; } } } PyObject* JPypeJavaArray::findArrayClass(PyObject* obj, PyObject* args) { try { char* cname; JPyArg::parseTuple(args, "s", &cname); JPTypeName name = JPTypeName::fromSimple(cname); JPArrayClass* claz = JPTypeManager::findArrayClass(name); if (claz == NULL) { Py_RETURN_NONE; } PyObject* res = JPyCObject::fromVoidAndDesc((void*)claz, "jclass", NULL); return res; } PY_STANDARD_CATCH; PyErr_Clear(); Py_RETURN_NONE; } PyObject* JPypeJavaArray::setJavaArrayClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setJavaArrayClass(t); Py_RETURN_NONE; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::setGetJavaArrayClassMethod(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setGetJavaArrayClassMethod(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::getArrayLength(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; JPyArg::parseTuple(arg, "O!", &PyCapsule_Type, &arrayObject); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); int res = a->getLength(); return JPyInt::fromLong(res); } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::getArrayItem(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int ndx; JPyArg::parseTuple(arg, "O!i", &PyCapsule_Type, &arrayObject, &ndx); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); HostRef* res = a->getItem(ndx); return detachRef(res); } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::getArraySlice(PyObject* self, PyObject* arg) { PyObject* arrayObject; int lo = -1; int hi = -1; try { JPyArg::parseTuple(arg, "O!ii", &PyCapsule_Type, &arrayObject, &lo, &hi); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); int length = a->getLength(); // stolen from jcc, to get nice slice support if (lo < 0) lo = length + lo; if (lo < 0) lo = 0; else if (lo > length) lo = length; if (hi < 0) hi = length + hi; if (hi < 0) hi = 0; else if (hi > length) hi = length; if (lo > hi) lo = hi; const JPTypeName& componentName = a->getType()->getObjectType().getComponentName(); const string& name = componentName.getNativeName(); if(is_primitive(name[0])) { // for primitive types, we have fast sequence generation available return a->getSequenceFromRange(lo, hi); } else { // slow wrapped access for non primitives vector values = a->getRange(lo, hi); JPCleaner cleaner; PyObject* res = JPySequence::newList((int)values.size()); for (unsigned int i = 0; i < values.size(); i++) { JPySequence::setItem(res, i, (PyObject*)values[i]->data()); cleaner.add(values[i]); } return res; } } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::setArraySlice(PyObject* self, PyObject* arg) { TRACE_IN("JPypeJavaArray::setArraySlice") PyObject* arrayObject; int lo = -1; int hi = -1; PyObject* sequence; try { JPyArg::parseTuple(arg, "O!iiO", &PyCapsule_Type, &arrayObject, &lo, &hi, &sequence); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); int length = a->getLength(); if(length == 0) Py_RETURN_NONE; if (lo < 0) lo = length + lo; if (lo < 0) lo = 0; else if (lo > length) lo = length; if (hi < 0) hi = length + hi; if (hi < 0) hi = 0; else if (hi > length) hi = length; if (lo > hi) lo = hi; const JPTypeName& componentName = a->getType()->getObjectType().getComponentName(); const string& name = componentName.getNativeName(); if(is_primitive(name[0])) { // for primitive types, we have fast setters available a->setRange(lo, hi, sequence); } else { // slow wrapped access for non primitive types vector values; values.reserve(hi - lo); JPCleaner cleaner; for (Py_ssize_t i = 0; i < hi - lo; i++) { HostRef* v = new HostRef(JPySequence::getItem(sequence, i), false); values.push_back(v); cleaner.add(v); } a->setRange(lo, hi, values); } Py_RETURN_NONE; } PY_STANDARD_CATCH return NULL; TRACE_OUT } PyObject* JPypeJavaArray::setArrayItem(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int ndx; PyObject* value; JPyArg::parseTuple(arg, "O!iO", &PyCapsule_Type, &arrayObject, &ndx, &value); JPArray* a = (JPArray*)JPyCObject::asVoidPtr(arrayObject); JPCleaner cleaner; HostRef* v = new HostRef(value); cleaner.add(v); a->setItem(ndx, v); Py_RETURN_NONE; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaArray::newArray(PyObject* self, PyObject* arg) { try { PyObject* arrayObject; int sz; JPyArg::parseTuple(arg, "O!i", &PyCapsule_Type, &arrayObject, &sz); JPArrayClass* a = (JPArrayClass*)JPyCObject::asVoidPtr(arrayObject); JPArray* v = a->newInstance(sz); PyObject* res = JPyCObject::fromVoidAndDesc(v, "JPArray", PythonHostEnvironment::deleteJPArrayDestructor); return res; } PY_STANDARD_CATCH return NULL; } jpype-0.6.2+dfsg/native/python/jpype_javaclass.cpp0000664000175000017500000000421413036015411021545 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include PyObject* JPypeJavaClass::setJavaLangObjectClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setJavaLangObjectClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaClass::setGetClassMethod(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setGetJavaClassMethod(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaClass::setSpecialConstructorKey(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setSpecialConstructorKey(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaClass::findClass(PyObject* obj, PyObject* args) { TRACE_IN("JPypeModule::findClass"); try { char* cname; JPyArg::parseTuple(args, "s", &cname); TRACE1(cname); JPTypeName name = JPTypeName::fromSimple(cname); JPClass* claz = JPTypeManager::findClass(name); if (claz == NULL) { Py_INCREF(Py_None); return Py_None; } PyObject* res = (PyObject*)PyJPClass::alloc(claz); return res; } PY_STANDARD_CATCH; PyErr_Clear(); Py_INCREF(Py_None); return Py_None; TRACE_OUT; } jpype-0.6.2+dfsg/native/python/jpype_javanio.cpp0000664000175000017500000000316713036015411021233 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include PyObject* JPypeJavaNio::convertToDirectBuffer(PyObject* self, PyObject* args) { TRACE_IN("convertStringToBuffer"); // Use special method defined on the TypeConverter interface ... PyObject* src; JPyArg::parseTuple(args, "O", &src); PyObject* res = NULL; if (JPyObject::isMemoryView(src)) { // converts to byte buffer ... JPTypeName tname = JPTypeName::fromType(JPTypeName::_byte); JPType* type = JPTypeManager::getType(tname); HostRef srcRef(src); TRACE1("Converting"); HostRef* ref = type->convertToDirectBuffer(&srcRef); JPEnv::registerRef(ref, &srcRef); TRACE1("detaching result"); res = detachRef(ref); } if (res != NULL) { return res; } RAISE(JPypeException, "Do not know how to convert to direct byte buffer, only memory view supported"); return NULL; TRACE_OUT; } jpype-0.6.2+dfsg/native/python/jpype_memory_view.c0000664000175000017500000001551413036015411021605 0ustar takakitakaki//This is based on the simple memory view found in numpy /* * Simple PyMemoryView'ish object for Python 2.6 compatibility. * * On Python >= 2.7, we can use the actual PyMemoryView objects. * * Some code copied from the CPython implementation. */ #define PY_SSIZE_T_CLEAN #include #include "structmember.h" #include "jpype_memory_view.h" #if (PY_VERSION_HEX < 0x02070000) static PyObject * PyMemorySimpleView_FromObject(PyObject *base); /* * Memory allocation */ static int memorysimpleview_traverse(PyMemorySimpleViewObject *self, visitproc visit, void *arg) { if (self->base != NULL) Py_VISIT(self->base); if (self->view.obj != NULL) Py_VISIT(self->view.obj); return 0; } static int memorysimpleview_clear(PyMemorySimpleViewObject *self) { Py_CLEAR(self->base); PyBuffer_Release(&self->view); self->view.obj = NULL; return 0; } static void memorysimpleview_dealloc(PyMemorySimpleViewObject *self) { PyObject_GC_UnTrack(self); Py_CLEAR(self->base); if (self->view.obj != NULL) { PyBuffer_Release(&self->view); self->view.obj = NULL; } PyObject_GC_Del(self); } static PyObject * memorysimpleview_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { PyObject *obj; static char *kwlist[] = {"object", 0}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist, &obj)) { return NULL; } return PyMemorySimpleView_FromObject(obj); } /* * Buffer interface */ static int memorysimpleview_getbuffer(PyMemorySimpleViewObject *self, Py_buffer *view, int flags) { return PyObject_GetBuffer(self->base, view, flags); } static void memorysimpleview_releasebuffer(PyMemorySimpleViewObject *self, Py_buffer *view) { PyBuffer_Release(view); } static PyBufferProcs memorysimpleview_as_buffer = { (readbufferproc)0, /*bf_getreadbuffer*/ (writebufferproc)0, /*bf_getwritebuffer*/ (segcountproc)0, /*bf_getsegcount*/ (charbufferproc)0, /*bf_getcharbuffer*/ (getbufferproc)memorysimpleview_getbuffer, /* bf_getbuffer */ (releasebufferproc)memorysimpleview_releasebuffer, /* bf_releasebuffer */ }; /* * Getters */ static PyObject * _IntTupleFromSsizet(int len, Py_ssize_t *vals) { int i; PyObject *o; PyObject *intTuple; if (vals == NULL) { Py_INCREF(Py_None); return Py_None; } intTuple = PyTuple_New(len); if (!intTuple) return NULL; for(i=0; iview.format); } static PyObject * memorysimpleview_itemsize_get(PyMemorySimpleViewObject *self) { return PyLong_FromSsize_t(self->view.itemsize); } static PyObject * memorysimpleview_shape_get(PyMemorySimpleViewObject *self) { return _IntTupleFromSsizet(self->view.ndim, self->view.shape); } static PyObject * memorysimpleview_strides_get(PyMemorySimpleViewObject *self) { return _IntTupleFromSsizet(self->view.ndim, self->view.strides); } static PyObject * memorysimpleview_suboffsets_get(PyMemorySimpleViewObject *self) { return _IntTupleFromSsizet(self->view.ndim, self->view.suboffsets); } static PyObject * memorysimpleview_readonly_get(PyMemorySimpleViewObject *self) { return PyBool_FromLong(self->view.readonly); } static PyObject * memorysimpleview_ndim_get(PyMemorySimpleViewObject *self) { return PyLong_FromLong(self->view.ndim); } static PyGetSetDef memorysimpleview_getsets[] = { {"format", (getter)memorysimpleview_format_get, NULL, NULL, NULL}, {"itemsize", (getter)memorysimpleview_itemsize_get, NULL, NULL, NULL}, {"shape", (getter)memorysimpleview_shape_get, NULL, NULL, NULL}, {"strides", (getter)memorysimpleview_strides_get, NULL, NULL, NULL}, {"suboffsets", (getter)memorysimpleview_suboffsets_get, NULL, NULL, NULL}, {"readonly", (getter)memorysimpleview_readonly_get, NULL, NULL, NULL}, {"ndim", (getter)memorysimpleview_ndim_get, NULL, NULL, NULL}, {NULL, NULL, NULL, NULL} }; PyTypeObject PyMemorySimpleView_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_jpype.memoryview", sizeof(PyMemorySimpleViewObject), 0, /* tp_itemsize */ /* methods */ (destructor)memorysimpleview_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ (cmpfunc)0, /* tp_compare */ (reprfunc)0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ (reprfunc)0, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ &memorysimpleview_as_buffer, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_NEWBUFFER, /* tp_flags */ 0, /* tp_doc */ (traverseproc)memorysimpleview_traverse, /* tp_traverse */ (inquiry)memorysimpleview_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ memorysimpleview_getsets, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ memorysimpleview_new, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ #if PY_VERSION_HEX >= 0x02060000 0, /* tp_version_tag */ #endif }; /* * Factory */ static PyObject * PyMemorySimpleView_FromObject(PyObject *base) { PyMemorySimpleViewObject *mview = NULL; Py_buffer view; if (Py_TYPE(base)->tp_as_buffer == NULL || Py_TYPE(base)->tp_as_buffer->bf_getbuffer == NULL) { PyErr_SetString(PyExc_TypeError, "cannot make memory view because object does " "not have the buffer interface"); return NULL; } memset(&view, 0, sizeof(Py_buffer)); if (PyObject_GetBuffer(base, &view, PyBUF_FULL_RO) < 0) return NULL; mview = (PyMemorySimpleViewObject *) PyObject_GC_New(PyMemorySimpleViewObject, &PyMemorySimpleView_Type); if (mview == NULL) { PyBuffer_Release(&view); return NULL; } memcpy(&mview->view, &view, sizeof(Py_buffer)); mview->base = base; Py_INCREF(base); PyObject_GC_Track(mview); return (PyObject *)mview; } /* * Module initialization */ void jpype_memoryview_init(PyObject* module /*PyObject **typeobject*/) { PyType_Ready(&PyMemorySimpleView_Type); // *typeobject = (PyObject*)&PyMemorySimpleView_Type; // return 0; PyModule_AddObject(module, "memoryview", (PyObject*)&PyMemorySimpleView_Type); } #endif jpype-0.6.2+dfsg/native/python/jpype_module.cpp0000664000175000017500000001704213036015411021066 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include PyObject* JPypeModule::startup(PyObject* obj, PyObject* args) { TRACE_IN("startup"); try { PyObject* vmOpt; PyObject* vmPath; char ignoreUnrecognized = true; JPyArg::parseTuple(args, "OO!b|", &vmPath, &PyTuple_Type, &vmOpt, &ignoreUnrecognized); if (! (JPyString::check(vmPath))) { RAISE(JPypeException, "First paramter must be a string or unicode"); } string cVmPath = JPyString::asString(vmPath); StringVector args; for (int i = 0; i < JPyObject::length(vmOpt); i++) { PyObject* obj = JPySequence::getItem(vmOpt, i); if (JPyString::check(obj)) { // TODO support unicode string v = JPyString::asString(obj); args.push_back(v); } else if (JPySequence::check(obj)) { //String name = arg[0]; //Callable value = arg[1]; // TODO complete this for the hooks .... } else { RAISE(JPypeException, "VM Arguments must be string or tuple"); } } JPEnv::loadJVM(cVmPath, ignoreUnrecognized, args); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; TRACE_OUT; } PyObject* JPypeModule::attach(PyObject* obj, PyObject* args) { TRACE_IN("attach"); try { PyObject* vmPath; JPyArg::parseTuple(args, "O", &vmPath); if (! (JPyString::check(vmPath))) { RAISE(JPypeException, "First paramter must be a string or unicode"); } string cVmPath = JPyString::asString(vmPath); JPEnv::attachJVM(cVmPath); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; TRACE_OUT; } PyObject* JPypeModule::dumpJVMStats(PyObject* obj) { cerr << "JVM activity report :" << endl; //cerr << "\tmethod calls : " << methodCalls << endl; //cerr << "\tstatic method calls : " << staticMethodCalls << endl; //cerr << "\tconstructor calls : " << constructorCalls << endl; //cerr << "\tproxy callbacks : " << JProxy::getCallbackCount() << endl; //cerr << "\tfield gets : " << fieldGets << endl; //cerr << "\tfield sets : " << fieldSets << endl; cerr << "\tclasses loaded : " << JPTypeManager::getLoadedClasses() << endl; Py_INCREF(Py_None); return Py_None; } PyObject* JPypeModule::shutdown(PyObject* obj) { TRACE_IN("shutdown"); try { dumpJVMStats(obj); JPEnv::getJava()->checkInitialized(); JPTypeManager::shutdown(); if (JPEnv::getJava()->DestroyJavaVM() ) { RAISE(JPypeException, "Unable to destroy JVM"); } JPEnv::getJava()->shutdown(); cerr << "JVM has been shutdown" << endl; Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; TRACE_OUT; } PyObject* JPypeModule::synchronized(PyObject* obj, PyObject* args) { JPCleaner cleaner; TRACE_IN("synchronized"); try { PyObject* o; JPyArg::parseTuple(args, "O!", &PyCapsule_Type, &o); string desc = (char*)JPyCObject::getDesc(o); jobject obj; if (desc == "JPObject") { JPObject* jpo = (JPObject*)JPyCObject::asVoidPtr(o); obj = jpo->getObject(); cleaner.addLocal(obj); } else if (desc == "JPClass") { JPClass* jpo = (JPClass*)JPyCObject::asVoidPtr(o); obj = jpo->getClass(); cleaner.addLocal(obj); } else if (desc == "JPArray") { JPArray* jpo = (JPArray*)JPyCObject::asVoidPtr(o); obj = jpo->getObject(); cleaner.addLocal(obj); } else if (desc == "JPArrayClass") { JPArrayClass* jpo = (JPArrayClass*)JPyCObject::asVoidPtr(o); obj = jpo->getClass(); cleaner.addLocal(obj); } else if (hostEnv->isWrapper(o) && hostEnv->getWrapperTypeName(o).isObjectType()) { obj = hostEnv->getWrapperValue(o).l; cleaner.addLocal(obj); } // TODO proxy else { RAISE(JPypeException, "method only accepts object values."); } PyJPMonitor* c = PyJPMonitor::alloc(new JPMonitor(obj)); return (PyObject*)c; } PY_STANDARD_CATCH; PyErr_Clear(); Py_INCREF(Py_None); return Py_None; TRACE_OUT; } PyObject* JPypeModule::isStarted(PyObject* obj) { if (JPEnv::isInitialized()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PyObject* JPypeModule::attachThread(PyObject* obj) { try { JPEnv::attachCurrentThread(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::detachThread(PyObject* obj) { try { JPEnv::getJava()->DetachCurrentThread(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::isThreadAttached(PyObject* obj) { try { if (JPEnv::isThreadAttached()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::raiseJava(PyObject* , PyObject* args) { try { //PyObject* arg; //JPyArg::parseTuple(args, "O", &arg); //JPObject* obj; //JPCleaner cleaner; // //if (JPyCObject::check(arg) && string((char*)JPyCObject::getDesc(arg)) == "JPObject") //{ // obj = (JPObject*)JPyCObject::asVoidPtr(arg); //} //else //{ // JPyErr::setString(PyExc_TypeError, "You can only throw a subclass of java.lang.Throwable"); // return NULL; //} // //// check if claz is an instance of Throwable //JPClass* claz = obj->getClass(); //jclass jc = claz->getClass(); //cleaner.add(jc); //if (! JPJni::isThrowable(jc)) //{ // JPyErr::setString(PyExc_TypeError, "You can only throw a subclass of java.lang.Throwable"); // return NULL; //} // //jobject jobj = obj->getObject(); //cleaner.add(jobj); //JPEnv::getJava()->Throw((jthrowable)jobj); //PyJavaException::errorOccurred(); } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::attachThreadAsDaemon(PyObject* obj) { try { JPEnv::attachCurrentThreadAsDaemon(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::startReferenceQueue(PyObject* obj, PyObject* args) { try { int i; JPyArg::parseTuple(args, "i", &i); JPJni::startJPypeReferenceQueue(i == 1); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::stopReferenceQueue(PyObject* obj) { try { JPJni::stopJPypeReferenceQueue(); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } PyObject* JPypeModule::setConvertStringObjects(PyObject* obj, PyObject* args) { try { PyObject* flag; JPyArg::parseTuple(args, "O", &flag); if (JPyBoolean::isTrue(flag)) { JPEnv::getJava()->setConvertStringObjects(true); } else { JPEnv::getJava()->setConvertStringObjects(false); } Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH; return NULL; } jpype-0.6.2+dfsg/native/python/jpype_python.cpp0000664000175000017500000002034213036015411021117 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include #ifdef HAVE_NUMPY // #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define PY_ARRAY_UNIQUE_SYMBOL jpype_ARRAY_API #include #endif PythonHostEnvironment* hostEnv; PyObject* JPypeJavaWrapper::setWrapperClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setWrapperClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaWrapper::setStringWrapperClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setStringWrapperClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaProxy::setProxyClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setProxyClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* convertToJValue(PyObject* self, PyObject* arg) { try { char* tname; PyObject* value; JPyArg::parseTuple(arg, "sO", &tname, &value); JPTypeName name = JPTypeName::fromSimple(tname); JPType* type = JPTypeManager::getType(name); HostRef ref(value); jvalue v = type->convertToJava(&ref); jvalue* pv = new jvalue(); *pv = v; PyObject* res; if (type->isObjectType()) { res = JPyCObject::fromVoidAndDesc((void*)pv, "object jvalue", PythonHostEnvironment::deleteObjectJValueDestructor); } else { res = JPyCObject::fromVoidAndDesc((void*)pv, "jvalue", PythonHostEnvironment::deleteJValueDestructor); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* JPypeJavaProxy::createProxy(PyObject*, PyObject* arg) { try { JPCleaner cleaner; PyObject* self; PyObject* intf; JPyArg::parseTuple(arg, "OO", &self, &intf); std::vector interfaces; Py_ssize_t len = JPyObject::length(intf); for (Py_ssize_t i = 0; i < len; i++) { PyObject* subObj = JPySequence::getItem(intf, i); cleaner.add(new HostRef(subObj, false)); PyObject* claz = JPyObject::getAttrString(subObj, "__javaclass__"); PyJPClass* c = (PyJPClass*)claz; jclass jc = c->m_Class->getClass(); cleaner.addLocal(jc); interfaces.push_back(jc); } HostRef ref = HostRef(self); JPProxy* proxy = new JPProxy(&ref, interfaces); PyObject* res = JPyCObject::fromVoidAndDesc(proxy, "jproxy", PythonHostEnvironment::deleteJPProxyDestructor); return res; } PY_STANDARD_CATCH return NULL; } static PyObject* setJavaExceptionClass(PyObject* self, PyObject* arg) { try { PyObject* t; JPyArg::parseTuple(arg, "O", &t); hostEnv->setJavaExceptionClass(t); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } static PyMethodDef jpype_methods[] = { {"isStarted", (PyCFunction)&JPypeModule::isStarted, METH_NOARGS, ""}, {"startup", &JPypeModule::startup, METH_VARARGS, ""}, {"attach", &JPypeModule::attach, METH_VARARGS, ""}, {"shutdown", (PyCFunction)&JPypeModule::shutdown, METH_NOARGS, ""}, {"findClass", &JPypeJavaClass::findClass, METH_VARARGS, ""}, {"synchronized", &JPypeModule::synchronized, METH_VARARGS, ""}, {"isThreadAttachedToJVM", (PyCFunction)&JPypeModule::isThreadAttached, METH_NOARGS, ""}, {"attachThreadToJVM", (PyCFunction)&JPypeModule::attachThread, METH_NOARGS, ""}, {"detachThreadFromJVM", (PyCFunction)&JPypeModule::detachThread, METH_NOARGS, ""}, {"dumpJVMStats", (PyCFunction)&JPypeModule::dumpJVMStats, METH_NOARGS, ""}, {"attachThreadAsDaemon", (PyCFunction)&JPypeModule::attachThreadAsDaemon, METH_NOARGS, ""}, {"startReferenceQueue", &JPypeModule::startReferenceQueue, METH_VARARGS, ""}, {"stopReferenceQueue", (PyCFunction)&JPypeModule::stopReferenceQueue, METH_NOARGS, ""}, {"setJavaLangObjectClass", &JPypeJavaClass::setJavaLangObjectClass, METH_VARARGS, ""}, {"setGetClassMethod", &JPypeJavaClass::setGetClassMethod, METH_VARARGS, ""}, {"setSpecialConstructorKey", &JPypeJavaClass::setSpecialConstructorKey, METH_VARARGS, ""}, {"setJavaArrayClass", &JPypeJavaArray::setJavaArrayClass, METH_VARARGS, ""}, {"setGetJavaArrayClassMethod", &JPypeJavaArray::setGetJavaArrayClassMethod, METH_VARARGS, ""}, {"setWrapperClass", &JPypeJavaWrapper::setWrapperClass, METH_VARARGS, ""}, {"setProxyClass", &JPypeJavaProxy::setProxyClass, METH_VARARGS, ""}, {"createProxy", &JPypeJavaProxy::createProxy, METH_VARARGS, ""}, {"setStringWrapperClass", &JPypeJavaWrapper::setStringWrapperClass, METH_VARARGS, ""}, {"convertToJValue", &convertToJValue, METH_VARARGS, ""}, {"findArrayClass", &JPypeJavaArray::findArrayClass, METH_VARARGS, ""}, {"getArrayLength", &JPypeJavaArray::getArrayLength, METH_VARARGS, ""}, {"getArrayItem", &JPypeJavaArray::getArrayItem, METH_VARARGS, ""}, {"setArrayItem", &JPypeJavaArray::setArrayItem, METH_VARARGS, ""}, {"getArraySlice", &JPypeJavaArray::getArraySlice, METH_VARARGS, ""}, {"setArraySlice", &JPypeJavaArray::setArraySlice, METH_VARARGS, ""}, {"newArray", &JPypeJavaArray::newArray, METH_VARARGS, ""}, {"setJavaExceptionClass", &setJavaExceptionClass, METH_VARARGS, ""}, {"convertToDirectBuffer", &JPypeJavaNio::convertToDirectBuffer, METH_VARARGS, ""}, {"setConvertStringObjects", &JPypeModule::setConvertStringObjects, METH_VARARGS, ""}, // sentinel {NULL} }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "_jpype", "jpype module", -1, jpype_methods, }; #endif #if PY_MAJOR_VERSION >= 3 PyMODINIT_FUNC PyInit__jpype() #else PyMODINIT_FUNC init_jpype() #endif { Py_Initialize(); PyEval_InitThreads(); #if PY_MAJOR_VERSION >= 3 PyObject* module = PyModule_Create(&moduledef); #else PyObject* module = Py_InitModule("_jpype", jpype_methods); #endif Py_INCREF(module); hostEnv = new PythonHostEnvironment(); JPEnv::init(hostEnv); PyJPMonitor::initType(module); PyJPMethod::initType(module); PyJPBoundMethod::initType(module); PyJPClass::initType(module); PyJPField::initType(module); #if (PY_VERSION_HEX < 0x02070000) jpype_memoryview_init(module); #endif #ifdef HAVE_NUMPY import_array(); #endif #if PY_MAJOR_VERSION >= 3 return module; #endif } PyObject* detachRef(HostRef* ref) { PyObject* data = (PyObject*)ref->data(); Py_XINCREF(data); ref->release(); return data; } void JPypeJavaException::errorOccurred() { TRACE_IN("PyJavaException::errorOccurred"); JPCleaner cleaner; jthrowable th = JPEnv::getJava()->ExceptionOccurred(); cleaner.addLocal(th); JPEnv::getJava()->ExceptionClear(); jclass ec = JPJni::getClass(th); JPTypeName tn = JPJni::getName(ec); JPClass* jpclass = JPTypeManager::findClass(tn); cleaner.addLocal(ec); PyObject* jexclass = hostEnv->getJavaShadowClass(jpclass); HostRef* pyth = hostEnv->newObject(new JPObject(tn, th)); cleaner.add(pyth); PyObject* args = JPySequence::newTuple(2); PyObject* arg2 = JPySequence::newTuple(1); JPySequence::setItem(arg2, 0, args); Py_DECREF(args); JPySequence::setItem(args, 0, hostEnv->m_SpecialConstructorKey); JPySequence::setItem(args, 1, (PyObject*)pyth->data()); PyObject* pyexclass = JPyObject::getAttrString(jexclass, "PYEXC"); Py_DECREF(jexclass); JPyErr::setObject(pyexclass, arg2); Py_DECREF(arg2); Py_DECREF(pyexclass); TRACE_OUT; } jpype-0.6.2+dfsg/native/python/py_class.cpp0000664000175000017500000003454713036015411020220 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include static PyMethodDef classMethods[] = { {"getName", &PyJPClass::getName, METH_NOARGS, ""}, {"getBaseClass", &PyJPClass::getBaseClass, METH_NOARGS, ""}, {"getClassFields", &PyJPClass::getClassFields, METH_NOARGS, ""}, {"getClassMethods", &PyJPClass::getClassMethods, METH_NOARGS, ""}, {"newClassInstance", &PyJPClass::newClassInstance, METH_VARARGS, ""}, {"isInterface", &PyJPClass::isInterface, METH_NOARGS, ""}, {"getBaseInterfaces", &PyJPClass::getBaseInterfaces, METH_NOARGS, ""}, {"isSubclass", &PyJPClass::isSubclass, METH_VARARGS, ""}, {"isPrimitive", &PyJPClass::isPrimitive, METH_NOARGS, ""}, {"isException", &PyJPClass::isException, METH_NOARGS, ""}, {"isArray", &PyJPClass::isArray, METH_NOARGS, ""}, {"isAbstract", &PyJPClass::isAbstract, METH_NOARGS, ""}, {"getSuperclass",&PyJPClass::getBaseClass, METH_NOARGS, ""}, {"getConstructors", (PyCFunction)&PyJPClass::getConstructors, METH_NOARGS, ""}, {"getDeclaredConstructors", (PyCFunction)&PyJPClass::getDeclaredConstructors, METH_NOARGS, ""}, {"getDeclaredFields", (PyCFunction)&PyJPClass::getDeclaredFields, METH_NOARGS, ""}, {"getDeclaredMethods", (PyCFunction)&PyJPClass::getDeclaredMethods, METH_NOARGS, ""}, {"getFields", (PyCFunction)&PyJPClass::getFields, METH_NOARGS, ""}, {"getMethods", (PyCFunction)&PyJPClass::getMethods, METH_NOARGS, ""}, {"getModifiers", (PyCFunction)&PyJPClass::getModifiers, METH_NOARGS, ""}, {NULL}, }; static PyTypeObject classClassType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "JavaClass", /*tp_name*/ sizeof(PyJPClass), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPClass::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Class", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ classMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPClass::initType(PyObject* module) { PyType_Ready(&classClassType); PyModule_AddObject(module, "_JavaClass", (PyObject*)&classClassType); } PyJPClass* PyJPClass::alloc(JPClass* cls) { PyJPClass* res = PyObject_New(PyJPClass, &classClassType); res->m_Class = cls; return res; } void PyJPClass::__dealloc__(PyObject* o) { TRACE_IN("PyJPClass::__dealloc__"); PyJPClass* self = (PyJPClass*)o; Py_TYPE(self)->tp_free(o); TRACE_OUT; } PyObject* PyJPClass::getName(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; JPTypeName name = self->m_Class->getName(); PyObject* res = JPyString::fromString(name.getSimpleName().c_str()); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getBaseClass(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; JPClass* base = self->m_Class->getSuperClass(); if (base == NULL) { Py_INCREF(Py_None); return Py_None; } PyObject* res = (PyObject*)PyJPClass::alloc(base); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getBaseInterfaces(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; const vector& baseItf = self->m_Class->getInterfaces(); PyObject* result = JPySequence::newTuple((int)baseItf.size()); for (unsigned int i = 0; i < baseItf.size(); i++) { JPClass* base = baseItf[i]; PyObject* obj = (PyObject*)PyJPClass::alloc(base); JPySequence::setItem(result, i, obj); } return result; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getClassFields(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; map staticFields = self->m_Class->getStaticFields(); map instFields = self->m_Class->getInstanceFields(); PyObject* res = JPySequence::newTuple((int)(staticFields.size()+instFields.size())); int i = 0; for (map::iterator curStatic = staticFields.begin(); curStatic != staticFields.end(); curStatic ++) { PyObject* f = (PyObject*)PyJPField::alloc(curStatic->second); JPySequence::setItem(res, i, f); i++; Py_DECREF(f); } for (map::iterator curInst = instFields.begin(); curInst != instFields.end(); curInst ++) { PyObject* f = (PyObject*)PyJPField::alloc(curInst->second); JPySequence::setItem(res, i, f); i++; Py_DECREF(f); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::getClassMethods(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; vector methods = self->m_Class->getMethods(); PyObject* res = JPySequence::newTuple((int)methods.size()); int i = 0; for (vector::iterator curMethod = methods.begin(); curMethod != methods.end(); curMethod ++) { JPMethod* mth= *curMethod; PyJPMethod* methObj = PyJPMethod::alloc(mth); JPySequence::setItem(res, i, (PyObject*)methObj); i++; Py_DECREF(methObj); } return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::newClassInstance(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; JPCleaner cleaner; //cout << "Creating a new " << self->m_Class->getName().getSimpleName() << endl; //JPyHelper::dumpSequenceRefs(arg, "Start"); vector args; Py_ssize_t len = JPyObject::length(arg); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(arg, i); HostRef* ref = new HostRef((void*)obj); cleaner.add(ref); args.push_back(ref); Py_DECREF(obj); } JPObject* resObject = self->m_Class->newInstance(args); PyObject* res = JPyCObject::fromVoidAndDesc((void*)resObject, "JPObject", &PythonHostEnvironment::deleteJPObjectDestructor); //JPyHelper::dumpSequenceRefs(arg, "End"); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::isInterface(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; if (self->m_Class->isInterface()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::isSubclass(PyObject* o, PyObject* arg) { try { PyJPClass* self = (PyJPClass*)o; char* other; JPyArg::parseTuple(arg, "s", &other); JPTypeName name = JPTypeName::fromSimple(other); JPClass* otherClass = JPTypeManager::findClass(name); if (self->m_Class->isSubclass(otherClass)) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPClass::isException(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; bool res = JPJni::isThrowable(self->m_Class->getClass()); if (res) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH; return NULL; } bool PyJPClass::check(PyObject* o) { return o->ob_type == &classClassType; } PyObject* PyJPClass::getDeclaredMethods(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getDeclaredMethods(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getConstructors(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getConstructors(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getDeclaredConstructors(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getDeclaredConstructors(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getDeclaredFields(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getDeclaredFields(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName fieldClassName = JPTypeName::fromSimple("java.lang.reflect.Field"); JPClass* fieldClass = JPTypeManager::findClass(fieldClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = fieldClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getFields(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getFields(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName fieldClassName = JPTypeName::fromSimple("java.lang.reflect.Field"); JPClass* fieldClass = JPTypeManager::findClass(fieldClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = fieldClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getModifiers(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; long mod = JPJni::getClassModifiers(self->m_Class->getClass()); PyObject* res = JPyLong::fromLongLong(mod); return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::getMethods(PyObject* o) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; vector mth = JPJni::getMethods(self->m_Class->getClass()); PyObject* res = JPySequence::newTuple((int)mth.size()); JPTypeName methodClassName = JPTypeName::fromSimple("java.lang.reflect.Method"); JPClass* methodClass = JPTypeManager::findClass(methodClassName); for (unsigned int i = 0; i < mth.size(); i++) { jvalue v; v.l = mth[i]; HostRef* ref = methodClass->asHostObject(v); cleaner.add(ref); JPySequence::setItem(res, i, (PyObject*)ref->data()); } return res; } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::isPrimitive(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; JPTypeName name = self->m_Class->getName(); if (name.isObjectType()) { return JPyBoolean::getFalse(); } return JPyBoolean::getTrue(); } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::isArray(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; JPTypeName name = self->m_Class->getName(); char c = name.getNativeName()[0]; if (c == '[') { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH; return NULL; } PyObject* PyJPClass::isAbstract(PyObject* o, PyObject* args) { try { JPCleaner cleaner; PyJPClass* self = (PyJPClass*)o; if (self->m_Class->isAbstract()) { return JPyBoolean::getTrue(); } else { return JPyBoolean::getFalse(); } } PY_STANDARD_CATCH; return NULL; } jpype-0.6.2+dfsg/native/python/py_field.cpp0000664000175000017500000001365313036015411020171 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include static PyMethodDef fieldMethods[] = { {"getName", &PyJPField::getName, METH_VARARGS, ""}, {"isFinal", &PyJPField::isFinal, METH_VARARGS, ""}, {"isStatic", &PyJPField::isStatic, METH_VARARGS, ""}, {"getStaticAttribute", &PyJPField::getStaticAttribute, METH_VARARGS, ""}, {"setStaticAttribute", &PyJPField::setStaticAttribute, METH_VARARGS, ""}, {"getInstanceAttribute", &PyJPField::getInstanceAttribute, METH_VARARGS, ""}, {"setInstanceAttribute", &PyJPField::setInstanceAttribute, METH_VARARGS, ""}, {NULL}, }; static PyTypeObject fieldClassType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "JavaField", /*tp_name*/ sizeof(PyJPField), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPField::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Field", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ fieldMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPField::initType(PyObject* module) { PyType_Ready(&fieldClassType); PyModule_AddObject(module, "_JavaField", (PyObject*)&fieldClassType); } PyJPField* PyJPField::alloc(JPField* m) { PyJPField* res = PyObject_New(PyJPField, &fieldClassType); res->m_Field = m; return res; } void PyJPField::__dealloc__(PyObject* o) { PyJPField* self = (PyJPField*)o; Py_TYPE(self)->tp_free(o); } PyObject* PyJPField::getName(PyObject* o, PyObject* arg) { try { PyJPField* self = (PyJPField*)o; string name = self->m_Field->getName(); PyObject* res = JPyString::fromString(name.c_str()); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::getStaticAttribute(PyObject* o, PyObject* arg) { try { PyJPField* self = (PyJPField*)o; HostRef* res = self->m_Field->getStaticAttribute(); PyObject* result = detachRef(res); return result; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::setStaticAttribute(PyObject* o, PyObject* arg) { try { PyJPField* self = (PyJPField*)o; PyObject* value; JPyArg::parseTuple(arg, "O", &value); HostRef v(value); self->m_Field->setStaticAttribute(&v); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::setInstanceAttribute(PyObject* o, PyObject* arg) { JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; PyObject* jo; PyObject* value; JPyArg::parseTuple(arg, "O!O", &PyCapsule_Type, &jo, &value); JPObject* obj = (JPObject*)JPyCObject::asVoidPtr(jo); HostRef* ref = new HostRef(value); cleaner.add(ref); jobject jobj = obj->getObject(); cleaner.addLocal(jobj); self->m_Field->setAttribute(jobj, ref); Py_INCREF(Py_None); return Py_None; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::getInstanceAttribute(PyObject* o, PyObject* arg) { TRACE_IN("getInstanceAttribute"); JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; PyObject* jo; JPyArg::parseTuple(arg, "O!", &PyCapsule_Type, &jo); JPObject* obj = (JPObject*)JPyCObject::asVoidPtr(jo); jobject jobj = obj->getObject(); cleaner.addLocal(jobj); HostRef* res = self->m_Field->getAttribute(jobj); return detachRef(res); } PY_STANDARD_CATCH return NULL; TRACE_OUT; } PyObject* PyJPField::isStatic(PyObject* o, PyObject* arg) { JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; if (self->m_Field->isStatic()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPField::isFinal(PyObject* o, PyObject* arg) { JPCleaner cleaner; try { PyJPField* self = (PyJPField*)o; if (self->m_Field->isFinal()) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } jpype-0.6.2+dfsg/native/python/py_hostenv.cpp0000664000175000017500000004112413036015411020566 0ustar takakitakaki/***************************************************************************** Copyright 2004-2008 Steve Menard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include #define UNWRAP(ref) ((PyObject*)ref->data()) #define GETDESC(ref) string((char*)JPyCObject::getDesc(UNWRAP(ref))) #define WRAP(ref, t) new HostRef( JPyCObject::fromVoidAndDesc(ref, t, NULL) ) #define IS_REF(ref, t) JPyCObject::check((PyObject*)ref) && GETDESC(ref) == t void* PythonHostEnvironment::acquireRef(void* d) { Py_XINCREF((PyObject*)d); return d; } void PythonHostEnvironment::releaseRef(void* d) { Py_XDECREF((PyObject*)d); } bool PythonHostEnvironment::isRefNull(void* d) { return d == NULL; } string PythonHostEnvironment::describeRef(HostRef* ref) { stringstream out; return out.str(); } void* PythonHostEnvironment::gotoExternal() { PyThreadState *_save; _save = PyEval_SaveThread(); return (void*)_save; } void PythonHostEnvironment::returnExternal(void* state) { PyThreadState *_save = (PyThreadState *)state; PyEval_RestoreThread(_save); } void PythonHostEnvironment::setRuntimeException(const char* msg) { JPyErr::setString(PyExc_RuntimeError, msg); } void PythonHostEnvironment::setAttributeError(const char* msg) { JPyErr::setString(PyExc_AttributeError, msg); } void PythonHostEnvironment::setTypeError(const char* msg) { JPyErr::setString(PyExc_TypeError, msg); } void PythonHostEnvironment::raise(const char* msg) { throw PythonException(); } HostRef* PythonHostEnvironment::getNone() { return new HostRef(Py_None); } bool PythonHostEnvironment::isNone(HostRef* ref) { return UNWRAP(ref) == Py_None; } bool PythonHostEnvironment::isBoolean(HostRef* ref) { return JPyBoolean::isTrue(UNWRAP(ref)) || JPyBoolean::isFalse(UNWRAP(ref)); } jboolean PythonHostEnvironment::booleanAsBoolean(HostRef* ref) { if (JPyBoolean::isTrue(UNWRAP(ref))) { return true; } return false; } HostRef* PythonHostEnvironment::getTrue() { return new HostRef(JPyBoolean::getTrue(), false); } HostRef* PythonHostEnvironment::getFalse() { return new HostRef(JPyBoolean::getFalse(), false); } bool PythonHostEnvironment::isSequence(HostRef* ref) { return JPySequence::check(UNWRAP(ref)) && ! JPyString::check(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newMutableSequence(jsize sz) { return new HostRef(JPySequence::newList(sz), false); } HostRef* PythonHostEnvironment::newImmutableSequence(jsize sz) { return new HostRef(JPySequence::newTuple(sz), false); } jsize PythonHostEnvironment::getSequenceLength(HostRef* ref) { return (jsize)JPyObject::length(UNWRAP(ref)); } HostRef* PythonHostEnvironment::getSequenceItem(HostRef* ref, jsize pos) { return new HostRef(JPySequence::getItem(UNWRAP(ref), pos), false); } void PythonHostEnvironment::setSequenceItem(HostRef* seq, jsize pos, HostRef* val) { JPySequence::setItem(UNWRAP(seq), pos, UNWRAP(val)); } bool PythonHostEnvironment::isInt(HostRef* res) { #if PY_MAJOR_VERSION >= 3 || LONG_MAX > 2147483647 return false; #else return JPyInt::check(UNWRAP(res)); #endif } HostRef* PythonHostEnvironment::newInt(jint v) { return new HostRef(JPyInt::fromLong(v), false); } jint PythonHostEnvironment::intAsInt(HostRef* res) { return JPyInt::asLong(UNWRAP(res)); } bool PythonHostEnvironment::isLong(HostRef* ref) { #if PY_MAJOR_VERSION < 3 || LONG_MAX > 2147483647 return JPyInt::check(UNWRAP(ref)) || JPyLong::check(UNWRAP(ref)); #else return JPyLong::check(UNWRAP(ref)); #endif } HostRef* PythonHostEnvironment::newLong(jlong v) { TRACE_IN("PythonHostEnvironment::newLong"); return new HostRef(JPyLong::fromLongLong(v), false); TRACE_OUT; } jlong PythonHostEnvironment::longAsLong(HostRef* ref) { #if PY_MAJOR_VERSION >= 3 return JPyLong::asLongLong(UNWRAP(ref)); #elif LONG_MAX > 2147483647 return JPyInt::check(UNWRAP(ref)) ? JPyInt::asLong(UNWRAP(ref)) : JPyLong::asLongLong(UNWRAP(ref)); #else return JPyLong::asLongLong(UNWRAP(ref)); #endif } bool PythonHostEnvironment::isFloat(HostRef* ref) { return JPyFloat::check(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newFloat(jdouble v) { return new HostRef(JPyFloat::fromDouble(v), false); } jdouble PythonHostEnvironment::floatAsDouble(HostRef* ref) { return JPyFloat::asDouble(UNWRAP(ref)); } bool PythonHostEnvironment::isMethod(HostRef* ref) { return IS_REF(ref, "JPMethod"); } HostRef* PythonHostEnvironment::newMethod(JPMethod* m) { return WRAP(m, "JPMethod"); } JPMethod* PythonHostEnvironment::asMethod(HostRef* ref) { return (JPMethod*)JPyCObject::asVoidPtr(UNWRAP(ref)); } bool PythonHostEnvironment::isObject(HostRef* ref) { PyObject* obj = UNWRAP(ref); if (JPyObject::isInstance(obj, m_JavaLangObject)) { return true; } return false; } JPObject* PythonHostEnvironment::asObject(HostRef* m) { PyObject* obj = (PyObject*)m->data(); if (JPyCObject::check(obj)) { return (JPObject*)JPyCObject::asVoidPtr(obj); } PyObject* javaObject = JPyObject::getAttrString(obj, "__javaobject__"); JPObject* res = (JPObject*)JPyCObject::asVoidPtr(javaObject); Py_DECREF(javaObject); return res; } HostRef* PythonHostEnvironment::newObject(JPObject* obj) { TRACE_IN("PythonHostEnvironment::newObject"); TRACE2("classname", obj->getClass()->getName().getSimpleName()); JPClass* jc = obj->getClass(); JPTypeName name = jc->getName(); PyObject* pyClass = getJavaShadowClass(jc); PyObject* args = JPySequence::newTuple(2); PyObject* arg2 = JPySequence::newTuple(1); JPySequence::setItem(arg2, 0, args); Py_DECREF(args); PyObject* joHolder = JPyCObject::fromVoidAndDesc((void*)obj, "JPObject", &deleteJPObjectDestructor); JPySequence::setItem(args, 0, m_SpecialConstructorKey); JPySequence::setItem(args, 1, joHolder); Py_DECREF(joHolder); PyObject* res = JPyObject::call(pyClass, arg2, NULL); Py_DECREF(arg2); return new HostRef(res, false); TRACE_OUT; } bool PythonHostEnvironment::isClass(HostRef* ref) { PyObject* self = UNWRAP(ref); if (! JPyType::check(self)) { // If its not a type ... it can;t be a java type return false; } return JPyType::isSubclass(self, m_JavaLangObject); } HostRef* PythonHostEnvironment::newClass(JPClass* m) { PyJPClass* co = PyJPClass::alloc(m); PyObject* args = JPySequence::newTuple(1); JPySequence::setItem(args, 0, (PyObject*)co); Py_DECREF(co); PyObject* pyClass = JPyObject::call(m_GetClassMethod, args, NULL); return new HostRef(pyClass, false); } JPClass* PythonHostEnvironment::asClass(HostRef* ref) { PyObject* self = UNWRAP(ref); PyObject* claz = JPyObject::getAttrString(self, "__javaclass__"); PyJPClass* res = (PyJPClass*)claz; Py_DECREF(claz); return res->m_Class; } bool PythonHostEnvironment::isArrayClass(HostRef* ref) { PyObject* self = UNWRAP(ref); if (! JPyType::check(self)) { // If its not a type ... it can;t be a java type return false; } return JPyType::isSubclass(self, m_JavaArrayClass); } HostRef* PythonHostEnvironment::newArrayClass(JPArrayClass* m) { PyObject* args = JPySequence::newTuple(1); PyObject* cname = JPyString::fromString(m->getName().getSimpleName().c_str()); JPySequence::setItem(args, 0, cname); Py_DECREF(cname); PyObject* pyClass = JPyObject::call(m_GetArrayClassMethod, args, NULL); return new HostRef(pyClass, false); } JPArrayClass* PythonHostEnvironment::asArrayClass(HostRef* ref) { PyObject* self = UNWRAP(ref); PyObject* claz = JPyObject::getAttrString(self, "__javaclass__"); JPArrayClass* res = (JPArrayClass*)JPyCObject::asVoidPtr(claz); Py_DECREF(claz); return res; } bool PythonHostEnvironment::isArray(HostRef* ref) { PyObject* obj = UNWRAP(ref); if (JPyObject::isInstance(obj, m_JavaArrayClass)) { return true; } return false; } HostRef* PythonHostEnvironment::newArray(JPArray* m) { JPArrayClass* jc = m->getClass(); JPTypeName name = jc->getName(); PyObject* args = JPySequence::newTuple(1); PyObject* cname = JPyString::fromString(name.getSimpleName().c_str()); JPySequence::setItem(args, 0, cname); Py_DECREF(cname); PyObject* pyClass = JPyObject::call(m_GetArrayClassMethod, args, NULL); Py_DECREF(args); PyObject* joHolder = JPyCObject::fromVoidAndDesc((void*)m, "JPArray", &deleteJPArrayDestructor); args = JPySequence::newTuple(2); JPySequence::setItem(args, 0, m_SpecialConstructorKey); JPySequence::setItem(args, 1, joHolder); Py_DECREF(joHolder); PyObject* res = JPyObject::call(pyClass, args, NULL); Py_DECREF(args); return new HostRef(res, false); } JPArray* PythonHostEnvironment::asArray(HostRef* ref) { PyObject* obj = UNWRAP(ref); PyObject* javaObject = JPyObject::getAttrString(obj, "__javaobject__"); JPArray* res = (JPArray*)JPyCObject::asVoidPtr(javaObject); Py_DECREF(javaObject); return res; } bool PythonHostEnvironment::isWrapper(HostRef* ref) { return JPyObject::isInstance(UNWRAP(ref), m_WrapperClass); } bool PythonHostEnvironment::isProxy(HostRef* ref) { return JPyObject::isInstance(UNWRAP(ref), m_ProxyClass); } JPProxy* PythonHostEnvironment::asProxy(HostRef* ref) { JPCleaner cleaner; PyObject* proxy = UNWRAP(ref); PyObject* jproxy = JPyObject::getAttrString(proxy, "_proxy"); cleaner.add(new HostRef(jproxy, false)); JPProxy* res = (JPProxy*)JPyCObject::asVoidPtr(jproxy); return res; } HostRef* PythonHostEnvironment::getCallableFrom(HostRef* ref, string& name) { JPCleaner cleaner; PyObject* pname = JPyString::fromString(name.c_str()); cleaner.add(new HostRef(pname, false)); PyObject* mname = JPyString::fromString("getCallable"); cleaner.add(new HostRef(mname, false)); PyObject* call = PyObject_CallMethodObjArgs(UNWRAP(ref), mname, pname, NULL); JPyErr::check(); return new HostRef(call, false); } bool PythonHostEnvironment::isString(HostRef* ref) { return JPyString::check(UNWRAP(ref)); } jsize PythonHostEnvironment::getStringLength(HostRef* ref) { return (jsize)JPyObject::length(UNWRAP(ref)); } string PythonHostEnvironment::stringAsString(HostRef* ref) { return JPyString::asString(UNWRAP(ref)); } JCharString PythonHostEnvironment::stringAsJCharString(HostRef* ref) { return JPyString::asJCharString(UNWRAP(ref)); } HostRef* PythonHostEnvironment::newStringFromUnicode(const jchar* v, unsigned int l) { TRACE_IN("PythonHostEnvironment::newStringFromUnicode"); return new HostRef(JPyString::fromUnicode(v, l), false); TRACE_OUT; } HostRef* PythonHostEnvironment::newStringFromASCII(const char* v, unsigned int l) { return new HostRef(JPyString::fromString(v), false); } void* PythonHostEnvironment::prepareCallbackBegin() { PyGILState_STATE state = PyGILState_Ensure();; return (void*)new PyGILState_STATE(state); } void PythonHostEnvironment::prepareCallbackFinish(void* state) { PyGILState_STATE* state2 = (PyGILState_STATE*)state; PyGILState_Release(*state2); delete state2; } HostRef* PythonHostEnvironment::callObject(HostRef* c, vector& args) { JPCleaner cleaner; PyObject* pargs = JPySequence::newTuple((int)args.size()); cleaner.add(new HostRef(pargs, false)); for (unsigned int i = 0; i < args.size(); i++) { JPySequence::setItem(pargs, i, UNWRAP(args[i])); } PyObject* res = JPyObject::call(UNWRAP(c), pargs, NULL); return new HostRef(res, false); } void PythonHostEnvironment::printError() { PyErr_Print(); PyErr_Clear(); } bool PythonHostEnvironment::mapContains(HostRef* mapping, HostRef* key) { return JPyDict::contains(UNWRAP(mapping), UNWRAP(key)); } HostRef* PythonHostEnvironment::getMapItem(HostRef* mapping, HostRef* key) { return new HostRef(JPyDict::getItem(UNWRAP(mapping), UNWRAP(key)), false); } bool PythonHostEnvironment::objectHasAttribute(HostRef* obj, HostRef* key) { return JPyObject::hasAttr(UNWRAP(obj), UNWRAP(key)); } HostRef* PythonHostEnvironment::getObjectAttribute(HostRef* obj, HostRef* key) { return new HostRef(JPyObject::getAttr(UNWRAP(obj), UNWRAP(key)), false); } bool PythonHostEnvironment::isJavaException(HostException* ex) { PythonException* pe = (PythonException*)ex; return JPyObject::isSubclass(pe->m_ExceptionClass, m_JavaExceptionClass); } HostRef* PythonHostEnvironment::getJavaException(HostException* ex) { PythonException* pe = (PythonException*)ex; PyObject* obj = pe->getJavaException(); PyObject* javaObject = JPyObject::getAttrString(obj, "__javaobject__"); return new HostRef(javaObject, false); } void PythonHostEnvironment::clearError() { PyErr_Clear(); } bool PythonHostEnvironment::isWrapper(PyObject* obj) { return JPyObject::isInstance(obj, m_WrapperClass); } JPTypeName PythonHostEnvironment::getWrapperTypeName(PyObject* obj) { PyObject* pyTName = JPyObject::getAttrString(obj, "typeName"); string tname = JPyString::asString(pyTName); Py_DECREF(pyTName); return JPTypeName::fromSimple(tname.c_str()); } jvalue PythonHostEnvironment::getWrapperValue(PyObject* obj) { JPTypeName name = getWrapperTypeName(obj); PyObject* value = JPyObject::getAttrString(obj, "_value"); jvalue* v = (jvalue*)JPyCObject::asVoidPtr(value); Py_DECREF(value); if (name.isObjectType()) { jvalue res; res.l = JPEnv::getJava()->NewGlobalRef(v->l); return res; } return *v; } JPTypeName PythonHostEnvironment::getWrapperTypeName(HostRef* obj) { return getWrapperTypeName(UNWRAP(obj)); } jvalue PythonHostEnvironment::getWrapperValue(HostRef* obj) { return getWrapperValue(UNWRAP(obj)); } PyObject* PythonHostEnvironment::getJavaShadowClass(JPClass* jc) { PyJPClass* cls = PyJPClass::alloc(jc); PyObject* args = JPySequence::newTuple(1); JPySequence::setItem(args, 0, (PyObject*)cls); Py_DECREF(cls); PyObject* res = JPyObject::call(m_GetClassMethod, args, NULL); Py_DECREF(args); return res; } bool PythonHostEnvironment::isByteString(HostRef* ref) { PyObject* obj = UNWRAP(ref); return JPyString::checkStrict(obj); } bool PythonHostEnvironment::isByteBuffer(HostRef* ref) { PyObject* obj = UNWRAP(ref); return JPyObject::isMemoryView(obj); } bool PythonHostEnvironment::isUnicodeString(HostRef* ref) { return JPyString::checkUnicode(UNWRAP(ref)); } void PythonHostEnvironment::getRawByteString(HostRef* obj, char** outBuffer, long& outSize) { PyObject* objRef = UNWRAP(obj); Py_ssize_t tempSize = 0; JPyString::AsStringAndSize(objRef, outBuffer, &tempSize); outSize = (long)tempSize; } void PythonHostEnvironment::getByteBufferPtr(HostRef* obj, char** outBuffer, long& outSize) { TRACE_IN("PythonHostEnvironment::getByteBufferPtr"); PyObject* objRef = UNWRAP(obj); Py_ssize_t tempSize = 0; JPyObject::AsPtrAndSize(objRef, outBuffer, &tempSize); outSize = (long)tempSize; TRACE_OUT; } void PythonHostEnvironment::getRawUnicodeString(HostRef* obj, jchar** outBuffer, long& outSize) { PyObject* objRef = UNWRAP(obj); outSize = (long)JPyObject::length(objRef); *outBuffer = (jchar*)JPyString::AsUnicode(objRef); } size_t PythonHostEnvironment::getUnicodeSize() { return sizeof(Py_UNICODE); } HostRef* PythonHostEnvironment::newStringWrapper(jstring jstr) { TRACE_IN("PythonHostEnvironment::newStringWrapper"); jvalue* v = new jvalue; v->l = jstr; PyObject* value = JPyCObject::fromVoidAndDesc((void*)v, "object jvalue", deleteObjectJValueDestructor); PyObject* args = JPySequence::newTuple(1); JPySequence::setItem(args, 0, Py_None); PyObject* res = JPyObject::call(m_StringWrapperClass, args, Py_None); Py_DECREF(args); JPyObject::setAttrString(res, "_value", value); Py_DECREF(value); HostRef* resRef = new HostRef(res); Py_DECREF(res); return resRef; TRACE_OUT; } void PythonHostEnvironment::printReferenceInfo(HostRef* obj) { PyObject* pobj = UNWRAP(obj); cout << "Object info report" << endl; cout << " obj type " << pobj->ob_type->tp_name << endl; cout << " Ref count " << (long)pobj->ob_refcnt << endl; } jpype-0.6.2+dfsg/native/python/py_method.cpp0000664000175000017500000002477713036015411020377 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve M�nard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include static PyMethodDef methodMethods[] = { {"getName", &PyJPMethod::getName, METH_VARARGS, ""}, {"isBeanAccessor", &PyJPMethod::isBeanAccessor, METH_VARARGS, ""}, {"isBeanMutator", &PyJPMethod::isBeanMutator, METH_VARARGS, ""}, {"matchReport", &PyJPMethod::matchReport, METH_VARARGS, ""}, {NULL}, }; static PyTypeObject methodClassType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "JavaMethod", /*tp_name*/ sizeof(PyJPMethod), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPMethod::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ PyJPMethod::__call__, /*tp_call*/ PyJPMethod::__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Method", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ methodMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPMethod::initType(PyObject* module) { PyType_Ready(&methodClassType); PyModule_AddObject(module, "_JavaMethod", (PyObject*)&methodClassType); } PyJPMethod* PyJPMethod::alloc(JPMethod* m) { PyJPMethod* res = PyObject_New(PyJPMethod, &methodClassType); res->m_Method = m; return res; } PyObject* PyJPMethod::__call__(PyObject* o, PyObject* args, PyObject* kwargs) { TRACE_IN("PyJPMethod::__call__"); try { PyJPMethod* self = (PyJPMethod*)o; TRACE1(self->m_Method->getName()); JPCleaner cleaner; //JPyHelper::dumpSequenceRefs(args, "start"); vector vargs; Py_ssize_t len = JPyObject::length(args); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); // return a new ref HostRef* ref = new HostRef((void*)obj); cleaner.add(ref); vargs.push_back(ref); Py_DECREF(obj); // delete the new ref returned by getItem } //JPyHelper::dumpSequenceRefs(args, "middle"); HostRef* res = self->m_Method->invoke(vargs); //JPyHelper::dumpSequenceRefs(args, "end"); return detachRef(res); } PY_STANDARD_CATCH return NULL; TRACE_OUT; } void PyJPMethod::__dealloc__(PyObject* o) { PyJPMethod* self = (PyJPMethod*)o; Py_TYPE(self)->tp_free(o); } PyObject* PyJPMethod::__str__(PyObject* o) { PyJPMethod* self = (PyJPMethod*)o; stringstream sout; sout << "m_Method->getClassName() << "." << self->m_Method->getName() << ">"; return JPyString::fromString(sout.str().c_str()); } PyObject* PyJPMethod::isBeanAccessor(PyObject* o, PyObject* arg) { try { PyJPMethod* self = (PyJPMethod*)o; bool res = self->m_Method->isBeanAccessor(); if (res) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPMethod::isBeanMutator(PyObject* o, PyObject* arg) { try { PyJPMethod* self = (PyJPMethod*)o; bool res = self->m_Method->isBeanMutator(); if (res) { return JPyBoolean::getTrue(); } return JPyBoolean::getFalse(); } PY_STANDARD_CATCH return NULL; } PyObject* PyJPMethod::getName(PyObject* o, PyObject* arg) { try { PyJPMethod* self = (PyJPMethod*)o; string name = self->m_Method->getName(); PyObject* res = JPyString::fromString(name.c_str()); return res; } PY_STANDARD_CATCH return NULL; } PyObject* PyJPMethod::matchReport(PyObject* o, PyObject* args) { try { PyJPMethod* self = (PyJPMethod*)o; JPCleaner cleaner; vector vargs; Py_ssize_t len = JPyObject::length(args); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); HostRef* ref = new HostRef((void*)obj); cleaner.add(ref); vargs.push_back(ref); Py_DECREF(obj); } string report = self->m_Method->matchReport(vargs); PyObject* res = JPyString::fromString(report.c_str()); return res; } PY_STANDARD_CATCH return NULL; } static PyMethodDef boundMethodMethods[] = { {"matchReport", &PyJPBoundMethod::matchReport, METH_VARARGS, ""}, {NULL}, }; static PyTypeObject boundMethodClassType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "JavaBoundMethod", /*tp_name*/ sizeof(PyJPBoundMethod), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPBoundMethod::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ PyJPBoundMethod::__call__, /*tp_call*/ PyJPBoundMethod::__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Bound Method", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ boundMethodMethods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ PyJPBoundMethod::__init__, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPBoundMethod::initType(PyObject* module) { PyType_Ready(&boundMethodClassType); PyModule_AddObject(module, "_JavaBoundMethod", (PyObject*)&boundMethodClassType); } int PyJPBoundMethod::__init__(PyObject* o, PyObject* args, PyObject* kwargs) { try { PyJPBoundMethod* self = (PyJPBoundMethod*)o; PyObject* javaMethod; PyObject* inst; JPyArg::parseTuple(args, "OO", &javaMethod, &inst); Py_INCREF(inst); Py_INCREF(javaMethod); self->m_Instance = inst; self->m_Method = (PyJPMethod*)javaMethod; return 0; } PY_STANDARD_CATCH return -1; } PyObject* PyJPBoundMethod::__call__(PyObject* o, PyObject* args, PyObject* kwargs) { TRACE_IN("PyJPBoundMethod::__call__"); try { PyObject* result=NULL; { PyJPBoundMethod* self = (PyJPBoundMethod*)o; JPCleaner cleaner; TRACE1(self->m_Method->m_Method->getName()); vector vargs; Py_ssize_t len = JPyObject::length(args); HostRef* ref = new HostRef((void*)self->m_Instance); cleaner.add(ref); vargs.push_back(ref); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); // returns a new ref ref = new HostRef((void*)obj); cleaner.add(ref); vargs.push_back(ref); Py_DECREF(obj); // remove ref returned by getItem } HostRef* res = self->m_Method->m_Method->invoke(vargs); TRACE2("Call finished, result = ", res); result = detachRef(res); TRACE1("Cleaning up"); } return result; } PY_STANDARD_CATCH return NULL; TRACE_OUT; } void PyJPBoundMethod::__dealloc__(PyObject* o) { TRACE_IN("PyJPBoundMethod::__dealloc__"); PyJPBoundMethod* self = (PyJPBoundMethod*)o; Py_XDECREF(self->m_Instance); Py_XDECREF(self->m_Method); Py_TYPE(self)->tp_free(o); TRACE1("Method freed"); TRACE_OUT; } PyObject* PyJPBoundMethod::__str__(PyObject* o) { PyJPBoundMethod* self = (PyJPBoundMethod*)o; stringstream sout; sout << "m_Method->m_Method->getClassName() << "." << self->m_Method->m_Method->getName() << ">"; return JPyString::fromString(sout.str().c_str()); } PyObject* PyJPBoundMethod::matchReport(PyObject* o, PyObject* args) { try { PyJPBoundMethod* self = (PyJPBoundMethod*)o; cout << "Match report for " << self->m_Method->m_Method->getName() << endl; vector vargs; Py_ssize_t len = JPyObject::length(args); for (Py_ssize_t i = 0; i < len; i++) { PyObject* obj = JPySequence::getItem(args, i); vargs.push_back(new HostRef((void*)obj)); Py_DECREF(obj); } string report = self->m_Method->m_Method->matchReport(vargs); PyObject* res = JPyString::fromString(report.c_str()); return res; } PY_STANDARD_CATCH return NULL; } jpype-0.6.2+dfsg/native/python/py_monitor.cpp0000664000175000017500000000612013036015411020564 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include static PyMethodDef methods[] = { {NULL}, }; static PyTypeObject monitorClassType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "JavaMonitor", /*tp_name*/ sizeof(PyJPMonitor), /*tp_basicsize*/ 0, /*tp_itemsize*/ PyJPMonitor::__dealloc__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ PyJPMonitor::__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ "Java Monitor", /*tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew /* tp_new */ }; // Static methods void PyJPMonitor::initType(PyObject* module) { PyType_Ready(&monitorClassType); } PyJPMonitor* PyJPMonitor::alloc(JPMonitor* o) { PyJPMonitor* res = PyObject_New(PyJPMonitor, &monitorClassType); res->state = o; return res; } void PyJPMonitor::__dealloc__(PyObject* o) { PyJPMonitor* self = (PyJPMonitor*)o; delete self->state; Py_TYPE(self)->tp_free(o); } PyObject* PyJPMonitor::__str__(PyObject* o) { // TODO JPyErr::setString(PyExc_RuntimeError, "__str__ Not implemented"); return NULL; } jpype-0.6.2+dfsg/native/python/pythonenv.cpp0000664000175000017500000002622713036015411020431 0ustar takakitakaki/***************************************************************************** Copyright 2004 Steve Ménard Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *****************************************************************************/ #include #define PY_CHECK(op) op; { PyObject* __ex = PyErr_Occurred(); if (__ex) { throw PythonException(); }}; bool JPyString::check(PyObject* obj) { return PyBytes_Check(obj) || PyUnicode_Check(obj); } bool JPyString::checkStrict(PyObject* obj) { return PyBytes_Check(obj); } bool JPyString::checkUnicode(PyObject* obj) { return PyUnicode_Check(obj); } Py_UNICODE* JPyString::AsUnicode(PyObject* obj) { return PyUnicode_AsUnicode(obj); } string JPyString::asString(PyObject* obj) { TRACE_IN("JPyString::asString"); #if PY_MAJOR_VERSION < 3 PY_CHECK( string res = string(PyBytes_AsString(obj)) ); #else PyObject* val; bool needs_decref = false; if(PyUnicode_Check(obj)) { val = PyUnicode_AsEncodedString(obj, "UTF-8", "strict"); needs_decref = true; } else { val = obj; } PY_CHECK( string res = string(PyBytes_AsString(val)) ); if(needs_decref) { Py_DECREF(val); } #endif return res; TRACE_OUT; } JCharString JPyString::asJCharString(PyObject* obj) { PyObject* torelease = NULL; TRACE_IN("JPyString::asJCharString"); if (PyBytes_Check(obj)) { PY_CHECK( obj = PyUnicode_FromObject(obj) ); torelease = obj; } Py_UNICODE* val = PyUnicode_AS_UNICODE(obj); Py_ssize_t length = JPyObject::length(obj); JCharString res(length); for (int i = 0; val[i] != 0; i++) { res[i] = (jchar)val[i]; } if (torelease != NULL) { Py_DECREF(torelease); } return res; TRACE_OUT; } PyObject* JPyString::fromUnicode(const jchar* str, int len) { Py_UNICODE* value = new Py_UNICODE[len+1]; value[len] = 0; for (int i = 0; i < len; i++) { value[i] = (Py_UNICODE)str[i]; } PY_CHECK( PyObject* obj = PyUnicode_FromUnicode(value, len) ); delete[] value; return obj; } PyObject* JPyString::fromString(const char* str) { #if PY_MAJOR_VERSION < 3 PY_CHECK( PyObject* obj = PyString_FromString(str) ); return obj; #else PY_CHECK( PyObject* bytes = PyBytes_FromString(str) ); PY_CHECK( PyObject* unicode = PyUnicode_FromEncodedObject(bytes, "UTF-8", "strict") ); Py_DECREF(bytes); return unicode; #endif } Py_ssize_t JPyString::AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length) { PY_CHECK( Py_ssize_t res = PyBytes_AsStringAndSize(obj, buffer, length) ); return res; } PyObject* JPySequence::newTuple(Py_ssize_t sz) { PY_CHECK( PyObject* res = PyTuple_New(sz);); return res; } PyObject* JPySequence::newList(Py_ssize_t sz) { PY_CHECK( PyObject* res = PyList_New(sz);); return res; } void JPySequence::setItem(PyObject* lst, Py_ssize_t ndx, PyObject* val) { if (PyList_Check(lst)) { Py_XINCREF(val); PY_CHECK( PyList_SetItem(lst, ndx, val) ); } else if (PyTuple_Check(lst)) { Py_XINCREF(val); PY_CHECK( PyTuple_SetItem(lst, ndx, val) ); } else { Py_XINCREF(val); PY_CHECK( PySequence_SetItem(lst, ndx, val) ); } } bool JPySequence::check(PyObject* obj) { if (PySequence_Check(obj) || PyList_Check(obj) || PyTuple_Check(obj)) { return true; } return false; } PyObject* JPySequence::getItem(PyObject* tuple, Py_ssize_t ndx) { PY_CHECK( PyObject* res = PySequence_GetItem(tuple, ndx) ); return res; } Py_ssize_t JPyObject::length(PyObject* obj) { PY_CHECK( Py_ssize_t res = PyObject_Length(obj) ); return res; } bool JPyObject::hasAttr(PyObject* m, PyObject* k) { PY_CHECK( int res = PyObject_HasAttr(m, k) ); if (res) return true; return false; } PyObject* JPyObject::getAttr(PyObject* m, PyObject* k) { PY_CHECK( PyObject* res = PyObject_GetAttr(m, k) ); return res; } PyObject* JPyObject::getAttrString(PyObject* m, const char* k) { PY_CHECK( PyObject* res = PyObject_GetAttrString(m, (char*)k) ); return res; } void JPyObject::setAttrString(PyObject* m, const char* k, PyObject *v) { PY_CHECK( PyObject_SetAttrString(m, (char*)k, v ) ); } PyObject* JPyObject::call(PyObject* c, PyObject* a, PyObject* w) { PY_CHECK( PyObject* res = PyObject_Call(c, a, w) ); return res; } bool JPyObject::isInstance(PyObject* obj, PyObject* t) { PY_CHECK( int res = PyObject_IsInstance(obj, t) ); if (res) { return true; } return false; } bool JPyObject::isSubclass(PyObject* obj, PyObject* t) { int res = PyObject_IsSubclass(obj, t); if (res) { return true; } return false; } bool JPyObject::isMemoryView(PyObject* obj) { PY_CHECK( int res = PyMemoryView_Check(obj) ); if (res) { return true; } return false; } void JPyObject::AsPtrAndSize(PyObject *obj, char **buffer, Py_ssize_t *length) { TRACE_IN("JPyObject::AsPtrAndSize"); PY_CHECK( Py_buffer* py_buf = PyMemoryView_GET_BUFFER(obj) ); *buffer = (char*)py_buf->buf; *length = py_buf->len; TRACE_OUT; } void JPyErr::setString(PyObject* exClass, const char* str) { PyErr_SetString(exClass, str); } void JPyErr::setObject(PyObject* exClass, PyObject* str) { PyErr_SetObject(exClass, str); } PyObject* JPyInt::fromLong(long l) { TRACE_IN("JPyInt::fromLong"); PY_CHECK( PyObject* res = PyInt_FromLong(l) ); return res; TRACE_OUT; } bool JPyInt::check(PyObject* obj) { return PyInt_Check(obj); } long JPyInt::asLong(PyObject* obj) { return PyInt_AsLong(obj); } PyObject* JPyLong::fromLongLong(PY_LONG_LONG l) { TRACE_IN("JPyLong::fromLongLong"); PY_CHECK( PyObject* res = PyLong_FromLongLong(l) ); return res; TRACE_OUT; } bool JPyLong::check(PyObject* obj) { return PyLong_Check(obj); } PY_LONG_LONG JPyLong::asLongLong(PyObject* obj) { return PyLong_AsLongLong(obj); } PyObject* JPyFloat::fromDouble(double l) { PY_CHECK( PyObject* res = PyFloat_FromDouble(l) ); return res; } bool JPyFloat::check(PyObject* obj) { return PyFloat_Check(obj); } double JPyFloat::asDouble(PyObject* obj) { return PyFloat_AsDouble(obj); } PyObject* JPyBoolean::getTrue() { return PyInt_FromLong(1); } PyObject* JPyBoolean::getFalse() { return PyInt_FromLong(0); } bool JPyDict::contains(PyObject* m, PyObject* k) { PY_CHECK( int res = PyMapping_HasKey(m, k) ); if (res) return true; return false; } PyObject* JPyDict::getItem(PyObject* m, PyObject* k) { PY_CHECK( PyObject* res = PyDict_GetItem(m, k) ); Py_XINCREF(res); return res; } bool JPyDict::check(PyObject* obj) { return PyDict_Check(obj); } PyObject* JPyDict::getKeys(PyObject* m) { PY_CHECK( PyObject* res = PyDict_Keys(m) ); return res; } PyObject* JPyDict::copy(PyObject* m) { PY_CHECK( PyObject* res = PyDict_Copy(m) ); return res; } PyObject* JPyDict::newInstance() { PY_CHECK( PyObject* res = PyDict_New() ); return res; } void JPyDict::setItemString(PyObject* d, PyObject* o, const char* n) { PY_CHECK( PyDict_SetItemString(d, n, o) ); } PythonException::PythonException() { TRACE_IN("PythonException::PythonException"); PyObject* traceback; PyErr_Fetch(&m_ExceptionClass, &m_ExceptionValue, &traceback); Py_INCREF(m_ExceptionClass); Py_XINCREF(m_ExceptionValue); PyObject* name = JPyObject::getAttrString(m_ExceptionClass, "__name__"); string ascname = JPyString::asString(name); TRACE1(ascname); Py_DECREF(name); TRACE1(m_ExceptionValue->ob_type->tp_name); /*if (JPySequence::check(m_ExceptionValue)) { }*/ PyErr_Restore(m_ExceptionClass, m_ExceptionValue, traceback); TRACE_OUT; } PythonException::PythonException(const PythonException& ex) { m_ExceptionClass = ex.m_ExceptionClass; Py_INCREF(m_ExceptionClass); m_ExceptionValue = ex.m_ExceptionValue; Py_INCREF(m_ExceptionValue); } PythonException::~PythonException() { Py_XDECREF(m_ExceptionClass); Py_XDECREF(m_ExceptionValue); } PyObject* PythonException::getJavaException() { PyObject* retVal = NULL; // If the exception was caught further down ... if (JPySequence::check(m_ExceptionValue) && JPyObject::length(m_ExceptionValue) == 1) { PyObject* v0 = JPySequence::getItem(m_ExceptionValue, 0); if (JPySequence::check(v0) && JPyObject::length(v0) == 2) { PyObject* v00 = JPySequence::getItem(v0, 0); PyObject* v01 = JPySequence::getItem(v0, 1); if (v00 == hostEnv->getSpecialConstructorKey()) { retVal = v01; } else { Py_DECREF(v01); } Py_DECREF(v00); } else { Py_DECREF(v0); } } else { Py_XINCREF(m_ExceptionValue); retVal = m_ExceptionValue; } return retVal; } string PythonException::getMessage() { string message = ""; // Exception class name PyObject* className = JPyObject::getAttrString(m_ExceptionClass, "__name__"); message += JPyString::asString(className); Py_DECREF(className); // Exception value if(m_ExceptionValue) { // Convert the exception value to string PyObject* pyStrValue = PyObject_Str(m_ExceptionValue); if(pyStrValue) { message += ": " + JPyString::asString(pyStrValue); Py_DECREF(pyStrValue); } } return message; } PyObject* JPyCObject::fromVoid(void* data, PyCapsule_Destructor destr) { PY_CHECK( PyObject* res = PyCapsule_New(data, (char *)NULL, destr) ); return res; } PyObject* JPyCObject::fromVoidAndDesc(void* data, const char* desc, PyCapsule_Destructor destr) { PY_CHECK( PyObject* res = PyCapsule_New(data, desc, destr) ); return res; } void* JPyCObject::asVoidPtr(PyObject* obj) { PY_CHECK( void* res = PyCapsule_GetPointer(obj, PyCapsule_GetName(obj)) ); return res; } void* JPyCObject::getDesc(PyObject* obj) { PY_CHECK( void* res = (void*)PyCapsule_GetName(obj) ); return res; } bool JPyCObject::check(PyObject* obj) { return PyCapsule_CheckExact(obj); } bool JPyType::check(PyObject* obj) { return PyType_Check(obj); } bool JPyType::isSubclass(PyObject* o1, PyObject* o2) { if (PyType_IsSubtype((PyTypeObject*)o1, (PyTypeObject*)o2)) { return true; } return false; } void JPyHelper::dumpSequenceRefs(PyObject* seq, const char* comment) { cerr << "Dumping sequence state at " << comment << endl; cerr << " sequence has " << (long)seq->ob_refcnt << " reference(s)" << endl; Py_ssize_t dx = PySequence_Length(seq); for (Py_ssize_t i = 0; i < dx; i++) { PyObject* el = PySequence_GetItem(seq, i); Py_XDECREF(el); // PySequence_GetItem return a new ref cerr << " item[" << (long)i << "] has " << (long)el->ob_refcnt << " references" << endl; } } jpype-0.6.2+dfsg/setup.py0000664000175000017500000001450013036015411014565 0ustar takakitakaki#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys import codecs import platform from glob import glob import warnings from setuptools import setup from setuptools import Extension from setuptools.command.build_ext import build_ext """ this parameter is used to opt out numpy support in _jpype library """ if "--disable-numpy" in sys.argv: disabled_numpy = True sys.argv.remove("--disable-numpy") else: disabled_numpy = False class FeatureNotice(Warning): """ indicate notices about features """ pass def read_utf8(*parts): filename = os.path.join(os.path.dirname(__file__), *parts) return codecs.open(filename, encoding='utf-8').read() def find_sources(): cpp_files = [] for dirpath, dirnames, filenames in os.walk('native'): for filename in filenames: if filename.endswith('.cpp') or filename.endswith('.c'): cpp_files.append(os.path.join(dirpath, filename)) return cpp_files platform_specific = { 'include_dirs': [ os.path.join('native', 'common', 'include'), os.path.join('native', 'python', 'include'), ], 'sources': find_sources(), } fallback_jni = os.path.join('native', 'jni_include') # try to include JNI first from eventually given JAVA_HOME, then from distributed java_home = os.getenv('JAVA_HOME', '') found_jni = False if os.path.exists(java_home): platform_specific['include_dirs'] += [os.path.join(java_home, 'include')] # check if jni.h can be found for d in platform_specific['include_dirs']: if os.path.exists(os.path.join(d, 'jni.h')): found_jni = True break if not found_jni: import warnings warnings.warn('Falling back to provided JNI headers, since your provided' ' JAVA_HOME "%s" does not provide jni.h' % java_home) platform_specific['include_dirs'] += [fallback_jni] else: platform_specific['include_dirs'] += [fallback_jni] if sys.platform == 'win32': platform_specific['libraries'] = ['Advapi32'] platform_specific['define_macros'] = [('WIN32', 1)] jni_md_platform = 'win32' elif sys.platform == 'darwin': platform_specific['libraries'] = ['dl'] platform_specific['define_macros'] = [('MACOSX', 1)] jni_md_platform = 'darwin' elif sys.platform.startswith('linux'): platform_specific['libraries'] = ['dl'] jni_md_platform = 'linux' elif sys.platform.startswith('freebsd'): jni_md_platform = 'freebsd' else: warnings.warn("Your platform is not being handled explicitly." " It may work or not!", UserWarning) if found_jni: platform_specific['include_dirs'] += \ [os.path.join(java_home, 'include', jni_md_platform)] # include this stolen from FindJNI.cmake """ FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH}/win32 ${JAVA_INCLUDE_PATH}/linux ${JAVA_INCLUDE_PATH}/freebsd ${JAVA_INCLUDE_PATH}/solaris ${JAVA_INCLUDE_PATH}/hp-ux ${JAVA_INCLUDE_PATH}/alpha )""" jpypeLib = Extension(name='_jpype', **platform_specific) class my_build_ext(build_ext): """ Override some behavior in extension building: 1. Numpy: If not opted out, try to use NumPy and define macro 'HAVE_NUMPY', so arrays returned from Java can be wrapped efficiently in a ndarray. 2. handle compiler flags for different compilers via a dictionary. 3. try to disable warning ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ """ # extra compile args copt = {'msvc': ['/EHsc'], 'unix' : ['-ggdb'], 'mingw32' : [], } # extra link args lopt = { 'msvc': [], 'unix': [], 'mingw32' : [], } def initialize_options(self, *args): """omit -Wstrict-prototypes from CFLAGS since its only valid for C code.""" import distutils.sysconfig cfg_vars = distutils.sysconfig.get_config_vars() if 'CFLAGS' in cfg_vars: cfg_vars['CFLAGS'] = cfg_vars['CFLAGS'].replace('-Wstrict-prototypes', '') build_ext.initialize_options(self) def _set_cflags(self): # set compiler flags c = self.compiler.compiler_type if c in self.copt: for e in self.extensions: e.extra_compile_args = self.copt[ c ] if c in self.lopt: for e in self.extensions: e.extra_link_args = self.lopt[ c ] def build_extensions(self): self._set_cflags() # handle numpy if not disabled_numpy: try: import numpy jpypeLib.define_macros.append(('HAVE_NUMPY', 1)) jpypeLib.include_dirs.append(numpy.get_include()) warnings.warn("Turned ON Numpy support for fast Java array access", FeatureNotice) except ImportError: pass else: warnings.warn("Turned OFF Numpy support for fast Java array access", FeatureNotice) # has to be last call build_ext.build_extensions(self) setup( name='JPype1', version='0.6.2', description='A Python to Java bridge.', long_description=(read_utf8('README.rst') + '\n\n' + read_utf8('doc/CHANGELOG.rst') + '\n\n' + read_utf8('AUTHORS.rst')), license='License :: OSI Approved :: Apache Software License', author='Steve Menard', author_email='devilwolf@users.sourceforge.net', maintainer='Luis Nell', maintainer_email='cooperate@originell.org', url='https://github.com/originell/jpype/', platforms=[ 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows :: Windows 7', 'Operating System :: Microsoft :: Windows :: Windows Vista', 'Operating System :: POSIX :: Linux', ], classifiers=[ 'Programming Language :: Java', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', ], packages=[ 'jpype', 'jpype.awt', 'jpype.awt.event', 'jpypex', 'jpypex.swing'], package_dir={ 'jpype': 'jpype', 'jpypex': 'jpypex', }, extras_require = {'numpy' : ['numpy>=1.6']}, cmdclass={'build_ext': my_build_ext}, zip_safe=False, ext_modules=[jpypeLib], ) jpype-0.6.2+dfsg/test-requirements-py3.txt0000664000175000017500000000001413036015411020020 0ustar takakitakakimock==1.0.1 jpype-0.6.2+dfsg/test-requirements.txt0000664000175000017500000000003313036015411017310 0ustar takakitakakiunittest2==0.8 mock==1.0.1 jpype-0.6.2+dfsg/test/0000775000175000017500000000000013036015411014032 5ustar takakitakakijpype-0.6.2+dfsg/test/buf_leak_test.py0000664000175000017500000000110513036015411017210 0ustar takakitakakifrom jpype import * import time remote_pack="c:/tools/netbeean-remote-pack" profiler_options = [ "-agentpath:%s/lib/deployed/jdk15/windows/profilerinterface.dll=%s/lib,5140" % (remote_pack, remote_pack) ] options = [ '-verbose:gc', '-Xmx16m', ] #+ profiler_options startJVM(getDefaultJVMPath(), *options) class MyStr(str): def __del__(self): print 'string got deleted' while True: buf = java.lang.String('5' * 1024 * 1024 * 5) buf = nio.convertToDirectBuffer(MyStr('5' * 1024 * 1024)) # time.sleep(1) jpype-0.6.2+dfsg/test/buf_leak_test3.py0000664000175000017500000000256613036015411017307 0ustar takakitakakifrom jpype import * import time remote_pack="c:/tools/netbeean-remote-pack" profiler_options = [ "-agentpath:%s/lib/deployed/jdk15/windows/profilerinterface.dll=%s/lib,5140" % (remote_pack, remote_pack) ] options = [ #'-verbose:gc', '-Xmx64m', '-Djava.class.path=classes' ] #+ profiler_options cnt = 0 #setUsePythonThreadForDeamon(True) startJVM(getDefaultJVMPath(), *options) class MyStr(str): def __init__ (self, val): str.__init__(self, val) global cnt cnt += 1 print 'created string', cnt def __del__(self): global cnt cnt -= 1 print 'deleted string', cnt receive = JClass("jpype.nio.NioReceive") while True: # everything runs great with this line uncommented #p = JString('5' * 1024 * 1024) # with this line uncommented, the python strings aren't GC'd p = java.lang.StringBuffer(MyStr('5' * 1024 * 1024)) # with this line uncommented, the JVM throws an OutOfMemoryError (not GC'ing the proxied java objects?), # but the python strings are being GC'd #p = java.lang.StringBuffer(JString(MyStr('5' * 1024 * 1024))) # # forget the direct buffer for now.... # buf = nio.convertToDirectBuffer(MyStr('5' * 1024 * 1024 * 5)) try : receive.receiveBufferWithException(buf) except : pass jpype-0.6.2+dfsg/test/build.xml0000664000175000017500000000076313036015411015661 0ustar takakitakaki jpype-0.6.2+dfsg/test/convtest.py0000664000175000017500000000645613036015411016264 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype import array import time import os def generateStringData(aSize): return ''.join(['a']*aSize) DATA_SIZE = 5*1024*1024 # 5 MB def runBaseline(data): print 'Running baseline test : converting a python string->array.array->JArray(JByte). size = ', len(data)/1024.0, 'kb' print ' Start time (no optimize) on my machine is 3.56 seconds.' start = time.time() #darr = array.array('b', DATA) arr_cls = jpype.JArray(jpype.JByte) java_arr = arr_cls(DATA) end = time.time() print ' test run in', (end-start), 'seconds.' def runStringToByteBuffer(data): print 'Running String conversion to byte buffer. size = ', len(data)/1024.0, 'kb' start = time.time() bb = jpype.nio.convertToDirectBuffer(data) end = time.time() print ' test run in', (end-start), 'seconds.' jpype.JPackage("jpype").nio.NioReceive.receiveBuffer(bb) def runStringToByteArray(data): print 'Running String conversion to byte array. size = ', len(data)/1024.0, 'kb' start = time.time() arr_cls = jpype.JArray(jpype.JByte) java_arr = arr_cls(data) end = time.time() print ' test run in', (end-start), 'seconds.' root = os.path.abspath(os.path.dirname(__file__)) jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Xmx5M", "-verbose:gc", "-Djava.class.path=./classes%s%s%sclasses" % (os.pathsep, root, os.sep)) DELETED = False class MyStr(str): def __del__(self): global DELETED print 'string got deleted' DELETED = True def testStringMemory(): print 'with keeping the data' data = MyStr('5' * 1024) print data buf = jpype.nio.convertToDirectBuffer(data) # print buf.get() # print buf.get() # print buf.get() print 'now deleting the data' del data # print buf.get() # print buf.get() # print buf.get() # print buf.get() print 'now deleting the buffer itself' del buf print 'now waiting for the string to get deleted' while not DELETED: time.sleep(1) print '.', jpype.JPackage("jpype").nio.NioReceive.allocSomeMemory() testStringMemory() #for i in range(1,5) : # DATA = generateStringData(DATA_SIZE*i) # runBaseline(DATA) # runStringToByteBuffer(DATA) # runStringToByteArray(DATA) # expressly delete data to test the GC ... #del DATA #for i in range(3) : # print 'GC', i # jpype.JClass("java.lang.System").gc(); # time.sleep(15) jpype.shutdownJVM() jpype-0.6.2+dfsg/test/findjvm.py0000664000175000017500000000156613036015411016051 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype, os.path jvmlib = jpype.getDefaultJVMPath() print os.path.dirname(os.path.dirname(jvmlib)) jpype-0.6.2+dfsg/test/harness/0000775000175000017500000000000013036015411015475 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/0000775000175000017500000000000013036015411016624 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/array/0000775000175000017500000000000013036015411017742 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/array/Test2.java0000664000175000017500000000026213036015411021606 0ustar takakitakakipackage jpype.array; public class Test2 { public Object[] getValue() { return new Object[0]; } public Object test(Object o) { return null; } }jpype-0.6.2+dfsg/test/harness/jpype/array/TestArray.java0000664000175000017500000000255013036015411022525 0ustar takakitakaki// ***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.array; public class TestArray { public TestArray() { } public int[] i = {12234,1234,234,1324,424,234,234,142,5,251,242,35,235,62,1235,46,245132,51, 2, 3, 4}; public Object[] getSubClassArray() { return new String[] { "aaa", "bbb" }; } public Object getArrayAsObject() { return new String[] { "aaa", "bbb" }; } public char[] getCharArray() { return new char[] { 'a', 'v', 'c', 'd' }; } public byte[] getByteArray() { String s = "avcd"; return s.getBytes(); } }jpype-0.6.2+dfsg/test/harness/jpype/attr/0000775000175000017500000000000013036015411017576 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/attr/ClassWithBuffer.java0000664000175000017500000000031513036015411023473 0ustar takakitakakipackage jpype.attr; import java.awt.image.BufferStrategy; public class ClassWithBuffer { public BufferStrategy bufferStrategy; public void foo() { System.out.println("foo"); } } jpype-0.6.2+dfsg/test/harness/jpype/attr/Holder.java0000664000175000017500000000147713036015411021667 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.attr; public class Holder { public String f; }jpype-0.6.2+dfsg/test/harness/jpype/attr/SubHolder.java0000664000175000017500000000153113036015411022330 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.attr; public class SubHolder extends Holder implements java.io.Serializable { }jpype-0.6.2+dfsg/test/harness/jpype/attr/SyntheticMethods.java0000664000175000017500000000055013036015411023737 0ustar takakitakakipackage jpype.attr; import java.util.List; public class SyntheticMethods { public static interface GenericInterface { void foo(T value); } public static class GenericImpl implements GenericInterface { public List mListValue = null; public void foo(List value) { mListValue = value; } } }jpype-0.6.2+dfsg/test/harness/jpype/attr/Test1.java0000664000175000017500000000505613036015411021447 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //***************************************************************************** package jpype.attr; public class Test1 { private String mBigString; public Test1() { StringBuffer sb = new StringBuffer(4001); for (int i = 0; i < 4000; i++) { sb.append("A"); } mBigString = sb.toString(); } public String getBigString() { return mBigString; } public String toString() { return "aaa"; } public static String[] testStaticString(String s1, String s2) { return new String[] { s1, s2}; } public static String testStaticHolder(Holder h) { return h.f; } public String[] testString(String s1, String s2) { return new String[] { s1, s2}; } public String[] testStringArray(String[] vals) { return vals; } public String stringValue = "Foo"; public char charValue = 'a'; public static Object objectValue= new Integer(234); public static void reset() { objectValue= new Integer(234); } public Object getSubClass() { return new SubHolder(); } public void callWithClass(Class c) { } public void test1Method() { } boolean mBooleanValue = false; public void setBoolean(boolean b) { mBooleanValue = b; } byte mByteValue; public void setByte(byte b) { mByteValue = b; } short mShortValue = 0; public void setShort(short s) { mShortValue = s; } int mIntValue = 0; public void setInt(int i) { mIntValue = i; } long mLongValue = 0; public void setLong(long l) { mLongValue = l; } public String callWithSomething(Object obj) { return "Object"; } public String callWithSomething(Class obj) { return "Class"; } public Test1 delete(String arg1, String arg2) { System.out.println("Overloaded test 1 called"); return null; } }jpype-0.6.2+dfsg/test/harness/jpype/attr/Test2.java0000664000175000017500000000215613036015411021446 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //***************************************************************************** package jpype.attr; public class Test2 extends Test1 { public Test2() { super(); } public void test2Method() { } public String toString(String foo) { return foo; } public Test1 delete(String arg1, String arg2) { System.out.println("Overloaded test 2 called"); return null; } }jpype-0.6.2+dfsg/test/harness/jpype/attr/TestOverloadA.java0000664000175000017500000000016113036015411023153 0ustar takakitakakipackage jpype.attr; public class TestOverloadA { public String foo() { return "foo() in A"; } } jpype-0.6.2+dfsg/test/harness/jpype/attr/TestOverloadB.java0000664000175000017500000000011213036015411023150 0ustar takakitakakipackage jpype.attr; public class TestOverloadB extends TestOverloadA { } jpype-0.6.2+dfsg/test/harness/jpype/attr/TestOverloadC.java0000664000175000017500000000022513036015411023156 0ustar takakitakakipackage jpype.attr; public class TestOverloadC extends TestOverloadB { public String foo(int i) { return "foo(int) in C: " + i; } } jpype-0.6.2+dfsg/test/harness/jpype/collection/0000775000175000017500000000000013036015411020757 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/collection/TestEnum.java0000664000175000017500000000006013036015411023362 0ustar takakitakakipackage jpype.collection; enum TestEnum { A,B }jpype-0.6.2+dfsg/test/harness/jpype/exc/0000775000175000017500000000000013036015411017403 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/exc/ChildTestException.java0000664000175000017500000000012513036015411024006 0ustar takakitakakipackage jpype.exc; public class ChildTestException extends ParentTestException { }jpype-0.6.2+dfsg/test/harness/jpype/exc/ExceptionTest.java0000664000175000017500000000262213036015411023046 0ustar takakitakaki// ***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.exc; class ExceptionTest { public static void throwRuntime() { throw new RuntimeException("Foo"); } public static void throwIOException() throws java.io.IOException { throw new java.io.IOException("Bar"); } public static boolean delegateThrow(ExceptionThrower th) { try { th.throwIOException(); } catch (java.io.IOException ex) { return true; } catch (Throwable ex) { ex.printStackTrace(); } return false; } public static void throwChildTestException() throws ParentTestException { throw new ChildTestException(); } }jpype-0.6.2+dfsg/test/harness/jpype/exc/ExceptionThrower.java0000664000175000017500000000154313036015411023562 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.exc; interface ExceptionThrower { void throwIOException() throws java.io.IOException; }jpype-0.6.2+dfsg/test/harness/jpype/exc/ParentTestException.java0000664000175000017500000000012613036015411024215 0ustar takakitakakipackage jpype.exc; public class ParentTestException extends java.lang.Exception { }jpype-0.6.2+dfsg/test/harness/jpype/mro/0000775000175000017500000000000013036015411017421 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/mro/A.java0000664000175000017500000000147113036015411020447 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.mro; interface A extends E, F { void foo(); }jpype-0.6.2+dfsg/test/harness/jpype/mro/B.java0000664000175000017500000000145313036015411020450 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.mro; interface B extends D, A { }jpype-0.6.2+dfsg/test/harness/jpype/mro/C.java0000664000175000017500000000150313036015411020445 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.mro; class C implements A, B { public void foo() {} }jpype-0.6.2+dfsg/test/harness/jpype/mro/D.java0000664000175000017500000000143613036015411020453 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.mro; interface D { }jpype-0.6.2+dfsg/test/harness/jpype/mro/E.java0000664000175000017500000000143613036015411020454 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.mro; interface E { }jpype-0.6.2+dfsg/test/harness/jpype/mro/F.java0000664000175000017500000000143613036015411020455 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.mro; interface F { }jpype-0.6.2+dfsg/test/harness/jpype/mro/MultipleInterfaces.java0000664000175000017500000000176613036015411024075 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //***************************************************************************** package jpype.mro; interface IA {} interface IB {} interface ICombined1 extends IA,IB {} interface ICombined2 extends IB,IA {} public class MultipleInterfaces implements ICombined1, ICombined2 { public MultipleInterfaces() {} } jpype-0.6.2+dfsg/test/harness/jpype/nio/0000775000175000017500000000000013036015411017411 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/nio/NioReceive.java0000664000175000017500000000233313036015411022305 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.nio; import java.nio.*; class NioReceive { public static void receiveBuffer(ByteBuffer buffer) { System.out.println("Received a buffer of "+buffer.toString()); } public static void allocSomeMemory() { byte[] b = new byte[10000]; } public static void receiveBufferWithException(ByteBuffer buffer) { System.out.println("Received a buffer of "+buffer.toString()); throw new RuntimeException("hello!"); } }jpype-0.6.2+dfsg/test/harness/jpype/numeric/0000775000175000017500000000000013036015411020266 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/numeric/NumericTest.java0000664000175000017500000000161713036015411023400 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.numeric; class NumericTest { public static boolean doubleIsTwiceMaxFloat(double d) { return d == (Float.MAX_VALUE*2.0); } }jpype-0.6.2+dfsg/test/harness/jpype/objectwrapper/0000775000175000017500000000000013036015411021473 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/objectwrapper/Test1.java0000664000175000017500000000221113036015411023332 0ustar takakitakaki//***************************************************************************** // Copyright 2004-2008 Steve Menard // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //***************************************************************************** package jpype.objectwrapper; public class Test1 { public Test1() { } public int Method1(Number n) { return 1; } public int Method1(Integer n) { return 2; } public int Method1(Object n) { return 3; } public int Method1(String n) { return 4; } public Object ReturnObject(Object o) { return o; } }jpype-0.6.2+dfsg/test/harness/jpype/overloads/0000775000175000017500000000000013036015411020622 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/overloads/Test1.java0000664000175000017500000001165313036015411022473 0ustar takakitakakipackage jpype.overloads; import java.util.List; public class Test1 { public static class A{} public static class B extends A {} public static class C extends B {} public String testMostSpecific(A a) { return "A"; } public String testMostSpecific(B b) { return "B"; } public String testVarArgs(A a, A... as) { return "A,A..."; } public String testVarArgs(A a, B... bs) { return "A,B..."; } public String testVarArgs(B a, B... bs) { return "B,B..."; } public String testPrimitive(byte v) { return "byte"; } public String testPrimitive(Byte v) { return "Byte"; } public String testPrimitive(short v) { return "short"; } public String testPrimitive(Short v) { return "Short"; } public String testPrimitive(int v) { return "int"; } public String testPrimitive(Integer v) { return "Integer"; } public String testPrimitive(long v) { return "long"; } public String testPrimitive(Long v) { return "Long"; } public String testPrimitive(float v) { return "float"; } public String testPrimitive(Float v) { return "Float"; } public String testPrimitive(double v) { return "double"; } public String testPrimitive(Double v) { return "Double"; } public String testPrimitive(boolean v) { return "boolean"; } public String testPrimitive(Boolean v) { return "Boolean"; } public String testPrimitive(char v) { return "char"; } public String testPrimitive(Character v) { return "Character"; } public static String testInstanceVsClass(B b) { return "static B";} public String testInstanceVsClass(A a) { return "instance A"; } public static String testJavaInstanceVsClass() { return new Test1().testInstanceVsClass(new C()); } /* I1 / \ I2 I3 \ / \ I4 I5 | \ | I6 I7 \ | I8 */ public static interface I1 {} public static interface I2 extends I1 {} public static interface I3 extends I1 {} public static interface I4 extends I2, I3 {} public static interface I5 extends I3 {} public static interface I6 extends I4 {} public static interface I7 extends I4,I5 {} public static interface I8 extends I6,I7 {} public static class I1Impl implements I1 {} public static class I2Impl implements I2 {} public static class I3Impl implements I3 {} public static class I4Impl implements I4 {} public static class I5Impl implements I5 {} public static class I6Impl implements I6 {} public static class I7Impl implements I7 {} public static class I8Impl implements I8 {} public String testInterfaces1(I2 v) { return "I2"; } public String testInterfaces1(I3 v) { return "I3"; } public String testInterfaces2(I2 v) { return "I2"; } public String testInterfaces2(I3 v) { return "I3"; } public String testInterfaces2(I4 v) { return "I4"; } public String testInterfaces3(I4 v) { return "I4"; } public String testInterfaces3(I5 v) { return "I5"; } public String testInterfaces4(I1 v) { return "I1"; } public String testInterfaces4(I2 v) { return "I2"; } public String testInterfaces4(I3 v) { return "I3"; } public String testInterfaces4(I4 v) { return "I4"; } public String testInterfaces4(I5 v) { return "I5"; } public String testInterfaces4(I6 v) { return "I6"; } public String testInterfaces4(I7 v) { return "I7"; } public String testInterfaces4(I8 v) { return "I8"; } public String testClassVsObject(Object v) { return "Object"; } public String testClassVsObject(Class v) { return "Class"; } public String testStringArray(Object v) { return "Object"; } public String testStringArray(String v) { return "String"; } public String testStringArray(String[] v) { return "String[]"; } public String testListVSArray(String[] v) { return "String[]"; } public String testListVSArray(List v) { return "List"; } /* tests for java 1.8 default methods, commented out for travis environment public interface IDefaultA { public default String defaultMethod() { return "A"; } } public interface IDefaultB extends IDefaultA { public default String defaultMethod() { return "B"; } } public interface IDefaultC extends IDefaultA, IDefaultB { } public static class DefaultC implements IDefaultC { } //*/ }jpype-0.6.2+dfsg/test/harness/jpype/properties/0000775000175000017500000000000013036015411021020 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/properties/TestBean.java0000664000175000017500000000245013036015411023371 0ustar takakitakakipackage jpype.properties; public class TestBean { private String getA; private String setA; private String property1; private String property2Invisible; private String property3; private String property4; private String property5; private String property6; private String property7; public String getProperty1() { return "get" + property1; } public String getProperty2() { return "get" + property2Invisible; } public String getProperty3() { return "get" + property3; } public String abcProperty4() { return "abc" + property4; } public String getProperty6() { return "get" + property7; } public String property1() { return "method"; } protected String property2() { return "method"; } protected String property3() { return "method"; } public String returnProperty5() { return "return" + this.property5; } public void setProperty1(String property1) { this.property1 = "set" + property1; } public void setProperty2(String property2) { this.property2Invisible = "set" + property2; } public void setProperty3(String property3) { this.property3 = "set" + property3; } public void setProperty5(String property5) { this.property5 = "set" + property5; } public void setProperty6(String property6) { this.property7 = "set" + property6; } } jpype-0.6.2+dfsg/test/harness/jpype/proxy/0000775000175000017500000000000013036015411020005 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/proxy/ProxyTriggers.java0000664000175000017500000000430613036015411023503 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.proxy; import java.util.LinkedList; import java.util.List; public class ProxyTriggers { public static String[] testProxy(TestInterface2 itf) { List methods = new LinkedList<>(); if (itf instanceof TestInterface1) { methods.add("Test Method1 = "+((TestInterface1)itf).testMethod1()); } methods.add("Test Method2 = "+itf.testMethod2()); if (itf instanceof TestInterface3) { methods.add("Test Method3 = "+((TestInterface3)itf).testMethod3()); } return methods.toArray(new String[0]); } public void testProxyWithThread(final TestThreadCallback itf) { itf.notifyValue("Waiting for thread start"); Thread t = new Thread(new Runnable() { public void run() { for (int i = 1; i <= 3; i++) { itf.notifyValue(String.valueOf(i)); } } }); t.start(); try { t.join(); itf.notifyValue("Thread finished"); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); itf.notifyValue("Thread has been interrupted"); } } public Object[] testCallbackWithParameters(TestInterface2 itf) { byte[] vals = { 1, 2, 3, 4}; return itf.write(vals , 12, 13); } }jpype-0.6.2+dfsg/test/harness/jpype/proxy/TestInterface1.java0000664000175000017500000000012213036015411023464 0ustar takakitakakipackage jpype.proxy; public interface TestInterface1 { int testMethod1(); } jpype-0.6.2+dfsg/test/harness/jpype/proxy/TestInterface2.java0000664000175000017500000000160713036015411023476 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.proxy; public interface TestInterface2 { int testMethod2(); Object[] write(byte[] bytes, int pos, int length); }jpype-0.6.2+dfsg/test/harness/jpype/proxy/TestInterface3.java0000664000175000017500000000154613036015411023501 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.proxy; public interface TestInterface3 extends TestInterface2 { String testMethod3(); }jpype-0.6.2+dfsg/test/harness/jpype/proxy/TestThreadCallback.java0000664000175000017500000000015613036015411024336 0ustar takakitakakipackage jpype.proxy; public interface TestThreadCallback { public void notifyValue(String step); } jpype-0.6.2+dfsg/test/harness/jpype/ref/0000775000175000017500000000000013036015411017400 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/ref/TestReferenceQeue.java0000664000175000017500000000206213036015411023621 0ustar takakitakakipackage jpype.ref; public class TestReferenceQeue { public static void main(String[] args) { // final JPypeReferenceQueue queue = new JPypeReferenceQueue(); // // new Thread(new Runnable() { // // public void run() // { // queue.startManaging(); // } // // }).start(); // // Object dummy = new Object(); // long dummyAddress = 123456; // // JPypeReference ref = new JPypeReference(dummy, queue); // // queue.registerRef(ref, dummyAddress); // // System.out.println("ref is enqueued? "+ref.isEnqueued()); // // long start = System.currentTimeMillis(); // dummy = null; // while (System.currentTimeMillis()-start < 30000 && ! (ref.isEnqueued())) // { // System.gc(); // System.out.print("."); // try // { // Thread.sleep(250); // } // catch(InterruptedException ex) {} // } // // System.out.println(); // System.out.println("ref is enqueued? "+ref.isEnqueued()); // queue.stop(); } } jpype-0.6.2+dfsg/test/harness/jpype/rmi/0000775000175000017500000000000013036015411017413 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/rmi/IServer.java0000664000175000017500000000157013036015411021640 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.rmi; import java.rmi.*; interface IServer extends Remote { void callRemote() throws RemoteException; }jpype-0.6.2+dfsg/test/harness/jpype/rmi/ServerImpl.java0000664000175000017500000000343213036015411022350 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.rmi; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; class ServerImpl extends UnicastRemoteObject implements IServer { public ServerImpl() throws RemoteException { super(); } public void callRemote() throws RemoteException { System.out.println("Method has been called!!!!"); } public static void main(String args[]) { // Create and install a security manager // if (System.getSecurityManager() == null) { // System.setSecurityManager(new RMISecurityManager()); // } try { Registry reg = LocateRegistry.createRegistry(2004); ServerImpl obj = new ServerImpl(); // Bind this object instance to the name "HelloServer" Naming.rebind("//192.168.100.60:2004/server", obj); System.out.println("HelloServer bound in registry"); } catch (Exception e) { System.out.println("HelloImpl err: " + e.getMessage()); e.printStackTrace(); } } } jpype-0.6.2+dfsg/test/harness/jpype/serial/0000775000175000017500000000000013036015411020103 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/serial/SerializationTest.java0000664000175000017500000000140613036015411024424 0ustar takakitakaki//Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.serial; public class SerializationTest implements java.io.Serializable { }jpype-0.6.2+dfsg/test/harness/jpype/xml/0000775000175000017500000000000013036015411017424 5ustar takakitakakijpype-0.6.2+dfsg/test/harness/jpype/xml/DelegateHandler.java0000664000175000017500000000635713036015411023312 0ustar takakitakaki//***************************************************************************** //Copyright 2004-2008 Steve Menard // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // //http://www.apache.org/licenses/LICENSE-2.0 // //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and //limitations under the License. // //***************************************************************************** package jpype.xml; import org.xml.sax.helpers.*; import org.xml.sax.*; public class DelegateHandler extends DefaultHandler { private EntityResolver er; private DTDHandler dh; private ContentHandler ch; private ErrorHandler eh; public DelegateHandler(EntityResolver er, DTDHandler dh, ContentHandler ch, ErrorHandler eh) { this.er = er; this.dh = dh; this.ch = ch; this.eh = eh; } public void characters(char[] ch, int start, int length) throws SAXException { if (ch != null) { this.ch.characters(ch, start, length); } } public void endDocument() throws SAXException { if (ch != null) { ch.endDocument(); } } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (ch != null) { ch.endElement(namespaceURI, localName, qName); } } public void endPrefixMapping(String prefix) throws SAXException { if (ch != null) { ch.endPrefixMapping(prefix); } } public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { if (ch != null) { this.ch.ignorableWhitespace(ch, start, length); } } public void processingInstruction(String target, String data) throws SAXException { if (ch != null) { ch.processingInstruction(target, data); } } public void setDocumentLocator(Locator locator) { if (ch != null) { ch.setDocumentLocator(locator); } } public void skippedEntity(String name) throws SAXException { if (ch != null) { ch.skippedEntity(name); } } public void startDocument() throws SAXException { if (ch != null) { ch.startDocument(); } } public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (ch != null) { ch.startElement(namespaceURI, localName, qName, atts); } } public void startPrefixMapping(String prefix, String uri) throws SAXException { if (ch != null) { ch.startPrefixMapping(prefix, uri); } } }jpype-0.6.2+dfsg/test/java_dom.py0000664000175000017500000000333513036015411016170 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from os import path import time from jpype import * startJVM(getDefaultJVMPath(), "-ea") # XML test Element = JPackage("org").w3c.dom.Element def output(el, prefix="") : if not isinstance(el, Element) : return #print prefix, "<", el.getTagName(), atts = el.getAttributes() for i in range(atts.getLength()) : a = atts.item(i); #print a.getNodeName(), '="%s"' % a.getNodeValue(), #print '>' nl = el.getChildNodes() for i in range(nl.getLength()) : output(nl.item(i), prefix+" ") #print prefix, "" t = time.time() count = 30 for i in range(count) : build = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder() doc = build.parse(path.join(path.dirname(__file__), "sample", "big.xml")) el = doc.getDocumentElement() output(el) t2 = time.time() print count, "iterations in", t2-t, "seconds" shutdownJVM() jpype-0.6.2+dfsg/test/java_sax.py0000664000175000017500000000424013036015411016200 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from os import path import time from jpype import * root = path.abspath(path.dirname(__file__)) startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=%s" % path.join(root, "classes")) # XML test Element = JPackage("org").w3c.dom.Element class ContentHandler(object) : def characters(self, ch, start, length) : pass def endDocument(self) : pass def endElement(self, namespaceURI, localName, qName) : pass def endPrefixMapping(self, prefix) : pass def ignorableWhitespace(self, ch, start, length) : pass def processingInstruction(self, target, data) : pass def setDocumentLocator(self, locator) : pass def skippedEntity(self, name) : pass def startDocument(self, ) : pass def startElement(self, namespaceURI, localName, qName, atts) : pass def startPrefixMapping(self, prefix, uri) : pass t = time.time() count = 30 for i in range(count) : DelegateHandler = JPackage("jpype.xml").DelegateHandler dh = DelegateHandler(None, None, JProxy("org.xml.sax.ContentHandler", inst=ContentHandler()), None) build = javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser() build.parse(path.join(root, "sample", "big.xml"), dh) t2 = time.time() print count, "iterations in", t2-t, "seconds" shutdownJVM() jpype-0.6.2+dfsg/test/jpypetest/0000775000175000017500000000000013036015411016061 5ustar takakitakakijpype-0.6.2+dfsg/test/jpypetest/__init__.py0000664000175000017500000000141113036015411020167 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** jpype-0.6.2+dfsg/test/jpypetest/array.py0000664000175000017500000002257313036015411017562 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** try: import unittest2 as unittest except ImportError: import unittest import sys import jpype from jpype import JPackage, JArray, JByte, java from . import common if sys.version > '3': unicode = str def haveNumpy(): try: import numpy return True except ImportError: return False class ArrayTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) self.VALUES = [12234, 1234, 234, 1324, 424, 234, 234, 142, 5, 251, 242, 35, 235, 62, 1235, 46, 245132, 51, 2, 3, 4] def testReadArray(self): t = JPackage("jpype").array.TestArray() self.assertNotIsInstance(t, JPackage) self.assertCountEqual(self.VALUES, t.i) self.assertEqual(t.i[0], self.VALUES[0]) self.assertCountEqual(self.VALUES[1:-2], t.i[1:-2]) def testStangeBehavior(self): ''' Test for stange crash reported in bug #1089302''' Test2 = jpype.JPackage('jpype.array').Test2 test = Test2() test.test(test.getValue()) def testWriteArray(self): t = JPackage("jpype").array.TestArray() self.assertNotIsInstance(t, JPackage) t.i[0] = 32 self.assertEqual(t.i[0], 32) t.i[1:3] = (33, 34) self.assertEqual(t.i[1], 33) self.assertEqual(t.i[2], 34) self.assertCountEqual(t.i[:5], (32, 33, 34, 1324, 424)) def testObjectArraySimple(self): a = JArray(java.lang.String, 1)(2) a[1] = "Foo" self.assertEqual("Foo", a[1]) def testByteArraySimple(self): a = JArray(JByte)(2) a[1] = 2 self.assertEqual(a[1], 2) def testIterateArray(self): t = JPackage("jpype").array.TestArray() self.assertFalse(isinstance(t, JPackage)) for i in t.i: self.assertNotEqual(i, 0) def testGetSubclass(self): t = JPackage("jpype").array.TestArray() v = t.getSubClassArray() self.assertTrue(isinstance(v[0], unicode)) def testGetArrayAsObject(self): t = JPackage("jpype").array.TestArray() v = t.getArrayAsObject() def testCharArrayAsString(self): t = JPackage("jpype").array.TestArray() v = t.charArray self.assertEqual(str(v), 'avcd') self.assertEqual(unicode(v), u'avcd') def testByteArrayAsString(self): t = JPackage("jpype").array.TestArray() v = t.byteArray self.assertEqual(str(v), 'avcd') def testByteArrayIntoVector(self): ba = jpype.JArray(jpype.JByte)(b'123') v = jpype.java.util.Vector(1) v.add(ba) self.assertEqual(len(v), 1) self.assertNotEqual(v[0], None) def testJArrayConversionBool(self): expected = [True, False, False, True] jarr = jpype.JArray(jpype.JBoolean)(expected) self.assertCountEqual(expected, jarr[:]) def testJArrayConversionChar(self): t = JPackage("jpype").array.TestArray() v = t.charArray self.assertEqual(v[:], 'avcd') # FIXME: this returns unicode on windows self.assertEqual(str(v[:]), 'avcd') self.assertEqual(unicode(v[:]), u'avcd') def testJArrayConversionByte(self): expected = (0, 1, 2, 3) ByteBuffer = jpype.java.nio.ByteBuffer bb = ByteBuffer.allocate(4) buf = bb.array() for i in range(len(expected)): buf[i] = expected[i] self.assertCountEqual(expected[:], buf[:]) def testJArrayConversionShort(self): # filter out values, which can not be converted to jshort self.VALUES = [v for v in self.VALUES if v < (2**16 / 2 - 1) and v > (2**16 / 2 * -1)] jarr = jpype.JArray(jpype.JShort)(self.VALUES) result = jarr[0: len(jarr)] self.assertCountEqual(self.VALUES, result) result = jarr[2:10] self.assertCountEqual(self.VALUES[2:10], result) # TODO: investigate why overflow is being casted on linux, but not on windows # with self.assertRaises(jpype._): # jpype.JArray(jpype.JShort)([2**16/2]) def testJArrayConversionInt(self): jarr = jpype.JArray(jpype.JInt)(self.VALUES) result = jarr[0: len(jarr)] self.assertCountEqual(self.VALUES, result) result = jarr[2:10] self.assertCountEqual(self.VALUES[2:10], result) def testJArrayConversionLong(self): jarr = jpype.JArray(jpype.JLong)(self.VALUES) result = jarr[0: len(jarr)] self.assertCountEqual(self.VALUES, result) result = jarr[2:10] self.assertCountEqual(self.VALUES[2:10], result) def testJArrayConversionFloat(self): VALUES = [float(x) for x in self.VALUES] jarr = jpype.JArray(jpype.JFloat)(VALUES) result = jarr[0: len(jarr)] self.assertCountEqual(jarr, result) result = jarr[2:10] self.assertCountEqual(VALUES[2:10], result) def testJArrayConversionDouble(self): VALUES = [float(x) for x in self.VALUES] jarr = jpype.JArray(jpype.JDouble)(VALUES) self.assertCountEqual(VALUES, jarr) result = jarr[:] self.assertCountEqual(VALUES, result) result = jarr[2:10] self.assertEqual(len(VALUES[2:10]), len(result)) self.assertCountEqual(VALUES[2:10], result) # empty slice result = jarr[-1:3] expected = VALUES[-1:3] self.assertCountEqual(expected, result) result = jarr[3:-2] expected = VALUES[3:-2] self.assertCountEqual(expected, result) def testConversionError(self): jarr = jpype.JArray(jpype.JInt, 1)(10) with self.assertRaises(RuntimeError): jarr[1:2] = [dict()] # -1 is returned by python, if conversion fails also, ensure this works jarr[1:2] = [-1] def testObjectArrayInitial(self): l1 = java.util.ArrayList() l1.add(0) l2 = java.util.ArrayList() l2.add(42) l3 = java.util.ArrayList() l3.add(13) jarr = jpype.JArray(java.util.ArrayList, 1)([l1, l2, l3]) self.assertEqual(l1, jarr[0]) self.assertEqual(l2, jarr[1]) self.assertEqual(l3, jarr[2]) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPBoolArray(self): import numpy as np n = 100 a = np.random.randint(0, 1, size=n).astype(np.bool) jarr = jpype.JArray(jpype.JBoolean)(n) jarr[:] = a self.assertCountEqual(a, jarr) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPByteArray(self): import numpy as np n = 100 a = np.random.randint(-128, 127, size=n).astype(np.byte) jarr = jpype.JArray(jpype.JByte)(n) jarr[:] = a self.assertCountEqual(a, jarr) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPShortArray(self): import numpy as np n = 100 a = np.random.randint(-32768, 32767, size=n).astype(np.short) jarr = jpype.JArray(jpype.JShort)(n) jarr[:] = a self.assertCountEqual(a, jarr) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPIntArray(self): import numpy as np n = 100 a = np.random.randint(-2**31 - 1, 2**31 - 1, size=n).astype(np.int32) jarr = jpype.JArray(jpype.JInt)(n) jarr[:] = a self.assertCountEqual(a, jarr) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPLongArray(self): import numpy as np n = 100 # actuall the lower bound should be -2**63 -1, but raises Overflow # error in numpy a = np.random.randint(-2**63, 2**63 - 1, size=n).astype(np.int64) jarr = jpype.JArray(jpype.JLong)(n) jarr[:] = a self.assertCountEqual(a, jarr) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPFloatArray(self): import numpy as np n = 100 a = np.random.random(n).astype(np.float32) jarr = jpype.JArray(jpype.JFloat)(n) jarr[:] = a self.assertCountEqual(a, jarr) @unittest.skipUnless(haveNumpy(), "numpy not available") def testSetFromNPDoubleArray(self): import numpy as np n = 100 a = np.random.random(n).astype(np.float64) jarr = jpype.JArray(jpype.JDouble)(n) jarr[:] = a self.assertCountEqual(a, jarr) jpype-0.6.2+dfsg/test/jpypetest/attr.py0000664000175000017500000002251413036015411017411 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype from jpype import JString, java, JArray import sys import time from . import common class AttributeTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) self.__jp = self.jpype.attr def testWithBufferStrategy(self): j = jpype.JPackage("jpype").attr.ClassWithBuffer self.assertIsNone(j().bufferStrategy) def testCallOverloadedMethodWithCovariance(self): # This is a JDk5-specific problem. h = jpype.java.lang.StringBuffer() h.delete(0, 0) def testCallStaticString(self): h = self.__jp.Test1() v = h.testString(JString("abcd"), JString("abcde")) self.assertEqual(v[0], 'abcd') self.assertEqual(v[1], 'abcde') def testCallStaticUnicodeString(self): h = self.__jp.Test1() v = h.testString(JString(u"abcd"), JString(u"abcde")) self.assertEqual(v[0], 'abcd') self.assertEqual(v[1], 'abcde') def testCallString(self): v = self.__jp.Test1.testStaticString("a", "b") self.assertEqual(v[0], 'a') self.assertEqual(v[1], 'b') def testCallUnicodeString(self): v = self.__jp.Test1.testStaticString(u"a", u"b") self.assertEqual(v[0], 'a') self.assertEqual(v[1], 'b') def testCallStringWithNone(self): v = self.__jp.Test1.testStaticString("a", None) self.assertEqual(v[0], 'a') self.assertIsNone(v[1]) def testWithHolder(self): holder = self.__jp.Holder() holder.f = "ffff" self.assertEqual(holder.f, 'ffff') result = self.__jp.Test1.testStaticHolder(holder) self.assertEqual(result, 'ffff') def testWithSubHolder(self): h2 = self.__jp.SubHolder() h2.f = "subholder" result = self.__jp.Test1.testStaticHolder(h2) self.assertEqual(result, 'subholder') def testCallWithArray(self): h2 = self.__jp.Test1() StringArray = JArray(JString) v = StringArray(["Foo", "bar"]) t = self.__jp.Test1() result = t.testStringArray(v) self.assertSequenceEqual(["Foo", "bar"], result) def testGetStaticValue(self): self.assertEqual(str(self.__jp.Test1.objectValue), "234") def testGetStaticByInstance(self): h = self.__jp.Test1() self.assertEqual(str(h.objectValue), "234") def testGetNonStatic(self): h = self.__jp.Test1() self.assertEqual(h.stringValue, "Foo") def testSetStaticValue(self): self.__jp.Test1.objectValue = java.lang.Integer(43) self.assertEqual(str(self.__jp.Test1.objectValue), "43") self.__jp.Test1.reset() def testSetNonStaticValue(self): h = self.__jp.Test1() h.stringValue="bar" self.assertEqual(h.stringValue, "bar") def testReturnSubClass(self): h = self.__jp.Test1() v = h.getSubClass() self.assertIsInstance(v, self.__jp.SubHolder) def testCallWithClass(self): h = self.__jp.Test1() h.callWithClass(java.lang.Comparable) def testCallSuperclassMethod(self): h = self.__jp.Test2() h.test2Method() h.test1Method() def testCallWithLong(self): h = self.__jp.Test1() if sys.version > '3': l = int(123) else: l = long(123) h.setByte(l) self.assertEqual(l, h.mByteValue) h.setShort(l) self.assertEqual(l, h.mShortValue) h.setInt(l) self.assertEqual(l, h.mIntValue) h.setLong(l) self.assertEqual(l, h.mLongValue) def testCallWithBigLong(self): h = self.__jp.Test1() if sys.version > '3': l = int(4398046511103) else: l = long(4398046511103) self.assertRaises(TypeError, h.setByte, l) self.assertRaises(TypeError, h.setShort, l) self.assertRaises(TypeError, h.setInt, l) h.setLong(l) self.assertEqual(l, h.mLongValue) def testCallWithBigInt(self): h = self.__jp.Test1() if sys.version > '3' or sys.maxint > 2**31: l = int(4398046511103) else: l = long(4398046511103) self.assertRaises(TypeError, h.setByte, l) self.assertRaises(TypeError, h.setShort, l) self.assertRaises(TypeError, h.setInt, l) h.setLong(l) self.assertEqual(l, h.mLongValue) def testSetBoolean(self): h = self.__jp.Test1() self.assertEqual(False, h.mBooleanValue) h.setBoolean(True) self.assertEqual(True, h.mBooleanValue) h.setBoolean(False) self.assertEqual(False, h.mBooleanValue) # just testing the status quo, not sure about if this is nice h.setBoolean(42) self.assertEqual(True, h.mBooleanValue) h.setBoolean(0) self.assertEqual(False, h.mBooleanValue) if sys.version > '3': l = int(4398046511103) else: l = long(4398046511103) h.setBoolean(l) self.assertEqual(True, h.mBooleanValue) if sys.version > '3': l = int(0) else: l = long(0) h.setBoolean(l) self.assertEqual(False, h.mBooleanValue) def testCreateDate(self): d = jpype.java.util.Date(1448799485000) self.assertEqual(1448799485000, d.getTime()) def testCharAttribute(self): h = self.__jp.Test1() h.charValue = u'b' self.assertEqual(h.charValue, 'b') if sys.version < '3': exp_repr = "u'b'" else: exp_repr = "'b'" self.assertEqual(repr(h.charValue), exp_repr) def testGetPrimitiveType(self): Integer = jpype.JClass("java.lang.Integer") intType = Integer.TYPE def testDifferentiateClassAndObject(self): h = self.__jp.Test1() self.assertEqual(h.callWithSomething(self.__jp.Test1), u"Class") result = h.callWithSomething(jpype.JObject(self.__jp.Test1, jpype.java.lang.Object)) self.assertEqual(result, u"Object") def testToString(self): h = self.__jp.Test1() self.assertEqual(str(h), 'aaa') def testSuperToString(self): h = self.__jp.Test2() self.assertEqual(str(h), 'aaa') # def testStringToConversion(self): # try: # jpype.ConversionConfig.string = False # for i in range(1): # h = self.__jp.Test1() # # start = time.time(); # for j in range(10): # ts = h.getBigString() # stop = time.time() # print ts.__class__, (stop-start), 'ms' # # # for comparison ... convert a string to JStrng and back # s = "".join([" "]*1024*1024*5) # start = time.time() # js = JString(s) # stop = time.time() # print "converted to JString in", (stop-start), 'ms', len(s) # # start = time.time() # cs = str(JString(s)) # print cs # print "converted to String in", (stop-start), 'ms', len(cs), cs # finally: # jpype.ConversionConfig.string = True def testComplexMethodOvlerloading(self): c = self.__jp.TestOverloadC() self.assertEqual(c.foo(1), "foo(int) in C: 1") self.assertEqual(c.foo(), "foo() in A") def testPassedObjectGetsCleanedUp(self): h = self.__jp.Test1() block_size = 1024 * 1024 * 10 def allocate_then_free(): byte_buffer = jpype.JClass('java.nio.ByteBuffer') inst = byte_buffer.allocate(1024 * 1024 * 100) # passing the object back to java seems to stop it being collected result = h.callWithSomething(inst) rt = jpype.java.lang.Runtime.getRuntime() free = rt.freeMemory() for x in range(0, 10 * free // block_size): allocate_then_free() def testSyntheticMethod(self): h = jpype.JClass('jpype.attr.SyntheticMethods$GenericImpl')() h.foo(jpype.java.util.ArrayList()) jpype-0.6.2+dfsg/test/jpypetest/collection.py0000664000175000017500000000205113036015411020564 0ustar takakitakakiimport jpype from . import common class CollectionTestCase(common.JPypeTestCase): def setUp(self): super(CollectionTestCase, self).setUp() def testCollection(self): collection = jpype.java.util.ArrayList() collection.add(1) collection.add(2) self.assertEqual([1, 2], [i for i in collection]) def testIterateHashmap(self): collection = jpype.java.util.HashMap() collection.put('A',1) collection.put('B',2) asdict = dict() for x in collection.entrySet(): asdict[x.getKey()] = x.getValue().longValue() self.assertEqual({'A':1,'B':2}, asdict) def testEnumMap(self): enumclass = jpype.JClass('jpype.collection.TestEnum') enummap = jpype.java.util.EnumMap(enumclass) enummap.put(enumclass.A, 'ABC') enummap.put(enumclass.B, 'DEF') asdict = dict() for x in enummap.entrySet(): asdict[str(x.getKey())] = x.getValue() self.assertEqual({'A':'ABC','B':'DEF'}, asdict)jpype-0.6.2+dfsg/test/jpypetest/common.py0000664000175000017500000000330313036015411017722 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype import logging from os import path import sys try: import unittest2 as unittest except ImportError: import unittest CLASSPATH = None class JPypeTestCase(unittest.TestCase) : def setUp(self): if not jpype.isJVMStarted(): root = path.dirname(path.abspath(path.dirname(__file__))) jvm_path = jpype.getDefaultJVMPath() logger = logging.getLogger(__name__) logger.info("Running testsuite using JVM %s" % jvm_path) classpath_arg = "-Djava.class.path=%s" classpath_arg %= path.join(root, 'classes') jpype.startJVM(jvm_path, "-ea", # "-Xcheck:jni", "-Xmx256M", "-Xms16M", classpath_arg) self.jpype = jpype.JPackage('jpype') if sys.version < '3': self.assertCountEqual = self.assertItemsEqual def tearDown(self): pass jpype-0.6.2+dfsg/test/jpypetest/exc.py0000664000175000017500000000663513036015411017224 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from jpype import JException, java, JavaException, JProxy, JPackage import traceback try: import unittest2 as unittest except ImportError: import unittest from . import common def throwIOException(): raise java.io.IOException.PYEXC("Test throw") def throwByJavaException(): JPackage('jpype').exc.ExceptionTest.throwIOException() class ExceptionTestCase(common.JPypeTestCase): def testExceptionThrown(self): try: self.jpype.exc.ExceptionTest.throwRuntime() self.fail() except JavaException as ex: self.assertIs(ex.javaClass(), java.lang.RuntimeException) self.assertEqual('Foo', ex.message()) trace = ex.stacktrace() self.assertTrue(trace.startswith('java.lang.RuntimeException: Foo')) def testExceptionByJavaClass(self): try: self.jpype.exc.ExceptionTest.throwRuntime() self.fail() except JException(java.lang.RuntimeException) as ex: self.assertIs(ex.javaClass(), java.lang.RuntimeException) self.assertEqual('Foo', ex.message()) trace = ex.stacktrace() self.assertTrue(trace.startswith('java.lang.RuntimeException: Foo')) @unittest.skip("Throwing specific Java exception from Python doesn't work") def testThrowException(self): d = {"throwIOException": throwIOException, } p = JProxy(self.jpype.exc.ExceptionThrower, dict=d) self.assertTrue(self.jpype.exc.ExceptionTest.delegateThrow(p)) def testThrowException3(self): d = {"throwIOException": throwByJavaException, } p = JProxy(self.jpype.exc.ExceptionThrower, dict=d) self.assertTrue(self.jpype.exc.ExceptionTest.delegateThrow(p)) def testExceptionPYEXCName(self): e = self.jpype.exc.ChildTestException() name = "jpype.exc.ChildTestExceptionPyRaisable" self.assertEqual(name, e.PYEXC.__name__) def testExceptionInstanceof(self): e = self.jpype.exc.ChildTestException() self.assertIsInstance(e, self.jpype.exc.ParentTestException) def testExceptionPYEXCInstanceof(self): e = self.jpype.exc.ChildTestException() self.assertTrue(issubclass(e.PYEXC, self.jpype.exc.ParentTestException.PYEXC)) def testThrowChildExceptionFromCatchJExceptionParentClass(self): try: self.jpype.exc.ExceptionTest.throwChildTestException() self.fail() except JException(self.jpype.exc.ParentTestException) as ex: self.assertIsInstance(ex, self.jpype.exc.ChildTestException.PYEXC) jpype-0.6.2+dfsg/test/jpypetest/jvmfinder.py0000664000175000017500000001034113036015411020416 0ustar takakitakaki# part of JPype1; author Martin K. Scherer; 2014 try: import unittest2 as unittest except ImportError: import unittest import mock from jpype._jvmfinder import * from jpype._linux import * from jpype._darwin import * import sys class JVMFinderTest(unittest.TestCase): """ test some methods to obtain a jvm. TODO: add windows (need to mock registry) """ def test_find_libjvm(self): """ test JVMFinder.find_libjvm does not return broken jvm implementation. """ walk_fake = [('jre', ('lib',), ()), ('jre/lib', ('amd64',), ()), ('jre/lib/amd64', ('cacao', 'jamvm', 'server'), ()), ('jre/lib/amd64/cacao', ('',), ('libjvm.so',)), ('jre/lib/amd64/jamvm', ('',), ('libjvm.so',)), ('jre/lib/amd64/server', ('',), ('libjvm.so',)), ] with mock.patch('os.walk') as mockwalk: # contains broken and working jvms mockwalk.return_value = walk_fake finder = LinuxJVMFinder() p = finder.find_libjvm('arbitrary java home') self.assertEqual( p, os.path.join('jre/lib/amd64/server','libjvm.so'), 'wrong jvm returned') with mock.patch('os.walk') as mockwalk: # contains only broken jvms, since server impl is removed walk_fake[-1] = ((), (), (),) mockwalk.return_value = walk_fake finder = LinuxJVMFinder() with self.assertRaises(JVMNotSupportedException) as context: finder.find_libjvm('arbitrary java home') @mock.patch('os.walk') @mock.patch('os.path.exists') @mock.patch('os.path.realpath') def test_get_from_bin(self, mock_real_path, mock_path_exists, mock_os_walk): """ test _get_from_bin method (used in linux and darwin) '/usr/bin/java' => some jre/jdk path """ java_path = '/usr/lib/jvm/java-6-openjdk-amd64/bin/java' mock_os_walk.return_value = [ ('/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/server', ('',), ('libjvm.so',))] mock_path_exists.return_value = True mock_real_path.return_value = '/usr/lib/jvm/java-6-openjdk-amd64/bin/java' finder = LinuxJVMFinder() p = finder._get_from_bin() self.assertEqual( p, os.path.join('/usr/lib/jvm/java-6-openjdk-amd64/jre/lib/amd64/server','libjvm.so')) @unittest.skipIf(sys.version_info[:2] == (2, 6), "skip on py26") @mock.patch('platform.mac_ver') def test_javahome_binary_py27(self, mock_mac_ver): # this version has java_home binary mock_mac_ver.return_value = ('10.6.8', '', '') expected = '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home\n' finder = DarwinJVMFinder() # fake check_output with mock.patch('subprocess.check_output') as mock_checkoutput: mock_checkoutput.return_value = expected p = finder._javahome_binary() self.assertEqual(p, expected.strip()) # this version has no java_home binary mock_mac_ver.return_value = ('10.5', '', '') p = finder._javahome_binary() self.assertEqual(p, None) @unittest.skipUnless(sys.version_info[:2] == (2, 6), "only py26") @mock.patch('platform.mac_ver') def test_javahome_binary_py26(self, mock_mac_ver): # this version has java_home binary mock_mac_ver.return_value = ('10.6.8', '', '') expected = '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home\n' finder = DarwinJVMFinder() # fake check_output with mock.patch('subprocess.Popen') as mock_popen: class proc: def communicate(self): return (expected, ) mock_popen.return_value = proc() p = finder._javahome_binary() self.assertEqual(p.strip(), expected.strip()) # this version has no java_home binary mock_mac_ver.return_value = ('10.5', '', '') p = finder._javahome_binary() self.assertEqual(p, None) if __name__ == '__main__': unittest.main() jpype-0.6.2+dfsg/test/jpypetest/mro.py0000664000175000017500000000205713036015411017234 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from jpype import JPackage, java import sys from . import common class MroTestCase(common.JPypeTestCase): def testMro(self): C = JPackage('jpype.mro').C def testMultipleInterfaces(self): j = JPackage("jpype").mro.MultipleInterfaces myinstance = j() jpype-0.6.2+dfsg/test/jpypetest/numeric.py0000664000175000017500000000713513036015411020103 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from jpype import JPackage, java, JFloat, JByte, JShort, JInt, JLong from . import common import sys class NumericTestCase(common.JPypeTestCase): def testMathAbs(self): self.assertEqual(java.lang.Math.abs(-10), 10) def testDoubleConversion(self): f = java.lang.Float.MAX_VALUE * 2 jpype = JPackage("jpype") self.assertTrue(jpype.numeric.NumericTest.doubleIsTwiceMaxFloat(f)) def testDoubleIsProperlyConverted(self): self.assertTrue(java.lang.Double.POSITIVE_INFINITY != 0.0) self.assertTrue(java.lang.Double.MAX_VALUE != 0.0) self.assertTrue(java.lang.Double.NaN != 0.0) self.assertTrue(java.lang.Double.NEGATIVE_INFINITY != 0.0) def testNegativeJFloatWrapper(self): f = JFloat(-1) def checkJWrapper(self, min_value, max_value, javawrapper, jwrapper, expected=TypeError): self.assertEqual(max_value, javawrapper(max_value).longValue()) f = jwrapper(max_value) self.assertEqual(max_value, javawrapper(f).longValue()) self.assertEqual(min_value, javawrapper(min_value).longValue()) f = jwrapper(min_value) self.assertEqual(min_value, javawrapper(f).longValue()) self.assertRaises(expected, javawrapper, max_value+1) self.assertRaises(expected, jwrapper, max_value+1) self.assertRaises(expected, javawrapper, min_value-1) self.assertRaises(expected, jwrapper, min_value-1) # test against int overflow if(max_value < 2**32): self.assertRaises(expected, javawrapper, 2**32) self.assertRaises(expected, jwrapper, 2**32) def testJCharWrapper(self): self.checkJWrapper(-2**7, 2**7-1, java.lang.Byte, JByte) def testJByteWrapper(self): self.checkJWrapper(-2**7, 2**7-1, java.lang.Byte, JByte) def testJShortWrapper(self): self.checkJWrapper(-2**15, 2**15-1, java.lang.Short, JShort) def testJIntWrapper(self): self.checkJWrapper(-2**31, 2**31-1, java.lang.Integer, JInt) def testJLongWrapper(self): self.checkJWrapper(-2**63, 2**63-1, java.lang.Long, JLong, OverflowError) def testJFloatWrapper(self): jwrapper = JFloat javawrapper = java.lang.Float jwrapper(float(2**127)) javawrapper(float(2**127)) self.assertRaises(TypeError, jwrapper, float(2**128)) self.assertRaisesRegexp(RuntimeError, 'No matching overloads found', javawrapper, 5) # no conversion from int? # this difference might be undesirable, # a double bigger than maxfloat passed to java.lang.Float turns into infinity self.assertEquals(float('inf'), javawrapper(float(2**128)).doubleValue()) self.assertEquals(float('-inf'), javawrapper(float(-2**128)).doubleValue()) jpype-0.6.2+dfsg/test/jpypetest/objectwrapper.py0000664000175000017500000000661613036015411021313 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** try: import unittest2 as unittest except ImportError: import unittest import jpype from jpype import java, JObject, JPackage, JString from . import common #import os #import sys class ObjectWrapperTestCase(common.JPypeTestCase): def testCallOverloads(self): # build the harness h = JPackage("jpype.objectwrapper").Test1() o = java.lang.Integer(1) self.assertEqual(h.Method1(JObject(o, java.lang.Number)), 1) self.assertEqual(h.Method1(o), 2) self.assertEqual(h.Method1(JObject(java.lang.Integer(1), java.lang.Object)), 3) self.assertEqual(h.Method1(JString("")), 4) def testDefaultTypeNameString(self): self.assertEqual(JObject("123").typeName, "java.lang.String") def testDefaultTypeNameBoolean(self): self.assertEqual(JObject(True).typeName, "java.lang.Boolean") self.assertEqual(JObject(False).typeName, "java.lang.Boolean") def testPassingClassTypeSucceeds(self): h = JPackage("jpype.objectwrapper").Test1() # Select a convenient java.lang.Class object class_obj = h.getClass() # Check that funneling Class obj through java doesn't convert to null result = h.ReturnObject(class_obj) self.assertEqual(class_obj, result) self.assertNotEqual(result, None) @unittest.skip("This seems to be a bug in _jwrapper.py _getDefaultTypeName") def testDefaultTypeNameJavaClass(self): o = java.lang.String self.assertEqual(JObject(o).typeName, "java.lang.Class") # def testMakeSureWeCanLoadAllClasses(self): # def get_system_jars(): # for dirpath,_,files in os.walk(jpype.java.lang.System.getProperty("java.home")): # for file in files: # if file.endswith('.jar'): # yield (os.path.join(dirpath,file)) # for jar in get_system_jars(): # classes = [x.getName() for x in jpype.java.util.jar.JarFile(jar).entries() if x.getName().endswith('.class')] # classes = [x.replace('/','.')[:-6] for x in classes] # for clazz in classes: # try: # jpype.JClass(clazz) # except jpype.JavaException as exception: # if not 'not found' in exception.message(): # print(clazz) # print (exception.message()) # #print (exception.stacktrace()) # except: # print(sys.exc_info()[0]) # pass jpype-0.6.2+dfsg/test/jpypetest/overloads.py0000664000175000017500000002240413036015411020433 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype from jpype import JString, java, JArray, JClass, JByte, JShort, JInt, JLong, JFloat, JDouble, JChar, JBoolean import sys import time from . import common from jpype._jwrapper import JObject java = jpype.java class OverloadTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) self.__jp = self.jpype.overloads self._aclass = JClass('jpype.overloads.Test1$A') self._bclass = JClass('jpype.overloads.Test1$B') self._cclass = JClass('jpype.overloads.Test1$C') self._a = self._aclass() self._b = self._bclass() self._c = self._cclass() self._i1impl = JClass('jpype.overloads.Test1$I1Impl')() self._i2impl = JClass('jpype.overloads.Test1$I2Impl')() self._i3impl = JClass('jpype.overloads.Test1$I3Impl')() self._i4impl = JClass('jpype.overloads.Test1$I4Impl')() self._i5impl = JClass('jpype.overloads.Test1$I5Impl')() self._i6impl = JClass('jpype.overloads.Test1$I6Impl')() self._i7impl = JClass('jpype.overloads.Test1$I7Impl')() self._i8impl = JClass('jpype.overloads.Test1$I8Impl')() def testMostSpecificInstanceMethod(self): test1 = self.__jp.Test1() self.assertEquals('A', test1.testMostSpecific(self._a)) self.assertEquals('B', test1.testMostSpecific(self._b)) self.assertEquals('B', test1.testMostSpecific(self._c)) self.assertEquals('B', test1.testMostSpecific(None)) def testForceOverloadResolution(self): test1 = self.__jp.Test1() self.assertEquals('A', test1.testMostSpecific(JObject(self._c, self._aclass))) self.assertEquals('B', test1.testMostSpecific(JObject(self._c, self._bclass))) # JObject wrapper forces exact matches self.assertRaisesRegexp(RuntimeError, 'No matching overloads found', test1.testMostSpecific, JObject(self._c, self._cclass)) self.assertEquals('A', test1.testMostSpecific(JObject(self._c, 'jpype.overloads.Test1$A'))) self.assertEquals('B', test1.testMostSpecific(JObject(self._c, 'jpype.overloads.Test1$B'))) # JObject wrapper forces exact matches self.assertRaisesRegexp(RuntimeError, 'No matching overloads found', test1.testMostSpecific, JObject(self._c, 'jpype.overloads.Test1$C')) def testVarArgsCall(self): test1 = self.__jp.Test1() self.assertEquals('A,B...', test1.testVarArgs(self._a,[])) self.assertEquals('A,B...', test1.testVarArgs(self._a, None)) self.assertEquals('A,B...', test1.testVarArgs(self._a, [self._b])) self.assertEquals('A,A...', test1.testVarArgs(self._a, [self._a])) self.assertEquals('A,B...', test1.testVarArgs(self._a, [self._b,self._b])) self.assertEquals('B,B...', test1.testVarArgs(self._b, [self._b,self._b])) self.assertEquals('B,B...', test1.testVarArgs(self._c, [self._c,self._b])) self.assertEquals('B,B...', test1.testVarArgs(self._c, JArray(self._cclass,1)([self._c,self._c]))) self.assertEquals('B,B...', test1.testVarArgs(self._c, None)) self.assertEquals('B,B...', test1.testVarArgs(None, None)) def testPrimitive(self): test1 = self.__jp.Test1() intexpectation = 'int' if not sys.version_info[0] > 2 and sys.maxint == 2**31 - 1 else 'long' self.assertEquals(intexpectation, test1.testPrimitive(5)) self.assertEquals('long', test1.testPrimitive(2**31)) self.assertEquals('byte', test1.testPrimitive(JByte(5))) self.assertEquals('Byte', test1.testPrimitive(java.lang.Byte(5))) self.assertEquals('short', test1.testPrimitive(JShort(5))) self.assertEquals('Short', test1.testPrimitive(java.lang.Short(5))) self.assertEquals('int', test1.testPrimitive(JInt(5))) self.assertEquals('Integer', test1.testPrimitive(java.lang.Integer(5))) self.assertEquals('long', test1.testPrimitive(JLong(5))) self.assertEquals('Long', test1.testPrimitive(java.lang.Long(5))) self.assertEquals('float', test1.testPrimitive(JFloat(5))) self.assertEquals('Float', test1.testPrimitive(java.lang.Float(5.0))) self.assertEquals('double', test1.testPrimitive(JDouble(5))) self.assertEquals('Double', test1.testPrimitive(java.lang.Double(5.0))) self.assertEquals('boolean', test1.testPrimitive(JBoolean(5))) self.assertEquals('Boolean', test1.testPrimitive(java.lang.Boolean(5))) self.assertEquals('char', test1.testPrimitive(JChar('5'))) self.assertEquals('Character', test1.testPrimitive(java.lang.Character('5'))) def testInstanceVsClassMethod(self): # this behaviour is different than the one in java, so maybe we should change it? test1 = self.__jp.Test1() self.assertEquals('static B', self.__jp.Test1.testInstanceVsClass(self._c)) self.assertEquals('instance A', test1.testInstanceVsClass(self._c)) # here what would the above resolve to in java self.assertEquals('static B', self.__jp.Test1.testJavaInstanceVsClass()) def testInterfaces1(self): test1 = self.__jp.Test1() self.assertRaisesRegexp(RuntimeError, 'Ambiguous overloads found', test1.testInterfaces1, self._i4impl) self.assertEquals('I2', test1.testInterfaces1(JObject(self._i4impl, 'jpype.overloads.Test1$I2'))) self.assertEquals('I3', test1.testInterfaces1(JObject(self._i4impl, 'jpype.overloads.Test1$I3'))) def testInterfaces2(self): test1 = self.__jp.Test1() self.assertEquals('I4', test1.testInterfaces2(self._i4impl)) self.assertEquals('I2', test1.testInterfaces2(JObject(self._i4impl, 'jpype.overloads.Test1$I2'))) self.assertEquals('I3', test1.testInterfaces2(JObject(self._i4impl, 'jpype.overloads.Test1$I3'))) def testInterfaces3(self): test1 = self.__jp.Test1() self.assertRaisesRegexp(RuntimeError, 'Ambiguous overloads found', test1.testInterfaces3, self._i8impl) self.assertEquals('I4', test1.testInterfaces3(self._i6impl)) self.assertRaisesRegexp(RuntimeError, 'No matching overloads found', test1.testInterfaces3, self._i3impl) def testInterfaces4(self): test1 = self.__jp.Test1() self.assertEquals('I8', test1.testInterfaces4(None)) self.assertEquals('I1', test1.testInterfaces4(self._i1impl)) self.assertEquals('I2', test1.testInterfaces4(self._i2impl)) self.assertEquals('I3', test1.testInterfaces4(self._i3impl)) self.assertEquals('I4', test1.testInterfaces4(self._i4impl)) self.assertEquals('I5', test1.testInterfaces4(self._i5impl)) self.assertEquals('I6', test1.testInterfaces4(self._i6impl)) self.assertEquals('I7', test1.testInterfaces4(self._i7impl)) self.assertEquals('I8', test1.testInterfaces4(self._i8impl)) def testClassVsObject(self): test1 = self.__jp.Test1() self.assertEquals('Object', test1.testClassVsObject(self._i4impl)) self.assertEquals('Object', test1.testClassVsObject(1)) self.assertEquals('Class', test1.testClassVsObject(None)) self.assertEquals('Class', test1.testClassVsObject(JClass('jpype.overloads.Test1$I4Impl'))) self.assertEquals('Class', test1.testClassVsObject(JClass('jpype.overloads.Test1$I3'))) def testStringArray(self): test1 = self.__jp.Test1() self.assertEquals('Object', test1.testStringArray(self._i4impl)) self.assertEquals('Object', test1.testStringArray(1)) self.assertRaisesRegexp(RuntimeError, 'Ambiguous overloads found', test1.testStringArray, None) self.assertEquals('String', test1.testStringArray('somestring')) self.assertEquals('String[]', test1.testStringArray([])) self.assertEquals('String[]', test1.testStringArray(['a','b'])) self.assertEquals('String[]', test1.testStringArray(JArray(java.lang.String,1)(['a','b']))) self.assertEquals('Object', test1.testStringArray(JArray(JInt, 1)([1,2]))) def testListVSArray(self): test1 = self.__jp.Test1() self.assertEquals('String[]', test1.testListVSArray(['a','b'])) self.assertEquals('List', test1.testListVSArray(jpype.java.util.Arrays.asList(['a','b']))) def testDefaultMethods(self): try: testdefault = JClass('jpype.overloads.Test1$DefaultC')() except: pass else: self.assertEquals('B', testdefault.defaultMethod()) jpype-0.6.2+dfsg/test/jpypetest/properties.py0000664000175000017500000000426613036015411020637 0ustar takakitakakifrom . import common class PropertiesTestCase(common.JPypeTestCase): def setUp(self): super(PropertiesTestCase, self).setUp() self._bean = self.jpype.properties.TestBean() def testPropertyPublicMethodOverlap(self): self._bean.setProperty1("val") self.assertEqual("getsetval", self._bean.getProperty1()) def testPublicMethodPropertyOverlap(self): self.assertEqual("method", self._bean.property1()) def testPropertyProtectedMethodOverlapInvisibleAttribute(self): self._bean.property2 = "val" self.assertEqual("getsetval", self._bean.property2) def testProtectedMethodPropertyOverlapInvisibleAttribute(self): self.assertFalse(hasattr(self._bean.property2, '__call__')) def testPropertyProtectedMethodOverlapAttribute(self): self._bean.property3 = "val" self.assertEqual("getsetval", self._bean.property3) def testProtectedMethodPropertyOverlapAttribute(self): self.assertFalse(hasattr(self._bean.property3, '__call__')) def testPropertyProtectedMethodOverlapAttributeSet(self): self._bean.setProperty3("val") self.assertEqual("getsetval", self._bean.property3) def testPropertyProtectedMethodOverlapAttributeGet(self): self._bean.property3 = "val" self.assertEqual("getsetval", self._bean.getProperty3()) def testPrivateAttributeNoThreeCharacterMethodMatchCollision(self): self._bean.property4 ="val" self.assertEqual("abcval", self._bean.abcProperty4()) def testPropertyOnlySetter(self): self._bean.property5 = "val" self.assertEqual("returnsetval", self._bean.returnProperty5()) def testPropertyOnlySetterSet(self): self._bean.setProperty5("val") self.assertEqual("setval", self._bean.property5) def testPropertyDifferentAttribute(self): self._bean.property6 = "val" self.assertEqual("getsetval", self._bean.property6) self.assertEqual("setval", self._bean.property7) def testProertyDifferentAttributeSet(self): self._bean.setProperty6("val") self.assertEqual("getsetval", self._bean.property6) self.assertEqual("setval", self._bean.property7) jpype-0.6.2+dfsg/test/jpypetest/proxy.py0000664000175000017500000001044013036015411017613 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from jpype import * from . import common try: import unittest2 as unittest except ImportError: import unittest def _testMethod1(): return 33 def _testMethod2(): return 32 def _testMethod3(): return "Foo" class C: def testMethod1(self): return 43 def testMethod2(self): return 42 def testMethod3(self): return "Bar" def write(self, bytes, start, length): return bytes, start, length class ThreadCallbackImpl: def __init__(self): self.values = [] def notifyValue(self, val): self.values.append(val) class ProxyTestCase(common.JPypeTestCase): def setUp(self): super(ProxyTestCase, self).setUp() self.package = JPackage("jpype.proxy") self._triggers = self.package.ProxyTriggers def testProxyWithDict(self): d = { 'testMethod1': _testMethod1, 'testMethod2': _testMethod2, } itf1 = self.package.TestInterface1 itf2 = self.package.TestInterface2 proxy = JProxy([itf1, itf2], dict=d) result = self._triggers.testProxy(proxy) expected = ['Test Method1 = 33', 'Test Method2 = 32'] self.assertSequenceEqual(result, expected) def testProxyWithDictInherited(self): d = { 'testMethod2': _testMethod2, 'testMethod3': _testMethod3, } itf3 = self.package.TestInterface3 proxy = JProxy(itf3, dict=d) result = self._triggers.testProxy(proxy) expected = ['Test Method2 = 32', 'Test Method3 = Foo'] self.assertSequenceEqual(result, expected) def testProxyWithInst(self): itf3 = self.package.TestInterface3 c = C() proxy = JProxy(itf3, inst=c) result = self._triggers.testProxy(proxy) expected = ['Test Method2 = 42', 'Test Method3 = Bar'] self.assertSequenceEqual(result, expected) def testProxyWithThread(self): itf = self.package.TestThreadCallback tcb = ThreadCallbackImpl() proxy = JProxy(itf, inst=tcb) self._triggers().testProxyWithThread(proxy) self.assertEqual(tcb.values, ['Waiting for thread start', '1', '2', '3', 'Thread finished']) def testProxyWithArguments(self): itf2 = self.package.TestInterface2 c = C() proxy = JProxy(itf2, inst=c) result = self._triggers().testCallbackWithParameters(proxy) bytes, start, length = result self.assertSequenceEqual(bytes, [1, 2 ,3 ,4]) self.assertEqual(start, 12) self.assertEqual(length, 13) def testProxyWithMultipleInterface(self): itf1 = self.package.TestInterface1 itf2 = self.package.TestInterface2 c = C() proxy = JProxy([itf1, itf2], inst=c) result = self._triggers.testProxy(proxy) expected = ['Test Method1 = 43', 'Test Method2 = 42'] self.assertSequenceEqual(result, expected) def testProxyWithMultipleInterfaceInherited(self): itf2 = self.package.TestInterface2 itf3 = self.package.TestInterface3 c = C() proxy = JProxy([itf2,itf3], inst=c) result = self._triggers().testCallbackWithParameters(proxy) bytes, start, length = result self.assertSequenceEqual(bytes, [1, 2 ,3 ,4]) self.assertEqual(start, 12) self.assertEqual(length, 13) jpype-0.6.2+dfsg/test/jpypetest/serial.py0000664000175000017500000000331313036015411017712 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from jpype import JException, java, JavaException, JProxy, JClass import os import tempfile import traceback from . import common class SerializationTestCase(common.JPypeTestCase): def setUp(self): super(SerializationTestCase, self).setUp() self.tempname = tempfile.mktemp() def tearDown(self): os.remove(self.tempname) def testSerialize(self): o = JClass("jpype.serial.SerializationTest")() fos = java.io.FileOutputStream(self.tempname) oos = java.io.ObjectOutputStream(fos) oos.writeObject(o) oos.flush() oos.close() fos.close() # The following cannto work because JPype has no way to simulate the "caller's ClassLoader" # def testDeSerialize(self): # fis = java.io.FileInputStream(self.tempname) # ois = java.io.ObjectInputStream(fis) # # o = ois.readObject() # ois.close() # fis.close() jpype-0.6.2+dfsg/test/lists_and_maps.py0000664000175000017500000000121513036015411017403 0ustar takakitakakifrom jpype import * import time startJVM(getDefaultJVMPath()) #startJVM("c:/tools/jdk1.4.2/jre/bin/server/jvm.dll") arr = java.util.ArrayList() # no matching overloads found for this line: arr.addAll([str(x) for x in xrange(50)]) print arr hmap = java.util.HashMap() # no matching overloads found for this line: hmap.putAll({5:6, 7:8, 'hello':'there'}) print hmap #for x in xrange(5): # # this works: # hmap.put(str(x), str(x)) # # but this doesn't: # hmap.put(str(x), x) # # ## this throws: AttributeError: 'java.util.HashMap' object has no attribute 'iterator' #for x in hmap: # print x, hmap[x] jpype-0.6.2+dfsg/test/nbproject/0000775000175000017500000000000013036015411016020 5ustar takakitakakijpype-0.6.2+dfsg/test/nbproject/project.xml0000664000175000017500000000462213036015411020214 0ustar takakitakaki org.netbeans.modules.ant.freeform JPype - Native java harness compile test clean clean compile harness build.xml harness 1.7 jpype-0.6.2+dfsg/test/python_dom.py0000664000175000017500000000276213036015411016573 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** from os import path import time from xml.dom import minidom def output(el, prefix="") : if el.nodeType != el.ELEMENT_NODE : return #print prefix, "<", el.tagName, atts = el.attributes for i in range(atts.length) : a = atts.item(i); #print a.nodeName, '="%s"' % a.nodeValue, #print '>' nl = el.childNodes for i in range(nl.length) : output(nl.item(i), prefix+" ") #print prefix, "" t = time.time() count = 30 for i in range(count) : doc = minidom.parse(path.join(path.dirname(__file__), "sample", "big.xml")) el = doc.documentElement output(el) t2 = time.time() print count, "iterations in", t2-t, "seconds" jpype-0.6.2+dfsg/test/sample/0000775000175000017500000000000013240004460015312 5ustar takakitakakijpype-0.6.2+dfsg/test/stub.py0000664000175000017500000000162313036015411015363 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import jpype jpype.startJVM(jpype.getDefaultJVMPath(), "-ea") s = jpype.java.lang.String t = jpype.java.awt.Color print s print t jpype-0.6.2+dfsg/test/test_awt.py0000664000175000017500000000050513036015411016236 0ustar takakitakakifrom jpype import * import time def run(): print 'Thread started' try: print repr(java.awt.Frame) javax.swing.JFrame("Test Frame").setVisible(True) shutdownGuiEnvironment() except JException, ex : print ex startJVM(getDefaultJVMPath()) setupGuiEnvironment(run) jpype-0.6.2+dfsg/test/test_jarray_fixes.py0000775000175000017500000000352313036015411020137 0ustar takakitakaki#!/usr/bin/env python """ Checks for memory leak in the JVM when pushing array data from Python to Java. """ import pytest import jpype #!!! These settings are finely tuned !!! #!!! DO NOT fiddle with them unless you know what you are doing !!! # Size of array to be copied. ARRAY_SIZE = 4000000 # Number of iterations to run. # - raise this value to increase efficacy of the memory leak test. ITERATIONS = 10 # Maximum size of JVM heap. # - sets a cap to allow memory leak detection. MAX_JVM_HEAP_SIZE_BYTES = 128647168 def setup_module(module): # Module-level setup. if not jpype.isJVMStarted(): jvm_args = [ '-Xmx%dM' % (MAX_JVM_HEAP_SIZE_BYTES // 1000 ** 2), ] jpype.startJVM(jpype.getDefaultJVMPath(), *jvm_args) module.JavaDoubleArray = jpype.JArray(jpype.JDouble, 1) def test_memory_leak_fix(): """ This test raises java.lang.VirtualMachineErrorPyRaisable (java.lang.OutOfMemoryError: Java heap space) if the memory leak is present. """ # Check memory settings. rt = jpype.java.lang.Runtime.getRuntime() assert rt.maxMemory() == MAX_JVM_HEAP_SIZE_BYTES # Perform leak test. for i in xrange(ITERATIONS): print 'iteration:', i py_list1 = [float(f) for f in xrange(ARRAY_SIZE)] j_array1 = JavaDoubleArray(py_list1) py_list2 = j_array1[:] assert py_list1 == py_list2 def test_jarray_basic_slicing_fix(): jl1 = JavaDoubleArray([1., 2., 3.]) assert list(jl1) == [1., 2., 3.] assert list(jl1[0:-1]) == [1., 2.] assert list(jl1[0:1]) == [1.] def test_jarray_slice_copy_fix(): jl1 = JavaDoubleArray([1., 2., 3.]) pl1 = jl1[:] assert list(jl1) == pl1 def test_jarray_slice_assignment_fix(): jl2 = JavaDoubleArray([1., 2., 3.]) jl2[:] = [4., 5., 6.] assert list(jl2) == [4., 5., 6.] jpype-0.6.2+dfsg/test/testlucene.py0000664000175000017500000000236713036015411016567 0ustar takakitakakifrom os import path import shutil import tempfile from jpype import * lucene_jar = path.join("..", "build", "lucene-1.4.3.jar") if not path.isfile(lucene_jar): raise IOError, "Please provide %s" % path.abspath(lucene_jar) startJVM(getDefaultJVMPath(),'-Djava.class.path=%s' % lucene_jar) QueryParser = JClass("org.apache.lucene.queryParser.QueryParser") IndexSearcher = JClass("org.apache.lucene.search.IndexSearcher") IndexReader = JClass("org.apache.lucene.index.IndexReader") StandardAnalyzer = JClass("org.apache.lucene.analysis.standard.StandardAnalyzer") FSDirectory = JClass("org.apache.lucene.store.FSDirectory") IndexWriter = JClass("org.apache.lucene.index.IndexWriter") SimpleAnalyzer = JClass("org.apache.lucene.analysis.SimpleAnalyzer") tmppath = tempfile.mkdtemp() IndexWriter(tmppath, SimpleAnalyzer(), True).close() directory = FSDirectory.getDirectory(tmppath, False) reader = IndexReader.open(directory) searcher = IndexSearcher(reader) queryparser = QueryParser.parse("wenger","contents",StandardAnalyzer()) print queryparser.rewrite print queryparser.rewrite.matchReport(reader) qp = queryparser.rewrite(reader) print qp print searcher.search.matchReport(qp) hits = searcher.search(qp) shutil.rmtree(tmppath) jpype-0.6.2+dfsg/test/testsuite.py0000664000175000017500000000313013036015411016432 0ustar takakitakaki#***************************************************************************** # Copyright 2004-2008 Steve Menard # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #***************************************************************************** import unittest import jpype import logging import os.path import pkgutil import sys def suite() : loader = unittest.defaultTestLoader if len(sys.argv) > 1: names = sys.argv[1:] test_suite = loader.loadTestsFromNames(names) else: import jpypetest pkgpath = os.path.dirname(jpypetest.__file__) names = ["jpypetest.%s" % name for _, name, _ in pkgutil.iter_modules([pkgpath])] test_suite = loader.loadTestsFromNames(names) return test_suite def runTest() : runner = unittest.TextTestRunner() result = runner.run(suite()) if jpype.isJVMStarted(): jpype.shutdownJVM() if not result.wasSuccessful(): sys.exit(1) if __name__ == '__main__' : logging.basicConfig(level=logging.INFO) runTest() jpype-0.6.2+dfsg/test/transform_xunit_to_appveyor.xsl0000664000175000017500000000660413036015411022461 0ustar takakitakaki Fail Skip Pass