From c17ccf610b6829181baf2fc4d7310f72e410f0db Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sat, 10 Aug 2024 23:41:28 +0200 Subject: [PATCH] Add init_cx() This initializes the global context pointer, similar to what avrdude's main.c is doing at startup. --- src/libavrdude.i | 11 ++++++++++- src/python/adgui.py | 1 + src/python/swigtest.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libavrdude.i b/src/libavrdude.i index 75263255..98759371 100644 --- a/src/libavrdude.i +++ b/src/libavrdude.i @@ -47,11 +47,19 @@ int quell_progress; int ovsigck; const char *partdesc = ""; const char *pgmid = ""; +libavrdude_context *cx; static PyObject *msg_cb = NULL; static PyObject *progress_cb = NULL; static void swig_progress(int percent, double etime, const char *hdr, int finish); +#define mmt_malloc(n) cfg_malloc(__func__, n) + +void init_cx(void) { + cx = mmt_malloc(sizeof *cx); // Allocate and initialise context structure + (void) avr_ustimestamp(); // Base timestamps from program start +} + void set_msg_callback(PyObject *PyFunc) { if (PyFunc == Py_None) { if (msg_cb) @@ -257,6 +265,8 @@ typedef struct avrmem_alias AVRMEM_ALIAS; typedef struct programmer PROGRAMMER; typedef void pgm_initpgm(PROGRAMMER*); +void init_cx(void); + enum msglvl { MSG_EXT_ERROR = (-3), // OS-type error, no -v option, can be suppressed with -qqqqq MSG_ERROR = (-2), // Avrdude error, no -v option, can be suppressed with -qqqq @@ -652,7 +662,6 @@ AVRMEM_ALIAS * avr_find_memalias(const AVRPART *p, const AVRMEM *m_orig); } AVRPART * locate_part_by_signature(const LISTID parts, unsigned char *sig, int sigsize); AVRPART * locate_part_by_signature_pm(const LISTID parts, unsigned char *sig, int sigsize, int prog_modes); -const char *avr_prog_modes_str(int pm); PROGRAMMER *locate_programmer_set(const LISTID programmers, const char *id, const char **setid); PROGRAMMER *locate_programmer_starts_set(const LISTID programmers, const char *id, const char **setid, AVRPART *prt); diff --git a/src/python/adgui.py b/src/python/adgui.py index 6ef23377..2e4a449c 100755 --- a/src/python/adgui.py +++ b/src/python/adgui.py @@ -51,6 +51,7 @@ else: import swig_avrdude as ad def avrdude_init(): + ad.init_cx() ad.init_config() found = False diff --git a/src/python/swigtest.py b/src/python/swigtest.py index d0e9a082..2c3886b0 100644 --- a/src/python/swigtest.py +++ b/src/python/swigtest.py @@ -71,6 +71,7 @@ else: import swig_avrdude as ad +ad.init_cx() ad.init_config() found = False