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

Add function to set Py_NoSiteFlag global variable to 1#971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
filmor merged 4 commits intopythonnet:masterfromalexhelms:setnositeflag
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsAUTHORS.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@

## Contributors

- Alex Helms ([@alexhelms](https://github.com/alexhelms))
- Alexandre Catarino([@AlexCatarino](https://github.com/AlexCatarino))
- Arvid JB ([@ArvidJB](https://github.com/ArvidJB))
- Benoît Hudson ([@benoithudson](https://github.com/benoithudson))
Expand Down
1 change: 1 addition & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
### Added

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

### Changed

Expand Down
10 changes: 10 additions & 0 deletionssrc/runtime/pythonengine.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,6 +130,16 @@ public static string Compiler
get { return Marshal.PtrToStringAnsi(Runtime.Py_GetCompiler()); }
}

/// <summary>
/// Set the NoSiteFlag to disable loading the site module.
/// Must be called before Initialize.
/// https://docs.python.org/3/c-api/init.html#c.Py_NoSiteFlag
/// </summary>
public static void SetNoSiteFlag()
{
Runtime.SetNoSiteFlag();
}

public static int RunSimpleString(string code)
{
return Runtime.PyRun_SimpleString(code);
Expand Down
26 changes: 26 additions & 0 deletionssrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -414,6 +414,8 @@ internal static int AtExit()
internal static IntPtr PyNoneType;
internal static IntPtr PyTypeType;

internal static IntPtr Py_NoSiteFlag;

#if PYTHON3
internal static IntPtr PyBytesType;
#endif
Expand DownExpand Up@@ -1884,5 +1886,29 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int Py_MakePendingCalls();

internal static void SetNoSiteFlag()
{
var loader = LibraryLoader.Get(OperatingSystem);

IntPtr dllLocal;
if (_PythonDll != "__Internal")
{
dllLocal = loader.Load(_PythonDll);
}

try
{
Py_NoSiteFlag = loader.GetFunction(dllLocal, "Py_NoSiteFlag");
Marshal.WriteInt32(Py_NoSiteFlag, 1);
}
finally
{
if (dllLocal != IntPtr.Zero)
{
loader.Free(dllLocal);
}
}
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp