gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9653: Use an appropriate size_type


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9653: Use an appropriate size_type for SafeStack so that it is always guaranteed
Date: Sun, 31 Aug 2008 18:17:36 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9653
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Sun 2008-08-31 18:17:36 +0200
message:
  Use an appropriate size_type for SafeStack so that it is always guaranteed
  to be valid (although the stack size is never likely to exceed an unsigned
  int).
  
  Make more members private, which ought to fix any visibility problems.
  There's something wrong if private members need to be exported, and it builds
  fine for me now with visibility support enabled.
  
  Comment out unused variables in obsolete functions.
modified:
  libcore/as_environment.cpp
  libcore/as_environment.h
  libcore/vm/ASHandlers.cpp
  libcore/vm/ActionExec.h
  libcore/vm/SafeStack.h
    ------------------------------------------------------------
    revno: 9652.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sun 2008-08-31 16:31:29 +0200
    message:
      Comment out unused variable. This function should be dropped.
    modified:
      libcore/vm/ActionExec.h
    ------------------------------------------------------------
    revno: 9652.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sun 2008-08-31 16:32:00 +0200
    message:
      Use unsigned variable in for loop to silence warnings. Looks like
      these should be dropped too.
    modified:
      libcore/vm/ASHandlers.cpp
    ------------------------------------------------------------
    revno: 9652.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sun 2008-08-31 16:32:33 +0200
    message:
      Use an appropriate size_type for all methods of SafeStack rather than
      unsigned int, which may or may not be big enough to hold any possible
      size value.
    modified:
      libcore/vm/SafeStack.h
    ------------------------------------------------------------
    revno: 9652.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Sun 2008-08-31 16:33:58 +0200
    message:
      Make _stack private, group typedefs together at the top, and stop
      exporting private member functions and data members. It doesn't
      make any sense to do that!
    modified:
      libcore/as_environment.cpp
      libcore/as_environment.h
=== modified file 'libcore/as_environment.cpp'
--- a/libcore/as_environment.cpp        2008-08-28 22:12:35 +0000
+++ b/libcore/as_environment.cpp        2008-08-31 14:33:58 +0000
@@ -894,7 +894,7 @@
 
 
 void
-as_environment::padStack(size_t offset, size_t count)
+as_environment::padStack(size_t /*offset*/, size_t /*count*/)
 {
        // do nothing here, instead return undefined from top() and pop()
        //assert( offset <= _stack.size() );

=== modified file 'libcore/as_environment.h'
--- a/libcore/as_environment.h  2008-08-30 23:04:56 +0000
+++ b/libcore/as_environment.h  2008-08-31 14:33:58 +0000
@@ -39,15 +39,21 @@
 /// ActionScript execution environment.
 class as_environment
 {
+
 public:
 
        /// A stack of objects used for variables/members lookup
        //typedef std::vector<with_stack_entry> ScopeStack;
        typedef std::vector< boost::intrusive_ptr<as_object> > ScopeStack;
 
-       /// Stack of as_values in this environment
-       //std::vector<as_value> m_stack;
-       DSOEXPORT SafeStack<as_value>   _stack;
+       /// The variables container (case-insensitive)
+       typedef std::map<std::string, as_value, StringNoCaseLessThen> Variables;
+
+       /// The locals container 
+       //typedef std::vector<frame_slot>       LocalVars;
+       typedef boost::intrusive_ptr<as_object> LocalVars;
+
+       typedef std::vector<as_value> Registers;
 
        as_environment()
                :
@@ -500,15 +506,6 @@
        ///
        bool parse_path(const std::string& var_path, as_object** target, 
as_value& val);
 
-       /// The variables container (case-insensitive)
-       typedef std::map<std::string, as_value, StringNoCaseLessThen> Variables;
-
-       /// The locals container 
-       //typedef std::vector<frame_slot>       LocalVars;
-       typedef boost::intrusive_ptr<as_object> LocalVars;
-
-       typedef std::vector<as_value> Registers;
-
        struct CallFrame
        {
                CallFrame(as_function* funcPtr);
@@ -561,6 +558,10 @@
 
 private:
 
+       /// Stack of as_values in this environment
+       //std::vector<as_value> m_stack;
+       SafeStack<as_value>     _stack;
+
        static const short unsigned int numGlobalRegisters = 4;
 
        typedef std::vector<CallFrame> CallStack;
@@ -586,13 +587,13 @@
        /// @param func
        ///     The function being called
        ///
-       static DSOEXPORT void pushCallFrame(as_function* func);
+       static void pushCallFrame(as_function* func);
 
        /// Remove current call frame from the stack
        //
        /// This should happen when an ActionScript function returns.
        ///
-       static DSOEXPORT void popCallFrame();
+       static void popCallFrame();
        
        /// Return the (possibly UNDEFINED) value of the named variable.
        //
@@ -696,6 +697,7 @@
        static bool setLocal(LocalVars& locals, const std::string& varname, 
const as_value& val);
 
        static as_value undefVal;
+               
 };
 
 

=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2008-08-29 14:29:54 +0000
+++ b/libcore/vm/ASHandlers.cpp 2008-08-31 14:32:00 +0000
@@ -2859,7 +2859,7 @@
 #endif
 
     std::auto_ptr< std::vector<as_value> > args ( new std::vector<as_value> );
-    for (int i=0; i<nargs; ++i)
+    for (size_t i=0; i<nargs; ++i)
         args->push_back(env.pop()); // TODO: drop !
 
     //log_debug("ActionCallFunction calling call_method with %p as this_ptr", 
this_ptr);
@@ -3577,7 +3577,7 @@
 #endif
 
     std::auto_ptr< std::vector<as_value> > args ( new std::vector<as_value> );
-    for (int i=0; i<nargs; ++i)
+    for (size_t i=0; i<nargs; ++i)
         args->push_back(env.pop()); // TODO: drop !
 
     as_value result = call_method(method_val, &env, this_ptr, 

=== modified file 'libcore/vm/ActionExec.h'
--- a/libcore/vm/ActionExec.h   2008-08-28 22:12:35 +0000
+++ b/libcore/vm/ActionExec.h   2008-08-31 14:31:29 +0000
@@ -226,7 +226,7 @@
        /// stack frame, so that undefined function arguments are the
        /// *last* ones in the list.
        ///
-       void ensureStack(size_t required)
+       void ensureStack(size_t /*required*/)
        {
 #if 0 // obsoleted
                // The stack_size() < _initialStackSize case should

=== modified file 'libcore/vm/SafeStack.h'
--- a/libcore/vm/SafeStack.h    2008-08-30 23:04:56 +0000
+++ b/libcore/vm/SafeStack.h    2008-08-31 14:32:33 +0000
@@ -40,36 +40,43 @@
 template <class T>
 class SafeStack
 {
+
+       typedef std::vector<T*> StackType;
+
 public:
+
+    // May be useful for callers to know.
+    typedef typename StackType::size_type StackSize;
+
        /// From the top of the stack, get the i'th value down. 0 is the topmost
        /// value.
-       T& top(unsigned int i)
+       T& top(StackSize i)
        {
                if (i >= size()) 
                        throw StackException();
-               unsigned int offset = mEnd - i;
+               StackSize offset = mEnd - i;
                //log_debug("top(%d): mEnd:%d, mDownstop:%d, offset:%d", i, 
mEnd, mDownstop, offset);
                return mData[offset >> mChunkShift][offset & mChunkMod];
        }
 
        /// From the bottom of the stack, get the i'th value up. 0 is the
        /// bottommost value.
-       T& value(unsigned int i)
+       T& value(StackSize i)
        {
                if (i >= size())
                        throw StackException();
 
-               unsigned int offset = mDownstop + i + 2;
+               StackSize offset = mDownstop + i + 2;
                //log_debug("value(%d): mEnd:%d, mDownstop:%d, offset:%d", i, 
mEnd, mDownstop, offset);
                return mData[offset >> mChunkShift][offset & mChunkMod];
        }
 
-       const T& value(unsigned int i) const
+       const T& value(StackSize i) const
        {
                if (i >= size())
                        throw StackException();
 
-               unsigned int offset = mDownstop + i + 2;
+               StackSize offset = mDownstop + i + 2;
                //log_debug("value(%d): mEnd:%d, mDownstop:%d, offset:%d", i, 
mEnd, mDownstop, offset);
                return mData[offset >> mChunkShift][offset & mChunkMod];
        }
@@ -77,7 +84,7 @@
        /// Shrink the stack by i entries. Does not invalidate any entries
        /// previously given, it just sets the top for pop, push, and top
        /// operations.
-       void drop(unsigned int i)
+       void drop(StackSize i)
        { if (i > size()) throw StackException(); mEnd -= i; }
 
        /// Put a new value onto the top of the stack.  The value will be
@@ -91,10 +98,10 @@
 
        /// Grow by i entries. Normally this is 1, but there might be sometime
        /// when you need more than that.
-       void grow(unsigned int i)
+       void grow(StackSize i)
        {
-               unsigned int available = (1 << mChunkShift) * mData.size() - 
mEnd + 1;
-               unsigned int n = size()+i;
+               StackSize available = (1 << mChunkShift) * mData.size() - mEnd 
+ 1;
+               StackSize n = size()+i;
                while (available < n)
                {
                        mData.push_back(new T[1 << mChunkShift]);
@@ -104,11 +111,11 @@
        }
 
        /// Gives the size of the stack which is currently accessible.
-       unsigned int getDownstop() const 
+       StackSize getDownstop() const 
        { return mDownstop; }
 
        /// Alias for getDownstop()
-       size_t size() const { return mEnd - mDownstop - 1; /*mEnd is one past 
end*/ }
+       StackSize size() const { return mEnd - mDownstop - 1; /*mEnd is one 
past end*/ }
 
        /// Is the stack empty to us? (Check totalSize() != for actually empty)
        bool empty() const { return size() == 0; }
@@ -116,12 +123,12 @@
        /// Makes the stack appear empty to subsequent callers.  This can be 
used
        /// to simulate multiple stacks with a single stack, as in function
        /// calling. Returns the old downstop for restoring it using 
setDownstop.
-       unsigned int fixDownstop() 
-       { unsigned int ret = mDownstop; mDownstop = mEnd-1; return ret; }
+       StackSize fixDownstop() 
+       { StackSize ret = mDownstop; mDownstop = mEnd-1; return ret; }
 
        /// Makes the stack read to a depth of 'i'. This cannot be more than
        /// totalSize()
-       void setDownstop(unsigned int i)
+       void setDownstop(StackSize i)
        { if (i > mEnd) throw StackException(); mDownstop = i; }
 
        /// The total size of the stack. This is not what can be read. That
@@ -130,11 +137,11 @@
        /// This function is probably not what you need for anything except for
        /// setting downstops that weren't returned by either fixDownstop() or
        /// getDownstop()
-       unsigned int totalSize() const { return mEnd - 1; }
+       StackSize totalSize() const { return mEnd - 1; }
 
        /// Set the total size and local size of the stack, for restoring a
        /// stack through unknown changes.
-       void setAllSizes(unsigned int total, unsigned int downstop)
+       void setAllSizes(StackSize total, StackSize downstop)
        { mEnd = total + 1; mDownstop = downstop; }
 
        /// Default constructor.
@@ -144,19 +151,18 @@
        /// Delete the allocated data. 
        ~SafeStack()
        {
-               for (unsigned int i = 0; i < mData.size(); ++i)
+               for (StackSize i = 0; i < mData.size(); ++i)
                        delete [] mData[i];
        }
 
 private:
-       typedef std::vector<T*> stack_type;
-       stack_type mData;
-       unsigned int mDownstop;
-       unsigned int mEnd;
+       StackType mData;
+       StackSize mDownstop;
+       StackSize mEnd;
 
        // If mChunkMod is not a power of 2 less 1, it will not work properly.
-       static const unsigned int mChunkShift = 6;
-       static const unsigned int mChunkMod = (1 << mChunkShift) - 1;
+       static const StackSize mChunkShift = 6;
+       static const StackSize mChunkMod = (1 << mChunkShift) - 1;
 };
 
 } // namespace gnash


reply via email to

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