Skip to content

Binary substitution of Python.Runtime.dll becomes safe. #456

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

Merged
merged 7 commits into from
Jul 10, 2017

Conversation

dmitriyse
Copy link
Contributor

What does this implement/fix? Explain your changes.

Public constants replaced to static readonly fields. Relaxed platform binding.
C# Compiler copies constants of assembly. This may cause to errors when
code was compiled with reference to one build of Python.Runtime.dll and then
after compile other build of Python.Runtime.dll is used.
...

Does this close any currently open issues?

No, but it work towards cross-platform nuget package #165
...

Any other comments?

...

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

Public constants replaced to static readonly fields. Relaxed platform binding.
@mention-bot
Copy link

@dmitriyse, thanks! @vmuriart, @hsoft, @brianlloyd, @tiran and @tonyroberts, please review this.

@codecov
Copy link

codecov bot commented Apr 25, 2017

Codecov Report

Merging #456 into master will decrease coverage by 0.03%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #456      +/-   ##
==========================================
- Coverage   77.16%   77.12%   -0.04%     
==========================================
  Files          65       65              
  Lines        5543     5547       +4     
  Branches      889      889              
==========================================
+ Hits         4277     4278       +1     
- Misses        978      981       +3     
  Partials      288      288
Flag Coverage Δ
#setup_linux 75.71% <ø> (ø) ⬆️
#setup_windows 76.47% <75%> (-0.04%) ⬇️
Impacted Files Coverage Δ
src/runtime/CustomMarshaler.cs 69.86% <100%> (ø) ⬆️
src/runtime/runtime.cs 90.58% <66.66%> (-1.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87eb102...77b49a2. Read the comment docs.

@filmor
Copy link
Member

filmor commented Apr 25, 2017

Why do you rename all of those fields?

@dmitriyse
Copy link
Contributor Author

Python.Runtime.dll consumers should not use public constants that have different values in different builds (platform, python version, etc). Otherwise when Python.Runtime.dll replaced in binary distribution, will have mismatch between constants values used in replaced Python.Runtime.dll and constant values copied to assemblies that referenced non replaced version of Python.Runtime.dll at compile time.

So we needs to replace constants to static read only fields.

Also we needs to honor source code backward compatibility and produce no any breaking change in an existing consumer source code.

So the only way to satisfy both "source code backward compatibility" and const->fields change is to rename constants and make them internal.

@den-run-ai den-run-ai closed this Apr 26, 2017
@den-run-ai den-run-ai reopened this Apr 26, 2017
@den-run-ai
Copy link
Contributor

closed and re-opened to check on Travis CI again

Copy link
Member

@filmor filmor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you should probably already add the static properties, if possible.


/// <summary>
/// EntryPoint to be used in DllImport to map to correct Unicode
/// methods prior to PEP393. Only used for PY27.
/// </summary>
private const string PyUnicodeEntryPoint = "PyUnicodeUCS4_";
#elif UCS2
public const int UCS = 2;
public const int _UCS = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only changed one branch of the #if here (same further down for _pyversion etc.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmor do you mean that only one if-branch is changed to from public to internal for _UCS? @dmitriyse can you please address this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this and some similar problems.

public const string pyversion = "3.7";
public const string pyver = "37";
public const string _pyversion = "3.7";
public const string _pyver = "37";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these _pyver* above should be internal @dmitriyse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will fix this soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@filmor
Copy link
Member

filmor commented Jul 3, 2017

@dmitriyse Are you going to continue on this branch? I fear we have to close it at some point as it will have deviated too far from master.

@dmitriyse
Copy link
Contributor Author

I will try to do update it tomorrow. Or we will close this branch.

@den-run-ai den-run-ai self-requested a review July 5, 2017 04:54
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.

public static readonly int UCS = _UCS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change these to properties. Allows us to make this fully dynamic in the future without breaking user code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will replace them to properties.
But I did not understand this:

fully dynamic in the future without breaking user code.

Probably I need some example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we ever want to have a single DLL for all platforms and Python versions, the values of pyversion or UCS will have to be evaluated at runtime on startup, that's what I meant.

// binary substitution of different Python.Runtime.dll builds in a target application.

public readonly string pyversion = _pyversion;
public readonly string pyver = _pyver;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two too.

@filmor filmor merged commit 25e66f0 into pythonnet:master Jul 10, 2017
testrunner123 pushed a commit to testrunner123/pythonnet that referenced this pull request Sep 22, 2017
* Binary substitution of Python.Runtime.Dll becomes safe.
* Public constants replaced to static readonly fields. Relaxed platform binding.
* Static readonly fields (related to build depented values) replaced by properties.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants