… | |
… | |
58 | #endif |
58 | #endif |
59 | |
59 | |
60 | typedef char *bdb_filename; |
60 | typedef char *bdb_filename; |
61 | |
61 | |
62 | static SV *prepare_cb; |
62 | static SV *prepare_cb; |
|
|
63 | |
|
|
64 | static HV |
|
|
65 | *bdb_stash, |
|
|
66 | *bdb_env_stash, |
|
|
67 | *bdb_txn_stash, |
|
|
68 | *bdb_cursor_stash, |
|
|
69 | *bdb_db_stash, |
|
|
70 | *bdb_sequence_stash; |
63 | |
71 | |
64 | #if DB_VERSION_MINOR >= 6 |
72 | #if DB_VERSION_MINOR >= 6 |
65 | # define c_close close |
73 | # define c_close close |
66 | # define c_count count |
74 | # define c_count count |
67 | # define c_del del |
75 | # define c_del del |
… | |
… | |
1018 | (void)0; |
1026 | (void)0; |
1019 | |
1027 | |
1020 | #define REQ_SEND \ |
1028 | #define REQ_SEND \ |
1021 | req_send (req) |
1029 | req_send (req) |
1022 | |
1030 | |
1023 | #define SvPTR(var, arg, type, class, nullok) \ |
1031 | #define SvPTR(var, arg, type, stash, class, nullok) \ |
1024 | if (!SvOK (arg)) \ |
1032 | if (!SvOK (arg)) \ |
1025 | { \ |
1033 | { \ |
1026 | if (nullok != 1) \ |
1034 | if (nullok != 1) \ |
1027 | croak (# var " must be a " # class " object, not undef"); \ |
1035 | croak (# var " must be a " # class " object, not undef"); \ |
1028 | \ |
1036 | \ |
1029 | (var) = 0; \ |
1037 | (var) = 0; \ |
1030 | } \ |
1038 | } \ |
1031 | else if (sv_derived_from ((arg), # class)) \ |
1039 | else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \ |
1032 | { \ |
1040 | { \ |
1033 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1041 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1034 | (var) = INT2PTR (type, tmp); \ |
1042 | (var) = INT2PTR (type, tmp); \ |
1035 | if (!var && nullok != 2) \ |
1043 | if (!var && nullok != 2) \ |
1036 | croak (# var " is not a valid " # class " object anymore"); \ |
1044 | croak (# var " is not a valid " # class " object anymore"); \ |
… | |
… | |
1039 | croak (# var " is not of type " # class); |
1047 | croak (# var " is not of type " # class); |
1040 | |
1048 | |
1041 | #define ARG_MUTABLE(name) \ |
1049 | #define ARG_MUTABLE(name) \ |
1042 | if (SvREADONLY (name)) \ |
1050 | if (SvREADONLY (name)) \ |
1043 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
1051 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
|
|
1052 | |
|
|
1053 | static SV * |
|
|
1054 | newSVptr (void *ptr, HV *stash) |
|
|
1055 | { |
|
|
1056 | SV *rv = NEWSV (0, 0); |
|
|
1057 | sv_upgrade (rv, SVt_PVMG); |
|
|
1058 | sv_setiv (rv, PTR2IV (ptr)); |
|
|
1059 | |
|
|
1060 | return sv_bless (newRV_noinc (rv), stash); |
|
|
1061 | } |
1044 | |
1062 | |
1045 | static void |
1063 | static void |
1046 | ptr_nuke (SV *sv) |
1064 | ptr_nuke (SV *sv) |
1047 | { |
1065 | { |
1048 | assert (SvROK (sv)); |
1066 | assert (SvROK (sv)); |
… | |
… | |
1170 | |
1188 | |
1171 | PROTOTYPES: ENABLE |
1189 | PROTOTYPES: ENABLE |
1172 | |
1190 | |
1173 | BOOT: |
1191 | BOOT: |
1174 | { |
1192 | { |
1175 | HV *stash = gv_stashpv ("BDB", 1); |
1193 | bdb_stash = gv_stashpv ("BDB" , 1); |
|
|
1194 | bdb_env_stash = gv_stashpv ("BDB::Env" , 1); |
|
|
1195 | bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1); |
|
|
1196 | bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1); |
|
|
1197 | bdb_db_stash = gv_stashpv ("BDB::Db" , 1); |
|
|
1198 | bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1); |
1176 | |
1199 | |
1177 | static const struct { |
1200 | static const struct { |
1178 | const char *name; |
1201 | const char *name; |
1179 | IV iv; |
1202 | IV iv; |
1180 | } *civ, const_iv[] = { |
1203 | } *civ, const_iv[] = { |
… | |
… | |
1378 | # endif |
1401 | # endif |
1379 | #endif |
1402 | #endif |
1380 | }; |
1403 | }; |
1381 | |
1404 | |
1382 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1405 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1383 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1406 | newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv)); |
1384 | |
1407 | |
1385 | prepare_cb = &PL_sv_undef; |
1408 | prepare_cb = &PL_sv_undef; |
1386 | |
1409 | |
1387 | { |
1410 | { |
1388 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1411 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1389 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1412 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1390 | |
1413 | |
1391 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1414 | newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3)); |
1392 | } |
1415 | } |
1393 | |
1416 | |
1394 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1417 | newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1395 | |
1418 | |
1396 | create_respipe (); |
1419 | create_respipe (); |
1397 | |
1420 | |
1398 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1421 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1399 | patch_errno (); |
1422 | patch_errno (); |