定义一个 swig 接口文件,用于从某个头文件生成每种类型的包装器

发布于 2024-08-31 05:24:53 字数 536 浏览 2 评论 0原文

我们在 Java 项目中使用一些 C 库。几年前,其他一些几年前退休的开发人员(一如既往)为我们创建了所有包装器。包装器是由 swig 生成的,但接口文件现在丢失了。

库及其包装器的基本思想如下:

  • 只有一个函数返回指向某个复杂对象的指针。并且有该函数的包装器。
  • 复杂对象是一个树状结构,有数十种节点种类和类型(C 结构)用于表示它们。每种类型的每个字段都有数百个包装器,我们正在尝试全部使用它们。

该库前段时间进行了更新,现在有一些我们尚未意识到但想要使用的新数据。这些数据包含在我们调用的函数创建的对象间接包含或引用的一些对象中(添加了一些新字段和类型)。

我知道我不应该手动对包装器进行任何更改,而应该修改接口,但正如我已经写的那样,它丢失了。现在我只想生成一些添加/更改的类型的包装器,并将它们添加到我们的旧包装器中,但稍后我想开始创建接口文件,该文件将定义“应该包装什么以及如何包装”。

我们所需的所有定义都在单个头文件中定义。是否可以告诉 swig 为该标头中的每种类型生成包装器?如果可以的话,我该如何编写这样的接口文件?

We're using some C library in our Java project. Several years ago some other developer which has retired few years ago (as always) has created all the wrappers for us. The wrappers were generated by the swig, but the interface file is lost now.

The basic idea of library and the wrappers for it is following:

  • There only one function which returns pointer to some complex object. And there are wrapper for that function.
  • The complex object is a tree-like structure with dozens of node kinds and types (C structures) used to represent them. There are hundreds of wrappers for every field of every type and we're trying to use them all.

The library was updated some time ago and now there are some new data we unaware of which yet, but would like to use. This data is contained in some of the objects indirectly contained or referenced from the object created by the function we call (Some new fields and types were added).

I know that I shouldn't make any changes to the wrappers by hand and should rather modify the interface, but as I already wrote it's missing. For now I only want to generate wrappers some few types which are added/changed and them to our old wrappers, but later I want to start creation of interface file which will define "what and how should be wrapped".

All the definitions necessary for us are defined in single header file. Is it possible to tell swig to generate wrappers for every type in this header? If so, how can I write such interface file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤檠 2024-09-07 05:24:53

来自 swig 教程

事实证明,情况并不总是如此
需要写一个特殊的接口
文件。如果你有头文件,你
通常可以直接将其包含在
SWIG 接口。例如:

 %module example
 %{
 /* Includes the header in the wrapper code */
 #include "header.h"
 %}

 /* Parse the header file to generate wrappers */
 %include "header.h"

From the swig tutorial:

As it turns out, it is not always
necessary to write a special interface
file. If you have a header file, you
can often just include it directly in
the SWIG interface. For example:

 %module example
 %{
 /* Includes the header in the wrapper code */
 #include "header.h"
 %}

 /* Parse the header file to generate wrappers */
 %include "header.h"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文