From ebf52d6a902b88a375fb07637425c2032cabb801 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Fri, 1 Nov 2013 13:26:28 +0100 Subject: [PATCH] [truetype] Minor code refactoring. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two benefits: The allocated FDEF (and IDEF) array gets slightly smaller, and the `ttdebug' demo program has access to function numbers without additional costs. Fortunately, no changes to FontForge are necessary – this is the only external TrueType debugger I know of, but others may exist and should check the code accordingly. * src/truetype/ttinterp.h (TT_CallRec): Replace `Cur_Restart' and `Cur_End' with a pointer to the corresponding `TT_DefRecord' structure. * src/truetype/ttinterp.c (DO_JROT, DO_JMPR, DO_JROF, Ins_ENDF, Ins_CALL, Ins_LOOPCALL, Ins_UNKNOWN, TT_RunIns ): Updated. --- ChangeLog | 20 +++++++++++ src/truetype/ttinterp.c | 74 +++++++++++++++++++---------------------- src/truetype/ttinterp.h | 4 +-- 3 files changed, 57 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f5585a42..757abd904 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2013-11-01 Werner Lemberg + + [truetype] Minor code refactoring. + + Two benefits: The allocated FDEF (and IDEF) array gets slightly + smaller, and the `ttdebug' demo program has access to function + numbers without additional costs. + + Fortunately, no changes to FontForge are necessary – this is the + only external TrueType debugger I know of, but others may exist and + should check the code accordingly. + + * src/truetype/ttinterp.h (TT_CallRec): Replace `Cur_Restart' and + `Cur_End' with a pointer to the corresponding `TT_DefRecord' + structure. + + * src/truetype/ttinterp.c (DO_JROT, DO_JMPR, DO_JROF, Ins_ENDF, + Ins_CALL, Ins_LOOPCALL, Ins_UNKNOWN, TT_RunIns ): + Updated. + 2013-10-27 Werner Lemberg [sfnt] Implement support for `OS/2' table version 5. diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c index fedad9dca..56bc7f8f7 100644 --- a/src/truetype/ttinterp.c +++ b/src/truetype/ttinterp.c @@ -3151,42 +3151,42 @@ } -#define DO_JROT \ - if ( args[1] != 0 ) \ - { \ - if ( args[0] == 0 && CUR.args == 0 ) \ - CUR.error = FT_THROW( Bad_Argument ); \ - CUR.IP += args[0]; \ - if ( CUR.IP < 0 || \ - ( CUR.callTop > 0 && \ - CUR.IP > CUR.callStack[CUR.callTop - 1].Cur_End ) ) \ - CUR.error = FT_THROW( Bad_Argument ); \ - CUR.step_ins = FALSE; \ +#define DO_JROT \ + if ( args[1] != 0 ) \ + { \ + if ( args[0] == 0 && CUR.args == 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.IP += args[0]; \ + if ( CUR.IP < 0 || \ + ( CUR.callTop > 0 && \ + CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.step_ins = FALSE; \ } -#define DO_JMPR \ - if ( args[0] == 0 && CUR.args == 0 ) \ - CUR.error = FT_THROW( Bad_Argument ); \ - CUR.IP += args[0]; \ - if ( CUR.IP < 0 || \ - ( CUR.callTop > 0 && \ - CUR.IP > CUR.callStack[CUR.callTop - 1].Cur_End ) ) \ - CUR.error = FT_THROW( Bad_Argument ); \ +#define DO_JMPR \ + if ( args[0] == 0 && CUR.args == 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.IP += args[0]; \ + if ( CUR.IP < 0 || \ + ( CUR.callTop > 0 && \ + CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \ + CUR.error = FT_THROW( Bad_Argument ); \ CUR.step_ins = FALSE; -#define DO_JROF \ - if ( args[1] == 0 ) \ - { \ - if ( args[0] == 0 && CUR.args == 0 ) \ - CUR.error = FT_THROW( Bad_Argument ); \ - CUR.IP += args[0]; \ - if ( CUR.IP < 0 || \ - ( CUR.callTop > 0 && \ - CUR.IP > CUR.callStack[CUR.callTop - 1].Cur_End ) ) \ - CUR.error = FT_THROW( Bad_Argument ); \ - CUR.step_ins = FALSE; \ +#define DO_JROF \ + if ( args[1] == 0 ) \ + { \ + if ( args[0] == 0 && CUR.args == 0 ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.IP += args[0]; \ + if ( CUR.IP < 0 || \ + ( CUR.callTop > 0 && \ + CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \ + CUR.error = FT_THROW( Bad_Argument ); \ + CUR.step_ins = FALSE; \ } @@ -4902,7 +4902,7 @@ if ( pRec->Cur_Count > 0 ) { CUR.callTop++; - CUR.IP = pRec->Cur_Restart; + CUR.IP = pRec->Def->start; } else /* Loop through the current function */ @@ -4992,8 +4992,7 @@ pCrec->Caller_Range = CUR.curRange; pCrec->Caller_IP = CUR.IP + 1; pCrec->Cur_Count = 1; - pCrec->Cur_Restart = def->start; - pCrec->Cur_End = def->end; + pCrec->Def = def; CUR.callTop++; @@ -5081,8 +5080,7 @@ pCrec->Caller_Range = CUR.curRange; pCrec->Caller_IP = CUR.IP + 1; pCrec->Cur_Count = (FT_Int)args[0]; - pCrec->Cur_Restart = def->start; - pCrec->Cur_End = def->end; + pCrec->Def = def; CUR.callTop++; @@ -7917,8 +7915,7 @@ call->Caller_Range = CUR.curRange; call->Caller_IP = CUR.IP + 1; call->Cur_Count = 1; - call->Cur_Restart = def->start; - call->Cur_End = def->end; + call->Def = def; INS_Goto_CodeRange( def->range, def->start ); @@ -8974,8 +8971,7 @@ callrec->Caller_Range = CUR.curRange; callrec->Caller_IP = CUR.IP + 1; callrec->Cur_Count = 1; - callrec->Cur_Restart = def->start; - callrec->Cur_End = def->end; + callrec->Def = def; if ( INS_Goto_CodeRange( def->range, def->start ) == FAILURE ) goto LErrorLabel_; diff --git a/src/truetype/ttinterp.h b/src/truetype/ttinterp.h index 69f5011ed..b3916acb6 100644 --- a/src/truetype/ttinterp.h +++ b/src/truetype/ttinterp.h @@ -101,8 +101,8 @@ FT_BEGIN_HEADER FT_Int Caller_Range; FT_Long Caller_IP; FT_Long Cur_Count; - FT_Long Cur_Restart; - FT_Long Cur_End; + + TT_DefRecord *Def; /* either FDEF or IDEF */ } TT_CallRec, *TT_CallStack;