4040 */
4141package com .oracle .graal .python .builtins .modules ;
4242
43+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
4344import static com .oracle .graal .python .builtins .PythonBuiltinClassType .ValueError ;
4445import static com .oracle .graal .python .runtime .exception .PythonErrorType .SystemError ;
4546
5051import com .oracle .graal .python .builtins .Builtin ;
5152import com .oracle .graal .python .builtins .CoreFunctions ;
5253import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
53- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TypeError ;
5454import com .oracle .graal .python .builtins .PythonBuiltins ;
5555import com .oracle .graal .python .builtins .objects .PNone ;
5656import com .oracle .graal .python .builtins .objects .array .PArray ;
6666import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
6767import com .oracle .graal .python .nodes .ErrorMessages ;
6868import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
69+ import com .oracle .graal .python .nodes .call .CallNode ;
6970import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
7071import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
7172import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
7273import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
74+ import com .oracle .graal .python .nodes .statement .RaiseNode ;
75+ import com .oracle .graal .python .nodes .statement .RaiseNodeGen ;
7376import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
7477import com .oracle .graal .python .runtime .PythonCore ;
7578import com .oracle .graal .python .runtime .exception .PException ;
@@ -140,7 +143,9 @@ private byte[] b64decode(byte[] data) {
140143 @ Builtin (name = "a2b_hex" , minNumOfPositionalArgs = 2 , declaresExplicitSelf = true )
141144 @ GenerateNodeFactory
142145 abstract static class A2bHexNode extends PythonBinaryBuiltinNode {
143- private ReadAttributeFromObjectNode readAttrNode ;
146+ @ Child private ReadAttributeFromObjectNode readAttrNode ;
147+ @ Child private RaiseNode raiseNode ;
148+ @ Child private CallNode callExceptionConstructor ;
144149
145150 @ Specialization
146151 @ TruffleBoundary
@@ -204,11 +209,15 @@ private int digitValue(PythonModule self, char b) {
204209 }
205210
206211 private PException oddLengthError (PythonModule self ) {
207- throw getRaiseNode ().execute (getAttrNode ().execute (self , ERROR ), PNone .NO_VALUE , ErrorMessages .ODD_LENGTH_STRING , new Object [0 ]);
212+ raiseObject (getAttrNode ().execute (self , ERROR ), ErrorMessages .ODD_LENGTH_STRING );
213+ CompilerDirectives .transferToInterpreterAndInvalidate ();
214+ throw new IllegalStateException ("should not be reached" );
208215 }
209216
210217 private PException nonHexError (PythonModule self ) {
211- throw getRaiseNode ().execute (getAttrNode ().execute (self , ERROR ), PNone .NO_VALUE , ErrorMessages .NON_HEX_DIGIT_FOUND , new Object [0 ]);
218+ raiseObject (getAttrNode ().execute (self , ERROR ), ErrorMessages .NON_HEX_DIGIT_FOUND );
219+ CompilerDirectives .transferToInterpreterAndInvalidate ();
220+ throw new IllegalStateException ("should not be reached" );
212221 }
213222
214223 private ReadAttributeFromObjectNode getAttrNode () {
@@ -218,6 +227,18 @@ private ReadAttributeFromObjectNode getAttrNode() {
218227 }
219228 return readAttrNode ;
220229 }
230+
231+ private void raiseObject (Object exceptionObject , String message ) {
232+ if (callExceptionConstructor == null ) {
233+ CompilerDirectives .transferToInterpreterAndInvalidate ();
234+ callExceptionConstructor = insert (CallNode .create ());
235+ }
236+ if (raiseNode == null ) {
237+ CompilerDirectives .transferToInterpreterAndInvalidate ();
238+ raiseNode = insert (RaiseNodeGen .create (null , null ));
239+ }
240+ raiseNode .execute (callExceptionConstructor .execute (exceptionObject , message ), PNone .NO_VALUE );
241+ }
221242 }
222243
223244 @ Builtin (name = "b2a_base64" , minNumOfPositionalArgs = 1 , parameterNames = {"data" , "newline" })
0 commit comments