Commit 599d8cc2 authored by Olivier Bertrand's avatar Olivier Bertrand

- MDEV-11366 SIGBUS errors in Connect Storage Engine for ArmHF and MIPS.

  Fix includes launchpad fix plus more to cover writing BIN tables.
  modified:   storage/connect/tabfix.cpp
  modified:   storage/connect/value.cpp
  modified:   storage/connect/value.h

- Typo: Change the name of filamzip to filamgz to prepare future ZIP tables.
  modified:   storage/connect/CMakeLists.txt
  added:      storage/connect/filamgz.cpp
  added:      storage/connect/filamgz.h
  deleted:    storage/connect/filamzip.cpp
  deleted:    storage/connect/filamzip.h
  modified:   storage/connect/plgdbsem.h
  modified:   storage/connect/reldef.cpp
  modified:   storage/connect/tabdos.cpp
  modified:   storage/connect/tabdos.h
  modified:   storage/connect/tabfix.cpp
  modified:   storage/connect/tabfmt.cpp
  modified:   storage/connect/tabjson.cpp
parent 2d78b25c
......@@ -20,14 +20,14 @@ SET(CONNECT_SOURCES
ha_connect.cc connect.cc user_connect.cc mycat.cc
fmdlex.c osutil.c plugutil.c rcmsg.c rcmsg.h
array.cpp blkfil.cpp colblk.cpp csort.cpp
filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamzip.cpp
filamap.cpp filamdbf.cpp filamfix.cpp filamgz.cpp filamtxt.cpp
filter.cpp json.cpp jsonudf.cpp maputil.cpp myconn.cpp myutil.cpp plgdbutl.cpp
reldef.cpp tabcol.cpp tabdos.cpp tabfix.cpp tabfmt.cpp tabjson.cpp table.cpp
tabmul.cpp tabmysql.cpp taboccur.cpp tabpivot.cpp tabsys.cpp tabtbl.cpp tabutil.cpp
tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp
array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h
engmsg.h filamap.h filamdbf.h filamfix.h filamtxt.h filamzip.h
engmsg.h filamap.h filamdbf.h filamfix.h filamgz.h filamtxt.h
filter.h global.h ha_connect.h inihandl.h json.h jsonudf.h maputil.h msgid.h
mycat.h myconn.h myutil.h os.h osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h
resource.h tabcol.h tabdos.h tabfix.h tabfmt.h tabjson.h tabmul.h tabmysql.h
......@@ -38,7 +38,7 @@ user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
# Definitions that are shared for all OSes
#
add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS)
add_definitions( -DHUGE_SUPPORT -DZIP_SUPPORT -DPIVOT_SUPPORT )
add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT -DPIVOT_SUPPORT )
#
......@@ -270,9 +270,9 @@ IF(CONNECT_WITH_JDBC)
# Find required libraries and include directories
SET (JAVA_SOURCES JdbcInterface.java)
add_jar(JdbcInterface ${JAVA_SOURCES})
install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/JavaWrappers.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/JavaWrappers.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
add_definitions(-DJDBC_SUPPORT)
ELSE()
SET(JDBC_LIBRARY "")
......
/************** FilAmZip H Declares Source Code File (.H) **************/
/* Name: FILAMZIP.H Version 1.2 */
/*************** FilAmGz H Declares Source Code File (.H) **************/
/* Name: FILAMGZ.H Version 1.3 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2014 */
/* (C) Copyright to the author Olivier BERTRAND 2005-2016 */
/* */
/* This file contains the GZIP access method classes declares. */
/***********************************************************************/
#ifndef __FILAMZIP_H
#define __FILAMZIP_H
#ifndef __FILAMGZ_H
#define __FILAMGZ_H
#include "zlib.h"
typedef class ZIPFAM *PZIPFAM;
typedef class GZFAM *PGZFAM;
typedef class ZBKFAM *PZBKFAM;
typedef class ZIXFAM *PZIXFAM;
typedef class ZLBFAM *PZLBFAM;
......@@ -20,19 +20,19 @@ typedef class ZLBFAM *PZLBFAM;
/* variable record length files compressed using the gzip library */
/* functions. File is accessed record by record (row). */
/***********************************************************************/
class DllExport ZIPFAM : public TXTFAM {
class DllExport GZFAM : public TXTFAM {
// friend class DOSCOL;
public:
// Constructor
ZIPFAM(PDOSDEF tdp) : TXTFAM(tdp) {Zfile = NULL; Zpos = 0;}
ZIPFAM(PZIPFAM txfp);
GZFAM(PDOSDEF tdp) : TXTFAM(tdp) {Zfile = NULL; Zpos = 0;}
GZFAM(PGZFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZIP;}
virtual AMT GetAmType(void) {return TYPE_AM_GZ;}
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZIPFAM(this);}
{return (PTXF)new(g) GZFAM(this);}
// Methods
virtual void Reset(void);
......@@ -57,14 +57,14 @@ class DllExport ZIPFAM : public TXTFAM {
// Members
gzFile Zfile; // Points to GZ file structure
z_off_t Zpos; // Uncompressed file position
}; // end of class ZIPFAM
}; // end of class GZFAM
/***********************************************************************/
/* This is the access method class declaration for optimized variable */
/* record length files compressed using the gzip library functions. */
/* The File is accessed by block (requires an opt file). */
/***********************************************************************/
class DllExport ZBKFAM : public ZIPFAM {
class DllExport ZBKFAM : public GZFAM {
public:
// Constructor
ZBKFAM(PDOSDEF tdp);
......@@ -167,4 +167,4 @@ class DllExport ZLBFAM : public BLKFAM {
bool Optimized; // true when opt file is available
}; // end of class ZLBFAM
#endif // __FILAMZIP_H
#endif // __FILAMGZ_H
......@@ -123,7 +123,7 @@ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_PRX = 129, /* PROXY access method type no */
TYPE_AM_XTB = 130, /* SYS table access method type */
TYPE_AM_BLK = 131, /* BLK access method type no */
TYPE_AM_ZIP = 132, /* ZIP access method type no */
TYPE_AM_GZ = 132, /* GZ access method type no */
TYPE_AM_ZLIB = 133, /* ZLIB access method type no */
TYPE_AM_JSON = 134, /* JSON access method type no */
TYPE_AM_JSN = 135, /* JSN access method type no */
......
/************* RelDef CPP Program Source Code File (.CPP) **************/
/* PROGRAM NAME: RELDEF */
/* ------------- */
/* Version 1.5 */
/* Version 1.6 */
/* */
/* COPYRIGHT: */
/* ---------- */
......@@ -43,9 +43,9 @@
#if defined(VCT_SUPPORT)
#include "filamvct.h"
#endif // VCT_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#if defined(GZ_SUPPORT)
#include "filamgz.h"
#endif // GZ_SUPPORT
#include "tabdos.h"
#include "valblk.h"
#include "tabmul.h"
......@@ -665,15 +665,15 @@ PTDB OEMDEF::GetTable(PGLOBAL g, MODE mode)
/*********************************************************************/
if (!((PTDBDOS)tdbp)->GetTxfp()) {
if (cmpr) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
if (cmpr == 1)
txfp = new(g) ZIPFAM(defp);
txfp = new(g) GZFAM(defp);
else
txfp = new(g) ZLBFAM(defp);
#else // !ZIP_SUPPORT
#else // !GZ_SUPPORT
strcpy(g->Message, "Compress not supported");
return NULL;
#endif // !ZIP_SUPPORT
#endif // !GZ_SUPPORT
} else if (rfm == RECFM_VAR) {
if (map)
txfp = new(g) MAPFAM(defp);
......
/************* TabDos C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: TABDOS */
/* ------------- */
/* Version 4.9 */
/* Version 4.9.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */
/* (C) Copyright to the author Olivier BERTRAND 1998-2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
......@@ -51,9 +51,9 @@
#include "filamap.h"
#include "filamfix.h"
#include "filamdbf.h"
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#if defined(GZ_SUPPORT)
#include "filamgz.h"
#endif // GZ_SUPPORT
#include "tabdos.h"
#include "tabfix.h"
#include "tabmul.h"
......@@ -350,28 +350,28 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
else if (map)
txfp = new(g) MPXFAM(this);
else if (Compressed) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
txfp = new(g) ZIXFAM(this);
#else // !ZIP_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
#else // !GZ_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL;
#endif // !ZIP_SUPPORT
#endif // !GZ_SUPPORT
} else
txfp = new(g) FIXFAM(this);
tdbp = new(g) TDBFIX(this, txfp);
} else {
if (Compressed) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
if (Compressed == 1)
txfp = new(g) ZIPFAM(this);
txfp = new(g) GZFAM(this);
else
txfp = new(g) ZLBFAM(this);
#else // !ZIP_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
#else // !GZ_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL;
#endif // !ZIP_SUPPORT
#endif // !GZ_SUPPORT
} else if (map)
txfp = new(g) MAPFAM(this);
else
......@@ -396,7 +396,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
if (map) {
txfp = new(g) MBKFAM(this);
} else if (Compressed) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
if (Compressed == 1)
txfp = new(g) ZBKFAM(this);
else {
......@@ -404,7 +404,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
((PZLBFAM)txfp)->SetOptimized(To_Pos != NULL);
} // endelse
#else
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL;
#endif
} else
......@@ -531,13 +531,13 @@ int TDBDOS::ResetTableOpt(PGLOBAL g, bool dop, bool dox)
// except for ZLIB access method.
if (Txfp->GetAmType() == TYPE_AM_MAP) {
Txfp = new(g) MAPFAM((PDOSDEF)To_Def);
#if defined(ZIP_SUPPORT)
} else if (Txfp->GetAmType() == TYPE_AM_ZIP) {
Txfp = new(g) ZIPFAM((PDOSDEF)To_Def);
#if defined(GZ_SUPPORT)
} else if (Txfp->GetAmType() == TYPE_AM_GZ) {
Txfp = new(g) GZFAM((PDOSDEF)To_Def);
} else if (Txfp->GetAmType() == TYPE_AM_ZLIB) {
Txfp->Reset();
((PZLBFAM)Txfp)->SetOptimized(false);
#endif // ZIP_SUPPORT
#endif // GZ_SUPPORT
} else if (Txfp->GetAmType() == TYPE_AM_BLK)
Txfp = new(g) DOSFAM((PDOSDEF)To_Def);
......@@ -2079,10 +2079,10 @@ bool TDBDOS::OpenDB(PGLOBAL g)
/*******************************************************************/
if (Txfp->GetAmType() == TYPE_AM_MAP && Mode == MODE_DELETE)
Txfp = new(g) MAPFAM((PDOSDEF)To_Def);
#if defined(ZIP_SUPPORT)
else if (Txfp->GetAmType() == TYPE_AM_ZIP)
Txfp = new(g) ZIPFAM((PDOSDEF)To_Def);
#endif // ZIP_SUPPORT
#if defined(GZ_SUPPORT)
else if (Txfp->GetAmType() == TYPE_AM_GZ)
Txfp = new(g) GZFAM((PDOSDEF)To_Def);
#endif // GZ_SUPPORT
else // if (Txfp->GetAmType() != TYPE_AM_DOS) ???
Txfp = new(g) DOSFAM((PDOSDEF)To_Def);
......
......@@ -91,7 +91,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
int Maxerr; /* Maximum number of bad records (DBF) */
int ReadMode; /* Specific to DBF */
int Ending; /* Length of end of lines */
int Teds; /* Binary table default endian setting */
char Teds; /* Binary table default endian setting */
}; // end of DOSDEF
/***********************************************************************/
......
/************* TabFix C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: TABFIX */
/* ------------- */
/* Version 4.9 */
/* Version 4.9.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1998-2015 */
/* (C) Copyright to the author Olivier BERTRAND 1998-2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
......@@ -589,9 +589,10 @@ void BINCOL::WriteColumn(PGLOBAL g)
switch (Fmt) {
case 'X':
// Standard not converted values
if (Eds && IsTypeChar(Buf_Type))
*(longlong *)p = Value->GetBigintValue();
else if (Value->GetBinValue(p, Long, Status)) {
if (Eds && IsTypeChar(Buf_Type)) {
if (Status)
Value->GetValueNonAligned<longlong>(p, Value->GetBigintValue());
} else if (Value->GetBinValue(p, Long, Status)) {
sprintf(g->Message, MSG(BIN_F_TOO_LONG),
Name, Value->GetSize(), Long);
longjmp(g->jumper[g->jump_level], 31);
......@@ -605,7 +606,7 @@ void BINCOL::WriteColumn(PGLOBAL g)
sprintf(g->Message, MSG(VALUE_TOO_BIG), n, Name);
longjmp(g->jumper[g->jump_level], 31);
} else if (Status)
*(short *)p = (short)n;
Value->GetValueNonAligned<short>(p, (short)n);
break;
case 'T': // Tiny integer
......@@ -625,7 +626,7 @@ void BINCOL::WriteColumn(PGLOBAL g)
sprintf(g->Message, MSG(VALUE_TOO_BIG), n, Name);
longjmp(g->jumper[g->jump_level], 31);
} else if (Status)
*(int *)p = Value->GetIntValue();
Value->GetValueNonAligned<int>(p, (int)n);
break;
case 'G': // Large (great) integer
......@@ -636,12 +637,12 @@ void BINCOL::WriteColumn(PGLOBAL g)
case 'F': // Float
case 'R': // Real
if (Status)
*(float *)p = (float)Value->GetFloatValue();
Value->GetValueNonAligned<float>(p, (float)Value->GetFloatValue());
break;
case 'D': // Double
if (Status)
*(double *)p = Value->GetFloatValue();
Value->GetValueNonAligned<double>(p, Value->GetFloatValue());
break;
case 'C': // Characters
......
/************* TabFmt C++ Program Source Code File (.CPP) **************/
/* PROGRAM NAME: TABFMT */
/* ------------- */
/* Version 3.9 */
/* Version 3.9.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 2001 - 2015 */
/* (C) Copyright to the author Olivier BERTRAND 2001 - 2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
......@@ -51,9 +51,9 @@
#include "plgdbsem.h"
#include "mycat.h"
#include "filamap.h"
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#if defined(GZ_SUPPORT)
#include "filamgz.h"
#endif // GZ_SUPPORT
#include "tabfmt.h"
#include "tabmul.h"
#define NO_FUNC
......@@ -462,16 +462,16 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
// Should be now compatible with UNIX
txfp = new(g) MAPFAM(this);
} else if (Compressed) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
if (Compressed == 1)
txfp = new(g) ZIPFAM(this);
txfp = new(g) GZFAM(this);
else
txfp = new(g) ZLBFAM(this);
#else // !ZIP_SUPPORT
#else // !GZ_SUPPORT
strcpy(g->Message, "Compress not supported");
return NULL;
#endif // !ZIP_SUPPORT
#endif // !GZ_SUPPORT
} else
txfp = new(g) DOSFAM(this);
......@@ -498,7 +498,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
if (map) {
txfp = new(g) MBKFAM(this);
} else if (Compressed) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
if (Compressed == 1)
txfp = new(g) ZBKFAM(this);
else {
......@@ -506,7 +506,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
((PZLBFAM)txfp)->SetOptimized(To_Pos != NULL);
} // endelse
#else
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL;
#endif
} else
......
/************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.1 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */
/* PROGRAM NAME: tabjson Version 1.2 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2016 */
/* This program are the JSON class DB execution routines. */
/***********************************************************************/
......@@ -25,9 +25,9 @@
//#include "resource.h" // for IDS_COLUMNS
#include "tabjson.h"
#include "filamap.h"
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif // ZIP_SUPPORT
#if defined(GZ_SUPPORT)
#include "filamgz.h"
#endif // GZ_SUPPORT
#include "tabmul.h"
#include "checklvl.h"
#include "resource.h"
......@@ -396,15 +396,15 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
(m == MODE_UPDATE || m == MODE_DELETE));
if (Compressed) {
#if defined(ZIP_SUPPORT)
#if defined(GZ_SUPPORT)
if (Compressed == 1)
txfp = new(g) ZIPFAM(this);
txfp = new(g) GZFAM(this);
else
txfp = new(g) ZLBFAM(this);
#else // !ZIP_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP");
#else // !GZ_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ");
return NULL;
#endif // !ZIP_SUPPORT
#endif // !GZ_SUPPORT
} else if (map)
txfp = new(g) MAPFAM(this);
else
......
/************* Value C++ Functions Source Code File (.CPP) *************/
/* Name: VALUE.CPP Version 2.5 */
/* Name: VALUE.CPP Version 2.6 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2015 */
/* (C) Copyright to the author Olivier BERTRAND 2001-2016 */
/* */
/* This file contains the VALUE and derived classes family functions. */
/* These classes contain values of different types. They are used so */
......@@ -792,19 +792,29 @@ uchar TYPVAL<uchar>::GetTypedValue(PVBLK blk, int n)
/***********************************************************************/
/* TYPVAL SetBinValue: with bytes extracted from a line. */
/* Currently only used reading column of binary files. */
/***********************************************************************/
template <class TYPE>
void TYPVAL<TYPE>::SetBinValue(void *p)
{
Tval = *(TYPE *)p;
Null = false;
} // end of SetBinValue
{
#if defined(UNALIGNED_OK)
// x86 can cast non-aligned memory directly
Tval = *(TYPE *)p;
#else
// Prevent unaligned memory access on MIPS and ArmHF platforms.
// Make use of memcpy instead of straight pointer dereferencing.
// Currently only used by WriteColumn of binary files.
// From original author: Vicentiu Ciorbaru <vicentiu@mariadb.org>
memcpy(&Tval, p, sizeof(TYPE));
#endif
Null = false;
} // end of SetBinValue
/***********************************************************************/
/* GetBinValue: fill a buffer with the internal binary value. */
/* This function checks whether the buffer length is enough and */
/* returns true if not. Actual filling occurs only if go is true. */
/* Currently used by WriteColumn of binary files. */
/* Currently only used writing column of binary files. */
/***********************************************************************/
template <class TYPE>
bool TYPVAL<TYPE>::GetBinValue(void *buf, int buflen, bool go)
......@@ -819,7 +829,16 @@ bool TYPVAL<TYPE>::GetBinValue(void *buf, int buflen, bool go)
//#endif
if (go)
*(TYPE *)buf = Tval;
#if defined(UNALIGNED_OK)
// x86 can cast non-aligned memory directly
*(TYPE *)buf = Tval;
#else
// Prevent unaligned memory access on MIPS and ArmHF platforms.
// Make use of memcpy instead of straight pointer dereferencing.
// Currently only used by WriteColumn of binary files.
// From original author: Vicentiu Ciorbaru <vicentiu@mariadb.org>
memcpy(buf, &Tval, sizeof(TYPE));
#endif
Null = false;
return false;
......
/**************** Value H Declares Source Code File (.H) ***************/
/* Name: VALUE.H Version 2.1 */
/* Name: VALUE.H Version 2.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2001-2014 */
/* (C) Copyright to the author Olivier BERTRAND 2001-2016 */
/* */
/* This file contains the VALUE and derived classes declares. */
/***********************************************************************/
......@@ -16,6 +16,13 @@
#include "assert.h"
#include "block.h"
/***********************************************************************/
/* This should list the processors accepting unaligned numeral values.*/
/***********************************************************************/
#if defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(_M_IA64)
#define UNALIGNED_OK
#endif
/***********************************************************************/
/* Types used in some class definitions. */
/***********************************************************************/
......@@ -116,27 +123,46 @@ class DllExport VALUE : public BLOCK {
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op);
virtual bool FormatValue(PVAL vp, char *fmt) = 0;
/**
Set value from a non-aligned in-memory value in the machine byte order.
TYPE can be either of:
- int, short, longlong
- uint, ushort, ulonglong
- float, double
@param - a pointer to a non-aligned value of type TYPE.
*/
template<typename TYPE>
void SetValueNonAligned(const char *p)
{
#if defined(__i386__) || defined(__x86_64__)
SetValue(*((TYPE*) p)); // x86 can cast non-aligned memory directly
/**
Set value from a non-aligned in-memory value in the machine byte order.
TYPE can be either of:
- int, short, longlong
- uint, ushort, ulonglong
- float, double
@param - a pointer to a non-aligned value of type TYPE.
*/
template<typename TYPE>
void SetValueNonAligned(const char *p)
{
#if defined(UNALIGNED_OK)
SetValue(*((TYPE*)p)); // x86 can cast non-aligned memory directly
#else
TYPE tmp; // a slower version for non-x86 platforms
memcpy(&tmp, p, sizeof(tmp));
SetValue(tmp);
TYPE tmp; // a slower version for non-x86 platforms
memcpy(&tmp, p, sizeof(tmp));
SetValue(tmp);
#endif
}
} // end of SetValueNonAligned
/**
Get value from a non-aligned in-memory value in the machine byte order.
TYPE can be either of:
- int, short, longlong
- uint, ushort, ulonglong
- float, double
@params - a pointer to a non-aligned value of type TYPE, the TYPE value.
*/
template<typename TYPE>
void GetValueNonAligned(char *p, TYPE n)
{
#if defined(UNALIGNED_OK)
*(TYPE *)p = n; // x86 can cast non-aligned memory directly
#else
TYPE tmp = n; // a slower version for non-x86 platforms
memcpy(p, &tmp, sizeof(tmp));
#endif
} // end of SetValueNonAligned
protected:
protected:
virtual bool SetConstFormat(PGLOBAL, FORMAT&) = 0;
const char *GetXfmt(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment