I'm having an odd problem when trying to add an array of simple types in an eet file. The attached file is the simple cut down version. The real code is more complex, and needs the fuller versions of these structures to be the way they are.
I have a macro that is patterned after the other eet macros - EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY. It's used twice in this example, once for the Meter.prizes array, the second one for the Barrel.cards array. If the Meter.prizes version is commented out, everything works fine. Otherwise I get the attached valgrind report (with no eet file existing when it starts). Likely there is something wrong with my macro. I think there should be such a macro already, but apparently the received wisdom from raster is that for something so simple, just use the eet_data_descriptor_element_add() function directly. Even though that functions docs say - "It is complex to use by hand and should be left to be used by the macros, and thus is not documented." Um, yeah. Well, I tried. lol -- A big old stinking pile of genius that no one wants coz there are too many silver coated monkeys in the world.
#include <Elementary.h> #ifndef ELM_LIB_QUICKLAUNCH typedef struct { unsigned long long prizes[7]; } Meter; typedef struct { unsigned char cards[375]; } Barrel; typedef struct { Barrel series[5]; Meter *machine; }gameData; #define EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(edd, struct_type, name, member, type) \ do { \ struct_type ___ett; \ eet_data_descriptor_element_add(edd, name, type, EET_G_ARRAY, \ (char *)(& (___ett.member)) - \ (char *)(& (___ett)), \ sizeof(___ett.member), \ NULL, NULL); \ } while(0) EAPI int elm_main(int argc, char **argv) { Eet_Data_Descriptor *gameDataDescriptor; Eet_Data_Descriptor *dataBarrelDescriptor; Eet_Data_Descriptor *dataMeterDescriptor; const char gameDataEntry[] = "gggData"; const char gameDataFile[] = "gggData.eet"; gameData *data = NULL; Eet_Data_Descriptor_Class eddc; Eet_File * ef = NULL; EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, gameData); gameDataDescriptor = eet_data_descriptor_stream_new(&eddc); EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Barrel); dataBarrelDescriptor = eet_data_descriptor_stream_new(&eddc); EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Meter); dataMeterDescriptor = eet_data_descriptor_stream_new(&eddc); // This causes problems. EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(dataMeterDescriptor, Meter, "prizes", prizes, EET_T_ULONG_LONG); EET_DATA_DESCRIPTOR_ADD_BASIC_ARRAY(dataBarrelDescriptor, Barrel, "cards", cards, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_ARRAY(gameDataDescriptor, gameData, "series", series, dataBarrelDescriptor); EET_DATA_DESCRIPTOR_ADD_SUB(gameDataDescriptor, gameData, "machine", machine, dataMeterDescriptor); ef = eet_open(gameDataFile, EET_FILE_MODE_READ); if (ef) data = eet_data_read(ef, gameDataDescriptor, gameDataEntry); if (!data) { data = calloc(1, sizeof(gameData)); if (data) { Meter *meters = calloc(1, sizeof(Meter)); if (!meters) { free(data); data = NULL; } else { data->machine = meters; } } } if (ef) eet_close(ef); if (data) { ef = eet_open(gameDataFile, EET_FILE_MODE_WRITE); if (ef) { eet_data_write(ef, gameDataDescriptor, gameDataEntry, data, EINA_TRUE); eet_close(ef); } free(data->machine); free(data); } eet_data_descriptor_free(dataMeterDescriptor); eet_data_descriptor_free(dataBarrelDescriptor); eet_data_descriptor_free(gameDataDescriptor); return 0; } #endif ELM_MAIN()
==3781== Memcheck, a memory error detector ==3781== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==3781== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==3781== Command: ./ggg ==3781== ==3781== Invalid read of size 8 ==3781== at 0x553E4FC: eet_data_put_long_long (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x553F389: eet_data_put_type (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5546320: eet_data_put_unknown (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5546E50: _eet_data_descriptor_encode (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x554620B: eet_data_put_array (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5546E50: _eet_data_descriptor_encode (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5546361: eet_data_put_unknown (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5546E50: _eet_data_descriptor_encode (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5540BFA: eet_data_write_cipher (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x5540C92: eet_data_write (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x400D83: elm_main (ggg_main.c:93) ==3781== by 0x400E38: main (ggg_main.c:108) ==3781== Address 0xfd7d628 is 0 bytes after a block of size 56 alloc'd ==3781== at 0x4C267CC: calloc (vg_replace_malloc.c:467) ==3781== by 0x400CCE: elm_main (ggg_main.c:71) ==3781== by 0x400E38: main (ggg_main.c:108) ==3781== ==3781== Syscall param write(buf) points to uninitialised byte(s) ==3781== at 0x5287500: __write_nocancel (syscall-template.S:82) ==3781== by 0x5222132: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1276) ==3781== by 0x5223784: _IO_do_write@@GLIBC_2.2.5 (fileops.c:530) ==3781== by 0x52228E7: _IO_file_sync@@GLIBC_2.2.5 (fileops.c:905) ==3781== by 0x5216F99: fflush (iofflush.c:43) ==3781== by 0x5539A31: eet_flush2 (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x553B880: eet_internal_close (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x553C32F: eet_close (in /opt/e17/lib/libeet.so.1.4.999) ==3781== by 0x400D92: elm_main (ggg_main.c:94) ==3781== by 0x400E38: main (ggg_main.c:108) ==3781== Address 0x402d2b5 is not stack'd, malloc'd or (recently) free'd ==3781== ==3781== ==3781== HEAP SUMMARY: ==3781== in use at exit: 388,235 bytes in 5,977 blocks ==3781== total heap usage: 43,765 allocs, 37,771 frees, 5,821,471 bytes allocated ==3781== ==3781== LEAK SUMMARY: ==3781== definitely lost: 400 bytes in 2 blocks ==3781== indirectly lost: 96 bytes in 2 blocks ==3781== possibly lost: 1,656 bytes in 24 blocks ==3781== still reachable: 368,707 bytes in 5,964 blocks ==3781== suppressed: 0 bytes in 0 blocks ==3781== Rerun with --leak-check=full to see details of leaked memory ==3781== ==3781== For counts of detected and suppressed errors, rerun with: -v ==3781== Use --track-origins=yes to see where uninitialised values come from ==3781== ERROR SUMMARY: 19 errors from 2 contexts (suppressed: 36581 from 37)
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel