Feature/qqbar direct backend#413
Conversation
|
Something has gone badly wrong with the diff here. |
ff733f3 to
2971ad0
Compare
…add multi-type interoperability for fmpz/fmpq
| def str(self, Py_ssize_t digits=15): | ||
| """ | ||
| Converts the algebraic number to a decimal string representation by capturing C-level stdout. | ||
| """ | ||
| import os | ||
| import sys | ||
|
|
||
| cdef int stdout_fd = 1 | ||
| cdef int saved_stdout = os.dup(stdout_fd) | ||
|
|
||
| pipe_read, pipe_write = os.pipe() | ||
| os.dup2(pipe_write, stdout_fd) | ||
|
|
||
| try: | ||
| qqbar_printn(self.val, digits) | ||
| sys.stdout.flush() | ||
| finally: | ||
| os.close(pipe_write) | ||
| os.dup2(saved_stdout, stdout_fd) | ||
| os.close(saved_stdout) | ||
|
|
||
| cdef bytes captured = os.read(pipe_read, 4096) | ||
| os.close(pipe_read) | ||
|
|
||
| return captured.decode('utf-8').strip() |
There was a problem hiding this comment.
This is some weird AI stuff. There is no way that the os module should be involved here.
|
Hi Oscar, Now that the logic is solid, I've refactored this method to use standard, cross-platform io.StringIO buffers to intercept the stream output from qqbar_printn. It removes the os module hacking while keeping the implementation lightweight, which is what took me a little bit more time as I was planning to push this along with the next step of comparisons and polynomial extraction. Since you are already reviewing this, I've updated it now. |
No description provided.