Fix s/bc/mpw/ typos in mpstr.
authorjbj <devnull@localhost>
Tue, 6 May 2003 19:57:10 +0000 (19:57 +0000)
committerjbj <devnull@localhost>
Tue, 6 May 2003 19:57:10 +0000 (19:57 +0000)
Fix cut and paste booboo, s/rshift/lshift/ for when x << y.

CVS patchset: 6819
CVS date: 2003/05/06 19:57:10

python/header-py.c
python/mpw/test/Makefile.am
python/mpw/test/test_methods.py
python/rpmmpw-py.c

index 11fdbe2..2aad11c 100644 (file)
@@ -421,14 +421,19 @@ static struct PyMethodDef hdr_methods[] = {
     {NULL,             NULL}           /* sentinel */
 };
 
-/** \ingroup py_c
- */
-static PyObject * hdr_getattr(hdrObject * s, char * name)
+static PyObject * hdr_getattro(PyObject * o, PyObject * n)
        /*@*/
 {
-    return Py_FindMethod(hdr_methods, (PyObject * ) s, name);
+    return PyObject_GenericGetAttr(o, n);
 }
 
+static int hdr_setattro(PyObject * o, PyObject * n, PyObject * v)
+       /*@*/
+{
+    return PyObject_GenericSetAttr(o, n, v);
+}
+
+
 /** \ingroup py_c
  */
 static void hdr_dealloc(hdrObject * s)
@@ -643,7 +648,7 @@ PyTypeObject hdr_Type = {
        0,                              /* tp_itemsize */
        (destructor) hdr_dealloc,       /* tp_dealloc */
        0,                              /* tp_print */
-       (getattrfunc) hdr_getattr,      /* tp_getattr */
+       (getattrfunc) 0,                /* tp_getattr */
        0,                              /* tp_setattr */
        (cmpfunc) hdr_compare,          /* tp_compare */
        0,                              /* tp_repr */
@@ -653,8 +658,8 @@ PyTypeObject hdr_Type = {
        hdr_hash,                       /* tp_hash */
        0,                              /* tp_call */
        0,                              /* tp_str */
-       0,                              /* tp_getattro */
-       0,                              /* tp_setattro */
+       (getattrofunc) hdr_getattro,    /* tp_getattro */
+       (setattrofunc) hdr_setattro,    /* tp_setattro */
        0,                              /* tp_as_buffer */
        Py_TPFLAGS_DEFAULT,             /* tp_flags */
        hdr_doc,                        /* tp_doc */
index 1e9ba89..ddf713a 100644 (file)
@@ -11,3 +11,6 @@ EXTRA_DIST = \
        unittest.py
 
 all:
+
+check:
+       python test_all.py
index 6c851eb..43c930c 100644 (file)
@@ -37,7 +37,7 @@ class BasicTestCase(unittest.TestCase):
     def test01_SimpleMethods(self):
         if verbose:
             print '\n', '-=' * 30
-            print "Running %s.test01_GetsAndPuts..." % \
+            print "Running %s.test01_SimpleMethods..." % \
                   self.__class__.__name__
 
        wa = mpw("0000000987654321")
@@ -47,26 +47,27 @@ class BasicTestCase(unittest.TestCase):
        zb = mpz.mpz(0x0000000000000010)
        zc = mpz.mpz(0x0fedcba000000000)
 
-       print hex(mpw.__add__(wa, wb)), hex(mpz.MPZType.__add__(za, zb))
-       print hex(mpw.__sub__(wa, wb)), hex(mpz.MPZType.__sub__(za, zb))
-       print hex(mpw.__mul__(wa, wb)), hex(mpz.MPZType.__mul__(za, zb))
-       print hex(mpw.__div__(wa, wb)), hex(mpz.MPZType.__div__(za, zb))
-       print hex(mpw.__mod__(wa, wb)), hex(mpz.MPZType.__mod__(za, zb))
-
-#      print mpw.__divmod__(a, b)
-#      print mpw.__pow__(a, b)
-
-#      print mpw.__lshift__(a, b)
-#      print mpw.__rshift__(a, b)
-
-#      print mpw.__and__(a, c)
-#      print mpw.__xor__(a, a)
-#      print mpw.__or__(a, c)
-
-#      print mpw.__neg__(a)
-#      print mpw.__pos__(a)
-#      print mpw.__abs__(a)
-#      print mpw.__invert__(a)
+       print "__neg__:\t", hex(mpw.__neg__(wa)), "\t",  hex(mpz.MPZType.__neg__(za))
+       print "__pos__:\t", hex(mpw.__pos__(wa)), "\t",  hex(mpz.MPZType.__pos__(za))
+       print "__abs__:\t", hex(mpw.__abs__(wa)), "\t",  hex(mpz.MPZType.__abs__(za))
+       print "__invert__:\t", hex(mpw.__invert__(wa)), "\t",  hex(mpz.MPZType.__invert__(za))
+
+       print "__add__:\t", hex(mpw.__add__(wa, wb)), "\t",  hex(mpz.MPZType.__add__(za, zb))
+       print "__sub__:\t", hex(mpw.__sub__(wa, wb)), "\t",  hex(mpz.MPZType.__sub__(za, zb))
+       print "__mul__:\t", hex(mpw.__mul__(wa, wb)), "\t",  hex(mpz.MPZType.__mul__(za, zb))
+       print "__div__:\t", hex(mpw.__div__(wa, wb)), "\t",  hex(mpz.MPZType.__div__(za, zb))
+       print "__mod__:\t", hex(mpw.__mod__(wa, wb)), "\t",  hex(mpz.MPZType.__mod__(za, zb))
+       wq, wr = mpw.__divmod__(wa, wb)
+       zq, zr = mpz.MPZType.__divmod__(za, zb)
+       print "__divmod__ q:\t", hex(wq), "\t",  hex(zq)
+       print "__divmod__ r:\t", hex(wr), "\t",  hex(zr)
+       print "__pow__:\t", hex(mpw.__pow__(mpw(16), wb)), "\t",  hex(mpz.MPZType.__pow__(mpz.mpz(16), zb))
+
+       print "__lshift__:\t", hex(mpw.__lshift__(wa, wb)), "\t",  hex(mpz.MPZType.__lshift__(za, zb))
+       print "__rshift__:\t", hex(mpw.__rshift__(wa, wb)), "\t",  hex(mpz.MPZType.__rshift__(za, zb))
+       print "__and__:\t", hex(mpw.__and__(wa, wc)), "\t",  hex(mpz.MPZType.__and__(za, zc))
+       print "__xor__:\t", hex(mpw.__xor__(wa, wa)), "\t",  hex(mpz.MPZType.__xor__(za, za))
+       print "__or__:\t", hex(mpw.__or__(wa, wc)), "\t",  hex(mpz.MPZType.__or__(za, zc))
 
 #      print mpw.__int__(b)
 #      print mpw.__long__(b)
index 17dbbee..79b8ba8 100644 (file)
@@ -371,7 +371,7 @@ mpstr(char * t, size_t nt, size_t zsize, mpw* zdata, size_t zbase)
     mpw* wksp = alloca((size+1) * sizeof(*wksp));
     mpw* adata = alloca(size * sizeof(*adata));
     mpw* bdata = alloca(size * sizeof(*bdata));
-    static char mpwhars[] = "0123456789ampwdefghijklmnopqrstuvwxyz";
+    static char bchars[] = "0123456789abcdefghijklmnopqrstuvwxyz";
     size_t result;
 
 if (_mpw_debug < -1)
@@ -388,7 +388,7 @@ fprintf(stderr, "***       a: %p[%d]\t", adata, size), mpfprintln(stderr, size,
 if (_mpw_debug < -1)
 fprintf(stderr, "***    nmod: %p[%d]\t", bdata, size), mpfprintln(stderr, size, bdata);
        result = bdata[size-1];
-       t[nt] = mpwhars[result];
+       t[nt] = bchars[result];
        mpndivmod(bdata, size, adata, 1, &zbase, wksp);
 if (_mpw_debug < -1)
 fprintf(stderr, "*** ndivmod: %p[%d]\t", bdata, size), mpfprintln(stderr, size, bdata);
@@ -448,6 +448,9 @@ fprintf(stderr, "*** mpw_format(%p,%d,%d):\t", z, zbase, withname), mpfprintln(s
        zdata = z->n.data + (z->n.size - zsize);
     }
 
+    if (withname && zsize > 1)
+       i++;    /* space for 'L' suffix */
+
     nt = mpsizeinbase(zsize, zdata, zbase);
     i += nt;
 
@@ -499,8 +502,11 @@ fprintf(stderr, "*** mpw_format(%p,%d,%d):\t", z, zbase, withname), mpfprintln(s
 
     te += strlen(te);
 
-    if (withname)
+    if (withname) {
+       if (zsize > 1)
+           *te++ = 'L';
        *te++ = /*'('*/ ')';
+    }
     *te = '\0';
 
     assert(te - PyString_AS_STRING(so) <= i);
@@ -1128,7 +1134,7 @@ fprintf(stderr, "    b %p[%d]:\t", m->n.data, m->n.size), mpfprintln(stderr, m->
        if (bsize == 1)
            count = bdata[0];
        mpninit(&z->n, x->n.size, x->n.data);
-       mprshift(z->n.size, z->n.data, count);
+       mplshift(z->n.size, z->n.data, count);
     }  break;
     case '>':
     {  size_t bnorm = m->n.size - (mpbitcnt(m->n.size, m->n.data) + 31)/32;