This repository was archived by the owner on Feb 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPy.cpp
More file actions
109 lines (93 loc) · 2.42 KB
/
Copy pathPy.cpp
File metadata and controls
109 lines (93 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "Py.h"
#include <iostream>
namespace Py {
namespace {
HANDLE pyModuleHandle;
template<typename F>
F GetPyFunc(const char* name) {
return (F)GetProcAddress(
(HMODULE)pyModuleHandle,
name);
}
}
REFProc IncRef;
REFProc DecRef;
namespace String {
FromStringProc FromString;
AsStringProc AsString;
}
namespace Import {
ImportProc Import;
}
namespace Object {
GetAttrStringProc GetAttrString;
CallObjectProc CallObject;
TypeProc Type;
IsInstanceProc IsInstance;
TypeCheckProc TypeCheck;
StrProc Str;
}
namespace GIL {
EnsureProc Ensure;
ReleaseProc Release;
}
namespace Tuple {
NewProc New;
SetItemProc SetItem;
}
namespace Dict {
CheckProc Check;
GetItemStringProc GetItemString;
NewProc New;
}
namespace List {
SizeProc Size;
GetItemProc GetItem;
}
bool init() {
if (!(pyModuleHandle = GetModuleHandleA("python27.dll"))) {
return false;
}
IncRef =
GetPyFunc<REFProc>("Py_IncRef");
DecRef =
GetPyFunc<REFProc>("Py_DecRef");
String::FromString =
GetPyFunc<String::FromStringProc>("PyString_FromString");
String::AsString =
GetPyFunc<String::AsStringProc>("PyString_AsString");
Import::Import =
GetPyFunc<Import::ImportProc>("PyImport_Import");
Tuple::New =
GetPyFunc<Tuple::NewProc>("PyTuple_New");
Tuple::SetItem =
GetPyFunc<Tuple::SetItemProc>("PyTuple_SetItem");
Object::GetAttrString =
GetPyFunc<Object::GetAttrStringProc>("PyObject_GetAttrString");
Object::Type =
GetPyFunc<Object::TypeProc>("PyObject_Type");
Object::CallObject =
GetPyFunc<Object::CallObjectProc>("PyObject_CallObject");
Object::IsInstance =
GetPyFunc<Object::IsInstanceProc>("PyObject_IsInstance");
Object::TypeCheck =
GetPyFunc<Object::TypeCheckProc>("PyObject_TypeCheck");
Object::Str =
GetPyFunc<Object::StrProc>("PyObject_Str");
GIL::Ensure =
GetPyFunc<GIL::EnsureProc>("PyGILState_Ensure");
GIL::Release =
GetPyFunc<GIL::ReleaseProc>("PyGILState_Release");
Dict::Check =
GetPyFunc<Dict::CheckProc>("PyDict_Check");
Dict::GetItemString =
GetPyFunc<Dict::GetItemStringProc>("PyDict_GetItemString");
Dict::New =
GetPyFunc<Dict::NewProc>("PyDict_New");
List::Size =
GetPyFunc<List::SizeProc>("PyList_Size");
List::GetItem =
GetPyFunc<List::GetItemProc>("PyList_GetItem");
return true;
}
}