Skip to content

Commit

Permalink
Merge branch 'py3'
Browse files Browse the repository at this point in the history
  • Loading branch information
rudimeier committed Mar 16, 2017
2 parents baa1d6d + 99810a4 commit 8400572
Show file tree
Hide file tree
Showing 20 changed files with 477 additions and 397 deletions.
24 changes: 24 additions & 0 deletions _jcc/boot.cpp
Expand Up @@ -49,15 +49,39 @@ PyObject *__initialize__(PyObject *module, PyObject *args, PyObject *kwds)

extern "C" {

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef _jccmodule = {
PyModuleDef_HEAD_INIT, /* m_base */
"_jcc", /* m_name */
"_jcc module", /* m_doc */
0, /* m_size */
jcc_funcs, /* m_methods */
0, /* m_reload */
0, /* m_traverse */
0, /* m_clear */
0, /* m_free */
};

PyObject *PyInit__jcc(void)
{
PyObject *m = PyModule_Create(&_jccmodule);
if (!m)
return NULL;
#else
void init_jcc(void)
{
PyObject *m = Py_InitModule3("_jcc", jcc_funcs, "_jcc");
#endif

initJCC(m);

INSTALL_TYPE(JObject, m);
INSTALL_TYPE(ConstVariableDescriptor, m);
java::lang::__install__(m);
java::io::__install__(m);

#if PY_MAJOR_VERSION >= 3
return m;
#endif
}
}
9 changes: 3 additions & 6 deletions _jcc/java/lang/Class.cpp
Expand Up @@ -397,17 +397,14 @@ namespace java {

static PyObject *t_Class_forName(PyTypeObject *type, PyObject *arg)
{
if (!PyString_Check(arg))
if (arg == Py_None)
{
PyErr_SetObject(PyExc_TypeError, arg);
PyErr_SetObject(PyExc_ValueError, arg);
return NULL;
}

try {
char *className = PyString_AsString(arg);
String name = String(env->fromUTF(className));

return t_Class::wrap_Object(Class::forName(name));
return t_Class::wrap_Object(Class::forName(p2j(arg)));
} catch (int e) {
switch (e) {
case _EXC_JAVA:
Expand Down
15 changes: 8 additions & 7 deletions helpers/darwin.py
Expand Up @@ -10,6 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import sys, os

global JAVAHOME, JAVAFRAMEWORKS
Expand All @@ -24,17 +25,17 @@
try:
args = ['/usr/libexec/java_home']
process = Popen(args, stdout=PIPE, stderr=PIPE)
except Exception, e:
print >>sys.stderr, "%s: %s" %(e, args)
except Exception as e:
print("%s: %s" %(e, args), file=sys.stderr)
else:
process.wait()
if process.returncode == 0:
_path = process.stdout.read().strip()
_path = process.stdout.read().strip().decode()
if os.path.exists(os.path.join(_path, "include", "jni.h")):
JAVAHOME = _path
print >>sys.stderr, 'found JAVAHOME =', JAVAHOME
print('found JAVAHOME =', JAVAHOME, file=sys.stderr)
else:
print >>sys.stderr, process.stderr.read()
print(process.stderr.read().strip().decode(), file=sys.stderr)

# figure out where the JDK Frameworks lives
import platform, re
Expand All @@ -44,14 +45,14 @@
_path = "/System/Library/Frameworks/JavaVM.framework"
if os.path.exists(os.path.join(_path, "Headers", "jni.h")):
JAVAFRAMEWORKS = _path
print >>sys.stderr, 'found JAVAFRAMEWORKS =', JAVAFRAMEWORKS
print('found JAVAFRAMEWORKS =', JAVAFRAMEWORKS, file=sys.stderr)
else:
# but their updates don't always match their documentation,
# so look up the same path in the OS's /Developer tree
_path = "/Developer/SDKs/MacOSX%s.sdk%s" %(_os_version, _path)
if os.path.exists(os.path.join(_path, "Headers", "jni.h")):
JAVAFRAMEWORKS = _path
print >>sys.stderr, 'found JAVAFRAMEWORKS =', JAVAFRAMEWORKS
print('found JAVAFRAMEWORKS =', JAVAFRAMEWORKS, file=sys.stderr)

# monkeypatch customize_compiler so that we can remove -Wl,-x from LDSHARED
# set in setuptools.command.build_ext.build_ext.setup_shlib_compiler
Expand Down
3 changes: 2 additions & 1 deletion helpers/linux.py
Expand Up @@ -10,6 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import sys, os, os.path, re
import distutils, setuptools

Expand Down Expand Up @@ -70,7 +71,7 @@ def patch_setuptools(with_setuptools):
build_ext.libtype = 'static'
build_ext.link_shared_object = st_link_shared_object

print >>sys.stderr, "Applied shared mode monkey patch to:", setuptools
print("Applied shared mode monkey patch to:", setuptools, file=sys.stderr)
return True # monkey patch was applied

return enable_shared
Expand Down
2 changes: 1 addition & 1 deletion helpers/windows.py
Expand Up @@ -19,7 +19,7 @@
# figure out where the JDK lives

try:
import _winreg as wreg
import winreg as wreg

class WindowsRegistry:
# see the Python Cookbook, #146305, Dirk Holtwick
Expand Down
5 changes: 3 additions & 2 deletions jcc/__init__.py
Expand Up @@ -12,12 +12,13 @@

# jcc package

from __future__ import absolute_import
import os, sys

if sys.platform == 'win32':

if '--find-jvm-dll' in sys.argv:
from windows import add_jvm_dll_directory_to_path
from .windows import add_jvm_dll_directory_to_path
add_jvm_dll_directory_to_path()

from jcc.config import SHARED
Expand All @@ -34,7 +35,7 @@
if __name__ == '__main__':
import jcc.__main__
else:
from _jcc import initVM
from ._jcc import initVM

CLASSPATH=os.path.join(os.path.abspath(os.path.dirname(__file__)), "classes")
_jcc.CLASSPATH = CLASSPATH
5 changes: 3 additions & 2 deletions jcc/__main__.py
@@ -1,4 +1,5 @@

from __future__ import absolute_import
from __future__ import print_function
import sys

from jcc import cpp
Expand Down Expand Up @@ -101,7 +102,7 @@
--extra-setup-arg - pass an extra argument on setup.py command line
(pip install uses --egg-base and --record params)
'''
print help
print(help)
sys.exit(0)

cpp.jcc(sys.argv)

0 comments on commit 8400572

Please sign in to comment.