@@ -1834,7 +1834,19 @@ module Python {
1834
1834
this .isOwned = true ;
1835
1835
this .ctxInitState = chpl_pythonContext.enter();
1836
1836
init this ;
1837
- this .obj = this .interpreter.loadPickle(pickleData);
1837
+ // Only catch-less try! statements are allowed in initializers for now :(
1838
+ proc helper () throws {
1839
+ try {
1840
+ this .obj = this .interpreter.loadPickle(pickleData);
1841
+ } catch e {
1842
+ // an exception thrown from the init will not result in a call to the postinit
1843
+ // or the deinit, so we have to handle that stuff here
1844
+ defer PyGILState_Release(this .gilInitState);
1845
+ // rethrow the exception
1846
+ throw e;
1847
+ }
1848
+ }
1849
+ helper();
1838
1850
}
1839
1851
/*
1840
1852
Creates a new Python object from a Chapel value.
@@ -1847,7 +1859,19 @@ module Python {
1847
1859
this .isOwned = true ;
1848
1860
this .ctxInitState = chpl_pythonContext.enter();
1849
1861
init this ;
1850
- this .obj = this .interpreter.toPythonInner(value);
1862
+ // Only catch-less try! statements are allowed in initializers for now :(
1863
+ proc helper () throws {
1864
+ try {
1865
+ this .obj = this .interpreter.toPythonInner(value);
1866
+ } catch e {
1867
+ // an exception thrown from the init will not result in a call to the postinit
1868
+ // or the deinit, so we have to handle that stuff here
1869
+ defer PyGILState_Release(this .gilInitState);
1870
+ // rethrow the exception
1871
+ throw e;
1872
+ }
1873
+ }
1874
+ helper();
1851
1875
}
1852
1876
1853
1877
@chpldoc.nodoc
@@ -2415,7 +2439,19 @@ module Python {
2415
2439
super .init(interpreter, nil : PyObjectPtr, isOwned= true );
2416
2440
this .modName = modName;
2417
2441
init this ;
2418
- this .obj = interpreter.compileModule(moduleContents, modName);
2442
+ // Only catch-less try! statements are allowed in initializers for now :(
2443
+ proc helper () throws {
2444
+ try {
2445
+ this .obj = interpreter.compileModule(moduleContents, modName);
2446
+ } catch e {
2447
+ // an exception thrown from the init will not result in a call to the postinit
2448
+ // or the deinit, so we have to handle that stuff here
2449
+ defer PyGILState_Release(this .gilInitState);
2450
+ // rethrow the exception
2451
+ throw e;
2452
+ }
2453
+ }
2454
+ helper();
2419
2455
}
2420
2456
2421
2457
/*
@@ -2427,7 +2463,19 @@ module Python {
2427
2463
super .init(interpreter, nil : PyObjectPtr, isOwned= true );
2428
2464
this .modName = modName;
2429
2465
init this ;
2430
- this .obj = interpreter.compileModule(moduleBytecode, modName);
2466
+ // Only catch-less try! statements are allowed in initializers for now :(
2467
+ proc helper () throws {
2468
+ try {
2469
+ this .obj = interpreter.compileModule(moduleBytecode, modName);
2470
+ } catch e {
2471
+ // an exception thrown from the init will not result in a call to the postinit
2472
+ // or the deinit, so we have to handle that stuff here
2473
+ defer PyGILState_Release(this .gilInitState);
2474
+ // rethrow the exception
2475
+ throw e;
2476
+ }
2477
+ }
2478
+ helper();
2431
2479
}
2432
2480
}
2433
2481
@@ -2482,7 +2530,19 @@ module Python {
2482
2530
super .init(interpreter, nil : PyObjectPtr, isOwned= true );
2483
2531
this .fnName = " <anon>" ;
2484
2532
init this ;
2485
- this .obj = interpreter.compileLambdaInternal(lambdaFn);
2533
+ // Only catch-less try! statements are allowed in initializers for now :(
2534
+ proc helper () throws {
2535
+ try {
2536
+ this .obj = interpreter.compileLambdaInternal(lambdaFn);
2537
+ } catch e {
2538
+ // an exception thrown from the init will not result in a call to the postinit
2539
+ // or the deinit, so we have to handle that stuff here
2540
+ defer PyGILState_Release(this .gilInitState);
2541
+ // rethrow the exception
2542
+ throw e;
2543
+ }
2544
+ }
2545
+ helper();
2486
2546
}
2487
2547
@chpldoc.nodoc
2488
2548
proc init (in interpreter: borrowed Interpreter,
@@ -3403,15 +3463,15 @@ module Python {
3403
3463
:arg interpreter: The interpreter that this object is associated with.
3404
3464
:arg arr: The Chapel array to create the object from.
3405
3465
*/
3406
- proc init (in interpreter: borrowed Interpreter, ref arr: [] ) throws
3466
+ proc init (in interpreter: borrowed Interpreter, ref arr: [] )
3407
3467
where isSupportedArrayType(arr) {
3408
3468
super .init(interpreter, nil : PyObjectPtr, isOwned= true );
3409
3469
this .eltType = arr.eltType;
3410
3470
init this ;
3411
3471
this .obj = ArrayTypes.createArray(arr);
3412
3472
}
3413
3473
@chpldoc.nodoc
3414
- proc init (in interpreter: borrowed Interpreter, ref arr: [] ) throws
3474
+ proc init (in interpreter: borrowed Interpreter, ref arr: [] )
3415
3475
where !isSupportedArrayType(arr) {
3416
3476
super .init(interpreter, nil : PyObjectPtr, isOwned= false );
3417
3477
compilerError(" Only 1D local rectangular arrays are currently supported" );
0 commit comments