1# cython: language_level=3
2# This file is part of h5py, a Python interface to the HDF5 library.
3#
4# http://www.h5py.org
5#
6# Copyright 2008-2013 Andrew Collette and contributors
7#
8# License:  Standard 3-clause BSD; see "license.txt" for full license terms
9#           and contributor agreement.
10
11include "config.pxi"
12
13from .api_types_hdf5 cimport *
14
15# Auto-set exception.  Returns 1 if exception set, 0 if no HDF5 error found.
16cdef int set_exception() except -1
17
18cdef extern from "hdf5.h":
19
20    IF HDF5_VERSION < (1, 13, 0):
21        ctypedef enum H5E_major_t:
22            H5E_NONE_MAJOR       = 0,   # special zero, no error
23            H5E_ARGS,                   # invalid arguments to routine
24            H5E_RESOURCE,               # resource unavailable
25            H5E_INTERNAL,               # Internal error (too specific to document)
26            H5E_FILE,                   # file Accessability
27            H5E_IO,                     # Low-level I/O
28            H5E_FUNC,                   # function Entry/Exit
29            H5E_ATOM,                   # object Atom
30            H5E_CACHE,                  # object Cache
31            H5E_BTREE,                  # B-Tree Node
32            H5E_SYM,                    # symbol Table
33            H5E_HEAP,                   # Heap
34            H5E_OHDR,                   # object Header
35            H5E_DATATYPE,               # Datatype
36            H5E_DATASPACE,              # Dataspace
37            H5E_DATASET,                # Dataset
38            H5E_STORAGE,                # data storage
39            H5E_PLIST,                  # Property lists
40            H5E_ATTR,                   # Attribute
41            H5E_PLINE,                  # Data filters
42            H5E_EFL,                    # External file list
43            H5E_REFERENCE,              # References
44            H5E_VFL,                    # Virtual File Layer
45        #   H5E_TBBT,                   # Threaded, Balanced, Binary Trees (not in 1.8)
46            H5E_TST,                    # Ternary Search Trees
47            H5E_RS,                     # Reference Counted Strings
48            H5E_ERROR,                  # Error API
49            H5E_SLIST                   # Skip Lists
50
51        ctypedef enum H5E_minor_t:
52            # Generic low-level file I/O errors
53            H5E_SEEKERROR      # Seek failed
54            H5E_READERROR      # Read failed
55            H5E_WRITEERROR     # Write failed
56            H5E_CLOSEERROR     # Close failed
57            H5E_OVERFLOW       # Address overflowed
58            H5E_FCNTL          # File control (fcntl) failed
59
60            # Resource errors
61            H5E_NOSPACE        # No space available for allocation
62            H5E_CANTALLOC      # Can't allocate space
63            H5E_CANTCOPY       # Unable to copy object
64            H5E_CANTFREE       # Unable to free object
65            H5E_ALREADYEXISTS  # Object already exists
66            H5E_CANTLOCK       # Unable to lock object
67            H5E_CANTUNLOCK     # Unable to unlock object
68            H5E_CANTGC         # Unable to garbage collect
69            H5E_CANTGETSIZE    # Unable to compute size
70            H5E_OBJOPEN        # Object is already open
71
72            # Heap errors
73            H5E_CANTRESTORE    # Can't restore condition
74            H5E_CANTCOMPUTE    # Can't compute value
75            H5E_CANTEXTEND     # Can't extend heap's space
76            H5E_CANTATTACH     # Can't attach object
77            H5E_CANTUPDATE     # Can't update object
78            H5E_CANTOPERATE    # Can't operate on object
79
80            # Function entry/exit interface errors
81            H5E_CANTINIT       # Unable to initialize object
82            H5E_ALREADYINIT    # Object already initialized
83            H5E_CANTRELEASE    # Unable to release object
84
85            # Property list errors
86            H5E_CANTGET        # Can't get value
87            H5E_CANTSET        # Can't set value
88            H5E_DUPCLASS       # Duplicate class name in parent class
89
90            # Free space errors
91            H5E_CANTMERGE      # Can't merge objects
92            H5E_CANTREVIVE     # Can't revive object
93            H5E_CANTSHRINK     # Can't shrink container
94
95            # Object header related errors
96            H5E_LINKCOUNT      # Bad object header link
97            H5E_VERSION        # Wrong version number
98            H5E_ALIGNMENT      # Alignment error
99            H5E_BADMESG        # Unrecognized message
100            H5E_CANTDELETE     # Can't delete message
101            H5E_BADITER        # Iteration failed
102            H5E_CANTPACK       # Can't pack messages
103            H5E_CANTRESET      # Can't reset object count
104
105            # System level errors
106            H5E_SYSERRSTR      # System error message
107
108            # I/O pipeline errors
109            H5E_NOFILTER       # Requested filter is not available
110            H5E_CALLBACK       # Callback failed
111            H5E_CANAPPLY       # Error from filter 'can apply' callback
112            H5E_SETLOCAL       # Error from filter 'set local' callback
113            H5E_NOENCODER      # Filter present but encoding disabled
114            H5E_CANTFILTER     # Filter operation failed
115
116            # Group related errors
117            H5E_CANTOPENOBJ    # Can't open object
118            H5E_CANTCLOSEOBJ   # Can't close object
119            H5E_COMPLEN        # Name component is too long
120            H5E_PATH           # Problem with path to object
121
122            # No error
123            H5E_NONE_MINOR     # No error
124
125            # File accessability errors
126            H5E_FILEEXISTS     # File already exists
127            H5E_FILEOPEN       # File already open
128            H5E_CANTCREATE     # Unable to create file
129            H5E_CANTOPENFILE   # Unable to open file
130            H5E_CANTCLOSEFILE  # Unable to close file
131            H5E_NOTHDF5        # Not an HDF5 file
132            H5E_BADFILE        # Bad file ID accessed
133            H5E_TRUNCATED      # File has been truncated
134            H5E_MOUNT          # File mount error
135
136            # Object atom related errors
137            H5E_BADATOM        # Unable to find atom information (already closed?)
138            H5E_BADGROUP       # Unable to find ID group information
139            H5E_CANTREGISTER   # Unable to register new atom
140            H5E_CANTINC        # Unable to increment reference count
141            H5E_CANTDEC        # Unable to decrement reference count
142            H5E_NOIDS          # Out of IDs for group
143
144            # Cache related errors
145            H5E_CANTFLUSH      # Unable to flush data from cache
146            H5E_CANTSERIALIZE  # Unable to serialize data from cache
147            H5E_CANTLOAD       # Unable to load metadata into cache
148            H5E_PROTECT        # Protected metadata error
149            H5E_NOTCACHED      # Metadata not currently cached
150            H5E_SYSTEM         # Internal error detected
151            H5E_CANTINS        # Unable to insert metadata into cache
152            H5E_CANTRENAME     # Unable to rename metadata
153            H5E_CANTPROTECT    # Unable to protect metadata
154            H5E_CANTUNPROTECT  # Unable to unprotect metadata
155            H5E_CANTPIN        # Unable to pin cache entry
156            H5E_CANTUNPIN      # Unable to un-pin cache entry
157            H5E_CANTMARKDIRTY  # Unable to mark a pinned entry as dirty
158            H5E_CANTDIRTY      # Unable to mark metadata as dirty
159            H5E_CANTEXPUNGE    # Unable to expunge a metadata cache entry
160            H5E_CANTRESIZE     # Unable to resize a metadata cache entry
161
162            # Link related errors
163            H5E_TRAVERSE       # Link traversal failure
164            H5E_NLINKS         # Too many soft links in path
165            H5E_NOTREGISTERED  # Link class not registered
166            H5E_CANTMOVE       # Move callback returned error
167            H5E_CANTSORT       # Can't sort objects
168
169            # Parallel MPI errors
170            H5E_MPI           # Some MPI function failed
171            H5E_MPIERRSTR     # MPI Error String
172            H5E_CANTRECV      # Can't receive data
173
174            # Dataspace errors
175            H5E_CANTCLIP      # Can't clip hyperslab region
176            H5E_CANTCOUNT     # Can't count elements
177            H5E_CANTSELECT    # Can't select hyperslab
178            H5E_CANTNEXT      # Can't move to next iterator location
179            H5E_BADSELECT     # Invalid selection
180            H5E_CANTCOMPARE   # Can't compare objects
181
182            # Argument errors
183            H5E_UNINITIALIZED  # Information is uinitialized
184            H5E_UNSUPPORTED    # Feature is unsupported
185            H5E_BADTYPE        # Inappropriate type
186            H5E_BADRANGE       # Out of range
187            H5E_BADVALUE       # Bad value
188
189            # B-tree related errors
190            H5E_NOTFOUND            # Object not found
191            H5E_EXISTS              # Object already exists
192            H5E_CANTENCODE          # Unable to encode value
193            H5E_CANTDECODE          # Unable to decode value
194            H5E_CANTSPLIT           # Unable to split node
195            H5E_CANTREDISTRIBUTE    # Unable to redistribute records
196            H5E_CANTSWAP            # Unable to swap records
197            H5E_CANTINSERT          # Unable to insert object
198            H5E_CANTLIST            # Unable to list node
199            H5E_CANTMODIFY          # Unable to modify record
200            H5E_CANTREMOVE          # Unable to remove object
201
202            # Datatype conversion errors
203            H5E_CANTCONVERT         # Can't convert datatypes
204            H5E_BADSIZE             # Bad size for object
205    ELSE:
206        ctypedef enum H5E_major_t:
207            H5E_NONE_MAJOR       = 0,   # special zero, no error
208            H5E_ARGS,                   # invalid arguments to routine
209            H5E_RESOURCE,               # resource unavailable
210            H5E_INTERNAL,               # Internal error (too specific to document)
211            H5E_FILE,                   # file Accessability
212            H5E_IO,                     # Low-level I/O
213            H5E_FUNC,                   # function Entry/Exit
214            H5E_ID,                     # object ID
215            H5E_CACHE,                  # object Cache
216            H5E_BTREE,                  # B-Tree Node
217            H5E_SYM,                    # symbol Table
218            H5E_HEAP,                   # Heap
219            H5E_OHDR,                   # object Header
220            H5E_DATATYPE,               # Datatype
221            H5E_DATASPACE,              # Dataspace
222            H5E_DATASET,                # Dataset
223            H5E_STORAGE,                # data storage
224            H5E_PLIST,                  # Property lists
225            H5E_ATTR,                   # Attribute
226            H5E_PLINE,                  # Data filters
227            H5E_EFL,                    # External file list
228            H5E_REFERENCE,              # References
229            H5E_VFL,                    # Virtual File Layer
230        #   H5E_TBBT,                   # Threaded, Balanced, Binary Trees (not in 1.8)
231            H5E_TST,                    # Ternary Search Trees
232            H5E_RS,                     # Reference Counted Strings
233            H5E_ERROR,                  # Error API
234            H5E_SLIST                   # Skip Lists
235
236        ctypedef enum H5E_minor_t:
237            # Generic low-level file I/O errors
238            H5E_SEEKERROR      # Seek failed
239            H5E_READERROR      # Read failed
240            H5E_WRITEERROR     # Write failed
241            H5E_CLOSEERROR     # Close failed
242            H5E_OVERFLOW       # Address overflowed
243            H5E_FCNTL          # File control (fcntl) failed
244
245            # Resource errors
246            H5E_NOSPACE        # No space available for allocation
247            H5E_CANTALLOC      # Can't allocate space
248            H5E_CANTCOPY       # Unable to copy object
249            H5E_CANTFREE       # Unable to free object
250            H5E_ALREADYEXISTS  # Object already exists
251            H5E_CANTLOCK       # Unable to lock object
252            H5E_CANTUNLOCK     # Unable to unlock object
253            H5E_CANTGC         # Unable to garbage collect
254            H5E_CANTGETSIZE    # Unable to compute size
255            H5E_OBJOPEN        # Object is already open
256
257            # Heap errors
258            H5E_CANTRESTORE    # Can't restore condition
259            H5E_CANTCOMPUTE    # Can't compute value
260            H5E_CANTEXTEND     # Can't extend heap's space
261            H5E_CANTATTACH     # Can't attach object
262            H5E_CANTUPDATE     # Can't update object
263            H5E_CANTOPERATE    # Can't operate on object
264
265            # Function entry/exit interface errors
266            H5E_CANTINIT       # Unable to initialize object
267            H5E_ALREADYINIT    # Object already initialized
268            H5E_CANTRELEASE    # Unable to release object
269
270            # Property list errors
271            H5E_CANTGET        # Can't get value
272            H5E_CANTSET        # Can't set value
273            H5E_DUPCLASS       # Duplicate class name in parent class
274
275            # Free space errors
276            H5E_CANTMERGE      # Can't merge objects
277            H5E_CANTREVIVE     # Can't revive object
278            H5E_CANTSHRINK     # Can't shrink container
279
280            # Object header related errors
281            H5E_LINKCOUNT      # Bad object header link
282            H5E_VERSION        # Wrong version number
283            H5E_ALIGNMENT      # Alignment error
284            H5E_BADMESG        # Unrecognized message
285            H5E_CANTDELETE     # Can't delete message
286            H5E_BADITER        # Iteration failed
287            H5E_CANTPACK       # Can't pack messages
288            H5E_CANTRESET      # Can't reset object count
289
290            # System level errors
291            H5E_SYSERRSTR      # System error message
292
293            # I/O pipeline errors
294            H5E_NOFILTER       # Requested filter is not available
295            H5E_CALLBACK       # Callback failed
296            H5E_CANAPPLY       # Error from filter 'can apply' callback
297            H5E_SETLOCAL       # Error from filter 'set local' callback
298            H5E_NOENCODER      # Filter present but encoding disabled
299            H5E_CANTFILTER     # Filter operation failed
300
301            # Group related errors
302            H5E_CANTOPENOBJ    # Can't open object
303            H5E_CANTCLOSEOBJ   # Can't close object
304            H5E_COMPLEN        # Name component is too long
305            H5E_PATH           # Problem with path to object
306
307            # No error
308            H5E_NONE_MINOR     # No error
309
310            # File accessability errors
311            H5E_FILEEXISTS     # File already exists
312            H5E_FILEOPEN       # File already open
313            H5E_CANTCREATE     # Unable to create file
314            H5E_CANTOPENFILE   # Unable to open file
315            H5E_CANTCLOSEFILE  # Unable to close file
316            H5E_NOTHDF5        # Not an HDF5 file
317            H5E_BADFILE        # Bad file ID accessed
318            H5E_TRUNCATED      # File has been truncated
319            H5E_MOUNT          # File mount error
320
321            # Object ID related errors
322            H5E_BADID          # Unable to find ID information (already closed?) */
323            H5E_BADGROUP       # Unable to find ID group information
324            H5E_CANTREGISTER   # Unable to register new ID
325            H5E_CANTINC        # Unable to increment reference count
326            H5E_CANTDEC        # Unable to decrement reference count
327            H5E_NOIDS          # Out of IDs for group
328
329            # Cache related errors
330            H5E_CANTFLUSH      # Unable to flush data from cache
331            H5E_CANTSERIALIZE  # Unable to serialize data from cache
332            H5E_CANTLOAD       # Unable to load metadata into cache
333            H5E_PROTECT        # Protected metadata error
334            H5E_NOTCACHED      # Metadata not currently cached
335            H5E_SYSTEM         # Internal error detected
336            H5E_CANTINS        # Unable to insert metadata into cache
337            H5E_CANTRENAME     # Unable to rename metadata
338            H5E_CANTPROTECT    # Unable to protect metadata
339            H5E_CANTUNPROTECT  # Unable to unprotect metadata
340            H5E_CANTPIN        # Unable to pin cache entry
341            H5E_CANTUNPIN      # Unable to un-pin cache entry
342            H5E_CANTMARKDIRTY  # Unable to mark a pinned entry as dirty
343            H5E_CANTDIRTY      # Unable to mark metadata as dirty
344            H5E_CANTEXPUNGE    # Unable to expunge a metadata cache entry
345            H5E_CANTRESIZE     # Unable to resize a metadata cache entry
346
347            # Link related errors
348            H5E_TRAVERSE       # Link traversal failure
349            H5E_NLINKS         # Too many soft links in path
350            H5E_NOTREGISTERED  # Link class not registered
351            H5E_CANTMOVE       # Move callback returned error
352            H5E_CANTSORT       # Can't sort objects
353
354            # Parallel MPI errors
355            H5E_MPI           # Some MPI function failed
356            H5E_MPIERRSTR     # MPI Error String
357            H5E_CANTRECV      # Can't receive data
358
359            # Dataspace errors
360            H5E_CANTCLIP      # Can't clip hyperslab region
361            H5E_CANTCOUNT     # Can't count elements
362            H5E_CANTSELECT    # Can't select hyperslab
363            H5E_CANTNEXT      # Can't move to next iterator location
364            H5E_BADSELECT     # Invalid selection
365            H5E_CANTCOMPARE   # Can't compare objects
366
367            # Argument errors
368            H5E_UNINITIALIZED  # Information is uinitialized
369            H5E_UNSUPPORTED    # Feature is unsupported
370            H5E_BADTYPE        # Inappropriate type
371            H5E_BADRANGE       # Out of range
372            H5E_BADVALUE       # Bad value
373
374            # B-tree related errors
375            H5E_NOTFOUND            # Object not found
376            H5E_EXISTS              # Object already exists
377            H5E_CANTENCODE          # Unable to encode value
378            H5E_CANTDECODE          # Unable to decode value
379            H5E_CANTSPLIT           # Unable to split node
380            H5E_CANTREDISTRIBUTE    # Unable to redistribute records
381            H5E_CANTSWAP            # Unable to swap records
382            H5E_CANTINSERT          # Unable to insert object
383            H5E_CANTLIST            # Unable to list node
384            H5E_CANTMODIFY          # Unable to modify record
385            H5E_CANTREMOVE          # Unable to remove object
386
387            # Datatype conversion errors
388            H5E_CANTCONVERT         # Can't convert datatypes
389            H5E_BADSIZE             # Bad size for object
390
391    cdef enum H5E_direction_t:
392        H5E_WALK_UPWARD    = 0      # begin deep, end at API function
393        H5E_WALK_DOWNWARD = 1       # begin at API function, end deep
394
395    ctypedef struct H5E_error_t:
396        H5E_major_t     maj_num     #  major error number
397        H5E_minor_t     min_num     #  minor error number
398        char    *func_name          #  function in which error occurred
399        char    *file_name          #  file in which error occurred
400        unsigned    line            #  line in file where error occurs
401        char    *desc               #  optional supplied description
402
403    int H5E_DEFAULT  # ID for default error stack
404
405    char      *H5Eget_major(H5E_major_t n)
406    char      *H5Eget_minor(H5E_minor_t n)
407    herr_t    H5Eclear(hid_t estack_id) except *
408
409    ctypedef herr_t (*H5E_auto_t)(void *client_data)
410    herr_t    H5Eset_auto(hid_t estack_id, H5E_auto_t func, void *client_data) nogil
411    herr_t    H5Eget_auto(hid_t estack_id, H5E_auto_t *func, void** client_data)
412
413    herr_t    H5Eprint(hid_t estack_id, void *stream)
414
415    ctypedef herr_t (*H5E_walk_t)(int n, H5E_error_t *err_desc, void* client_data)
416    herr_t    H5Ewalk(hid_t estack_id, H5E_direction_t direction, H5E_walk_t func, void* client_data)
417
418# --- Functions for managing the HDF5 error callback mechanism ---
419
420ctypedef struct err_cookie:
421    # Defines the error handler state (callback and callback data)
422    H5E_auto_t func
423    void *data
424
425# Set (via H5Eset_auto) the HDF5 error handler for this thread.  Returns
426# the old (presently installed) handler.
427cdef err_cookie set_error_handler(err_cookie handler)
428
429# Set the default error handler set by silence_errors/unsilence_errors
430cdef void set_default_error_handler() nogil
431