简体   繁体   English

复制包含字符串的CORBA :: Any时,CORBA程序seg错误

[英]CORBA program seg faults when copying CORBA::Any containing a string

I'm working on legacy product that uses CORBA. 我正在研究使用CORBA的旧产品。 We're looking to support omniiORB as another vendor. 我们希望将omn​​iiORB作为另一个供应商来支持。 I ran into one of our tests seg faulting, and I'm trying to understand if we've been doing something wrong that just happened to work with other vendors, or if there's a bug with omniiORB. 我遇到了一个测试段错误,并且试图了解我们是否在做与其他供应商一起使用的错误操作,或者omniiORB是否存在错误。

I tested with the version of omniiORB that comes in the Red Hat EPEL (4.2.0). 我测试了Red Hat EPEL(4.2.0)中提供的omniiORB版本。 I also downloaded and build the latest version, 4.2.3, and still saw the error. 我还下载并构建了最新版本4.2.3,仍然看到错误。

Below is a test case that I think demonstrates the behavior I'm seeing in our code. 下面是一个测试用例,我认为它演示了我在代码中看到的行为。

#include <omniORB4/CORBA.h>
//#include "typedefs.hh"

#include <iostream>

// only happens with string types.
// primitive CORBA types and user-defined types don't cause the error

int main() {
  CORBA::Any any1;
  any1 <<= "Hello";

  CORBA::Any any2;
  any2 = any1;  // copy the any, seg fault in omniiorb
  // any2 <<= any1; // any inside any, also seg faults
  // CORBA::Any any2(any1); // copy constructor, also seg faults

  return 0;
}

I know extracting to a generated smart pointer causes issues since the any should keep ownership. 我知道提取到生成的智能指针会导致问题,因为任何指针都应保持所有权。 But in the case of copying an Any, isn't it supposed to do a deep copy? 但是在复制Any的情况下,是否应该进行深层复制? What am I missing here? 我在这里想念什么?

I have another short example that is closer to what our legacy code does that involves a simple IDL if this example is deemed unrepresentative. 我还有另一个简短的示例,如果我们认为该示例不具有代表性,则该示例更接近于我们的旧代码所做的工作,其中涉及简单的IDL。

The gist of what the legacy code does is copy properties that use an any for the value, so it can be anything. 遗留代码要做的要点是将值使用any的复制属性,因此可以是任意值。 We haven't seen any issues in the past with Visibroker or ACE+TAO. 过去,Visibroker或ACE + TAO都没有出现任何问题。

The problem was on our side and its because we were not initializing the ORB runtime through CORBA::ORB_init(). 问题就在我们这边,这是因为我们没有通过CORBA :: ORB_init()初始化ORB运行时。

So the example described in the question is invalid and should be: 因此,问题中描述的示例无效,应为:

#include <omniORB4/CORBA.h>
#include "typedefs.hh"

#include <iostream>

// only happens with string types.
// primitive CORBA types and user-defined types don't cause the error

int main(int argc, char*argv[]) {
  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4");

  CORBA::Any any1;
  any1 <<= "Hello";

  CORBA::Any any2;
  any2 = any1;

  return 0;
}

Most of our CORBA code does initialize the ORB runtime, but the test I encountered was a unit test that dealt with translating and copying different CORBA types. 我们的大多数CORBA代码都确实初始化了ORB运行时,但是我遇到的测试是一个单元测试,涉及转换和复制不同的CORBA类型。 We assumed the initialization was only necessary when making network calls, rather than being required before ANY CORBA-related calls. 我们认为初始化仅在进行网络调用时才需要,而在任何与CORBA相关的调用之前都不需要进行初始化。

The test code happened to work with Orbix, Visibroker, and ACE+TAO since in those implementations it didn't matter. 测试代码碰巧可以与Orbix,Visibroker和ACE + TAO一起使用,因为在这些实现中,这无关紧要。 It failed in omniiORB because some of native codeset internal implementation details (and other things) aren't initialized (they're null) until ORB_init() is called and this caused the seg fault. 它在omniiORB中失败,因为在调用ORB_init()之前未初始化某些本机代码集内部实现细节(及其他内容)(它们为null),这导致了seg错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM