gpt4 book ai didi

c - PostgreSQL Type 1 接口(interface)和 ImageMagick 代码 - 冲突的 StringInfo 定义?

转载 作者:太空宇宙 更新时间:2023-11-03 23:55:57 27 4
gpt4 key购买 nike

这里遇到一个问题,试图将 ImageMagick 的代码片段集成到 PostgreSQL 中;这两个“框架”使用 StringInfo 的定义 - 当然,它们会发生冲突。

在 make 时,得到这个错误:

 /usr/include/magick/string_.h:42: error: conflicting types for 'StringInfo'
../../src/include/lib/stringinfo.h:43: error: previous declaration of 'StringInfo' was here

关于我如何将两者结合起来有什么建议吗?

typedef struct _StringInfo
{
char
path[MaxTextExtent];

unsigned char
*datum;

size_t
length;

unsigned long
signature;
} StringInfo;

而 PostgreSQL 想要这样做:

typedef struct StringInfoData
{
char *data;
int len;
int maxlen;
int cursor;
} StringInfoData;

typedef StringInfoData *StringInfo;


/*------------------------
* There are two ways to create a StringInfo object initially:
*
* StringInfo stringptr = makeStringInfo();
* Both the StringInfoData and the data buffer are palloc'd.
*
* StringInfoData string;
* initStringInfo(&string);
* The data buffer is palloc'd but the StringInfoData is just local.
* This is the easiest approach for a StringInfo object that will
* only live as long as the current routine.
*
* To destroy a StringInfo, pfree() the data buffer, and then pfree() the
* StringInfoData if it was palloc'd. There's no special support for this.
*
* NOTE: some routines build up a string using StringInfo, and then
* release the StringInfoData but return the data string itself to their
* caller. At that point the data string looks like a plain palloc'd
* string.
*-------------------------
*/

/*------------------------
* makeStringInfo
* Create an empty 'StringInfoData' & return a pointer to it.
*/
extern StringInfo makeStringInfo(void);

/*------------------------
* initStringInfo
* Initialize a StringInfoData struct (with previously undefined contents)
* to describe an empty string.
*/
extern void initStringInfo(StringInfo str);

/*------------------------
* resetStringInfo
* Clears the current content of the StringInfo, if any. The
* StringInfo remains valid.
*/
extern void resetStringInfo(StringInfo str);

最佳答案

我认为明显的答案是尽量不要将两者结合起来,而是考虑将 ImageMagick 代码编译成 .so 并在 PostgreSQL 代码中使用一组更窄的接口(interface)链接到它的可能性.这样 StringInfo 根本不需要出现在您的桥接代码中,或者如果您需要它,您可以使用不同的名称来定义它。

另一种选择是更改 ImageMagick 端的名称,并确保更改所有适当位置的代码。然而,这使得合并到新版本的程序变得更加困难。我强烈建议尝试使用模块化方法来尝试确保两者永远不会共享一个范围。

关于c - PostgreSQL Type 1 接口(interface)和 ImageMagick 代码 - 冲突的 StringInfo 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7734249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com