-
Notifications
You must be signed in to change notification settings - Fork 747
Optimize for Runtime.InitializePlatformData
#891
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
Comments
cpython3.7.1 |
I import platform for two pieces of info. Py_GetPlatform() gives the OS type. We should probably use that. I didn't see a C API for the architecture; do you know of one? |
Me too, it may also not provided by any c# runtimes. |
Architecture does this - worth replicating? def architecture(executable=sys.executable, bits='', linkage=''):
""" Queries the given executable (defaults to the Python interpreter
binary) for various architecture information.
Returns a tuple (bits, linkage) which contains information about
the bit architecture and the linkage format used for the
executable. Both values are returned as strings.
Values that cannot be determined are returned as given by the
parameter presets. If bits is given as '', the sizeof(pointer)
(or sizeof(long) on Python version < 1.5.2) is used as
indicator for the supported pointer size.
The function relies on the system's "file" command to do the
actual work. This is available on most if not all Unix
platforms. On some non-Unix platforms where the "file" command
does not exist and the executable is set to the Python interpreter
binary defaults from _default_architecture are used.
"""
# Use the sizeof(pointer) as default number of bits if nothing
# else is given as default.
if not bits:
import struct
size = struct.calcsize('P')
bits = str(size * 8) + 'bit'
# Get data from the 'file' system command
if executable:
fileout = _syscmd_file(executable, '')
else:
fileout = ''
if not fileout and \
executable == sys.executable:
# "file" command did not return anything; we'll try to provide
# some sensible defaults then...
if sys.platform in _default_architecture:
b, l = _default_architecture[sys.platform]
if b:
bits = b
if l:
linkage = l
return bits, linkage
if 'executable' not in fileout and 'shared object' not in fileout:
# Format not supported
return bits, linkage
# Bits
if '32-bit' in fileout:
bits = '32bit'
elif 'N32' in fileout:
# On Irix only
bits = 'n32bit'
elif '64-bit' in fileout:
bits = '64bit'
# Linkage
if 'ELF' in fileout:
linkage = 'ELF'
elif 'PE' in fileout:
# E.g. Windows uses this format
if 'Windows' in fileout:
linkage = 'WindowsPE'
else:
linkage = 'PE'
elif 'COFF' in fileout:
linkage = 'COFF'
elif 'MS-DOS' in fileout:
linkage = 'MSDOS'
else:
# XXX the A.OUT format also falls under this class...
pass
return bits, linkage |
See #897, if we drop support for .NET<4.7.1 we can use the respective .NET standard functions for this, which means we wouldn't even need to have Python loaded already to do the right thing. This would also be beneficial to @lostmsu's idea to use |
For Python3.8, this issue seems to be a blocker for embedding in dotnetcore on Linux. The
because the code in
The change in Python3.8 to start using the |
@Jeff17Robbins |
I'm assuming because this code in
I'm further assuming that since I'm also assuming that this lack of
But I don't know the history of the project, and don't know specifically why we need this I would appreciate any info anyone has as to the rationale for all this startup code, or a pointer to any work going on to simplify it, at least for the dotnet core 3.x case. |
The symbol should in python's ELF or .so, The loader code you specified can be remove, see #880 |
I apologize in advance for being a somewhat ignorant newbie wrt Linux. But the scenario I am testing, I am embedding C Python into a dotnet core 3 C# app using pythonnet. pythonnet uses
But since When I run And I assume that this expectation includes being loaded with the aforementioned Or why is pythonnet taking all this trouble to explicitly load [EDIT] @amos402 , why do you believe
I think this will break the embedding scenario on Linux dotnet core. Some code has to load
|
I've been reading more about this issue and found this bit of folklore
This led me to an official-looking Debian statement
I don't see how to support Pythonnet Embedding on Debian unless someone calls |
This issue is not restricted to Pythonnet, even regular C embedding of Python on certain Linux distributions face the same https://bugs.python.org/issue21536#msg340817
|
|
The implementation for
Runtime.InitializePlatformData
just have some limitations.The
platform.py
would importsubprocess
, but not all release binaries have it.Need a another genernal way to get the architecture type.
Originally posted by @amos402 in #887 (comment)
The text was updated successfully, but these errors were encountered: