Skip to content

Commit

Permalink
Report informative error if input locator has been annulled
Browse files Browse the repository at this point in the history
The container file is closed when the last primary locatyor is annulled,
and any remaining secondary locators are annulled automatically. Any
future use of an annulled secondary locator previously caused spurious
unrelated error messages to be reported (for instance, I got "Unexpected
locator with no dataspace"). The changes in this commit cause a more
informative error message to be issued.

Each public function now checks the validity of the input locators and
reports an error if they are not valid (e.g. if they have been annulled).
  • Loading branch information
David Berry committed Jul 7, 2017
1 parent 3604e70 commit 3aa74f5
Show file tree
Hide file tree
Showing 52 changed files with 388 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ dau1CheckName.c \
dau1CheckType.c \
dau1HdsType.c \
dau1Native2MemType.c \
dat1ValidateLocator.c \
hdstrack.c

hds_types.h: make-hds-types$(EXEEXT)
Expand Down
2 changes: 2 additions & 0 deletions dat1.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,7 @@ dat1GetStructureDims( const HDSLoc * locator, int maxdims, hdsdim dims[], int *s
hdsbool_t
dat1NeedsRootName( hid_t objid, hdsbool_t wantprim, char * rootname, size_t rootnamelen, int * status );

int dat1ValidateLocator( const HDSLoc *loc, int *status );

/* DAT1_H_INCLUDED */
#endif
86 changes: 86 additions & 0 deletions dat1ValidateLocator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
*+
* Name:
* dat1ValidateLocator
* Purpose:
* Check the supplied locator is usable.
* Language:
* Starlink ANSI C
* Type of Module:
* Library routine
* Invocation:
* dat1ValidateLocator( const HDSLoc *loc, int * status );
* Arguments:
* loc = HDSLoc * (Given)
* Locator to validate.
* status = int* (Given and Returned)
* Pointer to global status.
* Description:
* An error is reported if the supplied locator is not valid. This can
* occur for instance if the supplied locator is a secondary locator
* that has been annulled automatically as a result of the file being
* closed.
* Authors:
* DSB: David Berry (EAO)
* {enter_new_authors_here}
* History:
* 7-JUL-2017 (DSB):
* Initial version
* {enter_further_changes_here}
* Copyright:
* Copyright (C) 2017 East Asian Observatory
* All Rights Reserved.
* Licence:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* Bugs:
* {note_any_bugs_here}
*-
*/

#include "sae_par.h"
#include "ems.h"
#include "hds.h"
#include "dat1.h"
#include "dat_err.h"

int dat1ValidateLocator( const HDSLoc *loc, int * status ) {

/* Local Variables; */
int valid;

/* If the locator is not valid, report an error. */
datValid( loc, &valid, status );
if( !valid && *status == SAI__OK ) {
*status = DAT__LOCIN;
emsRep(" ", "The supplied HDS locator is invalid - it may have been "
"annulled as a result of the associated file being closed.",
status );
}

return *status;

}
3 changes: 3 additions & 0 deletions datAlter.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ datAlter( HDSLoc *locator, int ndim, const hdsdim dims[], int *status) {

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

if (locator->vectorized) {
*status = DAT__OBJIN;
emsRep("datAlter_1", "Can not alter the size of a vectorized object",
Expand Down
3 changes: 3 additions & 0 deletions datBasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ datBasic(const HDSLoc *locator, const char *mode_c, unsigned char **pntr,

if (*status == SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

*status = SAI__ERROR;
emsRep("datBasic", "datBasic is not available in HDF5 interface",
status);
Expand Down
4 changes: 4 additions & 0 deletions datCcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ datCcopy(const HDSLoc *locator1, const HDSLoc *locator2, const char *name,

if (*status != SAI__OK) return *status;

/* Validate input locators. */
dat1ValidateLocator( locator1, status );
dat1ValidateLocator( locator2, status );

if (dat1IsStructure(locator1, status)) {

/* need the type and dimensionality of the structure to create
Expand Down
3 changes: 3 additions & 0 deletions datCell.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ datCell(const HDSLoc *locator1, int ndim, const hdsdim subs[],

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator1, status );

datName(locator1, namestr, status );

/* Copy dimensions if appropriate */
Expand Down
3 changes: 3 additions & 0 deletions datClen.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ datClen( const HDSLoc * locator, size_t * clen, int * status ) {

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

if (locator->dataset_id <= 0) {
*status = DAT__OBJIN;
emsRep("datClen_1",
Expand Down
3 changes: 3 additions & 0 deletions datClone.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ datClone(const HDSLoc *locator1, HDSLoc **locator2, int *status) {
*locator2 = NULL;
if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator1, status );

clonedloc = dat1AllocLoc( status );
if (*status != SAI__OK) goto CLEANUP;

Expand Down
3 changes: 3 additions & 0 deletions datCoerc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ int datCoerc( const HDSLoc *locator1, int ndim, HDSLoc **locator2, int *status)

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator1, status );

*status = DAT__FATAL;
emsRep("datCoerc", "datCoerc: Not yet implemented for HDF5",
status);
Expand Down
3 changes: 3 additions & 0 deletions datConv.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ datConv(const HDSLoc *locator, const char *type_str, hdsbool_t *conv,
*conv = 1;
if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

*status = DAT__FATAL;
emsRep("datConv", "datConv: Obsolete routine. Do not use",
status);
Expand Down
4 changes: 4 additions & 0 deletions datCopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ datCopy( const HDSLoc *locator1, const HDSLoc *locator2,

if (*status != SAI__OK) return *status;

/* Validate input locators. */
dat1ValidateLocator( locator1, status );
dat1ValidateLocator( locator2, status );

dau1CheckName( name_str, 1, cleanname, sizeof(cleanname), status );
if (*status != SAI__OK) return *status;

Expand Down
3 changes: 3 additions & 0 deletions datDrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ datDrep(const HDSLoc *locator, char **format_str, char **order_str,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

*status = DAT__FATAL;
emsRep("datDrep", "datDrep: Not yet implemented for HDF5",
status);
Expand Down
3 changes: 3 additions & 0 deletions datErase.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ datErase(const HDSLoc *locator, const char *name_str, int *status) {

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

/* containing locator must refer to a group */
if (locator->group_id <= 0) {
*status = DAT__OBJIN;
Expand Down
3 changes: 3 additions & 0 deletions datFind.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ datFind( const HDSLoc *locator1,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator1, status );

/* containing locator must refer to a group */
if (!dat1IsStructure( locator1, status) ) {
*status = DAT__OBJIN;
Expand Down
3 changes: 3 additions & 0 deletions datGet.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ datGet(const HDSLoc *locator, const char *type_str, int ndim,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

/* For error messages */
datName( locator, namestr, status);
datType( locator, datatypestr, status );
Expand Down
3 changes: 3 additions & 0 deletions datGet1C.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ datGet1C( const HDSLoc * locator, size_t maxval, size_t bufsize, char *buffer,
/* Do nothing if bad status */
if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

/* Verify that we have the correct number of values */
datSize( locator, actval, status );

Expand Down
3 changes: 3 additions & 0 deletions datGetVC.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ datGetVC( const HDSLoc * locator, size_t maxval, size_t bufsize, char *buffer,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

datVec( locator, &vecLoc, status );
datGet1C( vecLoc, maxval, bufsize, buffer, pntrs, actval, status );
datAnnul( &vecLoc, status);
Expand Down
3 changes: 3 additions & 0 deletions datIndex.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ datIndex(const HDSLoc *locator1, int index, HDSLoc **locator2, int *status ) {

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator1, status );

datName( locator1, groupnam, status );
if (*status != SAI__OK) return *status;

Expand Down
3 changes: 3 additions & 0 deletions datLen.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ datLen( const HDSLoc * locator, size_t * clen, int * status ) {

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

if (locator->dataset_id <= 0) {
*status = DAT__OBJIN;
emsRep("datClen_1",
Expand Down
3 changes: 3 additions & 0 deletions datMap.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ datMap(HDSLoc *locator, const char *type_str, const char *mode_str, int ndim,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

/* Get the HDF5 type code and confirm this is a primitive type */
isprim = dau1CheckType( 1, type_str, &h5type, normtypestr,
sizeof(normtypestr), status );
Expand Down
3 changes: 3 additions & 0 deletions datMapN.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ int datMapN( HDSLoc* loc, const char * type, const char * mode,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( loc, status );

datShape( loc, ndim, dims, &actdim, status );

if (*status == SAI__OK) {
Expand Down
3 changes: 3 additions & 0 deletions datMould.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ datMould( HDSLoc *locator, int ndim, const hdsdim dims[], int *status ) {

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

*status = DAT__FATAL;
emsRep("datMould", "datMould: Not yet implemented for HDF5",
status);
Expand Down
3 changes: 3 additions & 0 deletions datMove.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ datMove( HDSLoc **locator1, const HDSLoc *locator2, const char *name_str,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator2, status );

dau1CheckName( name_str, 1, cleanname, sizeof(cleanname), status );
if (*status != SAI__OK) return *status;

Expand Down
3 changes: 3 additions & 0 deletions datName.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ datName(const HDSLoc *locator,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

objid = dat1RetrieveIdentifier( locator, status );
if (*status != SAI__OK) return *status;

Expand Down
3 changes: 3 additions & 0 deletions datNcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ datNcomp( const HDSLoc *locator, int *ncomp, int *status) {
*ncomp = 0;
if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

if (!dat1IsStructure( locator, status)) {
*status = DAT__OBJIN;
return *status;
Expand Down
3 changes: 3 additions & 0 deletions datNew.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ datNew( const HDSLoc *locator,

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

newloc = dat1New( locator, 0, name_str, type_str, ndim, dims, status );

/* Free the locator as datNew does not expect you to use the
Expand Down
3 changes: 3 additions & 0 deletions datParen.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ datParen( const HDSLoc *locator1, HDSLoc **locator2, int *status ) {
*locator2 = NULL;
if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator1, status );

/* Need to get the relevant identfier */
objid = dat1RetrieveIdentifier( locator1, status );

Expand Down
3 changes: 3 additions & 0 deletions datPrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ int datPrec( const HDSLoc * loc, size_t *nbytes, int *status ) {
*nbytes = 0;
if ( *status != SAI__OK ) return *status;

/* Validate input locator. */
dat1ValidateLocator( loc, status );

/* Get object type - assume this has to be nul-terminated */
datType( loc, type, status );

Expand Down
3 changes: 3 additions & 0 deletions datPut.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ datPut( const HDSLoc *locator, const char *type_str, int ndim, const hdsdim dims

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

datName(locator, namestr, status);

/* we do not care because this must be a temporary component
Expand Down
3 changes: 3 additions & 0 deletions datPut1C.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ datPut1C( const HDSLoc * locator, size_t nval, const char *values[], int * statu

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

/* Verify that we have the correct number of values */
datSize( locator, &actval, status );

Expand Down
3 changes: 3 additions & 0 deletions datPutVC.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ datPutVC( const HDSLoc * locator, size_t nval, const char *values[], int * statu

if (*status != SAI__OK) return *status;

/* Validate input locator. */
dat1ValidateLocator( locator, status );

/* Vectorize */
datVec( locator, &vecloc, status );

Expand Down
Loading

0 comments on commit 3aa74f5

Please sign in to comment.