Skip to content

Abstract FirmataParser memory allocation scheme #332

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

Merged
merged 1 commit into from
Nov 21, 2016

Conversation

zfields
Copy link
Contributor

@zfields zfields commented Nov 16, 2016

This is ready for testing. I haven't had any opportunity to test this between hardware, but it does pass the test suite.

I wanted to share what I'm working on, so I could get feedback. I think it resolves the memory allocation concerns @soundanalogous pointed out in issue #328, and it can also handle my desire to utilize realloc().

I will report back once I've had an opportunity to test.
[EDIT] I have confirmed it works with Windows Remote Arduino.
[EDIT] I have confirmed it works as expected on Linux.

@zfields zfields force-pushed the memory branch 8 times, most recently from 3bd356d to 12b63ec Compare November 18, 2016 05:24
@zfields zfields changed the title DO NOT PULL - Abstract FirmataParser memory allocation scheme Abstract FirmataParser memory allocation scheme Nov 18, 2016
@soundanalogous
Copy link
Member

I think we definitely need unit tests for the Parser to ensure all expected cases are covered. The test suit should also ensure there are no memory leaks.

@zfields
Copy link
Contributor Author

zfields commented Nov 20, 2016

This pull request relieves FirmataParser of the ownership of buffer. As a result, the parser can not cause a memory leak.
I haven't changed the parsing logic, only the buffering logic.

Currently, I am in the middle of my prototype, and I don't have time to write any test. I was hoping to be able to complete my prototype without forking your repo. If we can run this through your board tests this weekend and pull it in, I won't send you another change to the parser without first writing some tests.

@soundanalogous
Copy link
Member

Ok I will run it through my board tests tomorrow.

@soundanalogous
Copy link
Member

I get a compiler warning when compiling for the following boards (some compilers are more picky than others):

  • Arduino 101
  • Teensy 2.0/LC/3.1/3.2/3.5/3.6
/Users/soundanalogous/Google Drive/Arduino/libraries/Firmata/src/FirmataParser.cpp: In member function ‘bool FirmataParser::bufferDataAtPosition(uint8_t, size_t)’:
/Users/soundanalogous/Google Drive/Arduino/libraries/Firmata/src/FirmataParser.cpp:302:8: warning: unused variable ‘writeError’ [-Wunused-variable]
   bool writeError = false;

@soundanalogous
Copy link
Member

I get a compiler error when compiling for an Arduino Uno, Mega and Teensy 2.0 (all AVR boards) in Arduino 1.0.6:

In file included from StandardFirmata.ino:28:
/Applications/arduino-1.0.6/Arduino.app/Contents/Resources/Java/libraries/Firmata/Firmata.h:102: error: 'FirmataClass::parserBuffer' cannot appear in a constant-expression
/Applications/arduino-1.0.6/Arduino.app/Contents/Resources/Java/libraries/Firmata/Firmata.h:102: error: ISO C++ forbids initialization of member 'parser'
/Applications/arduino-1.0.6/Arduino.app/Contents/Resources/Java/libraries/Firmata/Firmata.h:102: error: making 'parser' static
/Applications/arduino-1.0.6/Arduino.app/Contents/Resources/Java/libraries/Firmata/Firmata.h:102: error: invalid in-class initialization of static data member of non-integral type 'FirmataParser'

@soundanalogous
Copy link
Member

Other than the above mentioned compiler error and compiler warning, I don't see any issues when running on hardware.

@zfields
Copy link
Contributor Author

zfields commented Nov 21, 2016

@soundanalogous I just got home, and I'll have those cleared up in a moment.

@zfields
Copy link
Contributor Author

zfields commented Nov 21, 2016

@soundanalogous Okay it should be all clear now. I have confirmed the update by talking from Arduino to Linux using the same exact code! 😄

@soundanalogous
Copy link
Member

Looks good. All tests are passing. Thanks again!

@soundanalogous soundanalogous merged commit 0eb25f2 into firmata:master Nov 21, 2016
@zfields zfields deleted the memory branch February 24, 2017 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants