Changeset 21031

Show
Ignore:
Timestamp:
02/13/08 17:49:12 (7 months ago)
Author:
patrick
Message:

Fixed an "XXX" comment that I made in July 2004 by replacing an error message
and an assertion with an exception. More specifically, the smart pointer
interface of vpr::TSObjectProxy<T> now throws an exception if the dynamic_cast
of the thread-specific data fails rather than just bombing out with no chance
for recovery. As part of this, I have introduced the new exception type
vpr::BadCastException?.

Bumped the version to 2.1.12.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/ChangeLog

    r21007 r21031  
    11DATE       AUTHOR   CHANGE 
    22---------- -------- ----------------------------------------------------------- 
     32008-02-13 patrick  Changed vpr::TSObjectProxy<T> smart pointer interface to 
     4                    throw an exception (of the new type vpr::BadCastException) 
     5                    if the downcast part of the thread-specific data access 
     6                    fails. 
     7                    NEW VERSION: 2.1.12 
    382008-01-16 patrick  Added vpr::AveragingAllocationStrategy for use with 
    49                    vpr::NoPushWriter. 
  • juggler/trunk/modules/vapor/VERSION

    r21007 r21031  
     12.1.12-0 @02/13/2008 23:50:00 UTC@ 
    122.1.11-0 @01/17/2008 03:10:00 UTC@ 
    232.1.10-0 @01/13/2008 14:15:00 UTC@ 
  • juggler/trunk/modules/vapor/vpr/Thread/TSObjectProxy.h

    r20974 r21031  
    3939 
    4040#include <vpr/vprConfig.h> 
    41 #include <stdlib.h> 
     41 
     42#include <sstream> 
     43#include <cstdlib> 
    4244#include <typeinfo> 
     45 
    4346#include <vpr/Thread/Thread.h> 
    4447#include <vpr/Thread/TSObject.h> 
    4548#include <vpr/Thread/ThreadManager.h> 
    4649#include <vpr/Util/Assert.h> 
     50#include <vpr/Util/BadCastException.h> 
    4751 
    4852 
     
    105109   {;} 
    106110 
     111   /** 
     112    * @throw vpr::BadCastException 
     113    *           Thrown when the cast from vpr::TSBaseObject* to T* fails. 
     114    */ 
    107115   T* operator->() 
    108116   { 
     
    110118   } 
    111119 
     120   /** 
     121    * @throw vpr::BadCastException 
     122    *           Thrown when the cast from vpr::TSBaseObject* to T* fails. 
     123    */ 
    112124   T& operator*() 
    113125   { 
     
    120132    * @note This should only be used by expert users.  It can cause MAJOR 
    121133    *       synchronization issues and even data corruption. 
     134    * 
     135    * @throw vpr::BadCastException 
     136    *           Thrown when the cast from vpr::TSBaseObject* to T* fails. 
    122137    */ 
    123138   T* getObjPtrForThread(vpr::Thread* thread) 
     
    136151    * 
    137152    * @param reqThread Request for this specific thread. 
     153    * 
     154    * @throw vpr::BadCastException 
     155    *           Thrown when the cast from vpr::TSBaseObject* to T* fails. 
    138156    */ 
    139157   T* getSpecific(vpr::Thread* reqThread = NULL) 
     
    184202      TSObject<T>* real_object = dynamic_cast< TSObject<T>* >(object); 
    185203 
    186       if(real_object == NULL)    // Failed cast 
    187       { 
    188          std::cout << "Failed dynamic cast\n"; 
    189          std::cout << "Have pointer of type: " << typeid(*object).name() 
    190                    << std::endl; 
    191          std::cout << "Want type: " << typeid(T).name() << std::endl; 
    192       } 
    193  
    194       // If fails, it means that "real" object was different type than the 
    195       // proxy. 
    196       // XXX: Throw an exception here instead of asserting.  With optimized 
    197       // code, a segmentation fault occurs for less-than-obvious reasons due 
    198       // to the smart pointer indirection.  -PH 7/13/2004 
    199       vprASSERT((real_object != NULL) && "Dynamic_cast of TS object failed"); 
     204      // If dynamic_cast fails, it means that "real" object was different type 
     205      // than the proxy. 
     206      if ( NULL == real_object )    // Failed cast 
     207      { 
     208         std::ostringstream msg_stream; 
     209         msg_stream << "Failed dynamic_cast for thread-specific object:\n" 
     210                    << "\tA pointer of type " << typeid(*object).name() 
     211                    << " was found,\n" 
     212                    << "\tbut we wanted it to be of type " 
     213                    << typeid(T).name(); 
     214         throw vpr::BadCastException(msg_stream.str(), VPR_LOCATION); 
     215      } 
    200216 
    201217      // Return the pointer. 
  • juggler/trunk/modules/vapor/vpr/Util/Makefile.in

    r20974 r21031  
    6565endif 
    6666 
    67 SRCS=           Debug.cpp                       \ 
     67SRCS=           BadCastException.cpp            \ 
     68                Debug.cpp                       \ 
    6869                Exception.cpp                   \ 
    6970                FileUtils.cpp                   \ 
  • juggler/trunk/vc7/VPR/VPR.vcproj

    r21007 r21031  
    195195                        </File> 
    196196                        <File 
     197                                RelativePath="..\..\modules\vapor\vpr\Util\BadCastException.cpp"> 
     198                        </File> 
     199                        <File 
    197200                                RelativePath="..\..\modules\vapor\vpr\IO\Stats\BandwidthIOStatsStrategy.cpp"> 
    198201                        </File> 
     
    425428                        <File 
    426429                                RelativePath="..\..\modules\vapor\vpr\AutoLink.h"> 
     430                        </File> 
     431                        <File 
     432                                RelativePath="..\..\modules\vapor\vpr\Util\BadCastException.h"> 
    427433                        </File> 
    428434                        <File 
  • juggler/trunk/vc8/VPR/VPR.vcproj

    r21007 r21031  
    561561                        </File> 
    562562                        <File 
     563                                RelativePath="..\..\modules\vapor\vpr\Util\BadCastException.cpp" 
     564                                > 
     565                        </File> 
     566                        <File 
    563567                                RelativePath="..\..\modules\vapor\vpr\IO\Stats\BandwidthIOStatsStrategy.cpp" 
    564568                                > 
     
    870874                        </File> 
    871875                        <File 
     876                                RelativePath="..\..\modules\vapor\vpr\Util\BadCastException.h" 
     877                                > 
     878                        </File> 
     879                        <File 
    872880                                RelativePath="..\..\modules\vapor\vpr\IO\Stats\BandwidthIOStatsStrategy.h" 
    873881                                >