… | |
… | |
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 |
… | |
… | |
608 | end_thread (); |
616 | end_thread (); |
609 | } |
617 | } |
610 | |
618 | |
611 | static void poll_wait (void) |
619 | static void poll_wait (void) |
612 | { |
620 | { |
613 | fd_set rfd; |
|
|
614 | |
|
|
615 | while (nreqs) |
621 | while (nreqs) |
616 | { |
622 | { |
617 | int size; |
623 | int size; |
618 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
624 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
619 | size = res_queue.size; |
625 | size = res_queue.size; |
… | |
… | |
1020 | (void)0; |
1026 | (void)0; |
1021 | |
1027 | |
1022 | #define REQ_SEND \ |
1028 | #define REQ_SEND \ |
1023 | req_send (req) |
1029 | req_send (req) |
1024 | |
1030 | |
1025 | #define SvPTR(var, arg, type, class, nullok) \ |
1031 | #define SvPTR(var, arg, type, stash, class, nullok) \ |
1026 | if (!SvOK (arg)) \ |
1032 | if (!SvOK (arg)) \ |
1027 | { \ |
1033 | { \ |
1028 | if (nullok != 1) \ |
1034 | if (nullok != 1) \ |
1029 | croak (# var " must be a " # class " object, not undef"); \ |
1035 | croak (# var " must be a " # class " object, not undef"); \ |
1030 | \ |
1036 | \ |
1031 | (var) = 0; \ |
1037 | (var) = 0; \ |
1032 | } \ |
1038 | } \ |
1033 | else if (sv_derived_from ((arg), # class)) \ |
1039 | else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \ |
1034 | { \ |
1040 | { \ |
1035 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1041 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1036 | (var) = INT2PTR (type, tmp); \ |
1042 | (var) = INT2PTR (type, tmp); \ |
1037 | if (!var && nullok != 2) \ |
1043 | if (!var && nullok != 2) \ |
1038 | croak (# var " is not a valid " # class " object anymore"); \ |
1044 | croak (# var " is not a valid " # class " object anymore"); \ |
… | |
… | |
1041 | croak (# var " is not of type " # class); |
1047 | croak (# var " is not of type " # class); |
1042 | |
1048 | |
1043 | #define ARG_MUTABLE(name) \ |
1049 | #define ARG_MUTABLE(name) \ |
1044 | if (SvREADONLY (name)) \ |
1050 | if (SvREADONLY (name)) \ |
1045 | 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 | } |
1046 | |
1062 | |
1047 | static void |
1063 | static void |
1048 | ptr_nuke (SV *sv) |
1064 | ptr_nuke (SV *sv) |
1049 | { |
1065 | { |
1050 | assert (SvROK (sv)); |
1066 | assert (SvROK (sv)); |
… | |
… | |
1172 | |
1188 | |
1173 | PROTOTYPES: ENABLE |
1189 | PROTOTYPES: ENABLE |
1174 | |
1190 | |
1175 | BOOT: |
1191 | BOOT: |
1176 | { |
1192 | { |
1177 | 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); |
1178 | |
1199 | |
1179 | static const struct { |
1200 | static const struct { |
1180 | const char *name; |
1201 | const char *name; |
1181 | IV iv; |
1202 | IV iv; |
1182 | } *civ, const_iv[] = { |
1203 | } *civ, const_iv[] = { |
… | |
… | |
1380 | # endif |
1401 | # endif |
1381 | #endif |
1402 | #endif |
1382 | }; |
1403 | }; |
1383 | |
1404 | |
1384 | 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; ) |
1385 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1406 | newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv)); |
1386 | |
1407 | |
1387 | prepare_cb = &PL_sv_undef; |
1408 | prepare_cb = &PL_sv_undef; |
1388 | |
1409 | |
1389 | { |
1410 | { |
1390 | /* 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 */ |
1391 | 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 }; |
1392 | |
1413 | |
1393 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1414 | newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3)); |
1394 | } |
1415 | } |
1395 | |
1416 | |
1396 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1417 | newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1397 | |
1418 | |
1398 | create_respipe (); |
1419 | create_respipe (); |
1399 | |
1420 | |
1400 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1421 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1401 | patch_errno (); |
1422 | patch_errno (); |