File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed
Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,15 @@ target_link_libraries(matplot PUBLIC nodesoup cimg)
8989# https://cmake.org/cmake/help/v3.14/manual/cmake-compile-features.7.html#requiring-language-standards
9090target_compile_features (matplot PUBLIC cxx_std_17)
9191
92+ include (CheckSymbolExists)
93+
94+ # Some hack to not depend on FILE* internals
95+ # https://github.com/alandefreitas/matplotplusplus/issues/4
96+ check_symbol_exists(__fbufsize "stdio_ext.h" HAVE_FBUFSIZE)
97+ if (HAVE_FBUFSIZE)
98+ target_compile_definitions (matplot PRIVATE MATPLOT_HAS_FBUFSIZE)
99+ endif ()
100+
92101if (BUILD_FOR_DOCUMENTATION_IMAGES)
93102 message ("Building matplot for documentation images. wait() commands will be ignored. ~figure will save the files." )
94103 target_compile_definitions (matplot PUBLIC MATPLOT_BUILD_FOR_DOCUMENTATION_IMAGES)
Original file line number Diff line number Diff line change 1010#include < matplot/util/popen.h>
1111#include < matplot/util/common.h>
1212
13+ #ifdef MATPLOT_HAS_FBUFSIZE
14+
15+ #include < stdio_ext.h>
16+
17+ static size_t gnuplot_pipe_capacity (FILE *f) {
18+ size_t sz = __fbufsize (f);
19+ return sz != 0 ? sz : matplot::backend::gnuplot::pipe_capacity_worst_case;
20+ }
21+
22+ #else
23+
24+ static size_t gnuplot_pipe_capacity (FILE *) {
25+ return matplot::backend::gnuplot::pipe_capacity_worst_case;
26+ }
27+
28+ #endif // MATPLOT_HAS_FBUFSIZE
29+
1330namespace matplot ::backend {
1431 bool gnuplot::consumes_gnuplot_commands () {
1532 return true ;
@@ -220,7 +237,7 @@ namespace matplot::backend {
220237 if (!pipe_) {
221238 return ;
222239 }
223- size_t pipe_capacity = (pipe_-> _bf . _base != nullptr ) ? pipe_-> _bf . _size : pipe_capacity_worst_case ;
240+ size_t pipe_capacity = gnuplot_pipe_capacity (pipe_) ;
224241 if (command.size () + bytes_in_pipe_ > pipe_capacity) {
225242 flush_commands ();
226243 bytes_in_pipe_ = 0 ;
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ namespace matplot::backend {
7777 static constexpr bool trace_commands = false ;
7878#endif
7979
80- static constexpr size_t pipe_capacity_worst_case = 4096 ;
80+ static constexpr size_t pipe_capacity_worst_case = BUFSIZ ;
8181 // / File formats for figures and properties of terminals
8282 static constexpr std::array<std::pair<std::string_view,std::string_view>,33 > extension_terminal () {
8383 return std::array<std::pair<std::string_view,std::string_view>,33 >
You can’t perform that action at this time.
0 commit comments