Skip to content

Commit

Permalink
Modernize C by changing #define constants to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 10, 2022
1 parent 2e31166 commit 8f70a72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
45 changes: 24 additions & 21 deletions lib/instructions/instruction_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@
#include <evmc/instructions.h>

/**
* Marks an instruction as undefined.
*
* The gas cost for undefined instructions is 0 because this is the cost of executing them
* in practice in EVM implementations.
* Gas cost tiers, names from Yellow Paper.
*/
#define UNDEFINED 0

/**
* Gas price tiers, names from Yellow Paper.
* @{
*/
#define ZERO 0
#define BASE 2
#define VERYLOW 3
#define LOW 5
#define MID 8
#define HIGH 10
enum
{
ZERO = 0,
BASE = 2,
VERYLOW = 3,
LOW = 5,
MID = 8,
HIGH = 10,

/** @} */
/**
* Marks an instruction as undefined.
*
* The gas cost for undefined instructions is 0 because this is the cost of executing them
* in practice in EVM implementations.
*/
UNDEFINED = ZERO
};

/**
* Defined in EIP-2929: Gas cost increases for state access opcodes.
*/
#define WARM_STORAGE_READ_COST 100
enum
{
/**
* Defined in EIP-2929: Gas cost increases for state access opcodes.
*/
WARM_STORAGE_READ_COST = 100
};


static struct evmc_instruction_metrics cancun_metrics[256] = {
Expand Down
8 changes: 5 additions & 3 deletions lib/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ static
return 0;
}

#define PATH_MAX_LENGTH 4096
enum
{
PATH_MAX_LENGTH = 4096,
LAST_ERROR_MSG_BUFFER_SIZE = 511
};

static const char* last_error_msg = NULL;

#define LAST_ERROR_MSG_BUFFER_SIZE 511

// Buffer for formatted error messages.
// It has one null byte extra to avoid buffer read overflow during concurrent access.
static char last_error_msg_buffer[LAST_ERROR_MSG_BUFFER_SIZE + 1];
Expand Down

0 comments on commit 8f70a72

Please sign in to comment.