test-scm-take-u8vector.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2009,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* Make sure `scm_take_u8vector ()' returns a u8vector that actually uses the
  16. provided storage. */
  17. #ifdef HAVE_CONFIG_H
  18. # include <config.h>
  19. #endif
  20. #include <libguile.h>
  21. #include <stdlib.h>
  22. static void *
  23. do_test (void *result)
  24. {
  25. #define LEN 123
  26. SCM u8v;
  27. uint8_t *data;
  28. scm_t_array_handle handle;
  29. data = scm_malloc (LEN);
  30. u8v = scm_take_u8vector (data, LEN);
  31. scm_array_get_handle (u8v, &handle);
  32. if (scm_array_handle_u8_writable_elements (&handle) == data
  33. && scm_array_handle_u8_elements (&handle) == data)
  34. * (int *) result = EXIT_SUCCESS;
  35. else
  36. * (int *) result = EXIT_FAILURE;
  37. scm_array_handle_release (&handle);
  38. return NULL;
  39. #undef LEN
  40. }
  41. int
  42. main (int argc, char *argv[])
  43. {
  44. int result;
  45. scm_with_guile (do_test, &result);
  46. return result;
  47. }