From edc14d6647d3819a9c6ee076ccc3c65f2283600b Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Fri, 24 Nov 2023 10:50:13 -0500 Subject: Fix 4320: add an optional argument list string to the configure CheckFunc method. Add an optional argument list string so the generated function argument list matches the function's prototype when including a header file. --- SCons/Conftest.py | 12 +++++++++--- SCons/SConf.py | 4 ++-- SCons/SConfTests.py | 2 ++ test/Configure/config-h.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/SCons/Conftest.py b/SCons/Conftest.py index 6af5e78..cd122e7 100644 --- a/SCons/Conftest.py +++ b/SCons/Conftest.py @@ -231,13 +231,15 @@ def _check_empty_program(context, comp, text, language, use_shared: bool = False return context.CompileProg(text, suffix) -def CheckFunc(context, function_name, header = None, language = None): +def CheckFunc(context, function_name, header = None, language = None, funcargs = None): """ Configure check for a function "function_name". "language" should be "C" or "C++" and is used to select the compiler. Default is "C". Optional "header" can be defined to define a function prototype, include a header file or anything else that comes before main(). + Optional "funcargs" can be defined to define an argument list for the + generated function invocation. Sets HAVE_function_name in context.havedict according to the result. Note that this uses the current value of compiler and linker flags, make sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly. @@ -274,6 +276,9 @@ char %s(void);""" % function_name context.Display("Cannot check for %s(): %s\n" % (function_name, msg)) return msg + if not funcargs: + funcargs = '' + text = """ %(include)s #include @@ -287,14 +292,15 @@ int main(void) { #if defined (__stub_%(name)s) || defined (__stub___%(name)s) #error "%(name)s has a GNU stub, cannot check" #else - %(name)s(); + %(name)s(%(args)s); #endif return 0; } """ % { 'name': function_name, 'include': includetext, - 'hdr': header } + 'hdr': header, + 'args': funcargs} context.Display("Checking for %s function %s()... " % (lang, function_name)) ret = context.BuildProg(text, suffix) diff --git a/SCons/SConf.py b/SCons/SConf.py index e522c8b..53666e6 100644 --- a/SCons/SConf.py +++ b/SCons/SConf.py @@ -1002,8 +1002,8 @@ def SConf(*args, **kw): return SCons.Util.Null() -def CheckFunc(context, function_name, header = None, language = None) -> bool: - res = SCons.Conftest.CheckFunc(context, function_name, header = header, language = language) +def CheckFunc(context, function_name, header = None, language = None, funcargs = None) -> bool: + res = SCons.Conftest.CheckFunc(context, function_name, header = header, language = language, funcargs = funcargs) context.did_show_result = 1 return not res diff --git a/SCons/SConfTests.py b/SCons/SConfTests.py index 2903ba6..6e9aa62 100644 --- a/SCons/SConfTests.py +++ b/SCons/SConfTests.py @@ -676,6 +676,8 @@ int main(void) { assert r, "did not find strcpy" r = sconf.CheckFunc('strcpy', '/* header */ char strcpy();') assert r, "did not find strcpy" + r = sconf.CheckFunc('strcpy', header='/* header */ char *strcpy(char *dest, char *src);', funcargs='"", ""') + assert r, "did not find strcpy" r = sconf.CheckFunc('hopefullynofunction') assert not r, "unexpectedly found hopefullynofunction" diff --git a/test/Configure/config-h.py b/test/Configure/config-h.py index e5df625..aca18e4 100644 --- a/test/Configure/config-h.py +++ b/test/Configure/config-h.py @@ -41,7 +41,7 @@ env = Environment() import os env.AppendENVPath('PATH', os.environ['PATH']) conf = Configure(env, config_h = 'config.h') -r1 = conf.CheckFunc('printf') +r1 = conf.CheckFunc('printf', header='#include ', funcargs='""') r2 = conf.CheckFunc('noFunctionCall') r3 = conf.CheckFunc('memmove') r4 = conf.CheckType('int') -- cgit v0.12 From 04eed99632e36a504cd7c758f0eb09f6bdf641e9 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 9 Dec 2023 17:42:53 -0800 Subject: Added blurb to CHANGES.txt, RELEASE.txt and updated CheckFunc() in manpage --- CHANGES.txt | 7 ++++--- RELEASE.txt | 5 +++-- doc/man/scons.xml | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index f45dc96..f3cdede 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,9 +9,10 @@ NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer suppo RELEASE VERSION/DATE TO BE FILLED IN LATER - From John Doe: - - - Whatever John Doe did. + From Joseph Brill: + - Add an optional argument list string to configures CheckFunc method so + that the generated function argument list matches the function's + prototype when including a header file. Fixes GH Issue #4320 RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700 diff --git a/RELEASE.txt b/RELEASE.txt index 6bf0d09..d7b24fa 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -26,8 +26,9 @@ DEPRECATED FUNCTIONALITY CHANGED/ENHANCED EXISTING FUNCTIONALITY --------------------------------------- -- List modifications to existing features, where the previous behavior - wouldn't actually be considered a bug +- Add an optional argument list string to configures CheckFunc method so + that the generated function argument list matches the function's + prototype when including a header file. Fixes GH Issue #4320 FIXES ----- diff --git a/doc/man/scons.xml b/doc/man/scons.xml index aaebc2c..81a9d0e 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -3954,7 +3954,7 @@ Returns a boolean indicating success or failure. - context.CheckFunc(function_name, [header, language]) + context.CheckFunc(function_name, [header, language, funcargs]) Checks if function_name is usable in the context's local environment, using the compiler @@ -3974,6 +3974,11 @@ If omitted, the default stanza will be (with function_name appropriately substituted): + + The optional funcargs can be defined to specify an argument list for the generated + function invocation. + + #ifdef __cplusplus extern "C" -- cgit v0.12 From b4f80a79e1e86a4ac0cba1677239ab2251ac5b64 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 10 Dec 2023 15:33:22 -0800 Subject: Address mwichmann's feedback. Annotate with changed version and remove now obsolete note about function prototype --- SCons/Conftest.py | 3 +++ doc/man/scons.xml | 25 ++++++++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/SCons/Conftest.py b/SCons/Conftest.py index cd122e7..79ede99 100644 --- a/SCons/Conftest.py +++ b/SCons/Conftest.py @@ -244,6 +244,9 @@ def CheckFunc(context, function_name, header = None, language = None, funcargs = Note that this uses the current value of compiler and linker flags, make sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly. Returns an empty string for success, an error message for failure. + + .. versionchanged:: 4.7.0 + The ``funcargs`` parameter was added. """ # Remarks from autoconf: diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 81a9d0e..e2e6a57 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -3974,11 +3974,6 @@ If omitted, the default stanza will be (with function_name appropriately substituted): - - The optional funcargs can be defined to specify an argument list for the generated - function invocation. - - #ifdef __cplusplus extern "C" @@ -3987,19 +3982,19 @@ char function_name(void); + The optional funcargs can be defined to specify an argument list for the generated + function invocation. + + + Note: if header is supplied, -it should not -include the standard header file that declares -function_name, -and it should include a -dummy prototype similar to the default case. -Compilers reject builds where a function call does -not match the declared prototype as happens -if the "real" header is included, -and modern compilers are now rejecting -implicit function declarations. + and the function_name being called takes any parameters, appropriate values for those + function arguments should be supplied + by using the funcargs. +Changed in version 4.7.0: added the funcargs. + Returns a boolean indicating success or failure. -- cgit v0.12 From 5c074f7de8a96328d5ff6f969e1be9713d5c1ae7 Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Mon, 11 Dec 2023 05:58:37 -0500 Subject: Minor grammatical update to CHANGES.txt and RELEASE.txt [ci skip] --- CHANGES.txt | 2 +- RELEASE.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 43669e0..98fb24c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,7 +13,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER of _ListVariable class From Joseph Brill: - - Add an optional argument list string to configures CheckFunc method so + - Add an optional argument list string to configure's CheckFunc method so that the generated function argument list matches the function's prototype when including a header file. Fixes GH Issue #4320 diff --git a/RELEASE.txt b/RELEASE.txt index 572ce4b..6082426 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -26,7 +26,7 @@ DEPRECATED FUNCTIONALITY CHANGED/ENHANCED EXISTING FUNCTIONALITY --------------------------------------- -- Add an optional argument list string to configures CheckFunc method so +- Add an optional argument list string to configure's CheckFunc method so that the generated function argument list matches the function's prototype when including a header file. Fixes GH Issue #4320 -- cgit v0.12 From 5ffe87e43ebd3c607084c745de702ed7ede0b8be Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:35:03 -0500 Subject: Add additional CheckFunc test cases and update change notice for CheckFunc. Changes: * add additional CheckFunc test cases to SCons/SConfTests.py * add paragraph tags around change notice for CheckFunc funcargs argument in doc/man/scons.xml --- SCons/SConfTests.py | 15 ++++++++++++++- doc/man/scons.xml | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/SCons/SConfTests.py b/SCons/SConfTests.py index 6e9aa62..08ef25e 100644 --- a/SCons/SConfTests.py +++ b/SCons/SConfTests.py @@ -671,12 +671,25 @@ int main(void) { log_file=self.test.workpath('config.log')) try: - # CheckFunc() + # look for function using default heading r = sconf.CheckFunc('strcpy') assert r, "did not find strcpy" + # no default heading, supply dummy signature r = sconf.CheckFunc('strcpy', '/* header */ char strcpy();') assert r, "did not find strcpy" + # ... supply complete signature, and function args r = sconf.CheckFunc('strcpy', header='/* header */ char *strcpy(char *dest, char *src);', funcargs='"", ""') + # ... supply standard header for prototype, and function args + assert r, "did not find strcpy" + r = sconf.CheckFunc('strcpy', header='#include ', funcargs='"", ""') + # also try in C++ mode + cpp_header = """\ +#ifdef __cplusplus +extern "C" +#endif +char *strcpy(char *dest, char *src); +""" + r = sconf.CheckFunc('strcpy', header=cpp_header, funcargs='"", ""', language="C++") assert r, "did not find strcpy" r = sconf.CheckFunc('hopefullynofunction') assert not r, "unexpectedly found hopefullynofunction" diff --git a/doc/man/scons.xml b/doc/man/scons.xml index e2e6a57..91e8dd7 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -3993,7 +3993,9 @@ Note: if header is supplied, by using the funcargs. + Changed in version 4.7.0: added the funcargs. + Returns a boolean indicating success or failure. -- cgit v0.12 From 9c4887a7988ec9ba37567b8523f0a367eca5b2be Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:22:06 -0500 Subject: Update man/scons.xml CheckFunc documentation for optional header and funcargs usage. [ci skip] --- CHANGES.txt | 10 +++++----- doc/man/scons.xml | 17 ++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 98fb24c..aad3f13 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,14 +8,15 @@ NOTE: The 4.0.0 Release of SCons dropped Python 2.7 Support NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer supported RELEASE VERSION/DATE TO BE FILLED IN LATER + From Ataf Fazledin Ahamed: - Use of NotImplemented instead of NotImplementedError for special methods of _ListVariable class - + From Joseph Brill: - - Add an optional argument list string to configure's CheckFunc method so - that the generated function argument list matches the function's - prototype when including a header file. Fixes GH Issue #4320 + - Fix issue #4320: add an optional argument list string to configure's CheckFunc + method so that the generated function argument list matches the function's + prototype when including a header file. From Michał Górny: - Remove unecessary dependencies on pypi packages from setup.cfg @@ -25,7 +26,6 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER statement with stop flag enabled - RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700 From Max Bachmann: diff --git a/doc/man/scons.xml b/doc/man/scons.xml index 91e8dd7..22f93f5 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -3982,15 +3982,14 @@ char function_name(void); - The optional funcargs can be defined to specify an argument list for the generated - function invocation. - - - -Note: if header is supplied, - and the function_name being called takes any parameters, appropriate values for those - function arguments should be supplied - by using the funcargs. +If header is supplied, it should not include +the standard header file that declares function_name and it +should include a dummy prototype similar to the default case. If +this is not possible, the optional funcargs argument can be used +to specify a string containing an argument list with the same number and type of +arguments as the prototype. The arguments can simply be constant values of the correct +type. Modern C/C++ compilers reject implicit function declarations and may also reject +function calls whose arguments are not type compatible with the prototype. -- cgit v0.12