[m-rev.] diff: bugfix for glut/opengl bindings

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Nov 25 19:12:30 AEDT 2004


Estimated hours taken: 0.1
Branches main.

Fix some problems with some of the libraries
in the extras distribution.  The main problem
was that several of the foreign procs in the glut/opengl
bindings promised to not make calls to mercury when
in fact they did.

Also, use the MR_YES and MR_NO constants to return
boolean values from foreign procs.

graphics/mercury_glut/glut.m:
graphics/mercury_glut/glut.overlay.m:
graphics/mercury_glut/glut.window.m:
graphics/mercury_opengl/mogl.m:
	Replace use of MR_bool_return_{yes,no} with the MR_YES
 	and MR_NO constants Ian added the other day.

	Make sure that the foreign procs in these module
 	don't promise will_not_call_mercury when they do.

	Reformat some C code so that it adheres to our
 	C coding standard.

posix/posix.select.m:
	Use symbolic constants for the values of yes and no
	instead of integers.

Julien.


Index: graphics/mercury_glut/glut.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.m,v
retrieving revision 1.2
diff -u -r1.2 glut.m
--- graphics/mercury_glut/glut.m	9 Jun 2004 04:44:41 -0000	1.2
+++ graphics/mercury_glut/glut.m	25 Nov 2004 07:57:33 -0000
@@ -391,12 +391,12 @@
 :- pred glut.has_device_2(int::in, bool::out, io::di, io::uo) is det.
 :- pragma foreign_proc("C",
 	glut.has_device_2(Device::in, Res::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure, terminates],
+	[will_not_call_mercury, promise_pure],
 "
 	if(glutDeviceGet((GLenum) Device)) {
-		Res = ML_bool_return_yes();
+		Res = MR_YES;
 	} else {
-		Res = ML_bool_return_no();
+		Res = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -466,12 +466,12 @@

 :- pragma foreign_proc("C",
 	glut.display_mode_possible(IsPossible::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure, terminates],
+	[will_not_call_mercury, promise_pure],
 "
 	if(glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
-		IsPossible = ML_bool_return_yes();
+		IsPossible = MR_YES;
 	} else {
-		IsPossible = ML_bool_return_no();
+		IsPossible = MR_NO;
 	}
 	IO = IO0;
 ").
Index: graphics/mercury_glut/glut.overlay.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.overlay.m,v
retrieving revision 1.1
diff -u -r1.1 glut.overlay.m
--- graphics/mercury_glut/glut.overlay.m	17 May 2004 08:28:52 -0000	1.1
+++ graphics/mercury_glut/glut.overlay.m	24 Nov 2004 05:41:55 -0000
@@ -123,12 +123,12 @@

 :- pragma foreign_proc("C",
 	overlay.possible(Result::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure, terminates],
+	[will_not_call_mercury, promise_pure],
 "
 	if (glutLayerGet(GLUT_OVERLAY_POSSIBLE)) {
-		Result = ML_bool_return_yes();
+		Result = MR_YES;
 	} else {
-		Result = ML_bool_return_no();
+		Result = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -137,18 +137,18 @@

 overlay.establish(Result, !IO) :-
 	overlay.establish_2(Result0, !IO),
-	Result = ( Result0 = 1 -> ok ; error("Unable to establish overlay.") ).
+	Result = ( Result0 = yes -> ok ; error("Unable to establish overlay.")).

-:- pred overlay.establish_2(int::out, io::di, io::uo) is det.
+:- pred overlay.establish_2(bool::out, io::di, io::uo) is det.
 :- pragma foreign_proc("C",
 	overlay.establish_2(Result::out, IO0::di, IO::uo),
 	[will_not_call_mercury, promise_pure],
 "
 	if (glutLayerGet(GLUT_OVERLAY_POSSIBLE)) {
 		glutEstablishOverlay();
-		Result = 1;
+		Result = MR_YES;
 	} else {
-		Result = 0;
+		Result = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -264,9 +264,9 @@
 	[will_not_call_mercury, promise_pure],
 "
 	if (glutLayerGet(GLUT_NORMAL_DAMAGED)) {
-		Result = ML_bool_return_yes();
+		Result = MR_YES;
 	} else {
-		Result = ML_bool_return_no();
+		Result = MR_NO;
 	}
 	IO = IO0;
 ").
Index: graphics/mercury_glut/glut.window.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_glut/glut.window.m,v
retrieving revision 1.1
diff -u -r1.1 glut.window.m
--- graphics/mercury_glut/glut.window.m	17 May 2004 08:28:52 -0000	1.1
+++ graphics/mercury_glut/glut.window.m	25 Nov 2004 07:58:01 -0000
@@ -629,34 +629,34 @@
 	window.is_double_buffered(DB::out, IO0::di, IO::uo),
 	[will_not_call_mercury, promise_pure],
 "
-	if(glutGet(GLUT_WINDOW_DOUBLEBUFFER)) {
-		DB = ML_bool_return_yes();
+	if (glutGet(GLUT_WINDOW_DOUBLEBUFFER)) {
+		DB = MR_YES;
 	} else {
-		DB = ML_bool_return_no();
+		DB = MR_NO;
 	}
 	IO = IO0;
 ").

 :- pragma foreign_proc("C",
 	window.is_stereo(Stereo::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure, terminates],
+	[will_not_call_mercury, promise_pure],
 "
-	if(glutGet(GLUT_WINDOW_STEREO)) {
-		Stereo = ML_bool_return_yes();
+	if (glutGet(GLUT_WINDOW_STEREO)) {
+		Stereo = MR_YES;
 	} else {
-		Stereo = ML_bool_return_no();
+		Stereo = MR_NO;
 	}
 	IO = IO0;
 ").

 :- pragma foreign_proc("C",
 	window.is_rgba(RGBA::out, IO0::di, IO::uo),
-	[will_not_call_mercury, promise_pure, terminates],
+	[will_not_call_mercury, promise_pure],
 "
-	if(glutGet(GLUT_WINDOW_RGBA)) {
-		RGBA = ML_bool_return_yes();
+	if (glutGet(GLUT_WINDOW_RGBA)) {
+		RGBA = MR_YES;
 	} else {
-		RGBA = ML_bool_return_no();
+		RGBA = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -828,12 +828,12 @@

 :- pragma foreign_proc("C",
 	window.has_overlay(Result::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure, terminates],
+	[will_not_call_mercury, promise_pure],
 "
 	if (glutLayerGet(GLUT_HAS_OVERLAY)) {
-		Result = ML_bool_return_yes();
+		Result = MR_YES;
 	} else {
-		Result = ML_bool_return_no();
+		Result = MR_NO;
 	}
 	IO = IO0;
 ").
Index: graphics/mercury_opengl/mogl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/graphics/mercury_opengl/mogl.m,v
retrieving revision 1.11
diff -u -r1.11 mogl.m
--- graphics/mercury_opengl/mogl.m	8 Jun 2004 04:47:47 -0000	1.11
+++ graphics/mercury_opengl/mogl.m	24 Nov 2004 06:33:19 -0000
@@ -2584,7 +2584,7 @@

 	textures = MR_GC_NEW_ARRAY(GLuint, NumTextures);

-	while(!MR_list_is_empty(Textures)) {
+	while (!MR_list_is_empty(Textures)) {
 		textures[i++] = MR_list_head(Textures);
 		Textures = MR_list_tail(Textures);
 	}
@@ -2612,7 +2612,7 @@

 	Textures = MR_list_empty();

-	for(i = 0; i < Num; i++) {
+	for (i = 0; i < Num; i++) {
 		Textures = MR_list_cons(new_textures[i], Textures);
 	}

@@ -2623,12 +2623,12 @@

 :- pragma foreign_proc("C",
 	is_texture(Name::in, IsList::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure],
+	[will_not_call_mercury, promise_pure],
 "
-	if(glIsTexture(Name)) {
-		IsList = ML_bool_return_yes();
+	if (glIsTexture(Name)) {
+		IsList = MR_YES;
 	} else {
-		IsList = ML_bool_return_no();
+		IsList = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -3516,9 +3516,9 @@
 	[may_call_mercury, promise_pure],
 "
 	if (glIsList((GLuint) L)) {
-		R = ML_bool_return_yes();
+		R = MR_YES;
 	} else {
-		R = ML_bool_return_no();
+		R = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -3646,16 +3646,15 @@
 	control_flag_to_int_and_offset(Flag, Int, Offset),
 	is_enabled_2(Int, Offset, IsEnabled, !IO).

-	% XXX Add `terminates' attribute.
 :- pred is_enabled_2(int::in, int::in, bool::out, io::di, io::uo) is det.
 :- pragma foreign_proc("C",
 	is_enabled_2(FlagVal::in, Offset::in, R::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure],
+	[will_not_call_mercury, promise_pure],
 "
 	if (glIsEnabled(control_flag_flags[FlagVal] + Offset)) {
-		R = ML_bool_return_yes();
+		R = MR_YES;
 	} else {
-		R = ML_bool_return_no();
+		R = MR_NO;
 	}
 	IO = IO0;
 ").
@@ -3816,16 +3815,16 @@
 :- pred get_boolean_2(int::in, bool::out, io::di, io::uo) is det.
 :- pragma foreign_proc("C",
 	get_boolean_2(Param::in, Value::out, IO0::di, IO::uo),
-	[may_call_mercury, promise_pure],
+	[will_not_call_mercury, promise_pure],
 "
 	GLboolean value;

 	glGetBooleanv(single_boolean_state_flags[Param], &value);

 	if (value == GL_TRUE) {
-		Value = ML_bool_return_yes();
+		Value = MR_YES;
 	} else {
-		Value = ML_bool_return_no();
+		Value = MR_NO;
 	}

 	IO = IO0;
@@ -3853,34 +3852,34 @@
 :- pragma foreign_proc("C",
 	get_boolean_2(Param::in, V0::out, V1::out, V2::out, V3::out, IO0::di,
 		IO::uo),
-	[may_call_mercury, promise_pure],
+	[will_not_call_mercury, promise_pure],
 "
 	GLboolean values[4];

 	glGetBooleanv(quad_boolean_state_flags[Param], values);

 	if (values[0] == GL_TRUE) {
-		V0 = ML_bool_return_yes();
+		V0 = MR_YES;
 	} else {
-		V0 = ML_bool_return_no();
+		V0 = MR_NO;
 	}

 	if (values[1] == GL_TRUE) {
-		V1 = ML_bool_return_yes();
+		V1 = MR_YES;
 	} else {
-		V1 = ML_bool_return_no();
+		V1 = MR_NO;
 	}

 	if (values[2] == GL_TRUE) {
-		V2 = ML_bool_return_yes();
+		V2 = MR_YES;
 	} else {
-		V2 = ML_bool_return_no();
+		V2 = MR_NO;
 	}

 	if (values[3] == GL_TRUE) {
-		V3 = ML_bool_return_yes();
+		V3 = MR_YES;
 	} else {
-		V3 = ML_bool_return_no();
+		V3 = MR_NO;
 	}

 	IO = IO0;
Index: posix/posix.select.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/posix/posix.select.m,v
retrieving revision 1.3
diff -u -r1.3 posix.select.m
--- posix/posix.select.m	5 Dec 2000 02:07:23 -0000	1.3
+++ posix/posix.select.m	24 Nov 2004 06:06:33 -0000
@@ -109,7 +109,7 @@

 :- pragma c_code(fd_isset(Fd::in, Fds::in, Res::out, IO0::di, IO::uo),
 		[will_not_call_mercury, thread_safe], "{
-	Res = (ME_fd_isset(Fd, (fd_set *) Fds) ? 1 : 0 );
+	Res = (ME_fd_isset(Fd, (fd_set *) Fds) ? MR_YES : MR_NO );
 	IO = IO0;
 }").


--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list