Skip to content

Commit

Permalink
Further changes to accomodate size_t string lengths in gfortran v8
Browse files Browse the repository at this point in the history
  • Loading branch information
dsberry committed May 10, 2022
1 parent d2f0caf commit 6db0cad
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 67 deletions.
2 changes: 1 addition & 1 deletion component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE component SYSTEM "componentinfo.dtd">

<component id="ast" support="S">
<version>9.2.7</version>
<version>9.2.8</version>
<path>libext/ast</path>
<description>WCS library</description>
<abstract>
Expand Down
21 changes: 19 additions & 2 deletions src/f77.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@
* Initialise pointers.
* 11-MAY-2011 (DSB):
* Added F77_LOCK
* 10-MAY-2022 (DSB):
* Added version of F77_EXPORT_CHARACTER that uses AST for memory
* management instead of CNF. This was driven by the change of
* TRAIL_TYPE from int to size_t in gfortran v8. Some AST source
* files were assuming int (e.g. fplot.c).
* {enter_further_changes_here}
*

Expand Down Expand Up @@ -469,7 +474,7 @@
#define DECLARE_POINTER(X) F77_POINTER_TYPE X

#define DECLARE_CHARACTER(X,L) F77_CHARACTER_TYPE X[L]; \
const @TRAIL_TYPE@ X##_length = L
@TRAIL_TYPE@ X##_length = L


/* --- Declare arrays --- */
Expand Down Expand Up @@ -556,7 +561,6 @@

/* --- IMPORT and EXPORT of values --- */
/* Export C variables to Fortran variables */
#define F77_EXPORT_CHARACTER(C,F,L) cnfExprt(C,F,L)
#define F77_EXPORT_DOUBLE(C,F) F=C
#define F77_EXPORT_INTEGER(C,F) F=C
#define F77_EXPORT_LOGICAL(C,F) F=C?F77_TRUE:F77_FALSE
Expand All @@ -568,6 +572,19 @@
#define F77_EXPORT_POINTER(C,F) F=cnfFptr(C)
#define F77_EXPORT_LOCATOR(C,F) cnfExpch(C,F,DAT__SZLOC)

/* CNF functions are not available within AST, so re-define a
F77_EXPORT_CHARACTER macro that exports a character string
from C to Fortran using functions in the AST memory.c module. */
/* #define F77_EXPORT_CHARACTER(C,F,L) cnfExprt(C,F,L) */
#define F77_EXPORT_CHARACTERL(C,F,L) \
if( F##_length > L ) F##_length = L; \
astStringExport( C, F, F##_length ); \

#define F77_EXPORT_CHARACTER(C,F) { \
@TRAIL_TYPE@ clen = strlen(C); \
F77_EXPORT_CHARACTERL(C,F,clen); \
}

/* Allow for character strings to be NULL, protects strlen. Note this
* does not allow lengths to differ. */
#define F77_CREATE_EXPORT_CHARACTER(C,F) \
Expand Down
10 changes: 3 additions & 7 deletions src/ferror.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,12 @@ F77_SUBROUTINE(ast_setputerr)( AstPutErrFun FUN, INTEGER(STATUS) ) {
static void FPutErrWrapper( AstPutErrFun fun, int status_value, const char *message ){

DECLARE_CHARACTER(LMESSAGE,MXSTRLEN);
int fmessage_length;

fmessage_length = strlen( message );
if( fmessage_length > LMESSAGE_length ) fmessage_length = LMESSAGE_length;
astStringExport( message, LMESSAGE, fmessage_length );
F77_EXPORT_CHARACTER(message, LMESSAGE);

( *(void (*)( INTEGER(status_value), CHARACTER(LMESSAGE)
TRAIL(fmessage) ) ) fun)(INTEGER_ARG(&status_value),
TRAIL(LMESSAGE) ) ) fun)(INTEGER_ARG(&status_value),
CHARACTER_ARG(LMESSAGE)
TRAIL_ARG(fmessage));
TRAIL_ARG(LMESSAGE));


}
Expand Down
42 changes: 14 additions & 28 deletions src/fplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,25 +529,18 @@ static int FGTextWrapper( AstPlot *this, const char *text, float x, float y,

DECLARE_CHARACTER(LTEXT,MXSTRLEN);
DECLARE_CHARACTER(LJUST,MXSTRLEN);
int ftext_length;
int fjust_length;

F77_INTEGER_TYPE(GRFCON);
int *status = astGetStatusPtr;
if ( !astOK ) return 0;
GRFCON = astP2I( astGrfConID( this ) );

ftext_length = strlen( text );
if( ftext_length > LTEXT_length ) ftext_length = LTEXT_length;
astStringExport( text, LTEXT, ftext_length );

fjust_length = strlen( just );
if( fjust_length > LJUST_length ) fjust_length = LJUST_length;
astStringExport( just, LJUST, fjust_length );
F77_EXPORT_CHARACTER(text,LTEXT);
F77_EXPORT_CHARACTER(just,LJUST);

return ( *(int (*)( INTEGER(grfcon), CHARACTER(LTEXT), REAL(x), REAL(y),
CHARACTER(LJUST), REAL(upx), REAL(upy)
TRAIL(ftext) TRAIL(fjust) ) )
TRAIL(LTEXT) TRAIL(LJUST) ) )
this->grffun[ AST__GTEXT ])(
INTEGER_ARG(&GRFCON),
CHARACTER_ARG(LTEXT),
Expand All @@ -556,8 +549,8 @@ static int FGTextWrapper( AstPlot *this, const char *text, float x, float y,
CHARACTER_ARG(LJUST),
REAL_ARG(&upx),
REAL_ARG(&upy)
TRAIL_ARG(ftext)
TRAIL_ARG(fjust) );
TRAIL_ARG(LTEXT)
TRAIL_ARG(LJUST) );
}

static int FGCapWrapper( AstPlot *this, int cap, int value ) {
Expand All @@ -577,26 +570,19 @@ static int FGTxExtWrapper( AstPlot *this, const char *text, float x, float y,
float *yb ) {
DECLARE_CHARACTER(LTEXT,MXSTRLEN);
DECLARE_CHARACTER(LJUST,MXSTRLEN);
int ftext_length;
int fjust_length;

F77_INTEGER_TYPE(GRFCON);
int *status = astGetStatusPtr;
if ( !astOK ) return 0;
GRFCON = astP2I( astGrfConID( this ) );

ftext_length = strlen( text );
if( ftext_length > LTEXT_length ) ftext_length = LTEXT_length;
astStringExport( text, LTEXT, ftext_length );

fjust_length = strlen( just );
if( fjust_length > LJUST_length ) fjust_length = LJUST_length;
astStringExport( just, LJUST, fjust_length );
F77_EXPORT_CHARACTER(text,LTEXT);
F77_EXPORT_CHARACTER(just,LJUST);

return ( *(int (*)( INTEGER(grfcon), CHARACTER(LTEXT), REAL(x), REAL(y),
CHARACTER(LJUST), REAL(upx), REAL(upy),
REAL_ARRAY(xb), REAL_ARRAY(yb) TRAIL(ftext)
TRAIL(fjust) ) )
REAL_ARRAY(xb), REAL_ARRAY(yb) TRAIL(LTEXT)
TRAIL(LJUST) ) )
this->grffun[ AST__GTXEXT ])(
INTEGER_ARG(&GRFCON),
CHARACTER_ARG(LTEXT),
Expand All @@ -607,8 +593,8 @@ static int FGTxExtWrapper( AstPlot *this, const char *text, float x, float y,
REAL_ARG(&upy),
REAL_ARRAY_ARG(xb),
REAL_ARRAY_ARG(yb)
TRAIL_ARG(ftext)
TRAIL_ARG(fjust) );
TRAIL_ARG(LTEXT)
TRAIL_ARG(LJUST) );
}

static int FGQchWrapper( AstPlot *this, float *chv, float *chh ) {
Expand Down Expand Up @@ -649,19 +635,19 @@ F77_SUBROUTINE(ast_stripescapes)( CHARACTER_RETURN_VALUE(RESULT),
GENPTR_CHARACTER(TEXT)
char *text;
const char *result;
int i;
size_t i;

astAt( "AST_STRIPESCAPES", NULL, 0 );
astWatchSTATUS(
text = astString( TEXT, TEXT_length );
result = astStripEscapes( text );
i = 0;
if ( astOK ) { /* Copy result */
for ( ; result[ i ] && i < RESULT_length; i++ ) {
for ( ; result[ i ] && i < (size_t) RESULT_length; i++ ) {
RESULT[ i ] = result[ i ];
}
}
while ( i < RESULT_length ) RESULT[ i++ ] = ' '; /* Pad with blanks */
while ( i < (size_t) RESULT_length ) RESULT[ i++ ] = ' '; /* Pad with blanks */
astFree( text );
)
}
Expand Down
13 changes: 5 additions & 8 deletions src/grf3d_pgplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -3102,25 +3102,22 @@ static void ccgrsyds( int *list, int *nlist, const char *text, int tlen,
F77_INTEGER_TYPE NLIST;
DECLARE_CHARACTER(LTEXT,MXSTRLEN);
F77_INTEGER_TYPE FONT;
int ftext_length;
int i;
size_t i;

ftext_length = tlen;
if( ftext_length > LTEXT_length ) ftext_length = LTEXT_length;
astStringExport( text, LTEXT, ftext_length );
F77_EXPORT_CHARACTERL(text,LTEXT,tlen);

LIST = (F77_INTEGER_TYPE *) astMalloc( sizeof( F77_INTEGER_TYPE )*(size_t) ftext_length );
LIST = (F77_INTEGER_TYPE *) astMalloc( sizeof( F77_INTEGER_TYPE )*(size_t) LTEXT_length );

if( astOK ){

FONT = (F77_INTEGER_TYPE) font;

F77_CALL(grsyds)( INTEGER_ARRAY_ARG(LIST), INTEGER_ARG(&NLIST),
CHARACTER_ARG(LTEXT), INTEGER_ARG(&FONT)
TRAIL_ARG(ftext) );
TRAIL_ARG(LTEXT) );

*nlist = (int) NLIST;
for( i = 0; i < ftext_length; i++ ){
for( i = 0; i < LTEXT_length; i++ ){
list[ i ] = (int) LIST[ i ];
}

Expand Down
30 changes: 9 additions & 21 deletions src/grf_pgplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
* 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 Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
Expand Down Expand Up @@ -1076,7 +1076,7 @@ int astGAttr( int attr, double value, double *old_value, int prim ){
* Synopsis:
* #include "grf.h"
* int int astGAttr( int attr, double value, double *old_value, int prim )
* int astGAttr( int attr, double value, double *old_value, int prim )
* Description:
* This function returns the current value of a specified graphics
Expand Down Expand Up @@ -1281,20 +1281,16 @@ static void ccpgptxt(float x, float y, float angle, float fjust, char *text ){
F77_REAL_TYPE ANGLE;
F77_REAL_TYPE FJUST;
DECLARE_CHARACTER(LTEXT,MXSTRLEN);
int ftext_length;

X = (F77_REAL_TYPE) x;
Y = (F77_REAL_TYPE) y;
ANGLE = (F77_REAL_TYPE) angle;
FJUST = (F77_REAL_TYPE) fjust;

ftext_length = strlen( text );
if( ftext_length > LTEXT_length ) ftext_length = LTEXT_length;
astStringExport( text, LTEXT, ftext_length );
F77_EXPORT_CHARACTER(text,LTEXT);

F77_CALL(pgptxt)( REAL_ARG(&X), REAL_ARG(&Y), REAL_ARG(&ANGLE),
REAL_ARG(&FJUST), CHARACTER_ARG(LTEXT)
TRAIL_ARG(ftext) );
TRAIL_ARG(LTEXT) );
}

static void ccpgqtxt(float x, float y, float angle, float fjust, char *text,
Expand All @@ -1307,21 +1303,18 @@ static void ccpgqtxt(float x, float y, float angle, float fjust, char *text,
F77_REAL_TYPE XBOX[ 4 ];
F77_REAL_TYPE YBOX[ 4 ];
int i;
int ftext_length;

X = (F77_REAL_TYPE) x;
Y = (F77_REAL_TYPE) y;
ANGLE = (F77_REAL_TYPE) angle;
FJUST = (F77_REAL_TYPE) fjust;

ftext_length = strlen( text );
if( ftext_length > LTEXT_length ) ftext_length = LTEXT_length;
astStringExport( text, LTEXT, ftext_length );
F77_EXPORT_CHARACTER(text,LTEXT);

F77_CALL(pgqtxt)( REAL_ARG(&X), REAL_ARG(&Y), REAL_ARG(&ANGLE),
REAL_ARG(&FJUST), CHARACTER_ARG(LTEXT),
REAL_ARRAY_ARG(XBOX), REAL_ARRAY_ARG(YBOX)
TRAIL_ARG(ftext) );
TRAIL_ARG(LTEXT) );

for( i = 0; i < 4; i++ ){
xbox[ i ] = (float) XBOX[ i ];
Expand Down Expand Up @@ -1359,17 +1352,12 @@ static void ccpglen(int units, char *text, float *xl, float *yl ){
F77_REAL_TYPE XL;
F77_REAL_TYPE YL;
DECLARE_CHARACTER(LTEXT,MXSTRLEN);
int ftext_length;

UNITS = (F77_INTEGER_TYPE) units;


ftext_length = strlen( text );
if( ftext_length > LTEXT_length ) ftext_length = LTEXT_length;
astStringExport( text, LTEXT, ftext_length );
F77_EXPORT_CHARACTER(text,LTEXT);

F77_CALL(pglen)( INTEGER_ARG(&UNITS), CHARACTER_ARG(LTEXT),
REAL_ARG(&XL), REAL_ARG(&YL) TRAIL_ARG(ftext) );
REAL_ARG(&XL), REAL_ARG(&YL) TRAIL_ARG(LTEXT) );

*xl = (float) XL;
*yl = (float) YL;
Expand Down

0 comments on commit 6db0cad

Please sign in to comment.