@@ -60,7 +60,6 @@ pub fn parser(args: AttributeArgs, input: ItemFn) -> Result<(TokenStream, Functi
6060 let arg_parser = build_arg_parser ( args. iter ( ) , & optional) ?;
6161 let arg_accessors = build_arg_accessors ( & args) ;
6262
63- let return_handler = build_return_handler ( output) ;
6463 let return_type = get_return_type ( output) ?;
6564
6665 let func = quote ! {
@@ -75,7 +74,10 @@ pub fn parser(args: AttributeArgs, input: ItemFn) -> Result<(TokenStream, Functi
7574
7675 let result = #ident( #( #arg_accessors, ) * ) ;
7776
78- #return_handler
77+ if let Err ( e) = result. set_zval( retval, false ) {
78+ let e: :: ext_php_rs:: php:: exceptions:: PhpException = e. into( ) ;
79+ e. throw( ) . expect( "Failed to throw exception" ) ;
80+ }
7981 }
8082 } ;
8183
@@ -202,61 +204,6 @@ fn build_arg_accessors(args: &[Arg]) -> Vec<TokenStream> {
202204 args. iter ( ) . map ( |arg| arg. get_accessor ( ) ) . collect ( )
203205}
204206
205- pub fn build_return_handler ( output_type : & ReturnType ) -> TokenStream {
206- let handler = match output_type {
207- ReturnType :: Default => Some ( quote ! { retval. set_null( ) ; } ) ,
208- ReturnType :: Type ( _, ref ty) => match * * ty {
209- Type :: Path ( ref path) => match path. path . segments . last ( ) {
210- Some ( path_seg) => match path_seg. ident . to_string ( ) . as_ref ( ) {
211- "Result" => Some ( quote ! {
212- match result {
213- Ok ( result) => match result. set_zval( retval, false ) {
214- Ok ( _) => { }
215- Err ( e) => {
216- let e: :: ext_php_rs:: php:: exceptions:: PhpException = e. into( ) ;
217- e. throw( ) . expect( "Failed to throw exception: Failed to set return value." ) ;
218- } ,
219- } ,
220- Err ( e) => {
221- let e: :: ext_php_rs:: php:: exceptions:: PhpException = e. into( ) ;
222- e. throw( ) . expect( "Failed to throw exception: Error type returned from internal function." ) ;
223- }
224- } ;
225- } ) ,
226- "Option" => Some ( quote ! {
227- match result {
228- Some ( result) => match result. set_zval( retval, false ) {
229- Ok ( _) => { }
230- Err ( e) => {
231- let e: :: ext_php_rs:: php:: exceptions:: PhpException = e. into( ) ;
232- e. throw( ) . expect( "Failed to throw exception: Failed to set return value." ) ;
233- } ,
234- } ,
235- None => retval. set_null( ) ,
236- } ;
237- } ) ,
238- _ => None ,
239- } ,
240- _ => None ,
241- } ,
242- _ => None ,
243- } ,
244- } ;
245-
246- match handler {
247- Some ( handler) => handler,
248- None => quote ! {
249- match result. set_zval( retval, false ) {
250- Ok ( _) => { } ,
251- Err ( e) => {
252- let e: :: ext_php_rs:: php:: exceptions:: PhpException = e. into( ) ;
253- e. throw( ) . expect( "Failed to throw exception: Failed to set return value." ) ;
254- }
255- }
256- } ,
257- }
258- }
259-
260207pub fn get_return_type ( output_type : & ReturnType ) -> Result < Option < ( String , bool ) > > {
261208 Ok ( match output_type {
262209 ReturnType :: Default => None ,
0 commit comments