home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / cplus / 2136 < prev    next >
Encoding:
Text File  |  1993-01-28  |  4.0 KB  |  97 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!charon.amdahl.com!amdahl!rtech!pacbell.com!sgiblab!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Use of nested functions
  5. Message-ID: <9302813.18482@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1993Jan13.174051.21288@ucc.su.OZ.AU> <9302002.3172@mulga.cs.mu.OZ.AU> <1993Jan22.081555.12027@us-es.sel.de> <1993Jan26.224107.9187@ucc.su.OZ.AU>
  9. Date: Thu, 28 Jan 1993 02:25:53 GMT
  10. Lines: 85
  11.  
  12. maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  13.  
  14. >reindorf@us-es.sel.de (Charles Reindorf) writes:
  15. >>Some people say that they "don't like" trampolenes, but don't seem to give any
  16. >>reason for it. 
  17. >
  18. >    Separation of code and data is an important machine
  19. >principle for safety. Some machines (all the good ones :-) do not
  20. >allow executing things in the data area.
  21.  
  22. That in itself is not a problem, so long as you are allowed to modify
  23. things in the code area ;-)
  24.  
  25. Seriously, trampolines are not in the least bit unsafe.
  26. Being able to modify the code area can in general be "unsafe", but then there
  27. are many other things that are unsafe: pointers, array indexing,
  28. dynamic allocation, unions, etc. etc.
  29. Do these same hand-holding operating systems only allow you to program in
  30. Ada? (Just kidding :-)
  31.  
  32. >    Trampolines feel a bit like the Cobol ALTER statement:
  33. >dangerous hacks.
  34.  
  35. So do these same operating systems prevent efficient implementations of the
  36. COBOL ALTER statement?
  37.  
  38. >>The main objection I can see is that on some operating systems
  39. >>you are not allowed to do any run-time code generation. 
  40. >
  41. >    Some OS may not grant the user the priviledges required
  42. >to generate and execute code on the fly. This is because
  43. >it is close to 'self-modifying' code, which is not
  44. >generally considered very safe.
  45.  
  46. Again, why is this less safe than, say, using function pointers?
  47.  
  48. >>But there again, in 
  49. >>these architectures there do exist other, 
  50. >>addmittedly less efficient workarounds
  51. >>to this problem, surely.
  52. >
  53. >    Such as? I would LOVE to hear of one that did not require
  54. >the standard C/C++ function pointers to double in size.
  55.  
  56. An approach that doesn't require the ability
  57. to write to code space at runtime is as follows:
  58.     At compile time, the programmer must specify the maximum depth
  59.     of the trampoline stack.
  60.     The compiler allocates space for N pairs of data+code pointers and
  61.     writes out code for N trampolines each of which refer indirectly to the
  62.     corresponding pair of pointers.
  63.     Since these pointers are in the data area, they can be written
  64.     to at runtime with no problem. The trampoline code itself does not
  65.     have to be modified at runtime.
  66.  
  67. The only problem with this scheme is the requirement that you specify the
  68. trampoline stack depth in advance.  Many systems, eg. DOS, have had this
  69. requirement for the normal data stack, so people using inflexible
  70. operating systems should be able to put up with it for the
  71. trampoline stack.
  72.  
  73. If you can make the code for all the trampolines the same (eg. by reading the
  74. IP or using IP-relative addressing to determine the location of the
  75. corresponding pair of pointers in the data area) and you also have 
  76. the ability to map a single code page to successive linearly
  77. addressable locations, then you could dynamically extend the trampoline
  78. stack, thus avoiding the need to specify the maximum size in advance.
  79.  
  80. >>... This
  81. >>surely makes member function closures an impracticable and unworkable addition
  82. >>to the language?
  83. >
  84. >    No, one can just leave it up to the user to delete the
  85. >trampoline---as for other dynamically allocated objects.
  86.  
  87. This would require an extension to the language, whereas so far what we
  88. have just been discussing only requires relaxing some restrictions.
  89. What syntax would you use for allocating and deallocating member function
  90. closures?
  91.  
  92. -- 
  93. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  94. This .signature virus is a self-referential statement that is true - but 
  95. you will only be able to consistently believe it if you copy it to your own
  96. .signature file!
  97.