8000 make it a bit more c++ · postgrespro/libblobstamper@dfcc968 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfcc968

Browse files
make it a bit more c++
1 parent 01c1be4 commit dfcc968

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

cpp_test.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,16 @@ char blob_data[]="aaalkjdhfs89345yu3ifhjew;lkhf4;lt;o34ithp;eriuwtgp;etup568p34t
1111

1212
int main()
1313
{
14-
wflMemCtx * mctx;
15-
wflBlobDsc blob;
16-
wflBlobDsc * b2;
17-
char* str;
14+
char *res1, *res2;
1815

19-
mctx = wflCreateMemCtx();
16+
poly_contain_prepare(blob_data,strlen(blob_data),&res1, &res2);
2017

21-
blob.mctx = mctx;
22-
blob.data = blob_data;
23-
blob.begin = 0;
24-
blob.end = strlen(blob_data)-1;
18+
19+
printf("---- %s\n",res1);
20+
printf("==== %s\n",res2);
2521

2622

27-
wflBlobDump(&blob);
28-
printf("-----\n");
29-
b2 = wflShiftN(&blob,3);
23+
if (res1) free(res1);
24+
if (res2) free(res2);
3025

31-
str = wflShiftDouble(&blob);
32-
33-
printf("\n aaa = %s\n-----\n",str);
34-
35-
str = wflShiftPgPoint(&blob);
36-
37-
printf("\n aaa = %s\n-----\n",str);
38-
39-
str = wflShiftPgPath(&blob);
40-
41-
printf("\n zzz = %s\n-----\n",str);
42-
43-
wflBlobDump(&blob);
44-
wflBlobDump(b2);
45-
46-
wflDestroyMemCtx(mctx);
4726
}

libwaffleizer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,22 @@ wflShiftPgPoint(wflBlobDsc* blob)
121121
}
122122

123123

124-
char *
124+
std::string
125125
wflShiftPgPath(wflBlobDsc* blob)
126126
{
127127
std::string res = "";
128-
char *pc, *pres;
128+
char *pc;
129129

130130
while (pc = wflShiftPgPoint(blob))
131131
{
132132
if (!res.empty()) res = res + ", ";
133133
res = res + pc;
134134
wflFree(blob->mctx, pc);
135135
}
136+
if (res.empty())
137+
return res;
136138
res = "(" + res + ")";
137-
pres = (char*) wflMalloc(blob->mctx, res.size() + 1);
138-
memcpy(pres,res.c_str(), res.size() + 1);
139-
return pres;
140-
139+
return res;
141140
}
142141

143142
extern "C" {
@@ -149,7 +148,9 @@ poly_contain_prepare(char* in, int in_size, char ** res1, char ** res2)
149148
wflMemCtx * mctx;
150149
wflBlobDsc blob;
151150
wflBlobDsc * b2;
152-
char *r1, *r2;
151+
char *r1;
152+
153+
std::string r2;
153154

154155
mctx = wflCreateMemCtx();
155156

@@ -169,7 +170,7 @@ poly_contain_prepare(char* in, int in_size, char ** res1, char ** res2)
169170

170171
r2 = wflShiftPgPath(& blob);
171172

172-
if (! r2)
173+
if (r2.empty())
173174
{
174175
fprintf(stderr,"Problema\n");
175176
return 1;
@@ -179,9 +180,8 @@ poly_contain_prepare(char* in, int in_size, char ** res1, char ** res2)
179180
memcpy(*res1, r1,strlen(r1) + 1);
180181
free(r1);
181182

182-
*res2 = (char *) malloc(strlen(r 8000 2)+1);
183-
memcpy(*res2, r2,strlen(r2) + 1);
184-
free(r2);
183+
*res2 = (char *) malloc(strlen(r2.c_str())+1);
184+
memcpy(*res2, r2.c_str(), strlen(r2.c_str()) + 1);
185185

186186
return 0;
187187
}

libwaffleizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void wflFree(wflMemCtx * mctx, void* ptr);
2626
wflBlobDsc* wflShiftN(wflBlobDsc* blob, size_t n);
2727
char * wflShiftDouble(wflBlobDsc* blob);
2828
char * wflShiftPgPoint(wflBlobDsc* blob);
29-
char * wflShiftPgPath(wflBlobDsc* blob);
29+
std::string wflShiftPgPath(wflBlobDsc* blob);
3030

3131

3232

0 commit comments

Comments
 (0)
0