Skip to content

Commit

Permalink
Use appropriate type CSetId/CollId/TTypeId instead plain SSHORT/USHORT
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPeshkoff committed Mar 27, 2024
1 parent 7b09922 commit c2413fb
Show file tree
Hide file tree
Showing 86 changed files with 796 additions and 850 deletions.
8 changes: 4 additions & 4 deletions src/burp/backup.epp
Expand Up @@ -741,13 +741,13 @@ burp_fld* get_fields( burp_rel* relation)

if (!Y.RDB$CHARACTER_SET_ID.NULL)
{
field->fld_character_set_id = Y.RDB$CHARACTER_SET_ID;
field->fld_character_set_id = CSetId(Y.RDB$CHARACTER_SET_ID);
field->fld_flags |= FLD_charset_flag;
}

if (!X.RDB$COLLATION_ID.NULL)
{
field->fld_collation_id = X.RDB$COLLATION_ID;
field->fld_collation_id = CollId(X.RDB$COLLATION_ID);
field->fld_flags |= FLD_collate_flag;
}

Expand Down Expand Up @@ -860,13 +860,13 @@ burp_fld* get_fields( burp_rel* relation)

if (!Y.RDB$CHARACTER_SET_ID.NULL)
{
field->fld_character_set_id = Y.RDB$CHARACTER_SET_ID;
field->fld_character_set_id = CSetId(Y.RDB$CHARACTER_SET_ID);
field->fld_flags |= FLD_charset_flag;
}

if (!X.RDB$COLLATION_ID.NULL)
{
field->fld_collation_id = X.RDB$COLLATION_ID;
field->fld_collation_id = CollId(X.RDB$COLLATION_ID);
field->fld_flags |= FLD_collate_flag;
}

Expand Down
5 changes: 3 additions & 2 deletions src/burp/burp.h
Expand Up @@ -47,6 +47,7 @@
#include "../common/status.h"
#include "../common/sha.h"
#include "../common/classes/ImplementHelper.h"
#include "../jrd/intl.h"

#ifdef HAVE_UNISTD_H
#include <unistd.h>
Expand Down Expand Up @@ -722,8 +723,8 @@ struct burp_fld
SSHORT fld_null_flag;
ISC_QUAD fld_default_value;
ISC_QUAD fld_default_source;
SSHORT fld_character_set_id;
SSHORT fld_collation_id;
CSetId fld_character_set_id;
CollId fld_collation_id;
RCRD_OFFSET fld_sql;
RCRD_OFFSET fld_null;
};
Expand Down
12 changes: 6 additions & 6 deletions src/burp/restore.epp
Expand Up @@ -3888,11 +3888,11 @@ burp_fld* get_field(BurpGlobals* tdgbl, burp_rel* relation)
break;

case att_field_character_set:
field->fld_character_set_id = (USHORT) get_int32(tdgbl);
field->fld_character_set_id = CSetId(get_int32(tdgbl));
break;

case att_field_collation_id:
field->fld_collation_id = (USHORT) get_int32(tdgbl);
field->fld_collation_id = CollId(get_int32(tdgbl));
X.RDB$COLLATION_ID.NULL = FALSE;
X.RDB$COLLATION_ID = field->fld_collation_id;
break;
Expand Down Expand Up @@ -4092,11 +4092,11 @@ burp_fld* get_field(BurpGlobals* tdgbl, burp_rel* relation)
break;

case att_field_character_set:
field->fld_character_set_id = (USHORT) get_int32(tdgbl);
field->fld_character_set_id = CSetId(get_int32(tdgbl));
break;

case att_field_collation_id:
field->fld_collation_id = (USHORT) get_int32(tdgbl);
field->fld_collation_id = CollId(get_int32(tdgbl));
X.RDB$COLLATION_ID.NULL = FALSE;
X.RDB$COLLATION_ID = field->fld_collation_id;
break;
Expand Down Expand Up @@ -11775,13 +11775,13 @@ bool WriteRelationMeta::prepareBatch(BurpGlobals* tdgbl)

SLONG sqlLength, sqlSubType, sqlScale, sqlType;
desc.getSqlInfo(&sqlLength, &sqlSubType, &sqlScale, &sqlType);
SLONG characterSetId = field->fld_character_set_id;
CSetId characterSetId = field->fld_character_set_id;

if (tdgbl->gbl_sw_fix_fss_data && field->fld_character_set_id == CS_UNICODE_FSS &&
((sqlType == SQL_BLOB && field->fld_sub_type == isc_blob_text && !(field->fld_flags & FLD_array)) ||
sqlType == SQL_TEXT || sqlType == SQL_VARYING))
{
characterSetId = tdgbl->gbl_sw_fix_fss_data_id;
characterSetId = CSetId(tdgbl->gbl_sw_fix_fss_data_id);
}
else if (field->fld_flags & FLD_array)
{
Expand Down
5 changes: 3 additions & 2 deletions src/common/CharSet.h
Expand Up @@ -32,6 +32,7 @@

#include "CsConvert.h"
#include "IntlUtil.h"
#include "../jrd/intl.h"

namespace Firebird {

Expand Down Expand Up @@ -89,7 +90,7 @@ class CharSet
public:
virtual ~CharSet() {}

USHORT getId() const { return id; }
CSetId getId() const { return id; }
const char* getName() const { return cs->charset_name; }
UCHAR minBytesPerChar() const { return cs->charset_min_bytes_per_char; }
UCHAR maxBytesPerChar() const { return cs->charset_max_bytes_per_char; }
Expand Down Expand Up @@ -138,7 +139,7 @@ class CharSet
const ULONG startPos, const ULONG length) const = 0;

private:
USHORT id;
CSetId id;
charset* cs;
UCHAR sqlMatchAny[sizeof(ULONG)];
UCHAR sqlMatchOne[sizeof(ULONG)];
Expand Down
3 changes: 2 additions & 1 deletion src/common/TextType.cpp
Expand Up @@ -94,14 +94,15 @@
#include "firebird.h"
#include "iberror.h"
#include "../jrd/intl_classes.h"
#include "../common/TextType.h"
#include "../common/IntlUtil.h"
#include "../common/classes/Aligner.h"


namespace Jrd {


TextType::TextType(TTYPE_ID _type, texttype *_tt, USHORT _attributes, CharSet* _cs)
TextType::TextType(TTypeId _type, texttype *_tt, USHORT _attributes, CharSet* _cs)
: tt(_tt), cs(_cs), type(_type), attributes(_attributes)
{
if (cs->getSqlMatchAnyLength() != 0)
Expand Down
7 changes: 4 additions & 3 deletions src/common/TextType.h
Expand Up @@ -31,6 +31,7 @@
#define JRD_TEXTTYPE_H

#include "../common/classes/MetaString.h"
#include "../jrd/intl.h"

struct texttype;

Expand All @@ -41,7 +42,7 @@ class CharSet;
class TextType
{
public:
TextType(TTYPE_ID _type, texttype* _tt, USHORT _attributes, CharSet* _cs);
TextType(TTypeId _type, texttype* _tt, USHORT _attributes, CharSet* _cs);

private:
TextType(const TextType&); // Not implemented
Expand Down Expand Up @@ -77,7 +78,7 @@ class TextType
ULONG dstLen,
UCHAR* dst);

USHORT getType() const
TTypeId getType() const
{
return type;
}
Expand Down Expand Up @@ -108,7 +109,7 @@ class TextType
CharSet* cs;

private:
TTYPE_ID type;
TTypeId type;
USHORT attributes;

public:
Expand Down
48 changes: 24 additions & 24 deletions src/common/cvt.cpp
Expand Up @@ -276,7 +276,7 @@ static void float_to_text(const dsc* from, dsc* to, Callbacks* cb)

dsc intermediate;
intermediate.dsc_dtype = dtype_text;
intermediate.dsc_ttype() = ttype_ascii;
intermediate.setTextType(ttype_ascii);
// CVC: If you think this is dangerous, replace the "else" with a call to
// MEMMOVE(temp, temp + 1, chars_printed) or something cleverer.
// Paranoid assumption:
Expand Down Expand Up @@ -321,7 +321,7 @@ static void decimal_float_to_text(const dsc* from, dsc* to, DecimalStatus decSt,

dsc intermediate;
intermediate.dsc_dtype = dtype_text;
intermediate.dsc_ttype() = ttype_ascii;
intermediate.setTextType(ttype_ascii);
intermediate.dsc_address = reinterpret_cast<UCHAR*>(temp);
intermediate.dsc_length = strlen(temp);

Expand Down Expand Up @@ -349,7 +349,7 @@ static void int128_to_text(const dsc* from, dsc* to, Callbacks* cb)

dsc intermediate;
intermediate.dsc_dtype = dtype_text;
intermediate.dsc_ttype() = ttype_ascii;
intermediate.setTextType(ttype_ascii);
intermediate.dsc_address = reinterpret_cast<UCHAR*>(temp);
intermediate.dsc_length = strlen(temp);

Expand Down Expand Up @@ -492,7 +492,7 @@ static void integer_to_text(const dsc* from, dsc* to, Callbacks* cb)
ULONG trailing = ULONG(to->dsc_length) - length;
if (trailing > 0)
{
CHARSET_ID chid = cb->getChid(to); // : DSC_GET_CHARSET(to);
CSetId chid = cb->getChid(to); // : DSC_GET_CHARSET(to);

const char pad = chid == ttype_binary ? '\0' : ' ';
memset(q, pad, trailing);
Expand Down Expand Up @@ -1555,11 +1555,11 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c

if ((from->dsc_dtype == dtype_text &&
to->dsc_dtype == dtype_dbkey &&
from->dsc_ttype() == ttype_binary &&
from->getTextType() == ttype_binary &&
from->dsc_length == to->dsc_length) ||
(to->dsc_dtype == dtype_text &&
from->dsc_dtype == dtype_dbkey &&
to->dsc_ttype() == ttype_binary &&
to->getTextType() == ttype_binary &&
from->dsc_length == to->dsc_length))
{
memcpy(p, q, length);
Expand Down Expand Up @@ -1853,12 +1853,12 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c
* unless really required is a good optimization.
*/

CHARSET_ID charset2;
CSetId charset2;
if (cb->transliterate(from, to, charset2))
return;

{ // scope
USHORT strtype_unused;
TTypeId strtype_unused;
UCHAR *ptr;
length = CVT_get_string_ptr_common(from, &strtype_unused, &ptr, NULL, 0, decSt, cb);
q = ptr;
Expand Down Expand Up @@ -1948,7 +1948,7 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c

dsc intermediate;
intermediate.dsc_dtype = dtype_text;
intermediate.dsc_ttype() = ttype_ascii;
intermediate.setTextType(ttype_ascii);
intermediate.makeText(static_cast<USHORT>(strlen(text)), CS_ASCII,
reinterpret_cast<UCHAR*>(text));

Expand Down Expand Up @@ -2019,7 +2019,7 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c
case dtype_dbkey:
if (from->isText())
{
USHORT strtype_unused;
TTypeId strtype_unused;
UCHAR* ptr;
USHORT len = CVT_get_string_ptr_common(from, &strtype_unused, &ptr, NULL, 0, decSt, cb);

Expand Down Expand Up @@ -2281,7 +2281,7 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb)
MOVE_CLEAR(&desc, sizeof(desc));
desc.dsc_address = (UCHAR*) temp;
desc.dsc_dtype = dtype_text;
desc.dsc_ttype() = ttype_ascii;
desc.setTextType(ttype_ascii);
desc.dsc_length = (p - temp);

if (from->isTimeStamp() && version4)
Expand All @@ -2301,7 +2301,7 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb)


void CVT_make_null_string(const dsc* desc,
USHORT to_interp,
TTypeId to_interp,
const char** address,
vary* temp,
USHORT length,
Expand Down Expand Up @@ -2343,7 +2343,7 @@ void CVT_make_null_string(const dsc* desc,


USHORT CVT_make_string(const dsc* desc,
USHORT to_interp,
TTypeId to_interp,
const char** address,
vary* temp,
USHORT length,
Expand Down Expand Up @@ -2495,7 +2495,7 @@ static SSHORT cvt_decompose(const char* string,
dsc errd;
MOVE_CLEAR(&errd, sizeof(errd));
errd.dsc_dtype = dtype_text;
errd.dsc_ttype() = ttype_ascii;
errd.setTextType(ttype_ascii);
errd.dsc_length = length;
errd.dsc_address = reinterpret_cast<UCHAR*>(const_cast<char*>(string));

Expand Down Expand Up @@ -2885,7 +2885,7 @@ Int128 CVT_hex_to_int128(const char* str, USHORT len)
}


USHORT CVT_get_string_ptr_common(const dsc* desc, USHORT* ttype, UCHAR** address,
USHORT CVT_get_string_ptr_common(const dsc* desc, TTypeId* ttype, UCHAR** address,
vary* temp, USHORT length, DecimalStatus decSt, Callbacks* cb)
{
/**************************************
Expand Down Expand Up @@ -3608,25 +3608,25 @@ namespace
}

public:
virtual bool transliterate(const dsc* from, dsc* to, CHARSET_ID&);
virtual CHARSET_ID getChid(const dsc* d);
virtual Jrd::CharSet* getToCharset(CHARSET_ID charset2);
virtual bool transliterate(const dsc* from, dsc* to, CSetId&);
virtual CSetId getChid(const dsc* d);
virtual Jrd::CharSet* getToCharset(CSetId charset2);
virtual void validateData(Jrd::CharSet* toCharset, SLONG length, const UCHAR* q);
virtual ULONG validateLength(Jrd::CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start,
virtual ULONG validateLength(Jrd::CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start,
const USHORT size);
virtual SLONG getLocalDate();
virtual ISC_TIMESTAMP getCurrentGmtTimeStamp();
virtual USHORT getSessionTimeZone();
virtual void isVersion4(bool& v4);
} commonCallbacks(status_exception::raise);

bool CommonCallbacks::transliterate(const dsc*, dsc* to, CHARSET_ID& charset2)
bool CommonCallbacks::transliterate(const dsc*, dsc* to, CSetId& charset2)
{
charset2 = INTL_TTYPE(to);
return false;
}

Jrd::CharSet* CommonCallbacks::getToCharset(CHARSET_ID)
Jrd::CharSet* CommonCallbacks::getToCharset(CSetId)
{
return NULL;
}
Expand All @@ -3635,7 +3635,7 @@ namespace
{
}

ULONG CommonCallbacks::validateLength(Jrd::CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start,
ULONG CommonCallbacks::validateLength(Jrd::CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start,
const USHORT size)
{
if (length > size)
Expand Down Expand Up @@ -3663,7 +3663,7 @@ namespace
return MIN(length, size);
}

CHARSET_ID CommonCallbacks::getChid(const dsc* d)
CSetId CommonCallbacks::getChid(const dsc* d)
{
return INTL_TTYPE(d);
}
Expand Down Expand Up @@ -3692,7 +3692,7 @@ namespace Firebird {
Callbacks* CVT_commonCallbacks = &commonCallbacks;
}

USHORT CVT_get_string_ptr(const dsc* desc, USHORT* ttype, UCHAR** address,
USHORT CVT_get_string_ptr(const dsc* desc, TTypeId* ttype, UCHAR** address,
vary* temp, USHORT length, DecimalStatus decSt, ErrorFunction err)
{
/**************************************
Expand Down

0 comments on commit c2413fb

Please sign in to comment.