Segmentaion fault #2

Closed
olleharstedt opened this Issue Nov 30, 2012 · 5 comments

Projects

None yet

2 participants

@olleharstedt

Hello!

Thank you for porting Lua API to OCaml! I'm planning to use it in a
project, but having some problems making the first steps. Perhaps you
could help?

This is what I'm trying to compile:

1 open Lua_api;;
2
3 let _ =
4 print_endline "1";;
5 let ls = LuaL.newstate () in
6 print_endline "2";;

Using "ocamlfind opt -o lua -package lua lua.cmxa lua_test.ml" it
compiles fine, but get "1 \ Segmentation fault (core dumped)" when
run. Same problem when using ocamlc.

My Lua version:

Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

Using Ubuntu 12.10.

This C-file test compiles and runs without problems:

1 #include <stdio.h>
2 #include "lua.h"
3 #include "lauxlib.h"
4 #include "lualib.h"
5
6 int main(void) {
7 fprintf(stderr, "1\n");
8 lua_State *L = luaL_newstate();
9 fprintf(stderr, "2\n");
10 lua_close(L);
11 }

Any idea what causes this error?

Kind regards
Olle

@pdonadeo pdonadeo was assigned Nov 30, 2012
@olleharstedt

Some additional information from my building of the package.

./configure

Configuration:
ocamlfind: ........................................................................................... /usr/bin/ocamlfind
ocamlc: .............................................................................................. /usr/bin/ocamlc
ocamlopt: ............................................................................................ /usr/bin/ocamlopt
ocamlbuild: .......................................................................................... /usr/bin/ocamlbuild
Package name: ........................................................................................ ocaml-lua
Package version: ..................................................................................... 1.0
os_type: ............................................................................................. Unix
system: .............................................................................................. linux
architecture: ........................................................................................ amd64
ccomp_type: .......................................................................................... cc
ocaml_version: ....................................................................................... 3.12.1
standard_library_default: ............................................................................ /usr/lib/ocaml
standard_library: .................................................................................... /usr/lib/ocaml
standard_runtime: .................................................................................... /usr/bin/ocamlrun
bytecomp_c_compiler: ................................................................................. gcc -D_FILE_OFFSET_BITS=64 -D_REENTRANT -fPIC
native_c_compiler: ................................................................................... gcc -D_FILE_OFFSET_BITS=64 -D_REENTRANT
model: ............................................................................................... default
ext_obj: ............................................................................................. .o
ext_asm: ............................................................................................. .s
ext_lib: ............................................................................................. .a
ext_dll: ............................................................................................. .so
default_executable_name: ............................................................................. a.out
systhread_supported: ................................................................................. true
Install architecture-independent files dir: .......................................................... /usr/local
Install architecture-dependent files in dir: ......................................................... $prefix
User executables: .................................................................................... $exec_prefix/bin
System admin executables: ............................................................................ $exec_prefix/sbin
Program executables: ................................................................................. $exec_prefix/libexec
Read-only single-machine data: ....................................................................... $prefix/etc
Modifiable architecture-independent data: ............................................................ $prefix/com
Modifiable single-machine data: ...................................................................... $prefix/var
Object code libraries: ............................................................................... $exec_prefix/lib
Read-only arch-independent data root: ................................................................ $prefix/share
Read-only architecture-independent data: ............................................................. $datarootdir
Info documentation: .................................................................................. $datarootdir/info
Locale-dependent data: ............................................................................... $datarootdir/locale
Man documentation: ................................................................................... $datarootdir/man
Documentation root: .................................................................................. $datarootdir/doc/$pkg_name
HTML documentation: .................................................................................. $docdir
DVI documentation: ................................................................................... $docdir
PDF documentation: ................................................................................... $docdir
PS documentation: .................................................................................... $docdir
findlib_version: ..................................................................................... 1.3.1
is_native: ........................................................................................... true
suffix_program: ......................................................................................
Remove a file.: ...................................................................................... rm -f
Remove a directory.: ................................................................................. rm -rf
Turn ocaml debug flag on: ............................................................................ true
Turn ocaml profile flag on: .......................................................................... false
Compiler support generation of .cmxs.: ............................................................... true
OCamlbuild additional flags: .........................................................................
The pkg-config name of lua can be lua5.1 or lua. If you are in
the first case, disable this flag.: ... true
Build all: ........................................................................................... false
Create and run programs to reveal memory leaks: ...................................................... false
Compile examples: .................................................................................... false
Create documentations: ............................................................................... true
Compile tests executable and library and run them: ................................................... false
pkg_unix: ............................................................................................ /usr/lib/ocaml
ocamldoc: ............................................................................................ /usr/bin/ocamldoc

./make

ocaml setup.ml -build
Finished, 1 target (0 cached) in 00:00:00.
ocamlfind ocamlc -ccopt -O3 -ccopt -Wall -ccopt -ggdb -ccopt -Isrc/ -ccopt -I/usr/include/lua5.1 -c src/stub.c
src/stub.c: In function ‘finalize_thread’:
src/stub.c:168:9: warning: variable ‘index’ set but not used [-Wunused-but-set-variable]
Finished, 21 targets (0 cached) in 00:00:04.

./make doc

ocaml setup.ml -build
Finished, 0 targets (0 cached) in 00:00:00.
Finished, 21 targets (20 cached) in 00:00:00.
ocaml setup.ml -doc
Finished, 0 targets (0 cached) in 00:00:00.
ocamlfind ocamldoc -dump src/lua_api.odoc -package unix -I src src/lua_api.ml
Warning: Module or module type Lua_aux_lib not found
Warning: Module or module type Lua_api_lib not found
Warning: Module or module type Lua_aux_lib not found
Warning: Module or module type Lua_api_lib not found
Warning: Element Lua_api_lib not found
Warning: Element Lua_aux_lib not found
ocamlfind ocamldoc -dump src/lua_api_lib.odoc -package unix -I src src/lua_api_lib.mli
Warning: Element Lua_aux_lib.newstate not found
Finished, 11 targets (5 cached) in 00:00:02.

@pdonadeo
Owner
pdonadeo commented Dec 1, 2012

Oh, thanks for the informations, I'm debugging, and I'm in the right direction.

@olleharstedt

Great :)

@pdonadeo
Owner
pdonadeo commented Dec 2, 2012

Fixed with commit 81d800f.

I'm currently working to another issue (#1) so I don't plan to release another version of the library too soon. Please, check out the master, the fix will be present in the next release, with the compatibility with LuaJIT.

@pdonadeo pdonadeo closed this Dec 2, 2012
@olleharstedt

Awesome! Thank you very much, it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment