src/components/pcp/linux-pcp.c
//-----------------------------------------------------------------------------
// makeQualifiedEvent: Create a new event as a copy of the old, plus a tag at
// the end.  This appends to the pcp_event_info[] array, which may be realloced
// (which CAN invalidate any pointers into it).
//-----------------------------------------------------------------------------
Create a new event as a copy of the old, plus a tag at
the end.  This appends to the pcp_event_info[] array, which may be realloced
(which CAN invalidate any pointers into it).
Create a new event as a copy of the old plus a tag at the end . This appends to the pcp_event_info [] array which may be realloced ( which CAN invalidate any pointers into it ) .
static void makeQualifiedEvent(int baseEvent, int idx, char *qualifier) 
{
   int prevSize;
   if (sEventCount >= sEventInfoSize) {                                 
      prevSize = sEventInfoSize;
      sEventInfoSize += sEventInfoBlock;                                
      pcp_event_info = realloc(pcp_event_info,                          
                       sEventInfoSize*sizeof(_pcp_event_info_t));       
      if (pcp_event_info == NULL) {                                     
         fprintf(stderr, "%s:%i:%s realloc denied; "
                 "pcp_event_info=%p at size=%i.\n",
                 __FILE__, __LINE__, __func__, 
                pcp_event_info, sEventInfoSize);
         exit(-1);
      } 
      memset(&pcp_event_info[prevSize], 0,                              
             sEventInfoBlock*sizeof(_pcp_event_info_t));                
   } 
   pcp_event_info[sEventCount] = pcp_event_info[baseEvent];             
   pcp_event_info[sEventCount].numVal = 1;                              
   pcp_event_info[sEventCount].idx = idx;                               
   pcp_event_info[sEventCount].zeroValue = 0;                           
   int slen = strlen(pcp_event_info[sEventCount].name);                 
   char *c = qualifier;                                                 
   pcp_event_info[sEventCount].name[slen++] = ':';                      
   while ( (*c) != 0 && slen < PAPI_MAX_STR_LEN-1) {                    appending qualifier,
      char v=*c++;                                                      what we intend to append, point at next.
      pcp_event_info[sEventCount].name[slen++] = v;                     add to name, inc slen.
   }
   pcp_event_info[sEventCount].name[slen] = 0;                          
   sEventCount++;                                                       
}
static void makeQualifiedEvent ( int baseEvent , int idx , char * qualifier ) { int prevSize ; if ( sEventCount >= sEventInfoSize ) { prevSize = sEventInfoSize ; sEventInfoSize += sEventInfoBlock ; pcp_event_info = realloc ( pcp_event_info , sEventInfoSize * sizeof ( _pcp_event_info_t ) ) ; if ( pcp_event_info == NULL ) { fprintf ( stderr , " " " \n " , __FILE__ , __LINE__ , __func__ , pcp_event_info , sEventInfoSize ) ; exit ( -1 ) ; } memset ( & pcp_event_info [ prevSize ] , 0 , sEventInfoBlock * sizeof ( _pcp_event_info_t ) ) ; } pcp_event_info [ sEventCount ] = pcp_event_info [ baseEvent ] ; pcp_event_info [ sEventCount ] . numVal = 1 ; pcp_event_info [ sEventCount ] . idx = idx ; pcp_event_info [ sEventCount ] . zeroValue = 0 ; int slen = strlen ( pcp_event_info [ sEventCount ] . name ) ; char * c = qualifier ; pcp_event_info [ sEventCount ] . name [ slen ++ ] = ' ' ; while ( ( * c ) != 0 && slen < PAPI_MAX_STR_LEN - 1 ) { char v = * c ++ ; pcp_event_info [ sEventCount ] . name [ slen ++ ] = v ; } pcp_event_info [ sEventCount ] . name [ slen ] = 0 ; sEventCount ++ ; }
makeQualifiedEvent: Create a new event as a copy of the old, plus a tag at
the end.
makeQualifiedEvent : Create a new event as a copy of the old plus a tag at the end .
// If we must realloc,  // .. Add another block. // .. attempt reallocation. // .. .. // If realloc failed, report it. // end if realloc failed. // .. clear the new block to zeros.. // ..  // end if realloc needed. // copy the structure. // Just one value. // Set the right index. // Set the base value.   // get length of user name. // point at qualifier. // place a colon. // .. appending qualifier, // .. what we intend to append, point at next. // your chance to invalidate any chars, right here! // .. add to name, inc slen. // ensure z-terminator.  // increment our count of events.