dslinux/user/perl/ext/NDBM_File Makefile.PL NDBM_File.pm NDBM_File.xs typemap
cayenne
dslinux_cayenne at user.in-berlin.de
Mon Dec 4 17:59:34 CET 2006
Update of /cvsroot/dslinux/dslinux/user/perl/ext/NDBM_File
In directory antilope:/tmp/cvs-serv17422/ext/NDBM_File
Added Files:
Makefile.PL NDBM_File.pm NDBM_File.xs typemap
Log Message:
Adding fresh perl source to HEAD to branch from
--- NEW FILE: NDBM_File.pm ---
package NDBM_File;
use strict;
use warnings;
require Tie::Hash;
use XSLoader ();
our @ISA = qw(Tie::Hash);
our $VERSION = "1.06";
XSLoader::load 'NDBM_File', $VERSION;
1;
__END__
=head1 NAME
NDBM_File - Tied access to ndbm files
=head1 SYNOPSIS
use Fcntl; # For O_RDWR, O_CREAT, etc.
use NDBM_File;
tie(%h, 'NDBM_File', 'filename', O_RDWR|O_CREAT, 0666)
or die "Couldn't tie NDBM file 'filename': $!; aborting";
# Now read and change the hash
$h{newkey} = newvalue;
print $h{oldkey};
...
untie %h;
=head1 DESCRIPTION
C<NDBM_File> establishes a connection between a Perl hash variable and
a file in NDBM_File format;. You can manipulate the data in the file
just as if it were in a Perl hash, but when your program exits, the
data will remain in the file, to be used the next time your program
runs.
Use C<NDBM_File> with the Perl built-in C<tie> function to establish
the connection between the variable and the file. The arguments to
C<tie> should be:
=over 4
=item 1.
The hash variable you want to tie.
=item 2.
The string C<"NDBM_File">. (Ths tells Perl to use the C<NDBM_File>
package to perform the functions of the hash.)
=item 3.
The name of the file you want to tie to the hash.
=item 4.
Flags. Use one of:
=over 2
=item C<O_RDONLY>
Read-only access to the data in the file.
=item C<O_WRONLY>
Write-only access to the data in the file.
=item C<O_RDWR>
Both read and write access.
=back
If you want to create the file if it does not exist, add C<O_CREAT> to
any of these, as in the example. If you omit C<O_CREAT> and the file
does not already exist, the C<tie> call will fail.
=item 5.
The default permissions to use if a new file is created. The actual
permissions will be modified by the user's umask, so you should
probably use 0666 here. (See L<perlfunc/umask>.)
=back
=head1 DIAGNOSTICS
On failure, the C<tie> call returns an undefined value and probably
sets C<$!> to contain the reason the file could not be tied.
=head2 C<ndbm store returned -1, errno 22, key "..." at ...>
This warning is emitted when you try to store a key or a value that
is too long. It means that the change was not recorded in the
database. See BUGS AND WARNINGS below.
=head1 BUGS AND WARNINGS
There are a number of limits on the size of the data that you can
store in the NDBM file. The most important is that the length of a
key, plus the length of its associated value, may not exceed 1008
bytes.
See L<perlfunc/tie>, L<perldbmfilter>, L<Fcntl>
=cut
--- NEW FILE: Makefile.PL ---
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'NDBM_File',
LIBS => ["-L/usr/local/lib -lndbm", "-ldbm -lucb"],
MAN3PODS => {}, # Pods will be built by installman.
XSPROTOARG => '-noprototypes', # XXX remove later?
VERSION_FROM => 'NDBM_File.pm',
INC => ($^O eq "MacOS" ? "-i ::::db:include" : "")
);
--- NEW FILE: typemap ---
#
#################################### DBM SECTION
#
datum_key T_DATUM_K
datum_value T_DATUM_V
gdatum T_GDATUM
NDBM_File T_PTROBJ
GDBM_File T_PTROBJ
SDBM_File T_PTROBJ
ODBM_File T_PTROBJ
DB_File T_PTROBJ
DBZ_File T_PTROBJ
FATALFUNC T_OPAQUEPTR
INPUT
T_DATUM_K
DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
$var.dptr = SvPVbyte($arg, PL_na);
$var.dsize = (int)PL_na;
T_DATUM_V
DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
if (SvOK($arg)) {
$var.dptr = SvPVbyte($arg, PL_na);
$var.dsize = (int)PL_na;
}
else {
$var.dptr = \"\";
$var.dsize = 0;
}
T_GDATUM
UNIMPLEMENTED
OUTPUT
T_DATUM_K
sv_setpvn($arg, $var.dptr, $var.dsize);
DBM_ckFilter($arg, filter_fetch_key,\"filter_fetch_key\");
T_DATUM_V
sv_setpvn($arg, $var.dptr, $var.dsize);
DBM_ckFilter($arg, filter_fetch_value,\"filter_fetch_value\");
T_GDATUM
sv_usepvn($arg, $var.dptr, $var.dsize);
T_PTROBJ
sv_setref_pv($arg, dbtype, (void*)$var);
--- NEW FILE: NDBM_File.xs ---
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <ndbm.h>
typedef struct {
DBM * dbp ;
SV * filter_fetch_key ;
SV * filter_store_key ;
SV * filter_fetch_value ;
SV * filter_store_value ;
int filtering ;
} NDBM_File_type;
typedef NDBM_File_type * NDBM_File ;
typedef datum datum_key ;
typedef datum datum_value ;
MODULE = NDBM_File PACKAGE = NDBM_File PREFIX = ndbm_
NDBM_File
ndbm_TIEHASH(dbtype, filename, flags, mode)
char * dbtype
char * filename
int flags
int mode
CODE:
{
DBM * dbp ;
RETVAL = NULL ;
if ((dbp = dbm_open(filename, flags, mode))) {
RETVAL = (NDBM_File)safemalloc(sizeof(NDBM_File_type)) ;
Zero(RETVAL, 1, NDBM_File_type) ;
RETVAL->dbp = dbp ;
}
}
OUTPUT:
RETVAL
void
ndbm_DESTROY(db)
NDBM_File db
CODE:
dbm_close(db->dbp);
safefree(db);
#define ndbm_FETCH(db,key) dbm_fetch(db->dbp,key)
datum_value
ndbm_FETCH(db, key)
NDBM_File db
datum_key key
#define ndbm_STORE(db,key,value,flags) dbm_store(db->dbp,key,value,flags)
int
ndbm_STORE(db, key, value, flags = DBM_REPLACE)
NDBM_File db
datum_key key
datum_value value
int flags
CLEANUP:
if (RETVAL) {
if (RETVAL < 0 && errno == EPERM)
croak("No write permission to ndbm file");
croak("ndbm store returned %d, errno %d, key \"%s\"",
RETVAL,errno,key.dptr);
dbm_clearerr(db->dbp);
}
#define ndbm_DELETE(db,key) dbm_delete(db->dbp,key)
int
ndbm_DELETE(db, key)
NDBM_File db
datum_key key
#define ndbm_FIRSTKEY(db) dbm_firstkey(db->dbp)
datum_key
ndbm_FIRSTKEY(db)
NDBM_File db
#define ndbm_NEXTKEY(db,key) dbm_nextkey(db->dbp)
datum_key
ndbm_NEXTKEY(db, key)
NDBM_File db
datum_key key = NO_INIT
#define ndbm_error(db) dbm_error(db->dbp)
int
ndbm_error(db)
NDBM_File db
#define ndbm_clearerr(db) dbm_clearerr(db->dbp)
void
ndbm_clearerr(db)
NDBM_File db
SV *
filter_fetch_key(db, code)
NDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
DBM_setFilter(db->filter_fetch_key, code) ;
SV *
filter_store_key(db, code)
NDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
DBM_setFilter(db->filter_store_key, code) ;
SV *
filter_fetch_value(db, code)
NDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
DBM_setFilter(db->filter_fetch_value, code) ;
SV *
filter_store_value(db, code)
NDBM_File db
SV * code
SV * RETVAL = &PL_sv_undef ;
CODE:
DBM_setFilter(db->filter_store_value, code) ;
More information about the dslinux-commit
mailing list