forked from github/server
WIP: quicklist->selist shim can compile and link, but tests crash
This commit is contained in:
parent
1382583109
commit
c72b050a42
|
@ -4,7 +4,7 @@
|
|||
#include <kernel/faction.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <quicklist.h>
|
||||
#include <selist.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -15,7 +15,7 @@ typedef struct transfer {
|
|||
int amount;
|
||||
} transfer;
|
||||
|
||||
static quicklist *transfers = 0;
|
||||
static selist *transfers = 0;
|
||||
|
||||
int cmp_transfer(const void *v1, const void *v2) {
|
||||
const transfer *t1 = (const transfer *)v1;
|
||||
|
@ -35,22 +35,22 @@ int cmp_transfer(const void *v1, const void *v2) {
|
|||
void add_donation(faction * f1, faction * f2, int amount, region * r)
|
||||
{
|
||||
transfer tr, *tf;
|
||||
quicklist *ql = transfers;
|
||||
selist *ql = transfers;
|
||||
int qi = 0;
|
||||
|
||||
tr.r = r;
|
||||
tr.f1 = f1;
|
||||
tr.f2 = f2;
|
||||
tr.amount = amount;
|
||||
if (ql_set_find_ex(&ql, &qi, &tr, cmp_transfer)) {
|
||||
tf = (transfer *)ql_get(ql, qi);
|
||||
if (selist_set_find(&ql, &qi, &tr, cmp_transfer)) {
|
||||
tf = (transfer *)selist_get(ql, qi);
|
||||
tf->amount += amount;
|
||||
}
|
||||
else {
|
||||
tf = malloc(sizeof(transfer));
|
||||
memcpy(tf, &tr, sizeof(transfer));
|
||||
}
|
||||
ql_set_insert_ex(&transfers, tf, cmp_transfer);
|
||||
selist_set_insert(&transfers, tf, cmp_transfer);
|
||||
}
|
||||
|
||||
void free_donations(void) {
|
||||
|
|
|
@ -1,6 +1,51 @@
|
|||
#include "quicklist.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ql_push(struct quicklist **qlp, void *el)
|
||||
{
|
||||
selist_push(qlp, el);
|
||||
}
|
||||
|
||||
int ql_length(const struct quicklist *ql)
|
||||
{
|
||||
return selist_length(ql);
|
||||
}
|
||||
|
||||
void * ql_replace(struct quicklist *ql, int index, void *el)
|
||||
{
|
||||
return selist_replace(ql, index, el);
|
||||
}
|
||||
|
||||
void *ql_get(struct quicklist *ql, int index)
|
||||
{
|
||||
return selist_get(ql, index);
|
||||
}
|
||||
|
||||
int ql_delete(struct quicklist **qlp, int index)
|
||||
{
|
||||
return selist_delete(qlp, index);
|
||||
}
|
||||
|
||||
bool ql_empty(const struct quicklist *ql)
|
||||
{
|
||||
return selist_empty(ql);
|
||||
}
|
||||
|
||||
void ql_foreach(struct quicklist *ql, selist_cb cb)
|
||||
{
|
||||
selist_foreach(ql, cb);
|
||||
}
|
||||
|
||||
int ql_advance(struct quicklist **qlp, int *index, int stride)
|
||||
{
|
||||
return selist_advance(qlp, index, stride);
|
||||
}
|
||||
|
||||
void ql_free(struct quicklist *ql)
|
||||
{
|
||||
selist_free(ql);
|
||||
}
|
||||
|
||||
bool ql_set_remove(struct quicklist **qlp, const void *data)
|
||||
{
|
||||
int qi, qn;
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#define selist quicklist
|
||||
#define selist_free ql_free
|
||||
#define selist_delete ql_delete
|
||||
#define selist_foreach ql_foreach
|
||||
#define selist_get ql_get
|
||||
#define selist_replace ql_replace
|
||||
#define selist_length ql_length
|
||||
#define selist_push ql_push
|
||||
#define selist_empty ql_empty
|
||||
#define selist_advance ql_advance
|
||||
#include <selist.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int ql_advance(struct quicklist **qlp, int *index, int stride);
|
||||
void ql_foreach(struct quicklist *ql, selist_cb cb);
|
||||
void ql_free(struct quicklist *ql);
|
||||
int ql_delete(struct quicklist **qlp, int index);
|
||||
void ql_push(struct quicklist **qlp, void *el);
|
||||
int ql_length(const struct quicklist *ql);
|
||||
void * ql_replace(struct quicklist *ql, int index, void *el);
|
||||
void *ql_get(struct quicklist *ql, int index);
|
||||
bool ql_empty(const struct quicklist *ql);
|
||||
typedef void(*ql_cb)(void *);
|
||||
bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs));
|
||||
bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs));
|
||||
|
|
|
@ -989,7 +989,7 @@ int cmp_faction(const void *lhs, const void *rhs) {
|
|||
}
|
||||
|
||||
static void add_seen_faction_i(struct quicklist **flist, faction *f) {
|
||||
ql_set_insert_ex(flist, f, cmp_faction);
|
||||
selist_set_insert(flist, f, cmp_faction);
|
||||
}
|
||||
|
||||
void add_seen_faction(faction *self, faction *seen) {
|
||||
|
|
Loading…
Reference in New Issue