wkschwartz / pigosat

Go (golang) bindings for Picosat, the satisfiability solver
Other
15 stars 4 forks source link

Close OutputFile #17

Closed wkschwartz closed 7 years ago

wkschwartz commented 8 years ago

If a client passes a non-nil OutputFile *os.File to the Pigosat constructor, the constructor opens a *C.FILE and leaves it open, passing it to Picosat. Since we create the *C.FILE in the constructor, we should close it in the destructor. This may require holding onto the *C.FILE in the Pigosat object (in a private data member), to be closed in Pigosat.delete. Make sure to set this data member to nil when delete is done with it.

We should test that closing the *C.FILE does not close the underlying *os.File. From what I can tell from the manpage for fclose, fclose(*FILE) only dissociates the particular instance of *FILE from the underlying file descriptor, so closing one *FILE doesn't close the descriptor for other open instances of that descriptor.

wkschwartz commented 7 years ago

Turns out calling c.fclose(outputFile) actually does close the underlying file descriptor. The up shot is that we cannot close the *C.FILE reference to OutputFile without closing the underlying file. It's better for the client to do this.