pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/devel/py-sysctl py-sysctl: port to python 3.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/d1b0c44ca705
branches:  trunk
changeset: 339237:d1b0c44ca705
user:      maya <maya%pkgsrc.org@localhost>
date:      Mon Sep 09 07:09:47 2019 +0000

description:
py-sysctl: port to python 3.

One remaining test fails, but it seems it failed before.
PR pkg/54530

diffstat:

 devel/py-sysctl/Makefile                     |    4 +-
 devel/py-sysctl/PLIST                        |    4 +-
 devel/py-sysctl/distinfo                     |    5 +-
 devel/py-sysctl/patches/patch-setup.py       |   11 +
 devel/py-sysctl/patches/patch-sysctlmodule.c |  202 +++++++++++++++++
 devel/py-sysctl/patches/patch-test.py        |  304 +++++++++++++++++++++++++++
 6 files changed, 525 insertions(+), 5 deletions(-)

diffs (truncated from 565 to 300 lines):

diff -r 91b510ae3e59 -r d1b0c44ca705 devel/py-sysctl/Makefile
--- a/devel/py-sysctl/Makefile  Mon Sep 09 03:11:23 2019 +0000
+++ b/devel/py-sysctl/Makefile  Mon Sep 09 07:09:47 2019 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.6 2015/01/04 05:43:31 dholland Exp $
+# $NetBSD: Makefile,v 1.7 2019/09/09 07:09:47 maya Exp $
 
 DISTNAME=      py-sysctl-0.1
 PKGNAME=       ${PYPKGPREFIX}-sysctl-0.1
-PKGREVISION=   1
+PKGREVISION=   2
 CATEGORIES=    devel python
 MASTER_SITES=  ftp://ftp.NetBSD.org/pub/NetBSD/misc/cherry/
 
diff -r 91b510ae3e59 -r d1b0c44ca705 devel/py-sysctl/PLIST
--- a/devel/py-sysctl/PLIST     Mon Sep 09 03:11:23 2019 +0000
+++ b/devel/py-sysctl/PLIST     Mon Sep 09 07:09:47 2019 +0000
@@ -1,2 +1,2 @@
-@comment $NetBSD: PLIST,v 1.1.1.1 2010/04/11 06:48:41 cherry Exp $
-${PYSITELIB}/sysctlmodule.so
+@comment $NetBSD: PLIST,v 1.2 2019/09/09 07:09:47 maya Exp $
+${PYSITELIB}/sysctl.so
diff -r 91b510ae3e59 -r d1b0c44ca705 devel/py-sysctl/distinfo
--- a/devel/py-sysctl/distinfo  Mon Sep 09 03:11:23 2019 +0000
+++ b/devel/py-sysctl/distinfo  Mon Sep 09 07:09:47 2019 +0000
@@ -1,6 +1,9 @@
-$NetBSD: distinfo,v 1.2 2015/11/03 03:29:16 agc Exp $
+$NetBSD: distinfo,v 1.3 2019/09/09 07:09:47 maya Exp $
 
 SHA1 (py-sysctl-0.1.tar.gz) = 120483a57fc85790702223317b1e29ece62f5bb0
 RMD160 (py-sysctl-0.1.tar.gz) = 053144711e41f5518efc418795eec5e6e06750a1
 SHA512 (py-sysctl-0.1.tar.gz) = 4b6123625a212364ef5a2a367f13ec32194503b8881248e3909f5958adac05149ed2c22aa49b67468c3d1fc23386c16d97af747b8045b322c749f37d1a086005
 Size (py-sysctl-0.1.tar.gz) = 6746 bytes
+SHA1 (patch-setup.py) = eef1ae1e7a6d60f332514670ebcd1ee08dece131
+SHA1 (patch-sysctlmodule.c) = 55c7cec28080a936022e17f6e599f00b6825011c
+SHA1 (patch-test.py) = ff610e1eb2371147454861dd80e4d31878ec0ae7
diff -r 91b510ae3e59 -r d1b0c44ca705 devel/py-sysctl/patches/patch-setup.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/py-sysctl/patches/patch-setup.py    Mon Sep 09 07:09:47 2019 +0000
@@ -0,0 +1,11 @@
+$NetBSD: patch-setup.py,v 1.1 2019/09/09 07:09:47 maya Exp $
+
+--- setup.py.orig      2010-04-10 17:41:18.000000000 +0000
++++ setup.py
+@@ -2,5 +2,5 @@
+ from distutils.core import setup, Extension
+ 
+-module1 = Extension('sysctlmodule',
++module1 = Extension('sysctl',
+                     sources = ['sysctlmodule.c'])
+ 
diff -r 91b510ae3e59 -r d1b0c44ca705 devel/py-sysctl/patches/patch-sysctlmodule.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/py-sysctl/patches/patch-sysctlmodule.c      Mon Sep 09 07:09:47 2019 +0000
@@ -0,0 +1,202 @@
+$NetBSD: patch-sysctlmodule.c,v 1.1 2019/09/09 07:09:47 maya Exp $
+
+Port to python 3
+
+--- sysctlmodule.c.orig        2010-04-10 17:41:18.000000000 +0000
++++ sysctlmodule.c
+@@ -33,6 +33,21 @@
+ #include <errno.h>
+ #include <sys/sysctl.h>
+ 
++struct module_state {
++    PyObject *error;
++};
++
++#if PY_MAJOR_VERSION >= 3
++#define PyInt_AsLong                  PyLong_AsLong
++#define PyInt_CheckExact              PyLong_CheckExact
++#define PyString_CheckExact(val)      PyUnicode_CheckExact(val)
++#define PyString_FromStringAndSize    PyUnicode_FromStringAndSize
++#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
++#else
++#define GETSTATE(m) (&_state)
++static struct module_state _state;
++#endif
++
+ /* 
+  * create Python object of type similar to the MIB node 'name'
+  * This is basically the laziest way to do this, as we outsource the
+@@ -104,14 +119,12 @@ nodetype(char *nodepath)
+ 
+       int rv;
+       char cname[SYSCTL_NAMELEN];
+-      int csz;
++      size_t csz = SYSCTL_NAMELEN;
+ 
+       struct sysctlnode *rnode = NULL;
+ 
+       assert (nodepath != NULL);
+ 
+-      csz = SYSCTL_NAMELEN;
+-
+       rv = sysctlgetmibinfo(nodepath, NULL, NULL, cname, &csz, &rnode, SYSCTL_VERSION);
+ 
+       if (rv == -1 || rnode == NULL) {
+@@ -149,7 +162,7 @@ write_sysctl_string(char *name, char *va
+       size_t nodelen;
+ 
+       char cname[SYSCTL_NAMELEN];
+-      int csz = SYSCTL_NAMELEN;
++      size_t csz = SYSCTL_NAMELEN;
+ 
+       /* Sanity checks */
+ 
+@@ -237,7 +250,7 @@ read_sysctl(PyObject *self, PyObject *ar
+ {
+       PyObject *o;
+       void *val;
+-      size_t len;
++      size_t len = 0;
+       const char *name;
+       int rv;
+ 
+@@ -245,9 +258,7 @@ read_sysctl(PyObject *self, PyObject *ar
+               return NULL;
+ 
+ getbyname:
+-      val = NULL;
+-      len = 0;
+-
++      len += 4;
+       rv = sysctlbyname(name, NULL, &len, NULL, 0);
+ 
+       if (rv == -1) {
+@@ -256,7 +267,7 @@ getbyname:
+       }
+ 
+       val = malloc(len);
+-      if (val ==NULL) {
++      if (val == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+@@ -309,7 +320,7 @@ write_sysctl(PyObject *self, PyObject *a
+ 
+       /* Arrange to obtain the oldvalue */
+       oldval = NULL;
+-      len = 0;
++      len = 4;
+ 
+       rv = sysctlbyname(name, NULL, &len, NULL, 0);
+ 
+@@ -445,7 +456,7 @@ create_node(const char *name, int ctl_ty
+ {
+ 
+       int mib[CTL_MAXNAME];
+-      u_int miblen = CTL_MAXNAME;
++      size_t miblen = CTL_MAXNAME;
+ 
+       char cname[SYSCTL_NAMELEN]; /* Canonical name */
+       char pname[SYSCTL_NAMELEN]; /* The Canonical prefix */
+@@ -456,6 +467,7 @@ create_node(const char *name, int ctl_ty
+       struct sysctlnode node;
+       size_t nodelen;
+ 
++
+       /* Check for NULL ptr dereference */
+       assert (value != NULL || vlen == 0);
+ 
+@@ -533,7 +545,7 @@ create_sysctl(PyObject *self, PyObject *
+       const char *typename = NULL;
+       size_t typelen = 0;
+ 
+-      int len, rv;
++      int rv;
+ 
+       /* XXX: Royal mess... needs more thought */
+       if (!PyArg_ParseTuple(args, "s|s#O: Incorrect values passed to sysctl.write", &name, &typename, &typelen, &value)) {
+@@ -546,7 +558,7 @@ create_sysctl(PyObject *self, PyObject *
+       }
+ 
+       /* XXX: Arrange to obtain the oldvalue */
+-      len = 0;
++      /*len = 4;*/
+ 
+       if ((typename == NULL && typelen == 0)
+           || (!strncmp(typename, "CTLTYPE_NODE", typelen)) ) {
+@@ -593,7 +605,12 @@ create_sysctl(PyObject *self, PyObject *
+                               PyErr_SetString(PyExc_TypeError, "Value passed is of wrong type");
+                               return NULL;
+                       }
++#if PY_MAJOR_VERSION >= 3
++                      strval = PyUnicode_AsUTF8AndSize(value, &vlen);
++                      if (strval == NULL) {
++#else
+                       if (-1 == PyString_AsStringAndSize(value, &strval, &vlen)) {
++#endif
+                               PyErr_SetString(PyExc_TypeError, "Error decoding string from buffer \n");
+                               return NULL;
+                       }
+@@ -694,8 +711,61 @@ static PyMethodDef sysctl_methods[] = {
+ };
+ 
+ 
++
++#if PY_MAJOR_VERSION >= 3
++
++static int sysctl_traverse(PyObject *m, visitproc visit, void *arg) {
++    Py_VISIT(GETSTATE(m)->error);
++    return 0;
++}
++
++static int sysctl_clear(PyObject *m) {
++    Py_CLEAR(GETSTATE(m)->error);
++    return 0;
++}
++
++
++static struct PyModuleDef moduledef = {
++        PyModuleDef_HEAD_INIT,
++        "sysctl",
++        NULL,
++        sizeof(struct module_state),
++        sysctl_methods,
++        NULL,
++        sysctl_traverse,
++        sysctl_clear,
++        NULL
++};
++
++#define INITERROR return NULL
++
+ PyMODINIT_FUNC
++PyInit_sysctl(void)
++
++#else
++#define INITERROR return
++
++void
+ initsysctl(void)
++#endif
+ {
+-      (void) Py_InitModule("sysctl", sysctl_methods);
++#if PY_MAJOR_VERSION >= 3
++    PyObject *module = PyModule_Create(&moduledef);
++#else
++    PyObject *module = Py_InitModule("sysctl", sysctl_methods);
++#endif
++
++    if (module == NULL)
++        INITERROR;
++    struct module_state *st = GETSTATE(module);
++
++    st->error = PyErr_NewException("sysctl.Error", NULL, NULL);
++    if (st->error == NULL) {
++        Py_DECREF(module);
++        INITERROR;
++    }
++
++#if PY_MAJOR_VERSION >= 3
++    return module;
++#endif
+ }
diff -r 91b510ae3e59 -r d1b0c44ca705 devel/py-sysctl/patches/patch-test.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/py-sysctl/patches/patch-test.py     Mon Sep 09 07:09:47 2019 +0000
@@ -0,0 +1,304 @@
+$NetBSD: patch-test.py,v 1.1 2019/09/09 07:09:47 maya Exp $
+
+Port to python 3.
+
+--- test.py.orig       2010-04-10 17:41:18.000000000 +0000
++++ test.py
+@@ -9,111 +9,111 @@ import sysctl
+ 
+ # Invalid node
+ try:
+-    print "Testing invalid node: sysctl.read(\"unknown\")"
++    print("Testing invalid node: sysctl.read(\"unknown\")")
+     sysctl.read("unknown")
+ except OSError as detail:
+-    print detail
+-    print "PASSED"
++    print(detail)
++    print("PASSED")
+ else:
+-    print "FAILED"
++    print("FAILED")
+ 
+ # Node with Struct/Table val.
+ tmp = 666 #Variable Declaration
+ try:
+-    print "Testing (integer) node sysctl.read(\"kern.maxproc\")"
++    print("Testing (integer) node sysctl.read(\"kern.maxproc\")")
+     tmp = sysctl.read("kern.maxproc")
+ except ValueError as detail:
+-    print detail
+-    print "FAILED"
++    print(detail)
++    print("FAILED")
+ else:
+-    print "kern.maxproc == %i" % tmp
+-    print "PASSED"
++    print("kern.maxproc == %i" % tmp)
++    print("PASSED")
+ 



Home | Main Index | Thread Index | Old Index