[120064] trunk/base/src/cregistry

cal at macports.org cal at macports.org
Wed May 14 15:09:19 PDT 2014


Revision: 120064
          https://trac.macports.org/changeset/120064
Author:   cal at macports.org
Date:     2014-05-14 15:09:19 -0700 (Wed, 14 May 2014)
Log Message:
-----------
base: cregistry: Fix warnings on Linux, stick to a standard, avoid undefined behavior

Modified Paths:
--------------
    trunk/base/src/cregistry/Makefile.in
    trunk/base/src/cregistry/registry.c
    trunk/base/src/cregistry/registry.h

Modified: trunk/base/src/cregistry/Makefile.in
===================================================================
--- trunk/base/src/cregistry/Makefile.in	2014-05-14 22:00:20 UTC (rev 120063)
+++ trunk/base/src/cregistry/Makefile.in	2014-05-14 22:09:19 UTC (rev 120064)
@@ -12,6 +12,9 @@
 
 include ../../Mk/macports.autoconf.mk
 
+# required for strdup(3) on Linux and OS X
+CPPFLAGS+=-D_XOPEN_SOURCE=600
+
 all:: ${STLIB_NAME} ${SQLEXT_NAME}
 
 .c.o:

Modified: trunk/base/src/cregistry/registry.c
===================================================================
--- trunk/base/src/cregistry/registry.c	2014-05-14 22:00:20 UTC (rev 120063)
+++ trunk/base/src/cregistry/registry.c	2014-05-14 22:09:19 UTC (rev 120064)
@@ -54,6 +54,21 @@
  *       alive at any given time.
  */
 
+/*
+ * Error constants. Those need to be constants and cannot be string literals
+ * because we'll use address comparisons for those and compilers don't have to
+ * guarantee string literals always have the same address (they don't have to
+ * guarantee string literals will have an address at all, so comparing the
+ * address of a string with a string literal is undefined behavior).
+ */
+char *const registry_err_not_found      = "registry::not-found";
+char *const registry_err_invalid        = "registry::invalid";
+char *const registry_err_constraint     = "registry::constraint";
+char *const registry_err_sqlite_error   = "registry::sqlite-error";
+char *const registry_err_misuse         = "registry::misuse";
+char *const registry_err_cannot_init    = "registry::cannot-init";
+char *const registry_err_already_active = "registry::already-active";
+
 /**
  * Destroys a `reg_error` object. This should be called on any reg_error when a
  * registry function returns a failure condition; depending on the function,

Modified: trunk/base/src/cregistry/registry.h
===================================================================
--- trunk/base/src/cregistry/registry.h	2014-05-14 22:00:20 UTC (rev 120063)
+++ trunk/base/src/cregistry/registry.h	2014-05-14 22:09:19 UTC (rev 120064)
@@ -37,14 +37,22 @@
 #include <sqlite3.h>
 #include <tcl.h>
 
-#define REG_NOT_FOUND       "registry::not-found"
-#define REG_INVALID         "registry::invalid"
-#define REG_CONSTRAINT      "registry::constraint"
-#define REG_SQLITE_ERROR    "registry::sqlite-error"
-#define REG_MISUSE          "registry::misuse"
-#define REG_CANNOT_INIT     "registry::cannot-init"
-#define REG_ALREADY_ACTIVE  "registry::already-active"
+#define REG_NOT_FOUND       (registry_err_not_found)
+#define REG_INVALID         (registry_err_invalid)
+#define REG_CONSTRAINT      (registry_err_constraint)
+#define REG_SQLITE_ERROR    (registry_err_sqlite_error)
+#define REG_MISUSE          (registry_err_misuse)
+#define REG_CANNOT_INIT     (registry_err_cannot_init)
+#define REG_ALREADY_ACTIVE  (registry_err_already_active)
 
+extern char *const registry_err_not_found;
+extern char *const registry_err_invalid;
+extern char *const registry_err_constraint;
+extern char *const registry_err_sqlite_error;
+extern char *const registry_err_misuse;
+extern char *const registry_err_cannot_init;
+extern char *const registry_err_already_active;
+
 typedef void reg_error_destructor(const char* description);
 
 typedef struct {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140514/6219fd62/attachment.html>


More information about the macports-changes mailing list