Skip to content

Commit 39e2dd5

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 4f25637 commit 39e2dd5

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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

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

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)