Skip to content

Conversation

@TiborGY
Copy link
Contributor

@TiborGY TiborGY commented Oct 9, 2022

Description

Definitions of various IO system call macros are currently replicated and/or scattered across files. These macros were added to paper over differences between Windows and Linux/Mac.
This PR coalesces all of them into psio.h.

User API & Changelog headlines

None

Dev notes & details

  • SYSTEM_WRITE, SYSTEM_READ, SYSTEM_LSEEK, SYSTEM_OPEN, SYSTEM_CLOSE, SYSTEM_UNLINK, PSIO_OPEN_OLD_FLAGS, PSIO_OPEN_NEW_FLAGS and PERMISSION_MODE are now only defined in psio.h, which is already included by pretty much all PSIO-related files anyways.
  • Same goes for the Windows specific io.h include, and the non-Windows unistd.h.

Checklist

  • Tests run by the CI are passing

Status

  • Ready for review
  • Ready for merge

@TiborGY TiborGY marked this pull request as ready for review October 9, 2022 15:22
#include <cstdio>
#ifdef _MSC_VER
#include <io.h>
#define SYSTEM_LSEEK ::_lseek
Copy link
Member

Choose a reason for hiding this comment

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

Only possible trouble I see is here with _lseek vs _lseeki64. Docs say: _lseek returns the offset, in bytes, of the new position from the beginning of the file. _lseeki64 returns the offset in a 64-bit integer. Harmless?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eagle-eyed review! This is something I have not noticed until now.
volseek.cc used _lseeki64 on Windows, while toclen.cc used _lseek.
Re-drafting this until I have had time to ponder the docs and the impact on the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In volseek.cc the return value is never stored, only compared with -1, so 32/64 bit should not matter.
In toclen.cc, the return value is stored in an auto variable, which is then only compared with -1.
So I think it is harmless.

@loriab loriab added this to the Psi4 1.7 milestone Oct 10, 2022
@loriab loriab added libpsio For all issue involving LIBPSIO, I/O library. cleanup For issues where the goal is to make Psi4 a little cleaner. labels Oct 10, 2022
@TiborGY TiborGY marked this pull request as draft October 10, 2022 19:30
@TiborGY TiborGY marked this pull request as ready for review October 12, 2022 08:29
Copy link
Member

@loriab loriab left a comment

Choose a reason for hiding this comment

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

nice cleanup, thank you!

@loriab loriab merged commit 4886f7f into psi4:master Oct 12, 2022
@TiborGY TiborGY deleted the psio_syscall_macros_1 branch October 20, 2022 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup For issues where the goal is to make Psi4 a little cleaner. libpsio For all issue involving LIBPSIO, I/O library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants