@@ -132,15 +132,23 @@ macro_rules! sh_eprintln {
132
132
#[ macro_export]
133
133
macro_rules! __sh_dispatch {
134
134
( $f: ident $fmt: literal $( $args: tt) * ) => {
135
- $crate:: Shell :: $f ( & mut * $crate:: Shell :: get( ) , :: core :: format_args! ( $fmt $( $args) * ) )
135
+ $crate:: __sh_dispatch! ( @ impl $f & mut * $crate:: Shell :: get( ) , $fmt $( $args) * )
136
136
} ;
137
137
138
138
( $f: ident $shell: expr, $( $args: tt) * ) => {
139
- $crate:: Shell :: $f ( $shell, :: core :: format_args! ( $( $args) * ) )
139
+ $crate:: __sh_dispatch! ( @ impl $f $shell, $( $args) * )
140
140
} ;
141
141
142
142
( $f: ident $( $args: tt) * ) => {
143
- $crate:: Shell :: $f( & mut * $crate:: Shell :: get( ) , :: core:: format_args!( $( $args) * ) )
143
+ $crate:: __sh_dispatch!( @impl $f & mut * $crate:: Shell :: get( ) , $( $args) * )
144
+ } ;
145
+
146
+ // Ensure that the global shell lock is held for as little time as possible.
147
+ // Also avoids deadlocks in case of nested calls.
148
+ ( @impl $f: ident $shell: expr, $( $args: tt) * ) => {
149
+ match :: core:: format_args!( $( $args) * ) {
150
+ fmt => $crate:: Shell :: $f( $shell, fmt) ,
151
+ }
144
152
} ;
145
153
}
146
154
@@ -168,6 +176,11 @@ mod tests {
168
176
sh_eprintln ! ( "eprintln" ) ?;
169
177
sh_eprintln ! ( "eprintln {}" , "arg" ) ?;
170
178
179
+ sh_println ! ( "{:?}" , {
180
+ sh_println!( "hi" ) ?;
181
+ "nested"
182
+ } ) ?;
183
+
171
184
Ok ( ( ) )
172
185
}
173
186
0 commit comments