home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnusmalltalk / dld.st < prev    next >
Text File  |  1992-02-15  |  5KB  |  209 lines

  1. "======================================================================
  2. |
  3. |   GNU Dynamic Loader Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29.  
  30.  
  31. "
  32. |     Change Log
  33. | ============================================================================
  34. | Author       Date       Change 
  35. | sbb         19 Jul 91      Created.
  36. |
  37. "
  38.  
  39. Object subclass: #DLD
  40.        instanceVariableNames: ''
  41.        classVariableNames: ''
  42.        poolDictionaries: ''
  43.        category: 'Cool hacks'
  44. !
  45.  
  46. DLD comment: '###NO COMMENT YET###'!
  47.  
  48. "
  49.      int dld_link (char *FILENAME)
  50. "
  51.  
  52. Behavior defineCFunc: 'dldLink'
  53.      withSelectorArgs: 'linkFile: aFileName'
  54.      forClass: DLD class
  55.      returning: #int
  56.      args: #(string)
  57. !
  58.  
  59. "
  60.      int dld_unlink_by_file (char *PATH, int HARD)
  61.  
  62.      int dld_unlink_by_symbol (char *ID, int HARD)
  63. "
  64.  
  65. Behavior defineCFunc: 'dldUnlinkByFile'
  66.      withSelectorArgs: 'unlinkFile: aFileName force: aBool'
  67.      forClass: DLD class
  68.      returning: #int
  69.      args: #(string int)
  70. !
  71.  
  72. Behavior defineCFunc: 'dldUnlinkBySymbol'
  73.      withSelectorArgs: 'unlinkModuleContaining: aStringName force: aBool'
  74.      forClass: DLD class
  75.      returning: #int
  76.      args: #(string int)
  77. !
  78.  
  79. "
  80.      unsigned long dld_get_symbol (char *ID)
  81.  
  82.      unsigned long dld_get_func (char *FUNC)
  83. "
  84.  
  85. Behavior defineCFunc: 'dldGetSymbol'
  86.      withSelectorArgs: 'getSymbol: aStringName'
  87.      forClass: DLD class
  88.      returning: #cObject
  89.      args: #(string)
  90. !
  91.  
  92. Behavior defineCFunc: 'dldGetFunc'
  93.      withSelectorArgs: 'getFunc: aFuncString'
  94.      forClass: DLD class
  95.      returning: #cObject
  96.      args: #(string)
  97. !
  98.  
  99.  
  100. "
  101.      int dld_function_executable_p (char *FUNC)
  102. "
  103.  
  104. Behavior defineCFunc: 'dldFunctionExecutableP'
  105.      withSelectorArgs: 'isExecutable: aFuncString'
  106.      forClass: DLD class
  107.      returning: #int    "bool"
  108.      args: #(string)
  109. !
  110.  
  111. "
  112.      char **dld_list_undefined_sym ()
  113. "
  114.  
  115. CStruct newStruct: #StringArray
  116.     declaration: #((val (ptr string)))
  117. !
  118.  
  119.  
  120. Behavior defineCFunc: 'dldListUndefinedSym'
  121.      withSelectorArgs: 'undefinedSymbols'
  122.      forClass: DLD class
  123.      returning: "CStringType ""(CType baseType: StringArray)"
  124.           "(CType baseType: CPtr subType: CStringType)"
  125.           (CType baseType: CArray subType: CStringType)
  126.      args: #()
  127. !
  128.  
  129. "
  130.      int dld_create_reference (char *NAME)
  131. "
  132.  
  133. Behavior defineCFunc: 'dldCreateReference'
  134.      withSelectorArgs: 'createReference: aString'
  135.      forClass: DLD class
  136.      returning: #int
  137.      args: #(string)
  138. !
  139.  
  140. "
  141.      int dld_define_sym (char *NAME, unsigned int SIZE)
  142.      void dld_remove_defined_symbol (char *NAME)
  143. "
  144.  
  145. Behavior defineCFunc: 'dldDefineSym'
  146.      withSelectorArgs: 'defineSym: symbolName size: anInteger'
  147.      forClass: DLD class
  148.      returning: #int
  149.      args: #(string int)
  150. !
  151.  
  152. Behavior defineCFunc: 'dldRemoveDefinedSymbol'
  153.      withSelectorArgs: 'removeDefinedSymbol: aString'
  154.      forClass: DLD class
  155.      returning: #void
  156.      args: #(string)
  157. !
  158.  
  159. Behavior defineCFunc: 'getUndefinedSymCount'
  160.      withSelectorArgs: 'numUndefinedSymbols'
  161.      forClass: DLD class
  162.      returning: #int
  163.      args: #()
  164. !
  165.  
  166.  
  167. "Generally useful in the presence of dynamic linking"
  168.  
  169. Behavior defineCFunc: 'defineCFunc'
  170.      withSelectorArgs: 'defineCFunc: aName as: aFuncAddr'
  171.      forClass: Behavior class
  172.      returning: #void
  173.      args: #(string cObject)
  174. !
  175.  
  176.  
  177. !DLD class methodsFor: 'Dynamic Linking'!
  178.  
  179. defineExternFunc: aFuncName
  180.     withSelectorArgs: selector
  181.     forClass: aClass
  182.     returning: aReturnType
  183.     args: argsArray
  184.     | funcAddr |
  185.     
  186.     funcAddr _ self getFunc: aFuncName.
  187.     funcAddr isNil
  188.     ifTrue: [ ^self error: 'Function ', aFuncName, ' not found' ].
  189.     Behavior defineCFunc: aFuncName as: funcAddr.
  190.     Behavior defineCFunc: aFuncName
  191.          withSelectorArgs: selector
  192.          forClass: aClass
  193.          returning: aReturnType
  194.          args: argsArray
  195. ! !
  196.  
  197.  
  198. "
  199. | syms |
  200.     DLD createReference: 'printf'.
  201.     DLD createReference: 'open'.
  202.     syms _ DLD undefinedSymbols.
  203.     0 to: DLD numUndefinedSymbols - 1
  204.       do: [ :i | (syms at: i) value printNl ]
  205. !
  206. "
  207.