/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/utils.h

  • Committer: Gustav Hartvigsson
  • Date: 2017-01-24 20:55:19 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20170124205519-gtr18o3dwbunrrnx
* Fixed the tests in the CMake file
* Made doxygen output static declarations.
* Started work on SApplication
* Played with BaseN.c
  * Now it is a lil' bit better
* Spilt defs.h
  * Added types.h
    * Started work on the full typesystem.
      (Still needs testing)
  * Added primes.[c,h]
    * Contains some static array with primes.
      ("Good" primes, and all primes up to 5 000.
    * And helper functions related to Primes (Needs Tests).
* fixed s_dynamic_array_dump_array.
  (The old version did not make much sense)
* removed some functions from DymanicArray.c
* fixed compiler warnings in Mainloop.c
* removed s_map_(de)serialize_json functions.
* Made s_thread_status_get_name be less prone to error
  (This due to the C11 standard not specifing what these
   values should be)
* fixed s_thread_run
* fixed s_threa_stop

  TODO:
* Write tests for the s_prime_* functions
* Write tests for the s_type_* functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <stdio.h>
29
29
#include <uchar.h>
30
30
#include <wchar.h>
 
31
#include<signal.h>
31
32
 
32
33
 
33
34
S_BEGIN_DECLS
151
152
schar *
152
153
s_current_time_full (void);
153
154
 
 
155
 
 
156
 
 
157
 
 
158
/*
 
159
 * Macro to create a defs for the bin search functions.
 
160
 * Do not use can not be used outside of here.
 
161
 */
 
162
#define _BIN_SEARCH_FUNC_NAME(type)\
 
163
s_binary_search_##type (type list[], size_t first, size_t last, type n)
 
164
 
 
165
 
 
166
#define _MAKE_BIN_SEARCH_DEF(type)\
 
167
S_EXPORTED \
 
168
sboolean \
 
169
_BIN_SEARCH_FUNC_NAME(type)
 
170
 
 
171
 
 
172
/**
 
173
 * Does a binary search in an orderd array of values.
 
174
 *
 
175
 * @param list The list to search.
 
176
 * @param first The lowest position to search.
 
177
 * @param last The last position to search.
 
178
 * @param n The value to see if it is in the list.
 
179
 */
 
180
#define s_binary_search(list, first, last, n) _Generic ((list),\
 
181
                         sbyte *: s_binary_search_sbyte ,\
 
182
                        subyte *: s_binary_search_subyte ,\
 
183
                        sshort *: s_binary_search_sshort ,\
 
184
                       sushort *: s_binary_search_sushort ,\
 
185
                          sint *: s_binary_search_sint ,\
 
186
                         suint *: s_binary_search_suint ,\
 
187
                         slong *: s_binary_search_slong ,\
 
188
                        sulong *: s_binary_search_sulong ,\
 
189
                        sfloat *: s_binary_search_sfloat ,\
 
190
                       sdouble *: s_binary_search_sdouble ,\
 
191
                    squadruple *: s_binary_search_squadruple\
 
192
                        )(list, first, last, n)
 
193
 
 
194
 
 
195
 
 
196
_MAKE_BIN_SEARCH_DEF(sbyte);
 
197
 
 
198
_MAKE_BIN_SEARCH_DEF(subyte);
 
199
 
 
200
_MAKE_BIN_SEARCH_DEF(sshort);
 
201
 
 
202
_MAKE_BIN_SEARCH_DEF(sushort);
 
203
 
 
204
_MAKE_BIN_SEARCH_DEF(sint);
 
205
 
 
206
_MAKE_BIN_SEARCH_DEF(suint);
 
207
 
 
208
_MAKE_BIN_SEARCH_DEF(slong);
 
209
 
 
210
_MAKE_BIN_SEARCH_DEF(sulong);
 
211
 
 
212
_MAKE_BIN_SEARCH_DEF(sfloat);
 
213
 
 
214
_MAKE_BIN_SEARCH_DEF(sdouble);
 
215
 
 
216
_MAKE_BIN_SEARCH_DEF(squadruple);
 
217
 
 
218
 
 
219
 
 
220
 
 
221
#undef _BIN_SEARCH_FUNC_NAME
 
222
#undef _MAKE_BIN_SEARCH_DEF
 
223
#undef _BIN_SEARCH_GENERIC_FN
 
224
 
 
225
 
154
226
#if 0
155
227
/* strdup is not ISO C, so we have to declare it somewhere, this should work
156
228
 * even if we do not implement the function ourself.
224
296
 
225
297
/* -------- TraceBack stuff ---- */
226
298
 
 
299
/**
 
300
 * @def print_traceback
 
301
 * Get a platform specific traceback.
 
302
 *
 
303
 * Works on UNIX's and Windows (Not working).
 
304
 */
 
305
 
227
306
#define S_STACK_TRACKE_SIZE 128
228
307
 
229
308
#ifdef  __unix__
230
309
  //#pragma message ("We are a UNIX.")
231
310
  #include <execinfo.h>
232
 
  /**
233
 
   * Get a platform specific traceback.
234
 
   *
235
 
   * Works on UNIX's and Windows (Not working).
236
 
   */
237
311
  #define print_backtrace() {\
238
312
    fprintf (stderr, "[BACKTRACE:]\n");\
239
313
    void ** _backtrace_data_ = s_calloc (S_STACK_TRACKE_SIZE, sizeof (void *));\
284
358
  }
285
359
#endif
286
360
 
 
361
/* ************************************************************************** 
 
362
 * Signal handlers
 
363
 * ************************************************************************** */
 
364
 
 
365
/**
 
366
 * @defgroup Sighand Signal handlers
 
367
 * @brief Signal handlers that can be uned in your code. (Use with care).
 
368
 * @{
 
369
 */
 
370
 
 
371
/**
 
372
 * Signal handler for segmentation faults.
 
373
 *
 
374
 * This can be hooked up if you want to print a traceback of what has happened
 
375
 * to cause the segmentatino fault.
 
376
 *
 
377
 * in the mainfunction add the following:
 
378
 * @code{c}
 
379
int
 
380
main (char ** argv, int argc) {
 
381
  // stuffs
 
382
  // code
 
383
  
 
384
  signal (SIGSEGV, s_sig_segfault);
 
385
  
 
386
  // start main loop or what ever.
 
387
  
 
388
 
389
 * @endcode
 
390
 */
 
391
void
 
392
s_sig_segfault (int);
 
393
 
 
394
/** @} */
287
395
 
288
396
/** @} */
289
397