[Ffmpeg-cvslog] r7249 - in trunk/libavcodec: dsputil.c dsputil.h mpegvideo.c

michael subversion
Thu Dec 7 19:33:01 CET 2006


Author: michael
Date: Thu Dec  7 19:33:00 2006
New Revision: 7249

Modified:
   trunk/libavcodec/dsputil.c
   trunk/libavcodec/dsputil.h
   trunk/libavcodec/mpegvideo.c

Log:
ff_check_alignment to warn the user about a missaligned stack


Modified: trunk/libavcodec/dsputil.c
==============================================================================
--- trunk/libavcodec/dsputil.c	(original)
+++ trunk/libavcodec/dsputil.c	Thu Dec  7 19:33:00 2006
@@ -3801,11 +3801,31 @@
     for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
 }
 
+int ff_check_alignment(void){
+    static int did_fail=0;
+    DECLARE_ALIGNED_16(int, aligned);
+
+    if((int)&aligned & 15){
+        if(!did_fail){
+#if defined(HAVE_MMX) || defined(HAVE_ALTIVEC)
+            av_log(NULL, AV_LOG_ERROR,
+                "Compiler did not align stack variables, your code has been misscompiled\n"
+                "and may crash, this is not a bug in the application but in the compiler\n"
+                "so reporting it anywhere but to the compiler maintainers is senseless!\n");
+#endif
+            did_fail=1;
+        }
+        return -1;
+    }
+    return 0;
+}
 
 void dsputil_init(DSPContext* c, AVCodecContext *avctx)
 {
     int i;
 
+    ff_check_alignment();
+
 #ifdef CONFIG_ENCODERS
     if(avctx->dct_algo==FF_DCT_FASTINT) {
         c->fdct = fdct_ifast;

Modified: trunk/libavcodec/dsputil.h
==============================================================================
--- trunk/libavcodec/dsputil.h	(original)
+++ trunk/libavcodec/dsputil.h	Thu Dec  7 19:33:00 2006
@@ -410,6 +410,8 @@
 void dsputil_static_init(void);
 void dsputil_init(DSPContext* p, AVCodecContext *avctx);
 
+int ff_check_alignment(void);
+
 /**
  * permute block according to permuatation.
  * @param last last non zero element in scantable order

Modified: trunk/libavcodec/mpegvideo.c
==============================================================================
--- trunk/libavcodec/mpegvideo.c	(original)
+++ trunk/libavcodec/mpegvideo.c	Thu Dec  7 19:33:00 2006
@@ -4838,6 +4838,8 @@
 static int estimate_motion_thread(AVCodecContext *c, void *arg){
     MpegEncContext *s= arg;
 
+    ff_check_alignment();
+
     s->me.dia_size= s->avctx->dia_size;
     s->first_slice_line=1;
     for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
@@ -4864,6 +4866,8 @@
     MpegEncContext *s= arg;
     int mb_x, mb_y;
 
+    ff_check_alignment();
+
     for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
         for(mb_x=0; mb_x < s->mb_width; mb_x++) {
             int xx = mb_x * 16;
@@ -4911,6 +4915,8 @@
     PutBitContext pb[2], pb2[2], tex_pb[2];
 //printf("%d->%d\n", s->resync_mb_y, s->end_mb_y);
 
+    ff_check_alignment();
+
     for(i=0; i<2; i++){
         init_put_bits(&pb    [i], bit_buf    [i], MAX_MB_BYTES);
         init_put_bits(&pb2   [i], bit_buf2   [i], MAX_MB_BYTES);




More information about the ffmpeg-cvslog mailing list