Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8396447

Browse files
committed
Create libpgcommon, and move pg_malloc et al to it
libpgcommon is a new static library to allow sharing code among thevarious frontend programs and backend; this lets us eliminate duplicateimplementations of common routines. We avoid libpgport, because that'sintended as a place for porting issues; per discussion, it seems betterto keep them separate.The first use case, and the only implemented by this patch, is pg_mallocand friends, which many frontend programs were already using.At the same time, we can use this to provide palloc emulation functionsfor the frontend; this way, some palloc-using files in the backend canalso be used by the frontend cleanly. To do this, we change palloc() inthe backend to be a function instead of a macro on top ofMemoryContextAlloc(). This was previously believed to cause loss ofperformance, but this implementation has been tweaked by Tom and Andresso that on modern compilers it provides a slight improvement over theprevious one.This lets us clean up some places that were already withlocalized hacks.Most of the pg_malloc/palloc changes in this patch were authored byAndres Freund. Zoltán Böszörményi also independently provided a form ofthat. libpgcommon infrastructure was authored by Álvaro.
1 parent0cb1fac commit8396447

File tree

59 files changed

+332
-684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+332
-684
lines changed

‎contrib/oid2name/oid2name.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ struct options
5050
/* function prototypes */
5151
staticvoidhelp(constchar*progname);
5252
voidget_opts(int,char**,structoptions*);
53-
void*pg_malloc(size_tsize);
54-
void*pg_realloc(void*ptr,size_tsize);
55-
char*pg_strdup(constchar*str);
5653
voidadd_one_elt(char*eltname,eary*eary);
5754
char*get_comma_elts(eary*eary);
5855
PGconn*sql_conn(structoptions*);
@@ -201,53 +198,6 @@ help(const char *progname)
201198
progname,progname);
202199
}
203200

204-
void*
205-
pg_malloc(size_tsize)
206-
{
207-
void*ptr;
208-
209-
/* Avoid unportable behavior of malloc(0) */
210-
if (size==0)
211-
size=1;
212-
ptr=malloc(size);
213-
if (!ptr)
214-
{
215-
fprintf(stderr,"out of memory\n");
216-
exit(1);
217-
}
218-
returnptr;
219-
}
220-
221-
void*
222-
pg_realloc(void*ptr,size_tsize)
223-
{
224-
void*result;
225-
226-
/* Avoid unportable behavior of realloc(NULL, 0) */
227-
if (ptr==NULL&&size==0)
228-
size=1;
229-
result=realloc(ptr,size);
230-
if (!result)
231-
{
232-
fprintf(stderr,"out of memory\n");
233-
exit(1);
234-
}
235-
returnresult;
236-
}
237-
238-
char*
239-
pg_strdup(constchar*str)
240-
{
241-
char*result=strdup(str);
242-
243-
if (!result)
244-
{
245-
fprintf(stderr,"out of memory\n");
246-
exit(1);
247-
}
248-
returnresult;
249-
}
250-
251201
/*
252202
* add_one_elt
253203
*

‎contrib/pg_upgrade/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/check.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/controldata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/controldata.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/dump.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/exec.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/file.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/function.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/function.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/info.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/option.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"miscadmin.h"
1313

‎contrib/pg_upgrade/page.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/page.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/parallel.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/pg_upgrade.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737

38-
#include"postgres.h"
38+
#include"postgres_fe.h"
3939

4040
#include"pg_upgrade.h"
4141

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@ void
451451
prep_status(constchar*fmt,...)
452452
__attribute__((format(PG_PRINTF_ATTRIBUTE,1,2)));
453453
voidcheck_ok(void);
454-
char*pg_strdup(constchar*s);
455-
void*pg_malloc(size_tsize);
456-
void*pg_realloc(void*ptr,size_tsize);
457-
voidpg_free(void*ptr);
458454
constchar*getErrorText(interrNum);
459455
unsignedintstr2uint(constchar*str);
460456
voidpg_putenv(constchar*var,constchar*val);

‎contrib/pg_upgrade/relfilenode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/relfilenode.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/server.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/tablespace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/tablespace.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/util.c

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/util.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

@@ -213,55 +213,6 @@ get_user_info(char **user_name)
213213
}
214214

215215

216-
void*
217-
pg_malloc(size_tsize)
218-
{
219-
void*p;
220-
221-
/* Avoid unportable behavior of malloc(0) */
222-
if (size==0)
223-
size=1;
224-
p=malloc(size);
225-
if (p==NULL)
226-
pg_log(PG_FATAL,"%s: out of memory\n",os_info.progname);
227-
returnp;
228-
}
229-
230-
void*
231-
pg_realloc(void*ptr,size_tsize)
232-
{
233-
void*p;
234-
235-
/* Avoid unportable behavior of realloc(NULL, 0) */
236-
if (ptr==NULL&&size==0)
237-
size=1;
238-
p=realloc(ptr,size);
239-
if (p==NULL)
240-
pg_log(PG_FATAL,"%s: out of memory\n",os_info.progname);
241-
returnp;
242-
}
243-
244-
245-
void
246-
pg_free(void*ptr)
247-
{
248-
if (ptr!=NULL)
249-
free(ptr);
250-
}
251-
252-
253-
char*
254-
pg_strdup(constchar*s)
255-
{
256-
char*result=strdup(s);
257-
258-
if (result==NULL)
259-
pg_log(PG_FATAL,"%s: out of memory\n",os_info.progname);
260-
261-
returnresult;
262-
}
263-
264-
265216
/*
266217
* getErrorText()
267218
*

‎contrib/pg_upgrade/version.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/version.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pg_upgrade/version_old_8_3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*contrib/pg_upgrade/version_old_8_3.c
88
*/
99

10-
#include"postgres.h"
10+
#include"postgres_fe.h"
1111

1212
#include"pg_upgrade.h"
1313

‎contrib/pgbench/pgbench.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -320,59 +320,6 @@ static char *select_only = {
320320
staticvoidsetalarm(intseconds);
321321
staticvoid*threadRun(void*arg);
322322

323-
324-
/*
325-
* routines to check mem allocations and fail noisily.
326-
*/
327-
staticvoid*
328-
pg_malloc(size_tsize)
329-
{
330-
void*result;
331-
332-
/* Avoid unportable behavior of malloc(0) */
333-
if (size==0)
334-
size=1;
335-
result=malloc(size);
336-
if (!result)
337-
{
338-
fprintf(stderr,"out of memory\n");
339-
exit(1);
340-
}
341-
returnresult;
342-
}
343-
344-
staticvoid*
345-
pg_realloc(void*ptr,size_tsize)
346-
{
347-
void*result;
348-
349-
/* Avoid unportable behavior of realloc(NULL, 0) */
350-
if (ptr==NULL&&size==0)
351-
size=1;
352-
result=realloc(ptr,size);
353-
if (!result)
354-
{
355-
fprintf(stderr,"out of memory\n");
356-
exit(1);
357-
}
358-
returnresult;
359-
}
360-
361-
staticchar*
362-
pg_strdup(constchar*s)
363-
{
364-
char*result;
365-
366-
result=strdup(s);
367-
if (!result)
368-
{
369-
fprintf(stderr,"out of memory\n");
370-
exit(1);
371-
}
372-
returnresult;
373-
}
374-
375-
376323
staticvoid
377324
usage(void)
378325
{

‎src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ top_builddir = ..
1313
include Makefile.global
1414

1515
SUBDIRS =\
16+
common\
1617
port\
1718
timezone\
1819
backend\

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp