Browse Source

avoid passing time_t between different compilers

David Rose 15 years ago
parent
commit
c2e54f12db

+ 5 - 1
direct/src/plugin/p3dInstance.cxx

@@ -220,7 +220,11 @@ P3DInstance(P3D_request_ready_func *func,
   _panda_script_object->set_string_property("coreapiHostUrl", inst_mgr->get_coreapi_host_url());
   time_t timestamp = inst_mgr->get_coreapi_timestamp();
   _panda_script_object->set_int_property("coreapiTimestamp", (int)timestamp);
-  _panda_script_object->set_string_property("coreapiTimestampString", ctime(&timestamp));
+  const char *timestamp_string = ctime(&timestamp);
+  if (timestamp_string == NULL) {
+    timestamp_string = "";
+  }
+  _panda_script_object->set_string_property("coreapiTimestampString", timestamp_string);
   _panda_script_object->set_string_property("coreapiVersionString", inst_mgr->get_coreapi_set_ver());
 
 

+ 7 - 1
direct/src/plugin/p3dInstanceManager.cxx

@@ -333,7 +333,12 @@ set_plugin_version(int major, int minor, int sequence,
   nout << "Plugin distributor: " << _plugin_distributor << "\n";
   nout << "Core API host URL: " <<  _coreapi_host_url << "\n";
   nout << "Core API version: " << _coreapi_set_ver << "\n";
-  nout << "Core API date: " << ctime(&_coreapi_timestamp) << "\n";
+
+  const char *timestamp_string = ctime(&_coreapi_timestamp);
+  if (timestamp_string == NULL) {
+    timestamp_string = "";
+  }
+  nout << "Core API date: " << timestamp_string << "\n";
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -1379,6 +1384,7 @@ create_runtime_environment() {
        << ", host_url = " << _host_url
        << ", verify_contents = " << _verify_contents
        << "\n";
+  nout << "api_version = " << _api_version << "\n";
 
   // Make the certificate directory.
   _certs_dir = _root_dir + "/certs";

+ 13 - 1
direct/src/plugin/p3d_plugin.cxx

@@ -104,7 +104,7 @@ void
 P3D_set_plugin_version(int major, int minor, int sequence,
                        bool official, const char *distributor,
                        const char *coreapi_host_url,
-                       time_t coreapi_timestamp,
+                       const char *coreapi_timestamp_str,
                        const char *coreapi_set_ver) {
   assert(P3DInstanceManager::get_global_ptr()->is_initialized());
   if (distributor == NULL) {
@@ -116,7 +116,19 @@ P3D_set_plugin_version(int major, int minor, int sequence,
 
   ACQUIRE_LOCK(_api_lock);
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
+
+  time_t coreapi_timestamp = 0;
+  if (inst_mgr->get_api_version() < 15) {
+    // Before version 15, this was passed as a time_t.  
+    coreapi_timestamp = (time_t)coreapi_timestamp_str;
+  } else {
+    // Passing a time_t causes problems with disagreements about word
+    // size, so since version 15 we pass it as a string.
+    coreapi_timestamp = strtoul(coreapi_timestamp_str, NULL, 10);
+  }
+
   if (inst_mgr->get_api_version() < 14 || coreapi_set_ver == NULL) {
+    // Prior to version 14 this parameter was absent.
     coreapi_set_ver = "";
   }
 

+ 2 - 2
direct/src/plugin/p3d_plugin.h

@@ -79,7 +79,7 @@ extern "C" {
    (below). This number will be incremented whenever there are changes
    to any of the interface specifications defined in this header
    file. */
-#define P3D_API_VERSION 14
+#define P3D_API_VERSION 15
 
 /************************ GLOBAL FUNCTIONS **************************/
 
@@ -168,7 +168,7 @@ typedef void
 P3D_set_plugin_version_func(int major, int minor, int sequence,
                             bool official, const char *distributor,
                             const char *coreapi_host_url,
-                            time_t coreapi_timestamp,
+                            const char *coreapi_timestamp,
                             const char *coreapi_set_ver);
 
 /* This function defines a "super mirror" URL: a special URL that is

+ 9 - 2
direct/src/plugin_activex/PPInstance.cpp

@@ -529,6 +529,13 @@ int PPInstance::LoadPlugin( const std::string& dllFilename )
         nout << "Unable to launch core API in " << pathname << "\n";
         error = 1;
       } else {
+
+        // Format the coreapi_timestamp as a string, for passing as a
+        // parameter.
+        ostringstream stream;
+        stream << _coreapi_dll.get_timestamp();
+        string coreapi_timestamp = stream.str();
+
 #ifdef PANDA_OFFICIAL_VERSION
         static const bool official = true;
 #else
@@ -537,7 +544,7 @@ int PPInstance::LoadPlugin( const std::string& dllFilename )
         P3D_set_plugin_version_ptr(P3D_PLUGIN_MAJOR_VERSION, P3D_PLUGIN_MINOR_VERSION,
                                    P3D_PLUGIN_SEQUENCE_VERSION, official,
                                    PANDA_DISTRIBUTOR,
-                                   PANDA_PACKAGE_HOST_URL, _coreapi_dll.get_timestamp(),
+                                   PANDA_PACKAGE_HOST_URL, coreapi_timestamp.c_str(),
                                    _coreapi_set_ver.c_str());
 
       }
@@ -831,7 +838,7 @@ lookup_token(const string &keyword) const {
     }
     
     if (lower_keyword == keyword) {
-      return m_parentCtrl.m_parameters[i].second;
+      return (const char *)m_parentCtrl.m_parameters[i].second;
     }
   }
 

+ 7 - 1
direct/src/plugin_npapi/ppInstance.cxx

@@ -1592,6 +1592,12 @@ do_load_plugin() {
     return;
   }
 
+  // Format the coreapi_timestamp as a string, for passing as a
+  // parameter.
+  ostringstream stream;
+  stream << _coreapi_dll.get_timestamp();
+  string coreapi_timestamp = stream.str();
+
 #ifdef PANDA_OFFICIAL_VERSION
   static const bool official = true;
 #else
@@ -1600,7 +1606,7 @@ do_load_plugin() {
   P3D_set_plugin_version_ptr(P3D_PLUGIN_MAJOR_VERSION, P3D_PLUGIN_MINOR_VERSION,
                              P3D_PLUGIN_SEQUENCE_VERSION, official,
                              PANDA_DISTRIBUTOR,
-                             PANDA_PACKAGE_HOST_URL, _coreapi_dll.get_timestamp(),
+                             PANDA_PACKAGE_HOST_URL, coreapi_timestamp.c_str(),
                              _coreapi_set_ver.c_str());
 
   create_instance();

+ 8 - 1
direct/src/plugin_standalone/panda3d.cxx

@@ -813,10 +813,17 @@ get_core_api() {
 #else
   static const bool official = false;
 #endif
+
+  // Format the coreapi_timestamp as a string, for passing as a
+  // parameter.
+  ostringstream stream;
+  stream << _coreapi_dll.get_timestamp();
+  string coreapi_timestamp = stream.str();
+
   P3D_set_plugin_version_ptr(P3D_PLUGIN_MAJOR_VERSION, P3D_PLUGIN_MINOR_VERSION,
                              P3D_PLUGIN_SEQUENCE_VERSION, official,
                              PANDA_DISTRIBUTOR,
-                             _host_url.c_str(), _coreapi_dll.get_timestamp(),
+                             _host_url.c_str(), coreapi_timestamp.c_str(),
                              _coreapi_set_ver.c_str());
 
   return true;