[Python-modules-commits] [billiard] 02/06: New upstream version 3.5.0.2

Brian May bam at debian.org
Wed Jul 12 22:12:37 UTC 2017


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

bam pushed a commit to branch debian/master
in repository billiard.

commit fec33c209925295dd126a1d65efb32b7ece814b8
Author: Brian May <bam at debian.org>
Date:   Thu Jul 13 07:58:11 2017 +1000

    New upstream version 3.5.0.2
---
 CHANGES.txt                                        |   38 +-
 Doc/library/multiprocessing.rst                    |    6 +-
 INSTALL.txt                                        |    6 +-
 MANIFEST.in                                        |    6 +
 Makefile                                           |  121 ++-
 Modules/_billiard/connection.h                     |  710 -------------
 Modules/_billiard/multiprocessing.c                |  124 ++-
 Modules/_billiard/multiprocessing.h                |   11 +-
 Modules/_billiard/pipe_connection.c                |  149 ---
 Modules/_billiard/semaphore.c                      |   34 +-
 Modules/_billiard/socket_connection.c              |  225 -----
 Modules/_billiard/win32_functions.c                |  725 +++++++++++++-
 PKG-INFO                                           |   78 +-
 README.rst                                         |   31 +-
 billiard.egg-info/PKG-INFO                         |   78 +-
 billiard.egg-info/SOURCES.txt                      |   39 +-
 billiard.egg-info/top_level.txt                    |    1 -
 billiard/__init__.py                               |  292 +-----
 billiard/_ext.py                                   |    6 -
 billiard/_win.py                                   |   20 +-
 billiard/common.py                                 |   69 +-
 billiard/compat.py                                 |  211 +++-
 billiard/connection.py                             | 1038 +++++++++++++++++++-
 billiard/context.py                                |  422 ++++++++
 billiard/dummy/__init__.py                         |    4 +-
 billiard/einfo.py                                  |    2 +-
 billiard/exceptions.py                             |    8 +-
 billiard/five.py                                   |    4 -
 billiard/forking.py                                |  580 -----------
 billiard/forkserver.py                             |  266 +++++
 billiard/heap.py                                   |  117 ++-
 billiard/managers.py                               |  265 ++---
 billiard/pool.py                                   |  230 +++--
 billiard/popen_fork.py                             |   91 ++
 billiard/popen_forkserver.py                       |   70 ++
 billiard/popen_spawn_posix.py                      |   76 ++
 billiard/popen_spawn_win32.py                      |  119 +++
 billiard/process.py                                |  143 +--
 billiard/py2/connection.py                         |  498 ----------
 billiard/py2/reduction.py                          |  248 -----
 billiard/py3/__init__.py                           |    0
 billiard/py3/connection.py                         |  965 ------------------
 billiard/py3/reduction.py                          |  249 -----
 billiard/queues.py                                 |  178 ++--
 billiard/reduction.py                              |  292 +++++-
 billiard/resource_sharer.py                        |  163 +++
 billiard/semaphore_tracker.py                      |  147 +++
 billiard/sharedctypes.py                           |   81 +-
 billiard/spawn.py                                  |  384 ++++++++
 billiard/synchronize.py                            |  283 +++---
 billiard/tests/compat.py                           |   85 --
 billiard/tests/test_package.py                     |   12 -
 billiard/tests/utils.py                            |  145 ---
 billiard/util.py                                   |   36 +-
 requirements/pkgutils.txt                          |    5 +
 requirements/test-ci.txt                           |    6 +-
 requirements/test.txt                              |    6 +-
 requirements/test3.txt                             |    1 -
 setup.cfg                                          |   12 +-
 setup.py                                           |   79 +-
 {billiard/py2 => t}/__init__.py                    |    0
 {funtests => t/integration}/__init__.py            |    0
 {funtests => t/integration}/setup.py               |    0
 {funtests => t/integration}/tests/__init__.py      |    0
 .../integration}/tests/test_multiprocessing.py     |    0
 {billiard/tests => t/unit}/__init__.py             |    0
 {billiard/tests => t/unit}/test_common.py          |   37 +-
 t/unit/test_package.py                             |    8 +
 t/unit/test_win32.py                               |   70 ++
 69 files changed, 5345 insertions(+), 5060 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index e954647..9e6c09e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,24 +1,32 @@
-3.3.0.23 - 2016-03-03
----------------------
+3.5.0.2 - 2016-10-03
+--------------------
 
-- ExceptionInfo: Adds tb_lasti and other missing traceback fields
-  (Issue #180).
+- max_memory_per_child was measured in kilobytes on Linux, but bytes on
+  *BSD/MacOS, it's now always kilobytes.
 
-- monotonic: Now makes sure ctypes is available.
+- Windows: Adds support for max_memory_per_child, but requires the
+  ``psutil`` package to be installed.
 
-- PipeConnection: Make sure the pipe is not closed multiple times.
+- Fixed bug in ForkingPickler.loadbuf, where it tried to pass
+  a BytesIO instance directly to ``pickle.loads`` on Python 2.7.
 
-3.3.0.22 - 2015-12-08
----------------------
+3.5.0.1 - 2016-09-07
+--------------------
 
-- Wheel packages for Windows now available.
+- Connection: Properly handle EINTR (Issue #191).
 
-3.3.0.21 - 2015-10-26
----------------------
+- Fixed bug with missing CreateProcess for Windows on Python 2.7.
+
+- Adds Process._counter for compatibility with Python <3.5.
+
+3.5.0.0 - 2016-07-28
+--------------------
+
+- No longer supports Python 2.6
 
-- Pool: Fixed semaphore error on Python3.
+    You need Python 2.7 or later to use this version of billiard.
 
-- Fixed libSystem error on OS X El Capitan.
+- Merged changes from CPython 3.5
 
 3.3.0.20 - 2015-04-17
 ---------------------
@@ -177,7 +185,7 @@
     Fix contributed by Tin Tvrtkovic.
 
 - Now uses ``ctypes.find_library`` instead of hardcoded path to find
-  the OS X CoreServices framework.
+  the macOS CoreServices framework.
 
     Fix contributed by Moritz Kassner.
 
@@ -250,7 +258,7 @@
 - Includes many changes from multiprocessing in 3.4.
 
 - Now uses ``time.monotonic`` when available, also including
-  fallback implementations for Linux and OS X.
+  fallback implementations for Linux and macOS.
 
 - No longer cleans up after receiving SIGILL, SIGSEGV or SIGFPE
 
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index 830340a..5745d62 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -560,7 +560,7 @@ For an example of the usage of queues for interprocess communication see
       multithreading/multiprocessing semantics, this number is not reliable.
 
       Note that this may raise :exc:`NotImplementedError` on Unix platforms like
-      Mac OS X where ``sem_getvalue()`` is not implemented.
+      macOS where ``sem_getvalue()`` is not implemented.
 
    .. method:: empty()
 
@@ -887,7 +887,7 @@ object -- see :ref:`multiprocessing-managers`.
 
    A bounded semaphore object: a clone of :class:`threading.BoundedSemaphore`.
 
-   (On Mac OS X, this is indistinguishable from :class:`Semaphore` because
+   (On macOS, this is indistinguishable from :class:`Semaphore` because
    ``sem_getvalue()`` is not implemented on that platform).
 
 .. class:: Condition([lock])
@@ -924,7 +924,7 @@ object -- see :ref:`multiprocessing-managers`.
 
 .. note::
 
-   On Mac OS X, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with
+   On macOS, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with
    a timeout will emulate that function's behavior using a sleeping loop.
 
 .. note::
diff --git a/INSTALL.txt b/INSTALL.txt
index 18d44e2..b05457b 100644
--- a/INSTALL.txt
+++ b/INSTALL.txt
@@ -17,7 +17,7 @@ Windows binary builds for Python 2.4 and Python 2.5 are available at
 
     http://pypi.python.org/pypi/multiprocessing
 
-Python 2.6 and newer versions already come with multiprocessing. Although 
+Python 2.6 and newer versions already come with multiprocessing. Although
 the stand alone variant of the multiprocessing package is kept compatible
 with 2.6, you mustn't install it with Python 2.6.
 
@@ -27,7 +27,7 @@ distribution can be installed the usual way::
    python setup.py install
 
 It should not be necessary to do any editing of `setup.py` if you are
-using Windows, Mac OS X or Linux.  On other unices it may be necessary
+using Windows, macOS or Linux.  On other unices it may be necessary
 to modify the values of the `macros` dictionary or `libraries` list.
 The section to modify reads ::
 
@@ -81,7 +81,7 @@ Building docs
 -------------
 
 To build the standalone documentation you need Sphinx 0.5 and setuptools
-0.6c9 or newer. Both are available at http://pypi.python.org/. With 
+0.6c9 or newer. Both are available at http://pypi.python.org/. With
 setuptools installed, do ::
 
     sudo easy_install-2.5 "Sphinx>=0.5"
diff --git a/MANIFEST.in b/MANIFEST.in
index 7b61fce..0c7f02d 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -8,3 +8,9 @@ recursive-include Doc  *.rst *.py
 recursive-include funtests *.py
 recursive-include requirements *.txt
 recursive-include billiard *.py
+recursive-include t *.py
+
+recursive-exclude docs/_build *
+recursive-exclude * __pycache__
+recursive-exclude * *.py[co]
+recursive-exclude * .*.sw*
diff --git a/Makefile b/Makefile
index 9f8b7d2..d1964c6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,38 +1,129 @@
+PROJ=billiard
 PYTHON=python
+GIT=git
+TOX=tox
+NOSETESTS=nosetests
+ICONV=iconv
+FLAKE8=flake8
+FLAKEPLUS=flakeplus
+SPHINX2RST=sphinx2rst
+
+SPHINX_DIR=docs/
+SPHINX_BUILDDIR="${SPHINX_DIR}/_build"
+README=README.rst
+README_SRC="docs/templates/readme.txt"
+CONTRIBUTING=CONTRIBUTING.rst
+CONTRIBUTING_SRC="docs/contributing.rst"
+SPHINX_HTMLDIR="${SPHINX_BUILDDIR}/html"
+DOCUMENTATION=Documentation
+FLAKEPLUSTARGET=2.7
+
+all: help
+
+help:
+	@echo "docs                 - Build documentation."
+	@echo "test-all             - Run tests for all supported python versions."
+	@echo "distcheck ---------- - Check distribution for problems."
+	@echo "  test               - Run unittests using current python."
+	@echo "  lint ------------  - Check codebase for problems."
+	@echo "    apicheck         - Check API reference coverage."
+	@echo "    configcheck      - Check configuration reference coverage."
+	@echo "    readmecheck      - Check README.rst encoding."
+	@echo "    contribcheck     - Check CONTRIBUTING.rst encoding"
+	@echo "    flakes --------  - Check code for syntax and style errors."
+	@echo "      flakecheck     - Run flake8 on the source code."
+	@echo "      flakepluscheck - Run flakeplus on the source code."
+	@echo "readme               - Regenerate README.rst file."
+	@echo "contrib              - Regenerate CONTRIBUTING.rst file"
+	@echo "clean-dist --------- - Clean all distribution build artifacts."
+	@echo "  clean-git-force    - Remove all uncomitted files."
+	@echo "  clean ------------ - Non-destructive clean"
+	@echo "    clean-pyc        - Remove .pyc/__pycache__ files"
+	@echo "    clean-docs       - Remove documentation build artifacts."
+	@echo "    clean-build      - Remove setup artifacts."
+
+clean: clean-docs clean-pyc clean-build
+
+clean-dist: clean clean-git-force
+
+Documentation:
+	(cd "$(SPHINX_DIR)"; $(MAKE) html)
+	mv "$(SPHINX_HTMLDIR)" $(DOCUMENTATION)
+
+docs: Documentation
+
+clean-docs:
+	-rm -rf "$(SPHINX_BUILDDIR)"
+
+lint: flakecheck apicheck configcheck readmecheck
+
+apicheck:
+	(cd "$(SPHINX_DIR)"; $(MAKE) apicheck)
+
+configcheck:
+	(cd "$(SPHINX_DIR)"; $(MAKE) configcheck)
 
 flakecheck:
-	flake8 billiard
+	# the only way to enable all-1 errors is to ignore one of them.
+	$(FLAKE8) --ignore=X999 "$(PROJ)"
 
 flakediag:
 	-$(MAKE) flakecheck
 
 flakepluscheck:
-	flakeplus billiard --2.6
+	$(FLAKEPLUS) --$(FLAKEPLUSTARGET) "$(PROJ)"
 
 flakeplusdiag:
 	-$(MAKE) flakepluscheck
 
 flakes: flakediag flakeplusdiag
 
-test:
-	nosetests -xv billiard.tests
+clean-readme:
+	-rm -f $(README)
 
-cov:
-	nosetests -xv billiard.tests --with-coverage --cover-html --cover-branch
+readmecheck:
+	$(ICONV) -f ascii -t ascii $(README) >/dev/null
 
-removepyc:
+$(README):
+	$(SPHINX2RST) "$(README_SRC)" --ascii > $@
+
+readme: clean-readme $(README) readmecheck
+
+clean-contrib:
+	-rm -f "$(CONTRIBUTING)"
+
+$(CONTRIBUTING):
+	$(SPHINX2RST) "$(CONTRIBUTING_SRC)" > $@
+
+contrib: clean-contrib $(CONTRIBUTING)
+
+clean-pyc:
 	-find . -type f -a \( -name "*.pyc" -o -name "*$$py.class" \) | xargs rm
 	-find . -type d -name "__pycache__" | xargs rm -r
 
-gitclean:
-	git clean -xdn
+removepyc: clean-pyc
+
+clean-build:
+	rm -rf build/ dist/ .eggs/ *.egg-info/ .tox/ .coverage cover/
 
-gitcleanforce:
-	git clean -xdf
+clean-git:
+	$(GIT) clean -xdn
+
+clean-git-force:
+	$(GIT) clean -xdf
+
+test-all: clean-pyc
+	$(TOX)
+
+test:
+	$(PYTHON) setup.py test
+
+cov:
+	$(NOSETESTS) -xv --with-coverage --cover-html --cover-branch
 
-bump_version:
-	$(PYTHON) extra/release/bump_version.py billiard/__init__.py
+build:
+	$(PYTHON) setup.py sdist bdist_wheel
 
-distcheck: flakecheck test gitclean
+distcheck: lint test clean
 
-dist: readme docsclean gitcleanforce removepyc
+dist: readme contrib clean-dist build
diff --git a/Modules/_billiard/connection.h b/Modules/_billiard/connection.h
deleted file mode 100644
index 6f3958d..0000000
--- a/Modules/_billiard/connection.h
+++ /dev/null
@@ -1,710 +0,0 @@
-/*
- * Definition of a `Connection` type.
- * Used by `socket_connection.c` and `pipe_connection.c`.
- *
- * connection.h
- *
- * Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
- */
-
-#ifndef CONNECTION_H
-#define CONNECTION_H
-
-/*
- * Read/write flags
- */
-
-#define READABLE 1
-#define WRITABLE 2
-
-#define CHECK_READABLE(self) \
-    if (!(self->flags & READABLE)) { \
-    PyErr_SetString(PyExc_IOError, "connection is write-only"); \
-    return NULL; \
-    }
-
-#define CHECK_WRITABLE(self) \
-    if (!(self->flags & WRITABLE)) { \
-    PyErr_SetString(PyExc_IOError, "connection is read-only"); \
-    return NULL; \
-    }
-
-/*
- * Externally implemented functions
- */
-
-extern void _Billiard_setblocking(int fd, int blocking);
-extern ssize_t _Billiard_conn_send_offset(HANDLE fd, char *string, Py_ssize_t len, Py_ssize_t offset);
-
-/*
- * Allocation and deallocation
- */
-
-static PyObject *
-Billiard_connection_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
-    BilliardConnectionObject *self;
-    HANDLE handle;
-    BOOL readable = TRUE, writable = TRUE;
-
-    static char *kwlist[] = {"handle", "readable", "writable", NULL};
-
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, F_HANDLE "|ii", kwlist,
-                                     &handle, &readable, &writable))
-        return NULL;
-
-    if (handle == INVALID_HANDLE_VALUE || (Py_ssize_t)handle < 0) {
-        PyErr_Format(PyExc_IOError, "invalid handle %zd",
-                     (Py_ssize_t)handle);
-        return NULL;
-    }
-
-    if (!readable && !writable) {
-        PyErr_SetString(PyExc_ValueError,
-                        "either readable or writable must be true");
-        return NULL;
-    }
-
-    self = PyObject_New(BilliardConnectionObject, type);
-    if (self == NULL)
-        return NULL;
-
-    self->weakreflist = NULL;
-    self->handle = handle;
-    self->flags = 0;
-
-    if (readable)
-        self->flags |= READABLE;
-    if (writable)
-        self->flags |= WRITABLE;
-    assert(self->flags >= 1 && self->flags <= 3);
-
-    return (PyObject*)self;
-}
-
-static void
-Billiard_connection_dealloc(BilliardConnectionObject* self)
-{
-    HANDLE handle = self->handle;
-
-    if (self->weakreflist != NULL)
-        PyObject_ClearWeakRefs((PyObject*)self);
-
-    if (handle != INVALID_HANDLE_VALUE) {
-        self->handle = INVALID_HANDLE_VALUE;
-        Py_BEGIN_ALLOW_THREADS
-        CLOSE(handle);
-        Py_END_ALLOW_THREADS
-    }
-    PyObject_Del(self);
-}
-
-/*
- * Functions for transferring buffers
- */
-
-static PyObject *
-Billiard_connection_sendbytes(BilliardConnectionObject *self, PyObject *args)
-{
-    char *buffer;
-    Py_ssize_t length, offset=0, size=PY_SSIZE_T_MIN;
-    int res;
-
-    if (!PyArg_ParseTuple(args, F_RBUFFER "#|" F_PY_SSIZE_T F_PY_SSIZE_T,
-                          &buffer, &length, &offset, &size))
-        return NULL;
-
-    CHECK_WRITABLE(self);
-
-    if (offset < 0) {
-        PyErr_SetString(PyExc_ValueError, "offset is negative");
-        return NULL;
-    }
-    if (length < offset) {
-        PyErr_SetString(PyExc_ValueError, "buffer length < offset");
-        return NULL;
-    }
-
-    if (size == PY_SSIZE_T_MIN) {
-        size = length - offset;
-    } else {
-        if (size < 0) {
-            PyErr_SetString(PyExc_ValueError, "size is negative");
-            return NULL;
-        }
-        if (offset + size > length) {
-            PyErr_SetString(PyExc_ValueError,
-                            "buffer length < offset + size");
-            return NULL;
-        }
-    }
-
-    res = Billiard_conn_send_string(self, buffer + offset, size);
-
-    if (res < 0) {
-        if (PyErr_Occurred())
-            return NULL;
-        else
-            return Billiard_SetError(PyExc_IOError, res);
-    }
-
-    Py_RETURN_NONE;
-}
-
-static PyObject *
-Billiard_connection_recvbytes(BilliardConnectionObject *self, PyObject *args)
-{
-    char *freeme = NULL;
-    Py_ssize_t res, maxlength = PY_SSIZE_T_MAX;
-    PyObject *result = NULL;
-    HANDLE handle;
-
-    if (!PyArg_ParseTuple(args, "|" F_PY_SSIZE_T, &maxlength))
-        return NULL;
-
-    CHECK_READABLE(self);
-
-    if (maxlength < 0) {
-        PyErr_SetString(PyExc_ValueError, "maxlength < 0");
-        return NULL;
-    }
-
-    res = Billiard_conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
-                           &freeme, maxlength);
-
-    if (res < 0) {
-        if (res == MP_BAD_MESSAGE_LENGTH) {
-            if ((self->flags & WRITABLE) == 0) {
-                handle = self->handle;
-                if (handle != INVALID_HANDLE_VALUE) {
-                    self->handle = INVALID_HANDLE_VALUE;
-                    Py_BEGIN_ALLOW_THREADS
-                    CLOSE(handle);
-                    Py_END_ALLOW_THREADS
-                }
-            } else {
-                self->flags = WRITABLE;
-            }
-        }
-        Billiard_SetError(PyExc_IOError, res);
-    } else {
-        if (freeme == NULL) {
-            result = PyString_FromStringAndSize(self->buffer, res);
-        } else {
-            result = PyString_FromStringAndSize(freeme, res);
-            PyMem_Free(freeme);
-        }
-    }
-
-    return result;
-}
-
-#ifdef HAS_NEW_PY_BUFFER
-static PyObject *
-Billiard_connection_recvbytes_into(BilliardConnectionObject *self, PyObject *args)
-{
-    char *freeme = NULL, *buffer = NULL;
-    Py_ssize_t res, length, offset = 0;
-    PyObject *result = NULL;
-    Py_buffer pbuf;
-    HANDLE handle;
-
-    CHECK_READABLE(self);
-
-    if (!PyArg_ParseTuple(args, "w*|" F_PY_SSIZE_T,
-                          &pbuf, &offset))
-        return NULL;
-
-    buffer = pbuf.buf;
-    length = pbuf.len;
-
-    if (offset < 0) {
-        PyErr_SetString(PyExc_ValueError, "negative offset");
-        goto _error;
-    }
-
-    if (offset > length) {
-        PyErr_SetString(PyExc_ValueError, "offset too large");
-        goto _error;
-    }
-
-    res = Billiard_conn_recv_string(self, buffer+offset, length-offset,
-                           &freeme, PY_SSIZE_T_MAX);
-
-    if (res < 0) {
-        if (res == MP_BAD_MESSAGE_LENGTH) {
-            if ((self->flags & WRITABLE) == 0) {
-                handle = self->handle;
-                if (handle != INVALID_HANDLE_VALUE) {
-                    self->handle = INVALID_HANDLE_VALUE;
-                    Py_BEGIN_ALLOW_THREADS
-                    CLOSE(handle);
-                    Py_END_ALLOW_THREADS
-                }
-            } else {
-                self->flags = WRITABLE;
-            }
-        }
-        Billiard_SetError(PyExc_IOError, res);
-    } else {
-        if (freeme == NULL) {
-            result = PyInt_FromSsize_t(res);
-        } else {
-            result = PyObject_CallFunction(Billiard_BufferTooShort,
-                                           F_RBUFFER "#",
-                                           freeme, res);
-            PyMem_Free(freeme);
-            if (result) {
-                PyErr_SetObject(Billiard_BufferTooShort, result);
-                Py_DECREF(result);
-            }
-            goto _error;
-        }
-    }
-
-_cleanup:
-    PyBuffer_Release(&pbuf);
-    return result;
-
-_error:
-    result = NULL;
-    goto _cleanup;
-}
-# else /* old buffer protocol */
-
-static PyObject *
-Billiard_connection_recvbytes_into(BilliardConnectionObject *self, PyObject *args)
-{
-    char *freeme = NULL, *buffer = NULL;
-    Py_ssize_t length = 0, res, offset = 0;
-    PyObject *result = NULL;
-    HANDLE handle;
-
-    CHECK_READABLE(self);
-
-    if (!PyArg_ParseTuple(args, "w#|", F_PY_SSIZE_T,
-            &buffer, &length, &offset))
-        return NULL;
-
-    if (offset < 0) {
-        PyErr_SetString(PyExc_ValueError, "negative offset");
-        goto _error;
-    }
-
-    if (offset > 0) {
-        PyErr_SetString(PyExc_ValueError, "offset out of bounds");
-        goto _error;
-    }
-
-    res = Billiard_conn_recv_string(self, buffer+offset, length-offset,
-            &freeme, PY_SSIZE_T_MAX);
-    if (res < 0) {
-       if (res == MP_BAD_MESSAGE_LENGTH) {
-            if ((self->flags & WRITABLE) == 0) {
-                handle = self->handle;
-                if (handle != INVALID_HANDLE_VALUE) {
-                    self->handle = INVALID_HANDLE_VALUE;
-                    Py_BEGIN_ALLOW_THREADS
-                    CLOSE(handle);
-                    Py_END_ALLOW_THREADS
-                }
-            } else {
-                self->flags = WRITABLE;
-            }
-       }
-       Billiard_SetError(PyExc_IOError, res);
-    } else {
-        if (freeme == NULL) {
-            result = PyInt_FromSsize_t(res);
-        } else {
-            result = PyObject_CallFunction(Billiard_BufferTooShort,
-                    F_RBUFFER "#",
-                    freeme, res);
-            PyMem_Free(freeme);
-            if (result) {
-                PyErr_SetObject(Billiard_BufferTooShort, result);
-                Py_DECREF(result);
-            }
-            goto _error;
-        }
-    }
-
-_cleanup:
-    return result;
-
-_error:
-    result = NULL;
-    goto _cleanup;
-
-}
-# endif /* buffer */
-
-
-/*
- * Functions for transferring objects
- */
-
-static PyObject *
-Billiard_connection_send_offset(BilliardConnectionObject *self, PyObject *args)
-{
-    Py_buffer view;
-    Py_ssize_t len = 0;
-    Py_ssize_t offset = 0;
-    ssize_t written = 0;
-
-    char *buf = NULL;
-
-    if (!PyArg_ParseTuple(args, "s*n", &view, &offset))
-        return NULL;
-
-    len = view.len;
-    buf = view.buf;
-
-    // CHECK_WRITABLE(self);
-    if (!(self->flags & WRITABLE)) {
-        PyErr_SetString(PyExc_IOError, "connection is read-only"); \
-        goto bail;
-    }
-
-    if (len < 0 || len == 0) {
-        errno = EINVAL;
-        PyErr_SetFromErrno(PyExc_OSError);
-        goto bail;
-    }
-
-    written = _Billiard_conn_send_offset(self->handle, buf, (size_t)len, offset);
-    if (written < 0) {
-        Billiard_SetError(NULL, MP_SOCKET_ERROR);
-        goto bail;
-    }
-
-    PyBuffer_Release(&view);
-    return PyInt_FromSsize_t((Py_ssize_t)written);
-
-bail:
-    PyBuffer_Release(&view);
-    return NULL;
-}
-
-static PyObject *
-Billiard_connection_send_obj(BilliardConnectionObject *self, PyObject *obj)
-{
-    char *buffer;
-    int res;
-    Py_ssize_t length;
-    PyObject *pickled_string = NULL;
-
-    CHECK_WRITABLE(self);
-
-    pickled_string = PyObject_CallFunctionObjArgs(
-        Billiard_pickle_dumps, obj, Billiard_pickle_protocol, NULL
-    );
-    if (!pickled_string)
-        goto failure;
-
-    if (PyString_AsStringAndSize(pickled_string, &buffer, &length) < 0)
-        goto failure;
-
-    res = Billiard_conn_send_string(self, buffer, (int)length);
-
-    if (res != MP_SUCCESS) {
-        Billiard_SetError(NULL, res);
-        goto failure;
-    }
-
-    Py_XDECREF(pickled_string);
-    Py_RETURN_NONE;
-
-  failure:
-    Py_XDECREF(pickled_string);
-    return NULL;
-}
-
-static PyObject *
-Billiard_connection_setblocking(BilliardConnectionObject *self, PyObject *arg)
-{
-    _Billiard_setblocking((int)self->handle, PyInt_AS_LONG(arg));
-    Py_RETURN_NONE;
-}
-
-static PyObject *
-Billiard_connection_recv_payload(BilliardConnectionObject *self)
-{
-    char *freeme = NULL;
-    Py_ssize_t res;
-    PyObject *view = NULL;
-    HANDLE handle;
-
-    CHECK_READABLE(self);
-
-    res = Billiard_conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
-                                    &freeme, PY_SSIZE_T_MAX);
-    if (res < 0) {
-        if (res == MP_BAD_MESSAGE_LENGTH) {
-            if ((self->flags & WRITABLE) == 0) {
-                handle = self->handle;
-                if (handle != INVALID_HANDLE_VALUE) {
-                    self->handle = INVALID_HANDLE_VALUE;
-                    Py_BEGIN_ALLOW_THREADS
-                    CLOSE(handle);
-                    Py_END_ALLOW_THREADS
-                }
-            } else {
-                self->flags = WRITABLE;
-            }
-        }
-        Billiard_SetError(PyExc_IOError, res);
-        goto error;
-    } else {
-        if (freeme == NULL) {
-            view = PyBuffer_FromMemory(self->buffer, res);
-        } else {
-            view = PyString_FromStringAndSize(freeme, res);
-            PyMem_Free(freeme);
-        }
-    }
-    //Py_XDECREF(view);
-    return view;
-error:
-    return NULL;
-}
-
-static PyObject *
-Billiard_connection_recv_obj(BilliardConnectionObject *self)
-{
-    char *freeme = NULL;
-    Py_ssize_t res;
-    PyObject *temp = NULL, *result = NULL;
-    HANDLE handle;
-
-    CHECK_READABLE(self);
-
-    res = Billiard_conn_recv_string(self, self->buffer, CONNECTION_BUFFER_SIZE,
-                           &freeme, PY_SSIZE_T_MAX);
-
-    if (res < 0) {
-        if (res == MP_BAD_MESSAGE_LENGTH) {
-            if ((self->flags & WRITABLE) == 0) {
-                handle = self->handle;
-                if (handle != INVALID_HANDLE_VALUE) {
-                    self->handle = INVALID_HANDLE_VALUE;
-                    Py_BEGIN_ALLOW_THREADS
-                    CLOSE(handle);
-                    Py_END_ALLOW_THREADS
-                }
-            } else {
-                self->flags = WRITABLE;
-            }
-        }
-        Billiard_SetError(PyExc_IOError, res);
-    } else {
-        if (freeme == NULL) {
-            temp = PyString_FromStringAndSize(self->buffer, res);
-        } else {
-            temp = PyString_FromStringAndSize(freeme, res);
-            PyMem_Free(freeme);
-        }
-    }
-
-    if (temp)
-        result = PyObject_CallFunctionObjArgs(Billiard_pickle_loads,
-                                              temp, NULL);
-    Py_XDECREF(temp);
-    return result;
-}
-
-/*
- * Other functions
- */
-
-static PyObject *
-Billiard_connection_poll(BilliardConnectionObject *self, PyObject *args)
-{
-    PyObject *timeout_obj = NULL;
-    double timeout = 0.0;
-    int res;
-
-    CHECK_READABLE(self);
-
-    if (!PyArg_ParseTuple(args, "|O", &timeout_obj))
-        return NULL;
-
-    if (timeout_obj == NULL) {
-        timeout = 0.0;
-    } else if (timeout_obj == Py_None) {
-        timeout = -1.0;                                 /* block forever */
-    } else {
-        timeout = PyFloat_AsDouble(timeout_obj);
-        if (PyErr_Occurred())
-            return NULL;
-        if (timeout < 0.0)
-            timeout = 0.0;
-    }
-
-    Py_BEGIN_ALLOW_THREADS
-    res = Billiard_conn_poll(self, timeout, _save);
-    Py_END_ALLOW_THREADS
-
-    switch (res) {
-    case TRUE:
-        Py_RETURN_TRUE;
-    case FALSE:
-        Py_RETURN_FALSE;
-    default:
-        return Billiard_SetError(PyExc_IOError, res);
-    }
-}
-
-static PyObject *
-Billiard_connection_fileno(BilliardConnectionObject* self)
-{
-    if (self->handle == INVALID_HANDLE_VALUE) {
-        PyErr_SetString(PyExc_IOError, "handle is invalid");
-        return NULL;
-    }
-    return PyInt_FromLong((long)self->handle);
-}
-
-static PyObject *
-Billiard_connection_close(BilliardConnectionObject *self)
-{
-    HANDLE handle = self->handle;
-
-    if (handle != INVALID_HANDLE_VALUE) {
-        self->handle = INVALID_HANDLE_VALUE;
-        Py_BEGIN_ALLOW_THREADS
-        CLOSE(handle);
-        Py_END_ALLOW_THREADS
-    }
-
-    Py_RETURN_NONE;
-}
-
-static PyObject *
-Billiard_connection_repr(BilliardConnectionObject *self)
-{
-    static char *conn_type[] = {"read-only", "write-only", "read-write"};
-
-    assert(self->flags >= 1 && self->flags <= 3);
-    return FROM_FORMAT("<%s %s, handle %zd>",
-                       conn_type[self->flags - 1],
-                       CONNECTION_NAME, (Py_ssize_t)self->handle);
-}
-
-/*
- * Getters and setters
- */
-
-static PyObject *
-Billiard_connection_closed(BilliardConnectionObject *self, void *closure)
-{
-    return PyBool_FromLong((long)(self->handle == INVALID_HANDLE_VALUE));
-}
-
-static PyObject *
-Billiard_connection_readable(BilliardConnectionObject *self, void *closure)
-{
-    return PyBool_FromLong((long)(self->flags & READABLE));
-}
-
-static PyObject *
-Billiard_connection_writable(BilliardConnectionObject *self, void *closure)
-{
-    return PyBool_FromLong((long)(self->flags & WRITABLE));
-}
-
-/*
- * Tables
- */
-
-static PyMethodDef Billiard_connection_methods[] = {
-    {"send_bytes", (PyCFunction)Billiard_connection_sendbytes, METH_VARARGS,
-     "send the byte data from a readable buffer-like object"},
-    {"recv_bytes", (PyCFunction)Billiard_connection_recvbytes, METH_VARARGS,
-     "receive byte data as a string"},
... 11926 lines suppressed ...

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



More information about the Python-modules-commits mailing list