j'ai simplifié la structure, le probleme a chaque fois que j'essaye de toucher à
la mem de string_buffer je catch un SIGBUS
Voila j'ai essayé plusieurs solutions mais je n'arrive pas réallouer de la mem
avec strcat , peut-être faut 'il faire un mem copy mais meme probleme
voila donc si quelqu'un a une solu plus sexy
(au lieu de créer un gros buffer en esperant qu'il sera suffisant sachant que elems est variant ...)
je pourrais bien sur faire une premiere boucle pour obtenir la len de chaque elems
mais c'est stupide (l e cpp pour ce genre de manipulation c'est plus souple )
ici le cas complet
la mem de string_buffer je catch un SIGBUS
Bloc de code:
char *string_buffer=(char *)calloc(1,2000);
/* j'ajoute une premiere chaine */
strcat(string_buffer,add_string);
/* puis je lis un Array */
for (i=0;i<elems;i++)
{
/* ->string_buffer=realloc -> strl(string_buffer) + strl(elems[i]) ) */
/* ici je voudrais réallouer de la mémoire à string_buffer */
strcat(string_buffer,elems[i]);
}
avec strcat , peut-être faut 'il faire un mem copy mais meme probleme
voila donc si quelqu'un a une solu plus sexy
(au lieu de créer un gros buffer en esperant qu'il sera suffisant sachant que elems est variant ...)
je pourrais bien sur faire une premiere boucle pour obtenir la len de chaque elems
mais c'est stupide (l e cpp pour ce genre de manipulation c'est plus souple )
ici le cas complet
Bloc de code:
/*
* PyApp.h
* Tries to load this from the Info.plist file
*/
extern char *pyApp_plistPyRoot;
extern char *pyApp_plistPyMainClass;
extern char *pyApp_plistPyClassPath;
extern char *pyApp_ClassPathMask;
extern char *pyApp_plistDebug;
int PyApp_getPlistDict(char *filename)
{
CFDataRef PlistData = PyApp_loadPlist(filename);
CFStringRef WorkingDirectory;
CFStringRef MainClass;
CFNumberRef PrintDebug;
CFArrayRef ClassPathArrayRef;
CFIndex numClassPath = 0;
char *classPathBuffer=(char *)calloc(1,2000);
if (PlistData != NULL)
{
/* Creates root dict */
CFPropertyListRef infoPlist = CFPropertyListCreateFromXMLData(
NULL,PlistData,
kCFPropertyListImmutable,
NULL
);
/* Gets Python Dict */
CFDictionaryRef PythonDict = CFDictionaryGetValue(infoPlist,CFSTR("Python"));
if(WorkingDirectory = CFDictionaryGetValue(PythonDict,CFSTR("WorkingDirectory")))
{
/* extern */
pyApp_plistPyRoot = PyApp_CFString2Char(WorkingDirectory);
}
if(MainClass = CFDictionaryGetValue(PythonDict,CFSTR("MainClass")))
{
/* extern */
pyApp_plistPyMainClass = PyApp_CFString2Char(MainClass);
}
if(PrintDebug = CFDictionaryGetValue(PythonDict,CFSTR("PrintDebug")))
{
SInt32 _debug = 0;
CFNumberGetValue(PrintDebug,kCFNumberSInt32Type,&_debug);
/* extern */
if(_debug == 1)
pyApp_plistDebug = "True";
else
pyApp_plistDebug = "False";
}
if(ClassPathArrayRef = (CFArrayRef) CFDictionaryGetValue(PythonDict,CFSTR("ClassPath")))
{
numClassPath = CFArrayGetCount(ClassPathArrayRef);
}
char *read_path = pyApp_plistPyRoot;
char *py_path=(char *)calloc(1,strlen(read_path));
sprintf(py_path,pyApp_ClassPathMask,read_path);
strcat(classPathBuffer,py_path);
if(numClassPath > 0)
{
int i = 0;
for (i=0;i<numClassPath;i++)
{
char *read_path = PyApp_CFString2Char(CFArrayGetValueAtIndex(ClassPathArrayRef,i));
char *py_path=(char *)calloc(1,strlen(read_path));
sprintf(py_path,pyApp_ClassPathMask,read_path);
strcat(classPathBuffer,py_path);
}
}
pyApp_plistPyClassPath = classPathBuffer;
CFRelease(PlistData);
CFRelease(infoPlist);
return 1;
}else
return 0;
}