You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2012/12/27 19:20:55 UTC

[lucy-commits] [1/12] git commit: refs/heads/cfc-sprintf - Add Strings probe to Charmonizer

Add Strings probe to Charmonizer

For now, the Strings probe only tests for a C99-compatible snprintf
function and for _scprintf from MSVCRT.


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

Branch: refs/heads/cfc-sprintf
Commit: 9ba0fc1541e3bdc06176dcbed99489cbd3c03443
Parents: d874b33
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Dec 26 19:17:55 2012 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Dec 26 19:17:55 2012 +0100

----------------------------------------------------------------------
 charmonizer/src/Charmonizer/Probe/Strings.c |   82 ++++++++++++++++++++++
 charmonizer/src/Charmonizer/Probe/Strings.h |   39 ++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/9ba0fc15/charmonizer/src/Charmonizer/Probe/Strings.c
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Probe/Strings.c b/charmonizer/src/Charmonizer/Probe/Strings.c
new file mode 100644
index 0000000..74dc292
--- /dev/null
+++ b/charmonizer/src/Charmonizer/Probe/Strings.c
@@ -0,0 +1,82 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Charmonizer/Core/Compiler.h"
+#include "Charmonizer/Core/ConfWriter.h"
+#include "Charmonizer/Probe/Strings.h"
+
+/* Check for C99-compatible snprintf and possible replacements.
+ */
+static void
+chaz_Strings_probe_c99_snprintf(void);
+
+void
+chaz_Strings_run(void) {
+    chaz_ConfWriter_start_module("Strings");
+
+    /* Check for C99 snprintf. */
+    chaz_Strings_probe_c99_snprintf();
+
+    chaz_ConfWriter_end_module();
+}
+
+static void
+chaz_Strings_probe_c99_snprintf(void) {
+    static const char snprintf_code[] =
+        CHAZ_QUOTE(  #include <stdio.h>                             )
+        CHAZ_QUOTE(  int main() {                                   )
+        CHAZ_QUOTE(      char buf[4];                               )
+        CHAZ_QUOTE(      int  result;                               )
+        CHAZ_QUOTE(      result = snprintf(buf, 4, "%s", "12345");  )
+        CHAZ_QUOTE(      printf("%d", result);                      )
+        CHAZ_QUOTE(      return 0;                                  )
+        CHAZ_QUOTE(  }                                              );
+    static const char scprintf_code[] =
+        CHAZ_QUOTE(  #include <stdio.h>                             )
+        CHAZ_QUOTE(  int main() {                                   )
+        CHAZ_QUOTE(      int  result;                               )
+        CHAZ_QUOTE(      result = _scprintf("%s", "12345");         )
+        CHAZ_QUOTE(      printf("%d", result);                      )
+        CHAZ_QUOTE(      return 0;                                  )
+        CHAZ_QUOTE(  }                                              );
+    char   *output = NULL;
+    size_t  output_len;
+
+    /* If the buffer passed to snprintf is too small, verify that snprintf
+     * returns the length of the untruncated string which would have been
+     * written to a large enough buffer.
+     */
+    output = chaz_CC_capture_output(snprintf_code, &output_len);
+    if (output != NULL) {
+        long result = strtol(output, NULL, 10);
+        if (result == 5) {
+            chaz_ConfWriter_add_def("HAS_C99_SNPRINTF", NULL);
+        }
+        free(output);
+    }
+
+    /* Test for _scprintf found in the MSVCRT.
+     */
+    output = chaz_CC_capture_output(scprintf_code, &output_len);
+    if (output != NULL) {
+        long result = strtol(output, NULL, 10);
+        if (result == 5) {
+            chaz_ConfWriter_add_def("HAS__SCPRINTF", NULL);
+        }
+        free(output);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/9ba0fc15/charmonizer/src/Charmonizer/Probe/Strings.h
----------------------------------------------------------------------
diff --git a/charmonizer/src/Charmonizer/Probe/Strings.h b/charmonizer/src/Charmonizer/Probe/Strings.h
new file mode 100644
index 0000000..031459d
--- /dev/null
+++ b/charmonizer/src/Charmonizer/Probe/Strings.h
@@ -0,0 +1,39 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Charmonizer/Probe/Strings.h
+ */
+
+#ifndef H_CHAZ_STRINGS
+#define H_CHAZ_STRINGS
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* The Strings module attempts to detect whether snprintf works as specified
+ * by the C99 standard. It also looks for system-specific functions which can
+ * be used to emulate snprintf.
+ */
+void chaz_Strings_run(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CHAZ_STRINGS */
+
+