Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 787f061

Browse files
author
Barton Cline
committed
# Build using %windir%\Microsoft.NET\Framework\v4.0.30319\ilasm #
# Remove duplicate script (perhaps intended to build alternate clr versions???) # # Windows clr.pyc now header indicates clr version 4.0 # # PYTHON26 => PYTHON27 # # InitExt() now keeps pace with "CLR" deprecation warnings # # PythonException doesn't seem to pick up the TraceBack - Test for null TB in Dispose() # # Clean up formatting on Runtime.Decref() for clear picture of intent. #
1 parent 015502e commit 787f061

File tree

7 files changed

+75
-65
lines changed

7 files changed

+75
-65
lines changed

pythonnet/src/runtime/Python.Runtime.csproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
23
<PropertyGroup>
34
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
45
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -14,20 +15,20 @@
1415
<DebugType>full</DebugType>
1516
<Optimize>true</Optimize>
1617
<OutputPath>.\bin\Debug\</OutputPath>
17-
<DefineConstants>TRACE;DEBUG;PYTHON26,UCS2</DefineConstants>
18+
<DefineConstants>TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
1819
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1920
</PropertyGroup>
2021
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2122
<DebugType>pdbonly</DebugType>
2223
<Optimize>true</Optimize>
2324
<OutputPath>.\bin\Release\</OutputPath>
24-
<DefineConstants>TRACE;PYTHON26,UCS2</DefineConstants>
25+
<DefineConstants>TRACE;PYTHON27, UCS2</DefineConstants>
2526
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2627
</PropertyGroup>
2728
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'EmbeddingTest|AnyCPU' ">
2829
<DebugSymbols>true</DebugSymbols>
2930
<OutputPath>bin\EmbeddingTest\</OutputPath>
30-
<DefineConstants>TRACE;DEBUG;PYTHON26,UCS2</DefineConstants>
31+
<DefineConstants>TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
3132
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3233
<Optimize>true</Optimize>
3334
<DebugType>full</DebugType>
@@ -36,7 +37,7 @@
3637
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'UnitTests|AnyCPU' ">
3738
<DebugSymbols>true</DebugSymbols>
3839
<OutputPath>bin\UnitTests\</OutputPath>
39-
<DefineConstants>TRACE;DEBUG;PYTHON26,UCS2</DefineConstants>
40+
<DefineConstants>TRACE;DEBUG;PYTHON27,UCS2</DefineConstants>
4041
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4142
<Optimize>true</Optimize>
4243
<DebugType>full</DebugType>
@@ -149,6 +150,9 @@
149150
<None Include="x64\clrmodule-platform.il" />
150151
<None Include="x86\clrmodule-platform.il" />
151152
</ItemGroup>
153+
<ItemGroup>
154+
<Content Include="python-clear.ico" />
155+
</ItemGroup>
152156
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
153157
<ProjectExtensions>
154158
<VisualStudio AllowExistingFolder="true" />
@@ -161,4 +165,4 @@ copy "$(TargetDir)clr.pyd" "$(SolutionDir)"
161165
</PostBuildEvent>
162166
<PreBuildEvent>del "$(TargetDir)clr.pyd"</PreBuildEvent>
163167
</PropertyGroup>
164-
</Project>
168+
</Project>

pythonnet/src/runtime/buildclrmodule.bat

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,7 @@ exit /b 1
3030

3131
:BUILD_CLR_MODULE
3232
if not exist %INPUT_PATH% goto ERROR_MISSING_INPUT
33-
%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH%
34-
:: Call with buildclrmodule.bat <AnyCPU|x64> <INPUT_DIRECTORY> <OUTPUT_PATH>
35-
36-
@echo off
37-
38-
set TARGET_PLATFORM=%1
39-
set INPUT_DIRECTORY=%~2
40-
set INPUT_PATH="%INPUT_DIRECTORY%\clrmodule.il"
41-
set OUTPUT_PATH=%3
42-
43-
if %TARGET_PLATFORM%==AnyCPU goto SETUP32
44-
if %TARGET_PLATFORM%==x64 goto SETUP64
45-
goto ERROR_BAD_PLATFORM
46-
47-
:SETUP32
48-
set INCLUDE_PATH="%INPUT_DIRECTORY%\x86"
49-
goto BUILD_CLR_MODULE
33+
%windir%\Microsoft.NET\Framework\v4.0.30319\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH%
5034

51-
:SETUP64
52-
set INCLUDE_PATH="%INPUT_DIRECTORY%\x64"
53-
set ILASM_EXTRA_ARGS=/pe64 /x64
54-
goto BUILD_CLR_MODULE
55-
56-
:ERROR_BAD_PLATFORM
57-
echo Unknown target platform: %TARGET_PLATFORM%
58-
exit /b 1
59-
60-
:ERROR_MISSING_INPUT
61-
echo Can't find input file: %INPUT_PATH%
62-
exit /b 1
63-
64-
:BUILD_CLR_MODULE
65-
if not exist %INPUT_PATH% goto ERROR_MISSING_INPUT
66-
%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH%
35+
::: 2.0
36+
:::%windir%\Microsoft.NET\Framework\v2.0.50727\ilasm /nologo /quiet /dll %ILASM_EXTRA_ARGS% /include=%INCLUDE_PATH% /output=%OUTPUT_PATH% %INPUT_PATH%

pythonnet/src/runtime/clrmodule.il

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
.assembly extern mscorlib
3333
{
3434
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
35-
.ver 2:0:0:0
35+
.ver 4:0:0:0
3636
}
3737

3838
.assembly clr
3939
{
4040
.hash algorithm 0x00008004
41-
.ver 2:0:0:2
41+
.ver 2:4:2:7
4242
}
4343

4444
.module clr.dll
@@ -208,6 +208,10 @@
208208
#ifdef DEBUG_PRINT
209209
ldstr "Success!"
210210
call void [mscorlib]System.Console::WriteLine(string)
211+
212+
ldloc pythonRuntime
213+
callvirt instance string [mscorlib]System.Reflection.Assembly::get_CodeBase()
214+
call void [mscorlib]System.Console::WriteLine(string)
211215
#endif
212216
leave.s LOADED_PYTHON_RUNTIME
213217
}

pythonnet/src/runtime/moduleobject.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,22 @@ public ManagedType GetAttribute(string name, bool guess) {
6464
return cached;
6565
}
6666

67-
string qname = (_namespace == String.Empty) ? name :
68-
_namespace + "." + name;
69-
7067
ModuleObject m;
7168
ClassBase c;
69+
Type type;
70+
71+
//if (AssemblyManager.IsValidNamespace(name))
72+
//{
73+
// IntPtr py_mod_name = Runtime.PyString_FromString(name);
74+
// IntPtr modules = Runtime.PyImport_GetModuleDict();
75+
// IntPtr module = Runtime.PyDict_GetItem(modules, py_mod_name);
76+
// if (module != IntPtr.Zero)
77+
// return (ManagedType)this;
78+
// return null;
79+
//}
80+
81+
string qname = (_namespace == String.Empty) ? name :
82+
_namespace + "." + name;
7283

7384
// If the fully-qualified name of the requested attribute is
7485
// a namespace exported by a currently loaded assembly, return
@@ -84,7 +95,7 @@ public ManagedType GetAttribute(string name, bool guess) {
8495
// includes types, delegates, enums, interfaces and structs.
8596
// Only public namespace members are exposed to Python.
8697

87-
Type type = AssemblyManager.LookupType(qname);
98+
type = AssemblyManager.LookupType(qname);
8899
if (type != null) {
89100
if (!type.IsPublic) {
90101
return null;
@@ -100,7 +111,8 @@ public ManagedType GetAttribute(string name, bool guess) {
100111
// of the steps in the qualified name, then try it again.
101112
bool fromFile;
102113
if (AssemblyManager.LoadImplicit(qname, out fromFile)) {
103-
if (true == fromFile) {
114+
bool ignore = name.StartsWith("__");
115+
if (true == fromFile && (!ignore)) {
104116
string deprWarning = String.Format("\nThe module was found, but not in a referenced namespace.\n" +
105117
"Implicit loading is deprecated. Please use clr.AddReference(\"{0}\").", qname);
106118
Exceptions.deprecation(deprWarning);
@@ -311,6 +323,9 @@ internal class CLRModule : ModuleObject
311323
protected static bool hacked = false;
312324
protected static bool interactive_preload = true;
313325
internal static bool preload;
326+
// XXX Test performance of new features //
327+
internal static bool _SuppressDocs = false;
328+
internal static bool _SuppressOverloads = false;
314329

315330
public CLRModule() : base("clr") {
316331
_namespace = String.Empty;
@@ -358,6 +373,18 @@ public static void setPreload(bool preloadFlag)
358373
preload = preloadFlag;
359374
}
360375

376+
//[ModulePropertyAttribute]
377+
public static bool SuppressDocs {
378+
get { return _SuppressDocs; }
379+
set { _SuppressDocs = value; }
380+
}
381+
382+
//[ModulePropertyAttribute]
383+
public static bool SuppressOverloads {
384+
get { return _SuppressOverloads; }
385+
set { _SuppressOverloads = value; }
386+
}
387+
361388
[ModuleFunctionAttribute()]
362389
[ForbidPythonThreadsAttribute()]
363390
public static Assembly AddReference(string name)

pythonnet/src/runtime/pythonengine.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ public static void InitExt() {
152152
"import traceback\n" +
153153
"for item in traceback.extract_stack():\n" +
154154
" line = item[3]\n" +
155-
" if line is not None:\n" +
155+
" if line is not None:\n" +
156156
" if line.startswith('import CLR') or \\\n" +
157+
" line.startswith('import clr') or \\\n" +
158+
" line.startswith('from clr') or \\\n" +
157159
" line.startswith('from CLR'):\n" +
158160
" exec line\n" +
159161
" break\n";

pythonnet/src/runtime/pythonexception.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ public void Dispose() {
122122
IntPtr gs = PythonEngine.AcquireLock();
123123
Runtime.Decref(_pyType);
124124
Runtime.Decref(_pyValue);
125-
Runtime.Decref(_pyTB);
125+
// XXX Do we ever get TraceBack? //
126+
if (_pyTB != IntPtr.Zero) {
127+
Runtime.Decref(_pyTB);
128+
}
126129
PythonEngine.ReleaseLock(gs);
127130
}
128131
GC.SuppressFinalize(this);

pythonnet/src/runtime/runtime.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,23 @@ internal unsafe static void Decref(IntPtr op) {
337337
Py_DecRef(op);
338338
return;
339339
#else
340-
void *p = (void *)op;
341-
if ((void *)0 != p) {
342-
if (is32bit) { --(*(int *)p); }
343-
else { --(*(long *)p); }
344-
if ((*(int *)p) == 0) {
345-
// PyObject_HEAD: struct _typeobject *ob_type
346-
void *t = is32bit ? (void *)(*((uint *)p + 1)) :
347-
(void *)(*((ulong *)p + 1));
348-
// PyTypeObject: destructor tp_dealloc
349-
void* f = is32bit ? (void*)(*((uint*)t + 6)) :
350-
(void*)(*((ulong*)t + 6));
351-
if ((void *)0 == f) {
352-
return;
340+
void* p = (void*) op;
341+
if ((void*) 0 != p) {
342+
if (is32bit) { --(*(int*) p); }
343+
else { --(*(long*) p); }
344+
if ((*(int*) p) == 0) {
345+
// PyObject_HEAD: struct _typeobject *ob_type
346+
void* t = is32bit ? (void*) (*((uint*) p + 1)) :
347+
(void*) (*((ulong*) p + 1));
348+
// PyTypeObject: destructor tp_dealloc
349+
void* f = is32bit ? (void*) (*((uint*) t + 6)) :
350+
(void*) (*((ulong*) t + 6));
351+
if ((void*) 0 == f) {
352+
return;
353+
}
354+
NativeCall.Impl.Void_Call_1(new IntPtr(f), op);
355+
return;
353356
}
354-
NativeCall.Impl.Void_Call_1(new IntPtr(f), op);
355-
return;
356-
}
357357
}
358358
#endif
359359
}
@@ -1021,7 +1021,7 @@ internal static bool PyUnicode_Check(IntPtr ob) {
10211021
return PyObject_TYPE(ob) == Runtime.PyUnicodeType;
10221022
}
10231023

1024-
#if (!UCS4)
1024+
#if (UCS2)
10251025
[DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl,
10261026
EntryPoint="PyUnicodeUCS2_FromObject",
10271027
ExactSpelling=true, CharSet=CharSet.Unicode)]

0 commit comments

Comments
 (0)