[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Tue May 19 14:18:03 MDT 2015


The branch, master has been updated
       via  0dcf535 Factor out submodule presence checking.
       via  5e08212 Make waf fail if submodules are out of date.
       via  5d672b9 Factor out function for finding Git binary.
       via  8eda4ef Drop bzr VCS support.
       via  8d56073 Simplify instructions for checking out submodules.
       via  e8de290 pytalloc: Test for all Python versions
       via  91b407f buildtools: Add a helper for running Python tests
       via  6f49000 buildtools: Add a helper to iterate through Python environments
       via  fb5d9c3 pytalloc: Build for two Python versions at once
       via  616dfae buildtools: Add --extra-python configure option
       via  13a91e5 buildtools: Expose the Python 3 ABI tag
       via  cd6615e pytalloc: Port to Python 3
      from  9f71b96 Fix a typo in the name of the default domain level

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 0dcf5357959d2bc5cb984eb0276684b56477ed62
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 18 20:19:23 2015 +0000

    Factor out submodule presence checking.
    
    Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Tue May 19 22:17:48 CEST 2015 on sn-devel-104

commit 5e0821201cc6b5ffc15b1b795ee85dabd3e9220c
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 18 20:00:30 2015 +0000

    Make waf fail if submodules are out of date.
    
    Instead, suggest the user run 'git submodule update'.
    
    This should prevent users from accidentally building Samba against
    outdated or too new versions of the bundled third party libraries
    after switching branches.
    
    I've opted to make this an error rather than actually
    running 'git submodule update' directly, as the latter could
    cause unpredictable behaviour. If we find that manually updating
    submodules is too cumbersome, we can always change this. The normal mode
    of operation for developers should not involve any submodules at all,
    but system versions of these libraries.
    
    Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 5d672b9a530e79aff2a7791df82893bcd50d6233
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 18 17:37:51 2015 +0000

    Factor out function for finding Git binary.
    
    Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 8eda4efacdeca4c6b8da8bd9e924af2f08db7f89
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Mon May 18 17:15:15 2015 +0000

    Drop bzr VCS support.
    
    Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 8d56073af8e759367ac9e4279c3c02d5abeb7c96
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Tue May 5 22:05:14 2015 +0000

    Simplify instructions for checking out submodules.
    
    Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit e8de2903fbbecac368347ffab019962ca66d43a6
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed May 6 18:05:18 2015 +0200

    pytalloc: Test for all Python versions
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

commit 91b407fc94fcd0015fe91b84619f3a6d1d3595f2
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Tue Mar 10 18:19:14 2015 +0100

    buildtools: Add a helper for running Python tests
    
    Add the function samba_utils.RUN_PYTHON_TESTS for running a Python
    test. When building for multiple Python versions, all are tested.
    
    Also, add the list of configured Python interpreters to build config.
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

commit 6f490000c6b233f275598a4680b2c49fcb69d35a
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed May 6 17:50:57 2015 +0200

    buildtools: Add a helper to iterate through Python environments
    
    This prevents code duplication to ensure the "extrapython" build
    is the same as the normal one.
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

commit fb5d9c3db17f4d40c15be7285edc296d14c69130
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed May 6 18:17:06 2015 +0200

    pytalloc: Build for two Python versions at once
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

commit 616dfae8ffa88bd6b8b1145bd9d75c5b873e7044
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Thu Jan 15 14:22:22 2015 +0100

    buildtools: Add --extra-python configure option
    
    This allows building Python support for two different Python versions
    at the same time.
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

commit 13a91e542737562e26368ca6a359cb20026bb724
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Wed May 6 12:45:42 2015 +0200

    buildtools: Expose the Python 3 ABI tag
    
    Expose the tag in the env to allow using it in pkg-config files
    
    Add a "pyembed_libname" function to correctly form library names.
    (This can't be done automatically in SAMBA_LIBRARY because the name
    could be used as a dependency for another library)
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

commit cd6615ecbd43d53fa353a18bd6db2291b086de2d
Author: Petr Viktorin <pviktori at redhat.com>
Date:   Thu Jan 15 14:07:09 2015 +0100

    pytalloc: Port to Python 3
    
    - Use native string for repr
    
    - Use rich comparison
      Removes the deprecated tp_compare in favor of tp_richcompare.
      Disparate types cannot be compared (except for == and !=),
      and True or False objects are returned explicitly.
    
    - Use Py_TYPE instead of ob_type
      This changed to conform to C aliasing rules,
      see http://legacy.python.org/dev/peps/pep-3123/
    
    - Don't provide CObject creation function
      A PyCapsule based replacement would be possible,
      but might not be necessary considering the function is
      not used much.
    
    - Use new-style module initialization
    
    Build changes:
    
    - Use ABI flag in the lib name and pkg-config template
    
    - Use the SAMBA_CHECK_PYTHON macro for finding Python
    
    Signed-off-by: Petr Viktorin <pviktori at redhat.com>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Jelmer Vernooij <jelmer at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 buildtools/wafsamba/samba_dist.py    |  6 ---
 buildtools/wafsamba/samba_git.py     | 57 +++++++++++++++++++++++
 buildtools/wafsamba/samba_install.py |  8 +++-
 buildtools/wafsamba/samba_python.py  | 75 ++++++++++++++++++++++++++++++-
 buildtools/wafsamba/samba_utils.py   | 16 +++++++
 buildtools/wafsamba/samba_version.py | 64 +++-----------------------
 buildtools/wafsamba/wafsamba.py      |  7 ++-
 buildtools/wafsamba/wscript          |  8 ++++
 lib/talloc/pytalloc-util.pc.in       |  2 +-
 lib/talloc/pytalloc.c                | 87 ++++++++++++++++++++++++++++++++----
 lib/talloc/pytalloc.h                |  2 +
 lib/talloc/pytalloc_guide.txt        | 10 +++++
 lib/talloc/pytalloc_util.c           |  4 ++
 lib/talloc/test_pytalloc.c           | 41 ++++++++++++++---
 lib/talloc/test_pytalloc.py          |  3 ++
 lib/talloc/wscript                   | 66 +++++++++++++--------------
 third_party/wscript                  |  6 +--
 wscript                              | 11 ++++-
 18 files changed, 350 insertions(+), 123 deletions(-)
 create mode 100644 buildtools/wafsamba/samba_git.py


Changeset truncated at 500 lines:

diff --git a/buildtools/wafsamba/samba_dist.py b/buildtools/wafsamba/samba_dist.py
index aecacb7..654a168 100644
--- a/buildtools/wafsamba/samba_dist.py
+++ b/buildtools/wafsamba/samba_dist.py
@@ -86,12 +86,6 @@ def vcs_dir_contents(path):
             env = dict(os.environ)
             env["GIT_DIR"] = os.path.join(repo, ".git")
             break
-        elif os.path.isdir(os.path.join(repo, ".bzr")):
-            ls_files_cmd = [ 'bzr', 'ls', '--recursive', '--versioned',
-                             os_path_relpath(path, repo)]
-            cwd = repo
-            env = None
-            break
         repo = os.path.dirname(repo)
     if repo == "/":
         raise Exception("unsupported or no vcs for %s" % path)
diff --git a/buildtools/wafsamba/samba_git.py b/buildtools/wafsamba/samba_git.py
new file mode 100644
index 0000000..c58a579
--- /dev/null
+++ b/buildtools/wafsamba/samba_git.py
@@ -0,0 +1,57 @@
+import os
+import subprocess
+
+def find_git(env=None):
+    """Find the git binary."""
+    if env is not None and 'GIT' in env:
+        return env['GIT']
+
+    # Get version from GIT
+    if os.path.exists("/usr/bin/git"):
+        # this is useful when doing make dist without configuring
+        return "/usr/bin/git"
+
+    return None
+
+
+def has_submodules(path):
+    """Check whether a source directory is git-versioned and has submodules.
+
+    :param path: Path to Samba source directory
+    """
+    return (os.path.isdir(os.path.join(path, ".git")) and
+            os.path.isfile(os.path.join(path, ".gitmodules")))
+
+
+def read_submodule_status(path, env=None):
+    """Check status of submodules.
+
+    :param path: Path to git directory
+    :param env: Optional waf environment
+    :return: Yields tuples with submodule relpath and status
+        (one of: 'out-of-date', 'not-checked-out', 'up-to-date')
+    :raise RuntimeError: raised when parsing of 'git submodule status' output
+        fails.
+    """
+    if not has_submodules(path):
+        # No point in running git.
+        return
+    git = find_git(env)
+    if git is None:
+        return
+    p = subprocess.Popen([git, "submodule", "status"], stdout=subprocess.PIPE,
+        cwd=path)
+    (stdout, stderr) = p.communicate(None)
+    for l in stdout.splitlines():
+        l = l.rstrip()
+        status = l[0]
+        l = l[1:]
+        parts = l.split(" ")
+        if len(parts) > 2 and status in ("-", "+"):
+            yield (parts[1], "out-of-date")
+        elif len(parts) == 2 and status == "-":
+            yield (parts[1], "not-checked-out")
+        elif len(parts) > 2 and status == " ":
+            yield (parts[1], "up-to-date")
+        else:
+            raise RuntimeError("Unable to parse submodule status: %r, %r" % (status, parts))
diff --git a/buildtools/wafsamba/samba_install.py b/buildtools/wafsamba/samba_install.py
index aa7f143..af8d2ad 100644
--- a/buildtools/wafsamba/samba_install.py
+++ b/buildtools/wafsamba/samba_install.py
@@ -59,6 +59,10 @@ def install_library(self):
 
     bld = self.bld
 
+    default_env = bld.all_envs['default']
+    if self.env['IS_EXTRA_PYTHON']:
+        bld.all_envs['default'] = bld.all_envs['extrapython']
+
     install_ldflags = install_rpath(self)
     build_ldflags   = build_rpath(bld)
 
@@ -83,7 +87,7 @@ def install_library(self):
         # install link. That stops us from overwriting the existing build
         # target, which has different ldflags
         self.done_install_library = True
-        t = self.clone('default')
+        t = self.clone(self.env)
         t.posted = False
         t.target += '.inst'
         self.env.RPATH = build_ldflags
@@ -144,6 +148,8 @@ def install_library(self):
     if dev_link:
         bld.symlink_as(os.path.join(install_path, dev_link), os.path.basename(install_name))
 
+    bld.all_envs['default'] = default_env
+
 
 @feature('cshlib')
 @after('apply_implib')
diff --git a/buildtools/wafsamba/samba_python.py b/buildtools/wafsamba/samba_python.py
index a371b43..8b20066 100644
--- a/buildtools/wafsamba/samba_python.py
+++ b/buildtools/wafsamba/samba_python.py
@@ -9,21 +9,63 @@ from Configure import conf
 @conf
 def SAMBA_CHECK_PYTHON(conf, mandatory=True, version=(2,4,2)):
     # enable tool to build python extensions
+    interpreters = []
+
+    if conf.env['EXTRA_PYTHON']:
+        conf.all_envs['extrapython'] = conf.env.copy()
+        conf.setenv('extrapython')
+        conf.env['PYTHON'] = conf.env['EXTRA_PYTHON']
+        conf.env['IS_EXTRA_PYTHON'] = 'yes'
+        conf.find_program('python', var='PYTHON', mandatory=True)
+        conf.check_tool('python')
+        try:
+            conf.check_python_version((3, 3, 0))
+        except Exception:
+            warn('extra-python needs to be Python 3.3 or later')
+            raise
+        interpreters.append(conf.env['PYTHON'])
+        conf.setenv('default')
+
     conf.find_program('python', var='PYTHON', mandatory=mandatory)
     conf.check_tool('python')
     path_python = conf.find_program('python')
     conf.env.PYTHON_SPECIFIED = (conf.env.PYTHON != path_python)
     conf.check_python_version(version)
 
+    interpreters.append(conf.env['PYTHON'])
+    conf.env.python_interpreters = interpreters
+
+
 @conf
 def SAMBA_CHECK_PYTHON_HEADERS(conf, mandatory=True):
     if conf.env["python_headers_checked"] == []:
-        conf.check_python_headers(mandatory)
+        if conf.env['EXTRA_PYTHON']:
+            conf.setenv('extrapython')
+            _check_python_headers(conf, mandatory=True)
+            conf.setenv('default')
+
+        _check_python_headers(conf, mandatory)
         conf.env["python_headers_checked"] = "yes"
+
+        if conf.env['EXTRA_PYTHON']:
+            extraversion = conf.all_envs['extrapython']['PYTHON_VERSION']
+            if extraversion == conf.env['PYTHON_VERSION']:
+                raise Utils.WafError("extrapython %s is same as main python %s" % (
+                    extraversion, conf.env['PYTHON_VERSION']))
     else:
         conf.msg("python headers", "using cache")
 
 
+def _check_python_headers(conf, mandatory):
+    conf.check_python_headers(mandatory=mandatory)
+
+    if conf.env['PYTHON_VERSION'] > '3':
+        abi_pattern = os.path.splitext(conf.env['pyext_PATTERN'])[0]
+        conf.env['PYTHON_SO_ABI_FLAG'] = abi_pattern % ''
+    else:
+        conf.env['PYTHON_SO_ABI_FLAG'] = ''
+
+
 def SAMBA_PYTHON(bld, name,
                  source='',
                  deps='',
@@ -38,6 +80,9 @@ def SAMBA_PYTHON(bld, name,
                  enabled=True):
     '''build a python extension for Samba'''
 
+    if bld.env['IS_EXTRA_PYTHON']:
+        name = 'extra-' + name
+
     # when we support static python modules we'll need to gather
     # the list from all the SAMBA_PYTHON() targets
     if init_function_sentinel is not None:
@@ -69,3 +114,31 @@ def SAMBA_PYTHON(bld, name,
                       enabled=enabled)
 
 Build.BuildContext.SAMBA_PYTHON = SAMBA_PYTHON
+
+
+def pyembed_libname(bld, name, extrapython=False):
+    return name + bld.env['PYTHON_SO_ABI_FLAG']
+
+Build.BuildContext.pyembed_libname = pyembed_libname
+
+
+def gen_python_environments(bld, extra_env_vars=()):
+    """Generate all Python environments
+
+    To be used in a for loop. Normally, the loop body will be executed once.
+
+    When --extra-python is used, the body will additionaly be executed
+    with the extra-python environment active.
+    """
+    yield
+
+    if bld.env['EXTRA_PYTHON']:
+        copied = ('GLOBAL_DEPENDENCIES', 'TARGET_TYPE') + tuple(extra_env_vars)
+        for name in copied:
+            bld.all_envs['extrapython'][name] = bld.all_envs['default'][name]
+        default_env = bld.all_envs['default']
+        bld.all_envs['default'] = bld.all_envs['extrapython']
+        yield
+        bld.all_envs['default'] = default_env
+
+Build.BuildContext.gen_python_environments = gen_python_environments
diff --git a/buildtools/wafsamba/samba_utils.py b/buildtools/wafsamba/samba_utils.py
index e8bc0f3..540fe44 100644
--- a/buildtools/wafsamba/samba_utils.py
+++ b/buildtools/wafsamba/samba_utils.py
@@ -386,6 +386,22 @@ def RUN_COMMAND(cmd,
     return -1
 
 
+def RUN_PYTHON_TESTS(testfiles, pythonpath=None):
+    env = LOAD_ENVIRONMENT()
+    if pythonpath is None:
+        pythonpath = os.path.join(Utils.g_module.blddir, 'python')
+    result = 0
+    for interp in env.python_interpreters:
+        for testfile in testfiles:
+            cmd = "PYTHONPATH=%s %s %s" % (pythonpath, interp, testfile)
+            print('Running Python test with %s: %s' % (interp, testfile))
+            ret = RUN_COMMAND(cmd)
+            if ret:
+                print('Python test failed: %s' % cmd)
+                result = ret
+    return result
+
+
 # make sure we have md5. some systems don't have it
 try:
     from hashlib import md5
diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py
index 67ff232..bb0be96 100644
--- a/buildtools/wafsamba/samba_version.py
+++ b/buildtools/wafsamba/samba_version.py
@@ -1,68 +1,16 @@
 import os
 import Utils
 import samba_utils
-import sys
-
-def bzr_version_summary(path):
-    try:
-        import bzrlib
-    except ImportError:
-        return ("BZR-UNKNOWN", {})
-
-    import bzrlib.ui
-    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
-        sys.stdin, sys.stdout, sys.stderr)
-    from bzrlib import branch, osutils, workingtree
-    from bzrlib.plugin import load_plugins
-    load_plugins()
-
-    b = branch.Branch.open(path)
-    (revno, revid) = b.last_revision_info()
-    rev = b.repository.get_revision(revid)
-
-    fields = {
-        "BZR_REVISION_ID": revid,
-        "BZR_REVNO": revno,
-        "COMMIT_DATE": osutils.format_date_with_offset_in_original_timezone(rev.timestamp,
-            rev.timezone or 0),
-        "COMMIT_TIME": int(rev.timestamp),
-        "BZR_BRANCH": rev.properties.get("branch-nick", ""),
-        }
-
-    # If possible, retrieve the git sha
-    try:
-        from bzrlib.plugins.git.object_store import get_object_store
-    except ImportError:
-        # No git plugin
-        ret = "BZR-%d" % revno
-    else:
-        store = get_object_store(b.repository)
-        store.lock_read()
-        try:
-            full_rev = store._lookup_revision_sha1(revid)
-        finally:
-            store.unlock()
-        fields["GIT_COMMIT_ABBREV"] = full_rev[:7]
-        fields["GIT_COMMIT_FULLREV"] = full_rev
-        ret = "GIT-" + fields["GIT_COMMIT_ABBREV"]
-
-    if workingtree.WorkingTree.open(path).has_changes():
-        fields["COMMIT_IS_CLEAN"] = 0
-        ret += "+"
-    else:
-        fields["COMMIT_IS_CLEAN"] = 1
-    return (ret, fields)
-
+from samba_git import find_git
 
 def git_version_summary(path, env=None):
-    # Get version from GIT
-    if not 'GIT' in env and os.path.exists("/usr/bin/git"):
-        # this is useful when doing make dist without configuring
-        env.GIT = "/usr/bin/git"
+    git = find_git(env)
 
-    if not 'GIT' in env:
+    if git is None:
         return ("GIT-UNKNOWN", {})
 
+    env.GIT = git
+
     environ = dict(os.environ)
     environ["GIT_DIR"] = '%s/.git' % path
     environ["GIT_WORK_TREE"] = path
@@ -200,8 +148,6 @@ also accepted as dictionary entries here
                 self.vcs_fields = {}
             elif os.path.exists(os.path.join(path, ".git")):
                 suffix, self.vcs_fields = git_version_summary(path, env=env)
-            elif os.path.exists(os.path.join(path, ".bzr")):
-                suffix, self.vcs_fields = bzr_version_summary(path)
             elif os.path.exists(os.path.join(path, ".distversion")):
                 suffix, self.vcs_fields = distversion_version_summary(path)
             else:
diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index d7e482c..64382da 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -143,6 +143,9 @@ def SAMBA_LIBRARY(bld, libname, source,
                   enabled=True):
     '''define a Samba library'''
 
+    if pyembed and bld.env['IS_EXTRA_PYTHON']:
+        public_headers = pc_files = None
+
     if LIB_MUST_BE_PRIVATE(bld, libname):
         private_library=True
 
@@ -217,10 +220,10 @@ def SAMBA_LIBRARY(bld, libname, source,
         if vnum is None and soname is None:
             raise Utils.WafError("public library '%s' must have a vnum" %
                     libname)
-        if pc_files is None:
+        if pc_files is None and not bld.env['IS_EXTRA_PYTHON']:
             raise Utils.WafError("public library '%s' must have pkg-config file" %
                        libname)
-        if public_headers is None:
+        if public_headers is None and not bld.env['IS_EXTRA_PYTHON']:
             raise Utils.WafError("public library '%s' must have header files" %
                        libname)
 
diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
index 694147e..d6bb688 100755
--- a/buildtools/wafsamba/wscript
+++ b/buildtools/wafsamba/wscript
@@ -195,6 +195,12 @@ def set_options(opt):
                    help='tag release in git at the same time',
                    type='string', action='store', dest='TAG_RELEASE')
 
+    opt.add_option('--extra-python', type=str,
+                    help=("build selected libraries for the specified "
+                          "additional version of Python "
+                          "(example: --extra-python=/usr/bin/python3)"),
+                    metavar="PYTHON", dest='EXTRA_PYTHON', default=None)
+
 
 @wafsamba.runonce
 def configure(conf):
@@ -266,6 +272,8 @@ def configure(conf):
     conf.env.AUTOCONF_HOST  = Options.options.AUTOCONF_HOST
     conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX
 
+    conf.env.EXTRA_PYTHON = Options.options.EXTRA_PYTHON
+
     if (conf.env.AUTOCONF_HOST and
         conf.env.AUTOCONF_BUILD and
         conf.env.AUTOCONF_BUILD != conf.env.AUTOCONF_HOST):
diff --git a/lib/talloc/pytalloc-util.pc.in b/lib/talloc/pytalloc-util.pc.in
index b7426bb..b87c94e 100644
--- a/lib/talloc/pytalloc-util.pc.in
+++ b/lib/talloc/pytalloc-util.pc.in
@@ -6,6 +6,6 @@ includedir=@includedir@
 Name: pytalloc-util
 Description: Utility functions for using talloc objects with Python
 Version: @TALLOC_VERSION@
-Libs: @LIB_RPATH@ -L${libdir} -lpytalloc-util
+Libs: @LIB_RPATH@ -L${libdir} -lpytalloc-util at PYTHON_SO_ABI_FLAG@
 Cflags: -I${includedir}
 URL: http://talloc.samba.org/
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
index ac4fe0f..3afae9c 100644
--- a/lib/talloc/pytalloc.c
+++ b/lib/talloc/pytalloc.c
@@ -21,7 +21,13 @@
 #include <talloc.h>
 #include <pytalloc.h>
 
-void inittalloc(void);
+static PyTypeObject TallocObject_Type;
+
+#if PY_MAJOR_VERSION >= 3
+#define PyStr_FromFormat PyUnicode_FromFormat
+#else
+#define PyStr_FromFormat PyString_FromFormat
+#endif
 
 /* print a talloc tree report for a talloc python object */
 static PyObject *pytalloc_report_full(PyObject *self, PyObject *args)
@@ -79,8 +85,8 @@ static PyObject *pytalloc_default_repr(PyObject *obj)
 	pytalloc_Object *talloc_obj = (pytalloc_Object *)obj;
 	PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
 
-	return PyString_FromFormat("<%s talloc object at 0x%p>", 
-				   type->tp_name, talloc_obj->ptr);
+	return PyStr_FromFormat("<%s talloc object at 0x%p>",
+				type->tp_name, talloc_obj->ptr);
 }
 
 /**
@@ -97,6 +103,35 @@ static void pytalloc_dealloc(PyObject* self)
 /**
  * Default (but only slightly more useful than the default) implementation of cmp.
  */
+#if PY_MAJOR_VERSION >= 3
+static PyObject *pytalloc_default_richcmp(PyObject *obj1, PyObject *obj2, int op)
+{
+	void *ptr1;
+	void *ptr2;
+	if (Py_TYPE(obj1) == Py_TYPE(obj2)) {
+		/* When types match, compare pointers */
+		ptr1 = pytalloc_get_ptr(obj1);
+		ptr2 = pytalloc_get_ptr(obj2);
+	} else if (PyObject_TypeCheck(obj2, &TallocObject_Type)) {
+		/* Otherwise, compare types */
+		ptr1 = Py_TYPE(obj1);
+		ptr2 = Py_TYPE(obj2);
+	} else {
+		Py_INCREF(Py_NotImplemented);
+		return Py_NotImplemented;
+	}
+	switch (op) {
+		case Py_EQ: return PyBool_FromLong(ptr1 == ptr2);
+		case Py_NE: return PyBool_FromLong(ptr1 != ptr2);
+		case Py_LT: return PyBool_FromLong(ptr1 < ptr2);
+		case Py_GT: return PyBool_FromLong(ptr1 > ptr2);
+		case Py_LE: return PyBool_FromLong(ptr1 <= ptr2);
+		case Py_GE: return PyBool_FromLong(ptr1 >= ptr2);
+	}
+	Py_INCREF(Py_NotImplemented);
+	return Py_NotImplemented;
+}
+#else
 static int pytalloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
 {
 	pytalloc_Object *obj1 = (pytalloc_Object *)_obj1,
@@ -106,6 +141,7 @@ static int pytalloc_default_cmp(PyObject *_obj1, PyObject *_obj2)
 
 	return ((char *)pytalloc_get_ptr(obj1) - (char *)pytalloc_get_ptr(obj2));
 }
+#endif
 
 static PyTypeObject TallocObject_Type = {
 	.tp_name = "talloc.Object",
@@ -114,21 +150,56 @@ static PyTypeObject TallocObject_Type = {
 	.tp_dealloc = (destructor)pytalloc_dealloc,
 	.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
 	.tp_repr = pytalloc_default_repr,
+#if PY_MAJOR_VERSION >= 3
+	.tp_richcompare = pytalloc_default_richcmp,
+#else
 	.tp_compare = pytalloc_default_cmp,
+#endif
 };
 
-void inittalloc(void)
+#define MODULE_DOC PyDoc_STR("Python wrapping of talloc-maintained objects.")
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    .m_name = "talloc",
+    .m_doc = MODULE_DOC,
+    .m_size = -1,
+    .m_methods = talloc_methods,
+};
+#endif


-- 
Samba Shared Repository


More information about the samba-cvs mailing list