comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/f2py/capi_maps.py @ 87:2a2c65a20a8b

Add Python libs and headers
author Chris Cannam
date Wed, 25 Feb 2015 14:05:22 +0000
parents
children
comparison
equal deleted inserted replaced
86:413a9d26189e 87:2a2c65a20a8b
1 #!/usr/bin/env python
2 """
3
4 Copyright 1999,2000 Pearu Peterson all rights reserved,
5 Pearu Peterson <pearu@ioc.ee>
6 Permission to use, modify, and distribute this software is given under the
7 terms of the NumPy License.
8
9 NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
10 $Date: 2005/05/06 10:57:33 $
11 Pearu Peterson
12
13 """
14 from __future__ import division, absolute_import, print_function
15
16 __version__ = "$Revision: 1.60 $"[10:-1]
17
18 from . import __version__
19 f2py_version = __version__.version
20
21 import copy
22 import re
23 import os
24 import sys
25 from .auxfuncs import *
26 from .crackfortran import markoutercomma
27 from . import cb_rules
28
29 # Numarray and Numeric users should set this False
30 using_newcore = True
31
32 depargs=[]
33 lcb_map={}
34 lcb2_map={}
35 # forced casting: mainly caused by the fact that Python or Numeric
36 # C/APIs do not support the corresponding C types.
37 c2py_map={'double': 'float',
38 'float': 'float', # forced casting
39 'long_double': 'float', # forced casting
40 'char': 'int', # forced casting
41 'signed_char': 'int', # forced casting
42 'unsigned_char': 'int', # forced casting
43 'short': 'int', # forced casting
44 'unsigned_short': 'int', # forced casting
45 'int': 'int', # (forced casting)
46 'long': 'int',
47 'long_long': 'long',
48 'unsigned': 'int', # forced casting
49 'complex_float': 'complex', # forced casting
50 'complex_double': 'complex',
51 'complex_long_double': 'complex', # forced casting
52 'string': 'string',
53 }
54 c2capi_map={'double':'NPY_DOUBLE',
55 'float':'NPY_FLOAT',
56 'long_double':'NPY_DOUBLE', # forced casting
57 'char':'NPY_CHAR',
58 'unsigned_char':'NPY_UBYTE',
59 'signed_char':'NPY_BYTE',
60 'short':'NPY_SHORT',
61 'unsigned_short':'NPY_USHORT',
62 'int':'NPY_INT',
63 'unsigned':'NPY_UINT',
64 'long':'NPY_LONG',
65 'long_long':'NPY_LONG', # forced casting
66 'complex_float':'NPY_CFLOAT',
67 'complex_double':'NPY_CDOUBLE',
68 'complex_long_double':'NPY_CDOUBLE', # forced casting
69 'string':'NPY_CHAR'}
70
71 #These new maps aren't used anyhere yet, but should be by default
72 # unless building numeric or numarray extensions.
73 if using_newcore:
74 c2capi_map={'double': 'NPY_DOUBLE',
75 'float': 'NPY_FLOAT',
76 'long_double': 'NPY_LONGDOUBLE',
77 'char': 'NPY_BYTE',
78 'unsigned_char': 'NPY_UBYTE',
79 'signed_char': 'NPY_BYTE',
80 'short': 'NPY_SHORT',
81 'unsigned_short': 'NPY_USHORT',
82 'int': 'NPY_INT',
83 'unsigned': 'NPY_UINT',
84 'long': 'NPY_LONG',
85 'unsigned_long': 'NPY_ULONG',
86 'long_long': 'NPY_LONGLONG',
87 'unsigned_long_long': 'NPY_ULONGLONG',
88 'complex_float': 'NPY_CFLOAT',
89 'complex_double': 'NPY_CDOUBLE',
90 'complex_long_double': 'NPY_CDOUBLE',
91 'string': 'NPY_CHAR', # f2py 2e is not ready for NPY_STRING (must set itemisize etc)
92 #'string':'NPY_STRING'
93
94 }
95 c2pycode_map={'double':'d',
96 'float':'f',
97 'long_double':'d', # forced casting
98 'char':'1',
99 'signed_char':'1',
100 'unsigned_char':'b',
101 'short':'s',
102 'unsigned_short':'w',
103 'int':'i',
104 'unsigned':'u',
105 'long':'l',
106 'long_long':'L',
107 'complex_float':'F',
108 'complex_double':'D',
109 'complex_long_double':'D', # forced casting
110 'string':'c'
111 }
112 if using_newcore:
113 c2pycode_map={'double':'d',
114 'float':'f',
115 'long_double':'g',
116 'char':'b',
117 'unsigned_char':'B',
118 'signed_char':'b',
119 'short':'h',
120 'unsigned_short':'H',
121 'int':'i',
122 'unsigned':'I',
123 'long':'l',
124 'unsigned_long':'L',
125 'long_long':'q',
126 'unsigned_long_long':'Q',
127 'complex_float':'F',
128 'complex_double':'D',
129 'complex_long_double':'G',
130 'string':'S'}
131 c2buildvalue_map={'double':'d',
132 'float':'f',
133 'char':'b',
134 'signed_char':'b',
135 'short':'h',
136 'int':'i',
137 'long':'l',
138 'long_long':'L',
139 'complex_float':'N',
140 'complex_double':'N',
141 'complex_long_double':'N',
142 'string':'z'}
143
144 if sys.version_info[0] >= 3:
145 # Bytes, not Unicode strings
146 c2buildvalue_map['string'] = 'y'
147
148 if using_newcore:
149 #c2buildvalue_map=???
150 pass
151
152 f2cmap_all={'real':{'':'float','4':'float','8':'double','12':'long_double','16':'long_double'},
153 'integer':{'':'int','1':'signed_char','2':'short','4':'int','8':'long_long',
154 '-1':'unsigned_char','-2':'unsigned_short','-4':'unsigned',
155 '-8':'unsigned_long_long'},
156 'complex':{'':'complex_float','8':'complex_float',
157 '16':'complex_double','24':'complex_long_double',
158 '32':'complex_long_double'},
159 'complexkind':{'':'complex_float','4':'complex_float',
160 '8':'complex_double','12':'complex_long_double',
161 '16':'complex_long_double'},
162 'logical':{'':'int','1':'char','2':'short','4':'int','8':'long_long'},
163 'double complex':{'':'complex_double'},
164 'double precision':{'':'double'},
165 'byte':{'':'char'},
166 'character':{'':'string'}
167 }
168
169 if os.path.isfile('.f2py_f2cmap'):
170 # User defined additions to f2cmap_all.
171 # .f2py_f2cmap must contain a dictionary of dictionaries, only.
172 # For example, {'real':{'low':'float'}} means that Fortran 'real(low)' is
173 # interpreted as C 'float'.
174 # This feature is useful for F90/95 users if they use PARAMETERSs
175 # in type specifications.
176 try:
177 outmess('Reading .f2py_f2cmap ...\n')
178 f = open('.f2py_f2cmap', 'r')
179 d = eval(f.read(), {}, {})
180 f.close()
181 for k, d1 in d.items():
182 for k1 in d1.keys():
183 d1[k1.lower()] = d1[k1]
184 d[k.lower()] = d[k]
185 for k in d.keys():
186 if k not in f2cmap_all:
187 f2cmap_all[k]={}
188 for k1 in d[k].keys():
189 if d[k][k1] in c2py_map:
190 if k1 in f2cmap_all[k]:
191 outmess("\tWarning: redefinition of {'%s':{'%s':'%s'->'%s'}}\n"%(k, k1, f2cmap_all[k][k1], d[k][k1]))
192 f2cmap_all[k][k1] = d[k][k1]
193 outmess('\tMapping "%s(kind=%s)" to "%s"\n' % (k, k1, d[k][k1]))
194 else:
195 errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n"%(k, k1, d[k][k1], d[k][k1], list(c2py_map.keys())))
196 outmess('Succesfully applied user defined changes from .f2py_f2cmap\n')
197 except Exception as msg:
198 errmess('Failed to apply user defined changes from .f2py_f2cmap: %s. Skipping.\n' % (msg))
199 cformat_map={'double': '%g',
200 'float': '%g',
201 'long_double': '%Lg',
202 'char': '%d',
203 'signed_char': '%d',
204 'unsigned_char': '%hhu',
205 'short': '%hd',
206 'unsigned_short': '%hu',
207 'int': '%d',
208 'unsigned': '%u',
209 'long': '%ld',
210 'unsigned_long': '%lu',
211 'long_long': '%ld',
212 'complex_float': '(%g,%g)',
213 'complex_double': '(%g,%g)',
214 'complex_long_double': '(%Lg,%Lg)',
215 'string': '%s',
216 }
217
218 ############### Auxiliary functions
219 def getctype(var):
220 """
221 Determines C type
222 """
223 ctype='void'
224 if isfunction(var):
225 if 'result' in var:
226 a=var['result']
227 else:
228 a=var['name']
229 if a in var['vars']:
230 return getctype(var['vars'][a])
231 else:
232 errmess('getctype: function %s has no return value?!\n'%a)
233 elif issubroutine(var):
234 return ctype
235 elif 'typespec' in var and var['typespec'].lower() in f2cmap_all:
236 typespec = var['typespec'].lower()
237 f2cmap=f2cmap_all[typespec]
238 ctype=f2cmap[''] # default type
239 if 'kindselector' in var:
240 if '*' in var['kindselector']:
241 try:
242 ctype=f2cmap[var['kindselector']['*']]
243 except KeyError:
244 errmess('getctype: "%s %s %s" not supported.\n'%(var['typespec'], '*', var['kindselector']['*']))
245 elif 'kind' in var['kindselector']:
246 if typespec+'kind' in f2cmap_all:
247 f2cmap=f2cmap_all[typespec+'kind']
248 try:
249 ctype=f2cmap[var['kindselector']['kind']]
250 except KeyError:
251 if typespec in f2cmap_all:
252 f2cmap=f2cmap_all[typespec]
253 try:
254 ctype=f2cmap[str(var['kindselector']['kind'])]
255 except KeyError:
256 errmess('getctype: "%s(kind=%s)" is mapped to C "%s" (to override define dict(%s = dict(%s="<C typespec>")) in %s/.f2py_f2cmap file).\n'\
257 %(typespec, var['kindselector']['kind'], ctype,
258 typespec, var['kindselector']['kind'], os.getcwd()))
259
260 else:
261 if not isexternal(var):
262 errmess('getctype: No C-type found in "%s", assuming void.\n'%var)
263 return ctype
264
265 def getstrlength(var):
266 if isstringfunction(var):
267 if 'result' in var:
268 a=var['result']
269 else:
270 a=var['name']
271 if a in var['vars']:
272 return getstrlength(var['vars'][a])
273 else:
274 errmess('getstrlength: function %s has no return value?!\n'%a)
275 if not isstring(var):
276 errmess('getstrlength: expected a signature of a string but got: %s\n'%(repr(var)))
277 len='1'
278 if 'charselector' in var:
279 a=var['charselector']
280 if '*' in a:
281 len=a['*']
282 elif 'len' in a:
283 len=a['len']
284 if re.match(r'\(\s*([*]|[:])\s*\)', len) or re.match(r'([*]|[:])', len):
285 #if len in ['(*)','*','(:)',':']:
286 if isintent_hide(var):
287 errmess('getstrlength:intent(hide): expected a string with defined length but got: %s\n'%(repr(var)))
288 len='-1'
289 return len
290
291 def getarrdims(a,var,verbose=0):
292 global depargs
293 ret={}
294 if isstring(var) and not isarray(var):
295 ret['dims']=getstrlength(var)
296 ret['size']=ret['dims']
297 ret['rank']='1'
298 elif isscalar(var):
299 ret['size']='1'
300 ret['rank']='0'
301 ret['dims']=''
302 elif isarray(var):
303 # if not isintent_c(var):
304 # var['dimension'].reverse()
305 dim=copy.copy(var['dimension'])
306 ret['size']='*'.join(dim)
307 try: ret['size']=repr(eval(ret['size']))
308 except: pass
309 ret['dims']=','.join(dim)
310 ret['rank']=repr(len(dim))
311 ret['rank*[-1]']=repr(len(dim)*[-1])[1:-1]
312 for i in range(len(dim)): # solve dim for dependecies
313 v=[]
314 if dim[i] in depargs: v=[dim[i]]
315 else:
316 for va in depargs:
317 if re.match(r'.*?\b%s\b.*'%va, dim[i]):
318 v.append(va)
319 for va in v:
320 if depargs.index(va)>depargs.index(a):
321 dim[i]='*'
322 break
323 ret['setdims'], i='', -1
324 for d in dim:
325 i=i+1
326 if d not in ['*', ':', '(*)', '(:)']:
327 ret['setdims']='%s#varname#_Dims[%d]=%s,'%(ret['setdims'], i, d)
328 if ret['setdims']: ret['setdims']=ret['setdims'][:-1]
329 ret['cbsetdims'], i='', -1
330 for d in var['dimension']:
331 i=i+1
332 if d not in ['*', ':', '(*)', '(:)']:
333 ret['cbsetdims']='%s#varname#_Dims[%d]=%s,'%(ret['cbsetdims'], i, d)
334 elif isintent_in(var):
335 outmess('getarrdims:warning: assumed shape array, using 0 instead of %r\n' \
336 % (d))
337 ret['cbsetdims']='%s#varname#_Dims[%d]=%s,'%(ret['cbsetdims'], i, 0)
338 elif verbose :
339 errmess('getarrdims: If in call-back function: array argument %s must have bounded dimensions: got %s\n'%(repr(a), repr(d)))
340 if ret['cbsetdims']: ret['cbsetdims']=ret['cbsetdims'][:-1]
341 # if not isintent_c(var):
342 # var['dimension'].reverse()
343 return ret
344
345 def getpydocsign(a, var):
346 global lcb_map
347 if isfunction(var):
348 if 'result' in var:
349 af=var['result']
350 else:
351 af=var['name']
352 if af in var['vars']:
353 return getpydocsign(af, var['vars'][af])
354 else:
355 errmess('getctype: function %s has no return value?!\n'%af)
356 return '', ''
357 sig, sigout=a, a
358 opt=''
359 if isintent_in(var): opt='input'
360 elif isintent_inout(var): opt='in/output'
361 out_a = a
362 if isintent_out(var):
363 for k in var['intent']:
364 if k[:4]=='out=':
365 out_a = k[4:]
366 break
367 init=''
368 ctype=getctype(var)
369
370 if hasinitvalue(var):
371 init, showinit=getinit(a, var)
372 init = ', optional\\n Default: %s' % showinit
373 if isscalar(var):
374 if isintent_inout(var):
375 sig='%s : %s rank-0 array(%s,\'%s\')%s'%(a, opt, c2py_map[ctype],
376 c2pycode_map[ctype], init)
377 else:
378 sig='%s : %s %s%s'%(a, opt, c2py_map[ctype], init)
379 sigout='%s : %s'%(out_a, c2py_map[ctype])
380 elif isstring(var):
381 if isintent_inout(var):
382 sig='%s : %s rank-0 array(string(len=%s),\'c\')%s'%(a, opt, getstrlength(var), init)
383 else:
384 sig='%s : %s string(len=%s)%s'%(a, opt, getstrlength(var), init)
385 sigout='%s : string(len=%s)'%(out_a, getstrlength(var))
386 elif isarray(var):
387 dim=var['dimension']
388 rank=repr(len(dim))
389 sig='%s : %s rank-%s array(\'%s\') with bounds (%s)%s'%(a, opt, rank,
390 c2pycode_map[ctype],
391 ','.join(dim), init)
392 if a==out_a:
393 sigout='%s : rank-%s array(\'%s\') with bounds (%s)'\
394 %(a, rank, c2pycode_map[ctype], ','.join(dim))
395 else:
396 sigout='%s : rank-%s array(\'%s\') with bounds (%s) and %s storage'\
397 %(out_a, rank, c2pycode_map[ctype], ','.join(dim), a)
398 elif isexternal(var):
399 ua=''
400 if a in lcb_map and lcb_map[a] in lcb2_map and 'argname' in lcb2_map[lcb_map[a]]:
401 ua=lcb2_map[lcb_map[a]]['argname']
402 if not ua==a: ua=' => %s'%ua
403 else: ua=''
404 sig='%s : call-back function%s'%(a, ua)
405 sigout=sig
406 else:
407 errmess('getpydocsign: Could not resolve docsignature for "%s".\\n'%a)
408 return sig, sigout
409
410 def getarrdocsign(a, var):
411 ctype=getctype(var)
412 if isstring(var) and (not isarray(var)):
413 sig='%s : rank-0 array(string(len=%s),\'c\')'%(a, getstrlength(var))
414 elif isscalar(var):
415 sig='%s : rank-0 array(%s,\'%s\')'%(a, c2py_map[ctype],
416 c2pycode_map[ctype],)
417 elif isarray(var):
418 dim=var['dimension']
419 rank=repr(len(dim))
420 sig='%s : rank-%s array(\'%s\') with bounds (%s)'%(a, rank,
421 c2pycode_map[ctype],
422 ','.join(dim))
423 return sig
424
425 def getinit(a, var):
426 if isstring(var): init, showinit='""', "''"
427 else: init, showinit='', ''
428 if hasinitvalue(var):
429 init=var['=']
430 showinit=init
431 if iscomplex(var) or iscomplexarray(var):
432 ret={}
433
434 try:
435 v = var["="]
436 if ',' in v:
437 ret['init.r'], ret['init.i']=markoutercomma(v[1:-1]).split('@,@')
438 else:
439 v = eval(v, {}, {})
440 ret['init.r'], ret['init.i']=str(v.real), str(v.imag)
441 except:
442 raise ValueError('getinit: expected complex number `(r,i)\' but got `%s\' as initial value of %r.' % (init, a))
443 if isarray(var):
444 init='(capi_c.r=%s,capi_c.i=%s,capi_c)'%(ret['init.r'], ret['init.i'])
445 elif isstring(var):
446 if not init: init, showinit='""', "''"
447 if init[0]=="'":
448 init='"%s"'%(init[1:-1].replace('"', '\\"'))
449 if init[0]=='"': showinit="'%s'"%(init[1:-1])
450 return init, showinit
451
452 def sign2map(a, var):
453 """
454 varname,ctype,atype
455 init,init.r,init.i,pytype
456 vardebuginfo,vardebugshowvalue,varshowvalue
457 varrfromat
458 intent
459 """
460 global lcb_map, cb_map
461 out_a = a
462 if isintent_out(var):
463 for k in var['intent']:
464 if k[:4]=='out=':
465 out_a = k[4:]
466 break
467 ret={'varname':a,'outvarname':out_a}
468 ret['ctype']=getctype(var)
469 intent_flags = []
470 for f, s in isintent_dict.items():
471 if f(var): intent_flags.append('F2PY_%s'%s)
472 if intent_flags:
473 #XXX: Evaluate intent_flags here.
474 ret['intent'] = '|'.join(intent_flags)
475 else:
476 ret['intent'] = 'F2PY_INTENT_IN'
477 if isarray(var): ret['varrformat']='N'
478 elif ret['ctype'] in c2buildvalue_map:
479 ret['varrformat']=c2buildvalue_map[ret['ctype']]
480 else: ret['varrformat']='O'
481 ret['init'], ret['showinit']=getinit(a, var)
482 if hasinitvalue(var) and iscomplex(var) and not isarray(var):
483 ret['init.r'], ret['init.i'] = markoutercomma(ret['init'][1:-1]).split('@,@')
484 if isexternal(var):
485 ret['cbnamekey']=a
486 if a in lcb_map:
487 ret['cbname']=lcb_map[a]
488 ret['maxnofargs']=lcb2_map[lcb_map[a]]['maxnofargs']
489 ret['nofoptargs']=lcb2_map[lcb_map[a]]['nofoptargs']
490 ret['cbdocstr']=lcb2_map[lcb_map[a]]['docstr']
491 ret['cblatexdocstr']=lcb2_map[lcb_map[a]]['latexdocstr']
492 else:
493 ret['cbname']=a
494 errmess('sign2map: Confused: external %s is not in lcb_map%s.\n'%(a, list(lcb_map.keys())))
495 if isstring(var):
496 ret['length']=getstrlength(var)
497 if isarray(var):
498 ret=dictappend(ret, getarrdims(a, var))
499 dim=copy.copy(var['dimension'])
500 if ret['ctype'] in c2capi_map:
501 ret['atype']=c2capi_map[ret['ctype']]
502 # Debug info
503 if debugcapi(var):
504 il=[isintent_in, 'input', isintent_out, 'output',
505 isintent_inout, 'inoutput', isrequired, 'required',
506 isoptional, 'optional', isintent_hide, 'hidden',
507 iscomplex, 'complex scalar',
508 l_and(isscalar, l_not(iscomplex)), 'scalar',
509 isstring, 'string', isarray, 'array',
510 iscomplexarray, 'complex array', isstringarray, 'string array',
511 iscomplexfunction, 'complex function',
512 l_and(isfunction, l_not(iscomplexfunction)), 'function',
513 isexternal, 'callback',
514 isintent_callback, 'callback',
515 isintent_aux, 'auxiliary',
516 #ismutable,'mutable',l_not(ismutable),'immutable',
517 ]
518 rl=[]
519 for i in range(0, len(il), 2):
520 if il[i](var): rl.append(il[i+1])
521 if isstring(var):
522 rl.append('slen(%s)=%s'%(a, ret['length']))
523 if isarray(var):
524 # if not isintent_c(var):
525 # var['dimension'].reverse()
526 ddim=','.join(map(lambda x, y:'%s|%s'%(x, y), var['dimension'], dim))
527 rl.append('dims(%s)'%ddim)
528 # if not isintent_c(var):
529 # var['dimension'].reverse()
530 if isexternal(var):
531 ret['vardebuginfo']='debug-capi:%s=>%s:%s'%(a, ret['cbname'], ','.join(rl))
532 else:
533 ret['vardebuginfo']='debug-capi:%s %s=%s:%s'%(ret['ctype'], a, ret['showinit'], ','.join(rl))
534 if isscalar(var):
535 if ret['ctype'] in cformat_map:
536 ret['vardebugshowvalue']='debug-capi:%s=%s'%(a, cformat_map[ret['ctype']])
537 if isstring(var):
538 ret['vardebugshowvalue']='debug-capi:slen(%s)=%%d %s=\\"%%s\\"'%(a, a)
539 if isexternal(var):
540 ret['vardebugshowvalue']='debug-capi:%s=%%p'%(a)
541 if ret['ctype'] in cformat_map:
542 ret['varshowvalue']='#name#:%s=%s'%(a, cformat_map[ret['ctype']])
543 ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
544 if isstring(var):
545 ret['varshowvalue']='#name#:slen(%s)=%%d %s=\\"%%s\\"'%(a, a)
546 ret['pydocsign'], ret['pydocsignout']=getpydocsign(a, var)
547 if hasnote(var):
548 ret['note']=var['note']
549 return ret
550
551 def routsign2map(rout):
552 """
553 name,NAME,begintitle,endtitle
554 rname,ctype,rformat
555 routdebugshowvalue
556 """
557 global lcb_map
558 name = rout['name']
559 fname = getfortranname(rout)
560 ret={'name': name,
561 'texname': name.replace('_', '\\_'),
562 'name_lower': name.lower(),
563 'NAME': name.upper(),
564 'begintitle': gentitle(name),
565 'endtitle': gentitle('end of %s'%name),
566 'fortranname': fname,
567 'FORTRANNAME': fname.upper(),
568 'callstatement': getcallstatement(rout) or '',
569 'usercode': getusercode(rout) or '',
570 'usercode1': getusercode1(rout) or '',
571 }
572 if '_' in fname:
573 ret['F_FUNC'] = 'F_FUNC_US'
574 else:
575 ret['F_FUNC'] = 'F_FUNC'
576 if '_' in name:
577 ret['F_WRAPPEDFUNC'] = 'F_WRAPPEDFUNC_US'
578 else:
579 ret['F_WRAPPEDFUNC'] = 'F_WRAPPEDFUNC'
580 lcb_map={}
581 if 'use' in rout:
582 for u in rout['use'].keys():
583 if u in cb_rules.cb_map:
584 for un in cb_rules.cb_map[u]:
585 ln=un[0]
586 if 'map' in rout['use'][u]:
587 for k in rout['use'][u]['map'].keys():
588 if rout['use'][u]['map'][k]==un[0]: ln=k;break
589 lcb_map[ln]=un[1]
590 #else:
591 # errmess('routsign2map: cb_map does not contain module "%s" used in "use" statement.\n'%(u))
592 elif 'externals' in rout and rout['externals']:
593 errmess('routsign2map: Confused: function %s has externals %s but no "use" statement.\n'%(ret['name'], repr(rout['externals'])))
594 ret['callprotoargument'] = getcallprotoargument(rout, lcb_map) or ''
595 if isfunction(rout):
596 if 'result' in rout:
597 a=rout['result']
598 else:
599 a=rout['name']
600 ret['rname']=a
601 ret['pydocsign'], ret['pydocsignout']=getpydocsign(a, rout)
602 ret['ctype']=getctype(rout['vars'][a])
603 if hasresultnote(rout):
604 ret['resultnote']=rout['vars'][a]['note']
605 rout['vars'][a]['note']=['See elsewhere.']
606 if ret['ctype'] in c2buildvalue_map:
607 ret['rformat']=c2buildvalue_map[ret['ctype']]
608 else:
609 ret['rformat']='O'
610 errmess('routsign2map: no c2buildvalue key for type %s\n'%(repr(ret['ctype'])))
611 if debugcapi(rout):
612 if ret['ctype'] in cformat_map:
613 ret['routdebugshowvalue']='debug-capi:%s=%s'%(a, cformat_map[ret['ctype']])
614 if isstringfunction(rout):
615 ret['routdebugshowvalue']='debug-capi:slen(%s)=%%d %s=\\"%%s\\"'%(a, a)
616 if isstringfunction(rout):
617 ret['rlength']=getstrlength(rout['vars'][a])
618 if ret['rlength']=='-1':
619 errmess('routsign2map: expected explicit specification of the length of the string returned by the fortran function %s; taking 10.\n'%(repr(rout['name'])))
620 ret['rlength']='10'
621 if hasnote(rout):
622 ret['note']=rout['note']
623 rout['note']=['See elsewhere.']
624 return ret
625
626 def modsign2map(m):
627 """
628 modulename
629 """
630 if ismodule(m):
631 ret={'f90modulename':m['name'],
632 'F90MODULENAME':m['name'].upper(),
633 'texf90modulename':m['name'].replace('_', '\\_')}
634 else:
635 ret={'modulename':m['name'],
636 'MODULENAME':m['name'].upper(),
637 'texmodulename':m['name'].replace('_', '\\_')}
638 ret['restdoc'] = getrestdoc(m) or []
639 if hasnote(m):
640 ret['note']=m['note']
641 #m['note']=['See elsewhere.']
642 ret['usercode'] = getusercode(m) or ''
643 ret['usercode1'] = getusercode1(m) or ''
644 if m['body']:
645 ret['interface_usercode'] = getusercode(m['body'][0]) or ''
646 else:
647 ret['interface_usercode'] = ''
648 ret['pymethoddef'] = getpymethoddef(m) or ''
649 if 'coutput' in m:
650 ret['coutput'] = m['coutput']
651 if 'f2py_wrapper_output' in m:
652 ret['f2py_wrapper_output'] = m['f2py_wrapper_output']
653 return ret
654
655 def cb_sign2map(a,var,index=None):
656 ret={'varname':a}
657 if index is None or 1: # disable 7712 patch
658 ret['varname_i'] = ret['varname']
659 else:
660 ret['varname_i'] = ret['varname'] + '_' + str(index)
661 ret['ctype']=getctype(var)
662 if ret['ctype'] in c2capi_map:
663 ret['atype']=c2capi_map[ret['ctype']]
664 if ret['ctype'] in cformat_map:
665 ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
666 if isarray(var):
667 ret=dictappend(ret, getarrdims(a, var))
668 ret['pydocsign'], ret['pydocsignout']=getpydocsign(a, var)
669 if hasnote(var):
670 ret['note']=var['note']
671 var['note']=['See elsewhere.']
672 return ret
673
674 def cb_routsign2map(rout, um):
675 """
676 name,begintitle,endtitle,argname
677 ctype,rctype,maxnofargs,nofoptargs,returncptr
678 """
679 ret={'name':'cb_%s_in_%s'%(rout['name'], um),
680 'returncptr':''}
681 if isintent_callback(rout):
682 if '_' in rout['name']:
683 F_FUNC='F_FUNC_US'
684 else:
685 F_FUNC='F_FUNC'
686 ret['callbackname'] = '%s(%s,%s)' \
687 % (F_FUNC,
688 rout['name'].lower(),
689 rout['name'].upper(),
690 )
691 ret['static'] = 'extern'
692 else:
693 ret['callbackname'] = ret['name']
694 ret['static'] = 'static'
695 ret['argname']=rout['name']
696 ret['begintitle']=gentitle(ret['name'])
697 ret['endtitle']=gentitle('end of %s'%ret['name'])
698 ret['ctype']=getctype(rout)
699 ret['rctype']='void'
700 if ret['ctype']=='string': ret['rctype']='void'
701 else:
702 ret['rctype']=ret['ctype']
703 if ret['rctype']!='void':
704 if iscomplexfunction(rout):
705 ret['returncptr'] = """
706 #ifdef F2PY_CB_RETURNCOMPLEX
707 return_value=
708 #endif
709 """
710 else:
711 ret['returncptr'] = 'return_value='
712 if ret['ctype'] in cformat_map:
713 ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
714 if isstringfunction(rout):
715 ret['strlength']=getstrlength(rout)
716 if isfunction(rout):
717 if 'result' in rout:
718 a=rout['result']
719 else:
720 a=rout['name']
721 if hasnote(rout['vars'][a]):
722 ret['note']=rout['vars'][a]['note']
723 rout['vars'][a]['note']=['See elsewhere.']
724 ret['rname']=a
725 ret['pydocsign'], ret['pydocsignout']=getpydocsign(a, rout)
726 if iscomplexfunction(rout):
727 ret['rctype']="""
728 #ifdef F2PY_CB_RETURNCOMPLEX
729 #ctype#
730 #else
731 void
732 #endif
733 """
734 else:
735 if hasnote(rout):
736 ret['note']=rout['note']
737 rout['note']=['See elsewhere.']
738 nofargs=0
739 nofoptargs=0
740 if 'args' in rout and 'vars' in rout:
741 for a in rout['args']:
742 var=rout['vars'][a]
743 if l_or(isintent_in, isintent_inout)(var):
744 nofargs=nofargs+1
745 if isoptional(var):
746 nofoptargs=nofoptargs+1
747 ret['maxnofargs']=repr(nofargs)
748 ret['nofoptargs']=repr(nofoptargs)
749 if hasnote(rout) and isfunction(rout) and 'result' in rout:
750 ret['routnote']=rout['note']
751 rout['note']=['See elsewhere.']
752 return ret
753
754 def common_sign2map(a, var): # obsolute
755 ret={'varname':a}
756 ret['ctype']=getctype(var)
757 if isstringarray(var):
758 ret['ctype']='char'
759 if ret['ctype'] in c2capi_map:
760 ret['atype']=c2capi_map[ret['ctype']]
761 if ret['ctype'] in cformat_map:
762 ret['showvalueformat']='%s'%(cformat_map[ret['ctype']])
763 if isarray(var):
764 ret=dictappend(ret, getarrdims(a, var))
765 elif isstring(var):
766 ret['size']=getstrlength(var)
767 ret['rank']='1'
768 ret['pydocsign'], ret['pydocsignout']=getpydocsign(a, var)
769 if hasnote(var):
770 ret['note']=var['note']
771 var['note']=['See elsewhere.']
772 ret['arrdocstr']=getarrdocsign(a, var) # for strings this returns 0-rank but actually is 1-rank
773 return ret