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: Fixes broken tests.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/58e05b91b909
branches:  trunk
changeset: 401361:58e05b91b909
user:      fox <fox%pkgsrc.org@localhost>
date:      Sun Sep 15 15:17:06 2019 +0000

description:
py-sysctl: Fixes broken tests.

- Fixes the broken test for creating and destroying integer nodes via py-sysctl.
- Bumps PKGREVISION due to the fix.

This addresses the issue mentioned by maya@ in PR pkg/54530

Thanks to christos@ for helping with the fix.

Reveiwed by:    maya

diffstat:

 devel/py-sysctl/Makefile                     |   4 +-
 devel/py-sysctl/distinfo                     |   4 +-
 devel/py-sysctl/patches/patch-sysctlmodule.c |  96 +++++++++++++++++++++++++--
 3 files changed, 92 insertions(+), 12 deletions(-)

diffs (195 lines):

diff -r ff319138cf48 -r 58e05b91b909 devel/py-sysctl/Makefile
--- a/devel/py-sysctl/Makefile  Sun Sep 15 14:53:13 2019 +0000
+++ b/devel/py-sysctl/Makefile  Sun Sep 15 15:17:06 2019 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.7 2019/09/09 07:09:47 maya Exp $
+# $NetBSD: Makefile,v 1.8 2019/09/15 15:17:06 fox Exp $
 
 DISTNAME=      py-sysctl-0.1
 PKGNAME=       ${PYPKGPREFIX}-sysctl-0.1
-PKGREVISION=   2
+PKGREVISION=   3
 CATEGORIES=    devel python
 MASTER_SITES=  ftp://ftp.NetBSD.org/pub/NetBSD/misc/cherry/
 
diff -r ff319138cf48 -r 58e05b91b909 devel/py-sysctl/distinfo
--- a/devel/py-sysctl/distinfo  Sun Sep 15 14:53:13 2019 +0000
+++ b/devel/py-sysctl/distinfo  Sun Sep 15 15:17:06 2019 +0000
@@ -1,9 +1,9 @@
-$NetBSD: distinfo,v 1.3 2019/09/09 07:09:47 maya Exp $
+$NetBSD: distinfo,v 1.4 2019/09/15 15:17:06 fox 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-sysctlmodule.c) = fd357f6205341ba7c9585f2788828a6e78ad7cb2
 SHA1 (patch-test.py) = ff610e1eb2371147454861dd80e4d31878ec0ae7
diff -r ff319138cf48 -r 58e05b91b909 devel/py-sysctl/patches/patch-sysctlmodule.c
--- a/devel/py-sysctl/patches/patch-sysctlmodule.c      Sun Sep 15 14:53:13 2019 +0000
+++ b/devel/py-sysctl/patches/patch-sysctlmodule.c      Sun Sep 15 15:17:06 2019 +0000
@@ -1,13 +1,18 @@
-$NetBSD: patch-sysctlmodule.c,v 1.1 2019/09/09 07:09:47 maya Exp $
+$NetBSD: patch-sysctlmodule.c,v 1.2 2019/09/15 15:17:06 fox Exp $
 
 Port to python 3
 
+Fixes how new integer data is inserted into nodes. It now sets the
+CTL_IMMEDIATE flag and value is placed in sysctl_idata. This fixes
+the failing test for creating and destroying integer type nodes.
+
 --- sysctlmodule.c.orig        2010-04-10 17:41:18.000000000 +0000
 +++ sysctlmodule.c
-@@ -33,6 +33,21 @@
+@@ -33,7 +33,22 @@
  #include <errno.h>
  #include <sys/sysctl.h>
  
+-/* 
 +struct module_state {
 +    PyObject *error;
 +};
@@ -23,9 +28,22 @@
 +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
+  * type recognition to the sysctl(3) API. Fantastic! :-)
+@@ -94,9 +109,9 @@ node_to_object(const char *name, void *v
+       return o;
+ }
+ 
+-/* 
++/*
+  * SYSCTL_TYPEMASK is used as an error type. This is an implementation
+- * detail. 
++ * detail.
+  */
+ static uint32_t
+ nodetype(char *nodepath)
 @@ -104,14 +119,12 @@ nodetype(char *nodepath)
  
        int rv;
@@ -42,6 +60,15 @@
        rv = sysctlgetmibinfo(nodepath, NULL, NULL, cname, &csz, &rnode, SYSCTL_VERSION);
  
        if (rv == -1 || rnode == NULL) {
+@@ -133,7 +146,7 @@ nodetype(char *nodepath)
+  * discarded ),  and a new one, with requested string is assigned.
+  *
+  * XXX: This is a workaround for sysctl(3) not allowing strings longer
+- * than the current value. 
++ * than the current value.
+  * See: http://mail-index.netbsd.org/tech-kern/2009/10/22/msg006329.html
+  */
+ 
 @@ -149,7 +162,7 @@ write_sysctl_string(char *name, char *va
        size_t nodelen;
  
@@ -89,6 +116,24 @@
  
        rv = sysctlbyname(name, NULL, &len, NULL, 0);
  
+@@ -350,7 +361,7 @@ write_sysctl(PyObject *self, PyObject *a
+                       return NULL;
+               }
+ 
+-              /* 
++              /*
+                * Strings are handled specially. We just use
+                * read_sysctl() to record the previous string value.
+                * We ignore and free(oldval)
+@@ -424,7 +435,7 @@ getnewleafname(const char *name, char *c
+ 
+ /*
+  * Get the common prefix of name from what's already in the MIB and
+- * what's been requested 
++ * what's been requested
+  */
+ static void
+ getprefixname(const char *name, char *pname)
 @@ -445,7 +456,7 @@ create_node(const char *name, int ctl_ty
  {
  
@@ -106,7 +151,21 @@
        /* Check for NULL ptr dereference */
        assert (value != NULL || vlen == 0);
  
-@@ -533,7 +545,7 @@ create_sysctl(PyObject *self, PyObject *
+@@ -504,7 +516,12 @@ create_node(const char *name, int ctl_ty
+       memset(&node, 0, nodelen);
+       node.sysctl_num = CTL_CREATE;
+       node.sysctl_flags = SYSCTL_VERSION | flags | ctl_type;
+-      node.sysctl_data = value;
++      if (ctl_type == CTLTYPE_INT) {
++        node.sysctl_idata = *(int *) value;
++      }
++      else {
++        node.sysctl_data = value;
++      }
+       node.sysctl_size = vlen;
+ 
+       snprintf(node.sysctl_name, csz + 1, cname);
+@@ -533,7 +550,7 @@ create_sysctl(PyObject *self, PyObject *
        const char *typename = NULL;
        size_t typelen = 0;
  
@@ -115,7 +174,7 @@
  
        /* 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 *
+@@ -546,7 +563,7 @@ create_sysctl(PyObject *self, PyObject *
        }
  
        /* XXX: Arrange to obtain the oldvalue */
@@ -124,12 +183,21 @@
  
        if ((typename == NULL && typelen == 0)
            || (!strncmp(typename, "CTLTYPE_NODE", typelen)) ) {
-@@ -593,7 +605,12 @@ create_sysctl(PyObject *self, PyObject *
+@@ -578,7 +595,7 @@ create_sysctl(PyObject *self, PyObject *
+                       }
+               }
+ 
+-              if (!create_node(name, CTLTYPE_INT, CTLFLAG_READWRITE, &intval, sizeof intval)) {
++              if (!create_node(name, CTLTYPE_INT, CTLFLAG_READWRITE|CTLFLAG_IMMEDIATE, &intval, sizeof intval)) {
+                       return NULL;
+               } else {
+                       Py_RETURN_NONE;
+@@ -593,7 +610,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);
++                      strval = (char *) PyUnicode_AsUTF8AndSize(value, &vlen);
 +                      if (strval == NULL) {
 +#else
                        if (-1 == PyString_AsStringAndSize(value, &strval, &vlen)) {
@@ -137,7 +205,19 @@
                                PyErr_SetString(PyExc_TypeError, "Error decoding string from buffer \n");
                                return NULL;
                        }
-@@ -694,8 +711,61 @@ static PyMethodDef sysctl_methods[] = {
+@@ -682,9 +704,9 @@ destroy_sysctl(PyObject *self, PyObject 
+ }
+ 
+ static PyMethodDef sysctl_methods[] = {
+-      { "read", read_sysctl, METH_VARARGS, 
++      { "read", read_sysctl, METH_VARARGS,
+         "read value from sysctl node." },
+-      { "write", write_sysctl, METH_VARARGS, 
++      { "write", write_sysctl, METH_VARARGS,
+         "write value to sysctl node." },
+       { "create", create_sysctl, METH_VARARGS,
+         "create a sysctl node." },
+@@ -694,8 +716,61 @@ static PyMethodDef sysctl_methods[] = {
  };
  
  



Home | Main Index | Thread Index | Old Index