<commit_before>/* file: papi.c */ 

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <string.h>
#include <strings.h>

#include "papi_internal.h"
#include "papi.h"

/* There are two global variables.    */ 
/* Their values are set in PAPI_init. */  
DynamicArray PAPI_EVENT_MAP;    
int          PAPI_ERR_LEVEL; 

/*========================================================================*/
/*========================================================================*/
/*========================================================================*/
/* begin function:                                                        */    
/* static void PAPI_init(DynamicArray *EM, int ERROR_LEVEL_CHOICE );      */
/*                                                                        */
/* This function must be called at the beginning of the program.          */
/* This function performs all initializations to set up PAPI environment. */
/* The user selects the level of error handling here.                     */
/* Failure of this function should shutdown the PAPI tool.                */
/*                                                                        */
/* Initialize EM.                                                         */
/* Set pointer to GLOBAL variable PAPI_EVENT_MAP.                         */
/* Since PAPI_EVENT_MAP is declared at the top of the program             */
/* no malloc for EM is needed.                                            */
/* But the pointer EM->dataSlotArray must be malloced here.               */
/*                                                                        */
/* Initialize PAPI_ERR_LEVEL.                                             */
/* The user selects error handling with ERROR_LEVEL_CHOICE.               */  
/* ERROR_LEVEL_CHOICE may have one of two values:                         */
/*   a. PAPI_VERB_ECONT [print error message, then continue processing ]  */
/*   b. PAPI_VERB_ESTOP [print error message, then shutdown ]             */
/*========================================================================*/
static void PAPI_init(DynamicArray *EM, int ERROR_LEVEL_CHOICE) {

   EM=&PAPI_EVENT_MAP;
   bzero(EM,sizeof(PAPI_EVENT_MAP));

/* initialize values in PAPI_EVENT_MAP */ 

   EM->dataSlotArray=(void **)malloc(EM->totalSlots*sizeof(void *));
   if(!EM->dataSlotArray) PAPI_shutdown(PAPI_ENOMEM);
   bzero(EM->dataSlotArray,sizeof(EM->dataSlotArray));

   EM->totalSlots = PAPI_INIT_SLOTS;
   EM->availSlots = PAPI_INIT_SLOTS - 1;
   EM->lowestEmptySlot = 1;

/* initialize PAPI_ERR_LEVEL */

   if(   (ERROR_LEVEL_CHOICE!=PAPI_VERB_ECONT)
       &&(ERROR_LEVEL_CHOICE!=PAPI_VERB_ESTOP) ) 
          PAPI_shutdown(PAPI_EINVAL); 

   PAPI_ERR_LEVEL=ERROR_LEVEL_CHOICE;

   return;
   }/***/
/*========================================================================*/
/*end function: PAPI_init                                                 */
/*========================================================================*/
/*========================================================================*/

/*========================================================================*/
/*========================================================================*/
/*========================================================================*/
/* begin function:                                                        */    
/* static void PAPI_shutdown (void);                                      */
/*                                                                        */
/* This function provides a graceful exit to the PAPI tool.               */
/*  a. all memory associated with the PAPI tool is freed.                 */
/*  b. a shutdown message is written to stderr                            */
/*                                                                        */
/*========================================================================*/
static void PAPI_shutdown(void) {

    DynamicArray *xEM;
    xEM=&PAPI_EVENT_MAP;
    /* close all memory pointed to by xEM */
    /* this code under construction       */

    /* shutdown message */
    fprintf(stderr,"\n\n PAPI SHUTDOWN. \n\n");


    return;
}/***/
/*========================================================================*/
/*end function: PAPI_shutdown                                             */
/*========================================================================*/
/*========================================================================*/<commit_msg>Revised the function PAPI_shutdown in papi.c.<commit_after>/* file: papi.c */ 

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <string.h>
#include <strings.h>

#include "papi_internal.h"
#include "papi.h"

/* There are two global variables.    */ 
/* Their values are set in PAPI_init. */  
DynamicArray PAPI_EVENT_MAP;    
int          PAPI_ERR_LEVEL; 

/*========================================================================*/
/*========================================================================*/
/*========================================================================*/
/* begin function:                                                        */    
/* static void PAPI_init(DynamicArray *EM, int ERROR_LEVEL_CHOICE );      */
/*                                                                        */
/* This function must be called at the beginning of the program.          */
/* This function performs all initializations to set up PAPI environment. */
/* The user selects the level of error handling here.                     */
/* Failure of this function should shutdown the PAPI tool.                */
/*                                                                        */
/* Initialize EM.                                                         */
/* Set pointer to GLOBAL variable PAPI_EVENT_MAP.                         */
/* Since PAPI_EVENT_MAP is declared at the top of the program             */
/* no malloc for EM is needed.                                            */
/* But the pointer EM->dataSlotArray must be malloced here.               */
/*                                                                        */
/* Initialize PAPI_ERR_LEVEL.                                             */
/* The user selects error handling with ERROR_LEVEL_CHOICE.               */  
/* ERROR_LEVEL_CHOICE may have one of two values:                         */
/*   a. PAPI_VERB_ECONT [print error message, then continue processing ]  */
/*   b. PAPI_VERB_ESTOP [print error message, then shutdown ]             */
/*========================================================================*/
static void PAPI_init(DynamicArray *EM, int ERROR_LEVEL_CHOICE) {

   EM=&PAPI_EVENT_MAP;
   bzero(EM,sizeof(PAPI_EVENT_MAP));

/* initialize values in PAPI_EVENT_MAP */ 

   EM->dataSlotArray=(void **)malloc(EM->totalSlots*sizeof(void *));
   if(!EM->dataSlotArray) PAPI_shutdown();
   bzero(EM->dataSlotArray,sizeof(EM->dataSlotArray));

   EM->totalSlots = PAPI_INIT_SLOTS;
   EM->availSlots = PAPI_INIT_SLOTS - 1;
   EM->lowestEmptySlot = 1;

/* initialize PAPI_ERR_LEVEL */

   if(   (ERROR_LEVEL_CHOICE!=PAPI_VERB_ECONT)
       &&(ERROR_LEVEL_CHOICE!=PAPI_VERB_ESTOP) ) 
          PAPI_shutdown(); 

   PAPI_ERR_LEVEL=ERROR_LEVEL_CHOICE;


/* from papi_internal.h
typedef struct _papi_options{
	int error_level;
	} papi_options;
*/

 	papi_options.error_level=PAPI_ERR_LEVEL;

   return;
   }/***/
/*========================================================================*/
/*end function: PAPI_init                                                 */
/*========================================================================*/
/*========================================================================*/

/*========================================================================*/
/*========================================================================*/
/*========================================================================*/
/* begin function:                                                        */    
/* static void PAPI_shutdown (void);                                      */
/*                                                                        */
/* This function provides a graceful exit to the PAPI tool.               */
/*  a. all memory associated with the PAPI tool is freed.                 */
/*  b. a shutdown message is written to stderr                            */
/*                                                                        */
/* Need to free:     

1. typedef struct _EventSetInfo {
  int EventSetIndex;       ** Index of the EventSet in the array  **

  int NumberOfCounters;    ** Number of counters used- usu. the number of 
                              events added **
  int *EventCodeArray;     ** PAPI/Native codes for events in this set from 
                              AddEvent **
  void *machdep;      ** A pointer to memory of size 
                         _papi_system_info.size_machdep bytes. This 
                         will contain the encoding necessary for the 
                         hardware to set the counters to the appropriate
                         conditions**
  long long *start;   ** Array of length _papi_system_info.num_gp_cntrs
                         + _papi_system_info.num_sp_cntrs 
                         This will most likely be zero for most cases**
  long long *stop;    ** Array of the same length as above, but 
                         containing the values of the counters when 
                         stopped **
  long long *latest;  ** Array of the same length as above, containing 
                         the values of the counters when last read ** 
} EventSetInfo;
*/
/*========================================================================*/
static void PAPI_shutdown(void) {

    int i;
    DynamicArray *EM;
    EM=&PAPI_EVENT_MAP;
    /* close all memory pointed to by xEM */
    /* this code under construction       */
    /* note: do we need to make a special case for EM->dataSlotArray[0]?*/


    /* free all the EventInfo Structures in the EM->dataSlotArray*/
    for(i=0;i<EM->totalSlots;i++) {
	if(EM->dataSlotArray[i]) {
	  if(EM->dataSlotArray[i]->EventCodeArray)
	    free(EM->dataSlotArray[i]->EventCodeArray);
	  if(EM->dataSlotArray[i]->machdep)
	    free(EM->dataSlotArray[i]->machdep);
	  if(EM->dataSlotArray[i]->start)
	    free(EM->dataSlotArray[i]->start);
	  if(EM->dataSlotArray[i]->stop)
	    free(EM->dataSlotArray[i]->stop);
	  if(EM->dataSlotArray[i]->latest)
	    free(EM->dataSlotArray[i]->latest);
	  free(EM->dataSlotArray[i]);
	  }/***/
	}/***/
		 
	free(EM->dataSlotArray);



    /* shutdown message */
    fprintf(stderr,"\n\n PAPI SHUTDOWN. \n\n");


    return;
}/***/
/*========================================================================*/
/*end function: PAPI_shutdown                                             */
/*========================================================================*/
/*========================================================================*/
{'fraction_non_alphanumeric': 0.26905949412183827, 'fraction_numerical': 0.0006234413965087282, 'mean_word_length': 1.9402985074626866, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7335152', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2458, 'n_words': 655}