-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put static variables into context structure #1803
Conversation
... and convert static memory for strings returned by avr_prog_modes() into closed-circuit memory area in the context structure
I am not so sure if I understand the intention correctly, but this seems to be able to enable multiple context with libavrdude. In that case, it may be good to have a function of Reference from libusb.
|
Good shout, I wanted to work through the needed variables first and see which ones actually need initialisation. |
The latter returns a string in a static buffer that is overwritten by the next call. Unfortunately, this function was used more than once in arguments of the *same* msg_error(), which would have given a wrong error message. pins_to_strdup() returns a string to malloc'd space that needs freeing.
... as it was used wrongly and led to errors. Better to use pin_to_strdup()
No longer is the string returned in static space (which the next call overwrites); instead a mmt_strdup()'d string is returned that needs mmt_free()'ing.
As far as I am aware all static variables are now dealt with and moved to the context structure. Following simple test works:
With the exception of one variable ( It's quite possible that something went wrong when I migrated the variables, so a few functionality checks with hardware will be needed. @mcuee? @MCUdude? I suggest merging a batch of current PRs including this one early next week, so that @dl8dtl can progress his PR #1714 (as this PR is meant to make |
Okay, let me carry out some simple tests in the next few days. |
First test: the results are good.
|
Second test is also fine.
|
I have not tested the legacy Arduino optiboot bootloader for a while and it is okay. The failure is expected as the bootloader does not support EEPROM and chip erase.
|
@mcuee Thanks for testing. And I can contribute two programmers as well:
The latter being a |
PR looks good to me! Are there any specific programmers you want me to test with? |
@MCUdude Thanks! If you have, an Also bitbanging programmers ( |
Regarding Answering my own question: The avrdude code is full of other |
@ndim Great shout. I'll change
Maybe, we can replace |
I think this is a good idea (some of them is already BTW, changing |
No issues with linuxgpio.
|
This PR intends to move all static variables used in libavrdude functions into a single structure called
cx_t
; the idea is that there is one global context pointercx_t *cx
that libavrdude applications need to allocate memory for at the beginning of each instantiation. Ideally, one would hide the components of the context structure and write access function that are used in libavrdude functions. However, that ship has sailed given all the explicit PROGRAMMER, AVRPART and AVRMEM structures and the tons of existing direct->
access to their components. And more importantly, there are a lot of variables to convert (some 111), so writing 222 access functions, one each for get and set, wouldn't be much fun.@dl8dtl @MCUdude @mcuee Have a look at the commit for the first source file that has been treated that way,
avr.c
, and see what you think. Other than that: it's one down and 34 to do.