Hi,
I started working on getting unbound work with Python 3.x and here are the
first results. With the attached patches, the unbound source code still builds
with Python 2.x but also builds with Python 3.x.
To test it, you need to configure the sources to build all the python stuff:
./configure --with-pythonmodule --with-pyunbound
So far I tested on Gentoo with the exact command above, as /usr/bin/python is
Python 3.x by default. I also tested it using a live Gentoo ebuild[1] and I'm
going to build it for Fedora[2] as part of the feature to use Python 3.x as the
default implementation on Fedora[3].
[1]
https://github.com/okias/ixit/blob/master/net-dns/unbound/unbound-9999.ebuild
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1115489
[3] https://fedoraproject.org/wiki/Changes/Python_3_as_Default
Note that the two patches represent the minimal changes needed to *build*
unbound with Python 3.x, that doesn't say whether the successful build will
also *work* properly, it is just the first step for it. Next step will be to
identify the issues that arise.
Cheers,
Pavel
From a9d2ae49c82d1de97e624a938b04dcab40ef5a19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20=C5=A0imerda?= <[email protected]>
Date: Mon, 15 Sep 2014 18:17:08 +0200
Subject: [PATCH 1/2] configure: don't choke when built Python 3.x
Tested on Gentoo using:
./configure --with-pythonmodule --with-pyunbound LDFLAGS=-L/usr/lib64/python3.3/
---
aclocal.m4 | 23 ++++++++++++++++-------
acx_python.m4 | 36 +++++++++++++++++-------------------
configure | 57 ++++++++++++++++++++++++++++++++-------------------------
configure.ac | 2 +-
4 files changed, 66 insertions(+), 52 deletions(-)
diff --git a/aclocal.m4 b/aclocal.m4
index 4e52c65..7a1cd5e 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,4 +1,4 @@
-# generated automatically by aclocal 1.12.2 -*- Autoconf -*-
+# generated automatically by aclocal 1.12.6 -*- Autoconf -*-
# Copyright (C) 1996-2012 Free Software Foundation, Inc.
@@ -2484,7 +2484,14 @@ freebsd* | dragonfly*)
*) objformat=elf ;;
esac
fi
- version_type=freebsd-$objformat
+ # Handle Gentoo/FreeBSD as it was Linux
+ case $host_vendor in
+ gentoo)
+ version_type=linux ;;
+ *)
+ version_type=freebsd-$objformat ;;
+ esac
+
case $version_type in
freebsd-elf*)
library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
@@ -2495,6 +2502,12 @@ freebsd* | dragonfly*)
library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
need_version=yes
;;
+ linux)
+ library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+ soname_spec='${libname}${release}${shared_ext}$major'
+ need_lib_prefix=no
+ need_version=no
+ ;;
esac
shlibpath_var=LD_LIBRARY_PATH
case $host_os in
@@ -2674,14 +2687,10 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu)
# before this can be enabled.
hardcode_into_libs=yes
- # Add ABI-specific directories to the system library path.
- sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib"
-
# Append ld.so.conf contents to the search path
if test -f /etc/ld.so.conf; then
lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '`
- sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
-
+ sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
fi
# We used to test for /lib/ld.so.1 and disable shared libraries on
diff --git a/acx_python.m4 b/acx_python.m4
index 99ffa25..8945401 100644
--- a/acx_python.m4
+++ b/acx_python.m4
@@ -14,17 +14,17 @@ AC_DEFUN([AC_PYTHON_DEVEL],[
fi
if test -z "$PYTHON_VERSION"; then
- PYTHON_VERSION=`$PYTHON -c "import sys, string; \
- print string.split(sys.version)[[0]]"`
+ PYTHON_VERSION=`$PYTHON -c "import sys; \
+ print(sys.version.split()[[0]])"`
fi
#
# Check for a version of Python >= 2.1.0
#
AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
- ac_supports_python_ver=`$PYTHON -c "import sys, string; \
- ver = string.split(sys.version)[[0]]; \
- print ver >= '2.1.0'"`
+ ac_supports_python_ver=`$PYTHON -c "import sys; \
+ ver = sys.version.split()[[0]]; \
+ print(ver >= '2.1.0')"`
if test "$ac_supports_python_ver" != "True"; then
if test -z "$PYTHON_NOVERSIONCHECK"; then
AC_MSG_RESULT([no])
@@ -49,9 +49,9 @@ to something else than an empty string.
#
if test -n "$1"; then
AC_MSG_CHECKING([for a version of Python $1])
- ac_supports_python_ver=`$PYTHON -c "import sys, string; \
- ver = string.split(sys.version)[[0]]; \
- print ver $1"`
+ ac_supports_python_ver=`$PYTHON -c "import sys; \
+ ver = sys.version.split()[[0]]; \
+ print(ver $1)"`
if test "$ac_supports_python_ver" = "True"; then
AC_MSG_RESULT([yes])
else
@@ -86,7 +86,7 @@ $ac_distutils_result])
AC_MSG_CHECKING([for Python include path])
if test -z "$PYTHON_CPPFLAGS"; then
python_path=`$PYTHON -c "import distutils.sysconfig; \
- print distutils.sysconfig.get_python_inc();"`
+ print(distutils.sysconfig.get_python_inc());"`
if test -n "${python_path}"; then
python_path="-I$python_path"
fi
@@ -103,22 +103,20 @@ $ac_distutils_result])
# (makes two attempts to ensure we've got a version number
# from the interpreter)
py_version=`$PYTHON -c "from distutils.sysconfig import *; \
- from string import join; \
- print join(get_config_vars('VERSION'))"`
+ print(''.join(get_config_vars('VERSION')))"`
if test "$py_version" = "[None]"; then
if test -n "$PYTHON_VERSION"; then
py_version=$PYTHON_VERSION
else
py_version=`$PYTHON -c "import sys; \
- print sys.version[[:3]]"`
+ print(sys.version[[:3]])"`
fi
fi
PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
- from string import join; \
- print '-L' + get_python_lib(0,1), \
- '-L' + os.path.dirname(get_python_lib(0,1)), \
- '-lpython';"`$py_version
+ print('-L' + get_python_lib(0,1) \
+ + ' -L' + os.path.dirname(get_python_lib(0,1)) \
+ + ' -lpython');"`$py_version
fi
AC_MSG_RESULT([$PYTHON_LDFLAGS])
AC_SUBST([PYTHON_LDFLAGS])
@@ -129,7 +127,7 @@ $ac_distutils_result])
AC_MSG_CHECKING([for Python site-packages path])
if test -z "$PYTHON_SITE_PKG"; then
PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
- print distutils.sysconfig.get_python_lib(1,0);"`
+ print(distutils.sysconfig.get_python_lib(1,0));"`
fi
AC_MSG_RESULT([$PYTHON_SITE_PKG])
AC_SUBST([PYTHON_SITE_PKG])
@@ -141,7 +139,7 @@ $ac_distutils_result])
if test -z "$PYTHON_EXTRA_LIBS"; then
PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
- print conf('LOCALMODLIBS'), conf('LIBS')"`
+ print(conf('LOCALMODLIBS'), conf('LIBS'))"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
AC_SUBST(PYTHON_EXTRA_LIBS)
@@ -153,7 +151,7 @@ $ac_distutils_result])
if test -z "$PYTHON_EXTRA_LDFLAGS"; then
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
- print conf('LINKFORSHARED')"`
+ print(conf('LINKFORSHARED'))"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
AC_SUBST(PYTHON_EXTRA_LDFLAGS)
diff --git a/configure b/configure
index 24c51cd..1af6628 100755
--- a/configure
+++ b/configure
@@ -12505,7 +12505,14 @@ freebsd* | dragonfly*)
*) objformat=elf ;;
esac
fi
- version_type=freebsd-$objformat
+ # Handle Gentoo/FreeBSD as it was Linux
+ case $host_vendor in
+ gentoo)
+ version_type=linux ;;
+ *)
+ version_type=freebsd-$objformat ;;
+ esac
+
case $version_type in
freebsd-elf*)
library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
@@ -12516,6 +12523,12 @@ freebsd* | dragonfly*)
library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
need_version=yes
;;
+ linux)
+ library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+ soname_spec='${libname}${release}${shared_ext}$major'
+ need_lib_prefix=no
+ need_version=no
+ ;;
esac
shlibpath_var=LD_LIBRARY_PATH
case $host_os in
@@ -12714,14 +12727,10 @@ fi
# before this can be enabled.
hardcode_into_libs=yes
- # Add ABI-specific directories to the system library path.
- sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib"
-
# Append ld.so.conf contents to the search path
if test -f /etc/ld.so.conf; then
lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '`
- sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra"
-
+ sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
fi
# We used to test for /lib/ld.so.1 and disable shared libraries on
@@ -15924,8 +15933,8 @@ fi
fi
if test -z "$PYTHON_VERSION"; then
- PYTHON_VERSION=`$PYTHON -c "import sys, string; \
- print string.split(sys.version)[0]"`
+ PYTHON_VERSION=`$PYTHON -c "import sys; \
+ print(sys.version.split()[0])"`
fi
#
@@ -15933,9 +15942,9 @@ fi
#
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a version of Python >= '2.1.0'" >&5
$as_echo_n "checking for a version of Python >= '2.1.0'... " >&6; }
- ac_supports_python_ver=`$PYTHON -c "import sys, string; \
- ver = string.split(sys.version)[0]; \
- print ver >= '2.1.0'"`
+ ac_supports_python_ver=`$PYTHON -c "import sys; \
+ ver = sys.version.split()[0]; \
+ print(ver >= '2.1.0')"`
if test "$ac_supports_python_ver" != "True"; then
if test -z "$PYTHON_NOVERSIONCHECK"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -15967,9 +15976,9 @@ $as_echo "yes" >&6; }
if test -n ""; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a version of Python " >&5
$as_echo_n "checking for a version of Python ... " >&6; }
- ac_supports_python_ver=`$PYTHON -c "import sys, string; \
- ver = string.split(sys.version)[0]; \
- print ver "`
+ ac_supports_python_ver=`$PYTHON -c "import sys; \
+ ver = sys.version.split()[0]; \
+ print(ver )"`
if test "$ac_supports_python_ver" = "True"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
@@ -16010,7 +16019,7 @@ $ac_distutils_result" "$LINENO" 5
$as_echo_n "checking for Python include path... " >&6; }
if test -z "$PYTHON_CPPFLAGS"; then
python_path=`$PYTHON -c "import distutils.sysconfig; \
- print distutils.sysconfig.get_python_inc();"`
+ print(distutils.sysconfig.get_python_inc());"`
if test -n "${python_path}"; then
python_path="-I$python_path"
fi
@@ -16029,22 +16038,20 @@ $as_echo_n "checking for Python library path... " >&6; }
# (makes two attempts to ensure we've got a version number
# from the interpreter)
py_version=`$PYTHON -c "from distutils.sysconfig import *; \
- from string import join; \
- print join(get_config_vars('VERSION'))"`
+ print(''.join(get_config_vars('VERSION')))"`
if test "$py_version" = "None"; then
if test -n "$PYTHON_VERSION"; then
py_version=$PYTHON_VERSION
else
py_version=`$PYTHON -c "import sys; \
- print sys.version[:3]"`
+ print(sys.version[:3])"`
fi
fi
PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
- from string import join; \
- print '-L' + get_python_lib(0,1), \
- '-L' + os.path.dirname(get_python_lib(0,1)), \
- '-lpython';"`$py_version
+ print('-L' + get_python_lib(0,1) \
+ + ' -L' + os.path.dirname(get_python_lib(0,1)) \
+ + ' -lpython');"`$py_version
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_LDFLAGS" >&5
$as_echo "$PYTHON_LDFLAGS" >&6; }
@@ -16057,7 +16064,7 @@ $as_echo "$PYTHON_LDFLAGS" >&6; }
$as_echo_n "checking for Python site-packages path... " >&6; }
if test -z "$PYTHON_SITE_PKG"; then
PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
- print distutils.sysconfig.get_python_lib(1,0);"`
+ print(distutils.sysconfig.get_python_lib(1,0));"`
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_SITE_PKG" >&5
$as_echo "$PYTHON_SITE_PKG" >&6; }
@@ -16071,7 +16078,7 @@ $as_echo_n "checking python extra libraries... " >&6; }
if test -z "$PYTHON_EXTRA_LIBS"; then
PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
- print conf('LOCALMODLIBS'), conf('LIBS')"`
+ print(conf('LOCALMODLIBS'), conf('LIBS'))"`
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_EXTRA_LIBS" >&5
$as_echo "$PYTHON_EXTRA_LIBS" >&6; }
@@ -16085,7 +16092,7 @@ $as_echo_n "checking python extra linking flags... " >&6; }
if test -z "$PYTHON_EXTRA_LDFLAGS"; then
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
- print conf('LINKFORSHARED')"`
+ print(conf('LINKFORSHARED'))"`
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON_EXTRA_LDFLAGS" >&5
$as_echo "$PYTHON_EXTRA_LDFLAGS" >&6; }
diff --git a/configure.ac b/configure.ac
index 26e8abc..a22ddc9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -465,7 +465,7 @@ if test x_$ub_test_python != x_no; then
ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
AC_PYTHON_DEVEL
if test ! -z "$PYTHON_VERSION"; then
- if test `$PYTHON -c "print '$PYTHON_VERSION' >= '2.4.0'"` = "False"; then
+ if test `$PYTHON -c "print('$PYTHON_VERSION' >= '2.4.0')"` = "False"; then
AC_ERROR([Python version >= 2.4.0 is required])
fi
--
1.8.5.5
From 3db0c2b767edb745eea6466cca29b00906ccdadb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20=C5=A0imerda?= <[email protected]>
Date: Mon, 15 Sep 2014 18:40:50 +0200
Subject: [PATCH 2/2] use Python 3.x API correctly
---
libunbound/python/libunbound.i | 4 ++--
pythonmod/interface.i | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/libunbound/python/libunbound.i b/libunbound/python/libunbound.i
index 4f92799..78a0ed6 100644
--- a/libunbound/python/libunbound.i
+++ b/libunbound/python/libunbound.i
@@ -764,13 +764,13 @@ Result: ['74.125.43.147', '74.125.43.99', '74.125.43.103', '74.125.43.104']
list = PyList_New(cnt);
for (i=0;i<cnt;i++)
- PyList_SetItem(list, i, PyString_FromStringAndSize(result->data[i],result->len[i]));
+ PyList_SetItem(list, i, PyBytes_FromStringAndSize(result->data[i],result->len[i]));
return list;
}
PyObject* _packet() {
- return PyString_FromStringAndSize($self->answer_packet, $self->answer_len);
+ return PyBytes_FromStringAndSize($self->answer_packet, $self->answer_len);
}
%pythoncode %{
diff --git a/pythonmod/interface.i b/pythonmod/interface.i
index 606d85f..4f1a25f 100644
--- a/pythonmod/interface.i
+++ b/pythonmod/interface.i
@@ -48,7 +48,7 @@
list = PyList_New(cnt);
i = 0; cnt = 0;
while (i < len) {
- PyList_SetItem(list, cnt, PyString_FromStringAndSize(name + i + 1, name[i]));
+ PyList_SetItem(list, cnt, PyBytes_FromStringAndSize(name + i + 1, name[i]));
i += name[i] + 1;
cnt++;
}
@@ -148,7 +148,7 @@ struct query_info {
};
PyObject* _get_qname(struct query_info* q) {
- return PyString_FromStringAndSize((char*)q->qname, q->qname_len);
+ return PyBytes_FromStringAndSize((char*)q->qname, q->qname_len);
}
PyObject* _get_qname_components(struct query_info* q) {
@@ -210,7 +210,7 @@ uint16_t ntohs(uint16_t netshort);
%inline %{
PyObject* _get_dname(struct packed_rrset_key* k) {
- return PyString_FromStringAndSize((char*)k->dname, k->dname_len);
+ return PyBytes_FromStringAndSize((char*)k->dname, k->dname_len);
}
PyObject* _get_dname_components(struct packed_rrset_key* k) {
return GetNameAsLabelList((char*)k->dname, k->dname_len);
@@ -317,7 +317,7 @@ struct packed_rrset_data {
PyObject* _get_data_rr_data(struct packed_rrset_data* d, int idx) {
if ((d != NULL) && (idx >= 0) &&
((size_t)idx < (d->count+d->rrsig_count)))
- return PyString_FromStringAndSize((char*)d->rr_data[idx],
+ return PyBytes_FromStringAndSize((char*)d->rr_data[idx],
d->rr_len[idx]);
return Py_None;
}
--
1.8.5.5
_______________________________________________
Unbound-users mailing list
[email protected]
http://unbound.nlnetlabs.nl/mailman/listinfo/unbound-users