MustangPeak Common Library(http://code.google.com/p/mustangpeakcommonlib/)包含以下代码,用于将方法转换为可在回调中使用的过程:
const
AsmPopEDX = $5A;
AsmMovEAX = $B8;
AsmPushEAX = $50;
AsmPushEDX = $52;
AsmJmpShort = $E9;
type
TStub = packed record
PopEDX: Byte;
MovEAX: Byte;
SelfPointer: Pointer;
PushEAX: Byte;
PushEDX: Byte;
JmpShort: Byte;
Displacement: Integer;
end;
{ ----------------------------------------------------------------------------- }
function CreateStub(ObjectPtr: Pointer; MethodPtr: Pointer): Pointer;
var
Stub: ^TStub;
begin
// Allocate memory for the stub
// 1/10/04 Support for 64 bit, executable code must be in virtual space
Stub := VirtualAlloc(nil, SizeOf(TStub), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
// Pop the …Run Code Online (Sandbox Code Playgroud) 在Windows 7中使用python 3.2我在IDLE中得到以下内容:
>>compile('pass', r'c:\temp\??\module1.py', 'exec')
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么编译语句尝试使用mbcs转换unicode文件名?我知道sys.getfilesystemencoding在Windows中返回'mbcs',但我认为在提供unicode文件名时不会使用它.
例如:
f = open(r'c:\temp\??\module1.py')
Run Code Online (Sandbox Code Playgroud)
作品.
要进行更完整的测试,请在utf8编码文件中保存以下内容,并使用标准python.exe 3.2版运行它
# -*- coding: utf8 -*-
fname = r'c:\temp\??\module1.py'
# I do have the a file named fname but you can comment out the following two lines
f = open(fname)
print('ok')
cmp = compile('pass', fname, 'exec')
print(cmp)
Run Code Online (Sandbox Code Playgroud)
输出:
ok
Traceback (most recent call last):
File "module8.py", line 6, in <module>
cmp = compile('pass', fname, 'exec')
UnicodeEncodeError: …Run Code Online (Sandbox Code Playgroud)