Eliminated some warnings under Windows; wxGetHomeDir problem in wxFile;

eliminated memory leak report by making class table dynamically allocated/freed;
tidied up names in wxClassInfo.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-09-10 11:41:14 +00:00
parent d8c838755a
commit 0c32066b58
19 changed files with 216 additions and 116 deletions

View File

@@ -13,6 +13,15 @@
#pragma implementation "dynlib.h"
#endif
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#ifndef WX_PRECOMP
#endif //WX_PRECOMP
#include <wx/dynlib.h>
#include <wx/filefn.h>
#include <wx/list.h>
@@ -87,9 +96,9 @@ void wxLibrary::PrepareClasses(wxClassInfo **first)
wxClassInfo *info = *first;
while (info)
{
if (info->className)
classTable.Put(info->className, (wxObject *)info);
info = info->next;
if (info->m_className)
classTable.Put(info->m_className, (wxObject *)info);
info = info->m_next;
}
// Set base pointers for each wxClassInfo
@@ -97,10 +106,10 @@ void wxLibrary::PrepareClasses(wxClassInfo **first)
while (info)
{
if (info->GetBaseClassName1())
info->baseInfo1 = (wxClassInfo *)classTable.Get(info->GetBaseClassName1());
info->m_baseInfo1 = (wxClassInfo *)classTable.Get(info->GetBaseClassName1());
if (info->GetBaseClassName2())
info->baseInfo2 = (wxClassInfo *)classTable.Get(info->GetBaseClassName2());
info = info->next;
info->m_baseInfo2 = (wxClassInfo *)classTable.Get(info->GetBaseClassName2());
info = info->m_next;
}
*first = NULL;
}
@@ -111,7 +120,7 @@ void *wxLibrary::GetSymbol(const wxString& symbname)
return dlsym(m_handle, WXSTRINGCAST symbname);
#endif
#ifdef __WINDOWS__
return GetProcAddress(m_handle, WXSTRINGCAST symbname);
return GetProcAddress((HINSTANCE) m_handle, WXSTRINGCAST symbname);
#endif
return NULL;
}

View File

@@ -84,14 +84,14 @@ void ConvertToIeeeExtended(double num, unsigned char *bytes)
bytes[0] = expon >> 8;
bytes[1] = expon;
bytes[2] = hiMant >> 24;
bytes[3] = hiMant >> 16;
bytes[4] = hiMant >> 8;
bytes[5] = hiMant;
bytes[6] = loMant >> 24;
bytes[7] = loMant >> 16;
bytes[8] = loMant >> 8;
bytes[9] = loMant;
bytes[2] = (unsigned char) hiMant >> 24;
bytes[3] = (unsigned char) hiMant >> 16;
bytes[4] = (unsigned char) hiMant >> 8;
bytes[5] = (unsigned char) hiMant;
bytes[6] = (unsigned char) loMant >> 24;
bytes[7] = (unsigned char) loMant >> 16;
bytes[8] = (unsigned char) loMant >> 8;
bytes[9] = (unsigned char) loMant;
}
/*

View File

@@ -788,8 +788,8 @@ bool wxDebugContext::PrintClasses(void)
wxNode *node;
wxClassInfo *info;
wxClassInfo::classTable.BeginFind();
node = wxClassInfo::classTable.Next();
wxClassInfo::sm_classTable->BeginFind();
node = wxClassInfo::sm_classTable->Next();
while (node)
{
info = (wxClassInfo *)node->Data();
@@ -801,7 +801,7 @@ bool wxDebugContext::PrintClasses(void)
wxTrace("is a %s", info->GetBaseClassName1());
else if (info->GetBaseClassName1() && info->GetBaseClassName2())
wxTrace("is a %s, %s", info->GetBaseClassName1(), info->GetBaseClassName2());
if (info->objectConstructor)
if (info->GetConstructor())
wxTrace(": dynamic\n");
else
wxTrace("\n");

View File

@@ -39,18 +39,18 @@ bool wxModule::RegisterModules(void)
wxNode *node;
wxClassInfo* classInfo;
wxClassInfo::classTable.BeginFind();
node = wxClassInfo::classTable.Next();
wxClassInfo::sm_classTable->BeginFind();
node = wxClassInfo::sm_classTable->Next();
while (node)
{
classInfo = (wxClassInfo *)node->Data();
if ((classInfo != (& (wxModule::classwxModule))) &&
if ((classInfo != (& (wxModule::sm_classwxModule))) &&
classInfo->IsKindOf(CLASSINFO(wxModule)))
{
wxModule* module = (wxModule*) classInfo->CreateObject();
RegisterModule(module);
}
node = wxClassInfo::classTable.Next();
node = wxClassInfo::sm_classTable->Next();
}
return TRUE;
}

View File

@@ -41,9 +41,9 @@
#endif
#if !USE_SHARED_LIBRARY
wxClassInfo wxObject::classwxObject((char *) "wxObject", (char *) NULL, (char *) NULL, (int ) sizeof(wxObject), (wxObjectConstructorFn) NULL);
wxClassInfo *wxClassInfo::first = (wxClassInfo *) NULL;
wxHashTable wxClassInfo::classTable(wxKEY_STRING);
wxClassInfo wxObject::sm_classwxObject((char *) "wxObject", (char *) NULL, (char *) NULL, (int ) sizeof(wxObject), (wxObjectConstructorFn) NULL);
wxClassInfo* wxClassInfo::sm_first = (wxClassInfo *) NULL;
wxHashTable* wxClassInfo::sm_classTable = (wxHashTable*) NULL;
#endif
/*
@@ -130,36 +130,36 @@ void wxObject::operator delete[] (void * buf)
wxClassInfo::wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn constr)
{
className = cName;
baseClassName1 = baseName1;
baseClassName2 = baseName2;
m_className = cName;
m_baseClassName1 = baseName1;
m_baseClassName2 = baseName2;
objectSize = sz;
objectConstructor = constr;
m_objectSize = sz;
m_objectConstructor = constr;
next = first;
first = this;
m_next = sm_first;
sm_first = this;
baseInfo1 = (wxClassInfo *) NULL;
baseInfo2 = (wxClassInfo *) NULL;
m_baseInfo1 = (wxClassInfo *) NULL;
m_baseInfo2 = (wxClassInfo *) NULL;
}
wxObject *wxClassInfo::CreateObject(void)
{
if (objectConstructor)
return (wxObject *)(*objectConstructor)();
if (m_objectConstructor)
return (wxObject *)(*m_objectConstructor)();
else
return (wxObject *) NULL;
}
wxClassInfo *wxClassInfo::FindClass(char *c)
{
wxClassInfo *p = first;
wxClassInfo *p = sm_first;
while (p)
{
if (p && p->GetClassName() && strcmp(p->GetClassName(), c) == 0)
return p;
p = p->next;
p = p->m_next;
}
return (wxClassInfo *) NULL;
}
@@ -174,20 +174,22 @@ bool wxClassInfo::IsKindOf(wxClassInfo *info)
// For some reason, when making/using a DLL, static data has to be included
// in both the DLL and the application. This can lead to duplicate
// wxClassInfo objects, so we have to test the name instead of the pointers.
// PROBABLY NO LONGER TRUE now I've done DLL creation right.
/*
#if WXMAKINGDLL
if (GetClassName() && info->GetClassName() && (strcmp(GetClassName(), info->GetClassName()) == 0))
return TRUE;
#else
*/
if (this == info)
return TRUE;
#endif
if (baseInfo1)
if (baseInfo1->IsKindOf(info))
if (m_baseInfo1)
if (m_baseInfo1->IsKindOf(info))
return TRUE;
if (baseInfo2)
return baseInfo2->IsKindOf(info);
if (m_baseInfo2)
return m_baseInfo2->IsKindOf(info);
return FALSE;
}
@@ -195,37 +197,58 @@ bool wxClassInfo::IsKindOf(wxClassInfo *info)
// Set pointers to base class(es) to speed up IsKindOf
void wxClassInfo::InitializeClasses(void)
{
wxClassInfo::sm_classTable = new wxHashTable(wxKEY_STRING);
// Index all class infos by their class name
wxClassInfo *info = first;
wxClassInfo *info = sm_first;
while (info)
{
if (info->className)
classTable.Put(info->className, (wxObject *)info);
info = info->next;
if (info->m_className)
sm_classTable->Put(info->m_className, (wxObject *)info);
info = info->m_next;
}
// Set base pointers for each wxClassInfo
info = first;
info = sm_first;
while (info)
{
if (info->GetBaseClassName1())
info->baseInfo1 = (wxClassInfo *)classTable.Get(info->GetBaseClassName1());
info->m_baseInfo1 = (wxClassInfo *)sm_classTable->Get(info->GetBaseClassName1());
if (info->GetBaseClassName2())
info->baseInfo2 = (wxClassInfo *)classTable.Get(info->GetBaseClassName2());
info = info->next;
info->m_baseInfo2 = (wxClassInfo *)sm_classTable->Get(info->GetBaseClassName2());
info = info->m_next;
}
first = NULL;
}
wxObject *wxCreateDynamicObject(char *name)
// Clean up hash table
void wxClassInfo::CleanUpClasses(void)
{
wxClassInfo *info;
delete wxClassInfo::sm_classTable;
wxClassInfo::sm_classTable = NULL;
}
info = (wxClassInfo *)wxClassInfo::classTable.Get(name);
if (!info)
return (wxObject *)NULL;
wxObject *wxCreateDynamicObject(const char *name)
{
if (wxClassInfo::sm_classTable)
{
wxClassInfo *info = (wxClassInfo *)wxClassInfo::sm_classTable->Get(name);
if (!info)
return (wxObject *)NULL;
return info->CreateObject();
return info->CreateObject();
}
else
{
wxClassInfo *info = wxClassInfo::sm_first;
while (info)
{
if (info->m_className && strcmp(info->m_className, name) == 0)
return info->CreateObject();
info = info->m_next;
}
return (wxObject*) NULL;
}
return (wxObject*) NULL;
}
#ifdef USE_SERIAL

View File

@@ -11,8 +11,8 @@
////////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "socket.h"
#pragma interface
#pragma implementation "socket.cpp"
// #pragma interface
// #pragma implementation "socket.cpp"
#endif
// For compilers that support precompilation, includes "wx.h".
@@ -92,6 +92,9 @@
#ifdef __WINDOWS__
#define close closesocket
#define ioctl ioctlsocket
#ifdef errno
#undef errno
#endif
#define errno WSAGetLastError()
#ifdef EWOULDBLOCK
#undef EWOULDBLOCK
@@ -369,26 +372,26 @@ wxSocketBase& wxSocketBase::WriteMsg(const char *buffer, size_t nbytes)
{
SockMsg msg;
msg.sig[0] = 0xad;
msg.sig[1] = 0xde;
msg.sig[2] = 0xed;
msg.sig[3] = 0xfe;
msg.sig[0] = (char) 0xad;
msg.sig[1] = (char) 0xde;
msg.sig[2] = (char) 0xed;
msg.sig[3] = (char) 0xfe;
msg.len[0] = nbytes & 0xff;
msg.len[1] = (nbytes >> 8) & 0xff;
msg.len[2] = (nbytes >> 16) & 0xff;
msg.len[3] = (nbytes >> 24) & 0xff;
msg.len[0] = (char) nbytes & 0xff;
msg.len[1] = (char) (nbytes >> 8) & 0xff;
msg.len[2] = (char) (nbytes >> 16) & 0xff;
msg.len[3] = (char) (nbytes >> 24) & 0xff;
if (Write((char *)&msg, sizeof(msg)).LastCount() < sizeof(msg))
return *this;
if (Write(buffer, nbytes).LastCount() < nbytes)
return *this;
msg.sig[0] = 0xed;
msg.sig[1] = 0xfe;
msg.sig[2] = 0xad;
msg.sig[3] = 0xde;
msg.len[0] = msg.len[1] = msg.len[2] = msg.len[3] = 0;
msg.sig[0] = (char) 0xed;
msg.sig[1] = (char) 0xfe;
msg.sig[2] = (char) 0xad;
msg.sig[3] = (char) 0xde;
msg.len[0] = msg.len[1] = msg.len[2] = msg.len[3] = (char) 0;
Write((char *)&msg, sizeof(msg));
return *this;
@@ -415,7 +418,7 @@ bool wxSocketBase::IsData() const
FD_ZERO(&sock_set);
FD_SET(m_fd, &sock_set);
select(FD_SETSIZE, &sock_set, NULL, NULL, &tv);
return FD_ISSET(m_fd, &sock_set);
return (FD_ISSET(m_fd, &sock_set) != 0);
}
// ---------------------------------------------------------------------

View File

@@ -348,7 +348,7 @@ wxInputStream& wxInputStream::operator>>(float& f)
}
if (c == '.') {
float f_multiplicator = 0.1;
float f_multiplicator = (float) 0.1;
c = GetC();
while (isdigit(c)) {

View File

@@ -293,6 +293,8 @@ void wxApp::CommonCleanUp(void)
wxCleanUpResourceSystem();
wxSystemSettings::Done();
wxClassInfo::CleanUpClasses();
}
wxLog *wxApp::CreateLogTarget()

View File

@@ -293,6 +293,8 @@ void wxApp::CommonCleanUp(void)
wxCleanUpResourceSystem();
wxSystemSettings::Done();
wxClassInfo::CleanUpClasses();
}
wxLog *wxApp::CreateLogTarget()

View File

@@ -337,6 +337,8 @@ void wxApp::CleanUp()
if (wxWinHandleList)
delete wxWinHandleList ;
wxClassInfo::CleanUpClasses();
// do it as the very last thing because everything else can log messages
wxLog::DontCreateOnDemand();
delete wxLog::SetActiveTarget(NULL);

View File

@@ -81,6 +81,7 @@ COMMONOBJS = \
$(COMMDIR)\docview.obj \
$(COMMDIR)\docmdi.obj \
$(COMMDIR)\dynarray.obj \
$(COMMDIR)\dynlib.obj \
$(COMMDIR)\event.obj \
$(COMMDIR)\file.obj \
$(COMMDIR)\filefn.obj \
@@ -770,6 +771,11 @@ $(COMMDIR)/dynarray.obj: $*.$(SRCSUFF)
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
<<
$(COMMDIR)/dynlib.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@
<<
$(COMMDIR)/event.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF) /Fo$@