Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5062377

Browse files
committed
Changes to the monoclr build so it builds for python 3.
1 parent6eb59ec commit5062377

File tree

4 files changed

+170
-24
lines changed

4 files changed

+170
-24
lines changed

‎setup.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ def build_extension(self, ext):
115115
ifCONFIG=="Debug":
116116
defines.extend(["DEBUG","TRACE"])
117117

118+
ifsys.platform!="win32"andDEVTOOLS=="Mono":
119+
defines.append("MONO_LINUX")
120+
121+
ifhasattr(sys,"abiflags"):
122+
if"d"insys.abiflags:
123+
defines.append("PYTHON_WITH_PYDEBUG")
124+
if"m"insys.abiflags:
125+
defines.append("PYTHON_WITH_PYMALLOC")
126+
if"u"insys.abiflags:
127+
defines.append("PYTHON_WITH_WIDE_UNICODE")
128+
118129
cmd= [
119130
_xbuild,
120131
"pythonnet.sln",

‎src/monoclr/clrmod.c‎

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,50 @@ PyDoc_STRVAR(clr_module_doc,
2525
staticPyNet_Args*pn_args;
2626
char**environ=NULL;
2727

28+
#ifPY_MAJOR_VERSION >=3
29+
staticstructPyModuleDefclrdef= {
30+
PyModuleDef_HEAD_INIT,
31+
"clr",/* m_name */
32+
clr_module_doc,/* m_doc */
33+
-1,/* m_size */
34+
clr_methods,/* m_methods */
35+
NULL,/* m_reload */
36+
NULL,/* m_traverse */
37+
NULL,/* m_clear */
38+
NULL,/* m_free */
39+
};
40+
#endif
41+
42+
staticPyObject*_initclr() {
43+
PyObject*m;
44+
45+
/* Create the module and add the functions */
46+
#ifPY_MAJOR_VERSION >=3
47+
m=PyModule_Create(&clrdef);
48+
#else
49+
m=Py_InitModule3("clr",clr_methods,clr_module_doc);
50+
#endif
51+
if (m==NULL)
52+
return;
53+
PyModule_AddObject(m,"facade",Py_True);
54+
Py_INCREF(Py_True);
55+
56+
pn_args=PyNet_Init(1);
57+
if (pn_args->error) {
58+
returnNULL;
59+
}
60+
returnm;
61+
}
62+
63+
#ifPY_MAJOR_VERSION >=3
64+
PyMODINIT_FUNC
65+
PyInit_clr(void) {
66+
return_initclr();
67+
}
68+
#else
2869
PyMODINIT_FUNC
2970
initclr(void)
30-
{
31-
PyObject*m;
32-
33-
/* Create the module and add the functions */
34-
m=Py_InitModule3("clr",clr_methods,clr_module_doc);
35-
if (m==NULL)
36-
return;
37-
PyModule_AddObject(m,"facade",Py_True);
38-
Py_INCREF(Py_True);
39-
40-
pn_args=PyNet_Init(1);
41-
if (pn_args->error) {
42-
return;
43-
}
71+
_initclr();
4472
}
73+
#endif
4574

‎src/monoclr/python.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,29 @@
1616

1717
#include<Python.h>
1818

19+
#if (PY_MAJOR_VERSION>2)
20+
#include<wchar.h>
21+
#endif
22+
1923
intmain(intargc,char**argv) {
24+
#if (PY_MAJOR_VERSION>2)
25+
inti,result;
26+
size_tlen;
27+
wchar_t**wargv= (wchar_t**)malloc(sizeof(wchar_t*)*argc);
28+
for (i=0;i<argc;++i) {
29+
len=strlen(argv[i]);
30+
wargv[i]= (wchar_t*)malloc(sizeof(wchar_t)*(len+1));
31+
if (len==mbsrtowcs(wargv[i], (constchar**)&argv[i],len,NULL))
32+
wargv[i][len]=0;
33+
}
34+
result=Py_Main(argc,wargv);
35+
for (i=0;i<argc;++i) {
36+
free((void*)wargv[i]);
37+
}
38+
free((void*)wargv);
39+
returnresult;
40+
#else
2041
returnPy_Main(argc,argv);
42+
#endif
2143
}
2244

‎src/runtime/runtime.cs‎

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,50 @@ namespace Python.Runtime {
2525

2626
staticclassNativeMethods
2727
{
28+
#ifMONO_LINUX
29+
staticpublicIntPtrLoadLibrary(stringfileName){
30+
returndlopen(fileName,RTLD_NOW|RTLD_SHARED);
31+
}
32+
33+
staticpublicvoidFreeLibrary(IntPtrhandle){
34+
dlclose(handle);
35+
}
36+
37+
staticpublicIntPtrGetProcAddress(IntPtrdllHandle,stringname){
38+
// clear previous errors if any
39+
dlerror();
40+
varres=dlsym(dllHandle,name);
41+
varerrPtr=dlerror();
42+
if(errPtr!=IntPtr.Zero){
43+
thrownewException("dlsym: "+Marshal.PtrToStringAnsi(errPtr));
44+
}
45+
returnres;
46+
}
47+
48+
constintRTLD_NOW=2;
49+
constintRTLD_SHARED=20;
50+
51+
[DllImport("libdl.so")]
52+
privatestaticexternIntPtrdlopen(StringfileName,intflags);
53+
54+
[DllImport("libdl.so")]
55+
privatestaticexternIntPtrdlsym(IntPtrhandle,Stringsymbol);
56+
57+
[DllImport("libdl.so")]
58+
privatestaticexternintdlclose(IntPtrhandle);
59+
60+
[DllImport("libdl.so")]
61+
privatestaticexternIntPtrdlerror();
62+
#else
2863
[DllImport("kernel32.dll")]
2964
publicstaticexternIntPtrLoadLibrary(stringdllToLoad);
3065

3166
[DllImport("kernel32.dll")]
3267
publicstaticexternIntPtrGetProcAddress(IntPtrhModule,stringprocedureName);
3368

34-
3569
[DllImport("kernel32.dll")]
3670
publicstaticexternboolFreeLibrary(IntPtrhModule);
71+
#endif
3772
}
3873

3974
publicclassRuntime{
@@ -54,49 +89,96 @@ public class Runtime {
5489
#endif
5590

5691
#if(PYTHON23)
57-
publicconststringdll="python23";
5892
publicconststringpyversion="2.3";
5993
publicconstintpyversionnumber=23;
6094
#endif
6195
#if(PYTHON24)
62-
publicconststringdll="python24";
6396
publicconststringpyversion="2.4";
6497
publicconstintpyversionnumber=24;
6598
#endif
6699
#if(PYTHON25)
67-
publicconststringdll="python25";
68100
publicconststringpyversion="2.5";
69101
publicconstintpyversionnumber=25;
70102
#endif
71103
#if(PYTHON26)
72-
publicconststringdll="python26";
73104
publicconststringpyversion="2.6";
74105
publicconstintpyversionnumber=26;
75106
#endif
76107
#if(PYTHON27)
77-
publicconststringdll="python27";
78108
publicconststringpyversion="2.7";
79109
publicconstintpyversionnumber=27;
80110
#endif
81111
#if(PYTHON32)
82-
publicconststringdll="python32";
83112
publicconststringpyversion="3.2";
84113
publicconstintpyversionnumber=32;
85114
#endif
86115
#if(PYTHON33)
87-
publicconststringdll="python33";
88116
publicconststringpyversion="3.3";
89117
publicconstintpyversionnumber=33;
90118
#endif
91119
#if(PYTHON34)
92-
publicconststringdll="python34";
93120
publicconststringpyversion="3.4";
94121
publicconstintpyversionnumber=34;
95122
#endif
96123
#if!(PYTHON23||PYTHON24||PYTHON25||PYTHON26||PYTHON27||PYTHON32||PYTHON33||PYTHON34)
97124
#error You must define one of PYTHON23 to PYTHON34
98125
#endif
99126

127+
#if(PYTHON23)
128+
internalconststringdllBase="python23";
129+
#endif
130+
#if(PYTHON24)
131+
internalconststringdllBase="python24";
132+
#endif
133+
#if(PYTHON25)
134+
internalconststringdllBase="python25";
135+
#endif
136+
#if(PYTHON26)
137+
internalconststringdllBase="python26";
138+
#endif
139+
#if(PYTHON27)
140+
internalconststringdllBase="python27";
141+
#endif
142+
#if(MONO_LINUX)
143+
#if(PYTHON32)
144+
internalconststringdllBase="python3.2";
145+
#endif
146+
#if(PYTHON33)
147+
internalconststringdllBase="python3.3";
148+
#endif
149+
#if(PYTHON34)
150+
internalconststringdllBase="python3.4";
151+
#endif
152+
#else
153+
#if(PYTHON32)
154+
internalconststringdllBase="python32";
155+
#endif
156+
#if(PYTHON33)
157+
internalconststringdllBase="python33";
158+
#endif
159+
#if(PYTHON34)
160+
internalconststringdllBase="python34";
161+
#endif
162+
#endif
163+
164+
#if(PYTHON_WITH_PYDEBUG)
165+
internalconststringdllWithPyDebug="d";
166+
#else
167+
internalconststringdllWithPyDebug="";
168+
#endif
169+
#if(PYTHON_WITH_PYMALLOC)
170+
internalconststringdllWithPyMalloc="m";
171+
#else
172+
internalconststringdllWithPyMalloc="";
173+
#endif
174+
#if(PYTHON_WITH_WIDE_UNICODE)
175+
internalconststringdllWithWideUnicode="u";
176+
#else
177+
internalconststringdllWithWideUnicode="";
178+
#endif
179+
180+
publicconststringdll=dllBase+dllWithPyDebug+dllWithPyMalloc+dllWithWideUnicode;
181+
100182
// set to true when python is finalizing
101183
internalstaticObjectIsFinalizingLock=newObject();
102184
internalstaticboolIsFinalizing=false;
@@ -108,7 +190,7 @@ public class Runtime {
108190
/// Intitialize the runtime...
109191
/// </summary>
110192
internalstaticvoidInitialize(){
111-
193+
112194
is32bit=IntPtr.Size==4;
113195

114196
if(0==Runtime.Py_IsInitialized())
@@ -211,8 +293,10 @@ internal static void Initialize() {
211293
#if(PYTHON32||PYTHON33||PYTHON34)
212294
IntPtrdll=NativeMethods.LoadLibrary(Runtime.dll);
213295
_PyObject_NextNotImplemented=NativeMethods.GetProcAddress(dll,"_PyObject_NextNotImplemented");
296+
#if!MONO_LINUX
214297
NativeMethods.FreeLibrary(dll);
215298
#endif
299+
#endif
216300

217301

218302
// Determine whether we need to wrap exceptions for versions of

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp