JDK7 "Project Coin" 语法新特性尝鲜

JDK7在20110728已经发布,分别在jvm、语法、国际化、jdbc、异步api等多方面有增强或新特性引入;其中java本身的语法增强似乎并不如想象中的那么令人激动...从代表着jdk7语法变更的"Project Coin"项目简介上看, jdk7的发布带来了以下语法变动:

  1. Strings in switch——String用在switch语句中
  2. Binary integral literals and underscores in numeric literals——二进制字面量与在数字字面量中添加下划线
  3. Multi-catch and more precise rethrow
  4. Improved type inference for generic instance creation (diamond)
  5. try-with-resources statement
  6. Simplified varargs method invocation

这些东西全是java编译器上的一些tricks,没有在jvm层面新增指令支持...可以说就是一群“语法糖”而已,目的在于让代码写得更方便
写了点代码分别试试:

package test;

import java.util.Map;
import java.util.HashMap;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Test {
    public static void main(String... args){
        // 二进制字面量
        binLiteral();
        // 带下划线的数字字面量
        numberUnderScore();
        // string用在switch中
        strSwitch("duck");
        // 泛型类型推断
        genericsInfer();
        // tryWithResource
        tryWithResource();
        // multi-catch
        multiCatch();
        // precise rethrow
        try{
        preciseRethrow();
        }catch(Exception1|Exception2 e){
            System.out.println(e);
        }
    }

    public static void binLiteral(){
        byte a = 0b00010001;
        System.out.println(a);
    }
    // 下划线不能出现在:
    // At the beginning or end of a number
    // Adjacent to a decimal point in a floating point literal
    // Prior to an F or L suffix
    // In positions where a string of digits is expected
    public static void numberUnderScore(){
        short s = 0b0010_0010_0010_0010;
        System.out.println(s);
    }

    // 内部变为hashCode、equals比较实现
    public static void strSwitch(String str){
        switch(str){
            case "cock":
                System.out.println("GeGe");
                break;
            case "duck":
                System.out.println("GaGa");
                break;
            default:
                System.out.println("Unhandled string: " + str);
        }
    }

    // generics inference
    public static void genericsInfer(){
        Map<String, Integer> map = new HashMap<>();
        map.put("one", 1);
        System.out.println(map);
    }

    // try with resource
    // resource == class implements java.lang.AutoCloseable
    // the close methods of resources are called in the opposite order of their creation
    // any catch or finally block is run after the resources declared have been closed
    public static void tryWithResource(){
        try(BufferedReader bf = new BufferedReader(new FileReader("text.txt"));){
            System.out.println(bf.readLine());
        }catch(IOException e){
            e.printStackTrace();
        }
    }

    // catching multiple exceptions
    private static class Exception1 extends Exception{}
    private static class Exception2 extends Exception{}

    public static void multiCatch(){
        int r1 = randInt(2);
        try{
        switch(r1){
            case 1:
                throw new Exception1();
            case 2:
                throw new Exception2();
        }
        }catch(Exception1|Exception2 e){
            System.out.println(e);
        }
    }
    public static int randInt(int max){
        return (int)(Math.random()*max+1);
    }
    // precise rethrow
    public static void preciseRethrow() throws Exception1, Exception2{
        int r1 = randInt(2);
        try{
        switch(r1){
            case 1:
                throw new Exception1();
            case 2:
                throw new Exception2();
        }
        //}catch(Exception1|Exception2 e){// precise
        }catch(Exception e){
            throw e;
        }
    }
}

个人认为比较有意思的是那个"switch语句中可以使用String",看了看"strSwitch"方法编译后的字节码:

public static void strSwitch(java.lang.String);
    Code:
       0: aload_0
       1: astore_1
       2: iconst_m1
       3: istore_2
       4: aload_1
       5: invokevirtual #15                 // Method java/lang/String.hashCode:()I
       8: lookupswitch  { // 2
               3059156: 36
               3094713: 50
               default: 61
          }
      36: aload_1
      37: ldc           #16                 // String cock
      39: invokevirtual #17                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      42: ifeq          61
      45: iconst_0
      46: istore_2
      47: goto          61
      50: aload_1
      51: ldc           #4                  // String duck
      53: invokevirtual #17                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      56: ifeq          61
      59: iconst_1
      60: istore_2
      61: iload_2
      62: lookupswitch  { // 2
                     0: 88
                     1: 99
               default: 110
          }
      88: getstatic     #12                 // Field java/lang/System.out:Ljava/io/PrintStream;
      91: ldc           #18                 // String GeGe
      93: invokevirtual #19                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      96: goto          135
      99: getstatic     #12                 // Field java/lang/System.out:Ljava/io/PrintStream;
     102: ldc           #20                 // String GaGa
     104: invokevirtual #19                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
     107: goto          135
     110: getstatic     #12                 // Field java/lang/System.out:Ljava/io/PrintStream;
     113: new           #21                 // class java/lang/StringBuilder
     116: dup
     117: invokespecial #22                 // Method java/lang/StringBuilder."<init>":()V
     120: ldc           #23                 // String Unhandled string:
     122: invokevirtual #24                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     125: aload_0
     126: invokevirtual #24                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     129: invokevirtual #25                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     132: invokevirtual #19                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
     135: return

可以看到,其实jvm内部并没有为switch string新增指令级别的支持,而仅仅是编译器将其转换为一些既有的指令进行实现,其原理是:

  1. 先计算switch(str)中str参数的hashCode(即将此string转化为一个int),然后利用老的switch(int)指令根据此值跳转到case语句中列出的某个string常量的hashCode对应的位置(代码中'3059156'和'3094713'分别正是case语句中'cock'和'duck'的hashCode值)
  2. 若第1步(switch by hashCode)就未能将程序跳转到任何case分支,则说明此str不可能是case语句中列出的任何string常量(cock/duck),于是程序直接可以结束了,若成功跳到某个case分支,再继续往下走:
  3. 光hashCode相同还不能判断str参数就是'cock'或'duck',还需要判断equals,于是如果str的hashCode等于'cock'的hashCode,编译器还准备了一段代码来判断str是否equals 'cock': 设置一个int变量i,调用equals方法,根据equals返回结果设置变量i为1或0,然后switch(i),就跳转到了对应的应用代码逻辑分支

也就是说,这个switch(str)新特性是通过编译为两次switch(int)实现的(第一次switch(hashCode),第二次switch(equals结果)),完完全全的使用老的jvm指令实现;不过我相信它确实能带给程序员很大的方便

其它新语法特性也是一样,都是编译器给出的trick,感觉它们之中最有用的除了switch(str)之外,就是泛型type inference了,我们这些苦逼的讨厌看到eclipse中黄线的程序员们曾经很苦逼地敲打着那一坨'<'和'>'组成的shi的时代终于可以结束了...
还有multi-catch也不错,使用'|'连接符同时catch多种具体的exception类型,这确实能使许多代码好看起来;
try-with-resource也可以试试,会让代码看起来更潮...
总结起来,jdk7的语法特性的增强可以说有点"渣",没有什么大的进步,或许JDK7的增强的重点并不在语法上,应该找时间看看“异步API”、jsr292、G1等等东西,那才是重点.

java:找出占用CPU资源最多的那个线程(HOW TO)

在这里对linux下、sun(oracle) JDK的线程资源占用问题的查找步骤做一个小结;linux环境下,当发现java进程占用CPU资源很高,且又要想更进一步查出哪一个java线程占用了CPU资源时,按照以下步骤进行查找:

  1. 先用top命令找出占用资源厉害的java进程id,如:
  2. 如上图所示,java的进程id为'12377',接下来用top命令单独对这个进程中的所有线程作监视:
    top -p 12377 -H

    如图:

  3. 如上图所示,linux下,所有的java内部线程,其实都对应了一个进程id,也就是说,linux上的sun jvm将java程序中的线程映射为了操作系统进程;我们看到,占用CPU资源最高的那个进程id是'15417',这个进程id对应java线程信息中的'nid'('n' stands for 'native');
  4. 要想找到到底是哪段具体的代码占用了如此多的资源,先使用jstack打出当前栈信息到一个文件里, 比如stack.log:
    jstack 12377 > stack.log

    然后使用'jtgrep'脚本把这个进程号为'15417'的java线程在stack.log中抓出来:

    jtgrep 15417 stack.log

其中,'jtgrep'是自己随便写的一个shell脚本:

#!/bin/sh

nid=`python -c "print hex($1)"`
grep -i $nid $2

道理很简单,就是把'15417'转换成16进制后,直接grep stack.log;可以看到,被grep出的那个线程的nid=0x3c39,正好是15417的16进制表示。

离散的世界

看了《天才在左疯子在右》这本书里摘录到网上的一些片段章节,很多疯子故事挺有意思的,当作小说浏览一遍挺不错的;其中“第二十四篇《迷失的旅行者——前篇:精神传输》”里面讲到了一个故事:

一个外星人偶然来到了地球,觉得地球很有意思,想带资料回去。但是因为是偶然来的,自己的飞船不够大,不可能放下很多样本。于是外星人找到了一套大英百科全书,觉得这个很好,准备带回去。但是发现那还不行,因为那一套太多了,还是太重了。外星人就把字母全部用数字代替,于是外星人得到了一串长长的数字,通过飞船的计算机全部按照百科全书顺序排列好后准备带走,但是外星人又发现飞船上的计算机还要存储很多画面和视频,那串大英百科全书数字太长了,占了很多硬盘空间——我们假设外星技术也需要硬盘。那怎么办呢?外星人就测量了自己飞船精确的长度后,把飞船假设为1。又把那串长长的‘大英百科数字’按照小数点后的模式,参照飞船长度,在飞船外壳上某处刻了很小的一个点。于是外星人回去了,他只刻了一个点,却带走了大英百科全书。回去只要测量出飞船的长度,再找到那个点在飞船上的位置......

简单地说,就是一个外星人将“大英百科全书”的所有内容编码成了一串巨大的数字序列"xx",并将这个数字序列xx放在了'0.'之后,组成了小数"0.xx",然后在自己的飞船长度按比例算恰好0.xx处刻了一个点,在回到自己的星球时,再将这个点在飞船长度上所占的精确位置测量出来,即还原这个0.xx,从而得到xx序列,也就达成了将“大英百科全书”所有内容带回去的目的;

美丽的故事!不过我认为这个是不可能的,因为这个故事忽略了一个重要的条件:我们的世界是离散的,从空间到时间都是;

怎么说呢?这里与“离散”相对立的概念是“连续”,所谓“连续”的意思就是“无限可分”,而“离散”就不是无限可分的,“离散”的量是有一个“最小单位”的;以长度为例的话,如果说“长度”这个概念是离散的,其实就是说存在一个最短长度,不可再分割为更短长度——所有的长度都是由很多很多个这样的“最短长度”所组成;

而以现代普遍被接受的量子论观点来看,这个“最短长度”是存在的,叫做“普朗克长度”;约等于16.16252 * 10^-36 (米),我们的宇宙中不存在比这更短的长度了;

好了,按照这样来分析一下这个外星人的宇宙飞船的问题:按照wikipedia的资料,"大英百科全书"总信息量为40000000个单词,假设保守估计每个单词3个字母,那就有120000000个字母...呃..还不算标点符号...还不算图片和视频等多媒体资料呢..算了,图片视频啊什么的就不算了吧!假设这个外星人就只是想把文字资料带回去;

那么,要用数字表示这120000000个字母,要多少位数字呢?我假设这些字母全是英文和数字,'0'-'9'以及'a-z',大小写就忽略了,一共36种字符;用十进制表示法(其实跟进制无关,我们既然刚才以十进制表示了普朗克长度,那么这里同样以十进制来编制这个信息串仅仅是为了方便比较),每个字母被表示为2个数字(最大36,就2位十进制数而言,大约浪费了2/3的数据空间,不过问题的重点不在数字的表示上,用十进制只是为了方便比较而已,其实无论用什么进制,用什么压缩算法,都无法改变这个外星人要将长度精确地分割这个事实),那么这些信息被转换成数字之后,就形成了一个长达240000000位(注意:是位数)的天文数字;而我们的普朗克长度是16 * 10^-36米,假设飞船有16米长,这个小数点之后仅仅能容下36位十进制数...显然是不够的,那么,要能在我们这个宇宙中精确地在他的飞船上刻下这个天文数字的话,这艘飞船的长度至少要: 16 * 10^(240000000-36)米长!这个长度有多长呢?目前所知我们所在的银河系“横向”总长度约为9.5 * 10^20米,也就是区区10万光年...那么这个巨大的宇宙飞船的长度将是银河系“横向”长度的2399999440倍...宇宙有这么大么?我不知道,我只是觉得这个外星人拥有这么大一艘宇宙飞船,与其绞尽脑汁想把大英百科全书刻在飞船的一个点上,还不如直接买一套装回去算了——不会很沉的,跟你的宇宙飞船比起来——只要你愿意,你都可以把地球打包带走...

其实这个故事还让我联想到一个比较有名的悖论(Zeno's paradox):

一个人要从A点移动到B点,首先要经过AB的1/2;

要经过A/B的1/2,就首先要经过AB的1/4;

......要先经过1/8...

......

这个人永远也无法迈出第一步!

这个悖论之所以在现实中不存在,跟前面的“刻舟求剑”外星版其实是一个道理:他想当然地认为我们这个世界的长度度量是连续的,是无限可分的;

有了普朗克长度,这个悖论就灰飞烟灭了——只要你想要移动,我们这个宇宙就“强迫”你至少移动一个普朗克长度,你要么不动,要么就至少移动一个普朗克长度,就这么简单!有了这样的法则,天上的星辰、地上的万物才能真正动起来。

其实,不仅仅是长度,能量、甚至时间都是离散的,而非连续的,可以说我们的世界是离散的——“连续”只是一个概念,只存在于数学中。

什么是LL(*) parsing

最近公司项目用到antlr3来做一些语法工具,它的文档里提到的那个神秘的LL(*) parsing从来没听说过,查了些资料,整理了一下,发觉LL(*)也不过就是这么一个东西:

  1. 机制:用一个带环(LL(k)不带环)的自动机来做超前查看
  2. 它是一种LL parsing,要parse的规则中不能出现左递归
  3. 由于自动机不带栈,无法处理中途带有递归的语法元素的超前查看(解决的办法是用EBNF描述来代替尾递归,实际上就是尾递归化循环); 对于非尾递归的情况, 自动机就无法无穷地超前查看token以决定该选择哪条规则, 只能做到一个指定最大步数地跟踪递归, 最大指定步数由命令行参数'-Xm'指定:$ java org.antlr.Tool -Xm 1 t.g
  4. 规则的不确定性: 如果不手工更改语法文件去除不确定性,antlr会默认选择先出现的语法规则; 要消除不确定性,方法有二:1.新增或去掉冲突的语法元素消除不确定性 2.用backtrack、syntactic predicate

首先,第1点,相对于传统的LL(k),LL(*)能超前查看不确定个数的token,这是因为它在正常的top-down parsing之外,还使用了一个带环的超前查看DFA(prediction DFA)来做对候选产生式的预判、选择,带环的意义在于在该环处,DFA能够越过任意多个组成该环的这些边上的token,最后跳出这个环的时候,就到了能够确定哪条语法规则应该被使用的地方;也就是说,这个超前查看的DFA自身带有循环(有环),而传统的LL(k)的prediction DFA是一棵树,就算这棵树再高(高度为k),相同的结构过多时,也不能完成判断任务(两个候选产生式的相同起始token数大于k时).

第2点,它是一种LL parsing,这个不用说了,写语法规则的时候要记得消除左递归;

第3点,“由于自动机不带栈,无法处理中途带有递归的语法元素的超前查看”,这个拿个例子来说明:

s : label ID '=' expr
  | label 'return' expr
  ;
label
   : ID ':' label // uses tail recursion to loop
   |
   ;

这个例子中,要想对s选择正确的产生式,则我们的prediction DFA要越过'label',直到见到'ID'或'return'才能完成判断,但这个要越过的label本身是一个递归结构(虽然它是一个尾递归),而由于DFA只有状态和边,没有像栈这样的存储结构,所以DFA无法对递归的结构进行处理;那么上面这个例子就要做一点改变,由于这个递归恰好是个尾递归,所以能够直接用一个循环来代替,正好EBNF有描述这种循环结构的方式,且antlr也是支持的:

s : label ID '=' expr
  | label 'return' expr
  ;
label
  : (ID ':' )*
  ;

这样一来'(ID ':' )*'直接在DFA中表示为一个环,也就解决了这个问题;其实说句题外话,antlr完全可以自动帮用户做这个尾递归化循环,不知道为什么没有做~
上面这个例子能够用EBNF的循环来代替尾递归,那么不是尾递归的情况呢?像下面这样:

se : e '%'
   | e '!'
   ;
e : '(' e ')'
  | ID
  ;

不是尾递归的情况的话,那就非用栈不可了,而DFA天生没有栈,也就是解决不了的了,这样的情况就叫做'non-LL(*)', 即不属于LL(*)的语法, 只能做到一个指定最大步数地跟踪递归, 最大指定步数由命令行参数'-Xm'指定:$ java org.antlr.Tool -Xm 1 t.g, 若解析过程中递归结构重复次数超过参数指定的这个数值,解析就可能不正确

第4点,当语法中出现不确定性(Nondeterministic)时,该怎么办?其实前面几条已经看到,LL(*)相对于传统的LL(k)已经帮用户解决了更多的不确定性,也就是说它能够描述更高级一些的语法,但尽管如此,还是有一些不确定性是LL(*)所不能解决的;而这样的情况并非LL(*)特有,LL(k)同样存在;其实这个第4点和LL(*)本身关系不大,只是antlr的作者建议用户在遇到连LL(*)都不能解决的不确定性时,路有两条:

  1. 更改语法,用户自己清除语法中过量的不确定性(也就是降低你的语法的等级)
  2. 使用syntactic/semantic predicate,或开启backtrack(回溯)功能,当然,这个回溯是有性能开销的

一个方便离线查看ruby文档的脚本

最近用做了点小脚本,使用了ruby,由于不是很熟api,经常需要查文档;不过ruby的repl(irb)中没有像python的help、dir一样方便的函数可以让人查详细的文档,因此还得打开浏览器去看那些html的文档;

不厌其烦...自己封装了一个小脚本,这下查这些html文档方便多了,记在下面:

首先下载ruby官网的离线html版本的文档,解压开放到一个固定的地方,比如我的机器上就是

/home/pf-miles/docs/ruby_1_8_7_core

然后写了这个脚本并放到$PATH中:
rubyDoc:

#!/bin/sh
docBase=/home/pf-miles/docs/ruby_1_8_7_core
if [ 0 == $# ]; then
    firefox $docBase/index.html
else
    cls=$1
    docPaths=`find $docBase/classes -name "*$cls*" | grep -i html`
    if [ '' == "$docPaths" ];then
        echo 'No docs found.'
    else
        for path in $docPaths
        do
            w3m $path
        done
    fi
fi

用法:rubyDoc className

pf-miles@pf-miles-desktop:~$ rubyDoc String


这样就能跳出String的帮助文档,其实如果仅仅输入'Str'也能出来String文档的,但是,就如shell中写的,可能会匹配中其它类名中也包含'Str'的类的文档,当匹配到多份文档的时候,w3m会依次显示;
匹配到多份文档的时候,w3m只能顺序查看(前一个文档退出后,才能看后一个文档),其实这里再花点时间,可以做到交互shell,让用户从多个匹配结果中选择一个进行显示,也是轻而易举的事情
另外,这里的w3m换成'firefox'也完全可以,并且还能省掉那个for循环——因为firefox是能够同时以多个tab来同时展示多份匹配结果的!

阿里巴巴B2B招聘高级java开发工程师

阿里巴巴B2B招聘高级java开发工程师

我不想列“精通xxx...熟悉xxx”,只要求,如果您:

  1. 有2年或以上java实际开发经验,或
  2. 1年以上java实际开发经验但技术能力较强

就能直接联系我: 直接在此帖留言或gtalk: miles.wy.1@gmail.com或msn:pf_miles@126.com或icq:144071475或yahooMsg:pf_miles@yahoo.cn,本人pidgin周一至周五工作日全程在线,谢绝qq

im沟通我们可以谈简历的事情,走内部推荐,1.电面2.来杭面试,流程简单,全程报销路费;

P.S. 年初,各大公司招聘旺季,阿里巴巴这里呢,我不想说有多好,但也绝对不算差,最实际的,薪酬待遇,各大公司基本保密,但其实业内人士大多心里也有数,秘而不宣;所以,待遇方面不用过多担心,请诸君仔细斟酌,欢迎联系!

再P.S. 为什么我这招聘帖这么简单呢?其实你懂的,“精通xxx熟悉xxx”那只是吓唬小菜的,对“高级java开发工程师”而言没有意义,我们需要的只是充分沟通、im沟通+当面沟通。在这个有点糟糕的时代,我们人人都不仅需要money,也需要平台与机遇,更需要个人修为与成长!请给阿里和您自己一个机会,谢谢!

linux下安装使用pytesser

pytesser是一个用于图片文本识别的python模块:http://code.google.com/p/pytesser/,即从文本的截图中还原出文本信息;

网上在windows上安装、使用的资料比较多,而没有linux的资料;

作者虽然没有说明pytesser在linux环境下测试过,但也表示“The scripts should work in Linux as well.”;

今天在我的ubuntu9.10上编译、安装、使用了一把,过程中遇到一些问题并解决,记在这里:

  1. pytesser依赖于PIL,因此需要先安装PIL模块,详见:http://wenyue.me/blog/278
  2. pytesser调用了tesseract,因此需要安装tesseract:
    先用包管理器安装这几个库:

    sudo apt-get install libpng12-dev
    sudo apt-get install libjpeg62-dev
    sudo apt-get install libtiff4-dev
    sudo apt-get install zlibg-dev
    

    下载tesseract的源码包:http://tesseract-ocr.googlecode.com/files/tesseract-3.00.tar.gz
    解压、cd到解压后目录下tesseract-3.00/
    运行./configure --prefix=你想要安装到的路径,比如:

    ./configure --prefix=/home/pf-miles/installation/install/tesseract

    然后make & make install
    将tesseract的运行脚本加到环境变量中,比如:

    export PATH=$PATH:/home/pf-miles/installation/install/tesseract/bin

    , 这个路径与刚才你configure的时候设置的路径有关
    http://code.google.com/p/tesseract-ocr/downloads/list页面去下载最新的eng.traineddata.gz文件,解压后的eng.traineddata放到/home/pf-miles/installation/install/tesseract/share/tessdata目录下,注意,虽然tesseract的svn trunk里也有这个文件,但那个用不得,会报

    actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file tessdatamanager.cpp, line 55

    错误,详见:http://www.uluga.ubuntuforums.org/showthread.php?p=10248384,所以一定要用http://code.google.com/p/tesseract-ocr/downloads/list这里下载的那一份
    试一试:

    pf-miles@pf-miles-desktop:~/downloads$ tesseract
    Usage:tesseract imagename outputbase [-l lang] [configfile [[+|-]varfile]...]
    

    OK,tesseract安装完毕

  3. 下载pytesser包:http://pytesser.googlecode.com/files/pytesser_v0.0.1.zip(目前是0.0.1版本), 解压...并cd到解压后的目录下
  4. 目录下有个“phototest.tif”图片文件作为测试用,直接在目录下写一个python脚本进行测试:
    test.py:

    from pytesser import *
    im = Image.open('phototest.tif')
    text = image_to_string(im)
    print text
    

    运行:

    pf-miles@pf-miles-desktop:~/downloads/pytesser$ python test.py 2>/dev/null

    结果:
    Thls IS a lot of 12 pornt text to test the
    ocr code and see lf It works on all types
    of frle format
    lazy fox The qurck brown dog jumped
    over the lazy fox The qulck brown dog
    jumped over the lazy fox The QUICK
    brown dog jumped over the lazy fox
    The quick brown dog jumped over the

应该说准确率还令人满意吧.

ubuntu9.10下编译、安装pil模块

  1. 下载Imaging-1.1.7.tar.gz源码包
  2. sudo apt-get install python-dev, 这个必须安装,否则报以下错误:
    pf-miles@pf-miles-desktop:~/downloads/Imaging-1.1.7$ python setup.py build
    running build
    running build_py
    running build_ext
    building '_imaging' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/local/include -I/usr/include/python2.6 -c _imaging.c -o build/temp.linux-i686-2.6/_imaging.o
    _imaging.c:75:20: error: Python.h: 没有那个文件或目录
    In file included from libImaging/Imaging.h:14,
    from _imaging.c:77:
    libImaging/ImPlatform.h:14:2: error: #error Sorry, this library requires support for ANSI prototypes.
    libImaging/ImPlatform.h:17:2: error: #error Sorry, this library requires ANSI header files.
    libImaging/ImPlatform.h:55:2: error: #error Cannot find required 32-bit integer type
    In file included from _imaging.c:77:
    libImaging/Imaging.h:90: error: expected specifier-qualifier-list before ‘INT32’
    libImaging/Imaging.h:264: error: expected specifier-qualifier-list before ‘INT32’
    libImaging/Imaging.h:395: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ImagingCRC32’
    _imaging.c:124: error: expected specifier-qualifier-list before ‘PyObject_HEAD’
    _imaging.c:129: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:143: error: expected specifier-qualifier-list before ‘PyObject_HEAD’
    _imaging.c:151: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:154: error: expected specifier-qualifier-list before ‘PyObject_HEAD’
    _imaging.c:160: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:165: error: expected specifier-qualifier-list before ‘PyObject_HEAD’
    _imaging.c:170: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:172: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c: In function ‘_dealloc’:
    _imaging.c:204: error: ‘ImagingObject’ has no member named ‘access’
    _imaging.c:206: error: ‘ImagingObject’ has no member named ‘image’
    _imaging.c:207: warning: implicit declaration of function ‘PyMem_DEL’
    _imaging.c: At top level:
    _imaging.c:212: error: expected ‘)’ before ‘*’ token
    _imaging.c: In function ‘ImagingSectionEnter’:
    _imaging.c:230: error: ‘PyThreadState’ undeclared (first use in this function)
    _imaging.c:230: error: (Each undeclared identifier is reported only once
    _imaging.c:230: error: for each function it appears in.)
    _imaging.c:230: error: expected expression before ‘)’ token
    _imaging.c: In function ‘ImagingSectionLeave’:
    _imaging.c:237: warning: implicit declaration of function ‘PyEval_RestoreThread’
    _imaging.c:237: error: ‘PyThreadState’ undeclared (first use in this function)
    _imaging.c:237: error: expected expression before ‘)’ token
    _imaging.c: At top level:
    _imaging.c:248: error: expected ‘)’ before ‘*’ token
    _imaging.c:257: error: expected ‘)’ before ‘*’ token
    _imaging.c: In function ‘ImagingError_IOError’:
    _imaging.c:301: warning: implicit declaration of function ‘PyErr_SetString’
    _imaging.c:301: error: ‘PyExc_IOError’ undeclared (first use in this function)
    _imaging.c:302: error: ‘NULL’ undeclared (first use in this function)
    _imaging.c: In function ‘ImagingError_MemoryError’:
    _imaging.c:308: warning: implicit declaration of function ‘PyErr_NoMemory’
    _imaging.c:308: warning: return makes pointer from integer without a cast
    _imaging.c: In function ‘ImagingError_Mismatch’:
    _imaging.c:314: error: ‘PyExc_ValueError’ undeclared (first use in this function)
    _imaging.c:315: error: ‘NULL’ undeclared (first use in this function)
    _imaging.c: In function ‘ImagingError_ModeError’:
    _imaging.c:321: error: ‘PyExc_ValueError’ undeclared (first use in this function)
    _imaging.c:322: error: ‘NULL’ undeclared (first use in this function)
    _imaging.c: In function ‘ImagingError_ValueError’:
    _imaging.c:329: error: ‘PyExc_ValueError’ undeclared (first use in this function)
    _imaging.c:332: error: ‘NULL’ undeclared (first use in this function)
    _imaging.c: In function ‘ImagingError_Clear’:
    _imaging.c:338: warning: implicit declaration of function ‘PyErr_Clear’
    _imaging.c: At top level:
    _imaging.c:369: error: expected ‘)’ before ‘*’ token
    _imaging.c:464: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:510: error: expected ‘)’ before ‘*’ token
    _imaging.c:587: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:619: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:631: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:643: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:655: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:664: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:675: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:686: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:697: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:719: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:743: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:760: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:777: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:786: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:803: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:813: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:824: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:857: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:879: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:914: error: expected ‘)’ before ‘*’ token
    _imaging.c:954: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:981: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1054: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1065: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1075: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1191: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1202: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1339: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1359: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1394: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1419: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1448: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1459: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1479: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1530: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1568: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1614: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1689: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1739: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1765: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1771: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1783: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1817: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1845: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1874: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1885: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1901: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1922: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1928: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1939: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1950: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1961: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1972: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:1983: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2001: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2019: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2030: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2041: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2052: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2063: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2081: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c: In function ‘_font_dealloc’:
    _imaging.c:2142: warning: implicit declaration of function ‘Py_XDECREF’
    _imaging.c:2142: error: ‘ImagingFontObject’ has no member named ‘ref’
    _imaging.c: In function ‘textwidth’:
    _imaging.c:2152: error: ‘ImagingFontObject’ has no member named ‘glyphs’
    _imaging.c: At top level:
    _imaging.c:2157: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2205: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2215: error: array type has incomplete element type
    _imaging.c:2216: error: ‘PyCFunction’ undeclared here (not in a function)
    _imaging.c:2216: error: expected ‘}’ before ‘_font_getmask’
    _imaging.c:2217: error: expected ‘}’ before ‘_font_getsize’
    _imaging.c:2218: error: ‘NULL’ undeclared here (not in a function)
    _imaging.c:2221: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2229: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c: In function ‘_draw_dealloc’:
    _imaging.c:2257: error: ‘ImagingDrawObject’ has no member named ‘image’
    _imaging.c: At top level:
    _imaging.c:2261: error: expected ‘)’ before ‘*’ token
    _imaging.c:2263: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2278: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2298: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2335: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2353: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2390: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2406: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2459: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2474: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2507: error: expected ‘)’ before ‘*’ token
    _imaging.c:2509: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2536: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2554: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2600: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2637: error: array type has incomplete element type
    _imaging.c:2640: error: expected ‘}’ before ‘_draw_line’
    _imaging.c:2641: error: expected ‘}’ before ‘_draw_lines’
    _imaging.c:2643: error: expected ‘}’ before ‘_draw_outline’
    _imaging.c:2645: error: expected ‘}’ before ‘_draw_polygon’
    _imaging.c:2646: error: expected ‘}’ before ‘_draw_rectangle’
    _imaging.c:2647: error: expected ‘}’ before ‘_draw_point’
    _imaging.c:2648: error: expected ‘}’ before ‘_draw_points’
    _imaging.c:2649: error: expected ‘}’ before ‘_draw_arc’
    _imaging.c:2650: error: expected ‘}’ before ‘_draw_bitmap’
    _imaging.c:2651: error: expected ‘}’ before ‘_draw_chord’
    _imaging.c:2652: error: expected ‘}’ before ‘_draw_ellipse’
    _imaging.c:2653: error: expected ‘}’ before ‘_draw_pieslice’
    _imaging.c:2654: error: expected ‘}’ before ‘_draw_ink’
    _imaging.c:2659: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2668: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c: In function ‘pixel_access_dealloc’:
    _imaging.c:2693: error: ‘PixelAccessObject’ has no member named ‘image’
    _imaging.c: At top level:
    _imaging.c:2697: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2708: error: expected declaration specifiers or ‘...’ before ‘PyObject’
    _imaging.c:2708: error: expected declaration specifiers or ‘...’ before ‘PyObject’
    _imaging.c: In function ‘pixel_access_setitem’:
    _imaging.c:2710: error: ‘PixelAccessObject’ has no member named ‘image’
    _imaging.c:2714: error: ‘PixelAccessObject’ has no member named ‘readonly’
    _imaging.c:2719: warning: implicit declaration of function ‘_getxy’
    _imaging.c:2719: error: ‘xy’ undeclared (first use in this function)
    _imaging.c:2723: error: ‘PyExc_IndexError’ undeclared (first use in this function)
    _imaging.c:2727: error: ‘color’ undeclared (first use in this function)
    _imaging.c:2730: warning: implicit declaration of function ‘getink’
    _imaging.c:2733: error: ‘PixelAccessObject’ has no member named ‘image’
    _imaging.c: At top level:
    _imaging.c:2744: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2763: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2774: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2791: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2811: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2846: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:2867: error: array type has incomplete element type
    _imaging.c:2870: error: expected ‘}’ before ‘_getpixel’
    _imaging.c:2871: error: expected ‘}’ before ‘_putpixel’
    _imaging.c:2873: error: expected ‘}’ before ‘pixel_access_new’
    _imaging.c:2876: error: expected ‘}’ before ‘_convert’
    _imaging.c:2877: error: expected ‘}’ before ‘_convert2’
    _imaging.c:2878: error: expected ‘}’ before ‘_convert_matrix’
    _imaging.c:2879: error: expected ‘}’ before ‘_copy’
    _imaging.c:2880: error: expected ‘}’ before ‘_copy2’
    _imaging.c:2884: error: expected ‘}’ before ‘_crop’
    _imaging.c:2885: error: expected ‘}’ before ‘_expand’
    _imaging.c:2886: error: expected ‘}’ before ‘_filter’
    _imaging.c:2887: error: expected ‘}’ before ‘_histogram’
    _imaging.c:2889: error: expected ‘}’ before ‘_modefilter’
    _imaging.c:2891: error: expected ‘}’ before ‘_offset’
    _imaging.c:2892: error: expected ‘}’ before ‘_paste’
    _imaging.c:2893: error: expected ‘}’ before ‘_point’
    _imaging.c:2894: error: expected ‘}’ before ‘_point_transform’
    _imaging.c:2895: error: expected ‘}’ before ‘_putdata’
    _imaging.c:2897: error: expected ‘}’ before ‘_quantize’
    _imaging.c:2900: error: expected ‘}’ before ‘_rankfilter’
    _imaging.c:2902: error: expected ‘}’ before ‘_resize’
    _imaging.c:2903: error: expected ‘}’ before ‘_rotate’
    _imaging.c:2904: error: expected ‘}’ before ‘_stretch’
    _imaging.c:2905: error: expected ‘}’ before ‘_transpose’
    _imaging.c:2906: error: expected ‘}’ before ‘_transform2’
    _imaging.c:2908: error: expected ‘}’ before ‘_isblock’
    _imaging.c:2910: error: expected ‘}’ before ‘_getbbox’
    _imaging.c:2911: error: expected ‘}’ before ‘_getcolors’
    _imaging.c:2912: error: expected ‘}’ before ‘_getextrema’
    _imaging.c:2913: error: expected ‘}’ before ‘_getprojection’
    _imaging.c:2915: error: expected ‘}’ before ‘_getband’
    _imaging.c:2916: error: expected ‘}’ before ‘_putband’
    _imaging.c:2917: error: expected ‘}’ before ‘_fillband’
    _imaging.c:2919: error: expected ‘}’ before ‘im_setmode’
    _imaging.c:2921: error: expected ‘}’ before ‘_getpalette’
    _imaging.c:2922: error: expected ‘}’ before ‘_putpalette’
    _imaging.c:2923: error: expected ‘}’ before ‘_putpalettealpha’
    _imaging.c:2927: error: expected ‘}’ before ‘_chop_invert’
    _imaging.c:2928: error: expected ‘}’ before ‘_chop_lighter’
    _imaging.c:2929: error: expected ‘}’ before ‘_chop_darker’
    _imaging.c:2930: error: expected ‘}’ before ‘_chop_difference’
    _imaging.c:2931: error: expected ‘}’ before ‘_chop_multiply’
    _imaging.c:2932: error: expected ‘}’ before ‘_chop_screen’
    _imaging.c:2933: error: expected ‘}’ before ‘_chop_add’
    _imaging.c:2934: error: expected ‘}’ before ‘_chop_subtract’
    _imaging.c:2935: error: expected ‘}’ before ‘_chop_add_modulo’
    _imaging.c:2936: error: expected ‘}’ before ‘_chop_subtract_modulo’
    _imaging.c:2937: error: expected ‘}’ before ‘_chop_and’
    _imaging.c:2938: error: expected ‘}’ before ‘_chop_or’
    _imaging.c:2939: error: expected ‘}’ before ‘_chop_xor’
    _imaging.c:2944: error: expected ‘}’ before ‘_gaussian_blur’
    _imaging.c:2945: error: expected ‘}’ before ‘_unsharp_mask’
    _imaging.c:2950: error: expected ‘}’ before ‘_effect_spread’
    _imaging.c:2954: error: expected ‘}’ before ‘_new_array’
    _imaging.c:2955: error: expected ‘}’ before ‘_new_block’
    _imaging.c:2958: error: expected ‘}’ before ‘_save_ppm’
    _imaging.c:2967: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c: In function ‘image_length’:
    _imaging.c:2996: error: ‘ImagingObject’ has no member named ‘image’
    _imaging.c: At top level:
    _imaging.c:3001: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3016: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘image_as_sequence’
    _imaging.c:3029: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:3050: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:3062: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:3076: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pixel_access_as_mapping’
    _imaging.c:3084: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’
    _imaging.c:3106: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3107: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3108: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3110: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3112: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3113: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3115: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3116: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3117: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3118: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3119: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3120: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3123: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3124: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3125: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3126: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3127: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3128: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3129: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3144: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3147: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3150: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
    _imaging.c:3152: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘functions’
    _imaging.c:3250: warning: return type defaults to ‘int’
    _imaging.c: In function ‘DL_EXPORT’:
    _imaging.c:3250: error: expected declaration specifiers before ‘init_imaging’
    _imaging.c:3281: error: expected ‘{’ at end of input
    error: command 'gcc' failed with exit status 1

    pf-miles@pf-miles-desktop:~/downloads/Imaging-1.1.7$ python setup.py buildrunning buildrunning build_pyrunning build_extbuilding '_imaging' extensiongcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/local/include -I/usr/include/python2.6 -c _imaging.c -o build/temp.linux-i686-2.6/_imaging.o_imaging.c:75:20: error: Python.h: 没有那个文件或目录In file included from libImaging/Imaging.h:14,                 from _imaging.c:77:libImaging/ImPlatform.h:14:2: error: #error Sorry, this library requires support for ANSI prototypes.libImaging/ImPlatform.h:17:2: error: #error Sorry, this library requires ANSI header files.libImaging/ImPlatform.h:55:2: error: #error Cannot find required 32-bit integer typeIn file included from _imaging.c:77:libImaging/Imaging.h:90: error: expected specifier-qualifier-list before ‘INT32’libImaging/Imaging.h:264: error: expected specifier-qualifier-list before ‘INT32’libImaging/Imaging.h:395: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ImagingCRC32’_imaging.c:124: error: expected specifier-qualifier-list before ‘PyObject_HEAD’_imaging.c:129: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:143: error: expected specifier-qualifier-list before ‘PyObject_HEAD’_imaging.c:151: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:154: error: expected specifier-qualifier-list before ‘PyObject_HEAD’_imaging.c:160: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:165: error: expected specifier-qualifier-list before ‘PyObject_HEAD’_imaging.c:170: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:172: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c: In function ‘_dealloc’:_imaging.c:204: error: ‘ImagingObject’ has no member named ‘access’_imaging.c:206: error: ‘ImagingObject’ has no member named ‘image’_imaging.c:207: warning: implicit declaration of function ‘PyMem_DEL’_imaging.c: At top level:_imaging.c:212: error: expected ‘)’ before ‘*’ token_imaging.c: In function ‘ImagingSectionEnter’:_imaging.c:230: error: ‘PyThreadState’ undeclared (first use in this function)_imaging.c:230: error: (Each undeclared identifier is reported only once_imaging.c:230: error: for each function it appears in.)_imaging.c:230: error: expected expression before ‘)’ token_imaging.c: In function ‘ImagingSectionLeave’:_imaging.c:237: warning: implicit declaration of function ‘PyEval_RestoreThread’_imaging.c:237: error: ‘PyThreadState’ undeclared (first use in this function)_imaging.c:237: error: expected expression before ‘)’ token_imaging.c: At top level:_imaging.c:248: error: expected ‘)’ before ‘*’ token_imaging.c:257: error: expected ‘)’ before ‘*’ token_imaging.c: In function ‘ImagingError_IOError’:_imaging.c:301: warning: implicit declaration of function ‘PyErr_SetString’_imaging.c:301: error: ‘PyExc_IOError’ undeclared (first use in this function)_imaging.c:302: error: ‘NULL’ undeclared (first use in this function)_imaging.c: In function ‘ImagingError_MemoryError’:_imaging.c:308: warning: implicit declaration of function ‘PyErr_NoMemory’_imaging.c:308: warning: return makes pointer from integer without a cast_imaging.c: In function ‘ImagingError_Mismatch’:_imaging.c:314: error: ‘PyExc_ValueError’ undeclared (first use in this function)_imaging.c:315: error: ‘NULL’ undeclared (first use in this function)_imaging.c: In function ‘ImagingError_ModeError’:_imaging.c:321: error: ‘PyExc_ValueError’ undeclared (first use in this function)_imaging.c:322: error: ‘NULL’ undeclared (first use in this function)_imaging.c: In function ‘ImagingError_ValueError’:_imaging.c:329: error: ‘PyExc_ValueError’ undeclared (first use in this function)_imaging.c:332: error: ‘NULL’ undeclared (first use in this function)_imaging.c: In function ‘ImagingError_Clear’:_imaging.c:338: warning: implicit declaration of function ‘PyErr_Clear’_imaging.c: At top level:_imaging.c:369: error: expected ‘)’ before ‘*’ token_imaging.c:464: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:510: error: expected ‘)’ before ‘*’ token_imaging.c:587: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:619: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:631: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:643: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:655: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:664: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:675: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:686: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:697: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:719: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:743: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:760: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:777: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:786: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:803: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:813: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:824: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:857: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:879: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:914: error: expected ‘)’ before ‘*’ token_imaging.c:954: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:981: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1054: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1065: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1075: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1191: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1202: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1339: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1359: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1394: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1419: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1448: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1459: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1479: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1530: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1568: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1614: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1689: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1739: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1765: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1771: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1783: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1817: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1845: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1874: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1885: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1901: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1922: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1928: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1939: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1950: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1961: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1972: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:1983: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2001: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2019: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2030: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2041: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2052: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2063: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2081: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c: In function ‘_font_dealloc’:_imaging.c:2142: warning: implicit declaration of function ‘Py_XDECREF’_imaging.c:2142: error: ‘ImagingFontObject’ has no member named ‘ref’_imaging.c: In function ‘textwidth’:_imaging.c:2152: error: ‘ImagingFontObject’ has no member named ‘glyphs’_imaging.c: At top level:_imaging.c:2157: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2205: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2215: error: array type has incomplete element type_imaging.c:2216: error: ‘PyCFunction’ undeclared here (not in a function)_imaging.c:2216: error: expected ‘}’ before ‘_font_getmask’_imaging.c:2217: error: expected ‘}’ before ‘_font_getsize’_imaging.c:2218: error: ‘NULL’ undeclared here (not in a function)_imaging.c:2221: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2229: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c: In function ‘_draw_dealloc’:_imaging.c:2257: error: ‘ImagingDrawObject’ has no member named ‘image’_imaging.c: At top level:_imaging.c:2261: error: expected ‘)’ before ‘*’ token_imaging.c:2263: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2278: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2298: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2335: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2353: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2390: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2406: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2459: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2474: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2507: error: expected ‘)’ before ‘*’ token_imaging.c:2509: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2536: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2554: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2600: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2637: error: array type has incomplete element type_imaging.c:2640: error: expected ‘}’ before ‘_draw_line’_imaging.c:2641: error: expected ‘}’ before ‘_draw_lines’_imaging.c:2643: error: expected ‘}’ before ‘_draw_outline’_imaging.c:2645: error: expected ‘}’ before ‘_draw_polygon’_imaging.c:2646: error: expected ‘}’ before ‘_draw_rectangle’_imaging.c:2647: error: expected ‘}’ before ‘_draw_point’_imaging.c:2648: error: expected ‘}’ before ‘_draw_points’_imaging.c:2649: error: expected ‘}’ before ‘_draw_arc’_imaging.c:2650: error: expected ‘}’ before ‘_draw_bitmap’_imaging.c:2651: error: expected ‘}’ before ‘_draw_chord’_imaging.c:2652: error: expected ‘}’ before ‘_draw_ellipse’_imaging.c:2653: error: expected ‘}’ before ‘_draw_pieslice’_imaging.c:2654: error: expected ‘}’ before ‘_draw_ink’_imaging.c:2659: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2668: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c: In function ‘pixel_access_dealloc’:_imaging.c:2693: error: ‘PixelAccessObject’ has no member named ‘image’_imaging.c: At top level:_imaging.c:2697: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2708: error: expected declaration specifiers or ‘...’ before ‘PyObject’_imaging.c:2708: error: expected declaration specifiers or ‘...’ before ‘PyObject’_imaging.c: In function ‘pixel_access_setitem’:_imaging.c:2710: error: ‘PixelAccessObject’ has no member named ‘image’_imaging.c:2714: error: ‘PixelAccessObject’ has no member named ‘readonly’_imaging.c:2719: warning: implicit declaration of function ‘_getxy’_imaging.c:2719: error: ‘xy’ undeclared (first use in this function)_imaging.c:2723: error: ‘PyExc_IndexError’ undeclared (first use in this function)_imaging.c:2727: error: ‘color’ undeclared (first use in this function)_imaging.c:2730: warning: implicit declaration of function ‘getink’_imaging.c:2733: error: ‘PixelAccessObject’ has no member named ‘image’_imaging.c: At top level:_imaging.c:2744: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2763: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2774: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2791: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2811: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2846: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:2867: error: array type has incomplete element type_imaging.c:2870: error: expected ‘}’ before ‘_getpixel’_imaging.c:2871: error: expected ‘}’ before ‘_putpixel’_imaging.c:2873: error: expected ‘}’ before ‘pixel_access_new’_imaging.c:2876: error: expected ‘}’ before ‘_convert’_imaging.c:2877: error: expected ‘}’ before ‘_convert2’_imaging.c:2878: error: expected ‘}’ before ‘_convert_matrix’_imaging.c:2879: error: expected ‘}’ before ‘_copy’_imaging.c:2880: error: expected ‘}’ before ‘_copy2’_imaging.c:2884: error: expected ‘}’ before ‘_crop’_imaging.c:2885: error: expected ‘}’ before ‘_expand’_imaging.c:2886: error: expected ‘}’ before ‘_filter’_imaging.c:2887: error: expected ‘}’ before ‘_histogram’_imaging.c:2889: error: expected ‘}’ before ‘_modefilter’_imaging.c:2891: error: expected ‘}’ before ‘_offset’_imaging.c:2892: error: expected ‘}’ before ‘_paste’_imaging.c:2893: error: expected ‘}’ before ‘_point’_imaging.c:2894: error: expected ‘}’ before ‘_point_transform’_imaging.c:2895: error: expected ‘}’ before ‘_putdata’_imaging.c:2897: error: expected ‘}’ before ‘_quantize’_imaging.c:2900: error: expected ‘}’ before ‘_rankfilter’_imaging.c:2902: error: expected ‘}’ before ‘_resize’_imaging.c:2903: error: expected ‘}’ before ‘_rotate’_imaging.c:2904: error: expected ‘}’ before ‘_stretch’_imaging.c:2905: error: expected ‘}’ before ‘_transpose’_imaging.c:2906: error: expected ‘}’ before ‘_transform2’_imaging.c:2908: error: expected ‘}’ before ‘_isblock’_imaging.c:2910: error: expected ‘}’ before ‘_getbbox’_imaging.c:2911: error: expected ‘}’ before ‘_getcolors’_imaging.c:2912: error: expected ‘}’ before ‘_getextrema’_imaging.c:2913: error: expected ‘}’ before ‘_getprojection’_imaging.c:2915: error: expected ‘}’ before ‘_getband’_imaging.c:2916: error: expected ‘}’ before ‘_putband’_imaging.c:2917: error: expected ‘}’ before ‘_fillband’_imaging.c:2919: error: expected ‘}’ before ‘im_setmode’_imaging.c:2921: error: expected ‘}’ before ‘_getpalette’_imaging.c:2922: error: expected ‘}’ before ‘_putpalette’_imaging.c:2923: error: expected ‘}’ before ‘_putpalettealpha’_imaging.c:2927: error: expected ‘}’ before ‘_chop_invert’_imaging.c:2928: error: expected ‘}’ before ‘_chop_lighter’_imaging.c:2929: error: expected ‘}’ before ‘_chop_darker’_imaging.c:2930: error: expected ‘}’ before ‘_chop_difference’_imaging.c:2931: error: expected ‘}’ before ‘_chop_multiply’_imaging.c:2932: error: expected ‘}’ before ‘_chop_screen’_imaging.c:2933: error: expected ‘}’ before ‘_chop_add’_imaging.c:2934: error: expected ‘}’ before ‘_chop_subtract’_imaging.c:2935: error: expected ‘}’ before ‘_chop_add_modulo’_imaging.c:2936: error: expected ‘}’ before ‘_chop_subtract_modulo’_imaging.c:2937: error: expected ‘}’ before ‘_chop_and’_imaging.c:2938: error: expected ‘}’ before ‘_chop_or’_imaging.c:2939: error: expected ‘}’ before ‘_chop_xor’_imaging.c:2944: error: expected ‘}’ before ‘_gaussian_blur’_imaging.c:2945: error: expected ‘}’ before ‘_unsharp_mask’_imaging.c:2950: error: expected ‘}’ before ‘_effect_spread’_imaging.c:2954: error: expected ‘}’ before ‘_new_array’_imaging.c:2955: error: expected ‘}’ before ‘_new_block’_imaging.c:2958: error: expected ‘}’ before ‘_save_ppm’_imaging.c:2967: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c: In function ‘image_length’:_imaging.c:2996: error: ‘ImagingObject’ has no member named ‘image’_imaging.c: At top level:_imaging.c:3001: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3016: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘image_as_sequence’_imaging.c:3029: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:3050: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:3062: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:3076: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pixel_access_as_mapping’_imaging.c:3084: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PyTypeObject’_imaging.c:3106: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3107: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3108: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3110: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3112: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3113: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3114: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3115: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3116: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3117: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3118: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3119: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3120: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3123: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3124: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3125: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3126: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3127: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3128: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3129: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3144: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3147: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3149: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3150: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token_imaging.c:3152: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘functions’_imaging.c:3250: warning: return type defaults to ‘int’_imaging.c: In function ‘DL_EXPORT’:_imaging.c:3250: error: expected declaration specifiers before ‘init_imaging’_imaging.c:3281: error: expected ‘{’ at end of inputerror: command 'gcc' failed with exit status 1

  3. cd Imaging-1.1.7/
  4. python setup.py build
  5. sudo python setup.py install

T[][] toTwoDim(T[] array) -- 不可能的任务?

在编码的时候遇到一个问题,关于这样一个签名的方法的实现:

public static <T> T[][] toTwoDim(T[] array)

意思就是"编写一个java函数,传入参数是一个泛型的一维数组,返回值是一个二维的泛型数组";
至于这个函数的具体功能,其实并不是那么重要,我们可以假定一个比较简单的功能:传入一个一维数组,返回的二维数组的第一“行”包含了传入数组的前半部分元素,第二“行”包含了后半部分元素
在stackoverFlow上发贴讨论
也都似乎一致认为这是不可实现的,原因是类型擦除,且数组在java中是一 种特殊的类型,其父类直接是object,似乎没有地方保存了其泛型实参;
但是,我自己现在已经找到了实现方法:
类型擦除是在编译时,要想在运行时找到这个被擦除的类型,就必须用反射;
简而言之,如果反射api中有得出数组元素类型的方法,那这个事情就能实现,反之不能;
恰好有:

array.getClass().getComponentType()

那么:

@SuppressWarnings("unchecked")
    public static <T> T[][] toTwoDim(T[] array) {
        Class<T> ctype = (Class<T>) array.getClass().getComponentType();
        int halfLength = array.length / 2;
        T[][] ret = (T[][]) Array.newInstance(ctype, 2, 1);
        T[] r1 = (T[]) Array.newInstance(ctype, halfLength);
        T[] r2 = (T[]) Array.newInstance(ctype, array.length - halfLength);
        ret[0] = r1;
        ret[1] = r2;
        for (int i = 0; i < halfLength; i++)
            r1[i] = array[i];
        for (int i = 0; i < array.length - halfLength; i++) {
            r2[i] = array[i + halfLength];
        }
        return ret;
    }

    public static void main(String[] a) {
        Integer[] bar = { 1, 2, 3, 4, 5 };
        Integer[][] dims = toTwoDim(bar);
        for (Integer[] r : dims) {
            for (Integer d : r) {
                System.out.print(d + " ");
            }
            System.out.println();
        }
    }

结果:
1 2
3 4 5

那么既然类型已经在编译时擦除,又怎么能在运行时得到呢?
那这个要看清楚了:擦除的是toTwoDim函数的签名及其内部的泛型参数;
而真实传入的参数:Integer[]的类型信息是存在的,且是可以通过反射得到的,所以该函数得以实现

也谈javascript空值判断

也来说说js的判空该怎么写;
首先,牢记两件事情:undefined在js中是一个对象,也就是一个"值";同样,null也是一个对象,其本身也是一个值;
好了,看下面4(3)个变量定义:

// notEx
var ex;
var exN = null;
var exe = 'ex';

我之所以说4个变量是因为我那行注释代表我“心里”定义了一个叫做notEx的变量(实际上它没定义),它是一个不存在的变量(typeof返回'undefined',但notEx是没有“值”的)
第二个变量:ex,是定义了,但是没有赋值,那么它的typeof也返回'undefined',但它是有值的,值就是undefined,这一点可用下面的代码验证:
这行代码会报错:因为notEx没有值

alert(notEx);

这行代码会打印undefined:

alert(ex);

变量exN是有值的,值是null,null是一个object类型的对象;
变量exe是有值的,是一个string类型的对象.
好了,综上考虑,要判断一个变量是否存在且存在了是否为undefined或者null,那么就应该这样判断了:

typeof v != 'undefined' && v != null

其中,typeof v!='undefined'就概括了notEx和ex两种情况(如果简单地用v!=undefined那么遇到notEx会报错);
如果还想判断不为空字符串,那就再&&上v!=''

再多说两句:上面给出的那行判空代码,如果被封装成为一个函数,也是无法传入‘notEx’这样的“未定义”的变量的,因为javascript的函数调用本身就不允许传入未定义的变量,所以,要对不确定是否已定义的变量进行判断,只能不要通过函数参数传入——直接写在想要判断的地方;
不过话说回来,变量未经定义就拿来使用不是一个好习惯,程序设计中应该避免.