Gif with dtor.

This commit is contained in:
2025-08-01 11:39:58 -04:00
parent 2e28fca5dd
commit 8fbb06a701
2 changed files with 13 additions and 10 deletions

View File

@ -8,8 +8,9 @@ extern "C" {
#include "url.hh" #include "url.hh"
#include "image.hh" #include "image.hh"
struct DilloGif;
void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version); DilloGif *a_Gif_new(DilloImage *Image, DilloUrl *url, int version);
void a_Gif_callback(int Op, void *data); void a_Gif_callback(int Op, void *data);

View File

@ -82,7 +82,9 @@
#define MAX_LWZ_BITS 12 #define MAX_LWZ_BITS 12
typedef struct { struct DilloGif {
~DilloGif();
DilloImage *Image; DilloImage *Image;
DilloUrl *url; DilloUrl *url;
int version; int version;
@ -131,7 +133,7 @@ typedef struct {
int num_spill_lines_max; int num_spill_lines_max;
int length[(1 << MAX_LWZ_BITS) + 1]; int length[(1 << MAX_LWZ_BITS) + 1];
int code_and_byte[(1 << MAX_LWZ_BITS) + 1]; int code_and_byte[(1 << MAX_LWZ_BITS) + 1];
} DilloGif; };
/* Some invariants: /* Some invariants:
* *
@ -153,9 +155,9 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *buf,
/** /**
* Create a new gif structure for decoding a gif into a RGB buffer * Create a new gif structure for decoding a gif into a RGB buffer
*/ */
void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version) DilloGif *a_Gif_new(DilloImage *Image, DilloUrl *url, int version)
{ {
DilloGif *gif = reinterpret_cast< DilloGif * >( dMalloc(sizeof(DilloGif)) ); DilloGif *gif = new DilloGif{};
_MSG("a_Gif_new: gif=%p\n", gif); _MSG("a_Gif_new: gif=%p\n", gif);
gif->Image = Image; gif->Image = Image;
@ -180,8 +182,9 @@ void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version)
/** /**
* Free the gif-decoding data structure. * Free the gif-decoding data structure.
*/ */
static void Gif_free(DilloGif *gif) DilloGif::~DilloGif()
{ {
DilloGif *gif= this;
int i; int i;
_MSG("Gif_free: gif=%p\n", gif); _MSG("Gif_free: gif=%p\n", gif);
@ -192,7 +195,6 @@ static void Gif_free(DilloGif *gif)
dFree(gif->spill_lines[i]); dFree(gif->spill_lines[i]);
dFree(gif->spill_lines); dFree(gif->spill_lines);
} }
dFree(gif);
} }
/** /**
@ -208,7 +210,7 @@ void a_Gif_callback(int Op, void *data)
CacheClient_t *Client = reinterpret_cast< CacheClient_t * >( data ); CacheClient_t *Client = reinterpret_cast< CacheClient_t * >( data );
Gif_close(reinterpret_cast< DilloGif * >( Client->CbData ), Client); Gif_close(reinterpret_cast< DilloGif * >( Client->CbData ), Client);
} else if (Op == CA_Abort) { } else if (Op == CA_Abort) {
Gif_free(reinterpret_cast< DilloGif * >( data )); delete reinterpret_cast< DilloGif * >( data );
} }
} }
@ -246,7 +248,7 @@ static void Gif_close(DilloGif *gif, CacheClient_t *Client)
{ {
_MSG("Gif_close: destroy gif %p\n", gif); _MSG("Gif_close: destroy gif %p\n", gif);
a_Dicache_close(gif->url, gif->version, Client); a_Dicache_close(gif->url, gif->version, Client);
Gif_free(gif); delete gif;
} }
@ -1023,7 +1025,7 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf,
#else /* ENABLE_GIF */ #else /* ENABLE_GIF */
void *a_Gif_new() { return 0; } DilloGif *a_Gif_new() { return 0; }
void a_Gif_callback() { return; } void a_Gif_callback() { return; }
#endif /* ENABLE_GIF */ #endif /* ENABLE_GIF */