void Mem :: resize ( const bytes_t & sz, bool clear ) { FUNC_ENTRY (); test_caps ( CAP_RESIZE ); // early cheap detection of noop if ( sz == bytes ) return; // a null ref can be resized to allocate if ( ptr == 0 ) { assert ( bytes == ( U64 ) 0 ); #ifdef _hpp_vdb3_rsrc_ * this = rsrc -> mmgr . alloc ( sz, clear ); #else CONST_THROW ( xc_unimplemented_err, "unimplemented" ); #endif } else { assert ( bytes != ( U64 ) 0 ); MemoryItf * itf = get_itf ( CAP_RESIZE ); // there are cases when the obj can be null if ( itf == 0 ) { #ifdef _hpp_vdb3_rsrc_ // ref represents constant data, not heap data Mem tmp = rsrc -> mmgr . alloc ( sz, false ); // copy in data from self bytes_t num_writ = tmp . copy ( bytes, 0, * this, 0 ); if ( bytes >= sz ) assert ( num_writ == sz ); else { assert ( num_writ == bytes ); if ( clear ) { bytes_t num_zeroed = tmp . fill ( ( U64 ) sz - bytes, ( I64 ) ( U64 ) num_writ, 0 ); assert ( num_writ + num_zeroed == sz ); } } * this = tmp; #else CONST_THROW ( xc_unimplemented_err, "unimplemented" ); #endif } else { // normal case itf -> resize ( sz, clear ); ptr = itf -> get_mapped_memory ( & bytes ); } } }
Rsrc :: Rsrc ( const MemMgr & pmmgr, const char * ident ) : mmgr ( pmmgr ) { // one-shot latch if ( rsrc != 0 ) { assert ( callstk != 0 ); FUNC_ENTRY (); CONST_THROW ( xc_program_state_violation, "not at top of call stack" ); } rsrc = this; try { // create obligatory resources tmmgr = PrimordTimeMgr :: make_primordial (); fdmgr = PrimordFDMgr :: make_primordial (); log = plogger_t :: make ( ident ); #if UNIX FileDesc fd2 = fdmgr . make ( 2, CAP_WRITE ); err = Stream ( fd2 ); #endif } catch ( exception & x ) { NULTermString what = x . what (); fprintf ( stderr, "ERROR: %s:\n", ( const char * ) what ); #if _DEBUGGING NULTermString stk = x . stack_trace (); fprintf ( stderr, "%s\n", ( const char * ) stk ); #endif } }
bytes_t StreamItf :: write ( const bytes_t & num_bytes, const Mem & src, const bytes_t & start ) { // should never have had the capabilities to issue message // so this is an unsupported capability // that should not have been granted CONST_THROW ( xc_caps_over_extended_err, "unsupported write message" ); }
Rsrc :: Rsrc ( rcaps_t mgrs ) { if ( rsrc == 0 ) { FUNC_ENTRY (); CONST_THROW ( xc_program_state_violation, "at top of call stack" ); } mmgr = rsrc -> mmgr; if ( ( mgrs & RCAP_TMMGR ) != 0 ) tmmgr = rsrc -> tmmgr; if ( ( mgrs & RCAP_FDMGR ) != 0 ) fdmgr = rsrc -> fdmgr; if ( ( mgrs & RCAP_LOG ) != 0 ) log = rsrc -> log; if ( ( mgrs & RCAP_ERR ) != 0 ) err = rsrc -> err; }