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
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commitf2e6f6f

Browse files
alexhelmsfilmor
authored andcommitted
Add function to set Py_NoSiteFlag global variable to 1 (pythonnet#971)
* Add function to set Py_NoSiteFlag global variable to 1.* Add myself to authors, update changelog.
1 parent4a9457f commitf2e6f6f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

‎AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
##Contributors
1414

15+
- Alex Helms ([@alexhelms](https://github.com/alexhelms))
1516
- Alexandre Catarino([@AlexCatarino](https://github.com/AlexCatarino))
1617
- Arvid JB ([@ArvidJB](https://github.com/ArvidJB))
1718
- Benoît Hudson ([@benoithudson](https://github.com/benoithudson))

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1010
###Added
1111

1212
- Added automatic NuGet package generation in appveyor and local builds
13+
- Added function that sets Py_NoSiteFlag to 1.
1314

1415
###Changed
1516

‎src/runtime/pythonengine.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ public static string Compiler
130130
get{returnMarshal.PtrToStringAnsi(Runtime.Py_GetCompiler());}
131131
}
132132

133+
/// <summary>
134+
/// Set the NoSiteFlag to disable loading the site module.
135+
/// Must be called before Initialize.
136+
/// https://docs.python.org/3/c-api/init.html#c.Py_NoSiteFlag
137+
/// </summary>
138+
publicstaticvoidSetNoSiteFlag()
139+
{
140+
Runtime.SetNoSiteFlag();
141+
}
142+
133143
publicstaticintRunSimpleString(stringcode)
134144
{
135145
returnRuntime.PyRun_SimpleString(code);

‎src/runtime/runtime.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ internal static int AtExit()
414414
internalstaticIntPtrPyNoneType;
415415
internalstaticIntPtrPyTypeType;
416416

417+
internalstaticIntPtrPy_NoSiteFlag;
418+
417419
#ifPYTHON3
418420
internalstaticIntPtrPyBytesType;
419421
#endif
@@ -1884,5 +1886,29 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
18841886

18851887
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
18861888
internalstaticexternint Py_MakePendingCalls();
1889+
1890+
internalstaticvoid SetNoSiteFlag()
1891+
{
1892+
var loader= LibraryLoader.Get(OperatingSystem);
1893+
1894+
IntPtr dllLocal;
1895+
if(_PythonDll!= "__Internal")
1896+
{
1897+
dllLocal= loader.Load(_PythonDll);
1898+
}
1899+
1900+
try
1901+
{
1902+
Py_NoSiteFlag= loader.GetFunction(dllLocal, "Py_NoSiteFlag");
1903+
Marshal.WriteInt32(Py_NoSiteFlag,1);
1904+
}
1905+
finally
1906+
{
1907+
if(dllLocal!= IntPtr.Zero)
1908+
{
1909+
loader.Free(dllLocal);
1910+
}
1911+
}
1912+
}
18871913
}
18881914
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp