gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r9723: Don't access the VM singleton


From: Sandro Santilli
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9723: Don't access the VM singleton from movie_root. Hold a ref instead.
Date: Thu, 11 Sep 2008 16:21:15 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9723
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Thu 2008-09-11 16:21:15 +0200
message:
  Don't access the VM singleton from movie_root. Hold a ref instead.
  Hush debugging for remoting.
modified:
  libcore/asobj/NetConnection.cpp
  libcore/movie_root.cpp
  libcore/movie_root.h
  libcore/vm/VM.cpp
    ------------------------------------------------------------
    revno: 9722.1.1
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Thu 2008-09-11 15:29:35 +0200
    message:
      hush remoting debugging
    modified:
      libcore/asobj/NetConnection.cpp
    ------------------------------------------------------------
    revno: 9722.1.2
    committer: Sandro Santilli <address@hidden>
    branch nick: mybranch
    timestamp: Thu 2008-09-11 16:20:25 +0200
    message:
      Have movie_root hold a ref on VM to avoid access to the singleton
    modified:
      libcore/movie_root.cpp
      libcore/movie_root.h
      libcore/vm/VM.cpp
=== modified file 'libcore/asobj/NetConnection.cpp'
--- a/libcore/asobj/NetConnection.cpp   2008-09-09 09:20:50 +0000
+++ b/libcore/asobj/NetConnection.cpp   2008-09-11 13:29:35 +0000
@@ -46,7 +46,8 @@
 #include "timers.h"
 #include "namedStrings.h"
 
-//using namespace amf;
+
+// #define GNASH_DEBUG_REMOTING
 
 namespace gnash {
 
@@ -272,16 +273,22 @@
        // callbacks when needed
        void tick() {
 
+#ifdef GNASH_DEBUG_REMOTING
                log_debug("tick running");
+#endif
                if(connection)
                {
 
             VM& vm = _nc.getVM();
 
+#ifdef GNASH_DEBUG_REMOTING
                        log_debug("have connection");
+#endif
                        int read = connection->readNonBlocking(reply.data() + 
reply_end, NCCALLREPLYMAX - reply_end);
                        if(read > 0) {
+#ifdef GNASH_DEBUG_REMOTING
                                log_debug("read '%1%' bytes: %2%", read, 
hexify(reply.data() + reply_end, read, false));
+#endif
                                reply_end += read;
                        }
 
@@ -303,7 +310,7 @@
                                log_debug("connection is in error condition, 
calling NetConnection.onStatus");
                                reply_start = 0;
                                reply_end = 0;
-                               log_debug("deleting connection");
+                               //log_debug("deleting connection");
                                connection.reset(); // reset connection before 
calling the callback
 
                                // FIXME: should only call NetConnection's 
onStatus
@@ -319,7 +326,9 @@
                                {
                     std::vector<as_object*> objRefs;
 
+#ifdef GNASH_DEBUG_REMOTING
                                        log_debug("hit eof");
+#endif
                                        boost::int16_t si;
                                        boost::uint16_t li;
                                        boost::uint8_t *b = reply.data() + 
reply_start;
@@ -333,7 +342,9 @@
                                        uint8_t headers_ok = 1;
                                        if(si != 0)
                                        {
+#ifdef GNASH_DEBUG_REMOTING
                                                
log_debug("NetConnection::call(): amf headers section parsing");
+#endif
                                                as_value tmp;
                                                for(int i = si; i > 0; --i)
                                                {
@@ -347,7 +358,9 @@
                                                                break;
                                                        }
                                                        std::string 
headerName((char*)b, si); // end-b);
+#ifdef GNASH_DEBUG_REMOTING
                                                        log_debug("Header name 
%s", headerName);
+#endif
                                                        b += si;
                                                        if ( b + 5 > end ) {
                                                                headers_ok = 0;
@@ -359,14 +372,18 @@
                                                                headers_ok = 0;
                                                                break;
                                                        }
+#ifdef GNASH_DEBUG_REMOTING
                                                        log_debug("Header value 
%s", tmp);
+#endif
 
                                                        { // method call for 
each header
                                                          // FIXME: it seems to 
me that the call should happen
                                                                VM& vm = 
_nc.getVM();
                                                                string_table& 
st = vm.getStringTable();
                                                                
string_table::key key = st.find(headerName);
+#ifdef GNASH_DEBUG_REMOTING
                                                                
log_debug("Calling NetConnection.%s(%s)", headerName, tmp);
+#endif
                                                                
_nc.callMethod(key, tmp);
                                                        }
                                                }
@@ -409,7 +426,9 @@
                                                                if(b + 4 > end) 
break;
                                                                li = 
readNetworkLong(b); b += 4; // reply length
 
+#ifdef GNASH_DEBUG_REMOTING
                                                                
log_debug("about to parse amf value");
+#endif
                                                                // this updates 
b to point to the next unparsed byte
                                                                as_value 
reply_as_value;
                                                                if ( ! 
reply_as_value.readAMF0(b, end, -1, objRefs, vm) )
@@ -422,7 +441,9 @@
                                                                        // 
don't know how to parse
                                                                        break;
                                                                }
+#ifdef GNASH_DEBUG_REMOTING
                                                                
log_debug("parsed amf");
+#endif
 
                                                                // update 
variable to show how much we've parsed
                                                                reply_start = b 
- reply.data();
@@ -430,12 +451,18 @@
                                                                // if 
actionscript specified a callback object, call it
                                                                
boost::intrusive_ptr<as_object> callback = pop_callback(id);
                                                                if(callback) {
-                                                                       
log_debug("calling callback");
+#ifdef GNASH_DEBUG_REMOTING
+                                                                       
log_debug("calling onResult callback");
+#endif
                                                                        // 
FIXME check if above line can fail and we have to react
                                                                        
callback->callMethod(NSV::PROP_ON_RESULT, reply_as_value);
+#ifdef GNASH_DEBUG_REMOTING
                                                                        
log_debug("callback called");
+#endif
                                                                } else {
+#ifdef GNASH_DEBUG_REMOTING
                                                                        
log_debug("couldn't find callback object");
+#endif
                                                                }
                                                        }
                                                }
@@ -446,7 +473,9 @@
                                        log_error("Response from remoting 
service < 8 bytes");
                                }
 
+#ifdef GNASH_DEBUG_REMOTING
                                log_debug("deleting connection");
+#endif
                                connection.reset();
                                reply_start = 0;
                                reply_end = 0;
@@ -454,21 +483,31 @@
                }
 
                if(connection == 0 && queued_count > 0) {
+#ifdef GNASH_DEBUG_REMOTING
                        log_debug("creating connection");
+#endif
                        // set the "number of bodies" header
                        (reinterpret_cast<boost::uint16_t*>(postdata.data() + 
4))[0] = htons(queued_count);
                        std::string 
postdata_str(reinterpret_cast<char*>(postdata.data()), postdata.size());
+#ifdef GNASH_DEBUG_REMOTING
                        log_debug("NetConnection.call(): encoded args from %1% 
calls: %2%", queued_count, hexify(postdata.data(), postdata.size(), false));
+#endif
                        queued_count = 0;
                        connection.reset( 
StreamProvider::getDefaultInstance().getStream(url, postdata_str) );
                        postdata.resize(6);
+#ifdef GNASH_DEBUG_REMOTING
                        log_debug("connection created");
+#endif
                }
 
                if(connection == 0 && queued_count == 0) {
+#ifdef GNASH_DEBUG_REMOTING
                        log_debug("stopping ticking");
+#endif
                        stop_ticking();
+#ifdef GNASH_DEBUG_REMOTING
                        log_debug("ticking stopped");
+#endif
                }
        };
 
@@ -564,7 +603,9 @@
        }
 
        std::stringstream ss; fn.dump_args(ss);
+#ifdef GNASH_DEBUG_REMOTING
         log_debug("NetConnection.call(%s)", ss.str());
+#endif
 
        // TODO: arg(1) is the response object. let it know when data comes back
        boost::intrusive_ptr<as_object> asCallback = 0;
@@ -629,7 +670,9 @@
        *(reinterpret_cast<uint32_t*>(buf->data() + total_size_offset)) = 
htonl(buf->size() - 4 - total_size_offset);
        
 
+#ifdef GNASH_DEBUG_REMOTING
        log_debug(_("NetConnection.call(): encoded args: %s"), 
hexify(buf->data(), buf->size(), false));
+#endif
 
        // FIXME check that ptr->_prefixURL is valid
        URL url(ptr->validateURL(std::string()));
@@ -642,16 +685,22 @@
 
        if (asCallback) {
                //boost::intrusive_ptr<as_object> 
intrusive_callback(asCallback);
+#ifdef GNASH_DEBUG_REMOTING
                log_debug("calling enqueue with callback");
+#endif
                ptr->_callQueue->enqueue(*buf, callNumberString, asCallback);
                //? delete asCallback;
        }
        
        else {
+#ifdef GNASH_DEBUG_REMOTING
                log_debug("calling enqueue without callback");
+#endif
                ptr->_callQueue->enqueue(*buf);
        }
+#ifdef GNASH_DEBUG_REMOTING
        log_debug("called enqueue");
+#endif
 
        return as_value();
 }

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2008-09-09 04:07:37 +0000
+++ b/libcore/movie_root.cpp    2008-09-11 14:20:25 +0000
@@ -88,8 +88,9 @@
 }
 
 
-movie_root::movie_root()
+movie_root::movie_root(VM& vm)
        :
+    _vm(vm),
        _interfaceHandler(0),
        _fsCommandHandler(0),
        m_viewport_x0(0),
@@ -181,7 +182,7 @@
        float fps = md->get_frame_rate();
        _movieAdvancementDelay = static_cast<int>(1000/fps);
 
-       _lastMovieAdvancement = VM::get().getTime();
+       _lastMovieAdvancement = _vm.getTime();
 
        m_viewport_width = static_cast<int>(md->get_width_pixels());
        m_viewport_height = static_cast<int>(md->get_height_pixels());
@@ -228,9 +229,7 @@
 movie_root::cleanupAndCollect()
 {
        // Cleanup the stack.
-       // TODO: don't access VM as a singleton
-       VM& vm = VM::get();
-       vm.getStack().clear();
+       _vm.getStack().clear();
 
        cleanupUnloadedListeners();
        cleanupDisplayList();
@@ -476,9 +475,7 @@
        m_mouse_listeners.clear();
 
        // Cleanup the stack.
-       // TODO: don't access VM as a singleton
-       VM& vm = VM::get();
-       vm.getStack().clear();
+       _vm.getStack().clear();
 
 #ifdef GNASH_USE_GC
        // Run the garbage collector again
@@ -492,8 +489,8 @@
 movie_root::getStageObject()
 {
        as_value v;
-       if ( ! VM::isInitialized() ) return NULL;
-       as_object* global = VM::get().getGlobal();
+       assert ( VM::isInitialized() ); // return NULL;
+       as_object* global = _vm.getGlobal();
        if ( ! global ) return NULL;
        if (!global->get_member(NSV::PROP_iSTAGE, &v) ) return NULL;
        return boost::dynamic_pointer_cast<Stage>(v.to_object());
@@ -534,8 +531,6 @@
 boost::intrusive_ptr<key_as_object>
 movie_root::getKeyObject()
 {
-       VM& vm = VM::get();
-
        // TODO: test what happens with the global "Key" object
        //       is removed or overridden by the user
 
@@ -550,7 +545,7 @@
                as_object* global = VM::get().getGlobal();
 
                std::string objName = PROPNAME("Key");
-               if (global->get_member(vm.getStringTable().find(objName), 
&kval) )
+               if (global->get_member(_vm.getStringTable().find(objName), 
&kval) )
                {
                        //log_debug("Found member 'Key' in _global: %s", 
kval.to_string());
                        boost::intrusive_ptr<as_object> obj = kval.to_object();
@@ -565,17 +560,15 @@
 boost::intrusive_ptr<as_object>
 movie_root::getMouseObject()
 {
-       VM& vm = VM::get();
-
        // TODO: test what happens with the global "Mouse" object
        //       is removed or overridden by the user
        if ( ! _mouseobject )
        {
                as_value val;
-               as_object* global = VM::get().getGlobal();
+               as_object* global = _vm.getGlobal();
 
                std::string objName = PROPNAME("Mouse");
-               if (global->get_member(vm.getStringTable().find(objName), &val) 
)
+               if (global->get_member(_vm.getStringTable().find(objName), 
&val) )
                {
                        //log_debug("Found member 'Mouse' in _global: %s", val);
                        _mouseobject = val.to_object();
@@ -589,8 +582,7 @@
 key_as_object *
 movie_root::notify_global_key(key::code k, bool down)
 {
-       VM& vm = VM::get();
-       if ( vm.getSWFVersion() < 5 )
+       if ( _vm.getSWFVersion() < 5 )
        {
                // Key was added in SWF5
                return NULL; 
@@ -1032,8 +1024,7 @@
 void
 movie_root::advance()
 {
-       VM& vm = VM::get(); // TODO: cache it !
-       unsigned int now = vm.getTime();
+       unsigned int now = _vm.getTime();
 
     try {
 
@@ -1047,7 +1038,7 @@
                    // slower. Might add a check here allowing a tolerance
                    // and printing a warnign when we're later then tolerated...
                    //
-                   _lastMovieAdvancement = now; // or vm.getTime(); ?
+                   _lastMovieAdvancement = now; // or _vm.getTime(); ?
            }
 
            // TODO: execute timers ?
@@ -1621,9 +1612,7 @@
        }
 
        // Cleanup the stack.
-       // TODO: don't access VM as a singleton
-       VM& vm = VM::get();
-       vm.getStack().clear();
+       _vm.getStack().clear();
 
 }
 
@@ -2028,8 +2017,7 @@
 
        std::string tgtstr = PROPNAME(tgtstr_orig);
 
-       VM& vm = VM::get();
-       string_table& st = vm.getStringTable();
+       string_table& st = _vm.getStringTable();
 
        // NOTE: getRootMovie() would be problematic in case the original
        //       root movie is replaced by a load to _level0... 

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2008-09-04 12:09:34 +0000
+++ b/libcore/movie_root.h      2008-09-11 14:20:25 +0000
@@ -136,7 +136,7 @@
     /// Make sure to call setRootMovie() 
     /// before using any of this class methods !
     ///
-    movie_root();
+    movie_root(VM& vm);
 
     ~movie_root();
 
@@ -788,6 +788,8 @@
 
 private:
 
+    VM& _vm;
+
     /// Registered Interface command handler, if any
     AbstractIfaceCallback* _interfaceHandler;
 
@@ -868,10 +870,10 @@
     LiveChars _liveChars;
 
     /// Forbid copy 
-    movie_root(const movie_root& ) { abort(); }
+    movie_root(const movie_root& ); 
 
     /// Forbid assignment
-    movie_root& operator=(const movie_root& ) { abort(); return *this; }
+    movie_root& operator=(const movie_root& );
 
     /// Execute expired timers
     void executeTimers();

=== modified file 'libcore/vm/VM.cpp'
--- a/libcore/vm/VM.cpp 2008-09-10 13:32:57 +0000
+++ b/libcore/vm/VM.cpp 2008-09-11 14:20:25 +0000
@@ -85,7 +85,7 @@
 
 VM::VM(movie_definition& topmovie, VirtualClock& clock)
        :
-       _root_movie(new movie_root()),
+       _root_movie(new movie_root(*this)),
        _swfversion(topmovie.get_version()),
        _swfurl(topmovie.get_url()),
        mMachine(0),


reply via email to

[Prev in Thread] Current Thread [Next in Thread]