| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4a9457f commit f2e6f6f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ## Contributors | |
| 14 | 14 | ||
| 15 | + - Alex Helms ([@alexhelms](https://github.com/alexhelms)) | ||
| 15 | 16 | - Alexandre Catarino([@AlexCatarino](https://github.com/AlexCatarino)) | |
| 16 | 17 | - Arvid JB ([@ArvidJB](https://github.com/ArvidJB)) | |
| 17 | 18 | - Benoît Hudson ([@benoithudson](https://github.com/benoithudson)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 10 | 10 | ### Added | |
| 11 | 11 | ||
| 12 | 12 | - Added automatic NuGet package generation in appveyor and local builds | |
| 13 | + - Added function that sets Py_NoSiteFlag to 1. | ||
| 13 | 14 | ||
| 14 | 15 | ### Changed | |
| 15 | 16 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -130,6 +130,16 @@ public static string Compiler | |||
| 130 | 130 | get { return Marshal.PtrToStringAnsi(Runtime.Py_GetCompiler()); } | |
| 131 | 131 | } | |
| 132 | 132 | ||
| 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 | + public static void SetNoSiteFlag() | ||
| 139 | + { | ||
| 140 | + Runtime.SetNoSiteFlag(); | ||
| 141 | + } | ||
| 142 | + | ||
| 133 | 143 | public static int RunSimpleString(string code) | |
| 134 | 144 | { | |
| 135 | 145 | return Runtime.PyRun_SimpleString(code); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -414,6 +414,8 @@ internal static int AtExit() | |||
| 414 | 414 | internal static IntPtr PyNoneType; | |
| 415 | 415 | internal static IntPtr PyTypeType; | |
| 416 | 416 | ||
| 417 | + internal static IntPtr Py_NoSiteFlag; | ||
| 418 | + | ||
| 417 | 419 | #if PYTHON3 | |
| 418 | 420 | internal static IntPtr PyBytesType; | |
| 419 | 421 | #endif | |
@@ -1884,5 +1886,29 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size) | |||
| 1884 | 1886 | ||
| 1885 | 1887 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1886 | 1888 | internal static extern int Py_MakePendingCalls(); | |
| 1889 | + | ||
| 1890 | + internal static void 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 | + } | ||
| 1887 | 1913 | } | |
| 1888 | 1914 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments