pllua / pllua-deprecated

[DEPRECATED] This repository is no longer maintained. Please follow https://github.com/pllua/pllua
197 stars 16 forks source link

1.1.0 broken on 32bit #50

Closed df7cb closed 7 years ago

df7cb commented 7 years ago

Hi, pllua seems completely broken on 32bit, e.g. on Debian sid/i386:

$ cat regression.diffs 
*** /srv/projects/postgresql/pllua/postgresql-pllua/expected/plluatest.out  2017-06-03 13:13:58.383700523 +0200
--- /srv/projects/postgresql/pllua/postgresql-pllua/results/plluatest.out   2017-06-03 14:06:24.976949300 +0200
***************
*** 502,515 ****
  $$
  language pllua;
  select nested_server_rows();
!  nested_server_rows 
! --------------------
!  3 5
!  3 6
!  4 5
!  4 6
! (4 rows)
! 
  CREATE OR REPLACE FUNCTION pg_temp.srf()
  RETURNS SETOF integer AS $$
    coroutine.yield(1)
--- 502,509 ----
  $$
  language pllua;
  select nested_server_rows();
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:4: attempt to concatenate field 'left' (a nil value)
  CREATE OR REPLACE FUNCTION pg_temp.srf()
  RETURNS SETOF integer AS $$
    coroutine.yield(1)
***************
*** 520,528 ****
   quote_nullable 
  ----------------
   '1'
!  NULL
!  '2'
! (3 rows)

  CREATE OR REPLACE FUNCTION pg_temp.srf()
  RETURNS SETOF integer AS $$
--- 514,520 ----
   quote_nullable 
  ----------------
   '1'
! (1 row)

  CREATE OR REPLACE FUNCTION pg_temp.srf()
  RETURNS SETOF integer AS $$
***************
*** 550,557 ****
  print(r.b)
  print(r.c)
  $$ language pllua;
! INFO:  b:ABC
! INFO:  5c:d
  -- body reload
  SELECT hello('PostgreSQL');
         hello        
--- 542,548 ----
  print(r.b)
  print(r.c)
  $$ language pllua;
! ERROR:  [pllua]: type 'record' (2249) not supported as argument
  -- body reload
  SELECT hello('PostgreSQL');
         hello        

======================================================================

*** /srv/projects/postgresql/pllua/postgresql-pllua/expected/biginttest.out 2017-02-11 18:10:37.000000000 +0100
--- /srv/projects/postgresql/pllua/postgresql-pllua/results/biginttest.out  2017-06-03 14:06:25.000949396 +0200
***************
*** 3,10 ****
    return value - 1;
  $$ LANGUAGE pllua;
  select int64_minus_one(9223372036854775807);
!    int64_minus_one   
! ---------------------
!  9223372036854775806
! (1 row)
! 
--- 3,7 ----
    return value - 1;
  $$ LANGUAGE pllua;
  select int64_minus_one(9223372036854775807);
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to perform arithmetic on local 'value' (a userdata value)

======================================================================

*** /srv/projects/postgresql/pllua/postgresql-pllua/expected/pgfunctest.out 2017-06-03 13:02:23.840866950 +0200
--- /srv/projects/postgresql/pllua/postgresql-pllua/results/pgfunctest.out  2017-06-03 14:06:25.048949589 +0200
***************
*** 23,28 ****
--- 23,29 ----
  return M

  $BODY$ LANGUAGE pllua;
+ ERROR:  [pllua]: functions cannot take type 'internal'
  CREATE OR REPLACE FUNCTION pg_temp.pgfunc_test()
  RETURNS SETOF text AS $$
    local quote_ident = pgfunc("quote_ident(text)")
***************
*** 35,52 ****
    coroutine.yield(i_void.getAnswer())
  $$ LANGUAGE pllua;
  select pg_temp.pgfunc_test();
!                             pgfunc_test                            
! -------------------------------------------------------------------
!  "int"
!  de
!  30414093201713378043612608166064768844377641568960512000000000000
!  42
! (4 rows)

  do $$
  print(pgfunc('quote_nullable(text)')(nil))
  $$ language pllua;
! INFO:  NULL
  create or replace function pg_temp.throw_error(text) returns void as $$
  begin
  raise exception '%', $1;
--- 36,50 ----
    coroutine.yield(i_void.getAnswer())
  $$ LANGUAGE pllua;
  select pg_temp.pgfunc_test();
!  pgfunc_test 
! -------------
! (0 rows)

  do $$
  print(pgfunc('quote_nullable(text)')(nil))
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  create or replace function pg_temp.throw_error(text) returns void as $$
  begin
  raise exception '%', $1;
***************
*** 55,70 ****
  do $$
  pgfunc('pg_temp.throw_error(text)',{only_internal=false})("exception test")
  $$ language pllua;
! ERROR:  exception test
! CONTEXT:  
! stack traceback(trusted):
!   [C]: ?
!   [string "anonymous"]:2: in main chunk
  do $$
  local f = pgfunc('pg_temp.throw_error(text)',{only_internal=false})
  print(pcall(f, "exception test"))
  $$ language pllua;
! INFO:  false  exception test
  create or replace function pg_temp.no_throw() returns json as $$
  select '{"a":5, "b":10}'::json
  $$ language sql;
--- 53,66 ----
  do $$
  pgfunc('pg_temp.throw_error(text)',{only_internal=false})("exception test")
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  do $$
  local f = pgfunc('pg_temp.throw_error(text)',{only_internal=false})
  print(pcall(f, "exception test"))
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  create or replace function pg_temp.no_throw() returns json as $$
  select '{"a":5, "b":10}'::json
  $$ language sql;
***************
*** 72,78 ****
  local f = pgfunc('pg_temp.no_throw()',{only_internal=false, throwable=false})
  print(f())
  $$ language pllua;
! INFO:  {"a":5, "b":10}
  CREATE or replace FUNCTION pg_temp.arg_count(a1 integer,a2 integer,a3 integer,a4 integer,a5 integer
  ,a6 integer,a7 integer,a8 integer,a9 integer,a10 integer
  ,a11 integer,a12 integer,a13 integer,a14 integer,a15 integer ) returns integer AS
--- 68,75 ----
  local f = pgfunc('pg_temp.no_throw()',{only_internal=false, throwable=false})
  print(f())
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  CREATE or replace FUNCTION pg_temp.arg_count(a1 integer,a2 integer,a3 integer,a4 integer,a5 integer
  ,a6 integer,a7 integer,a8 integer,a9 integer,a10 integer
  ,a11 integer,a12 integer,a13 integer,a14 integer,a15 integer ) returns integer AS
***************
*** 88,94 ****
   integer, integer, integer, integer, integer ) ]],{only_internal=false});
  print(f(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
  $$ language pllua;
! INFO:  120
  CREATE or replace FUNCTION pg_temp.inoutf(a integer, INOUT b text, INOUT c text)  AS
  $$
  begin
--- 85,92 ----
   integer, integer, integer, integer, integer ) ]],{only_internal=false});
  print(f(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  CREATE or replace FUNCTION pg_temp.inoutf(a integer, INOUT b text, INOUT c text)  AS
  $$
  begin
***************
*** 103,110 ****
  print(r.b)
  print(r.c)
  $$ language pllua;
! INFO:  b:ABC
! INFO:  5c:d
  do $$
  local f = pgfunc('generate_series(int,int)')
  print('4-6')
--- 101,108 ----
  print(r.b)
  print(r.c)
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  do $$
  local f = pgfunc('generate_series(int,int)')
  print('4-6')
***************
*** 118,131 ****
  end

  $$ language pllua;
! INFO:  4-6
! INFO:  4
! INFO:  5
! INFO:  6
! INFO:  1-3
! INFO:  1
! INFO:  2
! INFO:  3
  do $$
  local f = pgfunc('generate_series(int,int)')
  for rr in f(1,3) do
--- 116,123 ----
  end

  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  do $$
  local f = pgfunc('generate_series(int,int)')
  for rr in f(1,3) do
***************
*** 136,153 ****
    print(rr)
  end
  $$ language pllua;
! INFO:  41
! INFO:  42
! INFO:  43
! INFO:  1
! INFO:  41
! INFO:  42
! INFO:  43
! INFO:  2
! INFO:  41
! INFO:  42
! INFO:  43
! INFO:  3
  -- Type wrapper
  create extension hstore;
  do $$
--- 128,135 ----
    print(rr)
  end
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)
  -- Type wrapper
  create extension hstore;
  do $$
***************
*** 177,193 ****
    print ("key = " .. hv.key .. "    value = "..hv.value)
  end
   $$ language pllua;
! INFO:  "weight"=>"24.1 ounces", "ISBN-13"=>"978-0000000000", "language"=>"English", "paperback"=>"542", "publisher"=>"postgresql.org"
! INFO:  weight
! INFO:  ISBN-13
! INFO:  language
! INFO:  paperback
! INFO:  publisher
! INFO:  key = weight    value = 24.1 ounces
! INFO:  key = ISBN-13    value = 978-0000000000
! INFO:  key = language    value = English
! INFO:  key = paperback    value = 542
! INFO:  key = publisher    value = postgresql.org
  create or replace function getnull() returns text as $$
  begin
  return null;
--- 159,166 ----
    print ("key = " .. hv.key .. "    value = "..hv.value)
  end
   $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:6: attempt to call global 'pgfunc' (a nil value)
  create or replace function getnull() returns text as $$
  begin
  return null;
***************
*** 197,200 ****
  local a = pgfunc('getnull()',{only_internal = false})
  print(a())
  $$ language pllua;
! INFO:  nil
--- 170,174 ----
  local a = pgfunc('getnull()',{only_internal = false})
  print(a())
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'pgfunc' (a nil value)

======================================================================

*** /srv/projects/postgresql/pllua/postgresql-pllua/expected/subtransaction.out 2017-06-03 13:13:58.383700523 +0200
--- /srv/projects/postgresql/pllua/postgresql-pllua/results/subtransaction.out  2017-06-03 14:06:25.068949669 +0200
***************
*** 31,42 ****
    coroutine.yield(tostring(status))
  $$ LANGUAGE pllua;
  select pg_temp.sub_test();
!  sub_test 
! ----------
!  false
!  true
! (2 rows)
! 
  do $$
  local status, result = subtransaction(function() 
  server.execute('select 1,'); -- < special SQL syntax error
--- 31,38 ----
    coroutine.yield(tostring(status))
  $$ LANGUAGE pllua;
  select pg_temp.sub_test();
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:8: attempt to call global 'subtransaction' (a nil value)
  do $$
  local status, result = subtransaction(function() 
  server.execute('select 1,'); -- < special SQL syntax error
***************
*** 48,53 ****
  print (status, result)
  print ('done')
  $$ language pllua;
! INFO:  false  syntax error at end of input
! INFO:  false  syntax error at end of input
! INFO:  done
--- 44,48 ----
  print (status, result)
  print ('done')
  $$ language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'subtransaction' (a nil value)

======================================================================

*** /srv/projects/postgresql/pllua/postgresql-pllua/expected/error_info.out 2017-02-11 18:10:37.000000000 +0100
--- /srv/projects/postgresql/pllua/postgresql-pllua/results/error_info.out  2017-06-03 14:06:25.084949734 +0200
***************
*** 8,19 ****
  end
  f()
  $$language pllua;
! ERROR:  my error
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'error'
!   [string "anonymous"]:6: in function 'f'
!   [string "anonymous"]:9: in main chunk
  create or replace function pg_temp.function_with_error() returns integer as $$
    local testfunc = function () error("my error") end
    local f = function()
--- 8,15 ----
  end
  f()
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:6: [string "pllua chunk"]:2: my error
  create or replace function pg_temp.function_with_error() returns integer as $$
    local testfunc = function () error("my error") end
    local f = function()
***************
*** 30,66 ****
  do $$ 
    server.execute('select pg_temp.second_function()') 
  $$language pllua;
! ERROR:  my error
! CONTEXT:  
! stack traceback(untrusted):
!   [C]: in function 'error'
!   [string "function_with_error"]:6: in function 'f'
!   [string "function_with_error"]:9: in function <[string "function_with_error"]:1>
!   [C]: in function 'execute'
!   [string "second_function"]:2: in function <[string "second_function"]:1>
! SQL statement "select pg_temp.function_with_error()"
  SQL statement "select pg_temp.second_function()"
- SQL statement "select pg_temp.second_function()"
- stack traceback(trusted):
-   [C]: in function 'execute'
-   [string "anonymous"]:2: in main chunk
  do $$
  local status, err = subtransaction(function() assert(1==2) end)
  if (err) then
      error(err)
  end
  $$language pllua;
! ERROR:  assertion failed!
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'error'
!   [string "anonymous"]:4: in main chunk
  do $$
  info({message="info message", hint="info hint", detail="info detail"})
  $$language pllua;
! INFO:  info message
! DETAIL:  info detail
! HINT:  info hint
  do $$
  info("info message")
  $$language pllua;
--- 26,48 ----
  do $$ 
    server.execute('select pg_temp.second_function()') 
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:6: [string "pllua chunk"]:2: my error
! CONTEXT:  SQL statement "select pg_temp.function_with_error()"
  SQL statement "select pg_temp.second_function()"
  do $$
  local status, err = subtransaction(function() assert(1==2) end)
  if (err) then
      error(err)
  end
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: attempt to call global 'subtransaction' (a nil value)
  do $$
  info({message="info message", hint="info hint", detail="info detail"})
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: bad argument #1 to 'info' (string expected, got table)
  do $$
  info("info message")
  $$language pllua;
***************
*** 68,76 ****
  do $$
  warning({message="warning message", hint="warning hint", detail="warning detail"})
  $$language pllua;
! WARNING:  warning message
! DETAIL:  warning detail
! HINT:  warning hint
  do $$
  warning("warning message")
  $$language pllua;
--- 50,57 ----
  do $$
  warning({message="warning message", hint="warning hint", detail="warning detail"})
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: bad argument #1 to 'warning' (string expected, got table)
  do $$
  warning("warning message")
  $$language pllua;
***************
*** 78,119 ****
  do $$
  error({message="error message", hint="error hint", detail="error detail"})
  $$language pllua;
! ERROR:  error message
! DETAIL:  error detail
! HINT:  error hint
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'error'
!   [string "anonymous"]:2: in main chunk
  do $$
  error("error message")
  $$language pllua;
! ERROR:  error message
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'error'
!   [string "anonymous"]:2: in main chunk
  do $$
  info()
  $$language pllua;
! ERROR:  [string "anonymous"]:2: bad argument #1 to 'info' (string expected, got no value)
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'info'
!   [string "anonymous"]:2: in main chunk
  do $$
  warning()
  $$language pllua;
! ERROR:  [string "anonymous"]:2: bad argument #1 to 'warning' (string expected, got no value)
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'warning'
!   [string "anonymous"]:2: in main chunk
  do $$
  error()
  $$language pllua;
! ERROR:  [string "anonymous"]:2: no exception data
! CONTEXT:  
! stack traceback(trusted):
!   [C]: in function 'error'
!   [string "anonymous"]:2: in main chunk
--- 59,83 ----
  do $$
  error({message="error message", hint="error hint", detail="error detail"})
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  (null)
  do $$
  error("error message")
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: error message
  do $$
  info()
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: bad argument #1 to 'info' (string expected, got no value)
  do $$
  warning()
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  [string "pllua chunk"]:2: bad argument #1 to 'warning' (string expected, got no value)
  do $$
  error()
  $$language pllua;
! ERROR:  [pllua]: runtime error
! DETAIL:  (null)

======================================================================
golgote commented 7 years ago

Do you know which flavor of Lua it is using? 5.1, luajit or something else?

df7cb commented 7 years ago

5.1 - should have included that in the initial report...

eugwne commented 7 years ago

postgres int8 <-> lua int64 is broken, and I´m not sure how to fix it. What I see here :

      case INT8OID:{
        elog(INFO,"[pllua]: result =  %lld", get64lua(L, idx));
        dat = Int64GetDatum(get64lua(L, idx));
        break;
    }
SELECT echo_int8('1234567890');

INFO: [pllua]: result = 1234567890 but the output is : echo_int 89187201950435737471

df7cb commented 7 years ago

PG's int8 is pass-by-reference on 32 bit - get_int64(lua_State *L, int index) doesn't seem to take this into account.

eugwne commented 7 years ago

Added fix for int8, looks like it works for ubuntu 32, but I haven't checked it with debian.

eugwne commented 7 years ago

checked for debian 32

df7cb commented 7 years ago

Thanks! Pushed updated packages to Debian and apt.postgresql.org.