Browse Source

Fix compatibility with older OTP

* Use `?WITH_STACKTRACE` for pre-OTP21
* Don't use `?FUNCTION_NAME`
Sergey Prokhorov 4 years ago
parent
commit
5005e053c1
2 changed files with 10 additions and 3 deletions
  1. 7 1
      src/epgsql_sock.erl
  2. 3 2
      test/epgsql_copy_SUITE.erl

+ 7 - 1
src/epgsql_sock.erl

@@ -105,6 +105,12 @@
 
 -opaque pg_sock() :: #state{}.
 
+-ifndef(OTP_RELEASE).                           % pre-OTP21
+-define(WITH_STACKTRACE(T, R, S), T:R -> S = erlang:get_stacktrace(), ).
+-else.
+-define(WITH_STACKTRACE(T, R, S), T:R:S ->).
+-endif.
+
 %% -- client interface --
 
 start_link() ->
@@ -533,7 +539,7 @@ handle_io_request({put_chars, Encoding, Mod, Fun, Args}, State) ->
             handle_io_request({put_chars, Encoding, Chars}, State);
         Other ->
             {error, {fun_return_not_characters, Other}}
-    catch T:R:S ->
+    catch ?WITH_STACKTRACE(T, R, S)
             {error, {fun_exception, {T, R, S}}}
     end;
 handle_io_request({setopts, _}, _State) ->

+ 3 - 2
test/epgsql_copy_SUITE.erl

@@ -186,8 +186,9 @@ from_stdin_io_apis(Config) ->
                 ?assertEqual(ok, io:put_chars(C, [<<"37">>, $\t, <<"line 37">>, <<$\n>>])),
                 ?assertEqual(ok, file:write(C, [["38", <<$\t>>], [<<"line 38">>, $\n]])),
                 %% Raw IO-protocol message-passing
-                C ! {io_request, self(), ?FUNCTION_NAME, {put_chars, unicode, "39\tline 39\n"}},
-                ?assertEqual(ok, receive {io_reply, ?FUNCTION_NAME, Resp} -> Resp
+                Ref = erlang:make_ref(),
+                C ! {io_request, self(), Ref, {put_chars, unicode, "39\tline 39\n"}},
+                ?assertEqual(ok, receive {io_reply, Ref, Resp} -> Resp
                                  after 5000 ->
                                          timeout
                                  end),