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

Comparing BDB/BDB.xs (file contents):
Revision 1.31 by root, Sun Mar 30 04:34:20 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;
960errno_get (pTHX_ SV *sv, MAGIC *mg) 974errno_get (pTHX_ SV *sv, MAGIC *mg)
961{ 975{
962 if (*mg->mg_ptr == '!') // should always be the case 976 if (*mg->mg_ptr == '!') // should always be the case
963 if (-30999 <= errno && errno <= -30800) 977 if (-30999 <= errno && errno <= -30800)
964 { 978 {
979 sv_setnv (sv, (NV)errno);
965 sv_setpv (sv, db_strerror (errno)); 980 sv_setpv (sv, db_strerror (errno));
981 SvNOK_on (sv); /* what a wonderful hack! */
982 // ^^^ copied from perl sources
966 return 0; 983 return 0;
967 } 984 }
968 985
969 return PL_vtbl_sv.svt_get (aTHX_ sv, mg); 986 return PL_vtbl_sv.svt_get (aTHX_ sv, mg);
970} 987}
1363} 1380}
1364 OUTPUT: 1381 OUTPUT:
1365 RETVAL 1382 RETVAL
1366 1383
1367void 1384void
1368db_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)
1369 CODE: 1386 CODE:
1370{ 1387{
1371 dREQ (REQ_ENV_OPEN); 1388 dREQ (REQ_ENV_OPEN);
1372 1389
1373 req->env = env; 1390 req->env = env;
1444} 1461}
1445 OUTPUT: 1462 OUTPUT:
1446 RETVAL 1463 RETVAL
1447 1464
1448void 1465void
1449db_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)
1450 CODE: 1467 CODE:
1451{ 1468{
1452 dREQ (REQ_DB_OPEN); 1469 dREQ (REQ_DB_OPEN);
1453 req->db = db; 1470 req->db = db;
1454 req->txn = txnid; 1471 req->txn = txnid;
1494 req->uint1 = flags; 1511 req->uint1 = flags;
1495 REQ_SEND; 1512 REQ_SEND;
1496} 1513}
1497 1514
1498void 1515void
1499db_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)
1500 CODE: 1517 CODE:
1501{ 1518{
1502 dREQ (REQ_DB_SYNC); 1519 dREQ (REQ_DB_SYNC);
1503 req->db = db; 1520 req->db = db;
1504 req->buf1 = strdup (file); 1521 req->buf1 = strdup (file);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines