lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject lucy-charmonizer git commit: Add chaz_HeadCheck_defines_symbol
Date Sat, 10 Jan 2015 22:42:35 GMT
Repository: lucy-charmonizer
Updated Branches:
  refs/heads/master 3c4bdd891 -> c6d42668b


Add chaz_HeadCheck_defines_symbol

This function checks whether a symbol is defined in the given headers
files. Symbols defined as macros are supported.


Project: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/commit/c6d42668
Tree: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/tree/c6d42668
Diff: http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/diff/c6d42668

Branch: refs/heads/master
Commit: c6d42668b387c585583b0d1d70e8913042bf3c5f
Parents: 3c4bdd8
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat Jan 10 18:29:05 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Sat Jan 10 18:29:05 2015 +0100

----------------------------------------------------------------------
 src/Charmonizer/Core/HeaderChecker.c | 28 ++++++++++++++++++++++++++++
 src/Charmonizer/Core/HeaderChecker.h |  4 ++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/c6d42668/src/Charmonizer/Core/HeaderChecker.c
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/HeaderChecker.c b/src/Charmonizer/Core/HeaderChecker.c
index 7aea085..5b1c90b 100644
--- a/src/Charmonizer/Core/HeaderChecker.c
+++ b/src/Charmonizer/Core/HeaderChecker.c
@@ -131,6 +131,34 @@ chaz_HeadCheck_check_many_headers(const char **header_names) {
 }
 
 int
+chaz_HeadCheck_defines_symbol(const char *symbol, const char *includes) {
+    /*
+     * Casting function pointers to object pointers like 'char*' is a C
+     * extension, so for a bullet-proof check, a separate test for functions
+     * might be necessary.
+     */
+    static const char defines_code[] =
+        CHAZ_QUOTE(  %s                                            )
+        CHAZ_QUOTE(  int main() {                                  )
+        CHAZ_QUOTE(  #ifdef %s                                     )
+        CHAZ_QUOTE(      return 0;                                 )
+        CHAZ_QUOTE(  #else                                         )
+        CHAZ_QUOTE(      return *(char*)&%s;                       )
+        CHAZ_QUOTE(  #endif                                        )
+        CHAZ_QUOTE(  }                                             );
+    long needed = sizeof(defines_code)
+                  + 2 * strlen(symbol)
+                  + strlen(includes)
+                  + 10;
+    char *buf = (char*)malloc(needed);
+    int retval;
+    sprintf(buf, defines_code, includes, symbol, symbol);
+    retval = chaz_CC_test_compile(buf);
+    free(buf);
+    return retval;
+}
+
+int
 chaz_HeadCheck_contains_member(const char *struct_name, const char *member,
                                const char *includes) {
     static const char contains_code[] =

http://git-wip-us.apache.org/repos/asf/lucy-charmonizer/blob/c6d42668/src/Charmonizer/Core/HeaderChecker.h
----------------------------------------------------------------------
diff --git a/src/Charmonizer/Core/HeaderChecker.h b/src/Charmonizer/Core/HeaderChecker.h
index 2d0a175..e7c14cb 100644
--- a/src/Charmonizer/Core/HeaderChecker.h
+++ b/src/Charmonizer/Core/HeaderChecker.h
@@ -44,6 +44,10 @@ chaz_HeadCheck_check_header(const char *header_name);
 int
 chaz_HeadCheck_check_many_headers(const char **header_names);
 
+/* Return true if the symbol is defined (possibly as a macro). */
+int
+chaz_HeadCheck_defines_symbol(const char *symbol, const char *includes);
+
 /* Return true if the member is present in the struct. */
 int
 chaz_HeadCheck_contains_member(const char *struct_name, const char *member,


Mime
View raw message