473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Bug including a static lib in a MC++ application

Hello,

I think I found a bug in VC 7.1 concerning destruction of stack
objects when linking a static, non managed, C++ library within a
managed C++ application. Here is a repro case :

1) Build a static, unmanaged, library containing the following 2
files. Compiles with /MDd.
// FILE BaseHolder.h
#pragma once
#include <boost/shared_ptr.hpp>

class Base
{};

class Derived : public Base
{};

class Holder
{
public:
Holder(boost::shared_ptr<Base> pointer);
private:
boost::shared_ptr<Base> my_pointer;
};

//FILE BaseHolder.cpp
#include "StdAfx.h"
#include ".\baseholder.h"
Holder::Holder(boost::shared_ptr<Base> pointer)
my_pointer(pointer)

{
}

2) Build a MC++ console application with the following main file (also
compiles with /MDd) :
#include "stdafx.h"
#using <mscorlib.dll>
#include <boost/shared_ptr.hpp>
#include "../static_lib/BaseHolder.h"

void Function()
{
boost::shared_ptr<Derived> pointer (new Derived); //line 1
Holder my_holder (pointer); //line 2
}

int _tmain()
{
Function();
return 0;
}

3) Now, put breakpoints on boost::detail::sp_counted_base::add_ref()
and boost::detail::sp_counted_base::release() to see the shared_ptr
counter goes up and down : these are lines 119 and 129 of
shared_count.hpp in my version of Boost()

Run the program and observes the behaviour :
1) On line 2, add_ref() is called when copying a copy of pointer for
the parameter of Holder constructor.
2) BUG!!! release() is called from somewhere deep inside mscorwks.dll.
There is no shared_ptr to be destroyed at this point (the Holder
contructor has not yet been called).
3) The Holder constructor is called
4) add_ref is called during construction of Holder::my_pointer (counst
is now 2, should be 3).
5) Normal stuff continues (the parameter of Holder constructor is
destroyed, etc etc...). However, we have leaked an abnormal release,
and the program hangs (in
boost::detail::lightweight_mutex::scoped_lock constructor) during
leaving Function, when trying to delete twice the shared_ptr counter.

If you compile the main application as traditionnal C++ (not managed),
everything goes smooth, so I believe the problem lies somewhere within
mscorwks.dll.

If anyone has an idea on a workaround...

Arnaud
MVP - VC
Nov 17 '05 #1
1 1438
Hi Arnaud,

Now I am looking for some resource to help you on this problem.
We will reply in the microsoft.public.vc.language group with more
information soon.
Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lawrence | last post by:
2 Questions: 1.) Can anyone think of a way to speed up this function? It is terribly slow. I plan to reduce the number of directories to 3, which I guess will speed it up in the end. 2.) This...
3
by: MC D | last post by:
I am trying to move my Main() procedure out of a startup form and into it's own class. I've updated the app settings to use the "Globals" class (which contains the main form). Here's what I have:...
1
by: Tom | last post by:
Hi, I have an aspx file and it's cs file. I have another class cs file which execute stored procedure. In the class cs file, there are static methods. But, the button event method in...
0
by: Frank Duan via .NET 247 | last post by:
Hi, I am trying to create a .NET DLL using VC++.NET, which isbasically a wrapper of C functions in a statically linkedlibrary. I would like to ask if there is some good resource onusing static C...
2
by: rmathieu | last post by:
Hi, I want to initialize a static String array in MC++. What I want to do is to initialize my String array like the C# way: new String {"11", "22"} but I could not find an equivalent in MC++. The...
6
by: Maya | last post by:
Hello guys, in C#, is using "static" would be the most proper way to get around calling methods located in different classes? for instance, a method caller in class A wouldn't see a method in class...
7
by: Morgan Cheng | last post by:
In the book *Programming C#* 4th editionby Jesse Liberty, it reads "Actually, the CLR guarantees to start running the static constructor before anything else is done with your class. However, it...
8
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
6
by: recherche | last post by:
Hi! Is the following program valid, although it compiles and executes successfully? // params modifier // used to declare array parameter // value type, no constructor using System;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.