[Python-modules-commits] [python-setproctitle] 09/13: Import python-setproctitle_1.1.8.orig.tar.gz

Orestis Ioannou oorestisime-guest at moszumanska.debian.org
Sun Sep 18 12:02:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

oorestisime-guest pushed a commit to branch master
in repository python-setproctitle.

commit 9fc750ac877dded76c4daf3a92726722b773f601
Author: Orestis Ioannou <orestis at oioannou.com>
Date:   Wed Sep 14 00:43:29 2016 +0200

    Import python-setproctitle_1.1.8.orig.tar.gz
---
 COPYRIGHT                        |   2 +-
 HISTORY                          |  47 ----
 HISTORY.rst                      | 108 +++++++++
 Makefile                         |  72 ++++++
 PKG-INFO                         | 150 ++++++++++--
 README => README.rst             |  56 ++++-
 setup.py                         |  33 +--
 src/c.h                          |   9 +-
 src/setproctitle.c               | 168 ++++++--------
 src/spt.h                        |  20 ++
 src/spt_config.h                 |  10 +-
 src/spt_debug.c                  |  40 ++++
 src/spt_python.h                 |  63 ++++++
 src/spt_setup.c                  | 477 +++++++++++++++++++++++++++++++++++++++
 src/spt_setup.h                  |  18 ++
 src/spt_status.c                 |  52 +++--
 src/spt_status.h                 |  10 +-
 src/{strlcpy.c => spt_strlcpy.c} |   2 +-
 tests/pyrun.c                    |  30 +++
 tests/setproctitle_test.py       | 355 +++++++++++++++++++++++++++--
 20 files changed, 1472 insertions(+), 250 deletions(-)

diff --git a/COPYRIGHT b/COPYRIGHT
index b970a5a..ed84316 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,4 +1,4 @@
-Copyright (c) 2009-2010, Daniele Varrazzo <daniele.varrazzo at gmail.com>
+Copyright (c) 2009-2012, Daniele Varrazzo <daniele.varrazzo at gmail.com>
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
diff --git a/HISTORY b/HISTORY
deleted file mode 100644
index db33587..0000000
--- a/HISTORY
+++ /dev/null
@@ -1,47 +0,0 @@
-Releases history
-----------------
-
-Version 1.0.1
-~~~~~~~~~~~~~
-
-- ``setproctitle()`` works even when Python messes up with argv, e.g. when run
-  with the -m option.
-
-
-Version 1.0
-~~~~~~~~~~~
-
-No major change since the previous version.  The module has been heavily used
-in production environment without any problem reported, so it's time to declare
-it stable.
-
-
-Version 0.4
-~~~~~~~~~~~
-
-- Module works on BSD (tested on FreeBSD 7.2).
-
-- Module works on Windows. Many thanks to `Develer`_ for providing a neat `GCC
-  package for Windows with Python integration`__ that made the Windows porting
-  painless.
-
-  .. _Develer: http://www.develer.com/
-  .. __: http://www.develer.com/oss/GccWinBinaries
-
-
-Version 0.3
-~~~~~~~~~~~
-
-- Module works on Mac OS X 10.2. Reported working on OS X 10.6 too.
-
-
-Version 0.2
-~~~~~~~~~~~
-
-- Added ``prctl()`` call on Linux >= 2.6.9 to update ``/proc/self/status``.
-
-
-Version 0.1
-~~~~~~~~~~~
-
-- Initial public release.
diff --git a/HISTORY.rst b/HISTORY.rst
new file mode 100644
index 0000000..a532b0d
--- /dev/null
+++ b/HISTORY.rst
@@ -0,0 +1,108 @@
+Releases history
+----------------
+
+Version 1.1.8
+~~~~~~~~~~~~~
+
+- Added support for Python "diehard" 2.4.
+- Fixed build on Mac OS X 10.9 Maverick (issue #27).
+
+
+Version 1.1.7
+~~~~~~~~~~~~~
+
+- Added PyPy support, courtesy of Ozan Turksever (http://www.logsign.net).
+
+
+Version 1.1.6
+~~~~~~~~~~~~~
+
+- The module can be compiled again on Windows (issue #21).
+
+
+Version 1.1.5
+~~~~~~~~~~~~~
+
+- No module bug, but a packaging issue: files ``README`` and ``HISTORY``
+  added back into the distribution.
+
+
+Version 1.1.4
+~~~~~~~~~~~~~
+
+- The module works correctly in embedded Python.
+- ``setproctitle()`` accepts a keyword argument.
+- Debug output support always compiled in: the variable ``SPT_DEBUG`` can be
+  used to emit debug log.
+
+
+Version 1.1.3
+~~~~~~~~~~~~~
+
+- Don't clobber environ if the variable ``SPT_NOENV`` is set (issue #16).
+
+
+Version 1.1.2
+~~~~~~~~~~~~~
+
+- Find the setproctitle include file on OpenBSD (issue #11).
+- Skip test with unicode if the file system encoding wouldn't make it pass
+  (issue #13).
+
+
+Version 1.1.1
+~~~~~~~~~~~~~
+
+- Fixed segfault when the module is imported under mod_wsgi (issue #9).
+
+
+Version 1.1
+~~~~~~~~~~~
+
+- The module works correctly with Python 3.
+
+
+Version 1.0.1
+~~~~~~~~~~~~~
+
+- ``setproctitle()`` works even when Python messes up with argv, e.g. when run
+  with the -m option (issue #8).
+
+
+Version 1.0
+~~~~~~~~~~~
+
+No major change since the previous version.  The module has been heavily used
+in production environment without any problem reported, so it's time to declare
+it stable.
+
+
+Version 0.4
+~~~~~~~~~~~
+
+- Module works on BSD (tested on FreeBSD 7.2).
+
+- Module works on Windows. Many thanks to `Develer`_ for providing a neat `GCC
+  package for Windows with Python integration`__ that made the Windows porting
+  painless.
+
+  .. _Develer: http://www.develer.com/
+  .. __: http://www.develer.com/oss/GccWinBinaries
+
+
+Version 0.3
+~~~~~~~~~~~
+
+- Module works on Mac OS X 10.2. Reported working on OS X 10.6 too.
+
+
+Version 0.2
+~~~~~~~~~~~
+
+- Added ``prctl()`` call on Linux >= 2.6.9 to update ``/proc/self/status``.
+
+
+Version 0.1
+~~~~~~~~~~~
+
+- Initial public release.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..755de55
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,72 @@
+# Oh, makefile, help me with the python3 craze :D
+#
+# Copyright (c) 2010-2012 Daniele Varrazzo <daniele.varrazzo at gmail.com>
+
+MKDIR = mkdir -p
+RM = rm -f
+
+# Customize these to select the Python to build/test
+PYTHON ?= python
+PYCONFIG ?= python-config
+PY2TO3 ?= 2to3
+
+# PYVER value is 2 or 3
+PYVER := $(shell $(PYTHON) -c "import sys; print(sys.version_info[0])")
+ROOT_PATH := $(shell pwd)
+
+PYINC := $(shell $(PYCONFIG) --includes)
+PYLIB := $(shell $(PYCONFIG) --ldflags) -L$(shell $(PYCONFIG) --prefix)/lib
+
+BUILD_DIR = build/lib.$(PYVER)
+
+.PHONY: build check py3 clean
+
+ifeq (2,$(PYVER))
+
+build:
+	$(PYTHON) setup.py build --build-lib $(BUILD_DIR)
+
+check: build tests/pyrun2
+	PYTHONPATH=`pwd`/$(BUILD_DIR):$$PYTHONPATH \
+	ROOT_PATH=$(ROOT_PATH) \
+	$(PYTHON) `which nosetests` -v -s -w tests
+
+tests/pyrun2: tests/pyrun.c
+	$(CC) $(PYINC) -o $@ $< $(PYLIB)
+
+else
+
+build: py3
+	$(PYTHON) py3/setup.py build --build-lib $(BUILD_DIR)
+
+check: build tests/pyrun3
+	PYTHONPATH=$(BUILD_DIR):$$PYTHONPATH \
+	ROOT_PATH=$(ROOT_PATH) \
+	$(PYTHON) py3/tests/setproctitle_test.py -v
+
+py3: MANIFEST
+	$(MKDIR) py3
+	$(MKDIR) py3/src
+	$(MKDIR) py3/tests
+	for f in `grep -v "#" MANIFEST`; do cp -v $$f py3/$$f; done
+	# setup.py should be executable with python3 as distribute
+	# currenlty doesn't seem to try to convert it
+	$(PY2TO3) -w --no-diffs py3/tests
+
+tests/pyrun3: tests/pyrun.c
+	$(CC) $(PYINC) -o $@ $< $(PYLIB)
+
+endif
+
+sdist: MANIFEST
+	$(PYTHON) setup.py sdist --formats=gztar,zip
+
+MANIFEST:
+	# Must run twice because the manifest contains the manifest itself.
+	$(PYTHON) setup.py sdist --manifest-only
+	$(PYTHON) setup.py sdist --manifest-only
+
+clean:
+	$(RM) -r MANIFEST py3 build dist tests/pyrun2 tests/pyrun3
+
+
diff --git a/PKG-INFO b/PKG-INFO
index 75bc771..157a03e 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,7 +1,7 @@
-Metadata-Version: 1.0
+Metadata-Version: 1.1
 Name: setproctitle
-Version: 1.0.1
-Summary: Allow customization of the process title.
+Version: 1.1.8
+Summary: A library to allow customization of the process title.
 Home-page: http://code.google.com/p/py-setproctitle/
 Author: Daniele Varrazzo
 Author-email: daniele.varrazzo at gmail.com
@@ -24,9 +24,15 @@ Description: A ``setproctitle`` implementation for Python
         a good `multi-platform implementation`__:  this module is a Python wrapper
         around PostgreSQL code.
         
+        - `Homepage <http://code.google.com/p/py-setproctitle/>`__
+        - `Download <http://pypi.python.org/pypi/setproctitle/>`__
+        - `Source repository <https://github.com/dvarrazzo/py-setproctitle>`__
+        - `Bug tracker <http://code.google.com/p/py-setproctitle/issues/list>`__
+        
+        
         .. _PostgreSQL: http://www.postgresql.org
         .. _OpenSSH Server: http://www.openssh.com/
-        .. __: http://doxygen.postgresql.org/ps__status_8c-source.html
+        .. __: http://doxygen.postgresql.org/ps__status_8c_source.html
         
         
         Installation
@@ -35,28 +41,64 @@ Description: A ``setproctitle`` implementation for Python
         You can use ``easy_install`` to install the module: to perform a system-wide
         installation use::
         
-        sudo easy_install setproctitle
+            sudo easy_install setproctitle
         
         If you are an unprivileged user or you want to limit installation to a local
         environment, you can use the command::
         
-        easy_install -d /target/path setproctitle
+            easy_install -d /target/path setproctitle
         
-        Notice that ``easy_install`` requires ``/target/path`` to be in your
+        Note that ``easy_install`` requires ``/target/path`` to be in your
         ``PYTHONPATH``.
         
         
-        Module content
-        --------------
+        Python 3 support
+        ~~~~~~~~~~~~~~~~
         
-        The module exports the following functions:
+        As of version 1.1 the module works with Python 3.  In order to install the
+        module, you can use the `distribute`_ replacemente for ``easy_install``.
         
-        ``setproctitle(title)``
-        Set *title* as the title for the current process.
+        In order to build and test the module under Python 3, the ``Makefile``
+        contains some helper targets.
+        
+        .. _distribute: http://pypi.python.org/pypi/distribute
         
         
+        Usage
+        -----
+        
+        The ``setproctitle`` module exports the following functions:
+        
+        ``setproctitle(title)``
+            Set *title* as the title for the current process.
+        
         ``getproctitle()``
-        Return the current process title.
+            Return the current process title.
+        
+        
+        Environment variables
+        ~~~~~~~~~~~~~~~~~~~~~
+        
+        A few environment variables can be used to customize the module behavior:
+        
+        ``SPT_NOENV``
+            Avoid clobbering ``/proc/PID/environ``.
+        
+            On many platforms, setting the process title will clobber the
+            ``environ`` memory area. ``os.environ`` will work as expected from within
+            the Python process, but the content of the file ``/proc/PID/environ`` will
+            be overwritten.  If you require this file not to be broken you can set the
+            ``SPT_NOENV`` environment variable to any non-empty value: in this case
+            the maximum length for the title will be limited to the length of the
+            command line.
+        
+        ``SPT_DEBUG``
+            Print debug information on ``stderr``.
+        
+            If the module doesn't work as expected you can set this variable to a
+            non-empty value to generate information useful for debugging.  Note that
+            the most useful information is printed when the module is imported, not
+            when the functions are called.
         
         
         Module status
@@ -70,7 +112,7 @@ Description: A ``setproctitle`` implementation for Python
         - MacOS X
         - Windows
         
-        Notice that on Windows there is no way to change the process string:
+        Note that on Windows there is no way to change the process string:
         what the module does is to create a *Named Object* whose value can be read
         using a tool such as `Process Explorer`_ (contribution of a more useful tool
         to be used together with ``setproctitle`` would be well accepted).
@@ -84,27 +126,88 @@ Description: A ``setproctitle`` implementation for Python
         Other known implementations and discussions
         -------------------------------------------
         
-        - `procname`_: a module exposing the same functionality, but less portable
-        and not well packaged.
+        - `procname`_: a module exposing the same functionality, but less portable 
+          and not well packaged.
         - `Issue 5672`_: where the introduction of such functionality into the stdlib
-        is being discussed.
+          is being discussed.
         
         .. _procname: http://code.google.com/p/procname/
         .. _Issue 5672: http://bugs.python.org/issue5672
         
         
         ..
-        vim: set filetype=rst:
+            vim: set filetype=rst:
         
         
         Releases history
         ----------------
         
+        Version 1.1.8
+        ~~~~~~~~~~~~~
+        
+        - Added support for Python "diehard" 2.4.
+        - Fixed build on Mac OS X 10.9 Maverick (issue #27).
+        
+        
+        Version 1.1.7
+        ~~~~~~~~~~~~~
+        
+        - Added PyPy support, courtesy of Ozan Turksever (http://www.logsign.net).
+        
+        
+        Version 1.1.6
+        ~~~~~~~~~~~~~
+        
+        - The module can be compiled again on Windows (issue #21).
+        
+        
+        Version 1.1.5
+        ~~~~~~~~~~~~~
+        
+        - No module bug, but a packaging issue: files ``README`` and ``HISTORY``
+          added back into the distribution.
+        
+        
+        Version 1.1.4
+        ~~~~~~~~~~~~~
+        
+        - The module works correctly in embedded Python.
+        - ``setproctitle()`` accepts a keyword argument.
+        - Debug output support always compiled in: the variable ``SPT_DEBUG`` can be
+          used to emit debug log.
+        
+        
+        Version 1.1.3
+        ~~~~~~~~~~~~~
+        
+        - Don't clobber environ if the variable ``SPT_NOENV`` is set (issue #16).
+        
+        
+        Version 1.1.2
+        ~~~~~~~~~~~~~
+        
+        - Find the setproctitle include file on OpenBSD (issue #11).
+        - Skip test with unicode if the file system encoding wouldn't make it pass
+          (issue #13).
+        
+        
+        Version 1.1.1
+        ~~~~~~~~~~~~~
+        
+        - Fixed segfault when the module is imported under mod_wsgi (issue #9).
+        
+        
+        Version 1.1
+        ~~~~~~~~~~~
+        
+        - The module works correctly with Python 3.
+        
+        
         Version 1.0.1
         ~~~~~~~~~~~~~
         
         - ``setproctitle()`` works even when Python messes up with argv, e.g. when run
-        with the -m option.
+          with the -m option (issue #8).
         
         
         Version 1.0
@@ -121,11 +224,11 @@ Description: A ``setproctitle`` implementation for Python
         - Module works on BSD (tested on FreeBSD 7.2).
         
         - Module works on Windows. Many thanks to `Develer`_ for providing a neat `GCC
-        package for Windows with Python integration`__ that made the Windows porting
-        painless.
+          package for Windows with Python integration`__ that made the Windows porting
+          painless.
         
-        .. _Develer: http://www.develer.com/
-        .. __: http://www.develer.com/oss/GccWinBinaries
+          .. _Develer: http://www.develer.com/
+          .. __: http://www.develer.com/oss/GccWinBinaries
         
         
         Version 0.3
@@ -154,6 +257,7 @@ Classifier: Intended Audience :: Developers
 Classifier: License :: OSI Approved :: BSD License
 Classifier: Programming Language :: C
 Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 3
 Classifier: Operating System :: POSIX :: Linux
 Classifier: Operating System :: POSIX :: BSD
 Classifier: Operating System :: MacOS :: MacOS X
diff --git a/README b/README.rst
similarity index 55%
rename from README
rename to README.rst
index 43ef1da..4bd78a7 100644
--- a/README
+++ b/README.rst
@@ -15,9 +15,15 @@ The procedure is hardly portable across different systems.  PostgreSQL provides
 a good `multi-platform implementation`__:  this module is a Python wrapper
 around PostgreSQL code.
 
+- `Homepage <http://code.google.com/p/py-setproctitle/>`__
+- `Download <http://pypi.python.org/pypi/setproctitle/>`__
+- `Source repository <https://github.com/dvarrazzo/py-setproctitle>`__
+- `Bug tracker <http://code.google.com/p/py-setproctitle/issues/list>`__
+
+
 .. _PostgreSQL: http://www.postgresql.org
 .. _OpenSSH Server: http://www.openssh.com/
-.. __: http://doxygen.postgresql.org/ps__status_8c-source.html
+.. __: http://doxygen.postgresql.org/ps__status_8c_source.html
 
 
 Installation
@@ -33,23 +39,59 @@ environment, you can use the command::
 
     easy_install -d /target/path setproctitle
 
-Notice that ``easy_install`` requires ``/target/path`` to be in your 
+Note that ``easy_install`` requires ``/target/path`` to be in your
 ``PYTHONPATH``.
 
 
-Module content
---------------
+Python 3 support
+~~~~~~~~~~~~~~~~
+
+As of version 1.1 the module works with Python 3.  In order to install the
+module, you can use the `distribute`_ replacemente for ``easy_install``.
+
+In order to build and test the module under Python 3, the ``Makefile``
+contains some helper targets.
 
-The module exports the following functions:
+.. _distribute: http://pypi.python.org/pypi/distribute
+
+
+Usage
+-----
+
+The ``setproctitle`` module exports the following functions:
 
 ``setproctitle(title)``
     Set *title* as the title for the current process.
 
-
 ``getproctitle()``
     Return the current process title.
 
 
+Environment variables
+~~~~~~~~~~~~~~~~~~~~~
+
+A few environment variables can be used to customize the module behavior:
+
+``SPT_NOENV``
+    Avoid clobbering ``/proc/PID/environ``.
+
+    On many platforms, setting the process title will clobber the
+    ``environ`` memory area. ``os.environ`` will work as expected from within
+    the Python process, but the content of the file ``/proc/PID/environ`` will
+    be overwritten.  If you require this file not to be broken you can set the
+    ``SPT_NOENV`` environment variable to any non-empty value: in this case
+    the maximum length for the title will be limited to the length of the
+    command line.
+
+``SPT_DEBUG``
+    Print debug information on ``stderr``.
+
+    If the module doesn't work as expected you can set this variable to a
+    non-empty value to generate information useful for debugging.  Note that
+    the most useful information is printed when the module is imported, not
+    when the functions are called.
+
+
 Module status
 -------------
 
@@ -61,7 +103,7 @@ platforms:
 - MacOS X
 - Windows
 
-Notice that on Windows there is no way to change the process string:
+Note that on Windows there is no way to change the process string:
 what the module does is to create a *Named Object* whose value can be read
 using a tool such as `Process Explorer`_ (contribution of a more useful tool
 to be used together with ``setproctitle`` would be well accepted).
diff --git a/setup.py b/setup.py
index da53d01..ebf4e7e 100644
--- a/setup.py
+++ b/setup.py
@@ -2,10 +2,10 @@
 """
 setproctitle setup script.
 
-Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo at gmail.com>
+Copyright (c) 2009-2013 Daniele Varrazzo <daniele.varrazzo at gmail.com>
 """
 
-VERSION = '1.0.1'
+VERSION = '1.1.8'
 
 import os
 import re
@@ -16,11 +16,11 @@ define_macros={}
 
 define_macros['SPT_VERSION'] = VERSION
 
-if sys.platform == 'linux2':
+if sys.platform.startswith('linux'):
     try:
-        linux_version = map(int, 
+        linux_version = list(map(int,
             re.search("[.0-9]+", os.popen("uname -r").read())
-                .group().split(".")[:3])
+                .group().split(".")[:3]))
     except:
         pass
     else:
@@ -35,7 +35,7 @@ elif 'bsd' in sys.platform: # OMG, how many of them are?
     # Old BSD versions don't have setproctitle
     # TODO: not tested on an "old BSD"
     if 0 == os.spawnlp(os.P_WAIT, 'grep',
-            'grep', '-q', 'setproctitle', '/usr/include/unistd.h'):
+            'grep', '-q', 'setproctitle', '/usr/include/unistd.h', '/usr/include/stdlib.h'):
         define_macros['HAVE_SETPROCTITLE'] = 1
     else:
         define_macros['HAVE_PS_STRING'] = 1
@@ -46,11 +46,13 @@ elif 'bsd' in sys.platform: # OMG, how many of them are?
 # But I have none handy to test with.
 
 mod_spt = Extension('setproctitle',
-    define_macros=define_macros.items(),
+    define_macros=list(define_macros.items()),
     sources = [
         'src/setproctitle.c',
+        'src/spt_debug.c',
+        'src/spt_setup.c',
         'src/spt_status.c',
-        'src/strlcpy.c', # TODO: not needed on some platform
+        'src/spt_strlcpy.c',
         ])
 
 # patch distutils if it can't cope with the "classifiers" or
@@ -62,17 +64,17 @@ if sys.version < '2.2.3':
 
 # Try to include the long description in the setup
 kwargs = {}
-try: 
+try:
     kwargs['long_description'] = (
-        open('README').read()
+        open('README.rst').read()
         + '\n'
-        +open('HISTORY').read())
-except: 
+        +open('HISTORY.rst').read())
+except:
     pass
 
 setup(
     name = 'setproctitle',
-    description = 'Allow customization of the process title.',
+    description = 'A library to allow customization of the process title.',
     version = VERSION,
     author = 'Daniele Varrazzo',
     author_email = 'daniele.varrazzo at gmail.com',
@@ -80,17 +82,18 @@ setup(
     download_url = 'http://pypi.python.org/pypi/setproctitle/',
     license = 'BSD',
     platforms = ['GNU/Linux', 'BSD', 'MacOS X', 'Windows'],
-    classifiers = filter(None, map(str.strip, """
+    classifiers = [ r for r in map(str.strip, """
         Development Status :: 5 - Production/Stable
         Intended Audience :: Developers
         License :: OSI Approved :: BSD License
         Programming Language :: C
         Programming Language :: Python
+        Programming Language :: Python :: 3
         Operating System :: POSIX :: Linux
         Operating System :: POSIX :: BSD
         Operating System :: MacOS :: MacOS X
         Operating System :: Microsoft :: Windows
         Topic :: Software Development
-        """.splitlines())),
+        """.splitlines()) if r],
     ext_modules = [mod_spt],
     **kwargs)
diff --git a/src/c.h b/src/c.h
index 18f0639..b2addbc 100644
--- a/src/c.h
+++ b/src/c.h
@@ -3,13 +3,15 @@
  * c.h
  *    A few fundamental C definitions.
  *
- * Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo at gmail.com>
+ * Copyright (c) 2009-2012 Daniele Varrazzo <daniele.varrazzo at gmail.com>
  *-------------------------------------------------------------------------
  */
 
 #ifndef C_H
 #define C_H
 
+#include "spt_config.h"
+
 #ifndef __cplusplus
 
 #ifndef bool
@@ -27,9 +29,8 @@ typedef char bool;
 
 #include <stddef.h>
 
-#if !HAVE_DECL_STRLCPY
-extern size_t strlcpy(char *dst, const char *src, size_t siz);
-#endif
+/* Let's use our version of strlcpy to avoid portability problems */
+size_t spt_strlcpy(char *dst, const char *src, size_t siz);
 
 #ifdef WIN32
 #include <Windows.h>
diff --git a/src/setproctitle.c b/src/setproctitle.c
index a03f7b1..0ae6436 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -3,25 +3,22 @@
  * setproctitle.c
  *    Python extension module to update and read the process title.
  *
- * Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo at gmail.com>
+ * Copyright (c) 2009-2012 Daniele Varrazzo <daniele.varrazzo at gmail.com>
  *
  * The module allows Python code to access the functions get_ps_display()
- * and set_ps_display().  The process title initialization (functions
- * save_ps_display_args() and init_ps_display()) are called at module
- * initialization.
+ * and set_ps_display().
+ *
  *-------------------------------------------------------------------------
  */
 
-#include "Python.h"
+#include "spt.h"
+#include "spt_setup.h"
 #include "spt_status.h"
 
 #ifndef SPT_VERSION
 #define SPT_VERSION unknown
 #endif
 
-/* defined in Modules/main.c but not publically declared */
-void Py_GetArgcArgv(int *argc, char ***argv);
-
 /* macro trick to stringify a macro expansion */
 #define xstr(s) str(s)
 #define str(s) #s
@@ -30,16 +27,18 @@ void Py_GetArgcArgv(int *argc, char ***argv);
 
 static PyObject *spt_version;
 
+
 static char spt_setproctitle__doc__[] =
-"Change the process title."
+"setproctitle(title) -- Change the process title."
 ;
 
 static PyObject *
-spt_setproctitle(PyObject *self /* Not used */, PyObject *args)
+spt_setproctitle(PyObject *self, PyObject *args, PyObject *kwargs)
 {
-    const char *title;
+    const char *title = NULL;
+    static char *kwlist[] = {"title", NULL};
 
-    if (!PyArg_ParseTuple(args, "s", &title))
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &title))
         return NULL;
 
     set_ps_display(title, true);
@@ -48,87 +47,37 @@ spt_setproctitle(PyObject *self /* Not used */, PyObject *args)
     return Py_None;
 }
 
+
 static char spt_getproctitle__doc__[] =
-"Get the current process title."
+"getproctitle() -- Get the current process title."
 ;
 
 static PyObject *
-spt_getproctitle(PyObject *self /* Not used */, PyObject *args)
+spt_getproctitle(PyObject *self, PyObject *args)
 {
-
-    if (!PyArg_ParseTuple(args, ""))
-        return NULL;
-
-    int tlen;
+    size_t tlen;
     const char *title;
     title = get_ps_display(&tlen);
 
-    return Py_BuildValue("s#", title, tlen);
+    return Py_BuildValue("s#", title, (int)tlen);
 }
 
+
 /* List of methods defined in the module */
 
 static struct PyMethodDef spt_methods[] = {
-    {"setproctitle",    (PyCFunction)spt_setproctitle,  METH_VARARGS,   spt_setproctitle__doc__},
-    {"getproctitle",    (PyCFunction)spt_getproctitle,  METH_VARARGS,   spt_getproctitle__doc__},
-
-    {NULL,   (PyCFunction)NULL, 0, NULL}        /* sentinel */
-};
-
-
-/* return a concatenated version of a strings vector
- *
- * Return newly allocated heap space: clean it up with free()
- */
-static char *
-join_argv(int argc, char **argv)
-{
-    /* Calculate the final string length */
-    int i;
-    size_t len = 0;
-    for (i = 0; i < argc; i++) {
-        len += strlen(argv[i]) + 1;
-    }
-
-    char *buf = (char *)malloc(len);
-
-    /* Copy the strings in the buffer joining with spaces */
-    char *dest = buf;
-    char *src;
-    for (i = 0; i < argc; i++) {
-        src = argv[i];
-        while (*src) {
-            *dest++ = *src++;
-        }
-        *dest++ = ' ';
-    }
-    *--dest = '\x00';
-
-    return buf;
-}
+    {"setproctitle",
+        (PyCFunction)spt_setproctitle,
+        METH_VARARGS|METH_KEYWORDS,
+        spt_setproctitle__doc__},
 
+    {"getproctitle",
+        (PyCFunction)spt_getproctitle,
+        METH_NOARGS,
+        spt_getproctitle__doc__},
 
-/* Return a copy of argv referring to the original arg area.
- *
- * python -m messes up with arg (issue #8): ensure to have a vector to the
- * original args or save_ps_display_args() will stop processing too soon.
- *
- * Return a buffer allocated with malloc: should be cleaned up with free()
- * (it is never released though).
- */
-static char **
-fix_argv(int argc, char **argv)
-{
-    char **buf = (char **)malloc(argc * sizeof(char *));
-    int i;
-    char *ptr = argv[0];
-    for (i = 0; i < argc; ++i) {
-        buf[i] = ptr;
-        ptr += strlen(ptr) + 1;
-    }
-
-    return buf;
-}
+    {NULL, (PyCFunction)NULL, 0, NULL}        /* sentinel */
+};
 
 
 /* Initialization function for the module (*must* be called initsetproctitle) */
@@ -137,43 +86,60 @@ static char setproctitle_module_documentation[] =
 "Allow customization of the process title."
 ;
 
-void
-initsetproctitle(void)
+#ifdef IS_PY3K
+
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "setproctitle",
+    setproctitle_module_documentation,
+    -1,
+    spt_methods,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+#endif
+
+PyMODINIT_FUNC
+INIT_MODULE(setproctitle)(void)
 {
     PyObject *m, *d;
 
+    spt_debug("module init");
+
     /* Create the module and add the functions */
+#ifdef IS_PY3K
+    m = PyModule_Create(&moduledef);
+#else
     m = Py_InitModule3("setproctitle", spt_methods,
         setproctitle_module_documentation);
+#endif
+    if (m == NULL) { goto exit; }
 
     /* Add version string to the module*/
     d = PyModule_GetDict(m);
-    spt_version = PyString_FromString(xstr(SPT_VERSION));
+    spt_version = Py_BuildValue("s", xstr(SPT_VERSION));
     PyDict_SetItemString(d, "__version__", spt_version);
 
     /* Initialize the process title */
-#ifndef WIN32
-    int argc;
-    char **argv;
-    Py_GetArgcArgv(&argc, &argv);
-    argv = fix_argv(argc, argv);
-    save_ps_display_args(argc, argv);
-
-    /* Set up the first title to fully initialize the code */
-    char *init_title = join_argv(argc, argv);
-    init_ps_display(init_title);
-    free(init_title);
+    if (0 > spt_setup()) {
+        spt_debug("failed to initialize module setproctitle");
+
+        /* Check for errors */
+        if (PyErr_Occurred()) {
+            spt_debug("an exception is set: import will fail");
+        }
+    }
+
+exit:
+
+#ifdef IS_PY3K
+    return m;
 #else
-    /* On Windows save_ps_display_args is a no-op
-     * This is a good news, because Py_GetArgcArgv seems not usable.
-     */
-    LPTSTR init_title = GetCommandLine();
-    init_ps_display(init_title);
+    return;
 #endif
 
-
-    /* Check for errors */
-    if (PyErr_Occurred())
-        Py_FatalError("can't initialize module setproctitle");
 }
 
diff --git a/src/spt.h b/src/spt.h
new file mode 100644
index 0000000..a7ebd62
--- /dev/null
+++ b/src/spt.h
@@ -0,0 +1,20 @@
... 1285 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-setproctitle.git



More information about the Python-modules-commits mailing list