Skip to content

Fix iostream related issues #5047

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 5 commits into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,24 @@ void __throw_out_of_range(const char* str)
(void) str;
panic();
}

void __throw_bad_cast(void)
{
panic();
}

void __throw_ios_failure(const char* str)
{
(void) str;
panic();
}

void __throw_runtime_error(const char* str)
{
(void) str;
panic();
}
} // namespace std

// TODO: rebuild windows toolchain to make this unnecessary:
void* __dso_handle;
5 changes: 4 additions & 1 deletion cores/esp8266/libc_replacements.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,18 @@ int ICACHE_RAM_ATTR _read_r(struct _reent* unused, int file, char *ptr, int len)

int ICACHE_RAM_ATTR _write_r(struct _reent* r, int file, char *ptr, int len) {
(void) r;
int pos = len;
if (file == STDOUT_FILENO) {
while(len--) {
while(pos--) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this address a current issue or ongoing discussion? Maybe a link could be added in the PR description if that's the case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't seen this reported, probably because including iostream header caused compilation error, so no one got as far as using iostreams. Found when writing the test case.

ets_putc(*ptr);
++ptr;
}
}
return len;
}

int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) __attribute__((weak));

int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) {
(void) r;
if (file->_file == STDOUT_FILENO) {
Expand Down
34 changes: 34 additions & 0 deletions tests/device/test_iostream/test_iostream.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <ESP8266WiFi.h>
#include <BSTest.h>
#include <sstream>
#include <iostream>

BS_ENV_DECLARE();

void setup()
{
Serial.begin(115200);
BS_RUN(Serial);
}

TEST_CASE("can print to std::cout", "[iostream]")
{
std::stringstream test_stream("");
test_stream << "hello stream";

// empty the RX buffer, just in case
Serial.readString();

USC0(0) |= (1 << UCLBE); // enable loopback
std::cout << test_stream.str().c_str() << std::endl;
delay(100);
USC0(0) &= ~(1 << UCLBE); // disable loopback

String result = Serial.readStringUntil('\n');

Serial.printf("result: '%s'\n", result.c_str());

CHECK(result == test_stream.str().c_str());
}

void loop() { }