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

apply amos interop changes from soft shutdown#1219

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

Closed
koubaa wants to merge9 commits intopythonnet:masterfromkoubaa:amos-interop-changes

Conversation

koubaa
Copy link
Contributor

Fixes#1218

Changes taken from@amos402 soft shutdown branch

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

@koubaakoubaa changed the titleapply amos changes from soft shutdownapply amos interop changes from soft shutdownSep 13, 2020

private static int BaseOffset(IntPtr type)
{
Debug.Assert(type != IntPtr.Zero);
int typeSize = Marshal.ReadInt32(type, TypeOffset.tp_basicsize);
Debug.Assert(typeSize > 0 && typeSize <= ExceptionOffset.Size());
Debug.Assert(typeSize > 0);
Copy link
Member

Choose a reason for hiding this comment

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

@amos402@koubaa
As far as I can see, this is not actually fixing or explaining anything. It just removes the assert, that caused the problem.

Copy link
Member

@lostmsulostmsuSep 13, 2020
edited
Loading

Choose a reason for hiding this comment

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

IMHO, the assert should stay. This PR does not address it, but probably solves the problem@koubaa has.

Copy link
Member

Choose a reason for hiding this comment

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

The checking oftypeSize <= ExceptionOffset.Size() is totally a wrong idea, there's no connection between them. Why an other object size whould relates to an exception object size.
You can simply make it lager than that size by

classA(B,C,D,E,F,G):pass

Copy link
Member

Choose a reason for hiding this comment

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

@amos402 if I remember correctly,BaseOffset is only used for reflections of .NET classes created by Python.NET. Right now there are only two kinds of them:System.Exception and everything derived from it, that end up deriving Python'sbuiltins.BaseException orbuiltins.Exception, and every other .NET type, which end up deriving frombuiltins.object. Within those two categories each of the types has identical structure, and the ones derived fromException just happen to be larger.

When Python class is inherited from a reflected .NET class via single inheritance, and has no extra low-level PyType stuff defined explicitly, I see no reason for its objects to be larger, than corresponding base class objects. Hence all such types should have either the same size as reflectedSystem.Object or as reflectedSystem.Exception.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@lostmsu@amos402 if the check needs to be removed, it can be done in a follow-on PR. I don't think this discussion should hold this PR.

Copy link
Member

Choose a reason for hiding this comment

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

@koubaa I am fine with this PR without the check removal.

@codecov-commenter
Copy link

codecov-commenter commentedSep 14, 2020
edited
Loading

Codecov Report

Merging#1219 intomaster willnot change coverage.
The diff coverage isn/a.

Impacted file tree graph

@@           Coverage Diff           @@##           master    #1219   +/-   ##=======================================  Coverage   86.25%   86.25%           =======================================  Files           1        1             Lines         291      291           =======================================  Hits          251      251             Misses         40       40
FlagCoverage Δ
#setup_linux64.94% <ø> (ø)
#setup_windows72.50% <ø> (ø)

Flags with carried forward coverage won't be shown.Click here to find out more.


Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updated44f1da...2db6fa0. Read thecomment docs.

@lostmsu
Copy link
Member

@amos402@koubaa the fix is still incomplete. It placesGCHandle past the last field ofPyType (or Python classtype), it never allocates space for it, hence it still writes to an offset it does not own.

For example, on Windows x64 Python 3.8 an instance of PyType is 880 bytes long. An instance ofCLR Metatype, the type of all reflected classes, is also 880 bytes long. After this fixclass Sub(System.Exception) invokesMetaType.tp_new, that has this line:

Marshal.WriteIntPtr(type,TypeOffset.magic(),gc);

Where it writes theGCHandle immediately past the last byte of the new type object (an instance ofCLR Metatype), becauseTypeOffset.members is also 880.

To fix this it might be sufficient to increasetp_basicsize ofCLR Metatype byIntPtr.Size to allocate space forGCHandle.

@amos402
Copy link
Member

amos402 commentedSep 24, 2020
edited
Loading

It allocated the space, you can checkPyType_GenericAlloc. It has an extra space sizeof(PyMemberDef), as long you only use the first pointer which is points to thename and not to use wearef to CLR types, it's fine. If you want to use more space roughly, you should skip the memory oftype, because the typeobject may check it.
If you want a more complete general solution, you can check thisamos402#5

@koubaakoubaa closed thisOct 10, 2020
@amos402amos402 mentioned this pull requestOct 22, 2020
4 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@filmorfilmorfilmor left review comments

@lostmsulostmsulostmsu requested changes

@amos402amos402amos402 left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Multiple assertion failures for Python classes derived from System.Exception in debug builds
5 participants
@koubaa@codecov-commenter@lostmsu@amos402@filmor

[8]ページ先頭

©2009-2025 Movatter.jp