Operating System - Linux
1829116 Members
2524 Online
109986 Solutions
New Discussion

map->insert() it killing my procees the program just aborts

 
Pedro Dinis
Advisor

map->insert() it killing my procees the program just aborts

map->insert() it killing my procees the program just aborts

typedef std::map mapamemoria;
typedef std::pair Map_Str_Pair;


void streamFileXML(const char *filename,char * tag_oracle,mapamemoria *mapa_colunas)
try
{
// mapa_colunas->insert(Map_Str_Pair("sdfsdfds","uiyuiyui"));
(*mapa_colunas)["elemento"]="ola";
//(char *)namexml_temp;
(*mapa_colunas)["texto"]="ole";
//(char *)oracle_value;
}
catch(exception e)
{
sprintf(sstring, "excepcao -- >%s",e.what());
log_message(LOG_FILE,sstring);
}


this the makefile

# Fichero de construcción del proyecto Schengen

DIR_ACTUAL=$(shell echo $(PWD))
INCLUDE=.,$(DIR_ACTUAL)/common
OBJS=
CCC=aCC
ICLIBHOME=/usr/local/lib/hpux32
ICLIBPATH=-L$(ICLIBHOME)
CCLIB=$(ICLIBPATH) -lxml2 -lz
INCLUDES=/usr/local/include/libxml2
EXE=daemon

all: exe

daemon.o: daemon.cc
$(CCC) -c daemon.cc -I$(INCLUDES)
cp *.o ../../obj
rm *.o

exe: daemon.o

$(CCC) -o $(EXE) ../../obj/daemon.o $(CCLIB)
cp $(EXE) ../../bin
rm $(EXE)

.PHONY: clean
clean:
-rm ../obj/*.o
SLB SLB SLB Glorioso
3 REPLIES 3
Pedro Dinis
Advisor

Re: map->insert() it killing my procees the program just aborts

the insert() compiled successfully but aborts the program

so i have tried this

(*mapa_colunas)["elemento"]="ola";
//(char *)namexml_temp;
(*mapa_colunas)["texto"]="ole";

still does not work
SLB SLB SLB Glorioso
Pedro Dinis
Advisor

Re: map->insert() it killing my procees the program just aborts

i have made some changes in the function i am passing the address of the map

void streamFileXML(const char *filename,char * tag_oracle,mapamemoria &mapa_colunas)

try
{
mapa_colunas.insert(Map_Str_Pair((char *)namexml_temp,(char *)oracle_value));

}
catch(exception e)
{
sprintf(sstring, "excepcao -- >%s",e.what());
log_message(LOG_FILE,sstring);
}

this works BUT:

i have this struct with a map inside

typedef struct dataestrutura {
mapamemoria mapa_mem;
} dataestrutura;

i have this pointer to it in the function

dataestrutura *data_ptr;

mapamemoria xmlelementos_oracle_bd;

m_shmid=shmid;
/* attach to the segment to get a pointer to it: */
data_ptr = (dataestrutura *)shmat(shmid,0, 0);
if (data_ptr == (dataestrutura *)(-1))
{
perror("shmat");
exit(1);
}

i am going to fill up the map :

streamFileXML(CONFIG_FILE_NAME,ORACLE_BD_TAG, xmlelementos_oracle_bd);

then i have to fill up the map in memory segment :
WELL this it is not working , compiles but on execution kills the program -- abort
data_ptr->mapa_mem=xmlelementos_oracle_bd;
SLB SLB SLB Glorioso
Dennis Handly
Acclaimed Contributor

Re: map->insert() it killing my process, the program just aborts

If your process aborts, you need to show a stack trace.

typedef std::map mapamemoria;
typedef std::pair Map_Str_Pair;

The last typedef is illegal. You must NOT define the pair used in a map. You must use STL typedefs to compute it:
typedef mapamemoria::value_type Map_Str_Pair;

Is string the same as std::string?

>the insert() compiled successfully

I don't see how with the wrong Map_Str_Pair.

// attach to the segment to get a pointer to it:
data_ptr = (dataestrutura*)shmat(shmid,0, 0);

Don't even think of doing this. This won't work! You'll have the same problems as in your:


http://h30499.www3.hp.com/t5/Languages-and-Scripting/IPC-shared-memory-with-a-linked-list-or-a-hash-table/m-p/4044982

(Where I mention using a "STL allocator".)

>then I have to fill up the map in memory segment: WELL this it is not working, compiles but on execution kills the program
data_ptr->mapa_mem=xmlelementos_oracle_bd;

I'm not sure why this won't work. But it is useless. You can't have a shared pointer to private data. Only the original process can use that pointer to that map.

A stack trace would be helpful here.