Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include & external #2943

Closed
vicuna opened this issue Sep 3, 2001 · 2 comments
Closed

include & external #2943

vicuna opened this issue Sep 3, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Sep 3, 2001

Original bug ID: 506
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Winfried Dreckmann
Version: Ocaml 3.02
OS: Suse Linux 6.4 on PowerPC
Submission from: t4o902p30.telia.com (62.20.255.150)

This may be related to bug 505.

Including modules with external C functions gives segfaults or wrong results.
My smallest examples is as follows:

file test.ml

module M1 = struct
external test : int -> int = "test"
end
module M2 = struct
include M1
let foo = ref true
end

file test.c

include "/usr/local/lib/ocaml/caml/mlvalues.h"
value test(value x)
{
return x;
}

Creating a toplevel I get:

ocamlmktop -custom test.ml test.c -o mytop
./mytop
Objective Caml version 3.02

Test.M2.foo;;

Speicherzugriffsfehler

i. e. segmentation fault. With "let foo = 7" I get

Test.M2.foo;;

  • : int = 0

The same happens with standalone programs.

@vicuna
Copy link
Author

vicuna commented Sep 10, 2001

Comment author: administrator

This may be related to bug 505.
Including modules with external C functions gives segfaults or wrong results.

You're 100% percent correct, including the fact that it's the same bug
as #2941. I just fixed both bugs. A patch against 3.02 is included
below in case you'd like to give it more testing.

Thanks for the bug report,

  • Xavier Leroy

Index: csl/typing/typemod.ml
diff -c csl/typing/typemod.ml:1.43 csl/typing/typemod.ml:1.45
*** csl/typing/typemod.ml:1.43 Mon Jul 23 17:35:49 2001
--- csl/typing/typemod.ml Mon Sep 10 17:11:14 2001


*** 10,16 ****
(* *)
(***********************************************************************)

! (* $Id: typemod.ml,v 1.43 2001/07/23 15:35:49 xleroy Exp $ *)

(* Type-checking of the module language *)

--- 10,16 ----
(* *)
(***********************************************************************)

! (* $Id: typemod.ml,v 1.45 2001/09/10 15:11:14 xleroy Exp $ *)

(* Type-checking of the module language *)


*** 263,273 ****

(* Extract the list of "value" identifiers bound by a signature.
"Value" identifiers are identifiers for signature components that
! correspond to a run-time value: values, exceptions, modules, classes *)

let rec bound_value_identifiers = function
[] -> []
! | Tsig_value(id, decl) :: rem -> id :: bound_value_identifiers rem
| Tsig_exception(id, decl) :: rem -> id :: bound_value_identifiers rem
| Tsig_module(id, mty) :: rem -> id :: bound_value_identifiers rem
| Tsig_class(id, decl) :: rem -> id :: bound_value_identifiers rem
--- 263,275 ----

(* Extract the list of "value" identifiers bound by a signature.
"Value" identifiers are identifiers for signature components that
! correspond to a run-time value: values, exceptions, modules, classes.
! Note: manifest primitives do not correspond to a run-time value! *)

let rec bound_value_identifiers = function
[] -> []
! | Tsig_value(id, {val_kind = Val_reg}) :: rem ->
! id :: bound_value_identifiers rem
| Tsig_exception(id, decl) :: rem -> id :: bound_value_identifiers rem
| Tsig_module(id, mty) :: rem -> id :: bound_value_identifiers rem
| Tsig_class(id, decl) :: rem -> id :: bound_value_identifiers rem


*** 412,418 ****
let (path, mty) = type_module_path env loc lid in
let sg = extract_sig_open env loc mty in
type_struct (Env.open_signature path sg env) srem
! | {pstr_desc = Pstr_class cl} :: srem ->
let (classes, new_env) = Typeclass.class_declarations env cl in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
(Tstr_class
--- 414,423 ----
let (path, mty) = type_module_path env loc lid in
let sg = extract_sig_open env loc mty in
type_struct (Env.open_signature path sg env) srem
! | {pstr_desc = Pstr_class cl; pstr_loc = loc} :: srem ->
! List.iter
! (fun {pci_name = name} -> check "type" loc type_names name)
! cl;
let (classes, new_env) = Typeclass.class_declarations env cl in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
(Tstr_class


*** 432,438 ****
Tsig_type(i'', d''); Tsig_type(i''', d''')])
classes [sig_rem]),
final_env)
! | {pstr_desc = Pstr_class_type cl} :: srem ->
let (classes, new_env) = Typeclass.class_type_declarations env cl in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
(Tstr_cltype
--- 437,446 ----
Tsig_type(i'', d''); Tsig_type(i''', d''')])
classes [sig_rem]),
final_env)
! | {pstr_desc = Pstr_class_type cl; pstr_loc = loc} :: srem ->
! List.iter
! (fun {pci_name = name} -> check "type" loc type_names name)
! cl;
let (classes, new_env) = Typeclass.class_type_declarations env cl in
let (str_rem, sig_rem, final_env) = type_struct new_env srem in
(Tstr_cltype

@vicuna
Copy link
Author

vicuna commented Sep 10, 2001

Comment author: administrator

Fixed 2001-09-10 by XL.

@vicuna vicuna closed this as completed Sep 10, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant