<commit_before>/* /% C %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * Source file init.c
 ************************************************************************
 * Description:
 *  Entry functions
 ************************************************************************
 * Copyright(c) 1995~2010  <NAME>
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/

#include "common.h"
#include "Api.h"
#include <list>
#include <typeinfo>
#include <string>

#if defined(G__NOSTUBS) && defined(__APPLE__)
#include <libgen.h> //needed for basename
#endif

#ifdef G__SHAREDLIB
extern std::list<G__DLLINIT>* G__initpermanentsl;
#endif //G__SHAREDLIB

extern "C" {

#ifndef __CINT__
void G__setCINTLIBNAME G__P((char *cintlib));
void G__setcopyflag G__P((int flag));
#endif

extern int G__ispermanentsl;

#ifndef G__OLDIMPLEMENTATION1817
#if defined(G__ROOT) && !defined(G__NATIVELONGLONG)
void G__cpp_setuplongif();
#endif
#endif

#include "rflx_gendict.h"

//______________________________________________________________________________
//
//  For C++ dictionary setup
//
struct G__setup_func_struct {
   std::string libname;
   G__incsetup func;
   bool inited;
   bool registered;

   G__setup_func_struct() : libname(), func(), inited(false), registered(false) {}
   G__setup_func_struct(const char *name, G__incsetup functions, bool isregistered) : libname(name), func(functions), inited(false), registered(isregistered) {}

};

//______________________________________________________________________________
static std::list<G__setup_func_struct> *G__setup_func_list;
static char G__memsetup_init;
typedef void G__parse_hook_t();
static G__parse_hook_t* G__afterparse_hook;
static G__parse_hook_t* G__beforeparse_hook;
void G__platformMacro();

//______________________________________________________________________________
void G__add_setup_func(const char* libname, G__incsetup func)
{
   if (!G__memsetup_init) {
      for (int i = 0; i < G__MAXSTRUCT; ++i) {
         G__struct.incsetup_memvar[i] = 0;
         G__struct.incsetup_memfunc[i] = 0;
         G__memsetup_init = 1;
      }
   }
   if ( !G__setup_func_list ) {
      G__setup_func_list = new std::list<G__setup_func_struct>;
   }

   /* if already in table: ignore (could also print warning) */
   std::list<G__setup_func_struct>::iterator begin = G__setup_func_list->begin();
   std::list<G__setup_func_struct>::iterator end = G__setup_func_list->end();
   std::list<G__setup_func_struct>::iterator j;
   for (j = begin ; j != end; ++j) {
      if ( j->libname == libname ) {
         return;
      }
   }
   G__setup_func_list->push_back( G__setup_func_struct( libname, func, true ) );

   ++G__nlibs;

   G__RegisterLibrary(func);
}

//______________________________________________________________________________
void G__remove_setup_func(const char* libname)
{
   std::list<G__setup_func_struct>::iterator begin = G__setup_func_list->begin();
   std::list<G__setup_func_struct>::iterator end = G__setup_func_list->end();
   std::list<G__setup_func_struct>::iterator i;

   for (i = begin ; i != end; ++i) {
       if ( i->libname == libname ) {
          G__UnregisterLibrary( i->func );
          G__setup_func_list->erase(i);
         --G__nlibs;
         return;
      }
   }
}

//______________________________________________________________________________
int G__call_setup_funcs()
{
   if (!G__ifunc.inited || !G__init) {
      // Veto any dictionary uploading until at least G__ifunc is initialized
      // (because it's initialization will be wipe out 'some' of the work done.
      return 0;
   }
   int k = 0;
   G__var_array* store_p_local = G__p_local; // changed by setupfuncs
   G__LockCriticalSection();
#ifdef G__SHAREDLIB
   if (!G__initpermanentsl) {
      G__initpermanentsl = new std::list<G__DLLINIT>;
   }
#endif //G__SHAREDLIB

   if (!G__struct.namerange)
      G__struct.namerange = new NameMap;
   if (!G__newtype.namerange)
      G__newtype.namerange = new NameMap;

   // Call G__RegisterLibrary() again, after it got called already
   // in G__init_setup_funcs(), because G__scratchall might have been
   // called in between.
   // Do a separate loop so we don't re-load because of A->B->A
   // dependencies introduced by autoloading during dictionary
   // initialization
   if (G__setup_func_list) {
      std::list<G__setup_func_struct>::iterator begin = G__setup_func_list->begin();
      std::list<G__setup_func_struct>::iterator end = G__setup_func_list->end();
      std::list<G__setup_func_struct>::iterator i;
      for (i = begin ; i != end; ++i) {
         if (!i->registered) {
            G__RegisterLibrary(i->func);
            i->registered = true;
         }
      }

      int count = 0;
      for (i = begin ; i != end; ++i, ++count) {
         if (count < G__nlibs_highwatermark) continue;
         if (!i->inited) {
            (i->func)();
            // We setup inited to one only __after__ the execution because the execution
            // can trigger (in particular via ROOT's TCint::UpdateClassInfo)) code that
            // requires the dictionary to be fully initiliazed .. which is done by coming
            // back and expecting the setup function to be run.
            i->inited = 1;
#ifdef G__SHAREDLIB
            G__initpermanentsl->push_back(i->func);<commit_msg>Always register libCint itself in the list of files loaded. This fixes: <http://savannah.cern.ch/bugs/?95188><commit_after>/* /% C %/ */
/***********************************************************************
 * cint (C/C++ interpreter)
 ************************************************************************
 * Source file init.c
 ************************************************************************
 * Description:
 *  Entry functions
 ************************************************************************
 * Copyright(c) 1995~2010  <NAME>
 *
 * For the licensing terms see the file COPYING
 *
 ************************************************************************/

#include "common.h"
#include "Api.h"
#include <list>
#include <typeinfo>
#include <string>

#if defined(G__NOSTUBS) && defined(__APPLE__)
#include <libgen.h> //needed for basename
#endif

#ifdef G__SHAREDLIB
extern std::list<G__DLLINIT>* G__initpermanentsl;
#endif //G__SHAREDLIB

extern "C" {

#ifndef __CINT__
void G__setCINTLIBNAME G__P((char *cintlib));
void G__setcopyflag G__P((int flag));
#endif

extern int G__ispermanentsl;

#ifndef G__OLDIMPLEMENTATION1817
#if defined(G__ROOT) && !defined(G__NATIVELONGLONG)
void G__cpp_setuplongif();
#endif
#endif

#include "rflx_gendict.h"

//______________________________________________________________________________
//
//  For C++ dictionary setup
//
struct G__setup_func_struct {
   std::string libname;
   G__incsetup func;
   bool inited;
   bool registered;

   G__setup_func_struct() : libname(), func(), inited(false), registered(false) {}
   G__setup_func_struct(const char *name, G__incsetup functions, bool isregistered) : libname(name), func(functions), inited(false), registered(isregistered) {}

};

//______________________________________________________________________________
static std::list<G__setup_func_struct> *G__setup_func_list;
static char G__memsetup_init;
typedef void G__parse_hook_t();
static G__parse_hook_t* G__afterparse_hook;
static G__parse_hook_t* G__beforeparse_hook;
void G__platformMacro();

//______________________________________________________________________________
void G__add_setup_func(const char* libname, G__incsetup func)
{
   if (!G__memsetup_init) {
      for (int i = 0; i < G__MAXSTRUCT; ++i) {
         G__struct.incsetup_memvar[i] = 0;
         G__struct.incsetup_memfunc[i] = 0;
         G__memsetup_init = 1;
      }
   }
   if ( !G__setup_func_list ) {
      G__setup_func_list = new std::list<G__setup_func_struct>;
   }

   /* if already in table: ignore (could also print warning) */
   std::list<G__setup_func_struct>::iterator begin = G__setup_func_list->begin();
   std::list<G__setup_func_struct>::iterator end = G__setup_func_list->end();
   std::list<G__setup_func_struct>::iterator j;
   for (j = begin ; j != end; ++j) {
      if ( j->libname == libname ) {
         return;
      }
   }
   G__setup_func_list->push_back( G__setup_func_struct( libname, func, true ) );

   ++G__nlibs;

   G__RegisterLibrary(func);
}

//______________________________________________________________________________
void G__remove_setup_func(const char* libname)
{
   std::list<G__setup_func_struct>::iterator begin = G__setup_func_list->begin();
   std::list<G__setup_func_struct>::iterator end = G__setup_func_list->end();
   std::list<G__setup_func_struct>::iterator i;

   for (i = begin ; i != end; ++i) {
       if ( i->libname == libname ) {
          G__UnregisterLibrary( i->func );
          G__setup_func_list->erase(i);
         --G__nlibs;
         return;
      }
   }
}

//______________________________________________________________________________
int G__call_setup_funcs()
{
   if (!G__ifunc.inited || !G__init) {
      // Veto any dictionary uploading until at least G__ifunc is initialized
      // (because it's initialization will be wipe out 'some' of the work done.
      return 0;
   }
   int k = 0;
   G__var_array* store_p_local = G__p_local; // changed by setupfuncs
   G__LockCriticalSection();
#ifdef G__SHAREDLIB
   if (!G__initpermanentsl) {
      G__initpermanentsl = new std::list<G__DLLINIT>;
   }
#endif //G__SHAREDLIB

   if (!G__struct.namerange)
      G__struct.namerange = new NameMap;
   if (!G__newtype.namerange)
      G__newtype.namerange = new NameMap;

   // Call G__RegisterLibrary() again, after it got called already
   // in G__init_setup_funcs(), because G__scratchall might have been
   // called in between.
   
   // Register libCint itself.
   G__RegisterLibrary( (void (*)()) G__call_setup_funcs);
   
   // Do a separate loop so we don't re-load because of A->B->A
   // dependencies introduced by autoloading during dictionary
   // initialization
   if (G__setup_func_list) {
      std::list<G__setup_func_struct>::iterator begin = G__setup_func_list->begin();
      std::list<G__setup_func_struct>::iterator end = G__setup_func_list->end();
      std::list<G__setup_func_struct>::iterator i;
      for (i = begin ; i != end; ++i) {
         if (!i->registered) {
            G__RegisterLibrary(i->func);
            i->registered = true;
         }
      }

      int count = 0;
      for (i = begin ; i != end; ++i, ++count) {
         if (count < G__nlibs_highwatermark) continue;
         if (!i->inited) {
            (i->func)();
            // We setup inited to one only __after__ the execution because the execution
            // can trigger (in particular via ROOT's TCint::UpdateClassInfo)) code that
            // requires the dictionary to be fully initiliazed .. which is done by coming
            // back and expecting the setup function to be run.
            i->inited = 1;
#ifdef G__SHAREDLIB
            G__initpermanentsl->push_back(i->func);
{'fraction_non_alphanumeric': 0.16970721722879772, 'fraction_numerical': 0.004004627569636023, 'mean_word_length': 3.9880159786950733, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3181235', 'n_tokens_mistral': 3526, 'n_tokens_neox': 3381, 'n_words': 791}