diff --git a/microscript/ILibDuktape_Polyfills.c b/microscript/ILibDuktape_Polyfills.c index ce8b320..1fef0fa 100644 --- a/microscript/ILibDuktape_Polyfills.c +++ b/microscript/ILibDuktape_Polyfills.c @@ -2455,7 +2455,7 @@ void ILibDuktape_ChainViewer_Push(duk_context *ctx, void *chain) duk_push_object(ctx); // [viewer] ILibTransport *t = (ILibTransport*)ILibChain_Link_Allocate(sizeof(ILibTransport), 2*sizeof(void*)); - t->ChainLink.MetaData = "ILibDuktape_ChainViewer"; + t->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibDuktape_ChainViewer"); t->ChainLink.PostSelectHandler = ILibDuktape_ChainViewer_PostSelect; ((void**)t->ChainLink.ExtraMemoryPtr)[0] = ctx; ((void**)t->ChainLink.ExtraMemoryPtr)[1] = duk_get_heapptr(ctx, -1); diff --git a/microscript/ILibDuktape_fs.c b/microscript/ILibDuktape_fs.c index 47bf2be..5f41724 100644 --- a/microscript/ILibDuktape_fs.c +++ b/microscript/ILibDuktape_fs.c @@ -2009,7 +2009,7 @@ duk_ret_t ILibDuktape_fs_watch(duk_context *ctx) else { notifyDispatcher = ILibMemory_Allocate(sizeof(ILibDuktape_fs_linuxWatcher), 0, NULL, NULL); - notifyDispatcher->chainLink.MetaData = "ILibDuktape_fs_linuxWatcher"; + notifyDispatcher->chainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibDuktape_fs_linuxWatcher"); notifyDispatcher->chainLink.PreSelectHandler = ILibDuktape_fs_notifyDispatcher_PreSelect; notifyDispatcher->chainLink.PostSelectHandler = ILibDuktape_fs_notifyDispatcher_PostSelect; notifyDispatcher->chainLink.DestroyHandler = ILibDuktape_fs_notifyDispatcher_Destroy; diff --git a/microstack/ILibAsyncServerSocket.c b/microstack/ILibAsyncServerSocket.c index c1f02a0..46f5375 100644 --- a/microstack/ILibAsyncServerSocket.c +++ b/microstack/ILibAsyncServerSocket.c @@ -633,7 +633,7 @@ ILibAsyncServerSocket_ServerModule ILibCreateAsyncServerSocketModuleWithMemoryEx // Instantiate a new AsyncServer module RetVal = (struct ILibAsyncServerSocketModule*)ILibChain_Link_Allocate(sizeof(struct ILibAsyncServerSocketModule), ServerUserMappedMemorySize); - RetVal->ChainLink.MetaData = "ILibAsyncServerSocket"; + RetVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibAsyncServerSocket"); RetVal->ChainLink.PreSelectHandler = &ILibAsyncServerSocket_PreSelect; RetVal->ChainLink.PostSelectHandler = &ILibAsyncServerSocket_PostSelect; RetVal->ChainLink.DestroyHandler = &ILibAsyncServerSocket_Destroy; diff --git a/microstack/ILibAsyncSocket.c b/microstack/ILibAsyncSocket.c index 2a84ec4..a0f092b 100644 --- a/microstack/ILibAsyncSocket.c +++ b/microstack/ILibAsyncSocket.c @@ -445,7 +445,7 @@ ILibTransport_DoneState ILibAsyncSocket_TransportSend(void *transport, char* buf ILibAsyncSocket_SocketModule ILibCreateAsyncSocketModuleWithMemory(void *Chain, int initialBufferSize, ILibAsyncSocket_OnData OnData, ILibAsyncSocket_OnConnect OnConnect, ILibAsyncSocket_OnDisconnect OnDisconnect, ILibAsyncSocket_OnSendOK OnSendOK, int UserMappedMemorySize) { struct ILibAsyncSocketModule *RetVal = (struct ILibAsyncSocketModule*)ILibChain_Link_Allocate(sizeof(struct ILibAsyncSocketModule), UserMappedMemorySize); - RetVal->Transport.ChainLink.MetaData = "ILibAsyncSocket"; + RetVal->Transport.ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibAsyncSocket"); RetVal->Transport.IdentifierFlags = ILibTransports_AsyncSocket; RetVal->Transport.SendPtr = &ILibAsyncSocket_TransportSend; RetVal->Transport.ClosePtr = &ILibAsyncSocket_Disconnect; diff --git a/microstack/ILibIPAddressMonitor.c b/microstack/ILibIPAddressMonitor.c index be41c8d..eb81832 100644 --- a/microstack/ILibIPAddressMonitor.c +++ b/microstack/ILibIPAddressMonitor.c @@ -138,7 +138,7 @@ void ILibIPAddressMonitor_PostSelect(void* object, int slct, fd_set *readset, fd ILibIPAddressMonitor ILibIPAddressMonitor_Create(void *chain, ILibIPAddressMonitor_Handler handler, void *user) { _ILibIPAddressMonitor *obj = (_ILibIPAddressMonitor*)ILibChain_Link_Allocate(ILibMemory_IPAddressMonitor_CONTAINER_SIZE, 0); - obj->chainLink.MetaData = "ILibIPAddressMonitor"; + obj->chainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibIPAddressMonitor"); #ifndef NO_IPADDR_MONITOR obj->onUpdate = handler; diff --git a/microstack/ILibMulticastSocket.c b/microstack/ILibMulticastSocket.c index a2ac0b6..d8214a7 100644 --- a/microstack/ILibMulticastSocket.c +++ b/microstack/ILibMulticastSocket.c @@ -298,7 +298,7 @@ struct ILibMulticastSocket_StateModule *ILibMulticastSocket_Create(void *Chain, addr6.sin6_port = htons(LocalPort); // Setup the multicasting module - module->ChainLink.MetaData = "ILibMulticastSocket"; + module->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibMulticastSocket"); module->ChainLink.DestroyHandler = &ILibMulticastSocket_Destroy; module->ChainLink.ParentChain = Chain; module->LocalPort = LocalPort; diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index e27c639..4871fc7 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -1009,7 +1009,15 @@ void* ILibMemory_InitEx(void *ptr, size_t primarySize, size_t extraSize, ILibMem return(ILibMemory_Init(ptr, primarySize, extraSize, memType)); } #endif +char* ILibMemory_SmartAllocate_FromStringEx(char *str, size_t strLen) +{ + if (str == NULL) { return(NULL); } + if (strLen == 0) { strLen = strnlen_s(str, sizeof(ILibScratchPad)); } + char *ret = (char*)ILibMemory_SmartAllocate(1+strLen); + memcpy_s(ret, strLen + 1, str, strLen); + return(ret); +} void* ILibMemory_AllocateA_Init(void *buffer) { ((void**)buffer)[0] = (char*)buffer + sizeof(void*); @@ -1867,7 +1875,7 @@ int ILibChain_AddSignalHandler(void *chain, int signum, ILibChain_SignalHandler { if (g_signalHandlers[signum] == NULL) { g_signalHandlers[signum] = ILibLinkedList_Create(); } data = (ILibChain_SignalHandlerData*)ILibChain_Link_Allocate(sizeof(ILibChain_SignalHandlerData), 0); - data->link.MetaData = "ILibChain_SignalHandler"; + data->link.MetaData = ILibMemory_SmartAllocate_FromString("ILibChain_SignalHandler"); data->link.PreSelectHandler = ILibChain_SignalHandler_PreSelect; data->link.PostSelectHandler = ILibChain_SignalHandler_PostSelect; data->link.DestroyHandler = ILibChain_SignalHandler_DestroySelect; @@ -7748,7 +7756,7 @@ void *ILibCreateLifeTime(void *Chain) if ((RetVal = (struct ILibLifeTime*)malloc(sizeof(struct ILibLifeTime))) == NULL) ILIBCRITICALEXIT(254); memset(RetVal,0,sizeof(struct ILibLifeTime)); - RetVal->ChainLink.MetaData = "ILibLifeTime"; + RetVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibLifeTime"); RetVal->ObjectList = ILibLinkedList_Create(); RetVal->ChainLink.PreSelectHandler = &ILibLifeTime_Check; RetVal->ChainLink.DestroyHandler = &ILibLifeTime_Destroy; @@ -9195,13 +9203,6 @@ char* ILibString_Copy(const char *inString, size_t length) RetVal[length] = 0; return RetVal; } -char* ILibString_CopyEx(const char *inString, size_t length) -{ - if (length == 0 || length == (size_t)(-1)) { length = strnlen_s(inString, sizeof(ILibScratchPad)); } - char *retVal = ILibMemory_SmartAllocate(length + 1); - memcpy_s(retVal, length + 1, inString, length); - return(retVal); -} /*! \fn ILibString_ToUpper(const char *inString, int length) \brief Coverts the given string to upper case \par diff --git a/microstack/ILibParsers.h b/microstack/ILibParsers.h index 0e7ef4d..f986649 100644 --- a/microstack/ILibParsers.h +++ b/microstack/ILibParsers.h @@ -480,6 +480,8 @@ int ILibIsRunningOnChainThread(void* chain); void* ILibMemory_Init(void *ptr, size_t primarySize, size_t extraSize, ILibMemory_Types memType); #define ILibMemory_SmartAllocate(len) ILibMemory_InitEx(ILibMemory_Size_Validate(len,0)?malloc(ILibMemory_Init_Size(len, 0)):NULL, (int)len, 0, ILibMemory_Types_HEAP) #define ILibMemory_SmartAllocateEx(primaryLen, extraLen) ILibMemory_InitEx(ILibMemory_Size_Validate(primaryLen,extraLen)?malloc(ILibMemory_Init_Size(primaryLen, extraLen)):NULL, (int)primaryLen, (int)extraLen, ILibMemory_Types_HEAP) + #define ILibMemory_SmartAllocate_FromString(str) ILibMemory_SmartAllocate_FromStringEx(str, 0) + char* ILibMemory_SmartAllocate_FromStringEx(char *str, size_t strLen); void* ILibMemory_SmartReAllocate(void *ptr, size_t len); void* ILibMemory_SmartAllocateEx_ResizeExtra(void *ptr, size_t extraSize); @@ -1419,7 +1421,6 @@ int ILibIsRunningOnChainThread(void* chain); char* ILibString_Cat(const char *inString1, size_t inString1Len, const char *inString2, size_t inString2Len); char* ILibString_Cat_s(char *destination, size_t destinationSize, char *source); char* ILibString_Copy(const char *inString, size_t length); - char* ILibString_CopyEx(const char *inString, size_t length); int ILibString_Copy_s(char *destination, size_t destinationSize, char *source); int ILibString_n_Copy_s(char *destination, size_t destinationSize, char *source, size_t count); int ILibString_EndsWith(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength); diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index f3983bd..9a98ac5 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -270,8 +270,7 @@ ILibProcessPipe_Manager ILibProcessPipe_Manager_Create(void *chain) if ((retVal = (ILibProcessPipe_Manager_Object*)malloc(sizeof(ILibProcessPipe_Manager_Object))) == NULL) { ILIBCRITICALEXIT(254); } memset(retVal, 0, sizeof(ILibProcessPipe_Manager_Object)); - //retVal->ChainLink.MetaData = "ILibProcessPipe_Manager"; - retVal->ChainLink.MetaData = ILibString_CopyEx("ILibProcessPipe_Manager", 0); + retVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibProcessPipe_Manager"); retVal->ChainLink.ParentChain = chain; retVal->ActivePipes = ILibLinkedList_CreateEx(sizeof(int)); diff --git a/microstack/ILibWebClient.c b/microstack/ILibWebClient.c index 4aca2a7..49ce8e9 100644 --- a/microstack/ILibWebClient.c +++ b/microstack/ILibWebClient.c @@ -2478,7 +2478,7 @@ ILibWebClient_RequestManager ILibCreateWebClient(int PoolSize, void *Chain) if ((RetVal = (struct ILibWebClientManager*)malloc(sizeof(struct ILibWebClientManager))) == NULL) ILIBCRITICALEXIT(254); memset(RetVal, 0, sizeof(struct ILibWebClientManager)); RetVal->MaxConnectionsToSameServer = 1; - RetVal->ChainLink.MetaData = "ILibWebClient"; + RetVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWebClient"); RetVal->ChainLink.DestroyHandler = &ILibDestroyWebClient; RetVal->ChainLink.PreSelectHandler = &ILibWebClient_PreProcess; //RetVal->PostSelect = &ILibWebClient_PreProcess; diff --git a/microstack/ILibWebRTC.c b/microstack/ILibWebRTC.c index aa4640d..8a07f20 100644 --- a/microstack/ILibWebRTC.c +++ b/microstack/ILibWebRTC.c @@ -6381,7 +6381,7 @@ void* ILibStunClient_Start(void *Chain, unsigned short LocalPort, ILibStunClient memset(obj, 0, sizeof(struct ILibStun_Module)); obj->State = STUN_STATUS_NOT_TESTED; obj->StunUsers = ILibLinkedList_Create(); - obj->ChainLink.MetaData = "ILibWebRTC"; + obj->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWebRTC"); obj->OnResult = OnResult; obj->LocalIf.sin_family = AF_INET; obj->LocalIf.sin_port = htons(LocalPort); @@ -7058,7 +7058,7 @@ ILibTURN_ClientModule ILibTURN_CreateTurnClient(void* chain, ILibTURN_OnConnectT retVal->OnChannelDataCallback = OnChannelData; retVal->transactionData = ILibInitHashTree(); retVal->ChainLink.ParentChain = chain; - retVal->ChainLink.MetaData = "ILibWebRTC_TURN_Client"; + retVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWebRTC_TURN_Client"); ILibAddToChain(chain, retVal); return retVal; diff --git a/microstack/ILibWebServer.c b/microstack/ILibWebServer.c index 62589e1..be36213 100644 --- a/microstack/ILibWebServer.c +++ b/microstack/ILibWebServer.c @@ -459,7 +459,7 @@ void ILibWebServer_OnConnect(void *AsyncServerSocketModule, void *ConnectionToke wsm = (struct ILibWebServer_StateModule*)ILibAsyncServerSocket_GetTag(AsyncServerSocketModule); ws = (struct ILibWebServer_Session*)ILibChain_Link_Allocate(ILibMemory_WEBSERVERSESSION_CONTAINERSIZE, ILibMemory_GetExtraMemorySize(wsm->ChainLink.ExtraMemoryPtr)); - ws->Reserved_Transport.ChainLink.MetaData = "ILibWebServer_Session"; + ws->Reserved_Transport.ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWebServer_Session"); ws->Reserved_Transport.ChainLink.ParentChain = wsm->ChainLink.ParentChain; ws->Reserved_Transport.IdentifierFlags = (unsigned int)ILibTransports_WebServer; ws->Reserved_Transport.ClosePtr = (ILibTransport_ClosePtr)&ILibWebServer_DisconnectSession; @@ -1052,7 +1052,7 @@ void ILibWebServer_SetTLS(ILibWebServer_ServerToken object, void *ssl_ctx) ILibExportMethod ILibWebServer_ServerToken ILibWebServer_CreateEx2(void *Chain, int MaxConnections, unsigned short PortNumber, int loopbackFlag, ILibWebServer_Session_OnSession OnSession, int ExtraMemorySize, void *User) { struct ILibWebServer_StateModule *RetVal = (struct ILibWebServer_StateModule *)ILibChain_Link_Allocate(sizeof(struct ILibWebServer_StateModule), ExtraMemorySize); - RetVal->ChainLink.MetaData = "ILibWebServer"; + RetVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWebServer"); RetVal->ChainLink.DestroyHandler = &ILibWebServer_Destroy; RetVal->ChainLink.ParentChain = Chain; RetVal->OnSession = OnSession; diff --git a/microstack/ILibWrapperWebRTC.c b/microstack/ILibWrapperWebRTC.c index 4b80a1d..56e9749 100644 --- a/microstack/ILibWrapperWebRTC.c +++ b/microstack/ILibWrapperWebRTC.c @@ -758,7 +758,7 @@ int ILibWrapper_WebRTC_OnDataChannel(void *StunModule, void* WebRTCModule, unsig if((dataChannel = (ILibWrapper_WebRTC_DataChannel*)ILibSparseArray_Get(obj->DataChannels, (int)StreamId))==NULL) { dataChannel = (ILibWrapper_WebRTC_DataChannel*)ILibChain_Link_Allocate(sizeof(ILibWrapper_WebRTC_DataChannel), (int)ILibMemory_ExtraSize(obj)); - dataChannel->Header.transport.ChainLink.MetaData = "ILibWrapper_WebRTC_DataChannel"; + dataChannel->Header.transport.ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWrapper_WebRTC_DataChannel"); dataChannel->parent = obj; dataChannel->streamId = StreamId; if((dataChannel->channelName = (char*)malloc(ChannelNameLength+1))==NULL){ILIBCRITICALEXIT(254);} @@ -852,7 +852,7 @@ ILibWrapper_WebRTC_ConnectionFactory ILibWrapper_WebRTC_ConnectionFactory_Create if (retVal == NULL) { ILIBCRITICALEXIT(254); } memset(retVal, 0, sizeof(ILibWrapper_WebRTC_ConnectionFactoryStruct)); - retVal->ChainLink.MetaData = "ILibWrapper_WebRTC_ConnectionFactory"; + retVal->ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWrapper_WebRTC_ConnectionFactory"); retVal->ChainLink.DestroyHandler = &ILibWrapper_WebRTC_ConnectionFactory_OnDestroy; ILibAddToChain(chain, retVal); @@ -1258,7 +1258,7 @@ void ILibWrapper_WebRTC_DataChannel_Close(ILibWrapper_WebRTC_DataChannel* dataCh ILibWrapper_WebRTC_DataChannel* ILibWrapper_WebRTC_DataChannel_CreateEx(ILibWrapper_WebRTC_Connection connection, char* channelName, int channelNameLen, unsigned short streamId, ILibWrapper_WebRTC_DataChannel_OnDataChannelAck OnAckHandler) { ILibWrapper_WebRTC_DataChannel *retVal = (ILibWrapper_WebRTC_DataChannel*)ILibChain_Link_Allocate(sizeof(ILibWrapper_WebRTC_DataChannel), (int)ILibMemory_ExtraSize(connection)); - retVal->Header.transport.ChainLink.MetaData = "ILibWrapper_WebRTC_DataChannel"; + retVal->Header.transport.ChainLink.MetaData = ILibMemory_SmartAllocate_FromString("ILibWrapper_WebRTC_DataChannel"); retVal->parent = connection; if ((retVal->channelName = (char*)malloc(channelNameLen + 1)) == NULL) { ILIBCRITICALEXIT(254); } memcpy_s(retVal->channelName, channelNameLen + 1, channelName, channelNameLen);