On Wed, 25 Feb 2009, Pritpal Bedi wrote: Hi Pritpal,
> Przemek, Mindaugus can surely come up with same solution but > with better internal overhaul of the concept so that the potential > "dangers" discussed can be reduced to bare minimum. I'm not against the idea of creating some .prg level code to define and fill C structures which can be later passed to real C code with some set of functions to manage them at C level, f.e. verify that given parameter is the exact class pointer. But such system has to be precisely defined. The interactions with C API also. The C structures from xHarbour break some fundamental HVM rules like always valid pointers in string items. For me the interactions between different structures which have to keep pointers to each other are also not clear. I do not see any protection against leaving some dummy pointers. It's not clear for me how should be extracted pointers to structures set by C code. Here I do not even see any good mechanism which can be generalized because we do not know the life of this structures. The next bad thing is the fact that structures are defined in .prg code. It means that they cannot be taken directly from C header files. It creates serious problems when some extensions will appear. Also it' snot trivial to replicate the exact alignment as in C compiler. Simple #pragma pack() is not enough because they are also other rules which control alignment in some situations which are different in C compilers. Even the same C compiler may use different rules for for different hardware though the same #pragma pack() is set. Personally I do not find such C structure implementation like in xHarbour usable in more complicated situations. At least for me but if you check how many problems were detected in xHarbour in simple demonstration/test code for C structures which is used for very limited situation then you will find that it's not trivial also for other developers who well known the low level implementation and which operations can break HVM. If it's really necessary then in some spare time I can try to write such code with some basic protections but by definition it will not work in all cases. Just simply it's not possible to create such automatic interface without breaking some fundamental VM rules and reducing the .prg programming to the same level as in C: GPF or memory leak on even small typo. So I will have to forbid some operations, f.e. accessing nested structures allocated by C code. All such operations will have to be done by programmer at C level. I can only try to create some helper functions. And of course I will not be able to replicate the alignment rules used by different C compilers. Probably the ideal solution for this problem will be creating a tool in C which generate C code to manage any structures from some meta structure description files using the original definitions from C header files and of course the alignment rules which are valid for given C compiler/hardware/platform. Such met description may contain only public and documented structure members, f.e.: struct stat { st_dev; st_ino; st_mode; st_nlink; st_uid; st_gid; st_atime; st_mtime; st_ctime; }; The exact member offset and type will be taken from original header files but I have some much more important jobs now to work on it though if someone is interested then I can add to HVM support for sending messages to pointer items. At least on C level. best regards, Przemek _______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour