Skip to content

Commit 3c6ba5b

Browse files
committed
Merge branch 'ob-10.1' into 10.1
2 parents bcc3974 + 341a360 commit 3c6ba5b

File tree

8 files changed

+114
-79
lines changed

8 files changed

+114
-79
lines changed

storage/connect/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ IF(UNIX)
7878

7979
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fexceptions -fPIC ")
8080
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
81-
SET(CONNECT_SOURCES ${CONNECT_SOURCES} inihandl.c)
81+
SET(CONNECT_SOURCES ${CONNECT_SOURCES} inihandl.cpp)
8282
SET(IPHLPAPI_LIBRARY "")
8383
ELSE(NOT UNIX)
8484
SET(CONNECT_SOURCES ${CONNECT_SOURCES}

storage/connect/global.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ DllExport int PlugExit(PGLOBAL); // Plug global termination
217217
DllExport LPSTR PlugRemoveType(LPSTR, LPCSTR);
218218
DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR prefix, LPCSTR name, LPCSTR dir);
219219
DllExport BOOL PlugIsAbsolutePath(LPCSTR path);
220-
DllExport void *PlugAllocMem(PGLOBAL, uint);
220+
DllExport bool AllocSarea(PGLOBAL, uint);
221+
DllExport void FreeSarea(PGLOBAL);
221222
DllExport BOOL PlugSubSet(PGLOBAL, void *, uint);
222223
DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t);
223224
DllExport char *PlugDup(PGLOBAL g, const char *str);

storage/connect/ha_connect.cc

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,9 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
30093009
return NULL;
30103010

30113011
if (!x) {
3012+
const char *p;
30123013
char *s = (ishav) ? havg : body;
3014+
uint j, k, n;
30133015

30143016
// Append the value to the filter
30153017
switch (args[i]->field_type()) {
@@ -3065,16 +3067,38 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
30653067
strcat(s, "'}");
30663068
break;
30673069
default:
3068-
strcat(s, "'");
3069-
strncat(s, res->ptr(), res->length());
3070-
strcat(s, "'");
3071-
} // endswitch field type
3070+
j = strlen(s);
3071+
s[j++] = '\'';
3072+
p = res->ptr();
3073+
n = res->length();
3074+
3075+
for (k = 0; k < n; k++) {
3076+
if (p[k] == '\'')
3077+
s[j++] = '\'';
3078+
3079+
s[j++] = p[k];
3080+
} // endfor k
3081+
3082+
s[j++] = '\'';
3083+
s[j] = 0;
3084+
} // endswitch field type
30723085

30733086
} else {
3074-
strcat(s, "'");
3075-
strncat(s, res->ptr(), res->length());
3076-
strcat(s, "'");
3077-
} // endif tty
3087+
j = strlen(s);
3088+
s[j++] = '\'';
3089+
p = res->ptr();
3090+
n = res->length();
3091+
3092+
for (k = 0; k < n; k++) {
3093+
if (p[k] == '\'')
3094+
s[j++] = '\'';
3095+
3096+
s[j++] = p[k];
3097+
} // endfor k
3098+
3099+
s[j++] = '\'';
3100+
s[j] = 0;
3101+
} // endif tty
30783102

30793103
break;
30803104
default:
@@ -5386,10 +5410,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
53865410
#endif // __WIN__
53875411
//int hdr, mxe;
53885412
int port = 0, mxr = 0, rc = 0, mul = 0, lrecl = 0;
5413+
PCSZ tabtyp = NULL;
53895414
#if defined(ODBC_SUPPORT)
53905415
POPARM sop= NULL;
53915416
PCSZ ucnc= NULL;
5392-
PCSZ tabtyp = NULL;
53935417
bool cnc= false;
53945418
int cto= -1, qto= -1;
53955419
#endif // ODBC_SUPPORT

storage/connect/inihandl.c renamed to storage/connect/inihandl.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// The types and variables used locally
3838
//typedef int bool;
3939
typedef unsigned int uint;
40-
#define SVP(S) ((S) ? S : "<null>")
40+
//#define SVP(S) ((S) ? S : "<null>")
4141
#define _strlwr(P) strlwr(P) //OB: changed this line
4242
#define MAX_PATHNAME_LEN 256
4343
#define N_CACHED_PROFILES 10
@@ -61,8 +61,8 @@ void htrc(char const *fmt, ...)
6161
} /* end of htrc */
6262
#else // !TEST_MODULE
6363
// Normal included functions
64-
extern int trace;
65-
void htrc(char const *fmt, ...);
64+
//extern int trace;
65+
//void htrc(char const *fmt, ...);
6666
#endif // !TEST MODULE
6767

6868

@@ -112,10 +112,11 @@ static PROFILE *MRUProfile[N_CACHED_PROFILES] = {NULL};
112112

113113
//static CRITICAL_SECTION PROFILE_CritSect = CRITICAL_SECTION_INIT("PROFILE_CritSect");
114114

115-
static const char hex[16] = "0123456789ABCDEF";
115+
static const char hex[17] = "0123456789ABCDEF";
116116

117117
BOOL WritePrivateProfileString(LPCSTR section, LPCSTR entry,
118-
LPCSTR string, LPCSTR filename );
118+
LPCSTR string, LPCSTR filename);
119+
119120
/***********************************************************************
120121
* PROFILE_CopyEntry
121122
*
@@ -254,7 +255,7 @@ static PROFILESECTION *PROFILE_Load( FILE *file )
254255
PROFILESECTION* *next_section;
255256
PROFILEKEY *key, *prev_key, **next_key;
256257

257-
first_section = malloc(sizeof(*section));
258+
first_section = (PROFILESECTION*)malloc(sizeof(*section));
258259

259260
if (first_section == NULL)
260261
return NULL;
@@ -281,7 +282,7 @@ static PROFILESECTION *PROFILE_Load( FILE *file )
281282
*p2 = '\0';
282283
p++;
283284

284-
if (!(section = malloc(sizeof(*section) + strlen(p))))
285+
if (!(section = (PROFILESECTION*)malloc(sizeof(*section) + strlen(p))))
285286
break;
286287

287288
strcpy(section->name, p);
@@ -319,13 +320,13 @@ static PROFILESECTION *PROFILE_Load( FILE *file )
319320
} // endif p2
320321

321322
if (*p || !prev_key || *prev_key->name) {
322-
if (!(key = malloc(sizeof(*key) + strlen(p))))
323+
if (!(key = (PROFILEKEY*)malloc(sizeof(*key) + strlen(p))))
323324
break;
324325

325326
strcpy(key->name, p);
326327

327328
if (p2) {
328-
key->value = malloc(strlen(p2)+1);
329+
key->value = (char*)malloc(strlen(p2)+1);
329330
strcpy(key->value, p2);
330331
} else
331332
key->value = NULL;
@@ -452,7 +453,7 @@ static BOOL PROFILE_Open(LPCSTR filename)
452453
/* First time around */
453454
if (!CurProfile)
454455
for (i = 0; i < N_CACHED_PROFILES; i++) {
455-
MRUProfile[i] = malloc(sizeof(PROFILE));
456+
MRUProfile[i] = (PROFILE*)malloc(sizeof(PROFILE));
456457

457458
if (MRUProfile[i] == NULL)
458459
break;
@@ -520,7 +521,7 @@ static BOOL PROFILE_Open(LPCSTR filename)
520521
// strcpy(newdos_name, filename);
521522

522523
// CurProfile->dos_name = newdos_name;
523-
CurProfile->filename = malloc(strlen(filename) + 1);
524+
CurProfile->filename = (char*)malloc(strlen(filename) + 1);
524525
strcpy(CurProfile->filename, filename);
525526

526527
/* Try to open the profile file, first in $HOME/.wine */
@@ -783,7 +784,7 @@ static PROFILEKEY *PROFILE_Find(PROFILESECTION* *section,
783784
if (!create)
784785
return NULL;
785786

786-
if (!(*key = malloc(sizeof(PROFILEKEY) + strlen(key_name))))
787+
if (!(*key = (PROFILEKEY*)malloc(sizeof(PROFILEKEY) + strlen(key_name))))
787788
return NULL;
788789

789790
strcpy((*key)->name, key_name);
@@ -798,15 +799,15 @@ static PROFILEKEY *PROFILE_Find(PROFILESECTION* *section,
798799
if (!create)
799800
return NULL;
800801

801-
*section = malloc(sizeof(PROFILESECTION) + strlen(section_name));
802+
*section = (PROFILESECTION*)malloc(sizeof(PROFILESECTION) + strlen(section_name));
802803

803804
if (*section == NULL)
804805
return NULL;
805806

806807
strcpy((*section)->name, section_name);
807808
(*section)->next = NULL;
808809

809-
if (!((*section)->key = malloc(sizeof(PROFILEKEY) + strlen(key_name)))) {
810+
if (!((*section)->key = (tagPROFILEKEY*)malloc(sizeof(PROFILEKEY) + strlen(key_name)))) {
810811
free(*section);
811812
return NULL;
812813
} // endif malloc
@@ -1052,7 +1053,7 @@ static BOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name,
10521053
} else if (trace > 1)
10531054
htrc(" creating key\n" );
10541055

1055-
key->value = malloc(strlen(value) + 1);
1056+
key->value = (char*)malloc(strlen(value) + 1);
10561057
strcpy(key->value, value);
10571058
CurProfile->changed = TRUE;
10581059
} // endelse
@@ -1125,7 +1126,7 @@ static int PROFILE_GetPrivateProfileString(LPCSTR section, LPCSTR entry,
11251126
if (*p == ' ') { /* ouch, contained trailing ' ' */
11261127
int len = p - (LPSTR)def_val;
11271128

1128-
pDefVal = malloc(len + 1);
1129+
pDefVal = (LPSTR)malloc(len + 1);
11291130
strncpy(pDefVal, def_val, len);
11301131
pDefVal[len] = '\0';
11311132
} // endif *p
@@ -1277,7 +1278,7 @@ BOOL WritePrivateProfileSection(LPCSTR section,
12771278
ret = TRUE;
12781279

12791280
while (*string) {
1280-
LPSTR buf = malloc(strlen(string) + 1);
1281+
LPSTR buf = (LPSTR)malloc(strlen(string) + 1);
12811282
strcpy(buf, string);
12821283

12831284
if ((p = strchr(buf, '='))) {

storage/connect/jsonudf.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,23 +1505,16 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n,
15051505
ml += g->More;
15061506

15071507
if (ml > g->Sarea_Size) {
1508-
#if !defined(DEVELOPMENT)
1509-
if (trace)
1510-
#endif
1511-
htrc("Freeing Sarea at %p size=%d\n", g->Sarea, g->Sarea_Size);
1512-
1513-
free(g->Sarea);
1508+
FreeSarea(g);
15141509

1515-
if (!(g->Sarea = PlugAllocMem(g, ml))) {
1510+
if (AllocSarea(g, ml)) {
15161511
char errmsg[MAX_STR];
15171512

15181513
sprintf(errmsg, MSG(WORK_AREA), g->Message);
15191514
strcpy(g->Message, errmsg);
1520-
g->Sarea_Size = 0;
15211515
return true;
1522-
} // endif Alloc
1516+
} // endif SareaAlloc
15231517

1524-
g->Sarea_Size = ml;
15251518
g->Createas = 0;
15261519
g->Xchk = NULL;
15271520
initid->max_length = rl;

storage/connect/plgdbutl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ PDBUSER PlgMakeUser(PGLOBAL g)
334334
{
335335
PDBUSER dbuserp;
336336

337-
if (!(dbuserp = (PDBUSER)PlugAllocMem(g, (uint)sizeof(DBUSERBLK)))) {
337+
if (!(dbuserp = (PDBUSER)malloc(sizeof(DBUSERBLK)))) {
338338
sprintf(g->Message, MSG(MALLOC_ERROR), "PlgMakeUser");
339339
return NULL;
340340
} // endif dbuserp

storage/connect/plugutil.cpp

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
138138

139139
if (trace > 1)
140140
htrc("PlugInit: Language='%s'\n",
141-
((!Language) ? "Null" : (char*)Language));
141+
((!Language) ? "Null" : (char*)Language));
142142

143143
try {
144144
g = new GLOBAL;
@@ -160,13 +160,11 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
160160
/*******************************************************************/
161161
/* Allocate the main work segment. */
162162
/*******************************************************************/
163-
if (worksize && !(g->Sarea = PlugAllocMem(g, worksize))) {
163+
if (worksize && AllocSarea(g, worksize)) {
164164
char errmsg[MAX_STR];
165165
sprintf(errmsg, MSG(WORK_AREA), g->Message);
166166
strcpy(g->Message, errmsg);
167-
g->Sarea_Size = 0;
168-
} else
169-
g->Sarea_Size = worksize;
167+
} // endif Sarea
170168

171169
g->jump_level = -1; /* New setting to allow recursive call of Plug */
172170
return(g);
@@ -183,15 +181,7 @@ int PlugExit(PGLOBAL g)
183181
if (dup)
184182
free(dup);
185183

186-
if (g->Sarea) {
187-
#if !defined(DEVELOPMENT)
188-
if (trace)
189-
#endif
190-
htrc("Freeing Sarea at %p size=%d\n", g->Sarea, g->Sarea_Size);
191-
192-
free(g->Sarea);
193-
} // endif Sarea
194-
184+
FreeSarea(g);
195185
delete g;
196186
} // endif g
197187

@@ -459,30 +449,65 @@ short GetLineLength(PGLOBAL g)
459449
/***********************************************************************/
460450
/* Program for memory allocation of work and language areas. */
461451
/***********************************************************************/
462-
void *PlugAllocMem(PGLOBAL g, uint size)
452+
bool AllocSarea(PGLOBAL g, uint size)
463453
{
464-
void *areap; /* Pointer to allocated area */
465-
466454
/*********************************************************************/
467455
/* This is the allocation routine for the WIN32/UNIX/AIX version. */
468456
/*********************************************************************/
469-
if (!(areap = malloc(size)))
470-
sprintf(g->Message, MSG(MALLOC_ERROR), "malloc");
457+
#if defined(__WIN__)
458+
if (size >= 1048576) // 1M
459+
g->Sarea = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
460+
else
461+
#endif
462+
g->Sarea = malloc(size);
463+
464+
if (!g->Sarea) {
465+
sprintf(g->Message, MSG(MALLOC_ERROR), "malloc");
466+
g->Sarea_Size = 0;
467+
} else
468+
g->Sarea_Size = size;
471469

472470
#if defined(DEVELOPMENT)
473471
if (true) {
474472
#else
475473
if (trace) {
476474
#endif
477-
if (areap)
478-
htrc("Memory of %u allocated at %p\n", size, areap);
475+
if (g->Sarea)
476+
htrc("Work area of %u allocated at %p\n", size, g->Sarea);
479477
else
480-
htrc("PlugAllocMem: %s\n", g->Message);
478+
htrc("SareaAlloc: %s\n", g->Message);
481479

482480
} // endif trace
483481

484-
return (areap);
485-
} // end of PlugAllocMem
482+
return (!g->Sarea);
483+
} // end of AllocSarea
484+
485+
/***********************************************************************/
486+
/* Program for memory freeing the work area. */
487+
/***********************************************************************/
488+
void FreeSarea(PGLOBAL g)
489+
{
490+
if (g->Sarea) {
491+
#if defined(__WIN__)
492+
if (g->Sarea_Size >= 1048576) // 1M
493+
VirtualFree(g->Sarea, 0, MEM_RELEASE);
494+
else
495+
#endif
496+
free(g->Sarea);
497+
498+
#if defined(DEVELOPMENT)
499+
if (true)
500+
#else
501+
if (trace)
502+
#endif
503+
htrc("Freeing Sarea at %p size = %d\n", g->Sarea, g->Sarea_Size);
504+
505+
g->Sarea = NULL;
506+
g->Sarea_Size = 0;
507+
} // endif Sarea
508+
509+
return;
510+
} // end of FreeSarea
486511

487512
/***********************************************************************/
488513
/* Program for SubSet initialization of memory pools. */

0 commit comments

Comments
 (0)