Skip to content

Commit 38f555b

Browse files
committed
feat: check FLINT version at runtime
Add a runtime check that disallows FLINT versions earlier than 3.2.0. Note that the version check is also performed during the configure step. A runtime failure typically indicates that an incorrect shared library was linked.
1 parent d6973e8 commit 38f555b

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

sources/declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ extern WORD* flint_ratfun_add(PHEAD WORD *, WORD *);
16261626
extern int flint_ratfun_normalize(PHEAD WORD *);
16271627
extern WORD* flint_rem(PHEAD WORD *, WORD *, const WORD);
16281628
extern void flint_startup_init(void);
1629+
extern void flint_check_version(void);
16291630
#endif
16301631

16311632
extern void optimize_print_code (int);

sources/flintwrap.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
#include "form3.h"
88
}
99

10+
#include <sstream>
1011
#include "flintinterface.h"
1112

1213

@@ -289,4 +290,38 @@ void flint_startup_init(void) {
289290
}
290291
/*
291292
#] flint_startup_init :
293+
#[ flint_check_version :
294+
*/
295+
296+
/**
297+
* Checks the FLINT library version at runtime.
298+
*
299+
* This function should be called at startup.
300+
* The program will terminate if a known buggy version of FLINT is detected.
301+
*/
302+
void flint_check_version(void) {
303+
bool ok = true;
304+
std::stringstream ss(flint_version);
305+
int major, minor, patch;
306+
char dot1, dot2;
307+
if ( ss >> major >> dot1 >> minor >> dot2 >> patch ) {
308+
if ( dot1 != '.' || dot2 != '.' || major < 0 || minor < 0 || patch < 0 ) {
309+
ok = false;
310+
}
311+
else if ( major * 10000 + minor * 100 + patch < 30200 ) {
312+
// flint < 3.2.0: https://github.com/form-dev/form/issues/679
313+
ok = false;
314+
}
315+
}
316+
else {
317+
ok = false;
318+
}
319+
if ( !ok ) {
320+
MesPrint("Bad FLINT version detected at runtime: %s",flint_version);
321+
Terminate(-2);
322+
}
323+
}
324+
325+
/*
326+
#] flint_check_version :
292327
*/

sources/startup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,9 @@ int main(int argc, char **argv)
17391739
Globalize(1);
17401740
#ifdef WITH_ALARM
17411741
if ( AM.TimeLimit > 0 ) alarm(AM.TimeLimit);
1742+
#endif
1743+
#ifdef WITHFLINT
1744+
flint_check_version();
17421745
#endif
17431746
TimeCPU(0);
17441747
TimeChildren(0);

0 commit comments

Comments
 (0)