Skip to content

Commit

Permalink
chore: use pythoncapi_compat (#2754)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte authored Dec 27, 2024
1 parent bcbd8a0 commit 4834272
Show file tree
Hide file tree
Showing 6 changed files with 3,786 additions and 8 deletions.
4 changes: 3 additions & 1 deletion source/bases/Win32GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include "pythoncapi_compat.h"

extern PyStatus InitializePython(int argc, wchar_t** argv);
extern int ExecuteScript(void);

Expand Down Expand Up @@ -116,7 +118,7 @@ static int HandleSystemExitException()
PyErr_Clear();
else {
value = code;
if (value == Py_None)
if (Py_IsNone(value))
Py_Exit(0);
}
if (PyLong_Check(value))
Expand Down
8 changes: 5 additions & 3 deletions source/bases/Win32Service.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <windows.h>
#include <winsvc.h>

#include "pythoncapi_compat.h"

extern PyStatus InitializePython(int argc, wchar_t** argv);
extern int ExecuteScript(void);
extern PyStatus get_program_name(wchar_t** ptr_str, wchar_t* argv0);
Expand Down Expand Up @@ -260,7 +262,7 @@ static int Service_SetupPython(udt_ServiceInfo* info)
Service_SetStatus(info, SERVICE_STOPPED);
return -1;
}
gInterpreterState = threadState->interp;
gInterpreterState = PyThreadState_GetInterpreter(threadState);
PyThreadState_Swap(threadState);

// running base script
Expand Down Expand Up @@ -294,15 +296,15 @@ static int Service_SetupPython(udt_ServiceInfo* info)
temp = PyObject_GetAttrString(module, CX_SERVICE_AUTO_START);
if (!temp)
PyErr_Clear();
else if (temp == Py_True)
else if (Py_IsTrue(temp))
info->startType = SERVICE_AUTO_START;

// determine if service should monitor session changes (optional)
info->sessionChanges = 0;
temp = PyObject_GetAttrString(module, CX_SERVICE_SESSION_CHANGES);
if (!temp)
PyErr_Clear();
else if (temp == Py_True)
else if (Py_IsTrue(temp))
info->sessionChanges = 1;

// import the module which implements the service
Expand Down
Loading

0 comments on commit 4834272

Please sign in to comment.