80
80
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyMemberAccessNodes .HPyGetSetDescriptorSetterRootNode ;
81
81
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyMemberAccessNodes .HPyReadMemberNode ;
82
82
import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyMemberAccessNodes .HPyWriteMemberNode ;
83
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyAllHandleCloseNodeGen ;
84
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyGetSetSetterHandleCloseNodeGen ;
85
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyKeywordsHandleCloseNodeGen ;
86
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPySelfHandleCloseNodeGen ;
87
+ import com .oracle .graal .python .builtins .objects .cext .hpy .GraalHPyNodesFactory .HPyVarargsHandleCloseNodeGen ;
88
+ import com .oracle .graal .python .builtins .objects .cext .hpy .HPyArrayWrappers .HPyArrayWrapper ;
89
+ import com .oracle .graal .python .builtins .objects .cext .hpy .HPyArrayWrappers .HPyCloseArrayWrapperNode ;
83
90
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
84
91
import com .oracle .graal .python .builtins .objects .function .PFunction ;
85
92
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
@@ -1177,6 +1184,13 @@ static Object doGeneric(@SuppressWarnings("unused") CExtContext hpyContext, Obje
1177
1184
public abstract static class HPyConvertArgsToSulongNode extends PNodeWithContext {
1178
1185
1179
1186
public abstract void executeInto (VirtualFrame frame , GraalHPyContext hpyContext , Object [] args , int argsOffset , Object [] dest , int destOffset );
1187
+
1188
+ abstract HPyCloseArgHandlesNode createCloseHandleNode ();
1189
+ }
1190
+
1191
+ public abstract static class HPyCloseArgHandlesNode extends PNodeWithContext {
1192
+
1193
+ public abstract void executeInto (VirtualFrame frame , GraalHPyContext hpyContext , Object [] args , int argsOffset );
1180
1194
}
1181
1195
1182
1196
public abstract static class HPyVarargsToSulongNode extends HPyConvertArgsToSulongNode {
@@ -1188,6 +1202,37 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
1188
1202
dest [destOffset + 1 ] = args [argsOffset + 1 ];
1189
1203
dest [destOffset + 2 ] = args [argsOffset + 2 ];
1190
1204
}
1205
+
1206
+ @ Override
1207
+ HPyCloseArgHandlesNode createCloseHandleNode () {
1208
+ return HPyVarargsHandleCloseNodeGen .create ();
1209
+ }
1210
+ }
1211
+
1212
+ /**
1213
+ * The counter part of {@link HPyVarargsToSulongNode}.
1214
+ */
1215
+ public abstract static class HPyVarargsHandleCloseNode extends HPyCloseArgHandlesNode {
1216
+
1217
+ @ Specialization
1218
+ static void doConvert (GraalHPyContext hpyContext , Object [] dest , int destOffset ,
1219
+ @ Cached HPyEnsureHandleNode ensureHandleNode ,
1220
+ @ Cached HPyCloseArrayWrapperNode closeArrayWrapperNode ) {
1221
+ ensureHandleNode .execute (hpyContext , dest [destOffset ]).close (hpyContext );
1222
+ closeArrayWrapperNode .execute (hpyContext , (HPyArrayWrapper ) dest [destOffset + 1 ]);
1223
+ }
1224
+ }
1225
+
1226
+ /**
1227
+ * Always closes parameter at position {@code destOffset} (assuming that it is a handle).
1228
+ */
1229
+ public abstract static class HPySelfHandleCloseNode extends HPyCloseArgHandlesNode {
1230
+
1231
+ @ Specialization
1232
+ static void doConvert (GraalHPyContext hpyContext , Object [] dest , int destOffset ,
1233
+ @ Cached HPyEnsureHandleNode ensureHandleNode ) {
1234
+ ensureHandleNode .execute (hpyContext , dest [destOffset ]).close (hpyContext );
1235
+ }
1191
1236
}
1192
1237
1193
1238
public abstract static class HPyKeywordsToSulongNode extends HPyConvertArgsToSulongNode {
@@ -1201,6 +1246,26 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
1201
1246
dest [destOffset + 2 ] = args [argsOffset + 2 ];
1202
1247
dest [destOffset + 3 ] = kwAsHandleNode .execute (hpyContext , args [argsOffset + 3 ]);
1203
1248
}
1249
+
1250
+ @ Override
1251
+ HPyCloseArgHandlesNode createCloseHandleNode () {
1252
+ return HPyKeywordsHandleCloseNodeGen .create ();
1253
+ }
1254
+ }
1255
+
1256
+ /**
1257
+ * The counter part of {@link HPyKeywordsToSulongNode}.
1258
+ */
1259
+ public abstract static class HPyKeywordsHandleCloseNode extends HPyCloseArgHandlesNode {
1260
+
1261
+ @ Specialization
1262
+ static void doConvert (GraalHPyContext hpyContext , Object [] dest , int destOffset ,
1263
+ @ Cached HPyEnsureHandleNode ensureHandleNode ,
1264
+ @ Cached HPyCloseArrayWrapperNode closeArrayWrapperNode ) {
1265
+ ensureHandleNode .execute (hpyContext , dest [destOffset ]).close (hpyContext );
1266
+ closeArrayWrapperNode .execute (hpyContext , (HPyArrayWrapper ) dest [destOffset + 1 ]);
1267
+ ensureHandleNode .execute (hpyContext , dest [destOffset + 3 ]).close (hpyContext );
1268
+ }
1204
1269
}
1205
1270
1206
1271
public abstract static class HPyAllAsHandleNode extends HPyConvertArgsToSulongNode {
@@ -1223,6 +1288,7 @@ static void cached0(GraalHPyContext hpyContext, Object[] args, int argsOffset, O
1223
1288
static void cachedLoop (GraalHPyContext hpyContext , Object [] args , int argsOffset , Object [] dest , int destOffset ,
1224
1289
@ Cached ("args.length" ) int cachedLength ,
1225
1290
@ Cached HPyAsHandleNode toSulongNode ) {
1291
+ CompilerAsserts .partialEvaluationConstant (destOffset );
1226
1292
for (int i = 0 ; i < cachedLength - argsOffset ; i ++) {
1227
1293
dest [destOffset + i ] = toSulongNode .execute (hpyContext , args [argsOffset + i ]);
1228
1294
}
@@ -1236,6 +1302,46 @@ static void uncached(GraalHPyContext hpyContext, Object[] args, int argsOffset,
1236
1302
dest [destOffset + i ] = toSulongNode .execute (hpyContext , args [argsOffset + i ]);
1237
1303
}
1238
1304
}
1305
+
1306
+ @ Override
1307
+ HPyCloseArgHandlesNode createCloseHandleNode () {
1308
+ return HPyAllHandleCloseNodeGen .create ();
1309
+ }
1310
+ }
1311
+
1312
+ /**
1313
+ * The counter part of {@link HPyAllAsHandleNode}.
1314
+ */
1315
+ public abstract static class HPyAllHandleCloseNode extends HPyCloseArgHandlesNode {
1316
+
1317
+ @ Specialization (guards = {"dest.length == destOffset" })
1318
+ @ SuppressWarnings ("unused" )
1319
+ static void cached0 (GraalHPyContext hpyContext , Object [] dest , int destOffset ) {
1320
+ }
1321
+
1322
+ @ Specialization (guards = {"dest.length == cachedLength" , "isLeArgsOffsetPlus(cachedLength, destOffset, 8)" }, limit = "1" , replaces = "cached0" )
1323
+ @ ExplodeLoop
1324
+ static void cachedLoop (GraalHPyContext hpyContext , Object [] dest , int destOffset ,
1325
+ @ Cached ("dest.length" ) int cachedLength ,
1326
+ @ Cached HPyEnsureHandleNode ensureHandleNode ) {
1327
+ CompilerAsserts .partialEvaluationConstant (destOffset );
1328
+ for (int i = 0 ; i < cachedLength - destOffset ; i ++) {
1329
+ ensureHandleNode .execute (hpyContext , dest [destOffset + i ]).close (hpyContext );
1330
+ }
1331
+ }
1332
+
1333
+ @ Specialization (replaces = {"cached0" , "cachedLoop" })
1334
+ static void uncached (GraalHPyContext hpyContext , Object [] dest , int destOffset ,
1335
+ @ Cached HPyEnsureHandleNode ensureHandleNode ) {
1336
+ int len = dest .length ;
1337
+ for (int i = 0 ; i < len - destOffset ; i ++) {
1338
+ ensureHandleNode .execute (hpyContext , dest [destOffset + i ]).close (hpyContext );
1339
+ }
1340
+ }
1341
+
1342
+ static boolean isLeArgsOffsetPlus (int len , int off , int plus ) {
1343
+ return len < plus + off ;
1344
+ }
1239
1345
}
1240
1346
1241
1347
/**
@@ -1250,6 +1356,11 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
1250
1356
dest [destOffset ] = selfAsHandleNode .execute (hpyContext , args [argsOffset ]);
1251
1357
dest [destOffset + 1 ] = args [argsOffset + 1 ];
1252
1358
}
1359
+
1360
+ @ Override
1361
+ HPyCloseArgHandlesNode createCloseHandleNode () {
1362
+ return HPySelfHandleCloseNodeGen .create ();
1363
+ }
1253
1364
}
1254
1365
1255
1366
/**
@@ -1265,6 +1376,24 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
1265
1376
dest [destOffset + 1 ] = asHandleNode .execute (hpyContext , args [argsOffset + 1 ]);
1266
1377
dest [destOffset + 2 ] = args [argsOffset + 2 ];
1267
1378
}
1379
+
1380
+ @ Override
1381
+ HPyCloseArgHandlesNode createCloseHandleNode () {
1382
+ return HPyGetSetSetterHandleCloseNodeGen .create ();
1383
+ }
1384
+ }
1385
+
1386
+ /**
1387
+ * The counter part of {@link HPyGetSetSetterToSulongNode}.
1388
+ */
1389
+ public abstract static class HPyGetSetSetterHandleCloseNode extends HPyCloseArgHandlesNode {
1390
+
1391
+ @ Specialization
1392
+ static void doConvert (GraalHPyContext hpyContext , Object [] dest , int destOffset ,
1393
+ @ Cached HPyEnsureHandleNode ensureHandleNode ) {
1394
+ ensureHandleNode .execute (hpyContext , dest [destOffset ]).close (hpyContext );
1395
+ ensureHandleNode .execute (hpyContext , dest [destOffset + 1 ]).close (hpyContext );
1396
+ }
1268
1397
}
1269
1398
1270
1399
/**
@@ -1273,7 +1402,6 @@ static void doConvert(GraalHPyContext hpyContext, Object[] args, int argsOffset,
1273
1402
public abstract static class HPySSizeArgFuncToSulongNode extends HPyConvertArgsToSulongNode {
1274
1403
1275
1404
@ Specialization (guards = {"isArity(args.length, argsOffset, 2)" })
1276
- @ ExplodeLoop
1277
1405
static void doHandleSsizeT (VirtualFrame frame , GraalHPyContext hpyContext , Object [] args , int argsOffset , Object [] dest , int destOffset ,
1278
1406
@ Cached HPyAsHandleNode asHandleNode ,
1279
1407
@ Cached ConvertPIntToPrimitiveNode asSsizeTNode ) {
@@ -1283,7 +1411,6 @@ static void doHandleSsizeT(VirtualFrame frame, GraalHPyContext hpyContext, Objec
1283
1411
}
1284
1412
1285
1413
@ Specialization (guards = {"isArity(args.length, argsOffset, 3)" })
1286
- @ ExplodeLoop
1287
1414
static void doHandleSsizeTSsizeT (VirtualFrame frame , GraalHPyContext hpyContext , Object [] args , int argsOffset , Object [] dest , int destOffset ,
1288
1415
@ Cached HPyAsHandleNode asHandleNode ,
1289
1416
@ Cached ConvertPIntToPrimitiveNode asSsizeTNode ) {
@@ -1303,6 +1430,11 @@ static void doGeneric(VirtualFrame frame, @SuppressWarnings("unused") GraalHPyCo
1303
1430
}
1304
1431
}
1305
1432
1433
+ @ Override
1434
+ HPyCloseArgHandlesNode createCloseHandleNode () {
1435
+ return HPySelfHandleCloseNodeGen .create ();
1436
+ }
1437
+
1306
1438
static boolean isArity (int len , int off , int expected ) {
1307
1439
return len - off == expected ;
1308
1440
}
0 commit comments