1 /* Copyright (C) 2013, 2014 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #define SMOBS_COUNT (10000)
38 typedef struct x_tag x_t
;
40 unsigned int mark_call_count
= 0;
42 static scm_t_bits x_tag
;
43 static SCM
make_x (void);
44 static SCM
mark_x (SCM x
);
45 static int print_x (SCM x
, SCM port
, scm_print_state
* pstate
);
46 static size_t free_x (SCM x
);
47 static void init_smob_type (void);
48 static void test_scm_smob_mark (void);
58 c_x
= (x_t
*) scm_gc_malloc (sizeof (x_t
), "x");
59 c_x
->scm_value
= scm_from_int (i
);
61 SCM_NEWSMOB (s_x
, x_tag
, c_x
);
69 c_x
= (x_t
*) SCM_SMOB_DATA (x
);
70 scm_gc_mark (c_x
->scm_value
);
79 c_x
= (x_t
*) SCM_SMOB_DATA (x
);
80 scm_gc_free (c_x
, sizeof (x_t
), "x");
86 print_x (SCM x
, SCM port
, scm_print_state
* pstate SCM_UNUSED
)
88 x_t
*c_x
= (x_t
*) SCM_SMOB_DATA (x
);
89 scm_puts ("#<x ", port
);
90 if (c_x
== (x_t
*) NULL
)
91 scm_puts ("(freed)", port
);
93 scm_write (c_x
->scm_value
, port
);
100 test_scm_smob_mark ()
104 for (i
= 0; i
< SMOBS_COUNT
; i
++)
107 if (mark_call_count
< SMOBS_COUNT
)
109 fprintf (stderr
, "FAIL: SMOB mark function called for each SMOB\n");
117 x_tag
= scm_make_smob_type ("x", sizeof (x_t
));
118 scm_set_smob_free (x_tag
, free_x
);
119 scm_set_smob_print (x_tag
, print_x
);
120 scm_set_smob_mark (x_tag
, mark_x
);
124 tests (void *data
, int argc
, char **argv
)
127 test_scm_smob_mark ();
131 main (int argc
, char *argv
[])
133 scm_boot_guile (argc
, argv
, tests
, NULL
);