Description: do not use nested functions
 nested functions are a gcc-feature, that is not supported
 by other compilers, like clang.
 the attached patch converts the few nested functions into
 ordinary 'static inline' ones.
Author: Alexander Ovchinnikov <sanek23994@gmail.com>
Origin: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=758569
Last-Update: 2014-09-01
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- pd-pdp.orig/system/image/pdp_imageproc_gcc_mmx.c
+++ pd-pdp/system/image/pdp_imageproc_gcc_mmx.c
@@ -1024,6 +1024,24 @@
     x->height = h;
 }
 
+static INLINE __m64 wrap_0(__m64 val, __m64 max) {
+    /* Set components to zero when >= max */
+    __m64 mask = _mm_cmpgt_pi32(max, val); // 0xFFFFFFFF when true
+    __m64 val_out = _mm_and_si64(val, mask);
+    return val_out;
+}
+
+static INLINE word_t fetch_pixel(__m64 xy_offset, bool do_wrap, t_resample_zoom_rotate *p,
+                                 s16 *im) {
+    __m64 wrapped = do_wrap ?
+        wrap_0(xy_offset, p->cbrd.csrc.offset_max.v) :
+        xy_offset;
+    v2_t flat = {
+        .v = _mm_add_pi32(wrapped, _mm_srli_si64(wrapped, 32))
+    };
+    word_t pixel = im[flat.l[0]];
+    return pixel;
+}
 
 static INLINE void
 bilin_pixel(t_resample_zoom_rotate *p, word_t *out, __m64 xy_32) {
@@ -1070,26 +1088,12 @@
     /* Before fetch, set coords to 0 if they are out-of-bounds,
        effecitively implementing wrap-around addressing. */
     s16 *im = p->cbrd.csrc.image;
-    INLINE __m64 wrap_0(__m64 val, __m64 max) {
-        /* Set components to zero when >= max */
-        __m64 mask = _mm_cmpgt_pi32(max, val); // 0xFFFFFFFF when true
-        __m64 val_out = _mm_and_si64(val, mask);
-        return val_out;
-    }
-    INLINE word_t fetch_pixel(__m64 xy_offset, bool do_wrap) {
-        __m64 wrapped = do_wrap ?
-            wrap_0(xy_offset, p->cbrd.csrc.offset_max.v) :
-            xy_offset;
-        v2_t flat = {.v = _mm_add_pi32(wrapped, _mm_srli_si64(wrapped, 32))};
-        word_t pixel = im[flat.l[0]];
-        return pixel;
-    }
 
     /* Fetch 2x2 pixel grid to interpolate. */
-    word_t w_x0_y0 = fetch_pixel(offset_x0_y0, false);
-    word_t w_x1_y0 = fetch_pixel(offset_x1_y0, true);
-    word_t w_x0_y1 = fetch_pixel(offset_x0_y1, true);
-    word_t w_x1_y1 = fetch_pixel(offset_x1_y1, true);
+    word_t w_x0_y0 = fetch_pixel(offset_x0_y0, false, p, im);
+    word_t w_x1_y0 = fetch_pixel(offset_x1_y0, true, p, im);
+    word_t w_x0_y1 = fetch_pixel(offset_x0_y1, true, p, im);
+    word_t w_x1_y1 = fetch_pixel(offset_x1_y1, true, p, im);
 
     /* Perform bilinear interpolation using fractional coordinates. */
     word_t w_y0 = w_x0_y0 + (((w_x1_y0 - w_x0_y0) * frac_x) >> 16);
@@ -1220,8 +1224,15 @@
     *l = config;
 }
 
-
-
+/* affine x, y mappings in screen coordinates */
+static INLINE double mapx(
+                   double x, double y,
+                   double cx, double cy, double iz, double c, double s)
+                  {return cx + iz * ( c * (x-cx) + s * (y-cy));}
+static INLINE double mapy(
+                   double x, double y,
+                   double cx, double cy, double iz, double c, double s)
+                  {return cy + iz * (-s * (x-cx) + c * (y-cy));}
 
 /* convert floating point center and zoom data to incremental linear remapping vectors */
 static void pdp_imageproc_resample_clmd_init_from_id_zrd(t_resample_clmd *l, t_resample_id *i, t_resample_zrd *z)
@@ -1237,18 +1248,14 @@
     double c = cos(angle);
     double s = sin(angle);
 
-    /* affine x, y mappings in screen coordinates */
-    double mapx(double x, double y){return cx + izx * ( c * (x-cx) + s * (y-cy));}
-    double mapy(double x, double y){return cy + izy * (-s * (x-cx) + c * (y-cy));}
-
-    u32 tl_x = (u32)(scalew * mapx(0,0));
-    u32 tl_y = (u32)(scaleh * mapy(0,0));
+    u32 tl_x = (u32)(scalew * mapx(0,0, cx,cy,izx,c,s));
+    u32 tl_y = (u32)(scaleh * mapy(0,0, cx,cy,izy,c,s));
 
 
-    u32 row_inc_x = (u32)(scalew * (mapx(1,0)-mapx(0,0)));
-    u32 row_inc_y = (u32)(scaleh * (mapy(1,0)-mapy(0,0)));
-    u32 col_inc_x = (u32)(scalew * (mapx(0,1)-mapx(0,0)));
-    u32 col_inc_y = (u32)(scaleh * (mapy(0,1)-mapy(0,0)));
+    u32 row_inc_x = (u32)(scalew * (mapx(1,0, cx,cy,izx,c,s)-mapx(0,0, cx,cy,izx,c,s)));
+    u32 row_inc_y = (u32)(scaleh * (mapy(1,0, cx,cy,izy,c,s)-mapy(0,0, cx,cy,izy,c,s)));
+    u32 col_inc_x = (u32)(scalew * (mapx(0,1, cx,cy,izx,c,s)-mapx(0,0, cx,cy,izx,c,s)));
+    u32 col_inc_y = (u32)(scaleh * (mapy(0,1, cx,cy,izy,c,s)-mapy(0,0, cx,cy,izy,c,s)));
 
 
     pdp_imageproc_resample_cookedlinmap_init(l, tl_x, tl_y, row_inc_x, row_inc_y, col_inc_x, col_inc_y);
--- pd-pdp.orig/system/type/pdp_bitmap.c
+++ pd-pdp/system/type/pdp_bitmap.c
@@ -523,6 +523,11 @@
     return new_p;
 }
 
+static inline u8 _map(s32 pixel){
+  s32 mask = ~(pixel>>16);
+  return ((pixel >> 7) & mask);
+}
+
 static int _pdp_packet_bitmap_convert_mchp_to_rgb8(
     int packet, t_pdp_symbol __attribute__((unused)) *dest_template)
 {
@@ -536,12 +541,6 @@
     int nb_channels = image->depth;
     int new_p, i;
 
-    //    static inline u8 _map(s32 pixel){
-    inline u8 _map(s32 pixel){
-	s32 mask = ~(pixel>>16);
-	return ((pixel >> 7) & mask);
-    }
-
     switch(nb_channels){
     default: return -1;
     case 1:
--- pd-pdp.orig/system/zl/xwindow.c
+++ pd-pdp/system/zl/xwindow.c
@@ -329,10 +329,10 @@
     }
 }
 
-void zl_xwindow_drop_events(zl_xwindow_p x) {
-    void handle(void __attribute__((unused)) *x,
+static void handle_event0(void __attribute__((unused)) *x,
                 XEvent __attribute__((unused)) *e) {}
-    zl_xwindow_for_events(x, handle, NULL);
+void zl_xwindow_drop_events(zl_xwindow_p x) {
+    zl_xwindow_for_events(x, handle_event0, NULL);
 }
 
 void zl_xwindow_warppointer(zl_xwindow_p xwin, int x, int y)
