unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Re: [PATCH] Verify Size of Objcode Headers
@ 2010-06-20 23:59 Noah Lavine
  0 siblings, 0 replies; 4+ messages in thread
From: Noah Lavine @ 2010-06-20 23:59 UTC (permalink / raw)
  To: ludo; +Cc: guile-devel

Thanks for the corrections. I think this patch addresses them.

Noah

Add static checks to make sure that the statically-generated object code
headers in continuations.c, control.c, foreign.c, gsubr.c and smob.c are the
same length as the struct scm_objcode data type in objcodes.h.
---
 libguile/continuations.c |    5 +++++
 libguile/control.c       |    4 ++++
 libguile/foreign.c       |    4 ++++
 libguile/gsubr.c         |    5 +++++
 libguile/smob.c          |    5 ++++-
 5 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/libguile/continuations.c b/libguile/continuations.c
index dc504f0..0ded7e7 100644
--- a/libguile/continuations.c
+++ b/libguile/continuations.c
@@ -37,10 +37,12 @@
 #include "libguile/eval.h"
 #include "libguile/vm.h"
 #include "libguile/instructions.h"
+#include "libguile/objcodes.h"
 
 #include "libguile/validate.h"
 #include "libguile/continuations.h"
 
+#include "verify.h" /* from Gnulib, in guile/lib */
 

 
 static scm_t_bits tc16_continuation;
@@ -537,6 +539,9 @@ SCM_DEFINE (scm_with_continuation_barrier, "with-continuation-barrier", 1,0,0,
 void
 scm_init_continuations ()
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER(5,5) } SCM_UNUSED;
+  verify (sizeof (dummy) == sizeof (struct scm_objcode));
+
   tc16_continuation = scm_make_smob_type ("continuation", 0);
   scm_set_smob_print (tc16_continuation, continuation_print);
 #include "libguile/continuations.x"
diff --git a/libguile/control.c b/libguile/control.c
index 6c20675..605b2f9 100644
--- a/libguile/control.c
+++ b/libguile/control.c
@@ -26,6 +26,7 @@
 #include "libguile/instructions.h"
 #include "libguile/vm.h"
 
+#include "verify.h" /* from Gnulib, in guile/lib */
 

 
 
@@ -271,6 +272,9 @@ scm_i_prompt_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
 void
 scm_init_control (void)
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER(5,5) } SCM_UNUSED;
+  verify (sizeof (dummy) == sizeof (struct scm_objcode));
+
 #include "libguile/control.x"
 }
 
diff --git a/libguile/foreign.c b/libguile/foreign.c
index aae4c67..30dcf60 100644
--- a/libguile/foreign.c
+++ b/libguile/foreign.c
@@ -31,6 +31,7 @@
 #include "libguile/instructions.h"
 #include "libguile/foreign.h"
 
+#include "verify.h" /* from Gnulib, in guile/lib */
 

 
 SCM_SYMBOL (sym_void, "void");
@@ -1028,6 +1029,9 @@ scm_i_foreign_call (SCM foreign, const SCM *argv)
 static void
 scm_init_foreign (void)
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER } SCM_UNUSED;
+  verify (sizeof (dummy) == sizeof (struct scm_objcode));
+
 #ifndef SCM_MAGIC_SNARFER
 #include "libguile/foreign.x"
 #endif
diff --git a/libguile/gsubr.c b/libguile/gsubr.c
index de4bff6..21580b7 100644
--- a/libguile/gsubr.c
+++ b/libguile/gsubr.c
@@ -33,6 +33,8 @@
 #include "libguile/programs.h"
 
 #include "libguile/private-options.h"
+
+#include "verify.h" /* from Gnulib, in guile/lib */
 

 /*
  * gsubr.c
@@ -878,6 +880,9 @@ gsubr_21l(SCM req1, SCM req2, SCM opt, SCM rst)
 void
 scm_init_gsubr()
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER } SCM_UNUSED;
+  verify (sizeof (dummy) == sizeof (struct scm_objcode));
+
 #ifdef GSUBR_TEST
   scm_c_define_gsubr ("gsubr-2-1-l", 2, 1, 1, gsubr_21l); /* example */
 #endif
diff --git a/libguile/smob.c b/libguile/smob.c
index 171db8d..676c83b 100644
--- a/libguile/smob.c
+++ b/libguile/smob.c
@@ -42,7 +42,7 @@
 #include "libguile/bdw-gc.h"
 #include <gc/gc_mark.h>
 
-
+#include "verify.h" /* from Gnulib, in guile/lib */
 

 
 /* scm_smobs scm_numsmob
@@ -598,6 +598,9 @@ void
 scm_smob_prehistory ()
 {
   long i;
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER } SCM_UNUSED;
+
+  verify (sizeof (dummy) == sizeof (struct scm_objcode));
 
   smob_gc_kind = GC_new_kind (GC_new_free_list (),
 			      GC_MAKE_PROC (GC_new_proc (smob_mark), 0),
-- 
1.7.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] Verify Size of Objcode Headers
@ 2010-06-20 19:44 Noah Lavine
  2010-06-20 20:30 ` Andy Wingo
  2010-06-20 21:22 ` Ludovic Courtès
  0 siblings, 2 replies; 4+ messages in thread
From: Noah Lavine @ 2010-06-20 19:44 UTC (permalink / raw)
  To: guile-devel

Add static checks to make sure that the statically-generated object code
headers in continuations.c, control.c, foreign.c, gsubr.c and smob.c are the
same length as the struct scm_objcode data type in objcodes.h.
---
 libguile/continuations.c |    4 ++++
 libguile/control.c       |    3 +++
 libguile/foreign.c       |    3 +++
 libguile/gsubr.c         |    3 +++
 libguile/objcodes.h      |    5 +++++
 libguile/smob.c          |    3 +++
 6 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/libguile/continuations.c b/libguile/continuations.c
index dc504f0..e99043f 100644
--- a/libguile/continuations.c
+++ b/libguile/continuations.c
@@ -37,6 +37,7 @@
 #include "libguile/eval.h"
 #include "libguile/vm.h"
 #include "libguile/instructions.h"
+#include "libguile/objcodes.h"

 #include "libguile/validate.h"
 #include "libguile/continuations.h"
@@ -537,6 +538,9 @@ SCM_DEFINE (scm_with_continuation_barrier,
"with-continuation-barrier", 1,0,0,
 void
 scm_init_continuations ()
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER(5,5) };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
   tc16_continuation = scm_make_smob_type ("continuation", 0);
   scm_set_smob_print (tc16_continuation, continuation_print);
 #include "libguile/continuations.x"
diff --git a/libguile/control.c b/libguile/control.c
index 6c20675..91fedf1 100644
--- a/libguile/control.c
+++ b/libguile/control.c
@@ -271,6 +271,9 @@ scm_i_prompt_print (SCM exp, SCM port,
scm_print_state *pstate SCM_UNUSED)
 void
 scm_init_control (void)
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER(5,5) };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
 #include "libguile/control.x"
 }

diff --git a/libguile/foreign.c b/libguile/foreign.c
index aae4c67..60a01a1 100644
--- a/libguile/foreign.c
+++ b/libguile/foreign.c
@@ -1028,6 +1028,9 @@ scm_i_foreign_call (SCM foreign, const SCM *argv)
 static void
 scm_init_foreign (void)
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
 #ifndef SCM_MAGIC_SNARFER
 #include "libguile/foreign.x"
 #endif
diff --git a/libguile/gsubr.c b/libguile/gsubr.c
index de4bff6..c01471c 100644
--- a/libguile/gsubr.c
+++ b/libguile/gsubr.c
@@ -878,6 +878,9 @@ gsubr_21l(SCM req1, SCM req2, SCM opt, SCM rst)
 void
 scm_init_gsubr()
 {
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER };
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);
+
 #ifdef GSUBR_TEST
   scm_c_define_gsubr ("gsubr-2-1-l", 2, 1, 1, gsubr_21l); /* example */
 #endif
diff --git a/libguile/objcodes.h b/libguile/objcodes.h
index 2bff9aa..cb86e63 100644
--- a/libguile/objcodes.h
+++ b/libguile/objcodes.h
@@ -21,6 +21,8 @@

 #include <libguile.h>

+#include <verify.h> /* from Gnulib, in guile/lib */
+
 /* Objcode data should be directly mappable to this C structure.  */
 struct scm_objcode
 {
@@ -54,6 +56,9 @@ struct scm_objcode
 #define SCM_OBJCODE_IS_BYTEVECTOR(x) (SCM_OBJCODE_FLAGS (x) &
SCM_F_OBJCODE_IS_BYTEVECTOR)
 #define SCM_OBJCODE_IS_SLICE(x) (SCM_OBJCODE_FLAGS (x) &
SCM_F_OBJCODE_IS_SLICE)

+#define VERIFY_OBJCODE_HEADER_SIZE(header) verify(sizeof(header)        \
+                                                  == sizeof(struct
scm_objcode))
+
 SCM scm_c_make_objcode_slice (SCM parent, const scm_t_uint8 *ptr);
 SCM_API SCM scm_load_objcode (SCM file);
 SCM_API SCM scm_objcode_p (SCM obj);
diff --git a/libguile/smob.c b/libguile/smob.c
index 171db8d..3aba9de 100644
--- a/libguile/smob.c
+++ b/libguile/smob.c
@@ -598,6 +598,9 @@ void
 scm_smob_prehistory ()
 {
   long i;
+  scm_t_uint8 dummy[] = { OBJCODE_HEADER };
+
+  VERIFY_OBJCODE_HEADER_SIZE(dummy);

   smob_gc_kind = GC_new_kind (GC_new_free_list (),
 			      GC_MAKE_PROC (GC_new_proc (smob_mark), 0),
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-06-20 23:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-20 23:59 [PATCH] Verify Size of Objcode Headers Noah Lavine
  -- strict thread matches above, loose matches on Subject: below --
2010-06-20 19:44 Noah Lavine
2010-06-20 20:30 ` Andy Wingo
2010-06-20 21:22 ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).