Start C++ RAII conversions for dicache.
This commit is contained in:
+26
-24
@@ -60,7 +60,7 @@ static int Dicache_entry_cmp(const void *v1, const void *v2)
|
|||||||
{
|
{
|
||||||
const DICacheEntry *e1 = reinterpret_cast< const DICacheEntry * >( v1 ), *e2 = reinterpret_cast< const DICacheEntry * >( v2 );
|
const DICacheEntry *e1 = reinterpret_cast< const DICacheEntry * >( v1 ), *e2 = reinterpret_cast< const DICacheEntry * >( v2 );
|
||||||
|
|
||||||
int st = a_Url_cmp(e1->url, e2->url);
|
int st = a_Url_cmp(e1->url.get(), e2->url.get());
|
||||||
if (st == 0) {
|
if (st == 0) {
|
||||||
if (e2->version == DIC_Last)
|
if (e2->version == DIC_Last)
|
||||||
st = (e1->Flags & DIF_Last ? 0 : -1);
|
st = (e1->Flags & DIF_Last ? 0 : -1);
|
||||||
@@ -93,7 +93,7 @@ void a_Dicache_init(void)
|
|||||||
*/
|
*/
|
||||||
static DICacheEntry *Dicache_entry_new(void)
|
static DICacheEntry *Dicache_entry_new(void)
|
||||||
{
|
{
|
||||||
DICacheEntry *entry = dNew(DICacheEntry, 1);
|
DICacheEntry *entry = std::make_unique< DICacheEntry >().release();
|
||||||
|
|
||||||
entry->width = 0;
|
entry->width = 0;
|
||||||
entry->height = 0;
|
entry->height = 0;
|
||||||
@@ -125,7 +125,7 @@ static DICacheEntry *Dicache_add_entry(const DilloUrl *Url)
|
|||||||
DICacheEntry e, *entry, *last;
|
DICacheEntry e, *entry, *last;
|
||||||
|
|
||||||
entry = Dicache_entry_new();
|
entry = Dicache_entry_new();
|
||||||
e.url = (DilloUrl*)Url;
|
e.url = a_Url_dup( Url );
|
||||||
e.version = DIC_Last;
|
e.version = DIC_Last;
|
||||||
last = reinterpret_cast< DICacheEntry * >( dList_find_sorted(CachedIMGs, &e, Dicache_entry_cmp) );
|
last = reinterpret_cast< DICacheEntry * >( dList_find_sorted(CachedIMGs, &e, Dicache_entry_cmp) );
|
||||||
if (last) {
|
if (last) {
|
||||||
@@ -133,7 +133,7 @@ static DICacheEntry *Dicache_add_entry(const DilloUrl *Url)
|
|||||||
last->Flags &= ~DIF_Last;
|
last->Flags &= ~DIF_Last;
|
||||||
entry->version = last->version + 1;
|
entry->version = last->version + 1;
|
||||||
}
|
}
|
||||||
entry->url = a_Url_dup(Url).release();
|
entry->url = a_Url_dup(Url);
|
||||||
entry->Flags |= DIF_Last;
|
entry->Flags |= DIF_Last;
|
||||||
dList_insert_sorted(CachedIMGs, entry, Dicache_entry_cmp);
|
dList_insert_sorted(CachedIMGs, entry, Dicache_entry_cmp);
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ DICacheEntry *a_Dicache_get_entry(const DilloUrl *Url, int version)
|
|||||||
DICacheEntry *entry = NULL;
|
DICacheEntry *entry = NULL;
|
||||||
|
|
||||||
dReturn_val_if_fail(version != 0, NULL);
|
dReturn_val_if_fail(version != 0, NULL);
|
||||||
e.url = const_cast< DilloUrl * >( Url );
|
e.url = a_Url_dup( Url );
|
||||||
e.version = version;
|
e.version = version;
|
||||||
entry = reinterpret_cast< DICacheEntry * >( dList_find_sorted(CachedIMGs, &e, Dicache_entry_cmp) );
|
entry = reinterpret_cast< DICacheEntry * >( dList_find_sorted(CachedIMGs, &e, Dicache_entry_cmp) );
|
||||||
if (entry && !(entry->Flags & DIF_Valid) && version == DIC_Last)
|
if (entry && !(entry->Flags & DIF_Valid) && version == DIC_Last)
|
||||||
@@ -169,7 +169,7 @@ static void Dicache_remove(const DilloUrl *Url, int version)
|
|||||||
DICacheEntry e, *entry;
|
DICacheEntry e, *entry;
|
||||||
|
|
||||||
_MSG("Dicache_remove url=%s\n", URL_STR(Url));
|
_MSG("Dicache_remove url=%s\n", URL_STR(Url));
|
||||||
e.url = const_cast< DilloUrl * >( Url );
|
e.url = a_Url_dup( Url );
|
||||||
e.version = version;
|
e.version = version;
|
||||||
entry = reinterpret_cast< DICacheEntry * >( dList_find_sorted(CachedIMGs, &e, Dicache_entry_cmp) );
|
entry = reinterpret_cast< DICacheEntry * >( dList_find_sorted(CachedIMGs, &e, Dicache_entry_cmp) );
|
||||||
dReturn_if (entry == NULL);
|
dReturn_if (entry == NULL);
|
||||||
@@ -180,15 +180,18 @@ static void Dicache_remove(const DilloUrl *Url, int version)
|
|||||||
dList_remove(CachedIMGs, entry);
|
dList_remove(CachedIMGs, entry);
|
||||||
dicache_size_total -= entry->TotalSize;
|
dicache_size_total -= entry->TotalSize;
|
||||||
|
|
||||||
|
delete entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
DICacheEntry::~DICacheEntry()
|
||||||
|
{
|
||||||
/* entry cleanup */
|
/* entry cleanup */
|
||||||
delete entry->url;
|
dFree(cmap);
|
||||||
dFree(entry->cmap);
|
delete BitVec;
|
||||||
delete entry->BitVec;
|
if(v_imgbuf) a_Imgbuf_unref(v_imgbuf);
|
||||||
a_Imgbuf_unref(entry->v_imgbuf);
|
if (Decoder) {
|
||||||
if (entry->Decoder) {
|
Decoder(CA_Abort, reinterpret_cast< CacheClient * >( DecoderData ));
|
||||||
entry->Decoder(CA_Abort, reinterpret_cast< CacheClient * >( entry->DecoderData ));
|
|
||||||
}
|
}
|
||||||
dFree(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -410,27 +413,27 @@ static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,
|
|||||||
if (ImgType == DIC_Jpeg) {
|
if (ImgType == DIC_Jpeg) {
|
||||||
DicEntry->Decoder = (CA_Callback_t)a_Jpeg_callback;
|
DicEntry->Decoder = (CA_Callback_t)a_Jpeg_callback;
|
||||||
DicEntry->DecoderData =
|
DicEntry->DecoderData =
|
||||||
a_Jpeg_new(web->Image.get(), DicEntry->url, DicEntry->version);
|
a_Jpeg_new(web->Image.get(), DicEntry->url.get(), DicEntry->version);
|
||||||
} else if (ImgType == DIC_Gif) {
|
} else if (ImgType == DIC_Gif) {
|
||||||
DicEntry->Decoder = (CA_Callback_t)a_Gif_callback;
|
DicEntry->Decoder = (CA_Callback_t)a_Gif_callback;
|
||||||
DicEntry->DecoderData =
|
DicEntry->DecoderData =
|
||||||
a_Gif_new(web->Image.get(), DicEntry->url, DicEntry->version);
|
a_Gif_new(web->Image.get(), DicEntry->url.get(), DicEntry->version);
|
||||||
} else if (ImgType == DIC_Webp) {
|
} else if (ImgType == DIC_Webp) {
|
||||||
DicEntry->Decoder = (CA_Callback_t)a_Webp_callback;
|
DicEntry->Decoder = (CA_Callback_t)a_Webp_callback;
|
||||||
DicEntry->DecoderData =
|
DicEntry->DecoderData =
|
||||||
a_Webp_new(web->Image.get(), DicEntry->url, DicEntry->version);
|
a_Webp_new(web->Image.get(), DicEntry->url.get(), DicEntry->version);
|
||||||
} else if (ImgType == DIC_Png) {
|
} else if (ImgType == DIC_Png) {
|
||||||
DicEntry->Decoder = (CA_Callback_t)a_Png_callback;
|
DicEntry->Decoder = (CA_Callback_t)a_Png_callback;
|
||||||
DicEntry->DecoderData =
|
DicEntry->DecoderData =
|
||||||
a_Png_new(web->Image.get(), DicEntry->url, DicEntry->version);
|
a_Png_new(web->Image.get(), DicEntry->url.get(), DicEntry->version);
|
||||||
} else if (ImgType == DIC_Svg) {
|
} else if (ImgType == DIC_Svg) {
|
||||||
DicEntry->Decoder = (CA_Callback_t)a_Svg_callback;
|
DicEntry->Decoder = (CA_Callback_t)a_Svg_callback;
|
||||||
DicEntry->DecoderData =
|
DicEntry->DecoderData =
|
||||||
a_Svg_new(web->Image.get(), DicEntry->url, DicEntry->version);
|
a_Svg_new(web->Image.get(), DicEntry->url.get(), DicEntry->version);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Repeated image */
|
/* Repeated image */
|
||||||
a_Dicache_ref(DicEntry->url, DicEntry->version);
|
a_Dicache_ref(DicEntry->url.get(), DicEntry->version);
|
||||||
}
|
}
|
||||||
/* Survive three cleanup passes (set to zero = old behaviour). */
|
/* Survive three cleanup passes (set to zero = old behaviour). */
|
||||||
DicEntry->SurvCleanup = 3;
|
DicEntry->SurvCleanup = 3;
|
||||||
@@ -511,7 +514,7 @@ void a_Dicache_callback(int Op, CacheClient_t *Client)
|
|||||||
if (DicEntry->State < DIC_Close) {
|
if (DicEntry->State < DIC_Close) {
|
||||||
DicEntry->Decoder(Op, Client);
|
DicEntry->Decoder(Op, Client);
|
||||||
} else {
|
} else {
|
||||||
a_Dicache_close(DicEntry->url, DicEntry->version, Client);
|
a_Dicache_close(DicEntry->url.get(), DicEntry->version, Client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,7 +523,7 @@ void a_Dicache_callback(int Op, CacheClient_t *Client)
|
|||||||
if (Image->height == 0 && DicEntry->State >= DIC_SetParms) {
|
if (Image->height == 0 && DicEntry->State >= DIC_SetParms) {
|
||||||
/* Set parms */
|
/* Set parms */
|
||||||
a_Image_set_parms(
|
a_Image_set_parms(
|
||||||
Image, DicEntry->v_imgbuf, DicEntry->url,
|
Image, DicEntry->v_imgbuf, DicEntry->url.get(),
|
||||||
DicEntry->version, DicEntry->width, DicEntry->height,
|
DicEntry->version, DicEntry->width, DicEntry->height,
|
||||||
DicEntry->type);
|
DicEntry->type);
|
||||||
}
|
}
|
||||||
@@ -570,7 +573,7 @@ void a_Dicache_cleanup(void)
|
|||||||
continue; /* keep the entry one more pass */
|
continue; /* keep the entry one more pass */
|
||||||
|
|
||||||
/* free this unused entry */
|
/* free this unused entry */
|
||||||
Dicache_remove(entry->url, entry->version);
|
Dicache_remove(entry->url.get(), entry->version);
|
||||||
--i; /* adjust counter */
|
--i; /* adjust counter */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -590,12 +593,11 @@ void a_Dicache_freeall(void)
|
|||||||
/* Remove all the dicache entries */
|
/* Remove all the dicache entries */
|
||||||
while ((entry = reinterpret_cast< DICacheEntry * >( dList_nth_data(CachedIMGs, dList_length(CachedIMGs)-1) ))) {
|
while ((entry = reinterpret_cast< DICacheEntry * >( dList_nth_data(CachedIMGs, dList_length(CachedIMGs)-1) ))) {
|
||||||
dList_remove_fast(CachedIMGs, entry);
|
dList_remove_fast(CachedIMGs, entry);
|
||||||
delete entry->url;
|
|
||||||
dFree(entry->cmap);
|
dFree(entry->cmap);
|
||||||
delete entry->BitVec;
|
delete entry->BitVec;
|
||||||
a_Imgbuf_unref(entry->v_imgbuf);
|
a_Imgbuf_unref(entry->v_imgbuf);
|
||||||
dicache_size_total -= entry->TotalSize;
|
dicache_size_total -= entry->TotalSize;
|
||||||
dFree(entry);
|
delete entry;
|
||||||
}
|
}
|
||||||
dList_free(CachedIMGs);
|
dList_free(CachedIMGs);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-8
@@ -27,26 +27,27 @@ typedef enum {
|
|||||||
DIC_Abort /**< Image transfer aborted */
|
DIC_Abort /**< Image transfer aborted */
|
||||||
} DicEntryState;
|
} DicEntryState;
|
||||||
|
|
||||||
typedef struct DICacheEntry {
|
struct DICacheEntry {
|
||||||
DilloUrl *url; /**< Image URL for this entry */
|
std::unique_ptr< DilloUrl > url; /**< Image URL for this entry */
|
||||||
DilloImgType type; /**< Image type */
|
DilloImgType type; /**< Image type */
|
||||||
uint_t width, height; /**< As taken from image data */
|
uint_t width, height; /**< As taken from image data */
|
||||||
short Flags; /**< See Flags */
|
short Flags; /**< See Flags */
|
||||||
short SurvCleanup; /**< Cleanup-pass survival for unused images */
|
short SurvCleanup; /**< Cleanup-pass survival for unused images */
|
||||||
uchar_t *cmap; /**< Color map */
|
uchar_t *cmap= nullptr; /**< Color map */
|
||||||
void *v_imgbuf; /**< Void pointer to an Imgbuf object */
|
void *v_imgbuf= nullptr; /**< Void pointer to an Imgbuf object */
|
||||||
uint_t TotalSize; /**< Amount of memory the image takes up */
|
uint_t TotalSize; /**< Amount of memory the image takes up */
|
||||||
uint_t ScanNumber; /**< Current decoding scan */
|
uint_t ScanNumber; /**< Current decoding scan */
|
||||||
bitvec_t *BitVec; /**< Bit vector for decoded rows */
|
bitvec_t *BitVec= nullptr; /**< Bit vector for decoded rows */
|
||||||
DicEntryState State; /**< Current status for this entry */
|
DicEntryState State; /**< Current status for this entry */
|
||||||
int RefCount; /**< Reference Counter */
|
int RefCount; /**< Reference Counter */
|
||||||
int version; /**< Version number, used for different
|
int version; /**< Version number, used for different
|
||||||
versions of the same URL image */
|
versions of the same URL image */
|
||||||
|
|
||||||
uint_t DecodedSize; /**< Size of already decoded data */
|
uint_t DecodedSize; /**< Size of already decoded data */
|
||||||
CA_Callback_t Decoder; /**< Client function */
|
CA_Callback_t Decoder= nullptr; /**< Client function */
|
||||||
void *DecoderData; /**< Client function data */
|
void *DecoderData= nullptr; /**< Client function data */
|
||||||
} DICacheEntry;
|
~DICacheEntry();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void a_Dicache_init (void);
|
void a_Dicache_init (void);
|
||||||
|
|||||||
Reference in New Issue
Block a user