ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.30 by root, Sun Jan 13 09:43:21 2008 UTC vs.
Revision 1.34 by root, Sun Mar 30 06:28:08 2008 UTC

47typedef DBC DBC_ornuked; 47typedef DBC DBC_ornuked;
48typedef DB DB_ornuked; 48typedef DB DB_ornuked;
49typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 49typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
50 50
51typedef SV SV8; /* byte-sv, used for argument-checking */ 51typedef SV SV8; /* byte-sv, used for argument-checking */
52typedef char *octetstring; 52typedef char *bdb_filename;
53 53
54static SV *prepare_cb; 54static SV *prepare_cb;
55 55
56#if DB_VERSION_MINOR >= 6 56#if DB_VERSION_MINOR >= 6
57# define c_close close 57# define c_close close
60# define c_dup dup 60# define c_dup dup
61# define c_get get 61# define c_get get
62# define c_pget pget 62# define c_pget pget
63# define c_put put 63# define c_put put
64#endif 64#endif
65
66static char *
67get_bdb_filename (SV *sv)
68{
69 return !SvOK (sv)
70 ? 0
71 :
72#if WIN32
73 SvPVutf8_nolen (sv)
74#else
75 SvPVbyte_nolen (sv)
76#endif
77 ;
78}
65 79
66static void 80static void
67debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) 81debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg)
68{ 82{
69 printf ("err[%s]\n", msg); 83 printf ("err[%s]\n", msg);
205static mutex_t reqlock = X_MUTEX_INIT; 219static mutex_t reqlock = X_MUTEX_INIT;
206static cond_t reqwait = X_COND_INIT; 220static cond_t reqwait = X_COND_INIT;
207 221
208#if WORDACCESS_UNSAFE 222#if WORDACCESS_UNSAFE
209 223
210static unsigned int get_nready () 224static unsigned int get_nready (void)
211{ 225{
212 unsigned int retval; 226 unsigned int retval;
213 227
214 X_LOCK (reqlock); 228 X_LOCK (reqlock);
215 retval = nready; 229 retval = nready;
216 X_UNLOCK (reqlock); 230 X_UNLOCK (reqlock);
217 231
218 return retval; 232 return retval;
219} 233}
220 234
221static unsigned int get_npending () 235static unsigned int get_npending (void)
222{ 236{
223 unsigned int retval; 237 unsigned int retval;
224 238
225 X_LOCK (reslock); 239 X_LOCK (reslock);
226 retval = npending; 240 retval = npending;
227 X_UNLOCK (reslock); 241 X_UNLOCK (reslock);
228 242
229 return retval; 243 return retval;
230} 244}
231 245
232static unsigned int get_nthreads () 246static unsigned int get_nthreads (void)
233{ 247{
234 unsigned int retval; 248 unsigned int retval;
235 249
236 X_LOCK (wrklock); 250 X_LOCK (wrklock);
237 retval = started; 251 retval = started;
300 } 314 }
301 315
302 abort (); 316 abort ();
303} 317}
304 318
305static int poll_cb (); 319static int poll_cb (void);
306static void req_free (bdb_req req); 320static void req_free (bdb_req req);
307static void req_cancel (bdb_req req); 321static void req_cancel (bdb_req req);
308 322
309static int req_invoke (bdb_req req) 323static int req_invoke (bdb_req req)
310{ 324{
391#else 405#else
392# define TO_SOCKET(x) (x) 406# define TO_SOCKET(x) (x)
393#endif 407#endif
394 408
395static void 409static void
396create_respipe () 410create_respipe (void)
397{ 411{
398#ifdef _WIN32 412#ifdef _WIN32
399 int arg; /* argg */ 413 int arg; /* argg */
400#endif 414#endif
401 int old_readfd = respipe [0]; 415 int old_readfd = respipe [0];
455 free (wrk); 469 free (wrk);
456 470
457 X_UNLOCK (wrklock); 471 X_UNLOCK (wrklock);
458} 472}
459 473
460static void maybe_start_thread () 474static void maybe_start_thread (void)
461{ 475{
462 if (get_nthreads () >= wanted) 476 if (get_nthreads () >= wanted)
463 return; 477 return;
464 478
465 /* todo: maybe use idle here, but might be less exact */ 479 /* todo: maybe use idle here, but might be less exact */
550 564
551 while (started > wanted) 565 while (started > wanted)
552 end_thread (); 566 end_thread ();
553} 567}
554 568
555static void poll_wait () 569static void poll_wait (void)
556{ 570{
557 fd_set rfd; 571 fd_set rfd;
558 572
559 while (nreqs) 573 while (nreqs)
560 { 574 {
573 587
574 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); 588 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
575 } 589 }
576} 590}
577 591
578static int poll_cb () 592static int poll_cb (void)
579{ 593{
580 dSP; 594 dSP;
581 int count = 0; 595 int count = 0;
582 int maxreqs = max_poll_reqs; 596 int maxreqs = max_poll_reqs;
583 int do_croak = 0; 597 int do_croak = 0;
952static void 966static void
953ptr_nuke (SV *sv) 967ptr_nuke (SV *sv)
954{ 968{
955 assert (SvROK (sv)); 969 assert (SvROK (sv));
956 sv_setiv (SvRV (sv), 0); 970 sv_setiv (SvRV (sv), 0);
971}
972
973static int
974errno_get (pTHX_ SV *sv, MAGIC *mg)
975{
976 if (*mg->mg_ptr == '!') // should always be the case
977 if (-30999 <= errno && errno <= -30800)
978 {
979 sv_setnv (sv, (NV)errno);
980 sv_setpv (sv, db_strerror (errno));
981 SvNOK_on (sv); /* what a wonderful hack! */
982 // ^^^ copied from perl sources
983 return 0;
984 }
985
986 return PL_vtbl_sv.svt_get (aTHX_ sv, mg);
987}
988
989static MGVTBL vtbl_errno;
990
991// this wonderful hack :( patches perl's $! variable to support our errno values
992static void
993patch_errno (void)
994{
995 SV *sv;
996 MAGIC *mg;
997
998 if (!(sv = get_sv ("!", 1)))
999 return;
1000
1001 if (!(mg = mg_find (sv, PERL_MAGIC_sv)))
1002 return;
1003
1004 if (mg->mg_virtual != &PL_vtbl_sv)
1005 return;
1006
1007 vtbl_errno = PL_vtbl_sv;
1008 vtbl_errno.svt_get = errno_get;
1009 mg->mg_virtual = &vtbl_errno;
957} 1010}
958 1011
959MODULE = BDB PACKAGE = BDB 1012MODULE = BDB PACKAGE = BDB
960 1013
961PROTOTYPES: ENABLE 1014PROTOTYPES: ENABLE
1159 X_MUTEX_CHECK (reslock); 1212 X_MUTEX_CHECK (reslock);
1160 X_MUTEX_CHECK (reqlock); 1213 X_MUTEX_CHECK (reqlock);
1161 1214
1162 X_COND_CHECK (reqwait); 1215 X_COND_CHECK (reqwait);
1163#endif 1216#endif
1217 patch_errno ();
1164} 1218}
1165 1219
1166void 1220void
1167max_poll_reqs (int nreqs) 1221max_poll_reqs (int nreqs)
1168 PROTOTYPE: $ 1222 PROTOTYPE: $
1326} 1380}
1327 OUTPUT: 1381 OUTPUT:
1328 RETVAL 1382 RETVAL
1329 1383
1330void 1384void
1331db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) 1385db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef)
1332 CODE: 1386 CODE:
1333{ 1387{
1334 dREQ (REQ_ENV_OPEN); 1388 dREQ (REQ_ENV_OPEN);
1335 1389
1336 req->env = env; 1390 req->env = env;
1407} 1461}
1408 OUTPUT: 1462 OUTPUT:
1409 RETVAL 1463 RETVAL
1410 1464
1411void 1465void
1412db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) 1466db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef)
1413 CODE: 1467 CODE:
1414{ 1468{
1415 dREQ (REQ_DB_OPEN); 1469 dREQ (REQ_DB_OPEN);
1416 req->db = db; 1470 req->db = db;
1417 req->txn = txnid; 1471 req->txn = txnid;
1457 req->uint1 = flags; 1511 req->uint1 = flags;
1458 REQ_SEND; 1512 REQ_SEND;
1459} 1513}
1460 1514
1461void 1515void
1462db_upgrade (DB *db, octetstring file, U32 flags = 0, SV *callback = &PL_sv_undef) 1516db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = &PL_sv_undef)
1463 CODE: 1517 CODE:
1464{ 1518{
1465 dREQ (REQ_DB_SYNC); 1519 dREQ (REQ_DB_SYNC);
1466 req->db = db; 1520 req->db = db;
1467 req->buf1 = strdup (file); 1521 req->buf1 = strdup (file);
2045 CODE: 2099 CODE:
2046 RETVAL = seq->set_range (seq, min, max); 2100 RETVAL = seq->set_range (seq, min, max);
2047 OUTPUT: 2101 OUTPUT:
2048 RETVAL 2102 RETVAL
2049 2103
2104

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines