Skip to content

Commit

Permalink
20090405 code: detect ability of lua library to propagate exceptions at
Browse files Browse the repository at this point in the history
               compile time. Lua.Config.
  • Loading branch information
m0 committed Apr 5, 2009
1 parent 212113e commit b2ab654
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 43 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -9,3 +9,5 @@
procedure.
20090405 code: lua.udata -> Lua.User_Data
20090405 note: version number changed to track Lua distribution.
20090405 code: detect ability of lua library to propagate exceptions at
compile time. Lua.Config.
55 changes: 47 additions & 8 deletions Makefile
Expand Up @@ -16,8 +16,10 @@ UNIT_TESTS/raiser.o UNIT_TESTS/utest.ali UNIT_TESTS/utest.o ctxt/bindir.o \
ctxt/ctxt.a ctxt/dlibdir.o ctxt/incdir.o ctxt/repos.o ctxt/slibdir.o \
ctxt/version.o deinstaller deinstaller.o install-core.o install-error.o \
install-posix.o install-win32.o install.a installer installer.o instchk \
instchk.o insthier.o lua-ada-conf lua-ada-conf.o lua-ada.a lua-ext.o \
lua-lib.ali lua-lib.o lua-user_data.ali lua-user_data.o lua.ali lua.o
instchk.o insthier.o lua-ada-conf lua-ada-conf.o lua-ada.a lua-check-exception \
lua-check_raise.ali lua-check_raise.o lua-config.ali lua-config.o lua-ext.o \
lua-lib.ali lua-lib.o lua-user_data.ali lua-user_data.o lua.ali lua.o \
lua_check_exception.ali lua_check_exception.o

# Mkf-deinstall
deinstall: deinstaller conf-sosuffix
Expand Down Expand Up @@ -85,12 +87,13 @@ sysinfo_clean \

UNIT_TESTS/except1:\
ada-bind ada-link UNIT_TESTS/except1.ald UNIT_TESTS/except1.ali \
UNIT_TESTS/utest.ali UNIT_TESTS/raiser.ali lua.ali lua-lib.ali lua-ext.o
UNIT_TESTS/utest.ali UNIT_TESTS/raiser.ali lua.ali lua-lib.ali lua-config.ali \
lua-ext.o
./ada-bind UNIT_TESTS/except1.ali
./ada-link UNIT_TESTS/except1 UNIT_TESTS/except1.ali lua-ext.o

UNIT_TESTS/except1.ali:\
ada-compile UNIT_TESTS/except1.adb lua.ali UNIT_TESTS/raiser.ali \
ada-compile UNIT_TESTS/except1.adb lua.ali lua-config.ali UNIT_TESTS/raiser.ali \
UNIT_TESTS/utest.ali
./ada-compile UNIT_TESTS/except1.adb

Expand Down Expand Up @@ -385,8 +388,34 @@ cc-compile lua-ada-conf.c ctxt.h _sysinfo.h
./cc-compile lua-ada-conf.c

lua-ada.a:\
cc-slib lua-ada.sld lua-ext.o lua-lib.o lua-user_data.o lua.o
./cc-slib lua-ada lua-ext.o lua-lib.o lua-user_data.o lua.o
cc-slib lua-ada.sld lua-check_raise.o lua-config.o lua-ext.o lua-lib.o \
lua-user_data.o lua.o
./cc-slib lua-ada lua-check_raise.o lua-config.o lua-ext.o lua-lib.o \
lua-user_data.o lua.o

lua-check-exception:\
ada-bind ada-link lua-check-exception.ald lua_check_exception.ali \
lua-check_raise.ali lua-ext.o
./ada-bind lua_check_exception.ali
./ada-link lua-check-exception lua_check_exception.ali lua-ext.o

lua-check_raise.ali:\
ada-compile lua-check_raise.adb lua-check_raise.ads
./ada-compile lua-check_raise.adb

lua-check_raise.o:\
lua-check_raise.ali

# lua-config.ads.mff
lua-config.ads: lua-config.sh lua-check-exception
./lua-config.sh > lua-config.ads.tmp && mv lua-config.ads.tmp lua-config.ads

lua-config.ali:\
ada-compile lua-config.ads
./ada-compile lua-config.ads

lua-config.o:\
lua-config.ali

lua-ext.o:\
cc-compile lua-ext.c
Expand Down Expand Up @@ -419,6 +448,13 @@ ada-compile lua.adb lua.ads
lua.o:\
lua.ali

lua_check_exception.ali:\
ada-compile lua_check_exception.adb lua.ali lua-check_raise.ali
./ada-compile lua_check_exception.adb

lua_check_exception.o:\
lua_check_exception.ali

mk-adatype:\
conf-adacomp conf-systype

Expand Down Expand Up @@ -458,8 +494,11 @@ obj_clean:
ctxt/incdir.o ctxt/repos.c ctxt/repos.o ctxt/slibdir.c ctxt/slibdir.o \
ctxt/version.c ctxt/version.o deinstaller deinstaller.o install-core.o \
install-error.o install-posix.o install-win32.o install.a installer installer.o \
instchk instchk.o insthier.o lua-ada-conf lua-ada-conf.o lua-ada.a lua-ext.o
rm -f lua-lib.ali lua-lib.o lua-user_data.ali lua-user_data.o lua.ali lua.o
instchk instchk.o insthier.o lua-ada-conf lua-ada-conf.o lua-ada.a \
lua-check-exception
rm -f lua-check_raise.ali lua-check_raise.o lua-config.ads lua-config.ali \
lua-config.o lua-ext.o lua-lib.ali lua-lib.o lua-user_data.ali lua-user_data.o \
lua.ali lua.o lua_check_exception.ali lua_check_exception.o
ext_clean:
rm -f conf-adatype conf-cctype conf-ldtype conf-sosuffix conf-systype mk-ctxt

Expand Down
8 changes: 1 addition & 7 deletions TODO
@@ -1,7 +1 @@
Define:

Lua.Can_Propagate_Exceptions : constant Boolean := True;

Create above constant with compile-time check. Can exceptions
be propagated through C library?

Detect C types for lua_integer, lua_number, etc.
38 changes: 21 additions & 17 deletions UNIT_TESTS/except1.adb
@@ -1,5 +1,6 @@
with Ada.Text_IO;
with Lua;
with Lua.Config;
with Raiser;
with UTest;

Expand All @@ -12,24 +13,27 @@ procedure except1 is
use type Lua.State_t;
use type Lua.Number_t;
begin
State := Lua.Open;

Lua.At_Panic
(State => State,
Panic_Function => Raiser.Raiser'Access);
Ada.Text_IO.Put_Line ("registered panic handler");
if Lua.Config.Can_Propagate_Exceptions then
State := Lua.Open;

begin
Ada.Text_IO.Put_Line ("causing panic...");
Lua.Push_Number (State, -1.0);
Lua.Call (State, 1, 1);
exception
when Raiser.Raiser_Error =>
Ada.Text_IO.Put_Line ("Caught Raiser.Raiser_Error");
Caught := True;
end;
Lua.At_Panic
(State => State,
Panic_Function => Raiser.Raiser'Access);
Ada.Text_IO.Put_Line ("registered panic handler");

UTest.Check
(Check => Caught,
Message => "Caught exception");
begin
Ada.Text_IO.Put_Line ("causing panic...");
Lua.Push_Number (State, -1.0);
Lua.Call (State, 1, 1);
exception
when Raiser.Raiser_Error =>
Ada.Text_IO.Put_Line ("Caught Raiser.Raiser_Error");
Caught := True;
end;

UTest.Check
(Check => Caught,
Message => "Caught exception");
end if;
end except1;
1 change: 1 addition & 0 deletions UNIT_TESTS/except1.ald
Expand Up @@ -3,4 +3,5 @@ utest.ali
raiser.ali
../lua.ali
../lua-lib.ali
../lua-config.ali
../lua-ext.o
6 changes: 3 additions & 3 deletions UNIT_TESTS/except1.exp
@@ -1,5 +1,5 @@
registered panic handler
causing panic...
inside raiser.raiser...
caught raiser.raiser_error
[0] pass: caught exception
inside Raiser.Raiser...
Caught Raiser.Raiser_Error
[0] Pass: Caught exception
2 changes: 1 addition & 1 deletion conf-adacflags
@@ -1,4 +1,4 @@
-g -fstack-check -gnatwadleG -gnatVa -gnato -gnata -gnatW8 -gnatiw -gnaty2aAbdefhiklnprStu
-O2 -g -fstack-check -gnatwadleG -gnatVa -gnato -gnata -gnatW8 -gnatiw -gnaty2aAbdefhiklnprStu

The first line of this file is passed to the Ada compiler as extra flags.

Expand Down
2 changes: 1 addition & 1 deletion conf-adacomp
@@ -1,4 +1,4 @@
gcc-4.3
gcc43

The first line of this file is used as the path or location of the Ada compiler.
This program is used to compile single source files into object files.
2 changes: 1 addition & 1 deletion conf-cc
@@ -1,4 +1,4 @@
gcc-4.3
gcc43

The first line of this file is used as the path or location of the C compiler.
This program is used to compile single source files into object files.
2 changes: 1 addition & 1 deletion conf-cflags
@@ -1,4 +1,4 @@
-O2 -g -W -Werror -Wall -Wno-unused-parameter
-O2 -g -W -Werror -Wall -std=c99 -pedantic-errors -Wno-unused-parameter

The first line of this file is passed to the C compiler as additional flags.
This file is optional and may be deleted (remember to regenerate the Makefile
Expand Down
2 changes: 1 addition & 1 deletion conf-ld
@@ -1,4 +1,4 @@
gcc-4.3
gcc43

The first line of this file is used as the path or location of the C linker.
This program is used to combine object files and libraries into executables.
13 changes: 10 additions & 3 deletions gnat.adc
@@ -1,7 +1,10 @@

-- ./lua.apk
pragma source_file_name(lua, spec_file_name => "lua.ads");
pragma source_file_name(lua, body_file_name => "lua.adb");
-- ./lua-check_raise.apk
pragma source_file_name(Lua.Check_Raise, spec_file_name => "lua-check_raise.ads");
pragma source_file_name(Lua.Check_Raise, body_file_name => "lua-check_raise.adb");

-- ./lua-config.apk
pragma source_file_name(Lua.Config, spec_file_name => "lua-config.ads");

-- ./lua-lib.apk
pragma source_file_name(lua.lib, spec_file_name => "lua-lib.ads");
Expand All @@ -11,6 +14,10 @@ pragma source_file_name(lua.lib, body_file_name => "lua-lib.adb");
pragma source_file_name(lua.user_data, spec_file_name => "lua-user_data.ads");
pragma source_file_name(lua.user_data, body_file_name => "lua-user_data.adb");

-- ./lua.apk
pragma source_file_name(lua, spec_file_name => "lua.ads");
pragma source_file_name(lua, body_file_name => "lua.adb");

-- UNIT_TESTS/raiser.apk
pragma source_file_name(raiser, spec_file_name => "raiser.ads");
pragma source_file_name(raiser, body_file_name => "raiser.adb");
Expand Down
16 changes: 16 additions & 0 deletions insthier.c
Expand Up @@ -9,27 +9,43 @@ struct install_item insthier[] = {
{INST_MKDIR, 0, 0, ctxt_repos, 0, 0, 0755},
{INST_COPY, "lua-ada-conf.c", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-ext.c", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-check_raise.ads", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-check_raise.ads", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-config.ads", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-config.ads", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-lib.ads", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-lib.ads", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-user_data.ads", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-user_data.ads", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua.ads", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua.ads", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-check_raise.adb", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-check_raise.adb", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-lib.adb", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-lib.adb", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-user_data.adb", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-user_data.adb", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua.adb", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua.adb", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua_check_exception.adb", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua_check_exception.adb", 0, ctxt_incdir, 0, 0, 0644},
{INST_COPY, "lua-check_raise.ali", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-check_raise.ali", 0, ctxt_incdir, 0, 0, 0444},
{INST_COPY, "lua-config.ali", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-config.ali", 0, ctxt_incdir, 0, 0, 0444},
{INST_COPY, "lua-lib.ali", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-lib.ali", 0, ctxt_incdir, 0, 0, 0444},
{INST_COPY, "lua-user_data.ali", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-user_data.ali", 0, ctxt_incdir, 0, 0, 0444},
{INST_COPY, "lua.ali", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua.ali", 0, ctxt_incdir, 0, 0, 0444},
{INST_COPY, "lua_check_exception.ali", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua_check_exception.ali", 0, ctxt_incdir, 0, 0, 0444},
{INST_COPY, "lua-ada.sld", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY, "lua-ada.a", "liblua-ada.a", ctxt_slibdir, 0, 0, 0644},
{INST_COPY, "lua-ada-conf.ld", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY_EXEC, "lua-ada-conf", 0, ctxt_bindir, 0, 0, 0755},
{INST_COPY, "lua-check-exception.ald", 0, ctxt_repos, 0, 0, 0644},
{INST_COPY_EXEC, "lua-check-exception", 0, ctxt_bindir, 0, 0, 0755},
};
unsigned long insthier_len = sizeof(insthier) / sizeof(struct install_item);
2 changes: 2 additions & 0 deletions lua-ada.sld
@@ -1,3 +1,5 @@
lua-check_raise.o
lua-config.o
lua-ext.o
lua-lib.o
lua-user_data.o
Expand Down
3 changes: 3 additions & 0 deletions lua-check-exception.ald
@@ -0,0 +1,3 @@
lua_check_exception.ali
lua-check_raise.ali
lua-ext.o
11 changes: 11 additions & 0 deletions lua-check_raise.adb
@@ -0,0 +1,11 @@
package body Lua.Check_Raise is

function Check_Raise (State : Lua.State_t) return Lua.Integer_t is
use type Lua.State_t;
begin
pragma Assert (State /= Lua.State_Error);
raise Check_Raise_Error;
return 0;
end Check_Raise;

end Lua.Check_Raise;
8 changes: 8 additions & 0 deletions lua-check_raise.ads
@@ -0,0 +1,8 @@
package Lua.Check_Raise is

function Check_Raise (State : Lua.State_t) return Lua.Integer_t;
pragma Convention (C, Check_Raise);

Check_Raise_Error : exception;

end Lua.Check_Raise;
1 change: 1 addition & 0 deletions lua-check_raise.apk
@@ -0,0 +1 @@
Lua.Check_Raise lua-check_raise.ads lua-check_raise.adb
2 changes: 2 additions & 0 deletions lua-config.ads.mff
@@ -0,0 +1,2 @@
lua-config.ads: lua-config.sh lua-check-exception
./lua-config.sh > lua-config.ads.tmp && mv lua-config.ads.tmp lua-config.ads
Empty file added lua-config.ads.tbc
Empty file.
1 change: 1 addition & 0 deletions lua-config.apk
@@ -0,0 +1 @@
Lua.Config lua-config.ads
33 changes: 33 additions & 0 deletions lua-config.sh
@@ -0,0 +1,33 @@
#!/bin/sh

cleanup()
{

}

fatal()
{
echo "fatal: $1" 1>&2
cleanup
exit 1
}

ret_text=`./lua-check-exception`
ret_code=$?
if [ $ret_code -eq 0 ]
then
can_catch="True"
else
can_catch="False"
fi

cat <<EOF
package Lua.Config is
Can_Propagate_Exceptions : constant Boolean := ${can_catch};
end Lua.Config;
EOF

cleanup
exit 0
32 changes: 32 additions & 0 deletions lua_check_exception.adb
@@ -0,0 +1,32 @@
with Lua;
with Lua.Check_Raise;

procedure Lua_Check_Exception is
State : Lua.State_t;
Caught : Boolean := False;

use type Lua.State_t;
use type Lua.Number_t;
begin
State := Lua.Open;

if State = Lua.State_Error then
raise Program_Error;
end if;

Lua.At_Panic
(State => State,
Panic_Function => Lua.Check_Raise.Check_Raise'Access);

begin
Lua.Push_Number (State, -1.0);
Lua.Call (State, 1, 1);
exception
when Lua.Check_Raise.Check_Raise_Error => Caught := True;
end;

if not Caught then
raise Program_Error;
end if;

end Lua_Check_Exception;

0 comments on commit b2ab654

Please sign in to comment.