-
Notifications
You must be signed in to change notification settings - Fork 749
Add pysetargv #347
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pysetargv #347
Conversation
This replaces #301? |
src/runtime/runtime.cs
Outdated
@@ -2027,11 +2027,26 @@ internal unsafe static extern IntPtr | |||
internal unsafe static extern IntPtr | |||
PyImport_GetModuleDict(); | |||
|
|||
|
|||
#if !(PYTHON26 || PYTHON27) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be #if PYTHON3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll change it.
Yes, it's an alternative using directly the Python API function. |
using (new PythonEngine()) | ||
using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv"))) | ||
{ | ||
Assert.That(argv.Length() != 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first need to check that it is not null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? If it is null
, this will fail with a NullReferenceException
, perfectly fine. This PR is supposed to ensure that sys.argv
is always initialised.
src/runtime/Python.Runtime.csproj
Outdated
@@ -92,6 +92,7 @@ | |||
<Optimize>false</Optimize> | |||
<DebugType>full</DebugType> | |||
<PlatformTarget>x64</PlatformTarget> | |||
<DefineConstants>TRACE;DEBUG;PYTHON3;PYTHON35;UCS2</DefineConstants> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this gets overwritten by setup.py or specific needs of the user, so no need to update this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He probably added that during his development and forgot to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated #346 to include configuration for PY3 development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, exactly that, I'll remove this line.
I'm OK with merging this version as long as comments are addressed |
Checks whether an error occurred and in case it has throws a PythonException.
In particular in Py.Import.
@filmor rebased your work here |
174e1fa
to
3785c40
Compare
Codecov Report@@ Coverage Diff @@
## master #347 +/- ##
==========================================
- Coverage 61.45% 61.37% -0.08%
==========================================
Files 61 61
Lines 5336 5369 +33
Branches 900 896 -4
==========================================
+ Hits 3279 3295 +16
- Misses 1819 1853 +34
+ Partials 238 221 -17
Continue to review full report at Codecov.
|
@filmor the coverage on pythonengine.cs reduced |
It's probably the refactoring he did. The coverage needs some fine tuning, its definetly not as robust as python's coverage engine. |
src/runtime/interop.cs
Outdated
@@ -227,7 +227,7 @@ static ModuleDefOffset() | |||
byte[] ascii = Encoding.ASCII.GetBytes(modulename); | |||
int size = name + ascii.Length + 1; | |||
IntPtr ptr = Marshal.AllocHGlobal(size); | |||
for (int i = 0; i <= m_free; i += IntPtr.Size) | |||
for (int i = 0; i < m_free; i += IntPtr.Size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where m_free is set?
|
||
namespace Python.Runtime | ||
{ | ||
/// <summary> | ||
/// This class provides the public interface of the Python runtime. | ||
/// </summary> | ||
public class PythonEngine | ||
public class PythonEngine : IDisposable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this now IDisposable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because that's easier to use correctly than Initialize
and Shutdown
.
{ | ||
throw new PythonException(); | ||
} | ||
Py.Throw(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not also check for IntPtr.Zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this function either returns null and sets an exception, or it returns a module.
{ | ||
Initialize(Enumerable.Empty<string>()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did not click submit review few weeks ago
What does this implement/fix? Explain your changes.
Implements an overload of
Initialize
and aPy.SetArgv
function that allow the user to issue aPySys_SetArgvEx
call. By default, this call is done onInitialize
with a list that contains a single empty string (['']
), using the arguments supplied to the .NET process if available.Does this close any currently open issues?
#299.
Any other comments?
Based on the
fix-shutdown
branch as otherwise I'm not able to run the unit-tests reliably..