Changeset 391 for python/trunk/Modules/_bsddb.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/_bsddb.c
r132 r391 65 65 * http://www.python.org/peps/pep-0291.html 66 66 * 67 * This module contains 6types:67 * This module contains 7 types: 68 68 * 69 69 * DB (Database) … … 73 73 * DBLock (A lock handle) 74 74 * DBSequence (Sequence) 75 * DBSite (Site) 75 76 * 76 77 * More datatypes added: … … 100 101 #undef COMPILING_BSDDB_C 101 102 102 static char *rcs_id = "$Id : _bsddb.c 81029 2010-05-09 14:46:46Z antoine.pitrou$";103 static char *rcs_id = "$Id$"; 103 104 104 105 /* --------------------------------------------------------------------- */ … … 136 137 #define MYDB_END_ALLOW_THREADS Py_END_ALLOW_THREADS; 137 138 138 /* For 2.3, use the PyGILState_ calls */139 #if (PY_VERSION_HEX >= 0x02030000)140 #define MYDB_USE_GILSTATE141 #endif142 143 139 /* and these are for calling C --> Python */ 144 #if defined(MYDB_USE_GILSTATE)145 140 #define MYDB_BEGIN_BLOCK_THREADS \ 146 141 PyGILState_STATE __savestate = PyGILState_Ensure(); 147 142 #define MYDB_END_BLOCK_THREADS \ 148 143 PyGILState_Release(__savestate); 149 #else /* MYDB_USE_GILSTATE */150 /* Pre GILState API - do it the long old way */151 static PyInterpreterState* _db_interpreterState = NULL;152 #define MYDB_BEGIN_BLOCK_THREADS { \153 PyThreadState* prevState; \154 PyThreadState* newState; \155 PyEval_AcquireLock(); \156 newState = PyThreadState_New(_db_interpreterState); \157 prevState = PyThreadState_Swap(newState);158 159 #define MYDB_END_BLOCK_THREADS \160 newState = PyThreadState_Swap(prevState); \161 PyThreadState_Clear(newState); \162 PyEval_ReleaseLock(); \163 PyThreadState_Delete(newState); \164 }165 #endif /* MYDB_USE_GILSTATE */166 144 167 145 #else … … 188 166 static PyObject* DBVerifyBadError; /* DB_VERIFY_BAD */ 189 167 static PyObject* DBNoServerError; /* DB_NOSERVER */ 168 #if (DBVER < 52) 190 169 static PyObject* DBNoServerHomeError; /* DB_NOSERVER_HOME */ 191 170 static PyObject* DBNoServerIDError; /* DB_NOSERVER_ID */ 171 #endif 192 172 static PyObject* DBPageNotFoundError; /* DB_PAGE_NOTFOUND */ 193 173 static PyObject* DBSecondaryBadError; /* DB_SECONDARY_BAD */ … … 196 176 static PyObject* DBAccessError; /* EACCES */ 197 177 static PyObject* DBNoSpaceError; /* ENOSPC */ 198 static PyObject* DBNoMemoryError; /* DB_BUFFER_SMALL (ENOMEM when < 4.3)*/178 static PyObject* DBNoMemoryError; /* DB_BUFFER_SMALL */ 199 179 static PyObject* DBAgainError; /* EAGAIN */ 200 180 static PyObject* DBBusyError; /* EBUSY */ … … 203 183 static PyObject* DBPermissionsError; /* EPERM */ 204 184 205 #if (DBVER >= 42)206 185 static PyObject* DBRepHandleDeadError; /* DB_REP_HANDLE_DEAD */ 207 #endif208 186 #if (DBVER >= 44) 209 187 static PyObject* DBRepLockoutError; /* DB_REP_LOCKOUT */ … … 220 198 221 199 static PyObject* DBRepUnavailError; /* DB_REP_UNAVAIL */ 222 223 #if (DBVER < 43)224 #define DB_BUFFER_SMALL ENOMEM225 #endif226 200 227 201 #if (DBVER < 48) … … 253 227 staticforward PyTypeObject DB_Type, DBCursor_Type, DBEnv_Type, DBTxn_Type, 254 228 DBLock_Type, DBLogCursor_Type; 255 #if (DBVER >= 43)256 229 staticforward PyTypeObject DBSequence_Type; 230 #if (DBVER >= 52) 231 staticforward PyTypeObject DBSite_Type; 257 232 #endif 258 233 … … 268 243 #define DBTxnObject_Check(v) (Py_TYPE(v) == &DBTxn_Type) 269 244 #define DBLockObject_Check(v) (Py_TYPE(v) == &DBLock_Type) 270 #if (DBVER >= 43)271 245 #define DBSequenceObject_Check(v) (Py_TYPE(v) == &DBSequence_Type) 246 #if (DBVER >= 52) 247 #define DBSiteObject_Check(v) (Py_TYPE(v) == &DBSite_Type) 272 248 #endif 273 249 … … 373 349 _CHECK_OBJECT_NOT_CLOSED(logcurs->logc, DBCursorClosedError, DBLogCursor) 374 350 375 #if (DBVER >= 43)376 351 #define CHECK_SEQUENCE_NOT_CLOSED(curs) \ 377 352 _CHECK_OBJECT_NOT_CLOSED(curs->sequence, DBError, DBSequence) 353 354 #if (DBVER >= 52) 355 #define CHECK_SITE_NOT_CLOSED(db_site) \ 356 _CHECK_OBJECT_NOT_CLOSED(db_site->site, DBError, DBSite) 378 357 #endif 379 358 … … 568 547 * library. */ 569 548 static char _db_errmsg[1024]; 570 #if (DBVER <= 42)571 static void _db_errorCallback(const char* prefix, char* msg)572 #else573 549 static void _db_errorCallback(const DB_ENV *db_env, 574 550 const char* prefix, const char* msg) 575 #endif576 551 { 577 552 our_strlcpy(_db_errmsg, msg, sizeof(_db_errmsg)); … … 627 602 } 628 603 629 #if (PY_VERSION_HEX >= 0x02040000)630 604 r = PyTuple_Pack(2, a, b) ; 631 #else632 r = Py_BuildValue("OO", a, b);633 #endif634 605 Py_DECREF(a); 635 606 Py_DECREF(b); … … 697 668 case DB_VERIFY_BAD: errObj = DBVerifyBadError; break; 698 669 case DB_NOSERVER: errObj = DBNoServerError; break; 670 #if (DBVER < 52) 699 671 case DB_NOSERVER_HOME: errObj = DBNoServerHomeError; break; 700 672 case DB_NOSERVER_ID: errObj = DBNoServerIDError; break; 673 #endif 701 674 case DB_PAGE_NOTFOUND: errObj = DBPageNotFoundError; break; 702 675 case DB_SECONDARY_BAD: errObj = DBSecondaryBadError; break; 703 676 case DB_BUFFER_SMALL: errObj = DBNoMemoryError; break; 704 677 705 #if (DBVER >= 43)706 /* ENOMEM and DB_BUFFER_SMALL were one and the same until 4.3 */707 678 case ENOMEM: errObj = PyExc_MemoryError; break; 708 #endif709 679 case EINVAL: errObj = DBInvalidArgError; break; 710 680 case EACCES: errObj = DBAccessError; break; … … 716 686 case EPERM : errObj = DBPermissionsError; break; 717 687 718 #if (DBVER >= 42)719 688 case DB_REP_HANDLE_DEAD : errObj = DBRepHandleDeadError; break; 720 #endif721 689 #if (DBVER >= 44) 722 690 case DB_REP_LOCKOUT : errObj = DBRepLockoutError; break; … … 903 871 } 904 872 905 #if (DBVER >= 43)906 873 /* add an db_seq_t to a dictionary using the given name as a key */ 907 874 static void _addDb_seq_tToDict(PyObject* dict, char *name, db_seq_t value) … … 913 880 Py_XDECREF(v); 914 881 } 915 #endif916 882 917 883 static void _addDB_lsnToDict(PyObject* dict, char *name, DB_LSN value) … … 943 909 self->db = NULL; 944 910 self->children_cursors = NULL; 945 #if (DBVER >=43)946 911 self->children_sequences = NULL; 947 #endif948 912 self->associateCallback = NULL; 949 913 self->btCompareCallback = NULL; 914 self->dupCompareCallback = NULL; 950 915 self->primaryDBType = 0; 951 916 Py_INCREF(Py_None); … … 1029 994 self->btCompareCallback = NULL; 1030 995 } 996 if (self->dupCompareCallback != NULL) { 997 Py_DECREF(self->dupCompareCallback); 998 self->dupCompareCallback = NULL; 999 } 1031 1000 Py_DECREF(self->private_obj); 1032 1001 PyObject_Del(self); … … 1148 1117 self->children_txns = NULL; 1149 1118 self->children_logcursors = NULL ; 1119 #if (DBVER >= 52) 1120 self->children_sites = NULL; 1121 #endif 1150 1122 Py_INCREF(Py_None); 1151 1123 self->private_obj = Py_None; … … 1341 1313 1342 1314 1343 #if (DBVER >= 43)1344 1315 static DBSequenceObject* 1345 1316 newDBSequenceObject(DBObject* mydb, int flags) … … 1395 1366 1396 1367 Py_DECREF(self->mydb); 1368 PyObject_Del(self); 1369 } 1370 1371 #if (DBVER >= 52) 1372 static DBSiteObject* 1373 newDBSiteObject(DB_SITE* sitep, DBEnvObject* env) 1374 { 1375 DBSiteObject* self; 1376 1377 self = PyObject_New(DBSiteObject, &DBSite_Type); 1378 1379 if (self == NULL) 1380 return NULL; 1381 1382 self->site = sitep; 1383 self->env = env; 1384 1385 INSERT_IN_DOUBLE_LINKED_LIST(self->env->children_sites, self); 1386 1387 self->in_weakreflist = NULL; 1388 Py_INCREF(self->env); 1389 return self; 1390 } 1391 1392 /* Forward declaration */ 1393 static PyObject *DBSite_close_internal(DBSiteObject* self); 1394 1395 static void 1396 DBSite_dealloc(DBSiteObject* self) 1397 { 1398 PyObject *dummy; 1399 1400 if (self->site != NULL) { 1401 dummy = DBSite_close_internal(self); 1402 /* 1403 ** Raising exceptions while doing 1404 ** garbage collection is a fatal error. 1405 */ 1406 if (dummy) 1407 Py_DECREF(dummy); 1408 else 1409 PyErr_Clear(); 1410 } 1411 if (self->in_weakreflist != NULL) { 1412 PyObject_ClearWeakRefs((PyObject *) self); 1413 } 1414 Py_DECREF(self->env); 1397 1415 PyObject_Del(self); 1398 1416 } … … 1653 1671 } 1654 1672 1655 #if (DBVER >= 43)1656 1673 while(self->children_sequences) { 1657 1674 dummy=DBSequence_close_internal(self->children_sequences,0,0); 1658 1675 Py_XDECREF(dummy); 1659 1676 } 1660 #endif1661 1677 1662 1678 /* … … 2075 2091 else 2076 2092 keyObj = Build_PyString(key.data, key.size); 2077 #if (PY_VERSION_HEX >= 0x02040000)2078 2093 retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); 2079 #else2080 retval = Py_BuildValue("OOO", keyObj, pkeyObj, dataObj);2081 #endif2082 2094 Py_DECREF(keyObj); 2083 2095 } 2084 2096 else /* return just the pkey and data */ 2085 2097 { 2086 #if (PY_VERSION_HEX >= 0x02040000)2087 2098 retval = PyTuple_Pack(2, pkeyObj, dataObj); 2088 #else2089 retval = Py_BuildValue("OO", pkeyObj, dataObj);2090 #endif2091 2099 } 2092 2100 Py_DECREF(dataObj); … … 2133 2141 err = self->db->get(self->db, txn, &key, &data, flags); 2134 2142 MYDB_END_ALLOW_THREADS; 2135 if ( err == DB_BUFFER_SMALL) {2143 if ((err == DB_BUFFER_SMALL) || (err == 0)) { 2136 2144 retval = NUMBER_FromLong((long)data.size); 2137 2145 err = 0; … … 2386 2394 } 2387 2395 2388 #if (DBVER >= 42)2389 2396 self->db->get_flags(self->db, &self->setflags); 2390 #endif2391 2397 2392 2398 self->flags = flags; … … 2540 2546 2541 2547 static PyObject* 2548 DB_get_dbname(DBObject* self) 2549 { 2550 int err; 2551 const char *filename, *dbname; 2552 2553 CHECK_DB_NOT_CLOSED(self); 2554 2555 MYDB_BEGIN_ALLOW_THREADS; 2556 err = self->db->get_dbname(self->db, &filename, &dbname); 2557 MYDB_END_ALLOW_THREADS; 2558 RETURN_IF_ERR(); 2559 /* If "dbname==NULL", it is correctly converted to "None" */ 2560 return Py_BuildValue("(ss)", filename, dbname); 2561 } 2562 2563 static PyObject* 2564 DB_get_open_flags(DBObject* self) 2565 { 2566 int err; 2567 unsigned int flags; 2568 2569 CHECK_DB_NOT_CLOSED(self); 2570 2571 MYDB_BEGIN_ALLOW_THREADS; 2572 err = self->db->get_open_flags(self->db, &flags); 2573 MYDB_END_ALLOW_THREADS; 2574 RETURN_IF_ERR(); 2575 return NUMBER_FromLong(flags); 2576 } 2577 2578 static PyObject* 2542 2579 DB_set_q_extentsize(DBObject* self, PyObject* args) 2543 2580 { … … 2556 2593 } 2557 2594 2558 #if (DBVER >= 42)2559 2595 static PyObject* 2560 2596 DB_get_q_extentsize(DBObject* self) … … 2571 2607 return NUMBER_FromLong(extentsize); 2572 2608 } 2573 #endif2574 2609 2575 2610 static PyObject* … … 2589 2624 } 2590 2625 2591 #if (DBVER >= 42)2592 2626 static PyObject* 2593 2627 DB_get_bt_minkey(DBObject* self) … … 2604 2638 return NUMBER_FromLong(bt_minkey); 2605 2639 } 2606 #endif2607 2640 2608 2641 static int … … 2741 2774 } 2742 2775 2776 static int 2777 _db_dupCompareCallback(DB* db, 2778 const DBT *leftKey, 2779 const DBT *rightKey) 2780 { 2781 int res = 0; 2782 PyObject *args; 2783 PyObject *result = NULL; 2784 DBObject *self = (DBObject *)db->app_private; 2785 2786 if (self == NULL || self->dupCompareCallback == NULL) { 2787 MYDB_BEGIN_BLOCK_THREADS; 2788 PyErr_SetString(PyExc_TypeError, 2789 (self == 0 2790 ? "DB_dup_compare db is NULL." 2791 : "DB_dup_compare callback is NULL.")); 2792 /* we're in a callback within the DB code, we can't raise */ 2793 PyErr_Print(); 2794 res = _default_cmp(leftKey, rightKey); 2795 MYDB_END_BLOCK_THREADS; 2796 } else { 2797 MYDB_BEGIN_BLOCK_THREADS; 2798 2799 args = BuildValue_SS(leftKey->data, leftKey->size, rightKey->data, rightKey->size); 2800 if (args != NULL) { 2801 result = PyEval_CallObject(self->dupCompareCallback, args); 2802 } 2803 if (args == NULL || result == NULL) { 2804 /* we're in a callback within the DB code, we can't raise */ 2805 PyErr_Print(); 2806 res = _default_cmp(leftKey, rightKey); 2807 } else if (NUMBER_Check(result)) { 2808 res = NUMBER_AsLong(result); 2809 } else { 2810 PyErr_SetString(PyExc_TypeError, 2811 "DB_dup_compare callback MUST return an int."); 2812 /* we're in a callback within the DB code, we can't raise */ 2813 PyErr_Print(); 2814 res = _default_cmp(leftKey, rightKey); 2815 } 2816 2817 Py_XDECREF(args); 2818 Py_XDECREF(result); 2819 2820 MYDB_END_BLOCK_THREADS; 2821 } 2822 return res; 2823 } 2824 2825 static PyObject* 2826 DB_set_dup_compare(DBObject* self, PyObject* comparator) 2827 { 2828 int err; 2829 PyObject *tuple, *result; 2830 2831 CHECK_DB_NOT_CLOSED(self); 2832 2833 if (!PyCallable_Check(comparator)) { 2834 makeTypeError("Callable", comparator); 2835 return NULL; 2836 } 2837 2838 /* 2839 * Perform a test call of the comparator function with two empty 2840 * string objects here. verify that it returns an int (0). 2841 * err if not. 2842 */ 2843 tuple = Py_BuildValue("(ss)", "", ""); 2844 result = PyEval_CallObject(comparator, tuple); 2845 Py_DECREF(tuple); 2846 if (result == NULL) 2847 return NULL; 2848 if (!NUMBER_Check(result)) { 2849 Py_DECREF(result); 2850 PyErr_SetString(PyExc_TypeError, 2851 "callback MUST return an int"); 2852 return NULL; 2853 } else if (NUMBER_AsLong(result) != 0) { 2854 Py_DECREF(result); 2855 PyErr_SetString(PyExc_TypeError, 2856 "callback failed to return 0 on two empty strings"); 2857 return NULL; 2858 } 2859 Py_DECREF(result); 2860 2861 /* We don't accept multiple set_dup_compare operations, in order to 2862 * simplify the code. This would have no real use, as one cannot 2863 * change the function once the db is opened anyway */ 2864 if (self->dupCompareCallback != NULL) { 2865 PyErr_SetString(PyExc_RuntimeError, "set_dup_compare() cannot be called more than once"); 2866 return NULL; 2867 } 2868 2869 Py_INCREF(comparator); 2870 self->dupCompareCallback = comparator; 2871 2872 /* This is to workaround a problem with un-initialized threads (see 2873 comment in DB_associate) */ 2874 #ifdef WITH_THREAD 2875 PyEval_InitThreads(); 2876 #endif 2877 2878 err = self->db->set_dup_compare(self->db, _db_dupCompareCallback); 2879 2880 if (err) { 2881 /* restore the old state in case of error */ 2882 Py_DECREF(comparator); 2883 self->dupCompareCallback = NULL; 2884 } 2885 2886 RETURN_IF_ERR(); 2887 RETURN_NONE(); 2888 } 2889 2743 2890 2744 2891 static PyObject* … … 2760 2907 } 2761 2908 2762 #if (DBVER >= 42)2763 2909 static PyObject* 2764 2910 DB_get_cachesize(DBObject* self) … … 2778 2924 return Py_BuildValue("(iii)", gbytes, bytes, ncache); 2779 2925 } 2780 #endif2781 2926 2782 2927 static PyObject* … … 2798 2943 } 2799 2944 2800 #if (DBVER >= 42)2801 2945 static PyObject* 2802 2946 DB_get_flags(DBObject* self) … … 2813 2957 return NUMBER_FromLong(flags); 2814 2958 } 2815 #endif 2959 2960 static PyObject* 2961 DB_get_transactional(DBObject* self) 2962 { 2963 int err; 2964 2965 CHECK_DB_NOT_CLOSED(self); 2966 2967 MYDB_BEGIN_ALLOW_THREADS; 2968 err = self->db->get_transactional(self->db); 2969 MYDB_END_ALLOW_THREADS; 2970 2971 if(err == 0) { 2972 Py_INCREF(Py_False); 2973 return Py_False; 2974 } else if(err == 1) { 2975 Py_INCREF(Py_True); 2976 return Py_True; 2977 } 2978 2979 /* 2980 ** If we reach there, there was an error. The 2981 ** "return" should be unreachable. 2982 */ 2983 RETURN_IF_ERR(); 2984 assert(0); /* This code SHOULD be unreachable */ 2985 return NULL; 2986 } 2816 2987 2817 2988 static PyObject* … … 2831 3002 } 2832 3003 2833 #if (DBVER >= 42)2834 3004 static PyObject* 2835 3005 DB_get_h_ffactor(DBObject* self) … … 2846 3016 return NUMBER_FromLong(ffactor); 2847 3017 } 2848 #endif2849 3018 2850 3019 static PyObject* … … 2864 3033 } 2865 3034 2866 #if (DBVER >= 42)2867 3035 static PyObject* 2868 3036 DB_get_h_nelem(DBObject* self) … … 2879 3047 return NUMBER_FromLong(nelem); 2880 3048 } 2881 #endif2882 3049 2883 3050 static PyObject* … … 2897 3064 } 2898 3065 2899 #if (DBVER >= 42)2900 3066 static PyObject* 2901 3067 DB_get_lorder(DBObject* self) … … 2912 3078 return NUMBER_FromLong(lorder); 2913 3079 } 2914 #endif2915 3080 2916 3081 static PyObject* … … 2930 3095 } 2931 3096 2932 #if (DBVER >= 42)2933 3097 static PyObject* 2934 3098 DB_get_pagesize(DBObject* self) … … 2945 3109 return NUMBER_FromLong(pagesize); 2946 3110 } 2947 #endif2948 3111 2949 3112 static PyObject* … … 2968 3131 } 2969 3132 2970 #if (DBVER >= 42)2971 3133 static PyObject* 2972 3134 DB_get_re_delim(DBObject* self) … … 2982 3144 return NUMBER_FromLong(re_delim); 2983 3145 } 2984 #endif2985 3146 2986 3147 static PyObject* … … 3000 3161 } 3001 3162 3002 #if (DBVER >= 42)3003 3163 static PyObject* 3004 3164 DB_get_re_len(DBObject* self) … … 3015 3175 return NUMBER_FromLong(re_len); 3016 3176 } 3017 #endif3018 3177 3019 3178 static PyObject* … … 3037 3196 } 3038 3197 3039 #if (DBVER >= 42)3040 3198 static PyObject* 3041 3199 DB_get_re_pad(DBObject* self) … … 3051 3209 return NUMBER_FromLong(re_pad); 3052 3210 } 3053 #endif3054 3211 3055 3212 static PyObject* … … 3070 3227 } 3071 3228 3072 #if (DBVER >= 42)3073 3229 static PyObject* 3074 3230 DB_get_re_source(DBObject* self) … … 3085 3241 return PyBytes_FromString(source); 3086 3242 } 3087 #endif3088 3243 3089 3244 static PyObject* … … 3093 3248 void* sp; 3094 3249 PyObject* d; 3095 #if (DBVER >= 43)3096 3250 PyObject* txnobj = NULL; 3097 3251 DB_TXN *txn = NULL; 3098 3252 static char* kwnames[] = { "flags", "txn", NULL }; 3099 #else 3100 static char* kwnames[] = { "flags", NULL }; 3101 #endif 3102 3103 #if (DBVER >= 43) 3253 3104 3254 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:stat", kwnames, 3105 3255 &flags, &txnobj)) … … 3107 3257 if (!checkTxnObj(txnobj, &txn)) 3108 3258 return NULL; 3109 #else3110 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:stat", kwnames, &flags))3111 return NULL;3112 #endif3113 3259 CHECK_DB_NOT_CLOSED(self); 3114 3260 3115 3261 MYDB_BEGIN_ALLOW_THREADS; 3116 #if (DBVER >= 43)3117 3262 err = self->db->stat(self->db, txn, &sp, flags); 3118 #else3119 err = self->db->stat(self->db, &sp, flags);3120 #endif3121 3263 MYDB_END_ALLOW_THREADS; 3122 3264 RETURN_IF_ERR(); … … 3173 3315 MAKE_BT_ENTRY(dup_pg); 3174 3316 MAKE_BT_ENTRY(over_pg); 3175 #if (DBVER >= 43)3176 3317 MAKE_BT_ENTRY(empty_pg); 3177 #endif3178 3318 MAKE_BT_ENTRY(free); 3179 3319 MAKE_BT_ENTRY(int_pgfree); … … 3215 3355 } 3216 3356 3217 #if (DBVER >= 43)3218 3357 static PyObject* 3219 3358 DB_stat_print(DBObject* self, PyObject* args, PyObject *kwargs) … … 3235 3374 RETURN_NONE(); 3236 3375 } 3237 #endif3238 3376 3239 3377 … … 3382 3520 } 3383 3521 3384 #if (DBVER >= 42)3385 3522 static PyObject* 3386 3523 DB_get_encrypt_flags(DBObject* self) … … 3397 3534 return NUMBER_FromLong(flags); 3398 3535 } 3399 #endif3400 3536 3401 3537 … … 3421 3557 3422 3558 MYDB_BEGIN_ALLOW_THREADS; 3423 #if (DBVER >= 43)3424 3559 err = self->db->stat(self->db, /*txnid*/ NULL, &sp, 0); 3425 #else3426 err = self->db->stat(self->db, &sp, 0);3427 #endif3428 3560 MYDB_END_ALLOW_THREADS; 3429 3561 … … 3869 4001 3870 4002 4003 /* --------------------------------------------------------------------- */ 4004 /* DBSite methods */ 4005 4006 4007 #if (DBVER >= 52) 4008 static PyObject* 4009 DBSite_close_internal(DBSiteObject* self) 4010 { 4011 int err = 0; 4012 4013 if (self->site != NULL) { 4014 EXTRACT_FROM_DOUBLE_LINKED_LIST(self); 4015 4016 MYDB_BEGIN_ALLOW_THREADS; 4017 err = self->site->close(self->site); 4018 MYDB_END_ALLOW_THREADS; 4019 self->site = NULL; 4020 } 4021 RETURN_IF_ERR(); 4022 RETURN_NONE(); 4023 } 4024 4025 static PyObject* 4026 DBSite_close(DBSiteObject* self) 4027 { 4028 return DBSite_close_internal(self); 4029 } 4030 4031 static PyObject* 4032 DBSite_remove(DBSiteObject* self) 4033 { 4034 int err = 0; 4035 4036 CHECK_SITE_NOT_CLOSED(self); 4037 4038 MYDB_BEGIN_ALLOW_THREADS; 4039 err = self->site->remove(self->site); 4040 MYDB_END_ALLOW_THREADS; 4041 4042 RETURN_IF_ERR(); 4043 RETURN_NONE(); 4044 } 4045 4046 static PyObject* 4047 DBSite_get_eid(DBSiteObject* self) 4048 { 4049 int err = 0; 4050 int eid; 4051 4052 CHECK_SITE_NOT_CLOSED(self); 4053 4054 MYDB_BEGIN_ALLOW_THREADS; 4055 err = self->site->get_eid(self->site, &eid); 4056 MYDB_END_ALLOW_THREADS; 4057 4058 RETURN_IF_ERR(); 4059 return NUMBER_FromLong(eid); 4060 } 4061 4062 static PyObject* 4063 DBSite_get_address(DBSiteObject* self) 4064 { 4065 int err = 0; 4066 const char *host; 4067 u_int port; 4068 4069 CHECK_SITE_NOT_CLOSED(self); 4070 4071 MYDB_BEGIN_ALLOW_THREADS; 4072 err = self->site->get_address(self->site, &host, &port); 4073 MYDB_END_ALLOW_THREADS; 4074 4075 RETURN_IF_ERR(); 4076 4077 return Py_BuildValue("(sI)", host, port); 4078 } 4079 4080 static PyObject* 4081 DBSite_get_config(DBSiteObject* self, PyObject* args, PyObject* kwargs) 4082 { 4083 int err = 0; 4084 u_int32_t which, value; 4085 static char* kwnames[] = { "which", NULL }; 4086 4087 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:get_config", kwnames, 4088 &which)) 4089 return NULL; 4090 4091 CHECK_SITE_NOT_CLOSED(self); 4092 4093 MYDB_BEGIN_ALLOW_THREADS; 4094 err = self->site->get_config(self->site, which, &value); 4095 MYDB_END_ALLOW_THREADS; 4096 4097 RETURN_IF_ERR(); 4098 4099 if (value) { 4100 Py_INCREF(Py_True); 4101 return Py_True; 4102 } else { 4103 Py_INCREF(Py_False); 4104 return Py_False; 4105 } 4106 } 4107 4108 static PyObject* 4109 DBSite_set_config(DBSiteObject* self, PyObject* args, PyObject* kwargs) 4110 { 4111 int err = 0; 4112 u_int32_t which, value; 4113 PyObject *valueO; 4114 static char* kwnames[] = { "which", "value", NULL }; 4115 4116 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO:set_config", kwnames, 4117 &which, &valueO)) 4118 return NULL; 4119 4120 CHECK_SITE_NOT_CLOSED(self); 4121 4122 value = PyObject_IsTrue(valueO); 4123 4124 MYDB_BEGIN_ALLOW_THREADS; 4125 err = self->site->set_config(self->site, which, value); 4126 MYDB_END_ALLOW_THREADS; 4127 4128 RETURN_IF_ERR(); 4129 RETURN_NONE(); 4130 } 4131 #endif 4132 3871 4133 3872 4134 /* --------------------------------------------------------------------- */ … … 4128 4390 else 4129 4391 keyObj = Build_PyString(key.data, key.size); 4130 #if (PY_VERSION_HEX >= 0x02040000)4131 4392 retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj); 4132 #else4133 retval = Py_BuildValue("OOO", keyObj, pkeyObj, dataObj);4134 #endif4135 4393 Py_DECREF(keyObj); 4136 4394 FREE_DBT(key); /* 'make_key_dbt' could do a 'malloc' */ … … 4138 4396 else /* return just the pkey and data */ 4139 4397 { 4140 #if (PY_VERSION_HEX >= 0x02040000)4141 4398 retval = PyTuple_Pack(2, pkeyObj, dataObj); 4142 #else4143 retval = Py_BuildValue("OO", pkeyObj, dataObj);4144 #endif4145 4399 } 4146 4400 Py_DECREF(dataObj); … … 4657 4911 Py_XDECREF(dummy); 4658 4912 } 4913 #if (DBVER >= 52) 4914 while(self->children_sites) { 4915 dummy = DBSite_close_internal(self->children_sites); 4916 Py_XDECREF(dummy); 4917 } 4918 #endif 4659 4919 } 4660 4920 … … 4736 4996 4737 4997 MAKE_ENTRY(gbytes); 4998 MAKE_ENTRY(bytes); 4738 4999 MAKE_ENTRY(ncache); 4739 5000 #if (DBVER >= 46) … … 4741 5002 #endif 4742 5003 MAKE_ENTRY(regsize); 4743 #if (DBVER >= 43)4744 5004 MAKE_ENTRY(mmapsize); 4745 5005 MAKE_ENTRY(maxopenfd); 4746 5006 MAKE_ENTRY(maxwrite); 4747 5007 MAKE_ENTRY(maxwrite_sleep); 4748 #endif4749 5008 MAKE_ENTRY(map); 4750 5009 MAKE_ENTRY(cache_hit); … … 4829 5088 free(fsp); 4830 5089 4831 r = Py _BuildValue("(OO)", d, d2);5090 r = PyTuple_Pack(2, d, d2); 4832 5091 Py_DECREF(d); 4833 5092 Py_DECREF(d2); … … 4835 5094 } 4836 5095 4837 #if (DBVER >= 43)4838 5096 static PyObject* 4839 5097 DBEnv_memp_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) … … 4855 5113 RETURN_NONE(); 4856 5114 } 4857 #endif4858 5115 4859 5116 … … 4988 5245 } 4989 5246 4990 #if (DBVER >= 42)4991 5247 static PyObject* 4992 5248 DBEnv_get_encrypt_flags(DBEnvObject* self) … … 5026 5282 return NUMBER_FromLong(timeout); 5027 5283 } 5028 #endif5029 5284 5030 5285 … … 5065 5320 } 5066 5321 5067 #if (DBVER >= 42)5068 5322 static PyObject* 5069 5323 DBEnv_get_shm_key(DBEnvObject* self) … … 5082 5336 return NUMBER_FromLong(shm_key); 5083 5337 } 5084 #endif5085 5338 5086 5339 #if (DBVER >= 46) … … 5171 5424 } 5172 5425 5173 #if (DBVER >= 42)5174 5426 static PyObject* 5175 5427 DBEnv_get_cachesize(DBEnvObject* self) … … 5189 5441 return Py_BuildValue("(iii)", gbytes, bytes, ncache); 5190 5442 } 5191 #endif5192 5443 5193 5444 … … 5209 5460 } 5210 5461 5211 #if (DBVER >= 42)5212 5462 static PyObject* 5213 5463 DBEnv_get_flags(DBEnvObject* self) … … 5224 5474 return NUMBER_FromLong(flags); 5225 5475 } 5226 #endif5227 5476 5228 5477 #if (DBVER >= 47) … … 5424 5673 } 5425 5674 5426 #if (DBVER >= 42)5427 5675 static PyObject* 5428 5676 DBEnv_get_data_dirs(DBEnvObject* self) … … 5464 5712 return tuple; 5465 5713 } 5466 #endif5467 5714 5468 5715 #if (DBVER >= 44) … … 5514 5761 } 5515 5762 5516 #if (DBVER >= 42)5517 5763 static PyObject* 5518 5764 DBEnv_get_lg_bsize(DBEnvObject* self) … … 5529 5775 return NUMBER_FromLong(lg_bsize); 5530 5776 } 5531 #endif5532 5777 5533 5778 static PyObject* … … 5548 5793 } 5549 5794 5550 #if (DBVER >= 42)5551 5795 static PyObject* 5552 5796 DBEnv_get_lg_dir(DBEnvObject* self) … … 5563 5807 return PyBytes_FromString(dirp); 5564 5808 } 5565 #endif5566 5809 5567 5810 static PyObject* … … 5581 5824 } 5582 5825 5583 #if (DBVER >= 42)5584 5826 static PyObject* 5585 5827 DBEnv_get_lg_max(DBEnvObject* self) … … 5596 5838 return NUMBER_FromLong(lg_max); 5597 5839 } 5598 #endif5599 5600 5840 5601 5841 static PyObject* … … 5615 5855 } 5616 5856 5617 #if (DBVER >= 42)5618 5857 static PyObject* 5619 5858 DBEnv_get_lg_regionmax(DBEnvObject* self) … … 5630 5869 return NUMBER_FromLong(lg_regionmax); 5631 5870 } 5632 #endif5633 5871 5634 5872 #if (DBVER >= 47) … … 5681 5919 } 5682 5920 5683 #if (DBVER >= 42)5684 5921 static PyObject* 5685 5922 DBEnv_get_lk_detect(DBEnvObject* self) … … 5696 5933 return NUMBER_FromLong(lk_detect); 5697 5934 } 5698 #endif5699 5700 5935 5701 5936 #if (DBVER < 45) … … 5735 5970 } 5736 5971 5737 #if (DBVER >= 42)5738 5972 static PyObject* 5739 5973 DBEnv_get_lk_max_locks(DBEnvObject* self) … … 5750 5984 return NUMBER_FromLong(lk_max); 5751 5985 } 5752 #endif5753 5986 5754 5987 static PyObject* … … 5768 6001 } 5769 6002 5770 #if (DBVER >= 42)5771 6003 static PyObject* 5772 6004 DBEnv_get_lk_max_lockers(DBEnvObject* self) … … 5783 6015 return NUMBER_FromLong(lk_max); 5784 6016 } 5785 #endif5786 6017 5787 6018 static PyObject* … … 5801 6032 } 5802 6033 5803 #if (DBVER >= 42)5804 6034 static PyObject* 5805 6035 DBEnv_get_lk_max_objects(DBEnvObject* self) … … 5816 6046 return NUMBER_FromLong(lk_max); 5817 6047 } 5818 #endif 5819 5820 #if (DBVER >= 42) 6048 5821 6049 static PyObject* 5822 6050 DBEnv_get_mp_mmapsize(DBEnvObject* self) … … 5833 6061 return NUMBER_FromLong(mmapsize); 5834 6062 } 5835 #endif5836 5837 6063 5838 6064 static PyObject* … … 5870 6096 } 5871 6097 5872 5873 #if (DBVER >= 42)5874 6098 static PyObject* 5875 6099 DBEnv_get_tmp_dir(DBEnvObject* self) … … 5888 6112 return PyBytes_FromString(dirpp); 5889 6113 } 5890 #endif5891 5892 6114 5893 6115 static PyObject* … … 5900 6122 #define PREPLIST_LEN 16 5901 6123 DB_PREPLIST preplist[PREPLIST_LEN]; 5902 #if (DBVER < 48) 6124 #if (DBVER < 48) || (DBVER >= 52) 5903 6125 long retp; 5904 6126 #else … … 6004 6226 } 6005 6227 6006 6007 #if (DBVER >= 42)6008 6228 static PyObject* 6009 6229 DBEnv_get_tx_max(DBEnvObject* self) … … 6020 6240 return PyLong_FromUnsignedLong(max); 6021 6241 } 6022 #endif6023 6024 6242 6025 6243 static PyObject* … … 6039 6257 } 6040 6258 6041 6042 #if (DBVER >= 42)6043 6259 static PyObject* 6044 6260 DBEnv_get_tx_timestamp(DBEnvObject* self) … … 6055 6271 return NUMBER_FromLong(timestamp); 6056 6272 } 6057 #endif6058 6273 6059 6274 static PyObject* … … 6205 6420 6206 6421 6207 #if (DBVER >= 43)6208 6422 static PyObject* 6209 6423 DBEnv_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) … … 6225 6439 RETURN_NONE(); 6226 6440 } 6227 #endif6228 6441 6229 6442 … … 6289 6502 6290 6503 6291 #if (DBVER >= 43)6292 6504 static PyObject* 6293 6505 DBEnv_log_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) … … 6309 6521 RETURN_NONE(); 6310 6522 } 6311 #endif6312 6523 6313 6524 … … 6391 6602 } 6392 6603 6393 #if (DBVER >= 43)6394 6604 static PyObject* 6395 6605 DBEnv_lock_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) … … 6411 6621 RETURN_NONE(); 6412 6622 } 6413 #endif6414 6623 6415 6624 … … 6573 6782 6574 6783 6784 #if (DBVER >= 52) 6785 static PyObject* 6786 DBEnv_repmgr_site(DBEnvObject* self, PyObject* args, PyObject *kwargs) 6787 { 6788 int err; 6789 DB_SITE* site; 6790 char *host; 6791 u_int port; 6792 static char* kwnames[] = {"host", "port", NULL}; 6793 6794 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si:repmgr_site", kwnames, 6795 &host, &port)) 6796 return NULL; 6797 6798 CHECK_ENV_NOT_CLOSED(self); 6799 6800 MYDB_BEGIN_ALLOW_THREADS; 6801 err = self->db_env->repmgr_site(self->db_env, host, port, &site, 0); 6802 MYDB_END_ALLOW_THREADS; 6803 RETURN_IF_ERR(); 6804 return (PyObject*) newDBSiteObject(site, self); 6805 } 6806 6807 static PyObject* 6808 DBEnv_repmgr_site_by_eid(DBEnvObject* self, PyObject* args, PyObject *kwargs) 6809 { 6810 int err; 6811 DB_SITE* site; 6812 int eid; 6813 static char* kwnames[] = {"eid", NULL}; 6814 6815 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:repmgr_site_by_eid", 6816 kwnames, &eid)) 6817 return NULL; 6818 6819 CHECK_ENV_NOT_CLOSED(self); 6820 6821 MYDB_BEGIN_ALLOW_THREADS; 6822 err = self->db_env->repmgr_site_by_eid(self->db_env, eid, &site); 6823 MYDB_END_ALLOW_THREADS; 6824 RETURN_IF_ERR(); 6825 return (PyObject*) newDBSiteObject(site, self); 6826 } 6827 #endif 6828 6829 6575 6830 #if (DBVER >= 44) 6576 6831 static PyObject* … … 6641 6896 6642 6897 6643 #if (DBVER >= 43)6644 6898 static PyObject* 6645 6899 DBEnv_txn_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) … … 6663 6917 RETURN_NONE(); 6664 6918 } 6665 #endif6666 6919 6667 6920 … … 6757 7010 } 6758 7011 7012 #if (DBVER >= 47) 7013 static PyObject* 7014 DBEnv_set_intermediate_dir_mode(DBEnvObject* self, PyObject* args) 7015 { 7016 int err; 7017 const char *mode; 7018 7019 if (!PyArg_ParseTuple(args,"s:set_intermediate_dir_mode", &mode)) 7020 return NULL; 7021 7022 CHECK_ENV_NOT_CLOSED(self); 7023 7024 MYDB_BEGIN_ALLOW_THREADS; 7025 err = self->db_env->set_intermediate_dir_mode(self->db_env, mode); 7026 MYDB_END_ALLOW_THREADS; 7027 RETURN_IF_ERR(); 7028 RETURN_NONE(); 7029 } 7030 7031 static PyObject* 7032 DBEnv_get_intermediate_dir_mode(DBEnvObject* self) 7033 { 7034 int err; 7035 const char *mode; 7036 7037 CHECK_ENV_NOT_CLOSED(self); 7038 7039 MYDB_BEGIN_ALLOW_THREADS; 7040 err = self->db_env->get_intermediate_dir_mode(self->db_env, &mode); 7041 MYDB_END_ALLOW_THREADS; 7042 RETURN_IF_ERR(); 7043 return Py_BuildValue("s", mode); 7044 } 7045 #endif 7046 7047 #if (DBVER < 47) 7048 static PyObject* 7049 DBEnv_set_intermediate_dir(DBEnvObject* self, PyObject* args) 7050 { 7051 int err; 7052 int mode; 7053 u_int32_t flags; 7054 7055 if (!PyArg_ParseTuple(args, "iI:set_intermediate_dir", &mode, &flags)) 7056 return NULL; 7057 7058 CHECK_ENV_NOT_CLOSED(self); 7059 7060 MYDB_BEGIN_ALLOW_THREADS; 7061 err = self->db_env->set_intermediate_dir(self->db_env, mode, flags); 7062 MYDB_END_ALLOW_THREADS; 7063 RETURN_IF_ERR(); 7064 RETURN_NONE(); 7065 } 7066 #endif 7067 7068 static PyObject* 7069 DBEnv_get_open_flags(DBEnvObject* self) 7070 { 7071 int err; 7072 unsigned int flags; 7073 7074 CHECK_ENV_NOT_CLOSED(self); 7075 7076 MYDB_BEGIN_ALLOW_THREADS; 7077 err = self->db_env->get_open_flags(self->db_env, &flags); 7078 MYDB_END_ALLOW_THREADS; 7079 RETURN_IF_ERR(); 7080 return NUMBER_FromLong(flags); 7081 } 6759 7082 6760 7083 #if (DBVER < 48) … … 6782 7105 #endif 6783 7106 6784 #if (DBVER >= 43)6785 7107 static PyObject* 6786 7108 DBEnv_set_mp_max_openfd(DBEnvObject* self, PyObject* args) … … 6856 7178 return Py_BuildValue("(ii)", maxwrite, (int)maxwrite_sleep); 6857 7179 } 6858 #endif6859 7180 6860 7181 … … 6876 7197 } 6877 7198 6878 #if (DBVER >= 42)6879 7199 static PyObject* 6880 7200 DBEnv_get_verbose(DBEnvObject* self, PyObject* args) … … 6894 7214 return PyBool_FromLong(verbose); 6895 7215 } 6896 #endif6897 7216 6898 7217 #if (DBVER >= 45) … … 6976 7295 DBT control, rec; 6977 7296 int envid; 6978 #if (DBVER >= 42)6979 7297 DB_LSN lsn; 6980 #endif6981 7298 6982 7299 if (!PyArg_ParseTuple(args, "OOi:rep_process_message", &control_py, … … 6995 7312 envid, &lsn); 6996 7313 #else 6997 #if (DBVER >= 42)6998 7314 err = self->db_env->rep_process_message(self->db_env, &control, &rec, 6999 7315 &envid, &lsn); 7000 #else7001 err = self->db_env->rep_process_message(self->db_env, &control, &rec,7002 &envid);7003 #endif7004 7316 #endif 7005 7317 MYDB_END_ALLOW_THREADS; … … 7030 7342 break; 7031 7343 } 7032 #if (DBVER >= 42)7033 7344 case DB_REP_NOTPERM : 7034 7345 case DB_REP_ISPERM : 7035 7346 return Py_BuildValue("(i(ll))", err, lsn.file, lsn.offset); 7036 7347 break; 7037 #endif 7038 } 7039 RETURN_IF_ERR(); 7040 return Py_BuildValue("(OO)", Py_None, Py_None); 7348 } 7349 RETURN_IF_ERR(); 7350 return PyTuple_Pack(2, Py_None, Py_None); 7041 7351 } 7042 7352 … … 7063 7373 7064 7374 args = Py_BuildValue( 7065 #if (PY_VERSION_HEX >= 0x02040000)7066 7375 "(OOO(ll)iI)", 7067 #else7068 "(OOO(ll)ii)",7069 #endif7070 7376 dbenv, 7071 7377 a, b, … … 7087 7393 } 7088 7394 7089 #if (DBVER <= 41)7090 static int7091 _DBEnv_rep_transportCallbackOLD(DB_ENV* db_env, const DBT* control, const DBT* rec,7092 int envid, u_int32_t flags)7093 {7094 DB_LSN lsn;7095 7096 lsn.file = -1; /* Dummy values */7097 lsn.offset = -1;7098 return _DBEnv_rep_transportCallback(db_env, control, rec, &lsn, envid,7099 flags);7100 }7101 #endif7102 7103 7395 static PyObject* 7104 7396 DBEnv_rep_set_transport(DBEnvObject* self, PyObject* args) … … 7121 7413 &_DBEnv_rep_transportCallback); 7122 7414 #else 7123 #if (DBVER >= 42)7124 7415 err = self->db_env->set_rep_transport(self->db_env, envid, 7125 7416 &_DBEnv_rep_transportCallback); 7126 #else7127 err = self->db_env->set_rep_transport(self->db_env, envid,7128 &_DBEnv_rep_transportCallbackOLD);7129 #endif7130 7417 #endif 7131 7418 MYDB_END_ALLOW_THREADS; … … 7167 7454 MYDB_END_ALLOW_THREADS; 7168 7455 RETURN_IF_ERR(); 7169 #if (PY_VERSION_HEX >= 0x02040000)7170 7456 return Py_BuildValue("II", minimum, maximum); 7171 #else7172 return Py_BuildValue("ii", minimum, maximum);7173 #endif7174 7457 } 7175 7458 #endif … … 7258 7541 CHECK_ENV_NOT_CLOSED(self); 7259 7542 MYDB_BEGIN_ALLOW_THREADS; 7260 err = self->db_env->rep_elect(self->db_env, n votes, nvotes, 0);7543 err = self->db_env->rep_elect(self->db_env, nsites, nvotes, 0); 7261 7544 MYDB_END_ALLOW_THREADS; 7262 7545 RETURN_IF_ERR(); … … 7423 7706 unsigned int fast, slow; 7424 7707 7425 #if (PY_VERSION_HEX >= 0x02040000)7426 7708 if (!PyArg_ParseTuple(args,"II:rep_set_clockskew", &fast, &slow)) 7427 7709 return NULL; 7428 #else7429 if (!PyArg_ParseTuple(args,"ii:rep_set_clockskew", &fast, &slow))7430 return NULL;7431 #endif7432 7710 7433 7711 CHECK_ENV_NOT_CLOSED(self); … … 7451 7729 MYDB_END_ALLOW_THREADS; 7452 7730 RETURN_IF_ERR(); 7453 #if (PY_VERSION_HEX >= 0x02040000)7454 7731 return Py_BuildValue("(II)", fast, slow); 7455 #else 7456 return Py_BuildValue("(ii)", fast, slow); 7457 #endif 7458 } 7459 #endif 7460 7461 #if (DBVER >= 43) 7732 } 7733 #endif 7734 7462 7735 static PyObject* 7463 7736 DBEnv_rep_stat_print(DBEnvObject* self, PyObject* args, PyObject *kwargs) … … 7479 7752 RETURN_NONE(); 7480 7753 } 7481 #endif7482 7754 7483 7755 static PyObject* … … 7520 7792 #endif 7521 7793 MAKE_ENTRY(dupmasters); 7522 #if (DBVER >= 43)7523 7794 MAKE_ENTRY(egen); 7524 7795 MAKE_ENTRY(election_nvotes); … … 7529 7800 MAKE_ENTRY(next_pg); 7530 7801 MAKE_ENTRY(waiting_pg); 7531 #endif7532 7802 MAKE_ENTRY(election_cur_winner); 7533 7803 MAKE_ENTRY(election_gen); … … 7609 7879 } 7610 7880 7881 #if (DBVER < 52) 7611 7882 static PyObject* 7612 7883 DBEnv_repmgr_set_local_site(DBEnvObject* self, PyObject* args, PyObject* … … 7655 7926 return NUMBER_FromLong(eidp); 7656 7927 } 7928 #endif 7657 7929 7658 7930 static PyObject* … … 7715 7987 return NULL; 7716 7988 } 7717 #if (PY_VERSION_HEX >= 0x02040000)7718 7989 tuple=Py_BuildValue("(sII)", listp[countp].host, 7719 7990 listp[countp].port, listp[countp].status); 7720 #else7721 tuple=Py_BuildValue("(sii)", listp[countp].host,7722 listp[countp].port, listp[countp].status);7723 #endif7724 7991 if(!tuple) { 7725 7992 Py_DECREF(key); … … 7825 8092 { 7826 8093 DBObject *db; 7827 #if (DBVER >= 43)7828 8094 DBSequenceObject *dbs; 7829 #endif7830 8095 7831 8096 while (txn->children_dbs) { … … 7843 8108 } 7844 8109 7845 #if (DBVER >= 43)7846 8110 while (txn->children_sequences) { 7847 8111 dbs=txn->children_sequences; … … 7857 8121 } 7858 8122 } 7859 #endif7860 8123 } 7861 8124 … … 7954 8217 7955 8218 _close_transaction_cursors(self); 7956 #if (DBVER >= 43)7957 8219 while (self->children_sequences) { 7958 8220 dummy=DBSequence_close_internal(self->children_sequences,0,0); 7959 8221 Py_XDECREF(dummy); 7960 8222 } 7961 #endif7962 8223 while (self->children_dbs) { 7963 8224 dummy=DB_close_internal(self->children_dbs, 0, 0); … … 8095 8356 8096 8357 8097 #if (DBVER >= 43)8098 8358 /* --------------------------------------------------------------------- */ 8099 8359 /* DBSequence methods */ … … 8445 8705 return dict_stat; 8446 8706 } 8447 #endif8448 8707 8449 8708 … … 8483 8742 {"rename", (PyCFunction)DB_rename, METH_VARARGS}, 8484 8743 {"set_bt_minkey", (PyCFunction)DB_set_bt_minkey, METH_VARARGS}, 8485 #if (DBVER >= 42)8486 8744 {"get_bt_minkey", (PyCFunction)DB_get_bt_minkey, METH_NOARGS}, 8487 #endif8488 8745 {"set_bt_compare", (PyCFunction)DB_set_bt_compare, METH_O}, 8489 8746 {"set_cachesize", (PyCFunction)DB_set_cachesize, METH_VARARGS}, 8490 #if (DBVER >= 42)8491 8747 {"get_cachesize", (PyCFunction)DB_get_cachesize, METH_NOARGS}, 8492 #endif 8748 {"set_dup_compare", (PyCFunction)DB_set_dup_compare, METH_O}, 8493 8749 {"set_encrypt", (PyCFunction)DB_set_encrypt, METH_VARARGS|METH_KEYWORDS}, 8494 #if (DBVER >= 42)8495 8750 {"get_encrypt_flags", (PyCFunction)DB_get_encrypt_flags, METH_NOARGS}, 8496 #endif8497 8498 8751 {"set_flags", (PyCFunction)DB_set_flags, METH_VARARGS}, 8499 #if (DBVER >= 42)8500 8752 {"get_flags", (PyCFunction)DB_get_flags, METH_NOARGS}, 8501 #endif 8753 {"get_transactional", (PyCFunction)DB_get_transactional, METH_NOARGS}, 8502 8754 {"set_h_ffactor", (PyCFunction)DB_set_h_ffactor, METH_VARARGS}, 8503 #if (DBVER >= 42)8504 8755 {"get_h_ffactor", (PyCFunction)DB_get_h_ffactor, METH_NOARGS}, 8505 #endif8506 8756 {"set_h_nelem", (PyCFunction)DB_set_h_nelem, METH_VARARGS}, 8507 #if (DBVER >= 42)8508 8757 {"get_h_nelem", (PyCFunction)DB_get_h_nelem, METH_NOARGS}, 8509 #endif8510 8758 {"set_lorder", (PyCFunction)DB_set_lorder, METH_VARARGS}, 8511 #if (DBVER >= 42)8512 8759 {"get_lorder", (PyCFunction)DB_get_lorder, METH_NOARGS}, 8513 #endif8514 8760 {"set_pagesize", (PyCFunction)DB_set_pagesize, METH_VARARGS}, 8515 #if (DBVER >= 42)8516 8761 {"get_pagesize", (PyCFunction)DB_get_pagesize, METH_NOARGS}, 8517 #endif8518 8762 {"set_re_delim", (PyCFunction)DB_set_re_delim, METH_VARARGS}, 8519 #if (DBVER >= 42)8520 8763 {"get_re_delim", (PyCFunction)DB_get_re_delim, METH_NOARGS}, 8521 #endif8522 8764 {"set_re_len", (PyCFunction)DB_set_re_len, METH_VARARGS}, 8523 #if (DBVER >= 42)8524 8765 {"get_re_len", (PyCFunction)DB_get_re_len, METH_NOARGS}, 8525 #endif8526 8766 {"set_re_pad", (PyCFunction)DB_set_re_pad, METH_VARARGS}, 8527 #if (DBVER >= 42)8528 8767 {"get_re_pad", (PyCFunction)DB_get_re_pad, METH_NOARGS}, 8529 #endif8530 8768 {"set_re_source", (PyCFunction)DB_set_re_source, METH_VARARGS}, 8531 #if (DBVER >= 42)8532 8769 {"get_re_source", (PyCFunction)DB_get_re_source, METH_NOARGS}, 8533 #endif8534 8770 {"set_q_extentsize",(PyCFunction)DB_set_q_extentsize, METH_VARARGS}, 8535 #if (DBVER >= 42)8536 8771 {"get_q_extentsize",(PyCFunction)DB_get_q_extentsize, METH_NOARGS}, 8537 #endif8538 8772 {"set_private", (PyCFunction)DB_set_private, METH_O}, 8539 8773 {"get_private", (PyCFunction)DB_get_private, METH_NOARGS}, … … 8542 8776 {"get_priority", (PyCFunction)DB_get_priority, METH_NOARGS}, 8543 8777 #endif 8778 {"get_dbname", (PyCFunction)DB_get_dbname, METH_NOARGS}, 8779 {"get_open_flags", (PyCFunction)DB_get_open_flags, METH_NOARGS}, 8544 8780 {"stat", (PyCFunction)DB_stat, METH_VARARGS|METH_KEYWORDS}, 8545 #if (DBVER >= 43)8546 8781 {"stat_print", (PyCFunction)DB_stat_print, 8547 8782 METH_VARARGS|METH_KEYWORDS}, 8548 #endif8549 8783 {"sync", (PyCFunction)DB_sync, METH_VARARGS}, 8550 8784 {"truncate", (PyCFunction)DB_truncate, METH_VARARGS|METH_KEYWORDS}, … … 8628 8862 }; 8629 8863 8864 #if (DBVER >= 52) 8865 static PyMethodDef DBSite_methods[] = { 8866 {"get_config", (PyCFunction)DBSite_get_config, 8867 METH_VARARGS | METH_KEYWORDS}, 8868 {"set_config", (PyCFunction)DBSite_set_config, 8869 METH_VARARGS | METH_KEYWORDS}, 8870 {"remove", (PyCFunction)DBSite_remove, METH_NOARGS}, 8871 {"get_eid", (PyCFunction)DBSite_get_eid, METH_NOARGS}, 8872 {"get_address", (PyCFunction)DBSite_get_address, METH_NOARGS}, 8873 {"close", (PyCFunction)DBSite_close, METH_NOARGS}, 8874 {NULL, NULL} /* sentinel */ 8875 }; 8876 #endif 8630 8877 8631 8878 static PyMethodDef DBEnv_methods[] = { … … 8640 8887 #endif 8641 8888 {"set_encrypt", (PyCFunction)DBEnv_set_encrypt, METH_VARARGS|METH_KEYWORDS}, 8642 #if (DBVER >= 42)8643 8889 {"get_encrypt_flags", (PyCFunction)DBEnv_get_encrypt_flags, METH_NOARGS}, 8644 8890 {"get_timeout", (PyCFunction)DBEnv_get_timeout, 8645 8891 METH_VARARGS|METH_KEYWORDS}, 8646 #endif8647 8892 {"set_timeout", (PyCFunction)DBEnv_set_timeout, METH_VARARGS|METH_KEYWORDS}, 8648 8893 {"set_shm_key", (PyCFunction)DBEnv_set_shm_key, METH_VARARGS}, 8649 #if (DBVER >= 42)8650 8894 {"get_shm_key", (PyCFunction)DBEnv_get_shm_key, METH_NOARGS}, 8651 #endif8652 8895 #if (DBVER >= 46) 8653 8896 {"set_cache_max", (PyCFunction)DBEnv_set_cache_max, METH_VARARGS}, … … 8655 8898 #endif 8656 8899 {"set_cachesize", (PyCFunction)DBEnv_set_cachesize, METH_VARARGS}, 8657 #if (DBVER >= 42)8658 8900 {"get_cachesize", (PyCFunction)DBEnv_get_cachesize, METH_NOARGS}, 8659 #endif8660 8901 {"memp_trickle", (PyCFunction)DBEnv_memp_trickle, METH_VARARGS}, 8661 8902 {"memp_sync", (PyCFunction)DBEnv_memp_sync, METH_VARARGS}, 8662 8903 {"memp_stat", (PyCFunction)DBEnv_memp_stat, 8663 8904 METH_VARARGS|METH_KEYWORDS}, 8664 #if (DBVER >= 43)8665 8905 {"memp_stat_print", (PyCFunction)DBEnv_memp_stat_print, 8666 8906 METH_VARARGS|METH_KEYWORDS}, 8667 #endif8668 8907 #if (DBVER >= 44) 8669 8908 {"mutex_set_max", (PyCFunction)DBEnv_mutex_set_max, METH_VARARGS}, … … 8686 8925 #endif 8687 8926 {"set_data_dir", (PyCFunction)DBEnv_set_data_dir, METH_VARARGS}, 8688 #if (DBVER >= 42)8689 8927 {"get_data_dirs", (PyCFunction)DBEnv_get_data_dirs, METH_NOARGS}, 8690 #endif8691 #if (DBVER >= 42)8692 8928 {"get_flags", (PyCFunction)DBEnv_get_flags, METH_NOARGS}, 8693 #endif8694 8929 {"set_flags", (PyCFunction)DBEnv_set_flags, METH_VARARGS}, 8695 8930 #if (DBVER >= 47) … … 8698 8933 #endif 8699 8934 {"set_lg_bsize", (PyCFunction)DBEnv_set_lg_bsize, METH_VARARGS}, 8700 #if (DBVER >= 42)8701 8935 {"get_lg_bsize", (PyCFunction)DBEnv_get_lg_bsize, METH_NOARGS}, 8702 #endif8703 8936 {"set_lg_dir", (PyCFunction)DBEnv_set_lg_dir, METH_VARARGS}, 8704 #if (DBVER >= 42)8705 8937 {"get_lg_dir", (PyCFunction)DBEnv_get_lg_dir, METH_NOARGS}, 8706 #endif8707 8938 {"set_lg_max", (PyCFunction)DBEnv_set_lg_max, METH_VARARGS}, 8708 #if (DBVER >= 42)8709 8939 {"get_lg_max", (PyCFunction)DBEnv_get_lg_max, METH_NOARGS}, 8710 #endif8711 8940 {"set_lg_regionmax",(PyCFunction)DBEnv_set_lg_regionmax, METH_VARARGS}, 8712 #if (DBVER >= 42)8713 8941 {"get_lg_regionmax",(PyCFunction)DBEnv_get_lg_regionmax, METH_NOARGS}, 8714 #endif8715 8942 #if (DBVER >= 44) 8716 8943 {"set_lg_filemode", (PyCFunction)DBEnv_set_lg_filemode, METH_VARARGS}, … … 8722 8949 #endif 8723 8950 {"set_lk_detect", (PyCFunction)DBEnv_set_lk_detect, METH_VARARGS}, 8724 #if (DBVER >= 42)8725 8951 {"get_lk_detect", (PyCFunction)DBEnv_get_lk_detect, METH_NOARGS}, 8726 #endif8727 8952 #if (DBVER < 45) 8728 8953 {"set_lk_max", (PyCFunction)DBEnv_set_lk_max, METH_VARARGS}, 8729 8954 #endif 8730 8955 {"set_lk_max_locks", (PyCFunction)DBEnv_set_lk_max_locks, METH_VARARGS}, 8731 #if (DBVER >= 42)8732 8956 {"get_lk_max_locks", (PyCFunction)DBEnv_get_lk_max_locks, METH_NOARGS}, 8733 #endif8734 8957 {"set_lk_max_lockers", (PyCFunction)DBEnv_set_lk_max_lockers, METH_VARARGS}, 8735 #if (DBVER >= 42)8736 8958 {"get_lk_max_lockers", (PyCFunction)DBEnv_get_lk_max_lockers, METH_NOARGS}, 8737 #endif8738 8959 {"set_lk_max_objects", (PyCFunction)DBEnv_set_lk_max_objects, METH_VARARGS}, 8739 #if (DBVER >= 42)8740 8960 {"get_lk_max_objects", (PyCFunction)DBEnv_get_lk_max_objects, METH_NOARGS}, 8741 #endif8742 #if (DBVER >= 43)8743 8961 {"stat_print", (PyCFunction)DBEnv_stat_print, 8744 8962 METH_VARARGS|METH_KEYWORDS}, 8745 #endif8746 8963 {"set_mp_mmapsize", (PyCFunction)DBEnv_set_mp_mmapsize, METH_VARARGS}, 8747 #if (DBVER >= 42)8748 8964 {"get_mp_mmapsize", (PyCFunction)DBEnv_get_mp_mmapsize, METH_NOARGS}, 8749 #endif8750 8965 {"set_tmp_dir", (PyCFunction)DBEnv_set_tmp_dir, METH_VARARGS}, 8751 #if (DBVER >= 42)8752 8966 {"get_tmp_dir", (PyCFunction)DBEnv_get_tmp_dir, METH_NOARGS}, 8753 #endif8754 8967 {"txn_begin", (PyCFunction)DBEnv_txn_begin, METH_VARARGS|METH_KEYWORDS}, 8755 8968 {"txn_checkpoint", (PyCFunction)DBEnv_txn_checkpoint, METH_VARARGS}, 8756 8969 {"txn_stat", (PyCFunction)DBEnv_txn_stat, METH_VARARGS}, 8757 #if (DBVER >= 43)8758 8970 {"txn_stat_print", (PyCFunction)DBEnv_txn_stat_print, 8759 8971 METH_VARARGS|METH_KEYWORDS}, 8760 #endif8761 #if (DBVER >= 42)8762 8972 {"get_tx_max", (PyCFunction)DBEnv_get_tx_max, METH_NOARGS}, 8763 8973 {"get_tx_timestamp", (PyCFunction)DBEnv_get_tx_timestamp, METH_NOARGS}, 8764 #endif8765 8974 {"set_tx_max", (PyCFunction)DBEnv_set_tx_max, METH_VARARGS}, 8766 8975 {"set_tx_timestamp", (PyCFunction)DBEnv_set_tx_timestamp, METH_VARARGS}, … … 8771 8980 {"lock_put", (PyCFunction)DBEnv_lock_put, METH_VARARGS}, 8772 8981 {"lock_stat", (PyCFunction)DBEnv_lock_stat, METH_VARARGS}, 8773 #if (DBVER >= 43)8774 8982 {"lock_stat_print", (PyCFunction)DBEnv_lock_stat_print, 8775 8983 METH_VARARGS|METH_KEYWORDS}, 8776 #endif8777 8984 {"log_cursor", (PyCFunction)DBEnv_log_cursor, METH_NOARGS}, 8778 8985 {"log_file", (PyCFunction)DBEnv_log_file, METH_VARARGS}, … … 8784 8991 {"log_flush", (PyCFunction)DBEnv_log_flush, METH_NOARGS}, 8785 8992 {"log_stat", (PyCFunction)DBEnv_log_stat, METH_VARARGS}, 8786 #if (DBVER >= 43)8787 8993 {"log_stat_print", (PyCFunction)DBEnv_log_stat_print, 8788 8994 METH_VARARGS|METH_KEYWORDS}, 8789 #endif8790 8995 #if (DBVER >= 44) 8791 8996 {"fileid_reset", (PyCFunction)DBEnv_fileid_reset, METH_VARARGS|METH_KEYWORDS}, … … 8796 9001 #if (DBVER < 48) 8797 9002 {"set_rpc_server", (PyCFunction)DBEnv_set_rpc_server, 8798 METH_VARARGS||METH_KEYWORDS}, 8799 #endif 8800 #if (DBVER >= 43) 9003 METH_VARARGS|METH_KEYWORDS}, 9004 #endif 8801 9005 {"set_mp_max_openfd", (PyCFunction)DBEnv_set_mp_max_openfd, METH_VARARGS}, 8802 9006 {"get_mp_max_openfd", (PyCFunction)DBEnv_get_mp_max_openfd, METH_NOARGS}, 8803 9007 {"set_mp_max_write", (PyCFunction)DBEnv_set_mp_max_write, METH_VARARGS}, 8804 9008 {"get_mp_max_write", (PyCFunction)DBEnv_get_mp_max_write, METH_NOARGS}, 8805 #endif8806 9009 {"set_verbose", (PyCFunction)DBEnv_set_verbose, METH_VARARGS}, 8807 #if (DBVER >= 42) 8808 {"get_verbose", (PyCFunction)DBEnv_get_verbose, METH_VARARGS}, 8809 #endif 8810 {"set_private", (PyCFunction)DBEnv_set_private, METH_O}, 8811 {"get_private", (PyCFunction)DBEnv_get_private, METH_NOARGS}, 9010 {"get_verbose", (PyCFunction)DBEnv_get_verbose, METH_VARARGS}, 9011 {"set_private", (PyCFunction)DBEnv_set_private, METH_O}, 9012 {"get_private", (PyCFunction)DBEnv_get_private, METH_NOARGS}, 9013 {"get_open_flags", (PyCFunction)DBEnv_get_open_flags, METH_NOARGS}, 9014 #if (DBVER >= 47) 9015 {"set_intermediate_dir_mode", (PyCFunction)DBEnv_set_intermediate_dir_mode, 9016 METH_VARARGS}, 9017 {"get_intermediate_dir_mode", (PyCFunction)DBEnv_get_intermediate_dir_mode, 9018 METH_NOARGS}, 9019 #endif 9020 #if (DBVER < 47) 9021 {"set_intermediate_dir", (PyCFunction)DBEnv_set_intermediate_dir, 9022 METH_VARARGS}, 9023 #endif 8812 9024 {"rep_start", (PyCFunction)DBEnv_rep_start, 8813 9025 METH_VARARGS|METH_KEYWORDS}, … … 8848 9060 {"rep_stat", (PyCFunction)DBEnv_rep_stat, 8849 9061 METH_VARARGS|METH_KEYWORDS}, 8850 #if (DBVER >= 43)8851 9062 {"rep_stat_print", (PyCFunction)DBEnv_rep_stat_print, 8852 9063 METH_VARARGS|METH_KEYWORDS}, 8853 #endif8854 9064 8855 9065 #if (DBVER >= 45) 8856 9066 {"repmgr_start", (PyCFunction)DBEnv_repmgr_start, 8857 9067 METH_VARARGS|METH_KEYWORDS}, 9068 #if (DBVER < 52) 8858 9069 {"repmgr_set_local_site", (PyCFunction)DBEnv_repmgr_set_local_site, 8859 9070 METH_VARARGS|METH_KEYWORDS}, 8860 9071 {"repmgr_add_remote_site", (PyCFunction)DBEnv_repmgr_add_remote_site, 8861 9072 METH_VARARGS|METH_KEYWORDS}, 9073 #endif 8862 9074 {"repmgr_set_ack_policy", (PyCFunction)DBEnv_repmgr_set_ack_policy, 8863 9075 METH_VARARGS}, … … 8872 9084 {"repmgr_stat_print", (PyCFunction)DBEnv_repmgr_stat_print, 8873 9085 METH_VARARGS|METH_KEYWORDS}, 9086 #endif 9087 #if (DBVER >= 52) 9088 {"repmgr_site", (PyCFunction)DBEnv_repmgr_site, 9089 METH_VARARGS | METH_KEYWORDS}, 9090 {"repmgr_site_by_eid", (PyCFunction)DBEnv_repmgr_site_by_eid, 9091 METH_VARARGS | METH_KEYWORDS}, 8874 9092 #endif 8875 9093 {NULL, NULL} /* sentinel */ … … 8893 9111 8894 9112 8895 #if (DBVER >= 43)8896 9113 static PyMethodDef DBSequence_methods[] = { 8897 9114 {"close", (PyCFunction)DBSequence_close, METH_VARARGS}, … … 8913 9130 {NULL, NULL} /* sentinel */ 8914 9131 }; 8915 #endif8916 9132 8917 9133 … … 8923 9139 CHECK_ENV_NOT_CLOSED(self); 8924 9140 8925 #if (DBVER >= 42)8926 9141 MYDB_BEGIN_ALLOW_THREADS; 8927 9142 self->db_env->get_home(self->db_env, &home); 8928 9143 MYDB_END_ALLOW_THREADS; 8929 #else8930 home=self->db_env->db_home;8931 #endif8932 9144 8933 9145 if (home == NULL) { … … 9071 9283 }; 9072 9284 9285 #if (DBVER >= 52) 9286 statichere PyTypeObject DBSite_Type = { 9287 #if (PY_VERSION_HEX < 0x03000000) 9288 PyObject_HEAD_INIT(NULL) 9289 0, /*ob_size*/ 9290 #else 9291 PyVarObject_HEAD_INIT(NULL, 0) 9292 #endif 9293 "DBSite", /*tp_name*/ 9294 sizeof(DBSiteObject), /*tp_basicsize*/ 9295 0, /*tp_itemsize*/ 9296 /* methods */ 9297 (destructor)DBSite_dealloc,/*tp_dealloc*/ 9298 0, /*tp_print*/ 9299 0, /*tp_getattr*/ 9300 0, /*tp_setattr*/ 9301 0, /*tp_compare*/ 9302 0, /*tp_repr*/ 9303 0, /*tp_as_number*/ 9304 0, /*tp_as_sequence*/ 9305 0, /*tp_as_mapping*/ 9306 0, /*tp_hash*/ 9307 0, /*tp_call*/ 9308 0, /*tp_str*/ 9309 0, /*tp_getattro*/ 9310 0, /*tp_setattro*/ 9311 0, /*tp_as_buffer*/ 9312 #if (PY_VERSION_HEX < 0x03000000) 9313 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */ 9314 #else 9315 Py_TPFLAGS_DEFAULT, /* tp_flags */ 9316 #endif 9317 0, /* tp_doc */ 9318 0, /* tp_traverse */ 9319 0, /* tp_clear */ 9320 0, /* tp_richcompare */ 9321 offsetof(DBSiteObject, in_weakreflist), /* tp_weaklistoffset */ 9322 0, /*tp_iter*/ 9323 0, /*tp_iternext*/ 9324 DBSite_methods, /*tp_methods*/ 9325 0, /*tp_members*/ 9326 }; 9327 #endif 9073 9328 9074 9329 statichere PyTypeObject DBEnv_Type = { … … 9196 9451 }; 9197 9452 9198 #if (DBVER >= 43)9199 9453 statichere PyTypeObject DBSequence_Type = { 9200 9454 #if (PY_VERSION_HEX < 0x03000000) … … 9238 9492 0, /*tp_members*/ 9239 9493 }; 9240 #endif9241 9494 9242 9495 /* --------------------------------------------------------------------- */ … … 9272 9525 } 9273 9526 9274 #if (DBVER >= 43)9275 9527 static PyObject* 9276 9528 DBSequence_construct(PyObject* self, PyObject* args, PyObject* kwargs) … … 9288 9540 return (PyObject* )newDBSequenceObject((DBObject*)dbobj, flags); 9289 9541 } 9290 #endif9291 9542 9292 9543 static char bsddb_version_doc[] = … … 9299 9550 int major, minor, patch; 9300 9551 9552 /* This should be instantaneous, no need to release the GIL */ 9301 9553 db_version(&major, &minor, &patch); 9302 9554 return Py_BuildValue("(iii)", major, minor, patch); 9303 9555 } 9556 9557 #if (DBVER >= 50) 9558 static PyObject* 9559 bsddb_version_full(PyObject* self) 9560 { 9561 char *version_string; 9562 int family, release, major, minor, patch; 9563 9564 /* This should be instantaneous, no need to release the GIL */ 9565 version_string = db_full_version(&family, &release, &major, &minor, &patch); 9566 return Py_BuildValue("(siiiii)", 9567 version_string, family, release, major, minor, patch); 9568 } 9569 #endif 9304 9570 9305 9571 … … 9308 9574 {"DB", (PyCFunction)DB_construct, METH_VARARGS | METH_KEYWORDS }, 9309 9575 {"DBEnv", (PyCFunction)DBEnv_construct, METH_VARARGS}, 9310 #if (DBVER >= 43)9311 9576 {"DBSequence", (PyCFunction)DBSequence_construct, METH_VARARGS | METH_KEYWORDS }, 9312 #endif9313 9577 {"version", (PyCFunction)bsddb_version, METH_NOARGS, bsddb_version_doc}, 9578 #if (DBVER >= 50) 9579 {"full_version", (PyCFunction)bsddb_version_full, METH_NOARGS}, 9580 #endif 9314 9581 {NULL, NULL} /* sentinel */ 9315 9582 }; … … 9329 9596 #define ADD_INT(dict, NAME) _addIntToDict(dict, #NAME, NAME) 9330 9597 9598 /* 9599 ** We can rename the module at import time, so the string allocated 9600 ** must be big enough, and any use of the name must use this particular 9601 ** string. 9602 */ 9331 9603 #define MODULE_NAME_MAX_LEN 11 9332 9604 static char _bsddbModuleName[MODULE_NAME_MAX_LEN+1] = "_bsddb"; … … 9379 9651 || (PyType_Ready(&DBTxn_Type) < 0) 9380 9652 || (PyType_Ready(&DBLock_Type) < 0) 9381 #if (DBVER >= 43)9382 9653 || (PyType_Ready(&DBSequence_Type) < 0) 9654 #if (DBVER >= 52) 9655 || (PyType_Ready(&DBSite_Type) < 0) 9383 9656 #endif 9384 9657 ) { … … 9389 9662 #endif 9390 9663 } 9391 9392 #if defined(WITH_THREAD) && !defined(MYDB_USE_GILSTATE)9393 /* Save the current interpreter, so callbacks can do the right thing. */9394 _db_interpreterState = PyThreadState_GET()->interp;9395 #endif9396 9664 9397 9665 /* Create the module and add the functions */ … … 9429 9697 9430 9698 #if (DBVER < 48) 9431 #if (DBVER >= 42)9432 9699 ADD_INT(d, DB_RPCCLIENT); 9433 #else9434 ADD_INT(d, DB_CLIENT);9435 /* allow apps to be written using DB_RPCCLIENT on older Berkeley DB */9436 _addIntToDict(d, "DB_RPCCLIENT", DB_CLIENT);9437 #endif9438 9700 #endif 9439 9701 … … 9477 9739 ADD_INT(d, DB_TXN_SYNC); 9478 9740 ADD_INT(d, DB_TXN_NOWAIT); 9741 9742 #if (DBVER >= 51) 9743 ADD_INT(d, DB_TXN_BULK); 9744 #endif 9745 9746 #if (DBVER >= 48) 9747 ADD_INT(d, DB_CURSOR_BULK); 9748 #endif 9479 9749 9480 9750 #if (DBVER >= 46) … … 9512 9782 9513 9783 ADD_INT(d, DB_LOCK_EXPIRE); 9514 #if (DBVER >= 43)9515 9784 ADD_INT(d, DB_LOCK_MAXWRITE); 9516 #endif9517 9785 9518 9786 _addIntToDict(d, "DB_LOCK_CONFLICT", 0); … … 9550 9818 9551 9819 ADD_INT(d, DB_LSTAT_ABORTED); 9552 #if (DBVER < 43)9553 ADD_INT(d, DB_LSTAT_ERR);9554 #endif9555 9820 ADD_INT(d, DB_LSTAT_FREE); 9556 9821 ADD_INT(d, DB_LSTAT_HELD); … … 9562 9827 ADD_INT(d, DB_ARCH_DATA); 9563 9828 ADD_INT(d, DB_ARCH_LOG); 9564 #if (DBVER >= 42)9565 9829 ADD_INT(d, DB_ARCH_REMOVE); 9566 #endif9567 9830 9568 9831 ADD_INT(d, DB_BTREE); … … 9579 9842 ADD_INT(d, DB_SNAPSHOT); 9580 9843 9581 #if (DBVER >= 43)9582 9844 ADD_INT(d, DB_INORDER); 9583 #endif9584 9845 9585 9846 ADD_INT(d, DB_JOIN_NOSORT); … … 9592 9853 #endif 9593 9854 9594 #if (DBVER <= 41)9595 ADD_INT(d, DB_COMMIT);9596 #endif9597 9855 ADD_INT(d, DB_CONSUME); 9598 9856 ADD_INT(d, DB_CONSUME_WAIT); … … 9652 9910 ADD_INT(d, DB_LOCK_NOTGRANTED); 9653 9911 ADD_INT(d, DB_NOSERVER); 9912 #if (DBVER < 52) 9654 9913 ADD_INT(d, DB_NOSERVER_HOME); 9655 9914 ADD_INT(d, DB_NOSERVER_ID); 9915 #endif 9656 9916 ADD_INT(d, DB_NOTFOUND); 9657 9917 ADD_INT(d, DB_OLD_VERSION); … … 9666 9926 ADD_INT(d, DB_PANIC_ENVIRONMENT); 9667 9927 ADD_INT(d, DB_NOPANIC); 9668 9669 9928 ADD_INT(d, DB_OVERWRITE); 9670 9929 9671 #if (DBVER >= 43)9672 9930 ADD_INT(d, DB_STAT_SUBSYSTEM); 9673 9931 ADD_INT(d, DB_STAT_MEMP_HASH); 9674 #endif 9932 ADD_INT(d, DB_STAT_LOCK_CONF); 9933 ADD_INT(d, DB_STAT_LOCK_LOCKERS); 9934 ADD_INT(d, DB_STAT_LOCK_OBJECTS); 9935 ADD_INT(d, DB_STAT_LOCK_PARAMS); 9675 9936 9676 9937 #if (DBVER >= 48) … … 9691 9952 ADD_INT(d, DB_EID_BROADCAST); 9692 9953 9693 #if (DBVER >= 42)9694 9954 ADD_INT(d, DB_TIME_NOTGRANTED); 9695 9955 ADD_INT(d, DB_TXN_NOT_DURABLE); … … 9699 9959 ADD_INT(d, DB_ENCRYPT); 9700 9960 ADD_INT(d, DB_CHKSUM); 9701 #endif 9702 9703 #if (DBVER >= 42) && (DBVER < 47) 9961 9962 #if (DBVER < 47) 9704 9963 ADD_INT(d, DB_LOG_AUTOREMOVE); 9705 9964 ADD_INT(d, DB_DIRECT_LOG); … … 9734 9993 ADD_INT(d, DB_VERB_WAITSFOR); 9735 9994 9995 #if (DBVER >= 50) 9996 ADD_INT(d, DB_VERB_REP_SYSTEM); 9997 #endif 9998 9999 #if (DBVER >= 47) 10000 ADD_INT(d, DB_VERB_REP_ELECT); 10001 ADD_INT(d, DB_VERB_REP_LEASE); 10002 ADD_INT(d, DB_VERB_REP_MISC); 10003 ADD_INT(d, DB_VERB_REP_MSGS); 10004 ADD_INT(d, DB_VERB_REP_SYNC); 10005 ADD_INT(d, DB_VERB_REPMGR_CONNFAIL); 10006 ADD_INT(d, DB_VERB_REPMGR_MISC); 10007 #endif 10008 9736 10009 #if (DBVER >= 45) 9737 10010 ADD_INT(d, DB_EVENT_PANIC); … … 9749 10022 #endif 9750 10023 10024 #if (DBVER >= 50) 10025 ADD_INT(d, DB_REPMGR_CONF_ELECTIONS); 10026 ADD_INT(d, DB_EVENT_REP_MASTER_FAILURE); 10027 ADD_INT(d, DB_EVENT_REP_DUPMASTER); 10028 ADD_INT(d, DB_EVENT_REP_ELECTION_FAILED); 10029 #endif 10030 #if (DBVER >= 48) 10031 ADD_INT(d, DB_EVENT_REG_ALIVE); 10032 ADD_INT(d, DB_EVENT_REG_PANIC); 10033 #endif 10034 10035 #if (DBVER >=52) 10036 ADD_INT(d, DB_EVENT_REP_SITE_ADDED); 10037 ADD_INT(d, DB_EVENT_REP_SITE_REMOVED); 10038 ADD_INT(d, DB_EVENT_REP_LOCAL_SITE_REMOVED); 10039 ADD_INT(d, DB_EVENT_REP_CONNECT_BROKEN); 10040 ADD_INT(d, DB_EVENT_REP_CONNECT_ESTD); 10041 ADD_INT(d, DB_EVENT_REP_CONNECT_TRY_FAILED); 10042 ADD_INT(d, DB_EVENT_REP_INIT_DONE); 10043 10044 ADD_INT(d, DB_MEM_LOCK); 10045 ADD_INT(d, DB_MEM_LOCKOBJECT); 10046 ADD_INT(d, DB_MEM_LOCKER); 10047 ADD_INT(d, DB_MEM_LOGID); 10048 ADD_INT(d, DB_MEM_TRANSACTION); 10049 ADD_INT(d, DB_MEM_THREAD); 10050 10051 ADD_INT(d, DB_BOOTSTRAP_HELPER); 10052 ADD_INT(d, DB_GROUP_CREATOR); 10053 ADD_INT(d, DB_LEGACY); 10054 ADD_INT(d, DB_LOCAL_SITE); 10055 ADD_INT(d, DB_REPMGR_PEER); 10056 #endif 10057 9751 10058 ADD_INT(d, DB_REP_DUPMASTER); 9752 10059 ADD_INT(d, DB_REP_HOLDELECTION); … … 9755 10062 ADD_INT(d, DB_REP_JOIN_FAILURE); 9756 10063 #endif 9757 #if (DBVER >= 42)9758 10064 ADD_INT(d, DB_REP_ISPERM); 9759 10065 ADD_INT(d, DB_REP_NOTPERM); 9760 #endif9761 10066 ADD_INT(d, DB_REP_NEWSITE); 9762 10067 … … 9767 10072 9768 10073 #if (DBVER >= 44) 10074 #if (DBVER >= 50) 10075 ADD_INT(d, DB_REP_CONF_AUTOINIT); 10076 #else 9769 10077 ADD_INT(d, DB_REP_CONF_NOAUTOINIT); 10078 #endif /* 5.0 */ 10079 #endif /* 4.4 */ 10080 #if (DBVER >= 44) 9770 10081 ADD_INT(d, DB_REP_CONF_DELAYCLIENT); 9771 10082 ADD_INT(d, DB_REP_CONF_BULK); … … 9775 10086 #endif 9776 10087 9777 #if (DBVER >= 42)9778 10088 ADD_INT(d, DB_REP_NOBUFFER); 9779 #endif9780 10089 9781 10090 #if (DBVER >= 46) … … 9820 10129 #endif 9821 10130 9822 #if (DBVER >= 43) 10131 #if (DBVER >= 51) 10132 ADD_INT(d, DB_REPMGR_ACKS_ALL_AVAILABLE); 10133 #endif 10134 10135 #if (DBVER >= 48) 10136 ADD_INT(d, DB_REP_CONF_INMEM); 10137 #endif 10138 10139 ADD_INT(d, DB_TIMEOUT); 10140 10141 #if (DBVER >= 50) 10142 ADD_INT(d, DB_FORCESYNC); 10143 #endif 10144 10145 #if (DBVER >= 48) 10146 ADD_INT(d, DB_FAILCHK); 10147 #endif 10148 10149 #if (DBVER >= 51) 10150 ADD_INT(d, DB_HOTBACKUP_IN_PROGRESS); 10151 #endif 10152 9823 10153 ADD_INT(d, DB_BUFFER_SMALL); 9824 10154 ADD_INT(d, DB_SEQ_DEC); 9825 10155 ADD_INT(d, DB_SEQ_INC); 9826 10156 ADD_INT(d, DB_SEQ_WRAP); 9827 #endif 9828 9829 #if (DBVER >= 43) && (DBVER < 47) 10157 10158 #if (DBVER < 47) 9830 10159 ADD_INT(d, DB_LOG_INMEMORY); 9831 10160 ADD_INT(d, DB_DSYNC_LOG); … … 9856 10185 ADD_INT(d, DB_SET_LOCK_TIMEOUT); 9857 10186 ADD_INT(d, DB_SET_TXN_TIMEOUT); 10187 10188 #if (DBVER >= 48) 10189 ADD_INT(d, DB_SET_REG_TIMEOUT); 10190 #endif 9858 10191 9859 10192 /* The exception name must be correct for pickled exception * … … 9913 10246 MAKE_EX(DBVerifyBadError); 9914 10247 MAKE_EX(DBNoServerError); 10248 #if (DBVER < 52) 9915 10249 MAKE_EX(DBNoServerHomeError); 9916 10250 MAKE_EX(DBNoServerIDError); 10251 #endif 9917 10252 MAKE_EX(DBPageNotFoundError); 9918 10253 MAKE_EX(DBSecondaryBadError); … … 9928 10263 MAKE_EX(DBPermissionsError); 9929 10264 9930 #if (DBVER >= 42)9931 10265 MAKE_EX(DBRepHandleDeadError); 9932 #endif9933 10266 #if (DBVER >= 44) 9934 10267 MAKE_EX(DBRepLockoutError); … … 9948 10281 9949 10282 /* Initialise the C API structure and add it to the module */ 10283 bsddb_api.api_version = PYBSDDB_API_VERSION; 9950 10284 bsddb_api.db_type = &DB_Type; 9951 10285 bsddb_api.dbcursor_type = &DBCursor_Type; … … 9954 10288 bsddb_api.dbtxn_type = &DBTxn_Type; 9955 10289 bsddb_api.dblock_type = &DBLock_Type; 9956 #if (DBVER >= 43)9957 10290 bsddb_api.dbsequence_type = &DBSequence_Type; 9958 #endif9959 10291 bsddb_api.makeDBError = makeDBError; 9960 10292 9961 10293 /* 9962 ** Capsules exist from Python 3.1, but I9963 ** don't want to break the API compatibility9964 ** for already published Python versions.10294 ** Capsules exist from Python 2.7 and 3.1. 10295 ** We don't support Python 3.0 anymore, so... 10296 ** #if (PY_VERSION_HEX < ((PY_MAJOR_VERSION < 3) ? 0x02070000 : 0x03020000)) 9965 10297 */ 9966 #if (PY_VERSION_HEX < 0x0 3020000)10298 #if (PY_VERSION_HEX < 0x02070000) 9967 10299 py_api = PyCObject_FromVoidPtr((void*)&bsddb_api, NULL); 9968 10300 #else 9969 10301 { 9970 char py_api_name[250]; 10302 /* 10303 ** The data must outlive the call!!. So, the static definition. 10304 ** The buffer must be big enough... 10305 */ 10306 static char py_api_name[MODULE_NAME_MAX_LEN+10]; 9971 10307 9972 10308 strcpy(py_api_name, _bsddbModuleName); … … 9977 10313 #endif 9978 10314 9979 PyDict_SetItemString(d, "api", py_api); 9980 Py_DECREF(py_api); 10315 /* Check error control */ 10316 /* 10317 ** PyErr_NoMemory(); 10318 ** py_api = NULL; 10319 */ 10320 10321 if (py_api) { 10322 PyDict_SetItemString(d, "api", py_api); 10323 Py_DECREF(py_api); 10324 } else { /* Something bad happened */ 10325 PyErr_WriteUnraisable(m); 10326 if(PyErr_Warn(PyExc_RuntimeWarning, 10327 "_bsddb/_pybsddb C API will be not available")) { 10328 PyErr_WriteUnraisable(m); 10329 } 10330 PyErr_Clear(); 10331 } 9981 10332 9982 10333 /* Check for errors */
Note:
See TracChangeset
for help on using the changeset viewer.