Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Remove gratuitous gpointer usage, and other GLib-isms
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Garzik committed May 4, 2015
1 parent 3de4e81 commit ae4dd25
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 30 deletions.
9 changes: 7 additions & 2 deletions include/ccoin/addr_match.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
*/

#include <stdbool.h>
#include <glib.h>
#include <openssl/bn.h>
#include <ccoin/parr.h>

struct bp_txout;
struct bp_keyset;
struct bp_tx;
struct bp_block;

extern bool bp_txout_match(const struct bp_txout *txout,
const struct bp_keyset *ks);
Expand All @@ -26,6 +31,6 @@ extern struct bp_block_match *bbm_new(void);
extern void bbm_free(struct bp_block_match *match);

extern parr *bp_block_match(const struct bp_block *block,
const struct bp_keyset *ks);
const struct bp_keyset *ks);

#endif /* __LIBCCOIN_ADDR_MATCH_H__ */
3 changes: 1 addition & 2 deletions include/ccoin/buint.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ extern void bu256_copy_swap(bu256_t *vo, const bu256_t *vi);
extern void bu256_copy_swap_dwords(bu256_t *vo, const bu256_t *vi);
extern void bu256_swap_dwords(bu256_t *v);
extern unsigned long bu256_hash(const void *key);
extern void bu256_free(bu256_t *v);
extern void g_bu256_free(gpointer data);
extern void bu256_free(void *bu256_v);

static inline bool bu256_is_zero(const bu256_t *v)
{
Expand Down
1 change: 0 additions & 1 deletion include/ccoin/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include <unistd.h>
#include <glib.h>

#ifndef HAVE_FDATASYNC
static inline int fdatasync(int fd)
Expand Down
6 changes: 3 additions & 3 deletions include/ccoin/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extern void bp_txin_init(struct bp_txin *txin);
extern bool deser_bp_txin(struct bp_txin *txin, struct const_buffer *buf);
extern void ser_bp_txin(cstring *s, const struct bp_txin *txin);
extern void bp_txin_free(struct bp_txin *txin);
extern void g_bp_txin_free(gpointer data);
extern void bp_txin_free_cb(void *data);
static inline bool bp_txin_valid(const struct bp_txin *txin) { return true; }
extern void bp_txin_copy(struct bp_txin *dest, const struct bp_txin *src);

Expand All @@ -125,7 +125,7 @@ extern void bp_txout_init(struct bp_txout *txout);
extern bool deser_bp_txout(struct bp_txout *txout, struct const_buffer *buf);
extern void ser_bp_txout(cstring *s, const struct bp_txout *txout);
extern void bp_txout_free(struct bp_txout *txout);
extern void g_bp_txout_free(gpointer data);
extern void bp_txout_free_cb(void *data);
extern void bp_txout_set_null(struct bp_txout *txout);
extern void bp_txout_copy(struct bp_txout *dest, const struct bp_txout *src);

Expand Down Expand Up @@ -239,7 +239,7 @@ extern void bp_check_merkle_branch(bu256_t *hash, const bu256_t *txhash_in,
const GArray *mrkbranch, unsigned int txidx);
extern bool bp_block_valid(struct bp_block *block);
extern unsigned int bp_block_ser_size(const struct bp_block *block);
extern void g_bp_block_free(gpointer data);
extern void bp_block_free_cb(void *data);

static inline void bp_block_copy_hdr(struct bp_block *dest,
const struct bp_block *src)
Expand Down
1 change: 0 additions & 1 deletion include/ccoin/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <glib.h>
#include <ccoin/core.h>
#include <ccoin/buffer.h>

Expand Down
2 changes: 1 addition & 1 deletion include/ccoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <glib.h>
#include <ccoin/buffer.h>
#include <ccoin/core.h>
#include <ccoin/clist.h>
#include <ccoin/buint.h>
#include <ccoin/key.h>
#include <ccoin/parr.h>

/** Signature hash types/flags */
enum
Expand Down
8 changes: 2 additions & 6 deletions lib/buint.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,13 @@ unsigned long bu160_hash(const void *key_)
return key->dword[BU160_WORDS / 2]; /* return rand int in the middle */
}

void bu256_free(bu256_t *v)
void bu256_free(void *bu256_v)
{
bu256_t *v = bu256_v;
if (!v)
return;

memset(v, 0, sizeof(*v));
free(v);
}

void g_bu256_free(gpointer data)
{
bu256_free(data);
}

16 changes: 8 additions & 8 deletions lib/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void bp_locator_push(struct bp_locator *locator, const bu256_t *hash_in)
{
/* TODO: replace '16' with number based on real world usage */
if (!locator->vHave)
locator->vHave = parr_new(16, g_bu256_free);
locator->vHave = parr_new(16, bu256_free);

bu256_t *hash = bu256_new(hash_in);
parr_add(locator->vHave, hash);
Expand Down Expand Up @@ -148,7 +148,7 @@ void bp_txin_free(struct bp_txin *txin)
}
}

void g_bp_txin_free(gpointer data)
void bp_txin_free_cb(void *data)
{
if (!data)
return;
Expand Down Expand Up @@ -205,7 +205,7 @@ void bp_txout_free(struct bp_txout *txout)
}
}

void g_bp_txout_free(gpointer data)
void bp_txout_free_cb(void *data)
{
if (!data)
return;
Expand Down Expand Up @@ -249,8 +249,8 @@ bool deser_bp_tx(struct bp_tx *tx, struct const_buffer *buf)
{
bp_tx_free(tx);

tx->vin = parr_new(8, g_bp_txin_free);
tx->vout = parr_new(8, g_bp_txout_free);
tx->vin = parr_new(8, bp_txin_free_cb);
tx->vout = parr_new(8, bp_txout_free_cb);

if (!deser_u32(&tx->nVersion, buf)) return false;

Expand Down Expand Up @@ -392,7 +392,7 @@ void bp_tx_copy(struct bp_tx *dest, const struct bp_tx *src)
else {
unsigned int i;

dest->vin = parr_new(src->vin->len, g_bp_txin_free);
dest->vin = parr_new(src->vin->len, bp_txin_free_cb);

for (i = 0; i < src->vin->len; i++) {
struct bp_txin *txin_old, *txin_new;
Expand All @@ -410,7 +410,7 @@ void bp_tx_copy(struct bp_tx *dest, const struct bp_tx *src)
unsigned int i;

dest->vout = parr_new(src->vout->len,
g_bp_txout_free);
bp_txout_free_cb);

for (i = 0; i < src->vout->len; i++) {
struct bp_txout *txout_old, *txout_new;
Expand Down Expand Up @@ -522,7 +522,7 @@ void bp_block_free(struct bp_block *block)
bp_block_vtx_free(block);
}

void g_bp_block_free(gpointer data)
void bp_block_free_cb(void *data)
{
if (!data)
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/script_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void bp_tx_sighash(bu256_t *hash, const cstring *scriptCode,
if ((nHashType & 0x1f) == SIGHASH_NONE) {
/* Wildcard payee */
bp_tx_free_vout(&txTmp);
txTmp.vout = parr_new(1, g_bp_txout_free);
txTmp.vout = parr_new(1, bp_txout_free_cb);

/* Let the others update at will */
for (i = 0; i < txTmp.vin->len; i++) {
Expand Down Expand Up @@ -192,7 +192,7 @@ static void stack_insert(parr *stack, const struct buffer *buf, int index_)
int index = stack->len + index_;
parr_add(stack, NULL);
memmove(&stack->data[index + 1], &stack->data[index],
sizeof(gpointer) * (stack->len - index - 1));
sizeof(void *) * (stack->len - index - 1));
stack->data[index] = buffer_copy(buf->p, buf->len);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool deser_u256_array(parr **ao, struct const_buffer *buf)
if (!vlen)
return true;

arr = parr_new(vlen, g_bu256_free);
arr = parr_new(vlen, bu256_free);
if (!arr)
return false;

Expand Down
1 change: 1 addition & 0 deletions lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <glib.h> // for g_random_int_range
#include <openssl/sha.h>
#include <openssl/ripemd.h>
#include <ccoin/coredefs.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/utxo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool bp_utxo_from_tx(struct bp_utxo *coin, const struct bp_tx *tx,
coin->height = height;
coin->version = tx->nVersion;

coin->vout = parr_new(tx->vout->len, g_bp_txout_free);
coin->vout = parr_new(tx->vout->len, bp_txout_free_cb);
unsigned int i;

for (i = 0; i < tx->vout->len; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/rawtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void append_input(char *txid_str, char *vout_str)
static void mutate_inputs(void)
{
if (!tx.vin)
tx.vin = parr_new(8, g_bp_txin_free);
tx.vin = parr_new(8, bp_txin_free_cb);

// delete inputs
clist *tmp = opt_del_txin;
Expand Down Expand Up @@ -293,7 +293,7 @@ static void append_output(char *addr_str, char *amount_str)
static void mutate_outputs(void)
{
if (!tx.vout)
tx.vout = parr_new(8, g_bp_txout_free);
tx.vout = parr_new(8, bp_txout_free_cb);

// delete outputs
clist *tmp = opt_del_txout;
Expand Down

0 comments on commit ae4dd25

Please sign in to comment.