kopia lustrzana https://github.com/Hamlib/Hamlib
Allocate separate storage for cache buffer
Add address to rig_struct, change CACHE() macro to use it. Free it when done. Issue #1420pull/1753/head
rodzic
7d28822273
commit
6f8bf81514
|
@ -253,10 +253,14 @@ enum rig_debug_level_e {
|
|||
|
||||
/* --------------- Rig capabilities -----------------*/
|
||||
|
||||
/* Forward struct references */
|
||||
/* Forward struct references
|
||||
* may also include structures defined elsewhere,
|
||||
* but pointed to by rig
|
||||
*/
|
||||
|
||||
struct rig;
|
||||
struct rig_state;
|
||||
struct rig_cache;
|
||||
|
||||
/**
|
||||
* \brief Rig structure definition (see rig for details).
|
||||
|
@ -2518,7 +2522,7 @@ typedef hamlib_port_t port_t;
|
|||
#define RIGPORT(r) (&r->state.rigport)
|
||||
#define PTTPORT(r) (&r->state.pttport)
|
||||
#define DCDPORT(r) (&r->state.dcdport)
|
||||
#define CACHE(r) (&r->state.cache)
|
||||
#define CACHE(r) ((r)->cache_addr)
|
||||
#define AMPPORT(a) (&a->state.ampport)
|
||||
#define ROTPORT(r) (&r->state.rotport)
|
||||
#define ROTPORT2(r) (&r->state.rotport2)
|
||||
|
@ -3101,6 +3105,10 @@ struct s_rig {
|
|||
struct rig_callbacks callbacks; /*!< registered event callbacks */
|
||||
// state should really be a pointer but that's a LOT of changes involved
|
||||
struct rig_state state; /*!< Rig state */
|
||||
/* Data beyond this line is for hamlib internal use only,
|
||||
* and should *NOT* be referenced by applications, as layout will change!
|
||||
*/
|
||||
struct rig_cache *cache_addr;
|
||||
};
|
||||
|
||||
|
||||
|
|
21
src/rig.c
21
src/rig.c
|
@ -549,6 +549,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model)
|
|||
hamlib_port_t *rp, *pttp, *dcdp;
|
||||
struct rig_cache *cachep;
|
||||
int i;
|
||||
size_t needed;
|
||||
|
||||
if (rig_test_2038(NULL))
|
||||
{
|
||||
|
@ -598,7 +599,9 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model)
|
|||
* okay, we've found it. Allocate some memory and set it to zeros,
|
||||
* and especially the callbacks
|
||||
*/
|
||||
rig = calloc(1, sizeof(RIG));
|
||||
needed = sizeof(RIG);
|
||||
rig_debug(RIG_DEBUG_TRACE, "Requesting %zd bytes for rig_struct\n", needed);
|
||||
rig = calloc(1, needed);
|
||||
|
||||
if (rig == NULL)
|
||||
{
|
||||
|
@ -628,7 +631,16 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model)
|
|||
pttp = PTTPORT(rig);
|
||||
dcdp = DCDPORT(rig);
|
||||
|
||||
//TODO Ditto for cache
|
||||
// Allocate space for cached data
|
||||
needed = sizeof(struct rig_cache);
|
||||
rig_debug(RIG_DEBUG_TRACE, "Requesting %zd bytes for rig_cache\n", needed);
|
||||
CACHE(rig) = calloc(1, needed);
|
||||
if (!CACHE(rig))
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s:Cache calloc failed\n", __func__);
|
||||
free(rig); //TODO Replace with cleanup routine
|
||||
return NULL;
|
||||
}
|
||||
cachep = CACHE(rig);
|
||||
|
||||
rs->rig_model = caps->rig_model;
|
||||
|
@ -1875,6 +1887,11 @@ int HAMLIB_API rig_cleanup(RIG *rig)
|
|||
|
||||
//TODO Release and null any allocated data -
|
||||
// state, ports, cache, etc.
|
||||
if (CACHE(rig))
|
||||
{
|
||||
free(CACHE(rig));
|
||||
CACHE(rig) = NULL;
|
||||
}
|
||||
|
||||
free(rig);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue