<
10000
code class="diff-text-cell hunk">
@@ -1,8 +1,6 @@
1
1
using System ;
2
2
using System . Collections ;
3
- using System . Collections . Generic ;
4
3
using System . Globalization ;
5
- using System . Reflection ;
6
4
using System . Runtime . InteropServices ;
7
5
using System . Security ;
8
6
@@ -55,13 +53,13 @@ static Converter()
55
53
56
54
IntPtr dateTimeMod = Runtime . PyImport_ImportModule ( "datetime" ) ;
57
55
if ( dateTimeMod == null ) throw new PythonException ( ) ;
58
-
56
+
59
57
decimalCtor = Runtime . PyObject_GetAttrString ( decimalMod , "Decimal" ) ;
60
58
if ( decimalCtor == null ) throw new PythonException ( ) ;
61
-
59
+
62
60
dateTimeCtor = Runtime . PyObject_GetAttrString ( dateTimeMod , "datetime" ) ;
63
61
if ( dateTimeCtor == null ) throw new PythonException ( ) ;
64
-
62
+
65
63
timeSpanCtor = Runtime . PyObject_GetAttrString ( dateTimeMod , "timedelta" ) ;
66
64
if ( timeSpanCtor == null ) throw new PythonException ( ) ;
67
65
@@ -224,7 +222,10 @@ internal static IntPtr ToPython(object value, Type type)
224
222
225
223
IntPtr timeSpanArgs = Runtime . PyTuple_New ( 1 ) ;
226
224
Runtime . PyTuple_SetItem ( timeSpanArgs , 0 , Runtime . PyFloat_FromDouble ( timespan . TotalDays ) ) ;
227
- return Runtime . PyObject_CallObject ( timeSpanCtor , timeSpanArgs ) ;
225
+ var returnTimeSpan = Runtime . PyObject_CallObject ( timeSpanCtor , timeSpanArgs ) ;
226
+ // clean up
227
+ Runtime . XDecref ( timeSpanArgs ) ;
228
+ return returnTimeSpan ;
228
229
}
229
230
return CLRObject . GetInstHandle ( value , type ) ;
230
231
@@ -283,12 +284,14 @@ internal static IntPtr ToPython(object value, Type type)
283
284
IntPtr d2p = Runtime . PyString_FromString ( d2s ) ;
284
285
IntPtr decimalArgs = Runtime . PyTuple_New ( 1 ) ;
285
286
Runtime . PyTuple_SetItem ( decimalArgs , 0 , d2p ) ;
286
-
287
- return Runtime . PyObject_CallObject ( decimalCtor , decimalArgs ) ;
287
+ var returnDecimal = Runtime . PyObject_CallObject ( decimalCtor , decimalArgs ) ;
288
+ // clean up
289
+ Runtime . XDecref ( decimalArgs ) ;
290
+ return returnDecimal ;
288
291
289
292
case TypeCode . DateTime :
290
293
var datetime = ( DateTime ) value ;
291
-
294
+
292
295
IntPtr dateTimeArgs = Runtime . PyTuple_New ( 8 ) ;
293
296
Runtime . PyTuple_SetItem ( dateTimeArgs , 0 , Runtime . PyInt_FromInt32 ( datetime . Year ) ) ;
294
297
Runtime . PyTuple_SetItem ( dateTimeArgs , 1 , Runtime . PyInt_FromInt32 ( datetime . Month ) ) ;
@@ -298,8 +301,10 @@ internal static IntPtr ToPython(object value, Type type)
298
301
Runtime . PyTuple_SetItem ( dateTimeArgs , 5 , Runtime . PyInt_FromInt32 ( datetime . Second ) ) ;
299
302
Runtime . PyTuple_SetItem ( dateTimeArgs , 6 , Runtime . PyInt_FromInt32 ( datetime . Millisecond ) ) ;
300
303
Runtime . PyTuple_SetItem ( dateTimeArgs , 7 , TzInfo ( datetime . Kind ) ) ;
301
-
302
- return Runtime . PyObject_CallObject ( dateTimeCtor , dateTimeArgs ) ;
304
+ var returnDateTime = Runtime . PyObject_CallObject ( dateTimeCtor , dateTimeArgs ) ;
305
+ // clean up
306
+ Runtime . XDecref ( dateTimeArgs ) ;
307
+ return returnDateTime ;
303
308
304
309
default :
305
310
if ( value is IEnumerable )
@@ -329,7 +334,9 @@ private static IntPtr TzInfo(DateTimeKind kind)
329
334
IntPtr tzInfoArgs = Runtime . PyTuple_New ( 2 ) ;
330
335
Runtime . PyTuple_SetItem ( tzInfoArgs , 0 , Runtime . PyFloat_FromDouble ( offset . Hours ) ) ;
331
336
Runtime . PyTuple_SetItem ( tzInfoArgs , 1 , Runtime . PyFloat_FromDouble ( offset . Minutes ) ) ;
332
- return Runtime . PyObject_CallObject ( tzInfoCtor , tzInfoArgs ) ;
337
+ var returnValue = Runtime . PyObject_CallObject ( tzInfoCtor , tzInfoArgs ) ;
338
+ Runtime . XDecref ( tzInfoArgs ) ;
339
+ return returnValue ;
333
340
}
334
341
335
342
0 commit comments