Skip to content

Commit

Permalink
c / win: get rid of psutil_load_globals() and move it into psutil_set…
Browse files Browse the repository at this point in the history
…up() fun

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
  • Loading branch information
giampaolo committed Nov 4, 2021
1 parent 0e15b48 commit 8fa1746
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
47 changes: 19 additions & 28 deletions psutil/_psutil_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ AccessDenied(const char *syscall) {
}


// ====================================================================
// --- Global utils
// ====================================================================


// Enable or disable PSUTIL_DEBUG messages.
PyObject *
psutil_set_debug(PyObject *self, PyObject *args) {
Expand All @@ -156,17 +151,6 @@ psutil_set_debug(PyObject *self, PyObject *args) {
}


/*
* Called on module import on all platforms.
*/
int
psutil_setup(void) {
if (getenv("PSUTIL_DEBUG") != NULL)
PSUTIL_DEBUG = 1;
return 0;
}


// ============================================================================
// Utility functions (BSD)
// ============================================================================
Expand Down Expand Up @@ -369,18 +353,6 @@ psutil_set_winver() {
}


int
psutil_load_globals() {
if (psutil_loadlibs() != 0)
return 1;
if (psutil_set_winver() != 0)
return 1;
GetSystemInfo(&PSUTIL_SYSTEM_INFO);
InitializeCriticalSection(&PSUTIL_CRITICAL_SECTION);
return 0;
}


/*
* Convert the hi and lo parts of a FILETIME structure or a LARGE_INTEGER
* to a UNIX time.
Expand Down Expand Up @@ -416,3 +388,22 @@ psutil_LargeIntegerToUnixTime(LARGE_INTEGER li) {
(ULONGLONG)li.LowPart);
}
#endif // PSUTIL_WINDOWS


// Called on module import on all platforms.
int
psutil_setup(void) {
if (getenv("PSUTIL_DEBUG") != NULL)
PSUTIL_DEBUG = 1;

#ifdef PSUTIL_WINDOWS
if (psutil_loadlibs() != 0)
return 1;
if (psutil_set_winver() != 0)
return 1;
GetSystemInfo(&PSUTIL_SYSTEM_INFO);
InitializeCriticalSection(&PSUTIL_CRITICAL_SECTION);
#endif

return 0;
}
1 change: 0 additions & 1 deletion psutil/_psutil_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ void convert_kvm_err(const char *syscall, char *errbuf);
#define AF_INET6 23
#endif

int psutil_load_globals();
PVOID psutil_GetProcAddress(LPCSTR libname, LPCSTR procname);
PVOID psutil_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname);
PVOID psutil_SetFromNTStatusErr(NTSTATUS Status, const char *syscall);
Expand Down
2 changes: 0 additions & 2 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,8 +1736,6 @@ void init_psutil_windows(void)

if (psutil_setup() != 0)
INITERROR;
if (psutil_load_globals() != 0)
INITERROR;
if (psutil_set_se_debug() != 0)
INITERROR;

Expand Down

0 comments on commit 8fa1746

Please sign in to comment.