~pythonregexp2.7/python/issue2636-18

« back to all changes in this revision

Viewing changes to Modules/_bsddb.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 13:47:31 UTC
  • mfrom: (39021.1.404 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921134731-rudomuzeh1b2tz1y
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
#define PyBytes_AS_STRING PyString_AS_STRING
116
116
#endif
117
117
 
 
118
#if (PY_VERSION_HEX >= 0x03000000)
 
119
#define NUMBER_Check    PyLong_Check
 
120
#define NUMBER_AsLong   PyLong_AsLong
 
121
#define NUMBER_FromLong PyLong_FromLong
 
122
#else
 
123
#define NUMBER_Check    PyInt_Check
 
124
#define NUMBER_AsLong   PyInt_AsLong
 
125
#define NUMBER_FromLong PyInt_FromLong
 
126
#endif
 
127
 
118
128
#ifdef WITH_THREAD
119
129
 
120
130
/* These are for when calling Python --> C */
178
188
static PyObject* DBNoServerError;       /* DB_NOSERVER */
179
189
static PyObject* DBNoServerHomeError;   /* DB_NOSERVER_HOME */
180
190
static PyObject* DBNoServerIDError;     /* DB_NOSERVER_ID */
181
 
#if (DBVER >= 33)
182
191
static PyObject* DBPageNotFoundError;   /* DB_PAGE_NOTFOUND */
183
192
static PyObject* DBSecondaryBadError;   /* DB_SECONDARY_BAD */
184
 
#endif
185
193
 
186
194
#if !INCOMPLETE_IS_WARNING
187
195
static PyObject* DBIncompleteError;     /* DB_INCOMPLETE */
201
209
static PyObject* DBRepHandleDeadError;  /* DB_REP_HANDLE_DEAD */
202
210
#endif
203
211
 
 
212
static PyObject* DBRepUnavailError;     /* DB_REP_UNAVAIL */
 
213
 
204
214
#if (DBVER < 43)
205
215
#define DB_BUFFER_SMALL         ENOMEM
206
216
#endif
219
229
#define DEFAULT_CURSOR_SET_RETURNS_NONE         1   /* 0 in pybsddb < 4.2, python < 2.4 */
220
230
 
221
231
 
222
 
staticforward PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, DBLock_Type;
 
232
/* See comment in Python 2.6 "object.h" */
 
233
#ifndef staticforward
 
234
#define staticforward static
 
235
#endif
 
236
#ifndef statichere
 
237
#define statichere static
 
238
#endif
 
239
 
 
240
staticforward PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type,
 
241
              DBLock_Type;
223
242
#if (DBVER >= 43)
224
243
staticforward PyTypeObject DBSequence_Type;
225
244
#endif
320
339
    if ((nonNull) == NULL) {          \
321
340
        PyObject *errTuple = NULL;    \
322
341
        errTuple = Py_BuildValue("(is)", 0, #name " object has been closed"); \
323
 
        PyErr_SetObject((pyErrObj), errTuple);  \
324
 
        Py_DECREF(errTuple);          \
 
342
        if (errTuple) { \
 
343
            PyErr_SetObject((pyErrObj), errTuple);  \
 
344
            Py_DECREF(errTuple);          \
 
345
        } \
325
346
        return NULL;                  \
326
347
    }
327
348
 
354
375
/* Return the access method type of the DBObject */
355
376
static int _DB_get_type(DBObject* self)
356
377
{
357
 
#if (DBVER >= 33)
358
378
    DBTYPE type;
359
379
    int err;
 
380
 
360
381
    err = self->db->get_type(self->db, &type);
361
382
    if (makeDBError(err)) {
362
383
        return -1;
363
384
    }
364
385
    return type;
365
 
#else
366
 
    return self->db->get_type(self->db);
367
 
#endif
368
386
}
369
387
 
370
388
 
378
396
    }
379
397
    else if (!PyArg_Parse(obj, "s#", &dbt->data, &dbt->size)) {
380
398
        PyErr_SetString(PyExc_TypeError,
 
399
#if (PY_VERSION_HEX < 0x03000000)
381
400
                        "Data values must be of type string or None.");
 
401
#else
 
402
                        "Data values must be of type bytes or None.");
 
403
#endif
382
404
        return 0;
383
405
    }
384
406
    return 1;
417
439
        if (type == DB_RECNO || type == DB_QUEUE) {
418
440
            PyErr_SetString(
419
441
                PyExc_TypeError,
 
442
#if (PY_VERSION_HEX < 0x03000000)
420
443
                "String keys not allowed for Recno and Queue DB's");
 
444
#else
 
445
                "Bytes keys not allowed for Recno and Queue DB's");
 
446
#endif
421
447
            return 0;
422
448
        }
423
449
 
439
465
        key->size = PyBytes_GET_SIZE(keyobj);
440
466
    }
441
467
 
442
 
    else if (PyInt_Check(keyobj)) {
 
468
    else if (NUMBER_Check(keyobj)) {
443
469
        /* verify access method type */
444
470
        type = _DB_get_type(self);
445
471
        if (type == -1)
458
484
 
459
485
        /* Make a key out of the requested recno, use allocated space so DB
460
486
         * will be able to realloc room for the real key if needed. */
461
 
        recno = PyInt_AS_LONG(keyobj);
 
487
        recno = NUMBER_AsLong(keyobj);
462
488
        key->data = malloc(sizeof(db_recno_t));
463
489
        if (key->data == NULL) {
464
490
            PyErr_SetString(PyExc_MemoryError, "Key memory allocation failed");
470
496
    }
471
497
    else {
472
498
        PyErr_Format(PyExc_TypeError,
 
499
#if (PY_VERSION_HEX < 0x03000000)
473
500
                     "String or Integer object expected for key, %s found",
 
501
#else
 
502
                     "Bytes or Integer object expected for key, %s found",
 
503
#endif
474
504
                     Py_TYPE(keyobj)->tp_name);
475
505
        return 0;
476
506
    }
555
585
    p=DummyString;
556
586
    assert(s==0);
557
587
  }
558
 
  return Py_BuildValue("s#",p,s);
 
588
  return PyBytes_FromStringAndSize(p, s);
559
589
}
560
590
 
561
591
static PyObject *BuildValue_SS(const void *p1,int s1,const void *p2,int s2)
562
592
{
 
593
PyObject *a, *b, *r;
 
594
 
563
595
  if (!p1) {
564
596
    p1=DummyString;
565
597
    assert(s1==0);
568
600
    p2=DummyString;
569
601
    assert(s2==0);
570
602
  }
571
 
  return Py_BuildValue("s#s#",p1,s1,p2,s2);
 
603
 
 
604
  if (!(a = PyBytes_FromStringAndSize(p1, s1))) {
 
605
      return NULL;
 
606
  }
 
607
  if (!(b = PyBytes_FromStringAndSize(p2, s2))) {
 
608
      Py_DECREF(a);
 
609
      return NULL;
 
610
  }
 
611
 
 
612
#if (PY_VERSION_HEX >= 0x02040000)
 
613
  r = PyTuple_Pack(2, a, b) ;
 
614
#else
 
615
  r = Py_BuildValue("OO", a, b);
 
616
#endif
 
617
  Py_DECREF(a);
 
618
  Py_DECREF(b);
 
619
  return r;
572
620
}
573
621
 
574
622
static PyObject *BuildValue_IS(int i,const void *p,int s)
575
623
{
 
624
  PyObject *a, *r;
 
625
 
576
626
  if (!p) {
577
627
    p=DummyString;
578
628
    assert(s==0);
579
629
  }
580
 
  return Py_BuildValue("is#",i,p,s);
 
630
 
 
631
  if (!(a = PyBytes_FromStringAndSize(p, s))) {
 
632
      return NULL;
 
633
  }
 
634
 
 
635
  r = Py_BuildValue("iO", i, a);
 
636
  Py_DECREF(a);
 
637
  return r;
581
638
}
582
639
 
583
 
static PyObject *BuildValue_LS(long i,const void *p,int s)
 
640
static PyObject *BuildValue_LS(long l,const void *p,int s)
584
641
{
 
642
  PyObject *a, *r;
 
643
 
585
644
  if (!p) {
586
645
    p=DummyString;
587
646
    assert(s==0);
588
647
  }
589
 
  return Py_BuildValue("ls#",i,p,s);
 
648
 
 
649
  if (!(a = PyBytes_FromStringAndSize(p, s))) {
 
650
      return NULL;
 
651
  }
 
652
 
 
653
  r = Py_BuildValue("lO", l, a);
 
654
  Py_DECREF(a);
 
655
  return r;
590
656
}
591
657
 
592
658
 
634
700
        case DB_NOSERVER:           errObj = DBNoServerError;       break;
635
701
        case DB_NOSERVER_HOME:      errObj = DBNoServerHomeError;   break;
636
702
        case DB_NOSERVER_ID:        errObj = DBNoServerIDError;     break;
637
 
#if (DBVER >= 33)
638
703
        case DB_PAGE_NOTFOUND:      errObj = DBPageNotFoundError;   break;
639
704
        case DB_SECONDARY_BAD:      errObj = DBSecondaryBadError;   break;
640
 
#endif
641
705
        case DB_BUFFER_SMALL:       errObj = DBNoMemoryError;       break;
642
706
 
643
707
#if (DBVER >= 43)
657
721
        case DB_REP_HANDLE_DEAD : errObj = DBRepHandleDeadError; break;
658
722
#endif
659
723
 
 
724
        case DB_REP_UNAVAIL : errObj = DBRepUnavailError; break;
 
725
 
660
726
        default:      errObj = DBError;             break;
661
727
    }
662
728
 
671
737
        }
672
738
        _db_errmsg[0] = 0;
673
739
 
674
 
        errTuple = Py_BuildValue("(is)", err, errTxt);
 
740
        errTuple = Py_BuildValue("(is)", err, errTxt);
 
741
        if (errTuple == NULL) {
 
742
            Py_DECREF(errObj);
 
743
            return !0;
 
744
        }
675
745
        PyErr_SetObject(errObj, errTuple);
676
 
        Py_DECREF(errTuple);
 
746
        Py_DECREF(errTuple);
677
747
    }
678
748
 
679
749
    return ((errObj != NULL) || exceptionRaised);
801
871
/* add an integer to a dictionary using the given name as a key */
802
872
static void _addIntToDict(PyObject* dict, char *name, int value)
803
873
{
804
 
    PyObject* v = PyInt_FromLong((long) value);
 
874
    PyObject* v = NUMBER_FromLong((long) value);
805
875
    if (!v || PyDict_SetItemString(dict, name, v))
806
876
        PyErr_Clear();
807
877
 
818
888
                v = PyLong_FromLongLong((PY_LONG_LONG) value);
819
889
        else
820
890
#endif
821
 
                v = PyInt_FromLong((long) value);
 
891
                v = NUMBER_FromLong((long) value);
822
892
    if (!v || PyDict_SetItemString(dict, name, v))
823
893
        PyErr_Clear();
824
894
 
837
907
}
838
908
#endif
839
909
 
840
 
#if (DBVER >= 40)
841
910
static void _addDB_lsnToDict(PyObject* dict, char *name, DB_LSN value)
842
911
{
843
912
    PyObject *v = Py_BuildValue("(ll)",value.file,value.offset);
846
915
 
847
916
    Py_XDECREF(v);
848
917
}
849
 
#endif
850
918
 
851
919
/* --------------------------------------------------------------------- */
852
920
/* Allocators and deallocators */
866
934
    self->flags = 0;
867
935
    self->setflags = 0;
868
936
    self->myenvobj = NULL;
 
937
    self->db = NULL;
869
938
    self->children_cursors = NULL;
870
939
#if (DBVER >=43)
871
940
    self->children_sequences = NULL;
872
941
#endif
873
 
#if (DBVER >= 33)
874
942
    self->associateCallback = NULL;
875
943
    self->btCompareCallback = NULL;
876
944
    self->primaryDBType = 0;
877
 
#endif
 
945
    Py_INCREF(Py_None);
 
946
    self->private_obj = Py_None;
878
947
    self->in_weakreflist = NULL;
879
948
 
880
949
    /* keep a reference to our python DBEnv object */
901
970
    err = db_create(&self->db, db_env, flags);
902
971
    if (self->db != NULL) {
903
972
        self->db->set_errcall(self->db, _db_errorCallback);
904
 
#if (DBVER >= 33)
905
973
        self->db->app_private = (void*)self;
906
 
#endif
907
974
    }
908
975
    MYDB_END_ALLOW_THREADS;
909
976
    /* TODO add a weakref(self) to the self->myenvobj->open_child_weakrefs
940
1007
        Py_DECREF(self->myenvobj);
941
1008
        self->myenvobj = NULL;
942
1009
    }
943
 
#if (DBVER >= 33)
944
1010
    if (self->associateCallback != NULL) {
945
1011
        Py_DECREF(self->associateCallback);
946
1012
        self->associateCallback = NULL;
949
1015
        Py_DECREF(self->btCompareCallback);
950
1016
        self->btCompareCallback = NULL;
951
1017
    }
952
 
#endif
 
1018
    Py_DECREF(self->private_obj);
953
1019
    PyObject_Del(self);
954
1020
}
955
1021
 
1011
1077
    self->moduleFlags.cursorSetReturnsNone = DEFAULT_CURSOR_SET_RETURNS_NONE;
1012
1078
    self->children_dbs = NULL;
1013
1079
    self->children_txns = NULL;
 
1080
    Py_INCREF(Py_None);
 
1081
    self->private_obj = Py_None;
 
1082
    Py_INCREF(Py_None);
 
1083
    self->rep_transport = Py_None;
1014
1084
    self->in_weakreflist = NULL;
1015
 
 
1016
 
#if (DBVER >= 40)
1017
1085
    self->event_notifyCallback = NULL;
1018
 
#endif
1019
1086
 
1020
1087
    MYDB_BEGIN_ALLOW_THREADS;
1021
1088
    err = db_env_create(&self->db_env, flags);
1026
1093
    }
1027
1094
    else {
1028
1095
        self->db_env->set_errcall(self->db_env, _db_errorCallback);
1029
 
        self->db_env->app_private=self;
 
1096
        self->db_env->app_private = self;
1030
1097
    }
1031
1098
    return self;
1032
1099
}
1039
1106
{
1040
1107
  PyObject *dummy;
1041
1108
 
1042
 
    if (self->db_env && !self->closed) {
 
1109
    if (self->db_env) {
1043
1110
      dummy=DBEnv_close_internal(self,0);
1044
1111
      Py_XDECREF(dummy);
1045
1112
    }
1046
1113
 
1047
 
#if (DBVER >= 40)
1048
1114
    Py_XDECREF(self->event_notifyCallback);
1049
1115
    self->event_notifyCallback = NULL;
1050
 
#endif
1051
1116
 
1052
1117
    if (self->in_weakreflist != NULL) {
1053
1118
        PyObject_ClearWeakRefs((PyObject *) self);
1054
1119
    }
1055
 
 
 
1120
    Py_DECREF(self->private_obj);
 
1121
    Py_DECREF(self->rep_transport);
1056
1122
    PyObject_Del(self);
1057
1123
}
1058
1124
 
1084
1150
        self->txn = txn;
1085
1151
    } else {
1086
1152
        MYDB_BEGIN_ALLOW_THREADS;
1087
 
#if (DBVER >= 40)
1088
1153
        err = myenv->db_env->txn_begin(myenv->db_env, parent_txn, &(self->txn), flags);
1089
 
#else
1090
 
        err = txn_begin(myenv->db_env, parent->txn, &(self_txn), flags);
1091
 
#endif
1092
1154
        MYDB_END_ALLOW_THREADS;
1093
1155
 
1094
1156
        if (makeDBError(err)) {
1156
1218
    self->in_weakreflist = NULL;
1157
1219
 
1158
1220
    MYDB_BEGIN_ALLOW_THREADS;
1159
 
#if (DBVER >= 40)
1160
1221
    err = myenv->db_env->lock_get(myenv->db_env, locker, flags, obj, lock_mode,
1161
1222
                                  &self->lock);
1162
 
#else
1163
 
    err = lock_get(myenv->db_env, locker, flags, obj, lock_mode, &self->lock);
1164
 
#endif
1165
1223
    MYDB_END_ALLOW_THREADS;
1166
1224
    if (makeDBError(err)) {
1167
1225
        Py_DECREF(self);
1238
1296
/* DB methods */
1239
1297
 
1240
1298
static PyObject*
1241
 
DB_append(DBObject* self, PyObject* args)
 
1299
DB_append(DBObject* self, PyObject* args, PyObject* kwargs)
1242
1300
{
1243
1301
    PyObject* txnobj = NULL;
1244
1302
    PyObject* dataobj;
1245
1303
    db_recno_t recno;
1246
1304
    DBT key, data;
1247
1305
    DB_TXN *txn = NULL;
 
1306
    static char* kwnames[] = { "data", "txn", NULL };
1248
1307
 
1249
 
    if (!PyArg_UnpackTuple(args, "append", 1, 2, &dataobj, &txnobj))
 
1308
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:append", kwnames,
 
1309
                                     &dataobj, &txnobj))
1250
1310
        return NULL;
1251
1311
 
1252
1312
    CHECK_DB_NOT_CLOSED(self);
1265
1325
    if (-1 == _DB_put(self, txn, &key, &data, DB_APPEND))
1266
1326
        return NULL;
1267
1327
 
1268
 
    return PyInt_FromLong(recno);
 
1328
    return NUMBER_FromLong(recno);
1269
1329
}
1270
1330
 
1271
1331
 
1272
 
#if (DBVER >= 33)
1273
 
 
1274
1332
static int
1275
1333
_db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
1276
1334
                      DBT* secKey)
1299
1357
        else if (result == Py_None) {
1300
1358
            retval = DB_DONOTINDEX;
1301
1359
        }
1302
 
        else if (PyInt_Check(result)) {
1303
 
            retval = PyInt_AsLong(result);
 
1360
        else if (NUMBER_Check(result)) {
 
1361
            retval = NUMBER_AsLong(result);
1304
1362
        }
1305
1363
        else if (PyBytes_Check(result)) {
1306
1364
            char* data;
1426
1484
}
1427
1485
 
1428
1486
 
1429
 
#endif
1430
 
 
1431
 
 
1432
1487
static PyObject*
1433
1488
DB_close_internal(DBObject* self, int flags)
1434
1489
{
1438
1493
    if (self->db != NULL) {
1439
1494
        /* Can be NULL if db is not in an environment */
1440
1495
        EXTRACT_FROM_DOUBLE_LINKED_LIST_MAYBE_NULL(self);
 
1496
 
1441
1497
        if (self->txn) {
1442
1498
            EXTRACT_FROM_DOUBLE_LINKED_LIST_TXN(self);
1443
1499
            self->txn=NULL;
1598
1654
 
1599
1655
 
1600
1656
static PyObject*
1601
 
DB_fd(DBObject* self, PyObject* args)
 
1657
DB_fd(DBObject* self)
1602
1658
{
1603
1659
    int err, the_fd;
1604
1660
 
1605
 
    if (!PyArg_ParseTuple(args,":fd"))
1606
 
        return NULL;
1607
1661
    CHECK_DB_NOT_CLOSED(self);
1608
1662
 
1609
1663
    MYDB_BEGIN_ALLOW_THREADS;
1610
1664
    err = self->db->fd(self->db, &the_fd);
1611
1665
    MYDB_END_ALLOW_THREADS;
1612
1666
    RETURN_IF_ERR();
1613
 
    return PyInt_FromLong(the_fd);
 
1667
    return NUMBER_FromLong(the_fd);
1614
1668
}
1615
1669
 
1616
1670
 
1680
1734
    return retval;
1681
1735
}
1682
1736
 
1683
 
#if (DBVER >= 33)
1684
1737
static PyObject*
1685
1738
DB_pget(DBObject* self, PyObject* args, PyObject* kwargs)
1686
1739
{
1721
1774
 
1722
1775
    CLEAR_DBT(pkey);
1723
1776
    pkey.flags = DB_DBT_MALLOC;
1724
 
    
 
1777
 
1725
1778
    MYDB_BEGIN_ALLOW_THREADS;
1726
1779
    err = self->db->pget(self->db, txn, &key, &pkey, &data, flags);
1727
1780
    MYDB_END_ALLOW_THREADS;
1744
1797
 
1745
1798
        if (self->primaryDBType == DB_RECNO ||
1746
1799
            self->primaryDBType == DB_QUEUE)
1747
 
            pkeyObj = PyInt_FromLong(*(int *)pkey.data);
 
1800
            pkeyObj = NUMBER_FromLong(*(int *)pkey.data);
1748
1801
        else
1749
1802
            pkeyObj = Build_PyString(pkey.data, pkey.size);
1750
1803
 
1753
1806
            PyObject *keyObj;
1754
1807
            int type = _DB_get_type(self);
1755
1808
            if (type == DB_RECNO || type == DB_QUEUE)
1756
 
                keyObj = PyInt_FromLong(*(int *)key.data);
 
1809
                keyObj = NUMBER_FromLong(*(int *)key.data);
1757
1810
            else
1758
1811
                keyObj = Build_PyString(key.data, key.size);
1759
1812
#if (PY_VERSION_HEX >= 0x02040000)
1773
1826
        }
1774
1827
        Py_DECREF(dataObj);
1775
1828
        Py_DECREF(pkeyObj);
1776
 
        FREE_DBT(pkey);
 
1829
        FREE_DBT(pkey);
1777
1830
        FREE_DBT(data);
1778
1831
    }
1779
1832
    FREE_DBT(key);
1781
1834
    RETURN_IF_ERR();
1782
1835
    return retval;
1783
1836
}
1784
 
#endif
1785
1837
 
1786
1838
 
1787
1839
/* Return size of entry */
1816
1868
    err = self->db->get(self->db, txn, &key, &data, flags);
1817
1869
    MYDB_END_ALLOW_THREADS;
1818
1870
    if (err == DB_BUFFER_SMALL) {
1819
 
        retval = PyInt_FromLong((long)data.size);
 
1871
        retval = NUMBER_FromLong((long)data.size);
1820
1872
        err = 0;
1821
1873
    }
1822
1874
 
1840
1892
    DB_TXN *txn = NULL;
1841
1893
    static char* kwnames[] = { "key", "data", "txn", "flags", NULL };
1842
1894
 
1843
 
 
1844
1895
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|Oi:get_both", kwnames,
1845
1896
                                     &keyobj, &dataobj, &txnobj, &flags))
1846
1897
        return NULL;
1891
1942
 
1892
1943
 
1893
1944
static PyObject*
1894
 
DB_get_byteswapped(DBObject* self, PyObject* args)
 
1945
DB_get_byteswapped(DBObject* self)
1895
1946
{
1896
 
#if (DBVER >= 33)
1897
1947
    int err = 0;
1898
 
#endif
1899
1948
    int retval = -1;
1900
1949
 
1901
 
    if (!PyArg_ParseTuple(args,":get_byteswapped"))
1902
 
        return NULL;
1903
1950
    CHECK_DB_NOT_CLOSED(self);
1904
1951
 
1905
 
#if (DBVER >= 33)
1906
1952
    MYDB_BEGIN_ALLOW_THREADS;
1907
1953
    err = self->db->get_byteswapped(self->db, &retval);
1908
1954
    MYDB_END_ALLOW_THREADS;
1909
1955
    RETURN_IF_ERR();
1910
 
#else
1911
 
    MYDB_BEGIN_ALLOW_THREADS;
1912
 
    retval = self->db->get_byteswapped(self->db);
1913
 
    MYDB_END_ALLOW_THREADS;
1914
 
#endif
1915
 
    return PyInt_FromLong(retval);
 
1956
    return NUMBER_FromLong(retval);
1916
1957
}
1917
1958
 
1918
1959
 
1919
1960
static PyObject*
1920
 
DB_get_type(DBObject* self, PyObject* args)
 
1961
DB_get_type(DBObject* self)
1921
1962
{
1922
1963
    int type;
1923
1964
 
1924
 
    if (!PyArg_ParseTuple(args,":get_type"))
1925
 
        return NULL;
1926
1965
    CHECK_DB_NOT_CLOSED(self);
1927
1966
 
1928
1967
    type = _DB_get_type(self);
1929
1968
    if (type == -1)
1930
1969
        return NULL;
1931
 
    return PyInt_FromLong(type);
 
1970
    return NUMBER_FromLong(type);
1932
1971
}
1933
1972
 
1934
1973
 
2079
2118
    if (NULL == self->db) {
2080
2119
        PyObject *t = Py_BuildValue("(is)", 0,
2081
2120
                                "Cannot call open() twice for DB object");
2082
 
        PyErr_SetObject(DBError, t);
2083
 
        Py_DECREF(t);
 
2121
        if (t) {
 
2122
            PyErr_SetObject(DBError, t);
 
2123
            Py_DECREF(t);
 
2124
        }
2084
2125
        return NULL;
2085
2126
    }
2086
2127
 
2154
2195
    }
2155
2196
 
2156
2197
    if (flags & DB_APPEND)
2157
 
        retval = PyInt_FromLong(*((db_recno_t*)key.data));
 
2198
        retval = NUMBER_FromLong(*((db_recno_t*)key.data));
2158
2199
    else {
2159
2200
        retval = Py_None;
2160
2201
        Py_INCREF(retval);
2178
2219
        return NULL;
2179
2220
    CHECK_DB_NOT_CLOSED(self);
2180
2221
 
 
2222
    EXTRACT_FROM_DOUBLE_LINKED_LIST_MAYBE_NULL(self);
 
2223
 
 
2224
    MYDB_BEGIN_ALLOW_THREADS;
2181
2225
    err = self->db->remove(self->db, filename, database, flags);
 
2226
    MYDB_END_ALLOW_THREADS;
 
2227
 
2182
2228
    self->db = NULL;
2183
2229
    RETURN_IF_ERR();
2184
2230
    RETURN_NONE();
2208
2254
 
2209
2255
 
2210
2256
static PyObject*
 
2257
DB_get_private(DBObject* self)
 
2258
{
 
2259
    /* We can give out the private field even if db is closed */
 
2260
    Py_INCREF(self->private_obj);
 
2261
    return self->private_obj;
 
2262
}
 
2263
 
 
2264
static PyObject*
 
2265
DB_set_private(DBObject* self, PyObject* private_obj)
 
2266
{
 
2267
    /* We can set the private field even if db is closed */
 
2268
    Py_DECREF(self->private_obj);
 
2269
    Py_INCREF(private_obj);
 
2270
    self->private_obj = private_obj;
 
2271
    RETURN_NONE();
 
2272
}
 
2273
 
 
2274
 
 
2275
static PyObject*
2211
2276
DB_set_bt_minkey(DBObject* self, PyObject* args)
2212
2277
{
2213
2278
    int err, minkey;
2223
2288
    RETURN_NONE();
2224
2289
}
2225
2290
 
2226
 
#if (DBVER >= 33)
2227
 
static int 
 
2291
static int
2228
2292
_default_cmp(const DBT *leftKey,
2229
2293
             const DBT *rightKey)
2230
2294
{
2231
2295
  int res;
2232
2296
  int lsize = leftKey->size, rsize = rightKey->size;
2233
2297
 
2234
 
  res = memcmp(leftKey->data, rightKey->data, 
 
2298
  res = memcmp(leftKey->data, rightKey->data,
2235
2299
               lsize < rsize ? lsize : rsize);
2236
 
  
 
2300
 
2237
2301
  if (res == 0) {
2238
2302
      if (lsize < rsize) {
2239
2303
          res = -1;
2278
2342
            /* we're in a callback within the DB code, we can't raise */
2279
2343
            PyErr_Print();
2280
2344
            res = _default_cmp(leftKey, rightKey);
2281
 
        } else if (PyInt_Check(result)) {
2282
 
            res = PyInt_AsLong(result);
 
2345
        } else if (NUMBER_Check(result)) {
 
2346
            res = NUMBER_AsLong(result);
2283
2347
        } else {
2284
2348
            PyErr_SetString(PyExc_TypeError,
2285
2349
                            "DB_bt_compare callback MUST return an int.");
2287
2351
            PyErr_Print();
2288
2352
            res = _default_cmp(leftKey, rightKey);
2289
2353
        }
2290
 
    
 
2354
 
2291
2355
        Py_XDECREF(args);
2292
2356
        Py_XDECREF(result);
2293
2357
 
2297
2361
}
2298
2362
 
2299
2363
static PyObject*
2300
 
DB_set_bt_compare(DBObject* self, PyObject* args)
 
2364
DB_set_bt_compare(DBObject* self, PyObject* comparator)
2301
2365
{
2302
2366
    int err;
2303
 
    PyObject *comparator;
2304
2367
    PyObject *tuple, *result;
2305
2368
 
2306
 
    if (!PyArg_ParseTuple(args, "O:set_bt_compare", &comparator))
2307
 
        return NULL;
2308
 
 
2309
2369
    CHECK_DB_NOT_CLOSED(self);
2310
2370
 
2311
2371
    if (!PyCallable_Check(comparator)) {
2313
2373
        return NULL;
2314
2374
    }
2315
2375
 
2316
 
    /* 
 
2376
    /*
2317
2377
     * Perform a test call of the comparator function with two empty
2318
2378
     * string objects here.  verify that it returns an int (0).
2319
2379
     * err if not.
2323
2383
    Py_DECREF(tuple);
2324
2384
    if (result == NULL)
2325
2385
        return NULL;
2326
 
    if (!PyInt_Check(result)) {
 
2386
    if (!NUMBER_Check(result)) {
2327
2387
        PyErr_SetString(PyExc_TypeError,
2328
2388
                        "callback MUST return an int");
2329
2389
        return NULL;
2330
 
    } else if (PyInt_AsLong(result) != 0) {
 
2390
    } else if (NUMBER_AsLong(result) != 0) {
2331
2391
        PyErr_SetString(PyExc_TypeError,
2332
2392
                        "callback failed to return 0 on two empty strings");
2333
2393
        return NULL;
2362
2422
    RETURN_IF_ERR();
2363
2423
    RETURN_NONE();
2364
2424
}
2365
 
#endif /* DBVER >= 33 */
2366
2425
 
2367
2426
 
2368
2427
static PyObject*
2594
2653
    MYDB_BEGIN_ALLOW_THREADS;
2595
2654
#if (DBVER >= 43)
2596
2655
    err = self->db->stat(self->db, txn, &sp, flags);
2597
 
#elif (DBVER >= 33)
 
2656
#else
2598
2657
    err = self->db->stat(self->db, &sp, flags);
2599
 
#else
2600
 
    err = self->db->stat(self->db, &sp, NULL, flags);
2601
2658
#endif
2602
2659
    MYDB_END_ALLOW_THREADS;
2603
2660
    RETURN_IF_ERR();
2674
2731
        MAKE_QUEUE_ENTRY(nkeys);
2675
2732
        MAKE_QUEUE_ENTRY(ndata);
2676
2733
        MAKE_QUEUE_ENTRY(pagesize);
2677
 
#if (DBVER > 40)
 
2734
#if (DBVER >= 41)
2678
2735
        MAKE_QUEUE_ENTRY(extentsize);
2679
2736
#endif
2680
2737
        MAKE_QUEUE_ENTRY(pages);
2720
2777
}
2721
2778
 
2722
2779
 
2723
 
#if (DBVER >= 33)
2724
2780
static PyObject*
2725
2781
DB_truncate(DBObject* self, PyObject* args, PyObject* kwargs)
2726
2782
{
2741
2797
    err = self->db->truncate(self->db, txn, &count, flags);
2742
2798
    MYDB_END_ALLOW_THREADS;
2743
2799
    RETURN_IF_ERR();
2744
 
    return PyInt_FromLong(count);
 
2800
    return NUMBER_FromLong(count);
2745
2801
}
2746
 
#endif
2747
2802
 
2748
2803
 
2749
2804
static PyObject*
2821
2876
        ++oldValue;
2822
2877
    self->moduleFlags.getReturnsNone = (flags >= 1);
2823
2878
    self->moduleFlags.cursorSetReturnsNone = (flags >= 2);
2824
 
    return PyInt_FromLong(oldValue);
 
2879
    return NUMBER_FromLong(oldValue);
2825
2880
}
2826
2881
 
2827
2882
#if (DBVER >= 41)
2861
2916
 
2862
2917
    if (self->db == NULL) {
2863
2918
        PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed");
2864
 
        PyErr_SetObject(DBError, t);
2865
 
        Py_DECREF(t);
 
2919
        if (t) {
 
2920
            PyErr_SetObject(DBError, t);
 
2921
            Py_DECREF(t);
 
2922
        }
2866
2923
        return -1;
2867
2924
    }
2868
2925
 
2875
2932
redo_stat_for_length:
2876
2933
#if (DBVER >= 43)
2877
2934
    err = self->db->stat(self->db, /*txnid*/ NULL, &sp, flags);
2878
 
#elif (DBVER >= 33)
 
2935
#else
2879
2936
    err = self->db->stat(self->db, &sp, flags);
2880
 
#else
2881
 
    err = self->db->stat(self->db, &sp, NULL, flags);
2882
2937
#endif
2883
2938
 
2884
2939
    /* All the stat structures have matching fields upto the ndata field,
2953
3008
 
2954
3009
    if (self->db == NULL) {
2955
3010
        PyObject *t = Py_BuildValue("(is)", 0, "DB object has been closed");
2956
 
        PyErr_SetObject(DBError, t);
2957
 
        Py_DECREF(t);
 
3011
        if (t) {
 
3012
            PyErr_SetObject(DBError, t);
 
3013
            Py_DECREF(t);
 
3014
        }
2958
3015
        return -1;
2959
3016
    }
2960
3017
 
2989
3046
 
2990
3047
 
2991
3048
static PyObject*
2992
 
DB_has_key(DBObject* self, PyObject* args)
 
3049
DB_has_key(DBObject* self, PyObject* args, PyObject* kwargs)
2993
3050
{
2994
3051
    int err;
2995
3052
    PyObject* keyobj;
2996
3053
    DBT key, data;
2997
3054
    PyObject* txnobj = NULL;
2998
3055
    DB_TXN *txn = NULL;
 
3056
    static char* kwnames[] = {"key","txn", NULL};
2999
3057
 
3000
 
    if (!PyArg_ParseTuple(args,"O|O:has_key", &keyobj, &txnobj))
 
3058
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:has_key", kwnames,
 
3059
                &keyobj, &txnobj))
3001
3060
        return NULL;
 
3061
 
3002
3062
    CHECK_DB_NOT_CLOSED(self);
3003
3063
    if (!make_key_dbt(self, keyobj, &key, NULL))
3004
3064
        return NULL;
3020
3080
    FREE_DBT(key);
3021
3081
 
3022
3082
    if (err == DB_BUFFER_SMALL || err == 0) {
3023
 
        return PyInt_FromLong(1);
 
3083
        return NUMBER_FromLong(1);
3024
3084
    } else if (err == DB_NOTFOUND || err == DB_KEYEMPTY) {
3025
 
        return PyInt_FromLong(0);
 
3085
        return NUMBER_FromLong(0);
3026
3086
    }
3027
3087
 
3028
3088
    makeDBError(err);
3085
3145
                break;
3086
3146
            case DB_RECNO:
3087
3147
            case DB_QUEUE:
3088
 
                item = PyInt_FromLong(*((db_recno_t*)key.data));
 
3148
                item = NUMBER_FromLong(*((db_recno_t*)key.data));
3089
3149
                break;
3090
3150
            }
3091
3151
            break;
3117
3177
            list = NULL;
3118
3178
            goto done;
3119
3179
        }
3120
 
        PyList_Append(list, item);
 
3180
        if (PyList_Append(list, item)) {
 
3181
            Py_DECREF(list);
 
3182
            Py_DECREF(item);
 
3183
            list = NULL;
 
3184
            goto done;
 
3185
        }
3121
3186
        Py_DECREF(item);
3122
3187
    }
3123
3188
 
3202
3267
}
3203
3268
 
3204
3269
static PyObject*
3205
 
DBC_close(DBCursorObject* self, PyObject* args)
 
3270
DBC_close(DBCursorObject* self)
3206
3271
{
3207
 
    if (!PyArg_ParseTuple(args, ":close"))
3208
 
        return NULL;
3209
 
 
3210
3272
    return DBC_close_internal(self);
3211
3273
}
3212
3274
 
3228
3290
    MYDB_END_ALLOW_THREADS;
3229
3291
    RETURN_IF_ERR();
3230
3292
 
3231
 
    return PyInt_FromLong(count);
 
3293
    return NUMBER_FromLong(count);
3232
3294
}
3233
3295
 
3234
3296
 
3305
3367
    {
3306
3368
        PyErr_Clear();
3307
3369
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi|ii:get",
3308
 
                                         &kwnames[1], 
 
3370
                                         &kwnames[1],
3309
3371
                                         &keyobj, &flags, &dlen, &doff))
3310
3372
        {
3311
3373
            PyErr_Clear();
3361
3423
    return retval;
3362
3424
}
3363
3425
 
3364
 
#if (DBVER >= 33)
3365
3426
static PyObject*
3366
3427
DBC_pget(DBCursorObject* self, PyObject* args, PyObject *kwargs)
3367
3428
{
3427
3488
 
3428
3489
        if (self->mydb->primaryDBType == DB_RECNO ||
3429
3490
            self->mydb->primaryDBType == DB_QUEUE)
3430
 
            pkeyObj = PyInt_FromLong(*(int *)pkey.data);
 
3491
            pkeyObj = NUMBER_FromLong(*(int *)pkey.data);
3431
3492
        else
3432
3493
            pkeyObj = Build_PyString(pkey.data, pkey.size);
3433
3494
 
3436
3497
            PyObject *keyObj;
3437
3498
            int type = _DB_get_type(self->mydb);
3438
3499
            if (type == DB_RECNO || type == DB_QUEUE)
3439
 
                keyObj = PyInt_FromLong(*(int *)key.data);
 
3500
                keyObj = NUMBER_FromLong(*(int *)key.data);
3440
3501
            else
3441
3502
                keyObj = Build_PyString(key.data, key.size);
3442
3503
#if (PY_VERSION_HEX >= 0x02040000)
3466
3527
    }
3467
3528
    return retval;
3468
3529
}
3469
 
#endif
3470
3530
 
3471
3531
 
3472
3532
static PyObject*
3473
 
DBC_get_recno(DBCursorObject* self, PyObject* args)
 
3533
DBC_get_recno(DBCursorObject* self)
3474
3534
{
3475
3535
    int err;
3476
3536
    db_recno_t recno;
3477
3537
    DBT key;
3478
3538
    DBT data;
3479
3539
 
3480
 
    if (!PyArg_ParseTuple(args, ":get_recno"))
3481
 
        return NULL;
3482
 
 
3483
3540
    CHECK_CURSOR_NOT_CLOSED(self);
3484
3541
 
3485
3542
    CLEAR_DBT(key);
3491
3548
    RETURN_IF_ERR();
3492
3549
 
3493
3550
    recno = *((db_recno_t*)data.data);
3494
 
    return PyInt_FromLong(recno);
 
3551
    return NUMBER_FromLong(recno);
3495
3552
}
3496
3553
 
3497
3554
 
3741
3798
 
3742
3799
/* Return size of entry */
3743
3800
static PyObject*
3744
 
DBC_get_current_size(DBCursorObject* self, PyObject* args)
 
3801
DBC_get_current_size(DBCursorObject* self)
3745
3802
{
3746
3803
    int err, flags=DB_CURRENT;
3747
3804
    PyObject* retval = NULL;
3748
3805
    DBT key, data;
3749
3806
 
3750
 
    if (!PyArg_ParseTuple(args, ":get_current_size"))
3751
 
        return NULL;
3752
3807
    CHECK_CURSOR_NOT_CLOSED(self);
3753
3808
    CLEAR_DBT(key);
3754
3809
    CLEAR_DBT(data);
3762
3817
    MYDB_END_ALLOW_THREADS;
3763
3818
    if (err == DB_BUFFER_SMALL || !err) {
3764
3819
        /* DB_BUFFER_SMALL means positive size, !err means zero length value */
3765
 
        retval = PyInt_FromLong((long)data.size);
 
3820
        retval = NUMBER_FromLong((long)data.size);
3766
3821
        err = 0;
3767
3822
    }
3768
3823
 
3926
3981
          dummy=DB_close_internal(self->children_dbs,0);
3927
3982
          Py_XDECREF(dummy);
3928
3983
        }
 
3984
    }
3929
3985
 
 
3986
    self->closed = 1;
 
3987
    if (self->db_env) {
3930
3988
        MYDB_BEGIN_ALLOW_THREADS;
3931
3989
        err = self->db_env->close(self->db_env, flags);
3932
3990
        MYDB_END_ALLOW_THREADS;
3933
3991
        /* after calling DBEnv->close, regardless of error, this DBEnv
3934
3992
         * may not be accessed again (Berkeley DB docs). */
3935
 
        self->closed = 1;
3936
3993
        self->db_env = NULL;
3937
3994
        RETURN_IF_ERR();
3938
3995
    }
4066
4123
}
4067
4124
#endif /* DBVER >= 41 */
4068
4125
 
4069
 
#if (DBVER >= 40)
4070
4126
static PyObject*
4071
4127
DBEnv_set_timeout(DBEnvObject* self, PyObject* args, PyObject* kwargs)
4072
4128
{
4087
4143
    RETURN_IF_ERR();
4088
4144
    RETURN_NONE();
4089
4145
}
4090
 
#endif /* DBVER >= 40 */
4091
4146
 
4092
4147
static PyObject*
4093
4148
DBEnv_set_shm_key(DBEnvObject* self, PyObject* args)
4230
4285
 
4231
4286
#if (DBVER >= 42)
4232
4287
static PyObject*
4233
 
DBEnv_get_lg_max(DBEnvObject* self, PyObject* args)
 
4288
DBEnv_get_lg_max(DBEnvObject* self)
4234
4289
{
4235
4290
    int err;
4236
4291
    u_int32_t lg_max;
4237
4292
 
4238
 
    if (!PyArg_ParseTuple(args, ":get_lg_max"))
4239
 
        return NULL;
4240
4293
    CHECK_ENV_NOT_CLOSED(self);
4241
4294
 
4242
4295
    MYDB_BEGIN_ALLOW_THREADS;
4243
4296
    err = self->db_env->get_lg_max(self->db_env, &lg_max);
4244
4297
    MYDB_END_ALLOW_THREADS;
4245
4298
    RETURN_IF_ERR();
4246
 
    return PyInt_FromLong(lg_max);
 
4299
    return NUMBER_FromLong(lg_max);
4247
4300
}
4248
4301
#endif
4249
4302
 
4250
4303
 
4251
 
#if (DBVER >= 33)
4252
4304
static PyObject*
4253
4305
DBEnv_set_lg_regionmax(DBEnvObject* self, PyObject* args)
4254
4306
{
4264
4316
    RETURN_IF_ERR();
4265
4317
    RETURN_NONE();
4266
4318
}
4267
 
#endif
4268
4319
 
4269
4320
 
4270
4321
static PyObject*
4390
4441
}
4391
4442
 
4392
4443
 
4393
 
#if (DBVER >= 40)
4394
4444
static PyObject*
4395
 
DBEnv_txn_recover(DBEnvObject* self, PyObject* args)
 
4445
DBEnv_txn_recover(DBEnvObject* self)
4396
4446
{
4397
4447
    int flags = DB_FIRST;
4398
4448
    int err, i;
4402
4452
    DB_PREPLIST preplist[PREPLIST_LEN];
4403
4453
    long retp;
4404
4454
 
4405
 
    if (!PyArg_ParseTuple(args, ":txn_recover"))
4406
 
        return NULL;
4407
 
 
4408
4455
    CHECK_ENV_NOT_CLOSED(self);
4409
4456
 
4410
4457
    list=PyList_New(0);
4466
4513
    }
4467
4514
    return list;
4468
4515
}
4469
 
#endif
4470
4516
 
4471
4517
static PyObject*
4472
4518
DBEnv_txn_begin(DBEnvObject* self, PyObject* args, PyObject* kwargs)
4498
4544
    CHECK_ENV_NOT_CLOSED(self);
4499
4545
 
4500
4546
    MYDB_BEGIN_ALLOW_THREADS;
4501
 
#if (DBVER >= 40)
4502
4547
    err = self->db_env->txn_checkpoint(self->db_env, kbyte, min, flags);
4503
 
#else
4504
 
    err = txn_checkpoint(self->db_env, kbyte, min, flags);
4505
 
#endif
4506
4548
    MYDB_END_ALLOW_THREADS;
4507
4549
    RETURN_IF_ERR();
4508
4550
    RETURN_NONE();
4552
4594
    CHECK_ENV_NOT_CLOSED(self);
4553
4595
 
4554
4596
    MYDB_BEGIN_ALLOW_THREADS;
4555
 
#if (DBVER >= 40)
4556
4597
    err = self->db_env->lock_detect(self->db_env, flags, atype, &aborted);
4557
 
#else
4558
 
    err = lock_detect(self->db_env, flags, atype, &aborted);
4559
 
#endif
4560
4598
    MYDB_END_ALLOW_THREADS;
4561
4599
    RETURN_IF_ERR();
4562
 
    return PyInt_FromLong(aborted);
 
4600
    return NUMBER_FromLong(aborted);
4563
4601
}
4564
4602
 
4565
4603
 
4583
4621
 
4584
4622
 
4585
4623
static PyObject*
4586
 
DBEnv_lock_id(DBEnvObject* self, PyObject* args)
 
4624
DBEnv_lock_id(DBEnvObject* self)
4587
4625
{
4588
4626
    int err;
4589
4627
    u_int32_t theID;
4590
4628
 
4591
 
    if (!PyArg_ParseTuple(args, ":lock_id"))
4592
 
        return NULL;
4593
 
 
4594
4629
    CHECK_ENV_NOT_CLOSED(self);
4595
4630
    MYDB_BEGIN_ALLOW_THREADS;
4596
 
#if (DBVER >= 40)
4597
4631
    err = self->db_env->lock_id(self->db_env, &theID);
4598
 
#else
4599
 
    err = lock_id(self->db_env, &theID);
4600
 
#endif
4601
4632
    MYDB_END_ALLOW_THREADS;
4602
4633
    RETURN_IF_ERR();
4603
4634
 
4604
 
    return PyInt_FromLong((long)theID);
 
4635
    return NUMBER_FromLong((long)theID);
4605
4636
}
4606
4637
 
4607
 
#if (DBVER >= 40)
4608
4638
static PyObject*
4609
4639
DBEnv_lock_id_free(DBEnvObject* self, PyObject* args)
4610
4640
{
4621
4651
    RETURN_IF_ERR();
4622
4652
    RETURN_NONE();
4623
4653
}
4624
 
#endif
4625
4654
 
4626
4655
static PyObject*
4627
4656
DBEnv_lock_put(DBEnvObject* self, PyObject* args)
4634
4663
 
4635
4664
    CHECK_ENV_NOT_CLOSED(self);
4636
4665
    MYDB_BEGIN_ALLOW_THREADS;
4637
 
#if (DBVER >= 40)
4638
4666
    err = self->db_env->lock_put(self->db_env, &dblockobj->lock);
4639
 
#else
4640
 
    err = lock_put(self->db_env, &dblockobj->lock);
4641
 
#endif
4642
4667
    MYDB_END_ALLOW_THREADS;
4643
4668
    RETURN_IF_ERR();
4644
4669
    RETURN_NONE();
4666
4691
}
4667
4692
#endif /* DBVER >= 4.4 */
4668
4693
 
4669
 
#if (DBVER >= 40)
4670
4694
static PyObject*
4671
4695
DBEnv_log_stat(DBEnvObject* self, PyObject* args)
4672
4696
{
4702
4726
    MAKE_ENTRY(lg_size);
4703
4727
    MAKE_ENTRY(record);
4704
4728
#endif
4705
 
#if (DBVER <= 40)
 
4729
#if (DBVER < 41)
4706
4730
    MAKE_ENTRY(lg_max);
4707
4731
#endif
4708
4732
    MAKE_ENTRY(w_mbytes);
4729
4753
    free(statp);
4730
4754
    return d;
4731
4755
} /* DBEnv_log_stat */
4732
 
#endif /* DBVER >= 4.0 for log_stat method */
4733
4756
 
4734
4757
 
4735
4758
static PyObject*
4745
4768
    CHECK_ENV_NOT_CLOSED(self);
4746
4769
 
4747
4770
    MYDB_BEGIN_ALLOW_THREADS;
4748
 
#if (DBVER >= 40)
4749
4771
    err = self->db_env->lock_stat(self->db_env, &sp, flags);
4750
 
#else
4751
 
#if (DBVER >= 33)
4752
 
    err = lock_stat(self->db_env, &sp);
4753
 
#else
4754
 
    err = lock_stat(self->db_env, &sp, NULL);
4755
 
#endif
4756
 
#endif
4757
4772
    MYDB_END_ALLOW_THREADS;
4758
4773
    RETURN_IF_ERR();
4759
4774
 
4801
4816
    MAKE_ENTRY(locktimeout);
4802
4817
    MAKE_ENTRY(txntimeout);
4803
4818
#endif
4804
 
#if (DBVER >= 40)
4805
4819
    MAKE_ENTRY(nlocktimeouts);
4806
4820
    MAKE_ENTRY(ntxntimeouts);
4807
 
#endif
4808
4821
#if (DBVER >= 46)
4809
4822
    MAKE_ENTRY(objs_wait);
4810
4823
    MAKE_ENTRY(objs_nowait);
4828
4841
    return d;
4829
4842
}
4830
4843
 
4831
 
#if (DBVER >= 40)
4832
4844
static PyObject*
4833
 
DBEnv_log_flush(DBEnvObject* self, PyObject* args)
 
4845
DBEnv_log_flush(DBEnvObject* self)
4834
4846
{
4835
4847
    int err;
4836
4848
 
4837
 
    if (!PyArg_ParseTuple(args, ":log_flush"))
4838
 
        return NULL;
4839
4849
    CHECK_ENV_NOT_CLOSED(self);
4840
4850
 
4841
4851
    MYDB_BEGIN_ALLOW_THREADS
4845
4855
    RETURN_IF_ERR();
4846
4856
    RETURN_NONE();
4847
4857
}
4848
 
#endif
4849
4858
 
4850
4859
static PyObject*
4851
4860
DBEnv_log_archive(DBEnvObject* self, PyObject* args)
4861
4870
 
4862
4871
    CHECK_ENV_NOT_CLOSED(self);
4863
4872
    MYDB_BEGIN_ALLOW_THREADS;
4864
 
#if (DBVER >= 40)
4865
4873
    err = self->db_env->log_archive(self->db_env, &log_list, flags);
4866
 
#elif (DBVER == 33)
4867
 
    err = log_archive(self->db_env, &log_list, flags);
4868
 
#else
4869
 
    err = log_archive(self->db_env, &log_list, flags, NULL);
4870
 
#endif
4871
4874
    MYDB_END_ALLOW_THREADS;
4872
4875
    RETURN_IF_ERR();
4873
4876
 
4887
4890
                list = NULL;
4888
4891
                break;
4889
4892
            }
4890
 
            PyList_Append(list, item);
 
4893
            if (PyList_Append(list, item)) {
 
4894
                Py_DECREF(list);
 
4895
                list = NULL;
 
4896
                Py_DECREF(item);
 
4897
                break;
 
4898
            }
4891
4899
            Py_DECREF(item);
4892
4900
        }
4893
4901
        free(log_list_start);
4909
4917
    CHECK_ENV_NOT_CLOSED(self);
4910
4918
 
4911
4919
    MYDB_BEGIN_ALLOW_THREADS;
4912
 
#if (DBVER >= 40)
4913
4920
    err = self->db_env->txn_stat(self->db_env, &sp, flags);
4914
 
#elif (DBVER == 33)
4915
 
    err = txn_stat(self->db_env, &sp);
4916
 
#else
4917
 
    err = txn_stat(self->db_env, &sp, NULL);
4918
 
#endif
4919
4921
    MYDB_END_ALLOW_THREADS;
4920
4922
    RETURN_IF_ERR();
4921
4923
 
4930
4932
#define MAKE_TIME_T_ENTRY(name) _addTimeTToDict(d, #name, sp->st_##name)
4931
4933
#define MAKE_DB_LSN_ENTRY(name) _addDB_lsnToDict(d, #name, sp->st_##name)
4932
4934
 
4933
 
#if (DBVER >= 40)
4934
4935
    MAKE_DB_LSN_ENTRY(last_ckp);
4935
 
#endif
4936
4936
    MAKE_TIME_T_ENTRY(time_ckp);
4937
4937
    MAKE_ENTRY(last_txnid);
4938
4938
    MAKE_ENTRY(maxtxns);
4945
4945
    MAKE_ENTRY(nbegins);
4946
4946
    MAKE_ENTRY(naborts);
4947
4947
    MAKE_ENTRY(ncommits);
4948
 
#if (DBVER >= 40)
4949
4948
    MAKE_ENTRY(nrestores);
4950
 
#endif
4951
4949
    MAKE_ENTRY(regsize);
4952
4950
    MAKE_ENTRY(region_wait);
4953
4951
    MAKE_ENTRY(region_nowait);
4976
4974
        ++oldValue;
4977
4975
    self->moduleFlags.getReturnsNone = (flags >= 1);
4978
4976
    self->moduleFlags.cursorSetReturnsNone = (flags >= 2);
4979
 
    return PyInt_FromLong(oldValue);
4980
 
}
4981
 
 
4982
 
#if (DBVER >= 40)
 
4977
    return NUMBER_FromLong(oldValue);
 
4978
}
 
4979
 
 
4980
static PyObject*
 
4981
DBEnv_get_private(DBEnvObject* self)
 
4982
{
 
4983
    /* We can give out the private field even if dbenv is closed */
 
4984
    Py_INCREF(self->private_obj);
 
4985
    return self->private_obj;
 
4986
}
 
4987
 
 
4988
static PyObject*
 
4989
DBEnv_set_private(DBEnvObject* self, PyObject* private_obj)
 
4990
{
 
4991
    /* We can set the private field even if dbenv is closed */
 
4992
    Py_DECREF(self->private_obj);
 
4993
    Py_INCREF(private_obj);
 
4994
    self->private_obj = private_obj;
 
4995
    RETURN_NONE();
 
4996
}
 
4997
 
 
4998
 
4983
4999
static PyObject*
4984
5000
DBEnv_set_rpc_server(DBEnvObject* self, PyObject* args, PyObject* kwargs)
4985
5001
{
5001
5017
    RETURN_IF_ERR();
5002
5018
    RETURN_NONE();
5003
5019
}
5004
 
#endif
5005
5020
 
5006
 
#if (DBVER >= 40)
5007
5021
static PyObject*
5008
5022
DBEnv_set_verbose(DBEnvObject* self, PyObject* args)
5009
5023
{
5040
5054
    return PyBool_FromLong(verbose);
5041
5055
}
5042
5056
#endif
5043
 
#endif
5044
5057
 
5045
5058
#if (DBVER >= 45)
5046
5059
static void
5075
5088
 
5076
5089
#if (DBVER >= 45)
5077
5090
static PyObject*
5078
 
DBEnv_set_event_notify(DBEnvObject* self, PyObject* args)
 
5091
DBEnv_set_event_notify(DBEnvObject* self, PyObject* notifyFunc)
5079
5092
{
5080
5093
    int err;
5081
 
    PyObject *notifyFunc;
5082
 
 
5083
 
    if (!PyArg_ParseTuple(args, "O:set_event_notify", &notifyFunc)) {
5084
 
            return NULL;
5085
 
    }
5086
5094
 
5087
5095
    CHECK_ENV_NOT_CLOSED(self);
5088
5096
 
5095
5103
    Py_INCREF(notifyFunc);
5096
5104
    self->event_notifyCallback = notifyFunc;
5097
5105
 
 
5106
    /* This is to workaround a problem with un-initialized threads (see
 
5107
       comment in DB_associate) */
 
5108
#ifdef WITH_THREAD
 
5109
    PyEval_InitThreads();
 
5110
#endif
 
5111
 
5098
5112
    MYDB_BEGIN_ALLOW_THREADS;
5099
5113
    err = self->db_env->set_event_notify(self->db_env, _dbenv_event_notifyCallback);
5100
5114
    MYDB_END_ALLOW_THREADS;
5113
5127
/* --------------------------------------------------------------------- */
5114
5128
/* REPLICATION METHODS: Base Replication */
5115
5129
 
 
5130
 
 
5131
static PyObject*
 
5132
DBEnv_rep_process_message(DBEnvObject* self, PyObject* args)
 
5133
{
 
5134
    int err;
 
5135
    PyObject *control_py, *rec_py;
 
5136
    DBT control, rec;
 
5137
    int envid;
 
5138
#if (DBVER >= 42)
 
5139
    DB_LSN lsn;
 
5140
#endif
 
5141
 
 
5142
    if (!PyArg_ParseTuple(args, "OOi:rep_process_message", &control_py,
 
5143
                &rec_py, &envid))
 
5144
        return NULL;
 
5145
    CHECK_ENV_NOT_CLOSED(self);
 
5146
 
 
5147
    if (!make_dbt(control_py, &control))
 
5148
        return NULL;
 
5149
    if (!make_dbt(rec_py, &rec))
 
5150
        return NULL;
 
5151
 
 
5152
    MYDB_BEGIN_ALLOW_THREADS;
 
5153
#if (DBVER >= 46)
 
5154
    err = self->db_env->rep_process_message(self->db_env, &control, &rec,
 
5155
            envid, &lsn);
 
5156
#else
 
5157
#if (DBVER >= 42)
 
5158
    err = self->db_env->rep_process_message(self->db_env, &control, &rec,
 
5159
            &envid, &lsn);
 
5160
#else
 
5161
    err = self->db_env->rep_process_message(self->db_env, &control, &rec,
 
5162
            &envid);
 
5163
#endif
 
5164
#endif
 
5165
    MYDB_END_ALLOW_THREADS;
 
5166
    switch (err) {
 
5167
        case DB_REP_NEWMASTER :
 
5168
          return Py_BuildValue("(iO)", envid, Py_None);
 
5169
          break;
 
5170
 
 
5171
        case DB_REP_DUPMASTER :
 
5172
        case DB_REP_HOLDELECTION :
 
5173
#if (DBVER >= 44)
 
5174
        case DB_REP_IGNORE :
 
5175
        case DB_REP_JOIN_FAILURE :
 
5176
#endif
 
5177
            return Py_BuildValue("(iO)", err, Py_None);
 
5178
            break;
 
5179
        case DB_REP_NEWSITE :
 
5180
            {
 
5181
                PyObject *tmp, *r;
 
5182
 
 
5183
                if (!(tmp = PyBytes_FromStringAndSize(rec.data, rec.size))) {
 
5184
                    return NULL;
 
5185
                }
 
5186
 
 
5187
                r = Py_BuildValue("(iO)", err, tmp);
 
5188
                Py_DECREF(tmp);
 
5189
                return r;
 
5190
                break;
 
5191
            }
 
5192
#if (DBVER >= 42)
 
5193
        case DB_REP_NOTPERM :
 
5194
        case DB_REP_ISPERM :
 
5195
            return Py_BuildValue("(i(ll))", err, lsn.file, lsn.offset);
 
5196
            break;
 
5197
#endif
 
5198
    }
 
5199
    RETURN_IF_ERR();
 
5200
    return Py_BuildValue("(OO)", Py_None, Py_None);
 
5201
}
 
5202
 
 
5203
static int
 
5204
_DBEnv_rep_transportCallback(DB_ENV* db_env, const DBT* control, const DBT* rec,
 
5205
        const DB_LSN *lsn, int envid, u_int32_t flags)
 
5206
{
 
5207
    DBEnvObject *dbenv;
 
5208
    PyObject* rep_transport;
 
5209
    PyObject* args;
 
5210
    PyObject *a, *b;
 
5211
    PyObject* result = NULL;
 
5212
    int ret=0;
 
5213
 
 
5214
    MYDB_BEGIN_BLOCK_THREADS;
 
5215
    dbenv = (DBEnvObject *)db_env->app_private;
 
5216
    rep_transport = dbenv->rep_transport;
 
5217
 
 
5218
    /*
 
5219
    ** The errors in 'a' or 'b' are detected in "Py_BuildValue".
 
5220
    */
 
5221
    a = PyBytes_FromStringAndSize(control->data, control->size);
 
5222
    b = PyBytes_FromStringAndSize(rec->data, rec->size);
 
5223
 
 
5224
    args = Py_BuildValue(
 
5225
#if (PY_VERSION_HEX >= 0x02040000)
 
5226
            "(OOO(ll)iI)",
 
5227
#else
 
5228
            "(OOO(ll)ii)",
 
5229
#endif
 
5230
            dbenv,
 
5231
            a, b,
 
5232
            lsn->file, lsn->offset, envid, flags);
 
5233
    if (args) {
 
5234
        result = PyEval_CallObject(rep_transport, args);
 
5235
    }
 
5236
 
 
5237
    if ((!args) || (!result)) {
 
5238
        PyErr_Print();
 
5239
        ret = -1;
 
5240
    }
 
5241
    Py_XDECREF(a);
 
5242
    Py_XDECREF(b);
 
5243
    Py_XDECREF(args);
 
5244
    Py_XDECREF(result);
 
5245
    MYDB_END_BLOCK_THREADS;
 
5246
    return ret;
 
5247
}
 
5248
 
 
5249
#if (DBVER <= 41)
 
5250
static int
 
5251
_DBEnv_rep_transportCallbackOLD(DB_ENV* db_env, const DBT* control, const DBT* rec,
 
5252
        int envid, u_int32_t flags)
 
5253
{
 
5254
    DB_LSN lsn;
 
5255
 
 
5256
    lsn.file = -1;  /* Dummy values */
 
5257
    lsn.offset = -1;
 
5258
    return _DBEnv_rep_transportCallback(db_env, control, rec, &lsn, envid,
 
5259
            flags);
 
5260
}
 
5261
#endif
 
5262
 
 
5263
static PyObject*
 
5264
DBEnv_rep_set_transport(DBEnvObject* self, PyObject* args)
 
5265
{
 
5266
    int err;
 
5267
    int envid;
 
5268
    PyObject *rep_transport;
 
5269
 
 
5270
    if (!PyArg_ParseTuple(args, "iO:rep_set_transport", &envid, &rep_transport))
 
5271
        return NULL;
 
5272
    CHECK_ENV_NOT_CLOSED(self);
 
5273
    if (!PyCallable_Check(rep_transport)) {
 
5274
        makeTypeError("Callable", rep_transport);
 
5275
        return NULL;
 
5276
    }
 
5277
 
 
5278
    MYDB_BEGIN_ALLOW_THREADS;
 
5279
#if (DBVER >=45)
 
5280
    err = self->db_env->rep_set_transport(self->db_env, envid,
 
5281
            &_DBEnv_rep_transportCallback);
 
5282
#else
 
5283
#if (DBVER >= 42)
 
5284
    err = self->db_env->set_rep_transport(self->db_env, envid,
 
5285
            &_DBEnv_rep_transportCallback);
 
5286
#else
 
5287
    err = self->db_env->set_rep_transport(self->db_env, envid,
 
5288
            &_DBEnv_rep_transportCallbackOLD);
 
5289
#endif
 
5290
#endif
 
5291
    MYDB_END_ALLOW_THREADS;
 
5292
    RETURN_IF_ERR();
 
5293
 
 
5294
    Py_DECREF(self->rep_transport);
 
5295
    Py_INCREF(rep_transport);
 
5296
    self->rep_transport = rep_transport;
 
5297
    RETURN_NONE();
 
5298
}
 
5299
 
 
5300
#if (DBVER >= 47)
 
5301
static PyObject*
 
5302
DBEnv_rep_set_request(DBEnvObject* self, PyObject* args)
 
5303
{
 
5304
    int err;
 
5305
    unsigned int minimum, maximum;
 
5306
 
 
5307
    if (!PyArg_ParseTuple(args,"II:rep_set_request", &minimum, &maximum))
 
5308
        return NULL;
 
5309
    CHECK_ENV_NOT_CLOSED(self);
 
5310
 
 
5311
    MYDB_BEGIN_ALLOW_THREADS;
 
5312
    err = self->db_env->rep_set_request(self->db_env, minimum, maximum);
 
5313
    MYDB_END_ALLOW_THREADS;
 
5314
    RETURN_IF_ERR();
 
5315
    RETURN_NONE();
 
5316
}
 
5317
 
 
5318
static PyObject*
 
5319
DBEnv_rep_get_request(DBEnvObject* self)
 
5320
{
 
5321
    int err;
 
5322
    u_int32_t minimum, maximum;
 
5323
 
 
5324
    CHECK_ENV_NOT_CLOSED(self);
 
5325
    MYDB_BEGIN_ALLOW_THREADS;
 
5326
    err = self->db_env->rep_get_request(self->db_env, &minimum, &maximum);
 
5327
    MYDB_END_ALLOW_THREADS;
 
5328
    RETURN_IF_ERR();
 
5329
#if (PY_VERSION_HEX >= 0x02040000)
 
5330
    return Py_BuildValue("II", minimum, maximum);
 
5331
#else
 
5332
    return Py_BuildValue("ii", minimum, maximum);
 
5333
#endif
 
5334
}
 
5335
#endif
 
5336
 
 
5337
#if (DBVER >= 45)
 
5338
static PyObject*
 
5339
DBEnv_rep_set_limit(DBEnvObject* self, PyObject* args)
 
5340
{
 
5341
    int err;
 
5342
    int limit;
 
5343
 
 
5344
    if (!PyArg_ParseTuple(args,"i:rep_set_limit", &limit))
 
5345
        return NULL;
 
5346
    CHECK_ENV_NOT_CLOSED(self);
 
5347
 
 
5348
    MYDB_BEGIN_ALLOW_THREADS;
 
5349
    err = self->db_env->rep_set_limit(self->db_env, 0, limit);
 
5350
    MYDB_END_ALLOW_THREADS;
 
5351
    RETURN_IF_ERR();
 
5352
    RETURN_NONE();
 
5353
}
 
5354
 
 
5355
static PyObject*
 
5356
DBEnv_rep_get_limit(DBEnvObject* self)
 
5357
{
 
5358
    int err;
 
5359
    u_int32_t gbytes, bytes;
 
5360
 
 
5361
    CHECK_ENV_NOT_CLOSED(self);
 
5362
    MYDB_BEGIN_ALLOW_THREADS;
 
5363
    err = self->db_env->rep_get_limit(self->db_env, &gbytes, &bytes);
 
5364
    MYDB_END_ALLOW_THREADS;
 
5365
    RETURN_IF_ERR();
 
5366
    return NUMBER_FromLong(bytes);
 
5367
}
 
5368
#endif
 
5369
 
 
5370
#if (DBVER >= 44)
 
5371
static PyObject*
 
5372
DBEnv_rep_set_config(DBEnvObject* self, PyObject* args)
 
5373
{
 
5374
    int err;
 
5375
    int which;
 
5376
    int onoff;
 
5377
 
 
5378
    if (!PyArg_ParseTuple(args,"ii:rep_set_config", &which, &onoff))
 
5379
        return NULL;
 
5380
    CHECK_ENV_NOT_CLOSED(self);
 
5381
 
 
5382
    MYDB_BEGIN_ALLOW_THREADS;
 
5383
    err = self->db_env->rep_set_config(self->db_env, which, onoff);
 
5384
    MYDB_END_ALLOW_THREADS;
 
5385
    RETURN_IF_ERR();
 
5386
    RETURN_NONE();
 
5387
}
 
5388
 
 
5389
static PyObject*
 
5390
DBEnv_rep_get_config(DBEnvObject* self, PyObject* args)
 
5391
{
 
5392
    int err;
 
5393
    int which;
 
5394
    int onoff;
 
5395
 
 
5396
    if (!PyArg_ParseTuple(args, "i:rep_get_config", &which)) {
 
5397
        return NULL;
 
5398
    }
 
5399
    CHECK_ENV_NOT_CLOSED(self);
 
5400
    MYDB_BEGIN_ALLOW_THREADS;
 
5401
    err = self->db_env->rep_get_config(self->db_env, which, &onoff);
 
5402
    MYDB_END_ALLOW_THREADS;
 
5403
    RETURN_IF_ERR();
 
5404
    return PyBool_FromLong(onoff);
 
5405
}
 
5406
#endif
 
5407
 
 
5408
#if (DBVER >= 46)
 
5409
static PyObject*
 
5410
DBEnv_rep_elect(DBEnvObject* self, PyObject* args)
 
5411
{
 
5412
    int err;
 
5413
    u_int32_t nsites, nvotes;
 
5414
 
 
5415
    if (!PyArg_ParseTuple(args, "II:rep_elect", &nsites, &nvotes)) {
 
5416
        return NULL;
 
5417
    }
 
5418
    CHECK_ENV_NOT_CLOSED(self);
 
5419
    MYDB_BEGIN_ALLOW_THREADS;
 
5420
    err = self->db_env->rep_elect(self->db_env, nvotes, nvotes, 0);
 
5421
    MYDB_END_ALLOW_THREADS;
 
5422
    RETURN_IF_ERR();
 
5423
    RETURN_NONE();
 
5424
}
 
5425
#endif
 
5426
 
 
5427
static PyObject*
 
5428
DBEnv_rep_start(DBEnvObject* self, PyObject* args, PyObject* kwargs)
 
5429
{
 
5430
    int err;
 
5431
    PyObject *cdata_py = Py_None;
 
5432
    DBT cdata;
 
5433
    int flags;
 
5434
    static char* kwnames[] = {"flags","cdata", NULL};
 
5435
 
 
5436
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
5437
                "i|O:rep_start", kwnames, &flags, &cdata_py))
 
5438
    {
 
5439
            return NULL;
 
5440
    }
 
5441
    CHECK_ENV_NOT_CLOSED(self);
 
5442
 
 
5443
    if (!make_dbt(cdata_py, &cdata))
 
5444
        return NULL;
 
5445
 
 
5446
    MYDB_BEGIN_ALLOW_THREADS;
 
5447
    err = self->db_env->rep_start(self->db_env, cdata.size ? &cdata : NULL,
 
5448
            flags);
 
5449
    MYDB_END_ALLOW_THREADS;
 
5450
    RETURN_IF_ERR();
 
5451
    RETURN_NONE();
 
5452
}
 
5453
 
 
5454
#if (DBVER >= 44)
 
5455
static PyObject*
 
5456
DBEnv_rep_sync(DBEnvObject* self)
 
5457
{
 
5458
    int err;
 
5459
 
 
5460
    CHECK_ENV_NOT_CLOSED(self);
 
5461
    MYDB_BEGIN_ALLOW_THREADS;
 
5462
    err = self->db_env->rep_sync(self->db_env, 0);
 
5463
    MYDB_END_ALLOW_THREADS;
 
5464
    RETURN_IF_ERR();
 
5465
    RETURN_NONE();
 
5466
}
 
5467
#endif
 
5468
 
 
5469
 
5116
5470
#if (DBVER >= 45)
5117
5471
static PyObject*
5118
5472
DBEnv_rep_set_nsites(DBEnvObject* self, PyObject* args)
5132
5486
}
5133
5487
 
5134
5488
static PyObject*
5135
 
DBEnv_rep_get_nsites(DBEnvObject* self, PyObject* args)
 
5489
DBEnv_rep_get_nsites(DBEnvObject* self)
5136
5490
{
5137
5491
    int err;
5138
5492
#if (DBVER >= 47)
5141
5495
    int nsites;
5142
5496
#endif
5143
5497
 
5144
 
    if (!PyArg_ParseTuple(args, ":rep_get_nsites")) {
5145
 
        return NULL;
5146
 
    }
5147
5498
    CHECK_ENV_NOT_CLOSED(self);
5148
5499
    MYDB_BEGIN_ALLOW_THREADS;
5149
5500
    err = self->db_env->rep_get_nsites(self->db_env, &nsites);
5150
5501
    MYDB_END_ALLOW_THREADS;
5151
5502
    RETURN_IF_ERR();
5152
 
    return PyInt_FromLong(nsites);
 
5503
    return NUMBER_FromLong(nsites);
5153
5504
}
5154
5505
 
5155
5506
static PyObject*
5170
5521
}
5171
5522
 
5172
5523
static PyObject*
5173
 
DBEnv_rep_get_priority(DBEnvObject* self, PyObject* args)
 
5524
DBEnv_rep_get_priority(DBEnvObject* self)
5174
5525
{
5175
5526
    int err;
5176
5527
#if (DBVER >= 47)
5179
5530
    int priority;
5180
5531
#endif
5181
5532
 
5182
 
    if (!PyArg_ParseTuple(args, ":rep_get_priority")) {
5183
 
        return NULL;
5184
 
    }
5185
5533
    CHECK_ENV_NOT_CLOSED(self);
5186
5534
    MYDB_BEGIN_ALLOW_THREADS;
5187
5535
    err = self->db_env->rep_get_priority(self->db_env, &priority);
5188
5536
    MYDB_END_ALLOW_THREADS;
5189
5537
    RETURN_IF_ERR();
5190
 
    return PyInt_FromLong(priority);
 
5538
    return NUMBER_FromLong(priority);
5191
5539
}
5192
5540
 
5193
5541
static PyObject*
5222
5570
    err = self->db_env->rep_get_timeout(self->db_env, which, &timeout);
5223
5571
    MYDB_END_ALLOW_THREADS;
5224
5572
    RETURN_IF_ERR();
5225
 
    return PyInt_FromLong(timeout);
 
5573
    return NUMBER_FromLong(timeout);
5226
5574
}
5227
5575
#endif
5228
5576
 
5295
5643
    err = self->db_env->repmgr_add_remote_site(self->db_env, host, port, &eidp, flags);
5296
5644
    MYDB_END_ALLOW_THREADS;
5297
5645
    RETURN_IF_ERR();
5298
 
    return PyInt_FromLong(eidp);
 
5646
    return NUMBER_FromLong(eidp);
5299
5647
}
5300
5648
 
5301
5649
static PyObject*
5317
5665
}
5318
5666
 
5319
5667
static PyObject*
5320
 
DBEnv_repmgr_get_ack_policy(DBEnvObject* self, PyObject* args)
 
5668
DBEnv_repmgr_get_ack_policy(DBEnvObject* self)
5321
5669
{
5322
5670
    int err;
5323
5671
    int ack_policy;
5324
5672
 
5325
 
    if (!PyArg_ParseTuple(args, ":repmgr_get_ack_policy"))
5326
 
    {
5327
 
            return NULL;
5328
 
    }
5329
5673
    CHECK_ENV_NOT_CLOSED(self);
5330
5674
    MYDB_BEGIN_ALLOW_THREADS;
5331
5675
    err = self->db_env->repmgr_get_ack_policy(self->db_env, &ack_policy);
5332
5676
    MYDB_END_ALLOW_THREADS;
5333
5677
    RETURN_IF_ERR();
5334
 
    return PyInt_FromLong(ack_policy);
 
5678
    return NUMBER_FromLong(ack_policy);
5335
5679
}
5336
5680
 
5337
5681
static PyObject*
5338
 
DBEnv_repmgr_site_list(DBEnvObject* self, PyObject* args)
 
5682
DBEnv_repmgr_site_list(DBEnvObject* self)
5339
5683
{
5340
5684
    int err;
5341
5685
    unsigned int countp;
5342
5686
    DB_REPMGR_SITE *listp;
5343
5687
    PyObject *stats, *key, *tuple;
5344
5688
 
5345
 
    if (!PyArg_ParseTuple(args, ":repmgr_site_list"))
5346
 
    {
5347
 
        return NULL;
5348
 
    }
5349
5689
    CHECK_ENV_NOT_CLOSED(self);
5350
5690
    MYDB_BEGIN_ALLOW_THREADS;
5351
5691
    err = self->db_env->repmgr_site_list(self->db_env, &countp, &listp);
5359
5699
    }
5360
5700
 
5361
5701
    for(;countp--;) {
5362
 
        key=PyInt_FromLong(listp[countp].eid);
 
5702
        key=NUMBER_FromLong(listp[countp].eid);
5363
5703
        if(!key) {
5364
5704
            Py_DECREF(stats);
5365
5705
            free(listp);
5524
5864
        PyObject *t =  Py_BuildValue("(is)", 0, "DBTxn must not be used "
5525
5865
                                     "after txn_commit, txn_abort "
5526
5866
                                     "or txn_discard");
5527
 
        PyErr_SetObject(DBError, t);
5528
 
        Py_DECREF(t);
 
5867
        if (t) {
 
5868
            PyErr_SetObject(DBError, t);
 
5869
            Py_DECREF(t);
 
5870
        }
5529
5871
        return NULL;
5530
5872
    }
5531
5873
    self->flag_prepare=0;
5535
5877
    EXTRACT_FROM_DOUBLE_LINKED_LIST(self);
5536
5878
 
5537
5879
    MYDB_BEGIN_ALLOW_THREADS;
5538
 
#if (DBVER >= 40)
5539
5880
    err = txn->commit(txn, flags);
5540
 
#else
5541
 
    err = txn_commit(txn, flags);
5542
 
#endif
5543
5881
    MYDB_END_ALLOW_THREADS;
5544
5882
 
5545
5883
    _promote_transaction_dbs_and_sequences(self);
5551
5889
static PyObject*
5552
5890
DBTxn_prepare(DBTxnObject* self, PyObject* args)
5553
5891
{
5554
 
#if (DBVER >= 33)
5555
5892
    int err;
5556
5893
    char* gid=NULL;
5557
5894
    int   gid_size=0;
5569
5906
        PyObject *t = Py_BuildValue("(is)", 0,"DBTxn must not be used "
5570
5907
                                    "after txn_commit, txn_abort "
5571
5908
                                    "or txn_discard");
5572
 
        PyErr_SetObject(DBError, t);
5573
 
        Py_DECREF(t);
 
5909
        if (t) {
 
5910
            PyErr_SetObject(DBError, t);
 
5911
            Py_DECREF(t);
 
5912
        }
5574
5913
        return NULL;
5575
5914
    }
5576
5915
    self->flag_prepare=1;  /* Prepare state */
5577
5916
    MYDB_BEGIN_ALLOW_THREADS;
5578
 
#if (DBVER >= 40)
5579
5917
    err = self->txn->prepare(self->txn, (u_int8_t*)gid);
5580
 
#else
5581
 
    err = txn_prepare(self->txn, (u_int8_t*)gid);
5582
 
#endif
5583
 
    MYDB_END_ALLOW_THREADS;
5584
 
    RETURN_IF_ERR();
5585
 
    RETURN_NONE();
5586
 
#else
5587
 
    int err;
5588
 
 
5589
 
    if (!PyArg_ParseTuple(args, ":prepare"))
5590
 
        return NULL;
5591
 
 
5592
 
    if (!self->txn) {
5593
 
        PyObject *t = Py_BuildValue("(is)", 0, "DBTxn must not be used "
5594
 
                                    "after txn_commit, txn_abort "
5595
 
                                    "or txn_discard");
5596
 
        PyErr_SetObject(DBError, t);
5597
 
        Py_DECREF(t);
5598
 
        return NULL;
5599
 
    }
5600
 
    MYDB_BEGIN_ALLOW_THREADS;
5601
 
    err = txn_prepare(self->txn);
5602
 
    MYDB_END_ALLOW_THREADS;
5603
 
    RETURN_IF_ERR();
5604
 
    RETURN_NONE();
5605
 
#endif
 
5918
    MYDB_END_ALLOW_THREADS;
 
5919
    RETURN_IF_ERR();
 
5920
    RETURN_NONE();
5606
5921
}
5607
5922
 
5608
5923
 
5617
5932
        PyObject *t = Py_BuildValue("(is)", 0, "DBTxn must not be used "
5618
5933
                                    "after txn_commit, txn_abort "
5619
5934
                                    "or txn_discard");
5620
 
        PyErr_SetObject(DBError, t);
5621
 
        Py_DECREF(t);
 
5935
        if (t) {
 
5936
            PyErr_SetObject(DBError, t);
 
5937
            Py_DECREF(t);
 
5938
        }
5622
5939
        return NULL;
5623
5940
    }
5624
5941
    txn = self->txn;
5641
5958
    MYDB_BEGIN_ALLOW_THREADS;
5642
5959
    if (discard) {
5643
5960
        assert(!self->flag_prepare);
5644
 
#if (DBVER >= 40)
5645
5961
        err = txn->discard(txn,0);
5646
 
#else
5647
 
        err = txn_discard(txn);
5648
 
#endif
5649
5962
    } else {
5650
5963
        /*
5651
5964
        ** If the transaction is in the "prepare" or "recover" state,
5652
5965
        ** we better do not implicitly abort it.
5653
5966
        */
5654
5967
        if (!self->flag_prepare) {
5655
 
#if (DBVER >= 40)
5656
5968
            err = txn->abort(txn);
5657
 
#else
5658
 
            err = txn_abort(txn);
5659
 
#endif
5660
5969
        }
5661
5970
    }
5662
5971
    MYDB_END_ALLOW_THREADS;
5665
5974
}
5666
5975
 
5667
5976
static PyObject*
5668
 
DBTxn_abort(DBTxnObject* self, PyObject* args)
 
5977
DBTxn_abort(DBTxnObject* self)
5669
5978
{
5670
 
    if (!PyArg_ParseTuple(args, ":abort"))
5671
 
        return NULL;
5672
 
 
5673
5979
    self->flag_prepare=0;
5674
5980
    _close_transaction_cursors(self);
5675
5981
 
5677
5983
}
5678
5984
 
5679
5985
static PyObject*
5680
 
DBTxn_discard(DBTxnObject* self, PyObject* args)
 
5986
DBTxn_discard(DBTxnObject* self)
5681
5987
{
5682
 
    if (!PyArg_ParseTuple(args, ":discard"))
5683
 
        return NULL;
5684
 
 
5685
5988
    self->flag_prepare=0;
5686
5989
    _close_transaction_cursors(self);
5687
5990
 
5690
5993
 
5691
5994
 
5692
5995
static PyObject*
5693
 
DBTxn_id(DBTxnObject* self, PyObject* args)
 
5996
DBTxn_id(DBTxnObject* self)
5694
5997
{
5695
5998
    int id;
5696
5999
 
5697
 
    if (!PyArg_ParseTuple(args, ":id"))
5698
 
        return NULL;
5699
 
 
5700
6000
    if (!self->txn) {
5701
6001
        PyObject *t = Py_BuildValue("(is)", 0, "DBTxn must not be used "
5702
6002
                                    "after txn_commit, txn_abort "
5703
6003
                                    "or txn_discard");
5704
 
        PyErr_SetObject(DBError, t);
5705
 
        Py_DECREF(t);
 
6004
        if (t) {
 
6005
            PyErr_SetObject(DBError, t);
 
6006
            Py_DECREF(t);
 
6007
        }
5706
6008
        return NULL;
5707
6009
    }
5708
6010
    MYDB_BEGIN_ALLOW_THREADS;
5709
 
#if (DBVER >= 40)
5710
6011
    id = self->txn->id(self->txn);
5711
 
#else
5712
 
    id = txn_id(self->txn);
5713
 
#endif
5714
6012
    MYDB_END_ALLOW_THREADS;
5715
 
    return PyInt_FromLong(id);
 
6013
    return NUMBER_FromLong(id);
5716
6014
}
5717
6015
 
5718
6016
#if (DBVER >= 43)
5780
6078
}
5781
6079
 
5782
6080
static PyObject*
5783
 
DBSequence_get_dbp(DBSequenceObject* self, PyObject* args)
 
6081
DBSequence_get_dbp(DBSequenceObject* self)
5784
6082
{
5785
 
    if (!PyArg_ParseTuple(args,":get_dbp"))
5786
 
        return NULL;
5787
6083
    CHECK_SEQUENCE_NOT_CLOSED(self)
5788
6084
    Py_INCREF(self->mydb);
5789
6085
    return (PyObject* )self->mydb;
5790
6086
}
5791
6087
 
5792
6088
static PyObject*
5793
 
DBSequence_get_key(DBSequenceObject* self, PyObject* args)
 
6089
DBSequence_get_key(DBSequenceObject* self)
5794
6090
{
5795
6091
    int err;
5796
6092
    DBT key;
5797
6093
    PyObject *retval = NULL;
5798
6094
 
5799
 
    if (!PyArg_ParseTuple(args,":get_key"))
5800
 
        return NULL;
5801
 
 
5802
6095
    key.flags = DB_DBT_MALLOC;
5803
6096
    CHECK_SEQUENCE_NOT_CLOSED(self)
5804
6097
    MYDB_BEGIN_ALLOW_THREADS
5806
6099
    MYDB_END_ALLOW_THREADS
5807
6100
 
5808
6101
    if (!err)
5809
 
        retval = Build_PyString(key.data, key.size); 
 
6102
        retval = Build_PyString(key.data, key.size);
5810
6103
 
5811
6104
    FREE_DBT(key);
5812
6105
    RETURN_IF_ERR();
5857
6150
    err = self->sequence->open(self->sequence, txn, &key, flags);
5858
6151
    MYDB_END_ALLOW_THREADS
5859
6152
 
5860
 
    CLEAR_DBT(key);
 
6153
    FREE_DBT(key);
5861
6154
    RETURN_IF_ERR();
5862
6155
 
5863
6156
    if (txn) {
5913
6206
}
5914
6207
 
5915
6208
static PyObject*
5916
 
DBSequence_get_cachesize(DBSequenceObject* self, PyObject* args)
 
6209
DBSequence_get_cachesize(DBSequenceObject* self)
5917
6210
{
5918
6211
    int err, size;
5919
 
    if (!PyArg_ParseTuple(args,":get_cachesize"))
5920
 
        return NULL;
 
6212
 
5921
6213
    CHECK_SEQUENCE_NOT_CLOSED(self)
5922
6214
 
5923
6215
    MYDB_BEGIN_ALLOW_THREADS
5925
6217
    MYDB_END_ALLOW_THREADS
5926
6218
 
5927
6219
    RETURN_IF_ERR();
5928
 
    return PyInt_FromLong(size);
 
6220
    return NUMBER_FromLong(size);
5929
6221
}
5930
6222
 
5931
6223
static PyObject*
5945
6237
}
5946
6238
 
5947
6239
static PyObject*
5948
 
DBSequence_get_flags(DBSequenceObject* self, PyObject* args)
 
6240
DBSequence_get_flags(DBSequenceObject* self)
5949
6241
{
5950
6242
    unsigned int flags;
5951
6243
    int err;
5952
 
    if (!PyArg_ParseTuple(args,":get_flags"))
5953
 
        return NULL;
 
6244
 
5954
6245
    CHECK_SEQUENCE_NOT_CLOSED(self)
5955
6246
 
5956
6247
    MYDB_BEGIN_ALLOW_THREADS
5958
6249
    MYDB_END_ALLOW_THREADS
5959
6250
 
5960
6251
    RETURN_IF_ERR();
5961
 
    return PyInt_FromLong((int)flags);
 
6252
    return NUMBER_FromLong((int)flags);
5962
6253
}
5963
6254
 
5964
6255
static PyObject*
5982
6273
}
5983
6274
 
5984
6275
static PyObject*
5985
 
DBSequence_get_range(DBSequenceObject* self, PyObject* args)
 
6276
DBSequence_get_range(DBSequenceObject* self)
5986
6277
{
5987
6278
    int err;
5988
6279
    PY_LONG_LONG min, max;
5989
6280
    db_seq_t min2, max2;
5990
 
    if (!PyArg_ParseTuple(args,":get_range"))
5991
 
        return NULL;
 
6281
 
5992
6282
    CHECK_SEQUENCE_NOT_CLOSED(self)
5993
6283
 
5994
6284
    MYDB_BEGIN_ALLOW_THREADS
6049
6339
/* Method definition tables and type objects */
6050
6340
 
6051
6341
static PyMethodDef DB_methods[] = {
6052
 
    {"append",          (PyCFunction)DB_append,         METH_VARARGS},
6053
 
#if (DBVER >= 33)
 
6342
    {"append",          (PyCFunction)DB_append,         METH_VARARGS|METH_KEYWORDS},
6054
6343
    {"associate",       (PyCFunction)DB_associate,      METH_VARARGS|METH_KEYWORDS},
6055
 
#endif
6056
6344
    {"close",           (PyCFunction)DB_close,          METH_VARARGS},
6057
6345
    {"consume",         (PyCFunction)DB_consume,        METH_VARARGS|METH_KEYWORDS},
6058
6346
    {"consume_wait",    (PyCFunction)DB_consume_wait,   METH_VARARGS|METH_KEYWORDS},
6059
6347
    {"cursor",          (PyCFunction)DB_cursor,         METH_VARARGS|METH_KEYWORDS},
6060
6348
    {"delete",          (PyCFunction)DB_delete,         METH_VARARGS|METH_KEYWORDS},
6061
 
    {"fd",              (PyCFunction)DB_fd,             METH_VARARGS},
 
6349
    {"fd",              (PyCFunction)DB_fd,             METH_NOARGS},
6062
6350
    {"get",             (PyCFunction)DB_get,            METH_VARARGS|METH_KEYWORDS},
6063
 
#if (DBVER >= 33)
6064
6351
    {"pget",            (PyCFunction)DB_pget,           METH_VARARGS|METH_KEYWORDS},
6065
 
#endif
6066
6352
    {"get_both",        (PyCFunction)DB_get_both,       METH_VARARGS|METH_KEYWORDS},
6067
 
    {"get_byteswapped", (PyCFunction)DB_get_byteswapped,METH_VARARGS},
 
6353
    {"get_byteswapped", (PyCFunction)DB_get_byteswapped,METH_NOARGS},
6068
6354
    {"get_size",        (PyCFunction)DB_get_size,       METH_VARARGS|METH_KEYWORDS},
6069
 
    {"get_type",        (PyCFunction)DB_get_type,       METH_VARARGS},
 
6355
    {"get_type",        (PyCFunction)DB_get_type,       METH_NOARGS},
6070
6356
    {"join",            (PyCFunction)DB_join,           METH_VARARGS},
6071
6357
    {"key_range",       (PyCFunction)DB_key_range,      METH_VARARGS|METH_KEYWORDS},
6072
 
    {"has_key",         (PyCFunction)DB_has_key,        METH_VARARGS},
 
6358
    {"has_key",         (PyCFunction)DB_has_key,        METH_VARARGS|METH_KEYWORDS},
6073
6359
    {"items",           (PyCFunction)DB_items,          METH_VARARGS},
6074
6360
    {"keys",            (PyCFunction)DB_keys,           METH_VARARGS},
6075
6361
    {"open",            (PyCFunction)DB_open,           METH_VARARGS|METH_KEYWORDS},
6077
6363
    {"remove",          (PyCFunction)DB_remove,         METH_VARARGS|METH_KEYWORDS},
6078
6364
    {"rename",          (PyCFunction)DB_rename,         METH_VARARGS},
6079
6365
    {"set_bt_minkey",   (PyCFunction)DB_set_bt_minkey,  METH_VARARGS},
6080
 
#if (DBVER >= 33)
6081
 
    {"set_bt_compare",  (PyCFunction)DB_set_bt_compare, METH_VARARGS},
6082
 
#endif
 
6366
    {"set_bt_compare",  (PyCFunction)DB_set_bt_compare, METH_O},
6083
6367
    {"set_cachesize",   (PyCFunction)DB_set_cachesize,  METH_VARARGS},
6084
6368
#if (DBVER >= 41)
6085
6369
    {"set_encrypt",     (PyCFunction)DB_set_encrypt,    METH_VARARGS|METH_KEYWORDS},
6093
6377
    {"set_re_len",      (PyCFunction)DB_set_re_len,     METH_VARARGS},
6094
6378
    {"set_re_pad",      (PyCFunction)DB_set_re_pad,     METH_VARARGS},
6095
6379
    {"set_re_source",   (PyCFunction)DB_set_re_source,  METH_VARARGS},
6096
 
    {"set_q_extentsize",(PyCFunction)DB_set_q_extentsize,METH_VARARGS},
 
6380
    {"set_q_extentsize",(PyCFunction)DB_set_q_extentsize, METH_VARARGS},
 
6381
    {"set_private",     (PyCFunction)DB_set_private,    METH_O},
 
6382
    {"get_private",     (PyCFunction)DB_get_private,    METH_NOARGS},
6097
6383
    {"stat",            (PyCFunction)DB_stat,           METH_VARARGS|METH_KEYWORDS},
6098
6384
    {"sync",            (PyCFunction)DB_sync,           METH_VARARGS},
6099
 
#if (DBVER >= 33)
6100
6385
    {"truncate",        (PyCFunction)DB_truncate,       METH_VARARGS|METH_KEYWORDS},
6101
 
#endif
6102
 
    {"type",            (PyCFunction)DB_get_type,       METH_VARARGS},
 
6386
    {"type",            (PyCFunction)DB_get_type,       METH_NOARGS},
6103
6387
    {"upgrade",         (PyCFunction)DB_upgrade,        METH_VARARGS},
6104
6388
    {"values",          (PyCFunction)DB_values,         METH_VARARGS},
6105
6389
    {"verify",          (PyCFunction)DB_verify,         METH_VARARGS|METH_KEYWORDS},
6116
6400
 
6117
6401
 
6118
6402
static PyMethodDef DBCursor_methods[] = {
6119
 
    {"close",           (PyCFunction)DBC_close,         METH_VARARGS},
 
6403
    {"close",           (PyCFunction)DBC_close,         METH_NOARGS},
6120
6404
    {"count",           (PyCFunction)DBC_count,         METH_VARARGS},
6121
6405
    {"current",         (PyCFunction)DBC_current,       METH_VARARGS|METH_KEYWORDS},
6122
6406
    {"delete",          (PyCFunction)DBC_delete,        METH_VARARGS},
6123
6407
    {"dup",             (PyCFunction)DBC_dup,           METH_VARARGS},
6124
6408
    {"first",           (PyCFunction)DBC_first,         METH_VARARGS|METH_KEYWORDS},
6125
6409
    {"get",             (PyCFunction)DBC_get,           METH_VARARGS|METH_KEYWORDS},
6126
 
#if (DBVER >= 33)
6127
6410
    {"pget",            (PyCFunction)DBC_pget,          METH_VARARGS|METH_KEYWORDS},
6128
 
#endif
6129
 
    {"get_recno",       (PyCFunction)DBC_get_recno,     METH_VARARGS},
 
6411
    {"get_recno",       (PyCFunction)DBC_get_recno,     METH_NOARGS},
6130
6412
    {"last",            (PyCFunction)DBC_last,          METH_VARARGS|METH_KEYWORDS},
6131
6413
    {"next",            (PyCFunction)DBC_next,          METH_VARARGS|METH_KEYWORDS},
6132
6414
    {"prev",            (PyCFunction)DBC_prev,          METH_VARARGS|METH_KEYWORDS},
6134
6416
    {"set",             (PyCFunction)DBC_set,           METH_VARARGS|METH_KEYWORDS},
6135
6417
    {"set_range",       (PyCFunction)DBC_set_range,     METH_VARARGS|METH_KEYWORDS},
6136
6418
    {"get_both",        (PyCFunction)DBC_get_both,      METH_VARARGS},
6137
 
    {"get_current_size",(PyCFunction)DBC_get_current_size, METH_VARARGS},
 
6419
    {"get_current_size",(PyCFunction)DBC_get_current_size, METH_NOARGS},
6138
6420
    {"set_both",        (PyCFunction)DBC_set_both,      METH_VARARGS},
6139
6421
    {"set_recno",       (PyCFunction)DBC_set_recno,     METH_VARARGS|METH_KEYWORDS},
6140
6422
    {"consume",         (PyCFunction)DBC_consume,       METH_VARARGS|METH_KEYWORDS},
6155
6437
    {"dbrename",        (PyCFunction)DBEnv_dbrename,         METH_VARARGS|METH_KEYWORDS},
6156
6438
    {"set_encrypt",     (PyCFunction)DBEnv_set_encrypt,      METH_VARARGS|METH_KEYWORDS},
6157
6439
#endif
6158
 
#if (DBVER >= 40)
6159
6440
    {"set_timeout",     (PyCFunction)DBEnv_set_timeout,      METH_VARARGS|METH_KEYWORDS},
6160
 
#endif
6161
6441
    {"set_shm_key",     (PyCFunction)DBEnv_set_shm_key,      METH_VARARGS},
6162
6442
    {"set_cachesize",   (PyCFunction)DBEnv_set_cachesize,    METH_VARARGS},
6163
6443
    {"set_data_dir",    (PyCFunction)DBEnv_set_data_dir,     METH_VARARGS},
6169
6449
    {"set_lg_dir",      (PyCFunction)DBEnv_set_lg_dir,       METH_VARARGS},
6170
6450
    {"set_lg_max",      (PyCFunction)DBEnv_set_lg_max,       METH_VARARGS},
6171
6451
#if (DBVER >= 42)
6172
 
    {"get_lg_max",      (PyCFunction)DBEnv_get_lg_max,       METH_VARARGS},
 
6452
    {"get_lg_max",      (PyCFunction)DBEnv_get_lg_max,       METH_NOARGS},
6173
6453
#endif
6174
 
#if (DBVER >= 33)
6175
6454
    {"set_lg_regionmax",(PyCFunction)DBEnv_set_lg_regionmax, METH_VARARGS},
6176
 
#endif
6177
6455
    {"set_lk_detect",   (PyCFunction)DBEnv_set_lk_detect,    METH_VARARGS},
6178
6456
#if (DBVER < 45)
6179
6457
    {"set_lk_max",      (PyCFunction)DBEnv_set_lk_max,       METH_VARARGS},
6190
6468
    {"set_tx_timestamp", (PyCFunction)DBEnv_set_tx_timestamp, METH_VARARGS},
6191
6469
    {"lock_detect",     (PyCFunction)DBEnv_lock_detect,      METH_VARARGS},
6192
6470
    {"lock_get",        (PyCFunction)DBEnv_lock_get,         METH_VARARGS},
6193
 
    {"lock_id",         (PyCFunction)DBEnv_lock_id,          METH_VARARGS},
6194
 
#if (DBVER >= 40)
 
6471
    {"lock_id",         (PyCFunction)DBEnv_lock_id,          METH_NOARGS},
6195
6472
    {"lock_id_free",    (PyCFunction)DBEnv_lock_id_free,     METH_VARARGS},
6196
 
#endif
6197
6473
    {"lock_put",        (PyCFunction)DBEnv_lock_put,         METH_VARARGS},
6198
6474
    {"lock_stat",       (PyCFunction)DBEnv_lock_stat,        METH_VARARGS},
6199
6475
    {"log_archive",     (PyCFunction)DBEnv_log_archive,      METH_VARARGS},
6200
 
#if (DBVER >= 40)
6201
 
    {"log_flush",       (PyCFunction)DBEnv_log_flush,       METH_VARARGS},
6202
 
#endif
6203
 
#if (DBVER >= 40)
 
6476
    {"log_flush",       (PyCFunction)DBEnv_log_flush,        METH_NOARGS},
6204
6477
    {"log_stat",        (PyCFunction)DBEnv_log_stat,         METH_VARARGS},
6205
 
#endif
6206
6478
#if (DBVER >= 44)
6207
6479
    {"lsn_reset",       (PyCFunction)DBEnv_lsn_reset,        METH_VARARGS|METH_KEYWORDS},
6208
6480
#endif
6209
6481
    {"set_get_returns_none",(PyCFunction)DBEnv_set_get_returns_none, METH_VARARGS},
6210
 
#if (DBVER >= 40)
6211
 
    {"txn_recover",     (PyCFunction)DBEnv_txn_recover,       METH_VARARGS},
6212
 
#endif
6213
 
#if (DBVER >= 40)
 
6482
    {"txn_recover",     (PyCFunction)DBEnv_txn_recover,       METH_NOARGS},
6214
6483
    {"set_rpc_server",  (PyCFunction)DBEnv_set_rpc_server,
6215
6484
        METH_VARARGS||METH_KEYWORDS},
6216
 
#endif
6217
 
#if (DBVER >= 40)
6218
6485
    {"set_verbose",     (PyCFunction)DBEnv_set_verbose,       METH_VARARGS},
6219
6486
#if (DBVER >= 42)
6220
6487
    {"get_verbose",     (PyCFunction)DBEnv_get_verbose,       METH_VARARGS},
6221
6488
#endif
6222
 
#endif
6223
 
#if (DBVER >= 45)
6224
 
    {"set_event_notify", (PyCFunction)DBEnv_set_event_notify, METH_VARARGS},
 
6489
    {"set_private",     (PyCFunction)DBEnv_set_private,       METH_O},
 
6490
    {"get_private",     (PyCFunction)DBEnv_get_private,       METH_NOARGS},
 
6491
    {"rep_start",       (PyCFunction)DBEnv_rep_start,
 
6492
        METH_VARARGS|METH_KEYWORDS},
 
6493
    {"rep_set_transport", (PyCFunction)DBEnv_rep_set_transport, METH_VARARGS},
 
6494
    {"rep_process_message", (PyCFunction)DBEnv_rep_process_message,
 
6495
        METH_VARARGS},
 
6496
#if (DBVER >= 46)
 
6497
    {"rep_elect",       (PyCFunction)DBEnv_rep_elect,         METH_VARARGS},
 
6498
#endif
 
6499
#if (DBVER >= 44)
 
6500
    {"rep_set_config",  (PyCFunction)DBEnv_rep_set_config,    METH_VARARGS},
 
6501
    {"rep_get_config",  (PyCFunction)DBEnv_rep_get_config,    METH_VARARGS},
 
6502
    {"rep_sync",        (PyCFunction)DBEnv_rep_sync,          METH_NOARGS},
 
6503
#endif
 
6504
#if (DBVER >= 45)
 
6505
    {"rep_set_limit",   (PyCFunction)DBEnv_rep_set_limit,     METH_VARARGS},
 
6506
    {"rep_get_limit",   (PyCFunction)DBEnv_rep_get_limit,     METH_NOARGS},
 
6507
#endif
 
6508
#if (DBVER >= 47)
 
6509
    {"rep_set_request", (PyCFunction)DBEnv_rep_set_request,   METH_VARARGS},
 
6510
    {"rep_get_request", (PyCFunction)DBEnv_rep_get_request,   METH_NOARGS},
 
6511
#endif
 
6512
#if (DBVER >= 45)
 
6513
    {"set_event_notify", (PyCFunction)DBEnv_set_event_notify, METH_O},
6225
6514
#endif
6226
6515
#if (DBVER >= 45)
6227
6516
    {"rep_set_nsites", (PyCFunction)DBEnv_rep_set_nsites, METH_VARARGS},
6228
 
    {"rep_get_nsites", (PyCFunction)DBEnv_rep_get_nsites, METH_VARARGS},
 
6517
    {"rep_get_nsites", (PyCFunction)DBEnv_rep_get_nsites, METH_NOARGS},
6229
6518
    {"rep_set_priority", (PyCFunction)DBEnv_rep_set_priority, METH_VARARGS},
6230
 
    {"rep_get_priority", (PyCFunction)DBEnv_rep_get_priority, METH_VARARGS},
 
6519
    {"rep_get_priority", (PyCFunction)DBEnv_rep_get_priority, METH_NOARGS},
6231
6520
    {"rep_set_timeout", (PyCFunction)DBEnv_rep_set_timeout, METH_VARARGS},
6232
6521
    {"rep_get_timeout", (PyCFunction)DBEnv_rep_get_timeout, METH_VARARGS},
6233
6522
#endif
6241
6530
    {"repmgr_set_ack_policy", (PyCFunction)DBEnv_repmgr_set_ack_policy,
6242
6531
        METH_VARARGS},
6243
6532
    {"repmgr_get_ack_policy", (PyCFunction)DBEnv_repmgr_get_ack_policy,
6244
 
        METH_VARARGS},
 
6533
        METH_NOARGS},
6245
6534
    {"repmgr_site_list", (PyCFunction)DBEnv_repmgr_site_list,
6246
 
        METH_VARARGS},
 
6535
        METH_NOARGS},
6247
6536
#endif
6248
6537
#if (DBVER >= 46)
6249
6538
    {"repmgr_stat", (PyCFunction)DBEnv_repmgr_stat,
6258
6547
static PyMethodDef DBTxn_methods[] = {
6259
6548
    {"commit",          (PyCFunction)DBTxn_commit,      METH_VARARGS},
6260
6549
    {"prepare",         (PyCFunction)DBTxn_prepare,     METH_VARARGS},
6261
 
    {"discard",         (PyCFunction)DBTxn_discard,     METH_VARARGS},
6262
 
    {"abort",           (PyCFunction)DBTxn_abort,       METH_VARARGS},
6263
 
    {"id",              (PyCFunction)DBTxn_id,          METH_VARARGS},
 
6550
    {"discard",         (PyCFunction)DBTxn_discard,     METH_NOARGS},
 
6551
    {"abort",           (PyCFunction)DBTxn_abort,       METH_NOARGS},
 
6552
    {"id",              (PyCFunction)DBTxn_id,          METH_NOARGS},
6264
6553
    {NULL,      NULL}       /* sentinel */
6265
6554
};
6266
6555
 
6269
6558
static PyMethodDef DBSequence_methods[] = {
6270
6559
    {"close",           (PyCFunction)DBSequence_close,          METH_VARARGS},
6271
6560
    {"get",             (PyCFunction)DBSequence_get,            METH_VARARGS|METH_KEYWORDS},
6272
 
    {"get_dbp",         (PyCFunction)DBSequence_get_dbp,        METH_VARARGS},
6273
 
    {"get_key",         (PyCFunction)DBSequence_get_key,        METH_VARARGS},
 
6561
    {"get_dbp",         (PyCFunction)DBSequence_get_dbp,        METH_NOARGS},
 
6562
    {"get_key",         (PyCFunction)DBSequence_get_key,        METH_NOARGS},
6274
6563
    {"init_value",      (PyCFunction)DBSequence_init_value,     METH_VARARGS},
6275
6564
    {"open",            (PyCFunction)DBSequence_open,           METH_VARARGS|METH_KEYWORDS},
6276
6565
    {"remove",          (PyCFunction)DBSequence_remove,         METH_VARARGS|METH_KEYWORDS},
6277
6566
    {"set_cachesize",   (PyCFunction)DBSequence_set_cachesize,  METH_VARARGS},
6278
 
    {"get_cachesize",   (PyCFunction)DBSequence_get_cachesize,  METH_VARARGS},
 
6567
    {"get_cachesize",   (PyCFunction)DBSequence_get_cachesize,  METH_NOARGS},
6279
6568
    {"set_flags",       (PyCFunction)DBSequence_set_flags,      METH_VARARGS},
6280
 
    {"get_flags",       (PyCFunction)DBSequence_get_flags,      METH_VARARGS},
 
6569
    {"get_flags",       (PyCFunction)DBSequence_get_flags,      METH_NOARGS},
6281
6570
    {"set_range",       (PyCFunction)DBSequence_set_range,      METH_VARARGS},
6282
 
    {"get_range",       (PyCFunction)DBSequence_get_range,      METH_VARARGS},
 
6571
    {"get_range",       (PyCFunction)DBSequence_get_range,      METH_NOARGS},
6283
6572
    {"stat",            (PyCFunction)DBSequence_stat,           METH_VARARGS|METH_KEYWORDS},
6284
6573
    {NULL,      NULL}       /* sentinel */
6285
6574
};
6287
6576
 
6288
6577
 
6289
6578
static PyObject*
6290
 
DB_getattr(DBObject* self, char *name)
6291
 
{
6292
 
    return Py_FindMethod(DB_methods, (PyObject* )self, name);
6293
 
}
6294
 
 
6295
 
 
6296
 
static PyObject*
6297
 
DBEnv_getattr(DBEnvObject* self, char *name)
6298
 
{
6299
 
    if (!strcmp(name, "db_home")) {
6300
 
      const char *home = NULL;
6301
 
      CHECK_ENV_NOT_CLOSED(self);
 
6579
DBEnv_db_home_get(DBEnvObject* self)
 
6580
{
 
6581
    const char *home = NULL;
 
6582
 
 
6583
    CHECK_ENV_NOT_CLOSED(self);
 
6584
 
6302
6585
#if (DBVER >= 42)
6303
 
      self->db_env->get_home(self->db_env, &home);
 
6586
    self->db_env->get_home(self->db_env, &home);
6304
6587
#else
6305
 
      home=self->db_env->db_home;
 
6588
    home=self->db_env->db_home;
6306
6589
#endif
6307
 
      if (home == NULL) {
6308
 
          RETURN_NONE();
6309
 
      }
6310
 
      return PyBytes_FromString(home);
 
6590
 
 
6591
    if (home == NULL) {
 
6592
        RETURN_NONE();
6311
6593
    }
6312
 
 
6313
 
    return Py_FindMethod(DBEnv_methods, (PyObject* )self, name);
6314
 
}
6315
 
 
6316
 
 
6317
 
static PyObject*
6318
 
DBCursor_getattr(DBCursorObject* self, char *name)
6319
 
{
6320
 
    return Py_FindMethod(DBCursor_methods, (PyObject* )self, name);
6321
 
}
6322
 
 
6323
 
static PyObject*
6324
 
DBTxn_getattr(DBTxnObject* self, char *name)
6325
 
{
6326
 
    return Py_FindMethod(DBTxn_methods, (PyObject* )self, name);
6327
 
}
6328
 
 
6329
 
static PyObject*
6330
 
DBLock_getattr(DBLockObject* self, char *name)
6331
 
{
6332
 
    return NULL;
6333
 
}
6334
 
 
6335
 
#if (DBVER >= 43)
6336
 
static PyObject*
6337
 
DBSequence_getattr(DBSequenceObject* self, char *name)
6338
 
{
6339
 
    return Py_FindMethod(DBSequence_methods, (PyObject* )self, name);
6340
 
}
6341
 
#endif
 
6594
    return PyBytes_FromString(home);
 
6595
}
 
6596
 
 
6597
static PyGetSetDef DBEnv_getsets[] = {
 
6598
    {"db_home", (getter)DBEnv_db_home_get, NULL,},
 
6599
    {NULL}
 
6600
};
 
6601
 
6342
6602
 
6343
6603
statichere PyTypeObject DB_Type = {
 
6604
#if (PY_VERSION_HEX < 0x03000000)
6344
6605
    PyObject_HEAD_INIT(NULL)
6345
6606
    0,                  /*ob_size*/
 
6607
#else
 
6608
    PyVarObject_HEAD_INIT(NULL, 0)
 
6609
#endif
6346
6610
    "DB",               /*tp_name*/
6347
6611
    sizeof(DBObject),   /*tp_basicsize*/
6348
6612
    0,                  /*tp_itemsize*/
6349
6613
    /* methods */
6350
6614
    (destructor)DB_dealloc, /*tp_dealloc*/
6351
 
    0,                  /*tp_print*/
6352
 
    (getattrfunc)DB_getattr, /*tp_getattr*/
6353
 
    0,                      /*tp_setattr*/
 
6615
    0,          /*tp_print*/
 
6616
    0,          /*tp_getattr*/
 
6617
    0,          /*tp_setattr*/
6354
6618
    0,          /*tp_compare*/
6355
6619
    0,          /*tp_repr*/
6356
6620
    0,          /*tp_as_number*/
6360
6624
    0,                  /* tp_call */
6361
6625
    0,                  /* tp_str */
6362
6626
    0,                  /* tp_getattro */
6363
 
    0,                  /* tp_setattro */
 
6627
    0,          /* tp_setattro */
6364
6628
    0,                  /* tp_as_buffer */
 
6629
#if (PY_VERSION_HEX < 0x03000000)
6365
6630
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
6366
 
    0,                  /* tp_doc */
6367
 
    0,                  /* tp_traverse */
 
6631
#else
 
6632
    Py_TPFLAGS_DEFAULT,      /* tp_flags */
 
6633
#endif
 
6634
    0,          /* tp_doc */
 
6635
    0,              /* tp_traverse */
6368
6636
    0,                  /* tp_clear */
6369
6637
    0,                  /* tp_richcompare */
6370
6638
    offsetof(DBObject, in_weakreflist),   /* tp_weaklistoffset */
 
6639
    0,          /*tp_iter*/
 
6640
    0,          /*tp_iternext*/
 
6641
    DB_methods, /*tp_methods*/
 
6642
    0, /*tp_members*/
6371
6643
};
6372
6644
 
6373
6645
 
6374
6646
statichere PyTypeObject DBCursor_Type = {
 
6647
#if (PY_VERSION_HEX < 0x03000000)
6375
6648
    PyObject_HEAD_INIT(NULL)
6376
6649
    0,                  /*ob_size*/
 
6650
#else
 
6651
    PyVarObject_HEAD_INIT(NULL, 0)
 
6652
#endif
6377
6653
    "DBCursor",         /*tp_name*/
6378
6654
    sizeof(DBCursorObject),  /*tp_basicsize*/
6379
 
    0,                  /*tp_itemsize*/
 
6655
    0,          /*tp_itemsize*/
6380
6656
    /* methods */
6381
6657
    (destructor)DBCursor_dealloc,/*tp_dealloc*/
6382
 
    0,                  /*tp_print*/
6383
 
    (getattrfunc)DBCursor_getattr, /*tp_getattr*/
6384
 
    0,                  /*tp_setattr*/
6385
 
    0,                  /*tp_compare*/
6386
 
    0,                  /*tp_repr*/
6387
 
    0,                  /*tp_as_number*/
6388
 
    0,                  /*tp_as_sequence*/
6389
 
    0,                  /*tp_as_mapping*/
6390
 
    0,                  /*tp_hash*/
6391
 
    0,                  /* tp_call */
6392
 
    0,                  /* tp_str */
6393
 
    0,                  /* tp_getattro */
6394
 
    0,                  /* tp_setattro */
6395
 
    0,                  /* tp_as_buffer */
 
6658
    0,          /*tp_print*/
 
6659
    0,          /*tp_getattr*/
 
6660
    0,          /*tp_setattr*/
 
6661
    0,          /*tp_compare*/
 
6662
    0,          /*tp_repr*/
 
6663
    0,          /*tp_as_number*/
 
6664
    0,          /*tp_as_sequence*/
 
6665
    0,          /*tp_as_mapping*/
 
6666
    0,          /*tp_hash*/
 
6667
    0,          /*tp_call*/
 
6668
    0,          /*tp_str*/
 
6669
    0,          /*tp_getattro*/
 
6670
    0,          /*tp_setattro*/
 
6671
    0,          /*tp_as_buffer*/
 
6672
#if (PY_VERSION_HEX < 0x03000000)
6396
6673
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
6397
 
    0,                  /* tp_doc */
6398
 
    0,                  /* tp_traverse */
6399
 
    0,                  /* tp_clear */
6400
 
    0,                  /* tp_richcompare */
 
6674
#else
 
6675
    Py_TPFLAGS_DEFAULT,      /* tp_flags */
 
6676
#endif
 
6677
    0,          /* tp_doc */
 
6678
    0,          /* tp_traverse */
 
6679
    0,          /* tp_clear */
 
6680
    0,          /* tp_richcompare */
6401
6681
    offsetof(DBCursorObject, in_weakreflist),   /* tp_weaklistoffset */
 
6682
    0,          /*tp_iter*/
 
6683
    0,          /*tp_iternext*/
 
6684
    DBCursor_methods, /*tp_methods*/
 
6685
    0,          /*tp_members*/
6402
6686
};
6403
6687
 
6404
6688
 
6405
6689
statichere PyTypeObject DBEnv_Type = {
 
6690
#if (PY_VERSION_HEX < 0x03000000)
6406
6691
    PyObject_HEAD_INIT(NULL)
6407
 
    0,          /*ob_size*/
 
6692
    0,                  /*ob_size*/
 
6693
#else
 
6694
    PyVarObject_HEAD_INIT(NULL, 0)
 
6695
#endif
6408
6696
    "DBEnv",            /*tp_name*/
6409
6697
    sizeof(DBEnvObject),    /*tp_basicsize*/
6410
6698
    0,          /*tp_itemsize*/
6411
6699
    /* methods */
6412
6700
    (destructor)DBEnv_dealloc, /*tp_dealloc*/
6413
6701
    0,          /*tp_print*/
6414
 
    (getattrfunc)DBEnv_getattr, /*tp_getattr*/
 
6702
    0,          /*tp_getattr*/
6415
6703
    0,          /*tp_setattr*/
6416
6704
    0,          /*tp_compare*/
6417
6705
    0,          /*tp_repr*/
6422
6710
    0,                  /* tp_call */
6423
6711
    0,                  /* tp_str */
6424
6712
    0,                  /* tp_getattro */
6425
 
    0,                  /* tp_setattro */
 
6713
    0,          /* tp_setattro */
6426
6714
    0,                  /* tp_as_buffer */
 
6715
#if (PY_VERSION_HEX < 0x03000000)
6427
6716
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
6428
 
    0,                  /* tp_doc */
6429
 
    0,                  /* tp_traverse */
 
6717
#else
 
6718
    Py_TPFLAGS_DEFAULT,      /* tp_flags */
 
6719
#endif
 
6720
    0,          /* tp_doc */
 
6721
    0,              /* tp_traverse */
6430
6722
    0,                  /* tp_clear */
6431
6723
    0,                  /* tp_richcompare */
6432
6724
    offsetof(DBEnvObject, in_weakreflist),   /* tp_weaklistoffset */
 
6725
    0,          /* tp_iter */
 
6726
    0,          /* tp_iternext */
 
6727
    DBEnv_methods,      /* tp_methods */
 
6728
    0,          /* tp_members */
 
6729
    DBEnv_getsets,      /* tp_getsets */
6433
6730
};
6434
6731
 
6435
6732
statichere PyTypeObject DBTxn_Type = {
 
6733
#if (PY_VERSION_HEX < 0x03000000)
6436
6734
    PyObject_HEAD_INIT(NULL)
6437
 
    0,          /*ob_size*/
 
6735
    0,                  /*ob_size*/
 
6736
#else
 
6737
    PyVarObject_HEAD_INIT(NULL, 0)
 
6738
#endif
6438
6739
    "DBTxn",    /*tp_name*/
6439
6740
    sizeof(DBTxnObject),  /*tp_basicsize*/
6440
6741
    0,          /*tp_itemsize*/
6441
6742
    /* methods */
6442
6743
    (destructor)DBTxn_dealloc, /*tp_dealloc*/
6443
6744
    0,          /*tp_print*/
6444
 
    (getattrfunc)DBTxn_getattr, /*tp_getattr*/
6445
 
    0,                      /*tp_setattr*/
 
6745
    0,          /*tp_getattr*/
 
6746
    0,          /*tp_setattr*/
6446
6747
    0,          /*tp_compare*/
6447
6748
    0,          /*tp_repr*/
6448
6749
    0,          /*tp_as_number*/
6452
6753
    0,                  /* tp_call */
6453
6754
    0,                  /* tp_str */
6454
6755
    0,                  /* tp_getattro */
6455
 
    0,                  /* tp_setattro */
 
6756
    0,          /* tp_setattro */
6456
6757
    0,                  /* tp_as_buffer */
 
6758
#if (PY_VERSION_HEX < 0x03000000)
6457
6759
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
6458
 
    0,                  /* tp_doc */
6459
 
    0,                  /* tp_traverse */
 
6760
#else
 
6761
    Py_TPFLAGS_DEFAULT,      /* tp_flags */
 
6762
#endif
 
6763
    0,          /* tp_doc */
 
6764
    0,          /* tp_traverse */
6460
6765
    0,                  /* tp_clear */
6461
6766
    0,                  /* tp_richcompare */
6462
6767
    offsetof(DBTxnObject, in_weakreflist),   /* tp_weaklistoffset */
 
6768
    0,          /*tp_iter*/
 
6769
    0,          /*tp_iternext*/
 
6770
    DBTxn_methods, /*tp_methods*/
 
6771
    0,          /*tp_members*/
6463
6772
};
6464
6773
 
6465
6774
 
6466
6775
statichere PyTypeObject DBLock_Type = {
 
6776
#if (PY_VERSION_HEX < 0x03000000)
6467
6777
    PyObject_HEAD_INIT(NULL)
6468
 
    0,          /*ob_size*/
 
6778
    0,                  /*ob_size*/
 
6779
#else
 
6780
    PyVarObject_HEAD_INIT(NULL, 0)
 
6781
#endif
6469
6782
    "DBLock",   /*tp_name*/
6470
6783
    sizeof(DBLockObject),  /*tp_basicsize*/
6471
6784
    0,          /*tp_itemsize*/
6472
6785
    /* methods */
6473
6786
    (destructor)DBLock_dealloc, /*tp_dealloc*/
6474
6787
    0,          /*tp_print*/
6475
 
    (getattrfunc)DBLock_getattr, /*tp_getattr*/
6476
 
    0,                      /*tp_setattr*/
 
6788
    0,          /*tp_getattr*/
 
6789
    0,          /*tp_setattr*/
6477
6790
    0,          /*tp_compare*/
6478
6791
    0,          /*tp_repr*/
6479
6792
    0,          /*tp_as_number*/
6483
6796
    0,                  /* tp_call */
6484
6797
    0,                  /* tp_str */
6485
6798
    0,                  /* tp_getattro */
6486
 
    0,                  /* tp_setattro */
 
6799
    0,          /* tp_setattro */
6487
6800
    0,                  /* tp_as_buffer */
 
6801
#if (PY_VERSION_HEX < 0x03000000)
6488
6802
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
6489
 
    0,                  /* tp_doc */
6490
 
    0,                  /* tp_traverse */
 
6803
#else
 
6804
    Py_TPFLAGS_DEFAULT,      /* tp_flags */
 
6805
#endif
 
6806
    0,          /* tp_doc */
 
6807
    0,              /* tp_traverse */
6491
6808
    0,                  /* tp_clear */
6492
6809
    0,                  /* tp_richcompare */
6493
6810
    offsetof(DBLockObject, in_weakreflist),   /* tp_weaklistoffset */
6495
6812
 
6496
6813
#if (DBVER >= 43)
6497
6814
statichere PyTypeObject DBSequence_Type = {
 
6815
#if (PY_VERSION_HEX < 0x03000000)
6498
6816
    PyObject_HEAD_INIT(NULL)
6499
 
    0,          /*ob_size*/
 
6817
    0,                  /*ob_size*/
 
6818
#else
 
6819
    PyVarObject_HEAD_INIT(NULL, 0)
 
6820
#endif
6500
6821
    "DBSequence",                   /*tp_name*/
6501
6822
    sizeof(DBSequenceObject),       /*tp_basicsize*/
6502
6823
    0,          /*tp_itemsize*/
6503
6824
    /* methods */
6504
6825
    (destructor)DBSequence_dealloc, /*tp_dealloc*/
6505
6826
    0,          /*tp_print*/
6506
 
    (getattrfunc)DBSequence_getattr,/*tp_getattr*/
 
6827
    0,          /*tp_getattr*/
6507
6828
    0,          /*tp_setattr*/
6508
6829
    0,          /*tp_compare*/
6509
6830
    0,          /*tp_repr*/
6516
6837
    0,                  /* tp_getattro */
6517
6838
    0,          /* tp_setattro */
6518
6839
    0,                  /* tp_as_buffer */
 
6840
#if (PY_VERSION_HEX < 0x03000000)
6519
6841
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS,      /* tp_flags */
 
6842
#else
 
6843
    Py_TPFLAGS_DEFAULT,      /* tp_flags */
 
6844
#endif
6520
6845
    0,          /* tp_doc */
6521
6846
    0,              /* tp_traverse */
6522
6847
    0,                  /* tp_clear */
6523
6848
    0,                  /* tp_richcompare */
6524
6849
    offsetof(DBSequenceObject, in_weakreflist),   /* tp_weaklistoffset */
 
6850
    0,          /*tp_iter*/
 
6851
    0,          /*tp_iternext*/
 
6852
    DBSequence_methods, /*tp_methods*/
 
6853
    0,          /*tp_members*/
6525
6854
};
6526
6855
#endif
6527
6856
 
6580
6909
underlying DB library.";
6581
6910
 
6582
6911
static PyObject*
6583
 
bsddb_version(PyObject* self, PyObject* args)
 
6912
bsddb_version(PyObject* self)
6584
6913
{
6585
6914
    int major, minor, patch;
6586
6915
 
6587
 
        if (!PyArg_ParseTuple(args, ":version"))
6588
 
        return NULL;
6589
 
        db_version(&major, &minor, &patch);
6590
 
        return Py_BuildValue("(iii)", major, minor, patch);
 
6916
    db_version(&major, &minor, &patch);
 
6917
    return Py_BuildValue("(iii)", major, minor, patch);
6591
6918
}
6592
6919
 
6593
6920
 
6594
6921
/* List of functions defined in the module */
6595
 
 
6596
6922
static PyMethodDef bsddb_methods[] = {
6597
6923
    {"DB",          (PyCFunction)DB_construct,          METH_VARARGS | METH_KEYWORDS },
6598
6924
    {"DBEnv",       (PyCFunction)DBEnv_construct,       METH_VARARGS},
6599
 
#if (DBVER >= 43)    
 
6925
#if (DBVER >= 43)
6600
6926
    {"DBSequence",  (PyCFunction)DBSequence_construct,  METH_VARARGS | METH_KEYWORDS },
6601
 
#endif    
6602
 
    {"version",     (PyCFunction)bsddb_version,         METH_VARARGS, bsddb_version_doc},
 
6927
#endif
 
6928
    {"version",     (PyCFunction)bsddb_version,         METH_NOARGS, bsddb_version_doc},
6603
6929
    {NULL,      NULL}       /* sentinel */
6604
6930
};
6605
6931
 
 
6932
 
6606
6933
/* API structure */
6607
6934
static BSDDB_api bsddb_api;
6608
6935
 
6619
6946
#define MODULE_NAME_MAX_LEN     11
6620
6947
static char _bsddbModuleName[MODULE_NAME_MAX_LEN+1] = "_bsddb";
6621
6948
 
 
6949
#if (PY_VERSION_HEX >= 0x03000000)
 
6950
static struct PyModuleDef bsddbmodule = {
 
6951
    PyModuleDef_HEAD_INIT,
 
6952
    _bsddbModuleName,   /* Name of module */
 
6953
    NULL,               /* module documentation, may be NULL */
 
6954
    -1,                 /* size of per-interpreter state of the module,
 
6955
                            or -1 if the module keeps state in global variables. */
 
6956
    bsddb_methods,
 
6957
    NULL,   /* Reload */
 
6958
    NULL,   /* Traverse */
 
6959
    NULL,   /* Clear */
 
6960
    NULL    /* Free */
 
6961
};
 
6962
#endif
 
6963
 
 
6964
 
 
6965
#if (PY_VERSION_HEX < 0x03000000)
6622
6966
DL_EXPORT(void) init_bsddb(void)
 
6967
#else
 
6968
PyMODINIT_FUNC  PyInit__bsddb(void)    /* Note the two underscores */
 
6969
#endif
6623
6970
{
6624
6971
    PyObject* m;
6625
6972
    PyObject* d;
6628
6975
    PyObject* cvsid_s = PyBytes_FromString( rcs_id );
6629
6976
    PyObject* py_api;
6630
6977
 
6631
 
    /* Initialize the type of the new type objects here; doing it here
6632
 
       is required for portability to Windows without requiring C++. */
6633
 
    Py_TYPE(&DB_Type) = &PyType_Type;
6634
 
    Py_TYPE(&DBCursor_Type) = &PyType_Type;
6635
 
    Py_TYPE(&DBEnv_Type) = &PyType_Type;
6636
 
    Py_TYPE(&DBTxn_Type) = &PyType_Type;
6637
 
    Py_TYPE(&DBLock_Type) = &PyType_Type;
6638
 
#if (DBVER >= 43)    
6639
 
    Py_TYPE(&DBSequence_Type) = &PyType_Type;
6640
 
#endif    
6641
 
 
 
6978
    /* Initialize object types */
 
6979
    if ((PyType_Ready(&DB_Type) < 0)
 
6980
        || (PyType_Ready(&DBCursor_Type) < 0)
 
6981
        || (PyType_Ready(&DBEnv_Type) < 0)
 
6982
        || (PyType_Ready(&DBTxn_Type) < 0)
 
6983
        || (PyType_Ready(&DBLock_Type) < 0)
 
6984
#if (DBVER >= 43)
 
6985
        || (PyType_Ready(&DBSequence_Type) < 0)
 
6986
#endif
 
6987
        ) {
 
6988
#if (PY_VERSION_HEX < 0x03000000)
 
6989
        return;
 
6990
#else
 
6991
        return NULL;
 
6992
#endif
 
6993
    }
6642
6994
 
6643
6995
#if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE)
6644
6996
    /* Save the current interpreter, so callbacks can do the right thing. */
6646
6998
#endif
6647
6999
 
6648
7000
    /* Create the module and add the functions */
 
7001
#if (PY_VERSION_HEX < 0x03000000)
6649
7002
    m = Py_InitModule(_bsddbModuleName, bsddb_methods);
6650
 
    if (m == NULL)
6651
 
        return;
 
7003
#else
 
7004
    m=PyModule_Create(&bsddbmodule);
 
7005
#endif
 
7006
    if (m == NULL) {
 
7007
#if (PY_VERSION_HEX < 0x03000000)
 
7008
        return;
 
7009
#else
 
7010
        return NULL;
 
7011
#endif
 
7012
    }
6652
7013
 
6653
7014
    /* Add some symbolic constants to the module */
6654
7015
    d = PyModule_GetDict(m);
6693
7054
    ADD_INT(d, DB_INIT_TXN);
6694
7055
    ADD_INT(d, DB_JOINENV);
6695
7056
 
6696
 
#if (DBVER >= 40)
6697
7057
    ADD_INT(d, DB_XIDDATASIZE);
6698
 
#endif
6699
7058
 
6700
7059
    ADD_INT(d, DB_RECOVER);
6701
7060
    ADD_INT(d, DB_RECOVER_FATAL);
6725
7084
    ADD_INT(d, DB_NOORDERCHK);
6726
7085
    ADD_INT(d, DB_ORDERCHKONLY);
6727
7086
    ADD_INT(d, DB_PR_PAGE);
6728
 
#if ! (DBVER >= 33)
6729
 
    ADD_INT(d, DB_VRFY_FLAGMASK);
6730
 
    ADD_INT(d, DB_PR_HEADERS);
6731
 
#endif
 
7087
 
6732
7088
    ADD_INT(d, DB_PR_RECOVERYTEST);
6733
7089
    ADD_INT(d, DB_SALVAGE);
6734
7090
 
6737
7093
    ADD_INT(d, DB_LOCK_OLDEST);
6738
7094
    ADD_INT(d, DB_LOCK_RANDOM);
6739
7095
    ADD_INT(d, DB_LOCK_YOUNGEST);
6740
 
#if (DBVER >= 33)
6741
7096
    ADD_INT(d, DB_LOCK_MAXLOCKS);
6742
7097
    ADD_INT(d, DB_LOCK_MINLOCKS);
6743
7098
    ADD_INT(d, DB_LOCK_MINWRITE);
6744
 
#endif
6745
7099
 
6746
 
#if (DBVER >= 40)
6747
7100
    ADD_INT(d, DB_LOCK_EXPIRE);
6748
 
#endif
6749
7101
#if (DBVER >= 43)
6750
7102
    ADD_INT(d, DB_LOCK_MAXWRITE);
6751
7103
#endif
6752
7104
 
6753
 
 
6754
 
#if (DBVER >= 33)
6755
 
    /* docs say to use zero instead */
6756
7105
    _addIntToDict(d, "DB_LOCK_CONFLICT", 0);
6757
 
#else
6758
 
    ADD_INT(d, DB_LOCK_CONFLICT);
6759
 
#endif
6760
7106
 
6761
7107
    ADD_INT(d, DB_LOCK_DUMP);
6762
7108
    ADD_INT(d, DB_LOCK_GET);
6773
7119
    ADD_INT(d, DB_LOCK_IWRITE);
6774
7120
    ADD_INT(d, DB_LOCK_IREAD);
6775
7121
    ADD_INT(d, DB_LOCK_IWR);
6776
 
#if (DBVER >= 33)
6777
7122
#if (DBVER < 44)
6778
7123
    ADD_INT(d, DB_LOCK_DIRTY);
6779
7124
#else
6780
7125
    ADD_INT(d, DB_LOCK_READ_UNCOMMITTED);  /* renamed in 4.4 */
6781
7126
#endif
6782
7127
    ADD_INT(d, DB_LOCK_WWRITE);
6783
 
#endif
6784
7128
 
6785
7129
    ADD_INT(d, DB_LOCK_RECORD);
6786
7130
    ADD_INT(d, DB_LOCK_UPGRADE);
6787
7131
    ADD_INT(d, DB_LOCK_SWITCH);
6788
 
#if (DBVER >= 33)
6789
7132
    ADD_INT(d, DB_LOCK_UPGRADE_WRITE);
6790
 
#endif
6791
7133
 
6792
7134
    ADD_INT(d, DB_LOCK_NOWAIT);
6793
7135
    ADD_INT(d, DB_LOCK_RECORD);
6794
7136
    ADD_INT(d, DB_LOCK_UPGRADE);
6795
7137
 
6796
 
#if (DBVER >= 33)
6797
7138
    ADD_INT(d, DB_LSTAT_ABORTED);
6798
7139
#if (DBVER < 43)
6799
7140
    ADD_INT(d, DB_LSTAT_ERR);
6800
7141
#endif
6801
7142
    ADD_INT(d, DB_LSTAT_FREE);
6802
7143
    ADD_INT(d, DB_LSTAT_HELD);
6803
 
#if (DBVER == 33)
6804
 
    ADD_INT(d, DB_LSTAT_NOGRANT);
6805
 
#endif
 
7144
 
6806
7145
    ADD_INT(d, DB_LSTAT_PENDING);
6807
7146
    ADD_INT(d, DB_LSTAT_WAITING);
6808
 
#endif
6809
7147
 
6810
7148
    ADD_INT(d, DB_ARCH_ABS);
6811
7149
    ADD_INT(d, DB_ARCH_DATA);
6842
7180
    ADD_INT(d, DB_CHECKPOINT);
6843
7181
    ADD_INT(d, DB_CURLSN);
6844
7182
#endif
6845
 
#if ((DBVER >= 33) && (DBVER <= 41))
 
7183
#if (DBVER <= 41)
6846
7184
    ADD_INT(d, DB_COMMIT);
6847
7185
#endif
6848
7186
    ADD_INT(d, DB_CONSUME);
6849
7187
    ADD_INT(d, DB_CONSUME_WAIT);
6850
7188
    ADD_INT(d, DB_CURRENT);
6851
 
#if (DBVER >= 33)
6852
7189
    ADD_INT(d, DB_FAST_STAT);
6853
 
#endif
6854
7190
    ADD_INT(d, DB_FIRST);
6855
7191
    ADD_INT(d, DB_FLUSH);
6856
7192
    ADD_INT(d, DB_GET_BOTH);
6878
7214
 
6879
7215
    ADD_INT(d, DB_OPFLAGS_MASK);
6880
7216
    ADD_INT(d, DB_RMW);
6881
 
#if (DBVER >= 33)
6882
7217
    ADD_INT(d, DB_DIRTY_READ);
6883
7218
    ADD_INT(d, DB_MULTIPLE);
6884
7219
    ADD_INT(d, DB_MULTIPLE_KEY);
6885
 
#endif
6886
7220
 
6887
7221
#if (DBVER >= 44)
6888
7222
    ADD_INT(d, DB_READ_UNCOMMITTED);    /* replaces DB_DIRTY_READ in 4.4 */
6889
7223
    ADD_INT(d, DB_READ_COMMITTED);
6890
7224
#endif
6891
7225
 
6892
 
#if (DBVER >= 33)
6893
7226
    ADD_INT(d, DB_DONOTINDEX);
6894
 
#endif
6895
7227
 
6896
7228
#if (DBVER >= 41)
6897
7229
    _addIntToDict(d, "DB_INCOMPLETE", 0);
6909
7241
    ADD_INT(d, DB_OLD_VERSION);
6910
7242
    ADD_INT(d, DB_RUNRECOVERY);
6911
7243
    ADD_INT(d, DB_VERIFY_BAD);
6912
 
#if (DBVER >= 33)
6913
7244
    ADD_INT(d, DB_PAGE_NOTFOUND);
6914
7245
    ADD_INT(d, DB_SECONDARY_BAD);
6915
 
#endif
6916
 
#if (DBVER >= 40)
6917
7246
    ADD_INT(d, DB_STAT_CLEAR);
6918
7247
    ADD_INT(d, DB_REGION_INIT);
6919
7248
    ADD_INT(d, DB_NOLOCKING);
6920
7249
    ADD_INT(d, DB_YIELDCPU);
6921
7250
    ADD_INT(d, DB_PANIC_ENVIRONMENT);
6922
7251
    ADD_INT(d, DB_NOPANIC);
6923
 
#endif
6924
7252
 
6925
7253
#if (DBVER >= 41)
6926
7254
    ADD_INT(d, DB_OVERWRITE);
6961
7289
    ADD_INT(d, DB_TXN_SNAPSHOT);
6962
7290
#endif
6963
7291
 
6964
 
#if (DBVER >= 40)
6965
7292
    ADD_INT(d, DB_VERB_DEADLOCK);
6966
7293
#if (DBVER >= 46)
6967
7294
    ADD_INT(d, DB_VERB_FILEOPS);
6973
7300
#endif
6974
7301
    ADD_INT(d, DB_VERB_REPLICATION);
6975
7302
    ADD_INT(d, DB_VERB_WAITSFOR);
6976
 
#endif
6977
7303
 
6978
7304
#if (DBVER >= 45)
6979
7305
    ADD_INT(d, DB_EVENT_PANIC);
6990
7316
    ADD_INT(d, DB_EVENT_WRITE_FAILED);
6991
7317
#endif
6992
7318
 
6993
 
#if (DBVER >= 40)
 
7319
    ADD_INT(d, DB_REP_DUPMASTER);
 
7320
    ADD_INT(d, DB_REP_HOLDELECTION);
 
7321
#if (DBVER >= 44)
 
7322
    ADD_INT(d, DB_REP_IGNORE);
 
7323
    ADD_INT(d, DB_REP_JOIN_FAILURE);
 
7324
#endif
 
7325
#if (DBVER >= 42)
 
7326
    ADD_INT(d, DB_REP_ISPERM);
 
7327
    ADD_INT(d, DB_REP_NOTPERM);
 
7328
#endif
 
7329
    ADD_INT(d, DB_REP_NEWSITE);
 
7330
 
6994
7331
    ADD_INT(d, DB_REP_MASTER);
6995
7332
    ADD_INT(d, DB_REP_CLIENT);
6996
7333
#if (DBVER >= 45)
7005
7342
    ADD_INT(d, DB_REP_CHECKPOINT_DELAY);
7006
7343
    ADD_INT(d, DB_REP_FULL_ELECTION_TIMEOUT);
7007
7344
#endif
7008
 
#endif
7009
7345
 
7010
7346
#if (DBVER >= 45)
7011
7347
    ADD_INT(d, DB_REPMGR_PEER);
7051
7387
    ADD_INT(d, ENOENT);
7052
7388
    ADD_INT(d, EPERM);
7053
7389
 
7054
 
#if (DBVER >= 40)
7055
7390
    ADD_INT(d, DB_SET_LOCK_TIMEOUT);
7056
7391
    ADD_INT(d, DB_SET_TXN_TIMEOUT);
7057
 
#endif
7058
7392
 
7059
7393
    /* The exception name must be correct for pickled exception *
7060
7394
     * objects to unpickle properly.                            */
7072
7406
    DBError = NULL;     /* used in MAKE_EX so that it derives from nothing */
7073
7407
    MAKE_EX(DBError);
7074
7408
 
 
7409
#if (PY_VERSION_HEX < 0x03000000)
7075
7410
    /* Some magic to make DBNotFoundError and DBKeyEmptyError derive
7076
7411
     * from both DBError and KeyError, since the API only supports
7077
7412
     * using one base class. */
7082
7417
    DBNotFoundError = PyDict_GetItemString(d, "DBNotFoundError");
7083
7418
    DBKeyEmptyError = PyDict_GetItemString(d, "DBKeyEmptyError");
7084
7419
    PyDict_DelItemString(d, "KeyError");
 
7420
#else
 
7421
    /* Since Python 2.5, PyErr_NewException() accepts a tuple, to be able to
 
7422
    ** derive from several classes. We use this new API only for Python 3.0,
 
7423
    ** though.
 
7424
    */
 
7425
    {
 
7426
        PyObject* bases;
 
7427
 
 
7428
        bases = PyTuple_Pack(2, DBError, PyExc_KeyError);
 
7429
 
 
7430
#define MAKE_EX2(name)   name = PyErr_NewException(PYBSDDB_EXCEPTION_BASE #name, bases, NULL); \
 
7431
                         PyDict_SetItemString(d, #name, name)
 
7432
        MAKE_EX2(DBNotFoundError);
 
7433
        MAKE_EX2(DBKeyEmptyError);
 
7434
 
 
7435
#undef MAKE_EX2
 
7436
 
 
7437
        Py_XDECREF(bases);
 
7438
    }
 
7439
#endif
7085
7440
 
7086
7441
 
7087
7442
#if !INCOMPLETE_IS_WARNING
7098
7453
    MAKE_EX(DBNoServerError);
7099
7454
    MAKE_EX(DBNoServerHomeError);
7100
7455
    MAKE_EX(DBNoServerIDError);
7101
 
#if (DBVER >= 33)
7102
7456
    MAKE_EX(DBPageNotFoundError);
7103
7457
    MAKE_EX(DBSecondaryBadError);
7104
 
#endif
7105
7458
 
7106
7459
    MAKE_EX(DBInvalidArgError);
7107
7460
    MAKE_EX(DBAccessError);
7117
7470
    MAKE_EX(DBRepHandleDeadError);
7118
7471
#endif
7119
7472
 
 
7473
    MAKE_EX(DBRepUnavailError);
 
7474
 
7120
7475
#undef MAKE_EX
7121
7476
 
7122
7477
    /* Initiliase the C API structure and add it to the module */
7137
7492
    /* Check for errors */
7138
7493
    if (PyErr_Occurred()) {
7139
7494
        PyErr_Print();
7140
 
        Py_FatalError("can't initialize module _bsddb");
 
7495
        Py_FatalError("can't initialize module _bsddb/_pybsddb");
 
7496
        Py_DECREF(m);
 
7497
        m = NULL;
7141
7498
    }
 
7499
#if (PY_VERSION_HEX < 0x03000000)
 
7500
    return;
 
7501
#else
 
7502
    return m;
 
7503
#endif
7142
7504
}
7143
7505
 
7144
7506
/* allow this module to be named _pybsddb so that it can be installed
7145
7507
 * and imported on top of python >= 2.3 that includes its own older
7146
7508
 * copy of the library named _bsddb without importing the old version. */
 
7509
#if (PY_VERSION_HEX < 0x03000000)
7147
7510
DL_EXPORT(void) init_pybsddb(void)
 
7511
#else
 
7512
PyMODINIT_FUNC PyInit__pybsddb(void)  /* Note the two underscores */
 
7513
#endif
7148
7514
{
7149
7515
    strncpy(_bsddbModuleName, "_pybsddb", MODULE_NAME_MAX_LEN);
 
7516
#if (PY_VERSION_HEX < 0x03000000)
7150
7517
    init_bsddb();
 
7518
#else
 
7519
    return PyInit__bsddb();   /* Note the two underscores */
 
7520
#endif
7151
7521
}
 
7522