Exemple #1
0
void destroy_eval__safe() {
  prim_container *c = all_prims;

  while (c != NULL) {
    prim_container *t;
    free_malloced(c->prim);
    t = c;
    c = c->next;
    free_malloced(t);
  }

  /* Frees containers and non heap values (?) held in
     environments. */
  destroy_env(&special_forms);
  destroy_env(&toplevel);
  destroy_env(&primitives);
  destroy_env(&lib);
  destroy_env(&internal);


  //orig_sexpr == NULL;
  //*live_root;

  /* This will free resources held by symbol representation. */
  free_symtab(global_symtab);
  global_symtab = NULL;
  __gs.head = NULL;
}
Exemple #2
0
void uiloop(data_t a, data_t b, int nsteps, char *s)
{
	int done = 0;
	struct input inp;
	struct parse_options po;
	struct expr_environ *env = new_env();
	struct expr_var ans;
	data_t ans_data = 45;
	
	Genv = env;
	
	/* setup global vars */
	ans.name = "ans";
	ans.location = &ans_data;
	var_load(env, &ans);
	
	/*setup C funcions & constants*/
	load_builtins(env);
	func_multiload(env, local_funcs, ARSIZE(local_funcs));

	/*Parser options*/
	po.auto_clear = 0;
	po.n_args = (nsteps != 0);
	po.n_rets = CALC_N_RETS;
	
	if (s == NULL) {
		mk_lineinput(&inp, stdin);
		
		while(!done && !linput_done(inp) && !Gdone) {
			fputs("> ", stderr);
			if (linput_prefetch(inp)) {
				eval_print(a, b, nsteps, po, env, inp, &ans_data);
			}
		}
		
		destroy_lineinput(&inp);
	} else {
		mk_strinput(&inp, s, STRINP_NOCOPY);
		eval_print(a, b, nsteps, po, env, inp, &ans_data);
		destroy_strinput(&inp);
	}
	
	destroy_env(env);
}
Exemple #3
0
int sysinit (cfg_opts *options)
{
    struct t_os2process *proc; // sysinit's PTDA/proc
    //l4events_ch_t event_ch = L4EVENTS_EXIT_CHANNEL;
    //l4events_nr_t event_nr = L4EVENTS_NO_NR;
    //l4events_event_t event;
    char   *env;
    APIRET rc;

    // create global environment
    create_env(&env);

    // Create the sysinit process PTDA structure (pid == ppid == 0)
    proc = PrcCreate(0,         // ppid
                     "sysinit", // pPrg
                     NULL,      // pArg
                     env);      // pEnv

    /* set task number */
    sysinit_id = l4_myself();
    proc->task = sysinit_id;

    if (!names_register("os2srv.sysinit"))
        io_log("error registering on the name server\n");

    /* Start servers */
    exec_runserver(proc->pid);

    /* Start run=/call= */
    exec_run_call(proc->pid);

    // Check PROTSHELL statement value
    if (!options->protshell || !*(options->protshell))
    {
        io_log("No PROTSHELL statement in CONFIG.SYS\n");
        rc = ERROR_INVALID_PARAMETER; /*ERROR_INVALID_PARAMETER 87; Not defined for Windows*/
    } else {
        exec_protshell(options);
        rc = 0; /* NO_ERROR */
    }

    io_log("sem wait\n");

    if (!rc) // wait until child process (protshell) terminates (this will unblock us)
        l4semaphore_down(&proc->term_sem);

    io_log("done waiting\n");

    /* if (use_events) // use events server
    {
      // terminate by sending an exit event
      event.len = sizeof(l4_threadid_t);
      *(l4_threadid_t*)event.str = l4_myself();
      // send exit event
      l4events_send(event_ch, &event, &event_nr, L4EVENTS_SEND_ACK);
      // get acknowledge
      l4events_get_ack(&event_nr, L4_IPC_NEVER);
    } */

    io_log("event notification sent\n");

    // unregister at names
    if (!names_unregister_task(sysinit_id))
        io_log("Cannot unregister at name server!\n");

    // destroy proc/PTDA
    PrcDestroy(proc);

    // destroy global environment
    destroy_env(env);

    io_log("OS/2 Server ended\n");
    // terminate OS/2 Server
    exit(rc);

    return rc;
}
void LMDBFileIndex::commit_transaction_internal(bool handle_enosp)
{
	int rc = mdb_txn_commit(txn);
	
	
	if(rc==MDB_MAP_FULL && handle_enosp)
	{
		if(_has_error)
		{
			Server->Log("LMDB had error during increase (on commit). Aborting...", LL_ERROR);
			start_transaction();
			return;
		}

		{
			read_transaction_lock.reset();

			IScopedWriteLock lock(mutex);

			destroy_env();

			map_size*=2;

			Server->Log("Increased LMDB database size to "+PrettyPrintBytes(map_size)+" (on commit)", LL_DEBUG);

			if(!create_env())
			{
				Server->Log("Error creating env after database file size increase", LL_ERROR);
				_has_error=true;
				start_transaction();
				return;
			}
			
		}

		start_transaction();

		replay_transaction_log();
		
		commit_transaction_internal(false);
	}
	else if(rc==MDB_BAD_TXN && handle_enosp)
	{
		if(_has_error)
		{
			Server->Log("LMDB had error on BAD_TXN (on commit). Aborting...", LL_ERROR);
			start_transaction();
			return;
		}
		
		start_transaction();
		
		replay_transaction_log();
		
		commit_transaction_internal(false);
	}
	else if(rc)
	{
		Server->Log("LMDB: Failed to commit transaction ("+(std::string)mdb_strerror(rc)+")", LL_ERROR);
		_has_error=true;
	}

	read_transaction_lock.reset();
	transaction_log.clear();
}
void LMDBFileIndex::del_internal(const SIndexKey& key, bool log, bool handle_enosp)
{		
	MDB_val mdb_tkey;
	mdb_tkey.mv_data=const_cast<void*>(static_cast<const void*>(&key));
	mdb_tkey.mv_size=sizeof(SIndexKey);

	int rc = mdb_del(txn, dbi, &mdb_tkey, NULL);

	if(rc==MDB_MAP_FULL && handle_enosp)
	{
		mdb_txn_abort(txn);

		if(_has_error)
		{
			Server->Log("LMDB had error during increase (on del). Aborting...", LL_ERROR);
			start_transaction();
			return;
		}

		{
			read_transaction_lock.reset();

			IScopedWriteLock lock(mutex);

			destroy_env();

			map_size*=2;

			Server->Log("Increased LMDB database size to "+PrettyPrintBytes(map_size)+" (on delete)", LL_DEBUG);

			if(!create_env())
			{
				Server->Log("Error creating env after database file size increase", LL_ERROR);
				_has_error=true;
				start_transaction();
				return;
			}
			
		}

		start_transaction();

		replay_transaction_log();

		del(key);
	}
	else if(rc==MDB_BAD_TXN && handle_enosp)
	{
		mdb_txn_abort(txn);
		
		if(_has_error)
		{
			Server->Log("LMDB had error on BAD_TXN (on del). Aborting...", LL_ERROR);
			start_transaction();
			return;
		}
		
		start_transaction();
		
		replay_transaction_log();
		
		del_internal(key, true, false);
	}
	else if (rc == MDB_NOTFOUND)
	{
		FILEENTRY_DEBUG(Server->Log("LMDB: Failed to delete data (" + (std::string)mdb_strerror(rc) + ")", LL_ERROR));
	}
	else if(rc)
	{
		Server->Log("LMDB: Failed to delete data ("+(std::string)mdb_strerror(rc)+")", LL_ERROR);
		_has_error=true;
	}

	if(log)
	{
		STransactionLogItem item = { key, 0, 0 };
		transaction_log.push_back(item);
	}	
}
void LMDBFileIndex::put_internal(const SIndexKey& key, int64 value, int flags, bool log, bool handle_enosp)
{
	CWData vdata;
	vdata.addVarInt(value);
			
	MDB_val mdb_tkey;
	mdb_tkey.mv_data=const_cast<void*>(static_cast<const void*>(&key));
	mdb_tkey.mv_size=sizeof(SIndexKey);

	MDB_val mdb_tvalue;
	mdb_tvalue.mv_data=vdata.getDataPtr();
	mdb_tvalue.mv_size=vdata.getDataSize();

	int rc = mdb_put(txn, dbi, &mdb_tkey, &mdb_tvalue, flags);

	if(rc==MDB_MAP_FULL && handle_enosp)
	{
		mdb_txn_abort(txn);

		if(_has_error)
		{
			Server->Log("LMDB had error during increase (on put). Aborting...", LL_ERROR);
			start_transaction();
			return;
		}

		{
			read_transaction_lock.reset();

			IScopedWriteLock lock(mutex);

			destroy_env();

			map_size*=2;

			Server->Log("Increased LMDB database size to "+PrettyPrintBytes(map_size)+" (on put)", LL_DEBUG);

			if(!create_env())
			{
				Server->Log("Error creating env after database file size increase", LL_ERROR);
				_has_error=true;
				start_transaction();
				return;
			}
			
		}

		start_transaction();

		replay_transaction_log();
		
		put_internal(key, value, flags, false, true);
	}
	else if(rc==MDB_BAD_TXN && handle_enosp)
	{
		mdb_txn_abort(txn);
		
		if(_has_error)
		{
			Server->Log("LMDB had error on BAD_TXN (on put). Aborting...", LL_ERROR);
			start_transaction();
			return;
		}
		
		start_transaction();
		
		replay_transaction_log();
		
		put_internal(key, value, flags, false, false);
	}
	else if(rc)
	{
		Server->Log("LMDB: Failed to put data ("+(std::string)mdb_strerror(rc)+")", LL_ERROR);
		_has_error=true;
	}

	if(!_has_error && log)
	{
		STransactionLogItem item = { key, value, flags};
		transaction_log.push_back(item);
	}
}