Wrap code in #if defined(_WIN32)

This commit is contained in:
Guilherme Leobas
2025-10-16 20:54:22 -03:00
parent 8b302de0c5
commit d00fa92127
3 changed files with 11 additions and 6 deletions

View File

@ -46,7 +46,8 @@ extern "C" {
#elif IS_PYTHON_3_14_PLUS && defined(_WIN32) #elif IS_PYTHON_3_14_PLUS && defined(_WIN32)
#define F_CODE(x) ((PyCodeObject*)Torch_PyStackRef_AsPyObjectBorrow(&x->f_executable)) #define F_CODE(x) \
((PyCodeObject*)Torch_PyStackRef_AsPyObjectBorrow(&x->f_executable))
#define PREV_INSTR(x) (x)->instr_ptr #define PREV_INSTR(x) (x)->instr_ptr
#else #else

View File

@ -6,6 +6,8 @@
// initializers that are not supported in older C++ standards, but is supported // initializers that are not supported in older C++ standards, but is supported
// in C. // in C.
#if defined(_WIN32)
#define Py_BUILD_CORE #define Py_BUILD_CORE
#include <Python.h> #include <Python.h>
#include <internal/pycore_stackref.h> #include <internal/pycore_stackref.h>
@ -16,4 +18,6 @@
PyObject* Torch_PyStackRef_AsPyObjectBorrow(void* stackref) { PyObject* Torch_PyStackRef_AsPyObjectBorrow(void* stackref) {
_PyStackRef *sr = (_PyStackRef*)stackref; _PyStackRef *sr = (_PyStackRef*)stackref;
return PyStackRef_AsPyObjectBorrow(*sr); return PyStackRef_AsPyObjectBorrow(*sr);
} }
#endif

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#ifdef _WIN32 #if defined(_WIN32)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif // __cplusplus #endif
// Use a void* to avoid exposing the internal _PyStackRef union on this // Use a void* to avoid exposing the internal _PyStackRef union on this
// translation unit // translation unit
@ -12,6 +12,6 @@ PyObject* Torch_PyStackRef_AsPyObjectBorrow(void* stackref);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif // #ifdef __cplusplus #endif
#endif // #ifdef _WIN32 #endif