Skip to content
Permalink
Browse files
- Make possible to allocate work space larger than 4GB
  All variables handling sizes that were uint are now size_t.
  The variable connect_work_size is now ulong (was uint);
  Also make Json functiosn to allocate a larger memory (M=9 was 7)
  modified:   storage/connect/global.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/json.cpp
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/plgdbutl.cpp
  modified:   storage/connect/plugutil.cpp
  modified:   storage/connect/user_connect.cc

- Fix uninitialised variable (pretty) in Json_File.
  Make Jbin_file accept the same arguments as Json_File ones.
  modified:   storage/connect/jsonudf.cpp

- Change the Level option to Depth (the word currently used)
  (Level being still accepted)
  modified:   storage/connect/mongo.cpp
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabxml.cpp

- Suppress 2nd argument default value for MYSQLtoPLG function
  modified:   storage/connect/myutil.h

- Allow REST tables to be create not specifying a file_name
  modified:   storage/connect/tabrest.cpp
  • Loading branch information
Buggynours committed Oct 1, 2020
1 parent ad0d242 commit 99ab562
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 82 deletions.
@@ -1,7 +1,7 @@
/***********************************************************************/
/* GLOBAL.H: Declaration file used by all CONNECT implementations. */
/* (C) Copyright MariaDB Corporation Ab */
/* Author Olivier Bertrand 1993-2018 */
/* Author Olivier Bertrand 1993-2020 */
/***********************************************************************/

/***********************************************************************/
@@ -112,8 +112,8 @@ extern "C" {
/***********************************************************************/
#include "os.h"

typedef uint OFFSET;
typedef char NAME[9];
typedef size_t OFFSET;
typedef char NAME[9];

typedef struct {
ushort Length;
@@ -136,7 +136,7 @@ typedef struct _parm *PPARM;
/***********************************************************************/
typedef struct { /* Plug Area SubAlloc header */
OFFSET To_Free; /* Offset of next free block */
uint FreeBlk; /* Size of remaining free memory */
size_t FreeBlk; /* Size of remaining free memory */
} POOLHEADER, *PPOOLHEADER;

/***********************************************************************/
@@ -188,7 +188,7 @@ typedef struct _parm {
/***********************************************************************/
typedef struct _global { /* Global structure */
void *Sarea; /* Points to work area */
uint Sarea_Size; /* Work area size */
size_t Sarea_Size; /* Work area size */
PACTIVITY Activityp;
char Message[MAX_STR];
ulong More; /* Used by jsonudf */
@@ -210,16 +210,16 @@ DllExport char *PlugReadMessage(PGLOBAL, int, char *);
DllExport char *PlugGetMessage(PGLOBAL, int);
#endif // XMSG || NEWMSG
#if defined(__WIN__)
DllExport short GetLineLength(PGLOBAL); // Console line length
DllExport short GetLineLength(PGLOBAL); // Console line length
#endif // __WIN__
DllExport PGLOBAL PlugInit(LPCSTR, uint); // Plug global initialization
DllExport int PlugExit(PGLOBAL); // Plug global termination
DllExport PGLOBAL PlugInit(LPCSTR, size_t); // Plug global initialization
DllExport int PlugExit(PGLOBAL); // Plug global termination
DllExport LPSTR PlugRemoveType(LPSTR, LPCSTR);
DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR prefix, LPCSTR name, LPCSTR dir);
DllExport BOOL PlugIsAbsolutePath(LPCSTR path);
DllExport bool AllocSarea(PGLOBAL, uint);
DllExport bool AllocSarea(PGLOBAL, size_t);
DllExport void FreeSarea(PGLOBAL);
DllExport BOOL PlugSubSet(void *, uint);
DllExport BOOL PlugSubSet(void *, size_t);
DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t);
DllExport char *PlugDup(PGLOBAL g, const char *str);
DllExport void *MakePtr(void *, OFFSET);
@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size

extern "C" {
char version[]= "Version 1.07.0001 November 12, 2019";
char version[]= "Version 1.07.0001 September 30, 2020";
#if defined(__WIN__)
char compver[]= "Version 1.07.0001 " __DATE__ " " __TIME__;
char slash= '\\';
@@ -254,8 +254,8 @@ TYPCONV GetTypeConv(void);
char *GetJsonNull(void);
uint GetJsonGrpSize(void);
char *GetJavaWrapper(void);
uint GetWorkSize(void);
void SetWorkSize(uint);
ulong GetWorkSize(void);
void SetWorkSize(ulong);
extern "C" const char *msglang(void);

static char *strz(PGLOBAL g, LEX_STRING &ls);
@@ -348,10 +348,10 @@ static MYSQL_THDVAR_ENUM(
&usetemp_typelib); // typelib

// Size used for g->Sarea_Size
static MYSQL_THDVAR_UINT(work_size,
static MYSQL_THDVAR_ULONG(work_size,
PLUGIN_VAR_RQCMDARG,
"Size of the CONNECT work area.",
NULL, NULL, SZWORK, SZWMIN, UINT_MAX, 1);
NULL, NULL, SZWORK, SZWMIN, ULONG_MAX, 1);

// Size used when converting TEXT columns to VARCHAR
static MYSQL_THDVAR_INT(conv_size,
@@ -461,8 +461,8 @@ char *GetJsonNull(void)
{return connect_hton ? THDVAR(current_thd, json_null) : NULL;}
uint GetJsonGrpSize(void)
{return connect_hton ? THDVAR(current_thd, json_grp_size) : 10;}
uint GetWorkSize(void) {return THDVAR(current_thd, work_size);}
void SetWorkSize(uint)
ulong GetWorkSize(void) {return THDVAR(current_thd, work_size);}
void SetWorkSize(ulong)
{
// Changing the session variable value seems to be impossible here
// and should be done in a check function
@@ -5326,7 +5326,12 @@ static bool add_field(String *sql, const char *field_name, int typ, int len,
int dec, char *key, uint tm, const char *rem, char *dft,
char *xtra, char *fmt, int flag, bool dbf, char v)
{
char var= (len > 255) ? 'V' : v;
#if defined(DEVELOPMENT)
// Some client programs regard CHAR(36) as GUID
char var= (len > 255 || len == 36) ? 'V' : v;
#else
char var = (len > 255) ? 'V' : v;
#endif
bool q, error= false;
const char *type= PLGtoMYSQLtype(typ, dbf, var);

@@ -425,7 +425,7 @@ char *ParseString(PGLOBAL g, int& i, STRG& src)
int n = 0, len = src.len;

// Be sure of memory availability
if (len + 1 - i > (signed)((PPOOLHEADER)g->Sarea)->FreeBlk) {
if ((unsigned)(len + 1 - i) > ((PPOOLHEADER)g->Sarea)->FreeBlk) {
strcpy(g->Message, "ParseString: Out of memory");
return NULL;
} // endif len
@@ -25,7 +25,7 @@
#else
#define PUSH_WARNING(M) htrc(M)
#endif
#define M 7
#define M 9

bool IsNum(PSZ s);
char *NextChr(PSZ s, char sep);
@@ -4423,13 +4423,15 @@ char *json_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
fn = MakePSZ(g, args, 0);

if (args->arg_count > 1) {
int len, pretty, pty = 3;
int len, pretty = 3, pty = 3;
PJSON jsp;
PJVAL jvp = NULL;

pretty = (args->arg_type[1] == INT_RESULT) ? (int)*(longlong*)args->args[1]
: (args->arg_count > 2 && args->arg_type[2] == INT_RESULT)
? (int)*(longlong*)args->args[2] : 3;
for (unsigned int i = 1; i < args->arg_count; i++)
if (args->arg_type[i] == INT_RESULT && *(longlong*)args->args[i] < 4) {
pretty = (int) * (longlong*)args->args[i];
break;
} // endif type

/*******************************************************************************/
/* Parse the json file and allocate its tree structure. */
@@ -5626,20 +5628,19 @@ my_bool jbin_file_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
} else if (args->arg_type[0] != STRING_RESULT || !args->args[0]) {
strcpy(message, "First argument must be a constant string (file name)");
return true;
} else if (args->arg_count > 1 && args->arg_type[1] != STRING_RESULT) {
strcpy(message, "Second argument is not a string (path)");
return true;
} else if (args->arg_count > 2 && args->arg_type[2] != INT_RESULT) {
strcpy(message, "Third argument is not an integer (pretty)");
return true;
} else if (args->arg_count > 3) {
if (args->arg_type[3] != INT_RESULT) {
strcpy(message, "Fourth argument is not an integer (memory)");
} // endifs

for (unsigned int i = 1; i < args->arg_count; i++) {
if (!(args->arg_type[i] == INT_RESULT || args->arg_type[i] == STRING_RESULT)) {
sprintf(message, "Argument %d is not an integer or a string (pretty or path)", i);
return true;
} else
more += (ulong)*(longlong*)args->args[3];
} // endif arg_type

} // endifs
// Take care of eventual memory argument
if (args->arg_type[i] == INT_RESULT && args->args[i])
more += (ulong) * (longlong*)args->args[i];

} // endfor i

initid->maybe_null = 1;
CalcLen(args, false, reslen, memlen);
@@ -5654,7 +5655,7 @@ char *jbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error)
{
char *fn;
int pretty, len = 0, pty = 3;
int pretty = 3, len = 0, pty = 3;
PJSON jsp;
PJVAL jvp = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr;
@@ -5666,7 +5667,12 @@ char *jbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
PlugSubSet(g->Sarea, g->Sarea_Size);
g->Xchk = NULL;
fn = MakePSZ(g, args, 0);
pretty = (args->arg_count > 2 && args->args[2]) ? (int)*(longlong*)args->args[2] : 3;

for (unsigned int i = 1; i < args->arg_count; i++)
if (args->arg_type[i] == INT_RESULT && *(longlong*)args->args[i] < 4) {
pretty = (int) * (longlong*)args->args[i];
break;
} // endif type

/*********************************************************************************/
/* Parse the json file and allocate its tree structure. */
@@ -251,7 +251,7 @@ int MGODISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt)
PCSZ level = GetStringTableOption(g, topt, "Level", NULL);
PMGODEF tdp;

if (level) {
if (level = GetStringTableOption(g, topt, "Depth", level)) {
lvl = atoi(level);
lvl = (lvl > 16) ? 16 : lvl;
} else
@@ -6,8 +6,8 @@

enum enum_field_types PLGtoMYSQL(int type, bool dbf, char var = 0);
const char *PLGtoMYSQLtype(int type, bool dbf, char var = 0);
int MYSQLtoPLG(char *typname, char *var = NULL);
int MYSQLtoPLG(int mytype, char *var = NULL);
int MYSQLtoPLG(char *typname, char *var);
int MYSQLtoPLG(int mytype, char *var);
PCSZ MyDateFmt(int mytype);
PCSZ MyDateFmt(char *typname);

@@ -5,7 +5,7 @@
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1998-2018 */
/* (C) Copyright to the author Olivier BERTRAND 1998-2020 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
@@ -1242,7 +1242,7 @@ void *PlgDBalloc(PGLOBAL g, void *area, MBLOCK& mp)
mp.Sub = mp.Size <= ((mp.Sub) ? maxsub : (maxsub >> 2));

if (trace(2))
htrc("PlgDBalloc: in %p size=%d used=%d free=%d sub=%d\n",
htrc("PlgDBalloc: in %p size=%zd used=%zd free=%zd sub=%d\n",
arp, mp.Size, pph->To_Free, pph->FreeBlk, mp.Sub);

if (!mp.Sub) {
@@ -1258,7 +1258,7 @@ void *PlgDBalloc(PGLOBAL g, void *area, MBLOCK& mp)
mp.Memp = malloc(mp.Size);

if (trace(8))
htrc("PlgDBalloc: %s(%d) at %p\n", v, mp.Size, mp.Memp);
htrc("PlgDBalloc: %s(%zd) at %p\n", v, mp.Size, mp.Memp);

if (!mp.Inlist && mp.Memp) {
// New allocated block, put it in the memory block chain.
@@ -1290,7 +1290,7 @@ void *PlgDBrealloc(PGLOBAL g, void *area, MBLOCK& mp, size_t newsize)
#endif

if (trace(2))
htrc("PlgDBrealloc: %p size=%d sub=%d\n", mp.Memp, mp.Size, mp.Sub);
htrc("PlgDBrealloc: %p size=%zd sub=%d\n", mp.Memp, mp.Size, mp.Sub);

if (newsize == mp.Size)
return mp.Memp; // Nothing to do
@@ -1340,7 +1340,7 @@ void *PlgDBrealloc(PGLOBAL g, void *area, MBLOCK& mp, size_t newsize)
} // endif's

if (trace(8))
htrc(" newsize=%d newp=%p sub=%d\n", mp.Size, mp.Memp, mp.Sub);
htrc(" newsize=%zd newp=%p sub=%d\n", mp.Size, mp.Memp, mp.Sub);

return mp.Memp;
} // end of PlgDBrealloc
@@ -1392,13 +1392,13 @@ void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size)
pph = (PPOOLHEADER)memp;

if (trace(16))
htrc("PlgDBSubAlloc: memp=%p size=%d used=%d free=%d\n",
htrc("PlgDBSubAlloc: memp=%p size=%zd used=%zd free=%zd\n",
memp, size, pph->To_Free, pph->FreeBlk);

if ((uint)size > pph->FreeBlk) { /* Not enough memory left in pool */
if (size > pph->FreeBlk) { /* Not enough memory left in pool */
sprintf(g->Message,
"Not enough memory in Work area for request of %d (used=%d free=%d)",
(int) size, pph->To_Free, pph->FreeBlk);
"Not enough memory in Work area for request of %zd (used=%zd free=%zd)",
size, pph->To_Free, pph->FreeBlk);

if (trace(1))
htrc("%s\n", g->Message);
@@ -1414,7 +1414,7 @@ void *PlgDBSubAlloc(PGLOBAL g, void *memp, size_t size)
pph->FreeBlk -= size; // New size of pool free block

if (trace(16))
htrc("Done memp=%p used=%d free=%d\n",
htrc("Done memp=%p used=%zd free=%zd\n",
memp, pph->To_Free, pph->FreeBlk);

return (memp);
@@ -6,7 +6,7 @@
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier BERTRAND 1993-2019 */
/* (C) Copyright to the author Olivier BERTRAND 1993-2020 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
@@ -142,7 +142,7 @@ void htrc(char const* fmt, ...)
/* Language points on initial language name and eventual path. */
/* Return value is the pointer to the Global structure. */
/***********************************************************************/
PGLOBAL PlugInit(LPCSTR Language, uint worksize)
PGLOBAL PlugInit(LPCSTR Language, size_t worksize)
{
PGLOBAL g;

@@ -459,7 +459,7 @@ short GetLineLength(PGLOBAL g)
/***********************************************************************/
/* Program for memory allocation of work and language areas. */
/***********************************************************************/
bool AllocSarea(PGLOBAL g, uint size)
bool AllocSarea(PGLOBAL g, size_t size)
{
/*********************************************************************/
/* This is the allocation routine for the WIN32/UNIX/AIX version. */
@@ -483,7 +483,7 @@ bool AllocSarea(PGLOBAL g, uint size)
if (trace(8)) {
#endif
if (g->Sarea)
htrc("Work area of %u allocated at %p\n", size, g->Sarea);
htrc("Work area of %zd allocated at %p\n", size, g->Sarea);
else
htrc("SareaAlloc: %s\n", g->Message);

@@ -510,7 +510,7 @@ void FreeSarea(PGLOBAL g)
#else
if (trace(8))
#endif
htrc("Freeing Sarea at %p size = %d\n", g->Sarea, g->Sarea_Size);
htrc("Freeing Sarea at %p size = %zd\n", g->Sarea, g->Sarea_Size);

g->Sarea = NULL;
g->Sarea_Size = 0;
@@ -524,7 +524,7 @@ void FreeSarea(PGLOBAL g)
/* Here there should be some verification done such as validity of */
/* the address and size not larger than memory size. */
/***********************************************************************/
BOOL PlugSubSet(void *memp, uint size)
BOOL PlugSubSet(void *memp, size_t size)
{
PPOOLHEADER pph = (PPOOLHEADER)memp;

@@ -560,15 +560,15 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
pph = (PPOOLHEADER)memp;

if (trace(16))
htrc("SubAlloc in %p size=%d used=%d free=%d\n",
htrc("SubAlloc in %p size=%zd used=%zd free=%zd\n",
memp, size, pph->To_Free, pph->FreeBlk);

if ((uint)size > pph->FreeBlk) { /* Not enough memory left in pool */
if (size > pph->FreeBlk) { /* Not enough memory left in pool */
PCSZ pname = "Work";

sprintf(g->Message,
"Not enough memory in %s area for request of %u (used=%d free=%d)",
pname, (uint)size, pph->To_Free, pph->FreeBlk);
"Not enough memory in %s area for request of %zd (used=%zd free=%zd)",
pname, size, pph->To_Free, pph->FreeBlk);

if (trace(1))
htrc("PlugSubAlloc: %s\n", g->Message);
@@ -581,10 +581,10 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
/*********************************************************************/
memp = MakePtr(memp, pph->To_Free); /* Points to suballocated block */
pph->To_Free += (OFFSET)size; /* New offset of pool free block */
pph->FreeBlk -= (uint)size; /* New size of pool free block */
pph->FreeBlk -= size; /* New size of pool free block */

if (trace(16))
htrc("Done memp=%p used=%d free=%d\n",
htrc("Done memp=%p used=%zd free=%zd\n",
memp, pph->To_Free, pph->FreeBlk);

return (memp);

0 comments on commit 99ab562

Please sign in to comment.