src: remove Buffer::Data(Persistent<T>&)
authorBen Noordhuis <info@bnoordhuis.nl>
Sat, 13 Jul 2013 12:07:26 +0000 (14:07 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Sat, 13 Jul 2013 12:08:23 +0000 (14:08 +0200)
It hits a compiler bug in gcc <= 4.4 similar to the issue that was
recently addressed in commit 157d2bc:

    ../deps/v8/include/v8.h: In function ‘char*
    node::Buffer::Data(v8::Persistent&) [with TypeName = v8::Object]’:
    ../src/node_crypto.cc:1123: instantiated from here
    ../deps/v8/include/v8.h:876: error: ‘class v8::Data’ is not a
    function,
    ../src/node_internals.h:356: error: conflict with ‘template char*
    node::Buffer::Data(v8::Persistent&)’
    ../src/node_internals.h:357: error: in call to ‘Data’

Remove the helper function, it was only used in a couple of places.
Should fix the build on Ubuntu 10.04.

Fixes #5844.

src/node_crypto.cc
src/node_internals.h
src/tls_wrap.cc

index 77b1e85..0ecf14e 100644 (file)
@@ -1120,8 +1120,9 @@ int Connection::AdvertiseNextProtoCallback_(SSL *s,
     *data = reinterpret_cast<const unsigned char*>("");
     *len = 0;
   } else {
-    *data = reinterpret_cast<const unsigned char*>(Buffer::Data(p->npnProtos_));
-    *len = Buffer::Length(p->npnProtos_);
+    Local<Object> obj = PersistentToLocal(p->npnProtos_);
+    *data = reinterpret_cast<const unsigned char*>(Buffer::Data(obj));
+    *len = Buffer::Length(obj);
   }
 
   return SSL_TLSEXT_ERR_OK;
@@ -1148,11 +1149,12 @@ int Connection::SelectNextProtoCallback_(SSL *s,
     return SSL_TLSEXT_ERR_OK;
   }
 
+  Local<Object> obj = PersistentToLocal(p->npnProtos_);
   const unsigned char* npnProtos =
-      reinterpret_cast<const unsigned char*>(Buffer::Data(p->npnProtos_));
+      reinterpret_cast<const unsigned char*>(Buffer::Data(obj));
 
   int status = SSL_select_next_proto(out, outlen, in, inlen, npnProtos,
-                                     Buffer::Length(p->npnProtos_));
+                                     Buffer::Length(obj));
 
   switch (status) {
     case OPENSSL_NPN_UNSUPPORTED:
index 9742240..d59cd2e 100644 (file)
 
 namespace node {
 
-// Forward declarations from node_buffer.h.  We can't include node_buffer.h
-// in this file because:
-//
-// a) we're included early on in node.h, and
-// b) node_buffer.h depends on the definition of the |encoding| enum that's
-//    defined further down in node.h...
-namespace Buffer {
-
-NODE_EXTERN char* Data(v8::Handle<v8::Value>);
-NODE_EXTERN char* Data(v8::Handle<v8::Object>);
-NODE_EXTERN size_t Length(v8::Handle<v8::Value>);
-NODE_EXTERN size_t Length(v8::Handle<v8::Object>);
-
-} // namespace Buffer
-
 // Defined in node.cc
 extern v8::Isolate* node_isolate;
 
@@ -107,18 +92,6 @@ inline v8::Local<v8::Object> NewInstance(v8::Persistent<v8::Function>& ctor,
                                           int argc = 0,
                                           v8::Handle<v8::Value>* argv = NULL);
 
-// TODO(bnoordhuis) Move to src/node_buffer.h once it's been established
-// that the current approach to dealing with Persistent is working out.
-namespace Buffer {
-
-template <typename TypeName>
-inline char* Data(v8::Persistent<TypeName>& val);
-
-template <typename TypeName>
-inline size_t Length(v8::Persistent<TypeName>& val);
-
-} // namespace Buffer
-
 #ifdef _WIN32
 // emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer
 // on overflow...
@@ -350,20 +323,6 @@ inline v8::Local<v8::Object> NewInstance(v8::Persistent<v8::Function>& ctor,
   return constructor_handle->NewInstance(argc, argv);
 }
 
-namespace Buffer {
-
-template <typename TypeName>
-inline char* Data(v8::Persistent<TypeName>& val) {
-  return Data(PersistentToLocal(val));
-}
-
-template <typename TypeName>
-inline size_t Length(v8::Persistent<TypeName>& val) {
-  return Length(PersistentToLocal(val));
-}
-
-} // namespace Buffer
-
 } // namespace node
 
 #endif // SRC_NODE_INTERNALS_H_
index f28ccd7..db93a98 100644 (file)
@@ -1141,9 +1141,9 @@ int TLSCallbacks::AdvertiseNextProtoCallback(SSL* s,
     *data = reinterpret_cast<const unsigned char*>("");
     *len = 0;
   } else {
-    *data = reinterpret_cast<const unsigned char*>(
-        Buffer::Data(p->npn_protos_));
-    *len = Buffer::Length(p->npn_protos_);
+    Local<Object> obj = PersistentToLocal(p->npn_protos_);
+    *data = reinterpret_cast<const unsigned char*>(Buffer::Data(obj));
+    *len = Buffer::Length(obj);
   }
 
   return SSL_TLSEXT_ERR_OK;
@@ -1173,9 +1173,10 @@ int TLSCallbacks::SelectNextProtoCallback(SSL* s,
     return SSL_TLSEXT_ERR_OK;
   }
 
+  Local<Object> obj = PersistentToLocal(p->npn_protos_);
   const unsigned char* npn_protos =
-      reinterpret_cast<const unsigned char*>(Buffer::Data(p->npn_protos_));
-  size_t len = Buffer::Length(p->npn_protos_);
+      reinterpret_cast<const unsigned char*>(Buffer::Data(obj));
+  size_t len = Buffer::Length(obj);
 
   int status = SSL_select_next_proto(out, outlen, in, inlen, npn_protos, len);
   Handle<Value> result;