DebugString causing a crash

902 views
Skip to first unread message

des fitzgerald

unread,
Apr 4, 2011, 3:26:50 AM4/4/11
to Protocol Buffers
Hi, below is more orless the same example in the on-line documentation

"the message Foo" example turned into a cppunit_test

I thought the DebugString method would always work, based upon what I
have read.
This crashes? any guidance?
thanks
des

static std::string data; // Will store a serialized version of the
message.
void ProtocolsTestCase::testExerciseParsing() {
testCreateSerializedMessage();

// parse from string
testParseFromString();

//
// testDynamicParseFromString();
}
// get on top of dynamic creation of a protobuf message
void ProtocolsTestCase::testCreateSerializedMessage() {
// Create a message and serialize it.
Foo foo;
foo.set_text("Hello World!");
foo.add_numbers(1);
foo.add_numbers(5);
foo.add_numbers(42);

foo.SerializeToString(&data);
}
void ProtocolsTestCase::testParseFromString() {
// Parse the serialized message and check that it contains the
correct data.
Foo foo;
foo.ParseFromString(data);

CPPUNIT_ASSERT(foo.text() == "Hello World!");
CPPUNIT_ASSERT(foo.numbers_size() == 3);
CPPUNIT_ASSERT(foo.numbers(0) == 1);
CPPUNIT_ASSERT(foo.numbers(1) == 5);
CPPUNIT_ASSERT(foo.numbers(2) == 42);
std::string out = foo.DebugString();
lprintf("%s\n", out.c_str());
}

Henner Zeller

unread,
Apr 4, 2011, 1:07:17 PM4/4/11
to des fitzgerald, Protocol Buffers
On Mon, Apr 4, 2011 at 00:26, des fitzgerald
<d...@intrepid-geophysics.com> wrote:
> Hi, below is more orless the same example in the on-line documentation
>
> "the message Foo" example turned into a cppunit_test
>
> I thought the DebugString method would always work, based upon what I
> have read.
> This crashes? any guidance?

Where does it crash (stacktrace?). What compiler are you using ?

> --
> You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
> To post to this group, send email to prot...@googlegroups.com.
> To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
>
>

stew114

unread,
Apr 4, 2011, 8:56:58 PM4/4/11
to Protocol Buffers
Hi Henner,

Thanks for the reply. I am also working on this problem with Des.

The crash occurs on Mac x86_64 and Windows x86 or x86_64. We don't
build on 32 bit mac. Windows compiler is VS2008, MAC is clang. Have
not tested our linux builds.

The crash is in:
const FileDescriptor* DescriptorPool::FindFileByName(const string&
name) const {
MutexLockMaybe lock(mutex_);
...
}

The "this" pointer is NULL. The DescriptorPool singleton methods are
called ( was not created properly?). The
DescriptorPool::generated_pool() is called and appears to be
initialised when stepping through the code. We have triple+ checked we
are linking against the debug libraries and are building debug.


Stack trace below:

WorkStateTask_unittest.exe!
google::protobuf::DescriptorPool::FindFileByName(const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
name="invtaskmodel.proto") Line 873 + 0x3 bytes C++
WorkStateTask_unittest.exe!
invtaskmodel::protobuf_AssignDesc_invtaskmodel_2eproto() Line 195 +
0x2e bytes C++
WorkStateTask_unittest.exe!
google::protobuf::ProtobufOnceType::Init(void (void)*
init_func=0x0053c7b0) Line 79 + 0x5 bytes C++
WorkStateTask_unittest.exe!
google::protobuf::GoogleOnceInit(google::protobuf::ProtobufOnceType *
once=0x006971b4, void (void)* init_func=0x0053c7b0) Line 105 C++
WorkStateTask_unittest.exe!invtaskmodel::`anonymous
namespace'::protobuf_AssignDescriptorsOnce() Line 1269 + 0xf bytes C+
+
WorkStateTask_unittest.exe!
invtaskmodel::InversionTask::GetMetadata() Line 26904 C++
WorkStateTask_unittest.exe!
google::protobuf::Message::GetDescriptor() Line 296 + 0x32 bytes C++
WorkStateTask_unittest.exe!ProtocolsTestCase::testCreateInvTask()
Line 198 + 0xb bytes C++
WorkStateTask_unittest.exe!
CppUnit::TestCaller<ProtocolsTestCase>::runTest() Line 166 + 0x10
bytes C++
> cppunitd_dll.dll!CppUnit::TestSuccessListener::TestSuccessListener() + 0x1b588 bytes



Thanks in advance!
Stewart

stew114

unread,
Apr 4, 2011, 10:25:22 PM4/4/11
to prot...@googlegroups.com, des fitzgerald
Hi Henner,

I have done some more testing and it appears that CPPUNIT, for an unknown reason, is the cause of the problem. The exact same code worked fine when I removed the CPPUNIT wrapping and used assert() instead of CPPUNIT_ASSERT() .

Thanks for your help. If I find out why CPPUNIT was an issue I'll post it.

Cheers,
stewart
Reply all
Reply to author
Forward
0 new messages