On 12/30/15, Domingo Alvarez Duarte <sqlite-mail at dev.dadbiz.es> wrote:
> Hello Richard !
>
> I just saw this commit https://www.sqlite.org/src/info/6a4cfc7ab62046eb and
> noticed you've been using magic numbers would it be better to use a macro
> instead ?
>
> I think for other people (and maybe yourself) would be easier to see
> something like "INFO_SIZE_ADJUST" (or any meaningful name) instead of "4".

OVFL_PTR_SZ might be a better name.  4 is the size (in bytes) used by
the pointer to the first overflow page that occurs at the end of the
on-page record.

I spent some time editing the code - substituting OVFL_PTR_SZ for 4 in
appropriate places.  But after looking at that for a while, I felt
like OVFL_PTR_SZ obscured more than it clarified.  So I typed "fossil
revert" to go back to the code as it stands.

I'll continue look for an alternative way to make the intent of the
code clearer.


>
>
> This also happen on other places, although I understand that is hard to
> maintain consistency (there is several places where sqlite3 do use macros
> instead of magic numbers).
>
> Cheers !
> in src/btree.c
>
> 1054 pInfo->nSize = (u16)(&pInfo->pPayload[pInfo->nLocal] - pCell) + 4;
> 1079 assert( pPage->childPtrSize==4 );
> 1083 pInfo->nSize = 4 + getVarint(&pCell[4], (u64*)&pInfo->nKey);
> 1153 if( pInfo->nSize<4 ) pInfo->nSize = 4;
> 1191 if( pInfo->nSize<4 ) pInfo->nSize = 4;
> 1309 Pgno ovfl = get4byte(&pCell[info.nSize-4]);
> 3349 && iFrom==get4byte(pCell+info.nSize-4)
> 5999 ovflPgno = get4byte(pCell + info.nSize - 4);
> 6000 assert( pBt->usableSize > 4 );
> 6001 ovflPageSize = pBt->usableSize - 4;
> 6858 Pgno ovfl = get4byte(&z[info.nSize-4]);
> 9164 assert( pc + info.nSize - 4 <= usableSize );
> 9166 pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
D. Richard Hipp
drh at sqlite.org

Reply via email to