This function must be non-virtual to be called in a destructor.
| 92 | |
| 93 | // This function must be non-virtual to be called in a destructor. |
| 94 | int _sync() { |
| 95 | if (pbase() != pptr()) { // If buffer is not empty |
| 96 | gil_scoped_acquire tmp; |
| 97 | // This subtraction cannot be negative, so dropping the sign. |
| 98 | auto size = static_cast<size_t>(pptr() - pbase()); |
| 99 | size_t remainder = utf8_remainder(); |
| 100 | |
| 101 | if (size > remainder) { |
| 102 | str line(pbase(), size - remainder); |
| 103 | pywrite(std::move(line)); |
| 104 | pyflush(); |
| 105 | } |
| 106 | |
| 107 | // Copy the remainder at the end of the buffer to the beginning: |
| 108 | if (remainder > 0) { |
| 109 | std::memmove(pbase(), pptr() - remainder, remainder); |
| 110 | } |
| 111 | setp(pbase(), epptr()); |
| 112 | pbump(static_cast<int>(remainder)); |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int sync() override { return _sync(); } |
| 118 |