[Swift-commit] cog r3951

swift at ci.uchicago.edu swift at ci.uchicago.edu
Mon Jun 23 11:30:03 CDT 2014


------------------------------------------------------------------------
r3951 | timgarmstrong | 2014-06-23 11:29:22 -0500 (Mon, 23 Jun 2014) | 1 line

Ditch wrapper struct for settings
------------------------------------------------------------------------
Index: modules/provider-coaster-c-client/src/coasters.cpp
===================================================================
--- modules/provider-coaster-c-client/src/coasters.cpp	(revision 3950)
+++ modules/provider-coaster-c-client/src/coasters.cpp	(working copy)
@@ -51,12 +51,6 @@
   };
 };
 
-struct coaster_settings {
-  Settings settings;
-
-  coaster_settings() : settings() {};
-};
-
 static coaster_rc coaster_error_rc(const CoasterError &err);
 static coaster_rc exception_rc(const std::exception &ex);
 
@@ -103,7 +97,7 @@
 coaster_rc coaster_settings_create(coaster_settings **settings)
                                 COASTERS_THROWS_NOTHING {
   try {
-    *settings = new coaster_settings();
+    *settings = new Settings();
     if (!(*settings)) {
       return COASTER_ERROR_OOM;
     }
@@ -129,7 +123,7 @@
           const char *key, size_t key_len,
           const char *value, size_t value_len) COASTERS_THROWS_NOTHING {
   try {
-    settings->settings.set(key, key_len, value, value_len); 
+    settings->set(key, key_len, value, value_len); 
     return COASTER_SUCCESS;
   } catch (const CoasterError& err) {
     return coaster_error_rc(err);
@@ -143,7 +137,7 @@
             const char *key, size_t key_len,
             const char **value, size_t *value_len) COASTERS_THROWS_NOTHING {
   try {
-    std::map<string, string> &map = settings->settings.getSettings();
+    std::map<string, string> &map = settings->getSettings();
     std::string &str_value = map[string(key, key_len)];
     *value = str_value.c_str();
     *value_len = str_value.length();
@@ -160,7 +154,7 @@
               const char ***keys, size_t **key_lens, int *count)
                                 COASTERS_THROWS_NOTHING {
   try {
-    std::map<string, string> &map = settings->settings.getSettings();
+    std::map<string, string> &map = settings->getSettings();
     *count = map.size();
 
     // Use malloc so C client code can free
@@ -210,8 +204,12 @@
 coaster_apply_settings(coaster_client *client,
                                   coaster_settings *settings)
                                   COASTERS_THROWS_NOTHING {
+  if (settings == NULL || client == NULL) {
+    return COASTER_ERROR_INVALID;
+  }
+
   try {
-    client->client.setOptions(settings->settings);
+    client->client.setOptions(*settings);
     return COASTER_SUCCESS;
   } catch (const CoasterError& err) {
     return coaster_error_rc(err);
Index: modules/provider-coaster-c-client/src/coasters.h
===================================================================
--- modules/provider-coaster-c-client/src/coasters.h	(revision 3950)
+++ modules/provider-coaster-c-client/src/coasters.h	(working copy)
@@ -42,13 +42,18 @@
 
 // Opaque pointer types
 typedef struct coaster_client coaster_client;
-typedef struct coaster_settings coaster_settings;
 
+/*
+  Treat some types as direct pointers to real classes for C++, but opaque
+  pointers to dummy structs for C code to allow typechecking, but prevent
+  manipulation of the rbjects.
+ */
 #ifdef __cplusplus
-// Treat as direct pointer to class for C++
+typedef class Settings coaster_settings;
 typedef class Job coaster_job;
 #else
-// Treat as opaque pointer to unimplemented struct for C
+// Treat these types as opaque pointer to unimplemented struct for C
+typedef struct coaster_settings_opaque_ coaster_settings;
 typedef struct coaster_job_opaque_ coaster_job;
 #endif
 



More information about the Swift-commit mailing list