Chem-Structure-Parser

 view release on metacpan or  search on metacpan

Parser.xs  view on Meta::CPAN

blocks, which parse as a structure with nothing in it -- a silent empty answer
for what is always a mistake.  Both of the others came back as t/errors.t
failures from 0.031 smokers (Strawberry 5.42.0 on Win2012, and perl 5.42.3 on
NetBSD 11).  structure_info() rejects a directory in Perl before it ever gets
here; this is the same complaint for a caller that reached past it.*/
static char *slurp(pTHX_ const char *CSP_RESTRICT path, STRLEN *CSP_RESTRICT lenp){
	//no CSP_RESTRICT on fh: it is perl-managed, and the layers below it alias it
	PerlIO *fh;
	char *CSP_RESTRICT buf;
	Stat_t st;
	/*1 MB to start and doubling from there, for what stat() cannot size: a
	pipe, /dev/stdin.  A regular file is allocated at its size plus one byte,
	the byte being room for the read that comes back 0 at the end, so the loop
	below never grows the buffer at all.  Doubling would have left the 33 MB
	largest entry in PDBbind v2020 in a 64 MB block, reallocated six times on
	the way, and that block lives for the whole parse.*/
	STRLEN cap = 1 << 20, len = 0;
	const bool have_stat = PerlLIO_stat(path, &st) == 0;
	if (have_stat && S_ISDIR(st.st_mode))
		croak("Chem::Structure::Parser: cannot read '%s': it is a directory", path);
	//the comparison is the test that the size fits a STRLEN at all
	if (have_stat && S_ISREG(st.st_mode) && st.st_size > 0
	    && (Off_t)(STRLEN)st.st_size == st.st_size && (STRLEN)st.st_size < (STRLEN)-1)
		cap = (STRLEN)st.st_size + 1;
	fh = PerlIO_open(path, "rb");
	if (!fh) croak("Chem::Structure::Parser: cannot read '%s': %s", path, Strerror(errno));
	Newx(buf, cap, char);
	for (;;) {

t/parse.t  view on Meta::CPAN

#--------
throws_ok { Chem::Structure::Parser::_parse_string(undef) } qr/undefined/,
	'_parse_string: undefined text dies';
throws_ok { Chem::Structure::Parser::_parse_file(undef) } qr/undefined/,
	'_parse_file: an undefined file name dies';
throws_ok { Chem::Structure::Parser::_parse_file('t/data/does.not.exist.pdb') } qr/cannot read/,
	'_parse_file: a missing file dies, and says so';
throws_ok { Chem::Structure::Parser::_parse_string('', 'not a hashref') } qr/hash reference/,
	'_parse_string: options must be a hash reference';

# A regular file is read into a buffer of exactly its size, which stat() gives;
# a named pipe has no size to give, and is read in growing chunks instead.  The
# two must read the same.  mkfifo() is POSIX, and the fork below is the writer
# a pipe needs, so this is only possible where both are.
SKIP: {
	my $dir  = File::Temp::tempdir(CLEANUP => 1);
	my $fifo = "$dir/mini.fifo";
	skip 'no named pipes here', 2
		unless $^O ne 'MSWin32' && eval { require POSIX; POSIX::mkfifo($fifo, 0600) };
	my $pid = fork;
	skip 'no fork here', 2 unless defined $pid;



( run in 1.917 second using v1.01-cache-2.11-cpan-eb134014566 )