comments, typos

This commit is contained in:
Christian Grothoff 2015-07-01 14:31:48 +02:00
parent c448e48b53
commit 1e3a45e0cd

View File

@ -132,7 +132,7 @@ data_copy (const struct PERF_TALER_MINTDB_Data *data, struct PERF_TALER_MINTDB_D
* Finds the first command in cmd with the name search
*
* @return the index of the first command with name search
* GNUNET_SYSERR if none found
* #GNUNET_SYSERR if none found
*/
static int
cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
@ -152,7 +152,7 @@ cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
static int
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
{
unsigned int i = 0;
unsigned int i;
for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
{
@ -170,13 +170,12 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
GNUNET_new_array (cmd[i].details.save_array.nb_saved,
struct PERF_TALER_MINTDB_Data);
}
break;
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
/* Creating the permutation array to randomize the data order */
{
int save_index ;
int save_index;
GNUNET_assert (GNUNET_SYSERR !=
(save_index = cmd_find (
@ -204,15 +203,16 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
static int
cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
{
unsigned int i = 0;
unsigned int i;
for (i = 0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
for (i=0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
{
switch (cmd[i].command)
{
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
{
unsigned int j;
for (j = 0; j < cmd[i].details.save_array.nb_saved; j++)
{
data_free (&cmd[i].details.save_array.data_saved[j]);
@ -234,7 +234,7 @@ cmd_clean (struct PERF_TALER_MINTDB_Cmd cmd[])
}
}
return GNUNET_OK;
};
}
/**
@ -245,6 +245,7 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
{
unsigned int i;
int jump;
GNUNET_assert (GNUNET_SYSERR !=
(jump = cmd_find (state->cmd,
state->cmd[state->i]
@ -262,7 +263,9 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
{
/* jump back to the start */
state->i = jump;
}else{
}
else
{
/* Reset the loop counter and continue running */
state->cmd[jump].details.loop.curr_iteration = 0;
}
@ -276,26 +279,30 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
static void
interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
{
int loop_index, save_index;
struct PERF_TALER_MINTDB_Cmd *cmd = &state->cmd[state->i];
struct PERF_TALER_MINTDB_Cmd *save_ref;
struct PERF_TALER_MINTDB_Cmd *loop_ref;
int loop_index;
int save_index;
unsigned int selection_chance;
GNUNET_assert (GNUNET_SYSERR !=
(loop_index = cmd_find (state->cmd,
state->cmd[state->i]
.details.save_array.label_loop)));
cmd->details.save_array.label_loop)));
loop_ref = &state->cmd[save_index];
GNUNET_assert (GNUNET_SYSERR !=
(save_index = cmd_find (state->cmd,
state->cmd[state->i]
.details.save_array.label_save)));
cmd->details.save_array.label_save)));
save_ref = &state->cmd[save_index];
/* Array initialization on first loop iteration
Alows for nested loops */
if (0 == state->cmd[loop_index].details.loop.curr_iteration)
if (0 == cmd->details.loop.curr_iteration)
{
state->cmd[state->i].details.save_array.index = 0;
cmd->details.save_array.index = 0;
}
/* The probobility distribution of the saved items will be a little biased
against the few last items but it should not be a big problem. */
selection_chance = state->cmd[loop_index].details.loop.max_iterations /
selection_chance = loop_ref->details.loop.max_iterations /
state->cmd[state->i].details.save_array.nb_saved;
/*
* If the remaining space is equal to the remaining number of
@ -303,14 +310,14 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
*
* Else it is saved only if the random numbre generated is 0
*/
if ((0 < (state->cmd[state->i].details.save_array.nb_saved -
state->cmd[state->i].details.save_array.index)) &&
(((state->cmd[loop_index].details.loop.max_iterations -
if ( (0 < (state->cmd[state->i].details.save_array.nb_saved -
state->cmd[state->i].details.save_array.index) ) &&
( ((state->cmd[loop_index].details.loop.max_iterations -
state->cmd[loop_index].details.loop.curr_iteration) ==
(state->cmd[state->i].details.save_array.nb_saved -
state->cmd[state->i].details.save_array.index))
|| (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
selection_chance))))
state->cmd[state->i].details.save_array.index)) ||
(0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
selection_chance)) ) )
{
struct PERF_TALER_MINTDB_Data *save_location;
struct PERF_TALER_MINTDB_Data *item_saved;
@ -332,7 +339,8 @@ static void
interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
{
unsigned int loop_iter;
int loop_index, save_index;
int loop_index;
int save_index;
struct PERF_TALER_MINTDB_Data *loaded_data;
GNUNET_assert (GNUNET_SYSERR !=
@ -361,6 +369,7 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
data_copy (loaded_data, &state->cmd[state->i].exposed);
}
/**
* Main interpreter loop.
*
@ -377,7 +386,9 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
return GNUNET_YES;
case PERF_TALER_MINTDB_CMD_DEBUG:
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", state->cmd[state->i].label);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"%s\n",
state->cmd[state->i].label);
break;
case PERF_TALER_MINTDB_CMD_LOOP:
@ -430,7 +441,8 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
break;
case PERF_TALER_MINTDB_CMD_ABORT_TRANSACTION:
state->plugin->rollback (state->plugin->cls, state->session);
state->plugin->rollback (state->plugin->cls,
state->session);
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
interpret_save_array (state);
@ -444,13 +456,12 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
{
int dki_index;
struct TALER_MINTDB_Deposit *deposit;
GNUNET_assert (GNUNET_SYSERR !=
(dki_index = cmd_find(state->cmd,
state->cmd[state->i]
.details.insert_deposit.label_dki)));
state->cmd[state->i].details.insert_deposit.label_dki)));
GNUNET_assert (NULL !=
(deposit = PERF_TALER_MINTDB_deposit_init (
state->cmd[dki_index].exposed.data.dki)));
(deposit = PERF_TALER_MINTDB_deposit_init (state->cmd[dki_index].exposed.data.dki)));
GNUNET_assert (
state->plugin->insert_deposit (state->plugin->cls,
@ -616,7 +627,8 @@ PERF_TALER_MINTDB_interpret (struct TALER_MINTDB_Plugin *db_plugin,
cmd_init (state.cmd);
// Running the interpreter
GNUNET_assert (NULL !=
(state.session = db_plugin->get_session (db_plugin->cls, GNUNET_YES)));
(state.session = db_plugin->get_session (db_plugin->cls,
GNUNET_YES)));
interpret (&state);
// Cleaning the memory
cmd_clean (cmd);