示例#1
0
static aat_node_p aat_insert(aat_node_p node, aat_key_t key, aat_data_t value,
                             aat_status_t *status) {
    aat_node_s *new_node;
    
    if (node == bottom) {
        // allocate a new node
        new_node = ALLOCATE(sizeof(aat_node_s));
        
        // bail out if allocation failed
        if (new_node == NULL)
            BAILOUT(allocation_failed);
        
        // initialise new node
        new_node->level = 1;
        new_node->key = key;
        new_node->value = value;
        new_node->left = bottom;
        new_node->right = bottom;
        
        // link new node to the tree
        node = new_node;
    }
    else if (node->key > key) {
        node = aat_insert(node->left, key, value, status);
        
        // bail out if allocation failed
        if (*status == AAT_STATUS_ALLOCATION_FAILED)
            BAILOUT(allocation_failed);
    }
    else if (node->key < key) {
        node = aat_insert(node->right, key, value, status);
        
        // bail out if allocation failed
        if (*status == AAT_STATUS_ALLOCATION_FAILED)
            BAILOUT(allocation_failed);
    }
    else /* key already exists */ {
        BAILOUT(key_not_unique);
    } // end if
    
    node = aat_skew(node);
    node = aat_split(node);
    
    /* NORMAL TERMINATION */
    
    *status = AAT_STATUS_SUCCESS;
    return node;
    
    /* ERROR HANDLING */
    
    ON_ERROR(allocation_failed) :
    
    *status = AAT_STATUS_ALLOCATION_FAILED;
    return NULL;
    
    ON_ERROR(key_not_unique) :
    
    *status = AAT_STATUS_KEY_NOT_UNIQUE;
    return NULL;
} // end aat_insert
示例#2
0
void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
  LIRItem length(x->length(), this);
  // in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction
  // and therefore provide the state before the parameters have been consumed
  CodeEmitInfo* patching_info = NULL;
  if (!x->klass()->is_loaded() || PatchALot) {
    patching_info =  state_for(x, x->state_before());
  }

  CodeEmitInfo* info = state_for(x, x->state());

  const LIR_Opr reg = result_register_for(x->type());
  LIR_Opr tmp1 = FrameMap::rcx_oop_opr;
  LIR_Opr tmp2 = FrameMap::rsi_oop_opr;
  LIR_Opr tmp3 = FrameMap::rdi_oop_opr;
  LIR_Opr tmp4 = reg;
  LIR_Opr klass_reg = FrameMap::rdx_oop_opr;

  length.load_item_force(FrameMap::rbx_opr);
  LIR_Opr len = length.result();

  CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
  ciObject* obj = (ciObject*) ciObjArrayKlass::make(x->klass());
  if (obj == ciEnv::unloaded_ciobjarrayklass()) {
    BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
  }
  jobject2reg_with_patching(klass_reg, obj, patching_info);
  __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);

  LIR_Opr result = rlock_result(x);
  __ move(reg, result);
}
示例#3
0
GHashTable* get_dictionary(const FieldType * ftype, address src, address dest){
  ConversationTables* conversation_tables = NULL;
  GHashTable* dictionary = NULL;
  
  conversation_tables = get_conversation_table(src, dest);
  
  /* Determine if we need a template or a non-template dictionary */
  if(g_strcmp0(ftype->dictionary,TEMPLATE_DICTIONARY) == 0){
    dictionary = g_hash_table_lookup(conversation_tables->templates, &(ftype->tid));
    /* If the dictionary does not exist create it */
    if(!dictionary){
      dictionary = g_hash_table_new_full(&g_str_hash,&g_str_equal,
				       (GDestroyNotify)&g_free,
				       (GDestroyNotify)&free_typed_value);
      g_hash_table_insert(conversation_tables->templates, int_dup(ftype->tid), dictionary);
    } 
  } else {
    dictionary = g_hash_table_lookup(conversation_tables->normal, ftype->dictionary);
    /* If the dictionary does not exist create it */
    if(!dictionary){
      dictionary = g_hash_table_new_full(&g_str_hash,&g_str_equal,
				       (GDestroyNotify)&g_free,
				       (GDestroyNotify)&free_typed_value);
      g_hash_table_insert(conversation_tables->normal, ftype->dictionary, dictionary);
    } 
  }
  /* Should never be run */
  if(!dictionary){BAILOUT(NULL,"Unable to retrieve dictionary");}
  
  return dictionary;
}
示例#4
0
文件: config.c 项目: pickup09/pimd
/**
 * parse_compat_threshold - Parse old deprecated pimd.conf thresholds
 * @line:
 *
 * This is a backwards compatible parser for the two older threshold
 * settings used in pimd prior to v2.2.0.  The switchover mechanism has
 * been completely changed, however, so we simply read the settings as
 * if they where the same as the new spt_threshold, only converting the
 * rate argument differently (bps vs kbps).  Last line to be read is
 * what is activated in pimd as spt-threshold.
 *
 * Note, previously the parser was very lenient to errors, but since the
 * default has changed it is much more strict. Any syntax error and pimd
 * bails out ignoring the line.
 *
 * Syntax:
 * switch_register_threshold [rate <BPS> interval <SEC>]
 * switch_data_threshold     [rate <BPS> interval <SEC>]
 *
 * Returns:
 * When parsing @line is successful, returns %TRUE, otherwise %FALSE.
 */
static int parse_compat_threshold(char *line)
{
    char *w;
    int rate     = -1;
    int interval = -1;

    while (!EQUAL((w = next_word(&line)), "")) {
	if (EQUAL(w, "rate")) {
	    if (EQUAL((w = next_word(&line)), ""))
		BAILOUT("Missing rate value in compat threshold parser");

	    /* 10 --> 1,000,000,000 == 100 Gbps */
	    if (sscanf(w, "%10d", &rate) != 1)
		BAILOUT("Invalid rate value %s in compat threshold parser", w);

	    continue;
	}

	if (EQUAL(w, "interval")) {
	    if (EQUAL((w = next_word(&line)), ""))
		IGNORING("Missing interval value in compat threshold parser");

	    /* 5 --> 99,999 ~= 27h */
	    if (sscanf(w, "%5d", &interval) != 1)
		IGNORING("Invalid interval %s in compat threshold parser", w);

	    continue;
	}
    }

    /* Set polling mode */
    spt_threshold.mode = SPT_RATE;

    /* Only accept values if they don't messup for new spt-threshold */
    if (interval >= TIMER_INTERVAL)
	spt_threshold.interval = interval;

    /* Accounting for headers we can approximate 1 byte/s == 10 bits/s (bps) */
    spt_threshold.bytes = rate * spt_threshold.interval / 10;

    logit(LOG_INFO, 0, "Compatibility set spt-treshold rate %u kbps with interval %u sec",
	  spt_threshold.bytes, spt_threshold.interval);

    return TRUE;
}
示例#5
0
gboolean get_dictionary_value(const FieldType* ftype,
                              FieldData* fdata, address src, address dest)
{
  gboolean found = FALSE;
  GHashTable* dictionary = 0;
  const TypedValue* prev = 0;
  
  dictionary = get_dictionary(ftype, src, dest);
  if (!ftype->key) {
    BAILOUT(FALSE, "No key on field.");
  }
  prev = g_hash_table_lookup(dictionary,ftype->key);
  if (prev) {
    /* Determine if the types match */
    if (prev->type == ftype->type) {
      /* Copy the previous value for use */
      found = TRUE;
      fdata->status = prev->empty ? FieldEmpty : FieldExists;
      if (fdata->status == FieldExists) {
        copy_field_value(ftype->type, &prev->value, &fdata->value);
      }
    }
    else {
      /* An the types differ which is a dynamic error
       * The cast is to change the gchar* to guint8* so that our types will work with it
       */
      err_d(4, fdata);
    }
  }
  else if(ftype->hasDefault){
    /* TODO FIX THIS remove the || TRUE once the other todo has been handled*/
    if(ftype->mandatory || TRUE){
      fdata->status = FieldExists;
      copy_field_value(ftype->type, &ftype->value, &fdata->value);
    }
    else {
      /* TODO Determine if the default value is empty
       * if so set status accordingly and return the value
       * otherwise do the same as above but handle for optional (-1 for ints and such)
       */
      
    }
  }
  else {
    fdata->status = FieldUndefined;
  }
  
  return found;
}
void LIR_Assembler::check_codespace() {
    CodeSection* cs = _masm->code_section();
    if (cs->remaining() < (int)(NOT_LP64(1*K)LP64_ONLY(2*K))) {
        BAILOUT("CodeBuffer overflow");
    }
}
示例#7
0
文件: gpodder.c 项目: Vegasq/gpodder
int main(int argc, char** argv)
{
    char path_env[MAX_PATH];
    char current_dir[MAX_PATH];
    char *endmarker = NULL;
    const char *dll_path = NULL;
    const char *target_folder = NULL;
    char tmp[MAX_PATH];
    int force_select = 0;
    int i;
    void *MainPy;
    void *GtkModule;
    int _argc = 1;
    char *_argv[] = { MAIN_MODULE };
    TCHAR gPodder_Home[MAX_PATH];
    TCHAR Temp_Download_Filename[MAX_PATH];

    HMODULE python_dll;
    FARPROC Py_Initialize;
    FARPROC PySys_SetArgvEx;
    FARPROC PyImport_ImportModule;
    FARPROC PyFile_FromString;
    FARPROC PyFile_AsFile;
    FARPROC PyRun_SimpleFile;
    FARPROC Py_Finalize;

#if defined(GPODDER_CLI)
    SetConsoleTitle(PROGNAME);
#endif

    for (i=1; i<argc; i++) {
        if (strcmp(argv[i], "--select-folder") == 0) {
            force_select = 1;
        }
    }

    DetermineHomeFolder(force_select);

    if (GetEnvironmentVariable("GPODDER_HOME",
            gPodder_Home, sizeof(gPodder_Home)) == 0) {
        BAILOUT("Cannot determine download folder (GPODDER_HOME). Exiting.");
    }
    CreateDirectory(gPodder_Home, NULL);

    /* Set current directory to directory of launcher */
    strncpy(current_dir, argv[0], MAX_PATH);
    endmarker = strrchr(current_dir, '\\');
    if (endmarker == NULL) {
        endmarker = strrchr(current_dir, '/');
    }
    if (endmarker != NULL) {
        *endmarker = '\0';
        /* We know the folder where the launcher sits - cd into it */
        if (SetCurrentDirectory(current_dir) == 0) {
            BAILOUT("Cannot set current directory.");
        }
    }

    /**
     * Workaround for error R6034 (need to do this before Python DLL
     * is loaded, otherwise the runtime error will still show up)
     **/
    char *new_path = clean_path_variable(getenv("PATH"));
    SetEnvironmentVariable("PATH", new_path);
    free(new_path);

    /* Only load the Python DLL after we've set up the environment */
    python_dll = LoadLibrary("python27.dll");

    if (python_dll == NULL) {
        /* Try to detect "just for me"-installed Python version (bug 1480) */
        dll_path = FindPythonDLL(HKEY_CURRENT_USER);
        if (dll_path == NULL) {
            /* Try to detect "for all users" Python (bug 1480, comment 9) */
            dll_path = FindPythonDLL(HKEY_LOCAL_MACHINE);
        }
        if (dll_path != NULL) {
            python_dll = LoadLibrary(dll_path);
        }
    }

    if (python_dll == NULL) {
        if (MessageBox(NULL,
                PROGNAME " requires Python 2.7.\n"
                "Do you want to install it now?",
                "Python 2.7 installation not found",
                MB_YESNO | MB_ICONQUESTION) == IDYES) {
            strncpy(Temp_Download_Filename, gPodder_Home, MAX_PATH);
            strncat(Temp_Download_Filename, "\\", MAX_PATH);
            strncat(Temp_Download_Filename, PYTHON_INSTALLER_FILE, MAX_PATH);
            if (DownloadFile(Temp_Download_Filename,
                        PYTHON_INSTALLER_URL,
                        PYTHON_INSTALLER_SIZE) == PYTHON_INSTALLER_SIZE) {
                ShellExecute(NULL,
                        "open",
                        Temp_Download_Filename,
                        NULL,
                        NULL,
                        SW_SHOWNORMAL);
            }
        }

        return 1;
    }

    LOOKUP_FUNCTION(Py_Initialize);
    LOOKUP_FUNCTION(PySys_SetArgvEx);
    LOOKUP_FUNCTION(PyImport_ImportModule);
    LOOKUP_FUNCTION(PyFile_FromString);
    LOOKUP_FUNCTION(PyFile_AsFile);
    LOOKUP_FUNCTION(PyRun_SimpleFile);
    LOOKUP_FUNCTION(Py_Finalize);

    Py_Initialize();
    argv[0] = MAIN_MODULE;
    PySys_SetArgvEx(argc, argv, 0);

#if defined(GPODDER_GUI)
    /* Check for GTK, but not if we are running the CLI */
    GtkModule = (void*)PyImport_ImportModule("gtk");
    if (GtkModule == NULL) {
        if (MessageBox(NULL,
                PROGNAME " requires PyGTK.\n"
                "Do you want to install it now?",
                "PyGTK installation not found",
                MB_YESNO | MB_ICONQUESTION) == IDYES) {
            strncpy(Temp_Download_Filename, gPodder_Home, MAX_PATH);
            strncat(Temp_Download_Filename, "\\", MAX_PATH);
            strncat(Temp_Download_Filename, PYGTK_INSTALLER_FILE, MAX_PATH);
            if (DownloadFile(Temp_Download_Filename,
                        PYGTK_INSTALLER_URL,
                        PYGTK_INSTALLER_SIZE) == PYGTK_INSTALLER_SIZE) {
                ShellExecute(NULL,
                        "open",
                        Temp_Download_Filename,
                        NULL,
                        NULL,
                        SW_SHOWNORMAL);
            }
        }

        return 1;
    }
    // decref GtkModule
#endif

    // XXX: Test for feedparser, mygpoclient, dbus

    MainPy = (void*)PyFile_FromString(MAIN_MODULE, "r");
    if (MainPy == NULL) { BAILOUT("Cannot load main file") }
    if (PyRun_SimpleFile(PyFile_AsFile(MainPy), MAIN_MODULE) != 0) {
        BAILOUT("There was an error running " MAIN_MODULE " in Python.");
    }
    // decref MainPy
    Py_Finalize();

    return 0;
}