1 /* Copyright (C) 2013 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
28 #define SMOBS_COUNT (10000)
36 typedef struct x_tag x_t
;
38 unsigned int mark_call_count
= 0;
40 static scm_t_bits x_tag
;
41 static SCM
make_x (void);
42 static SCM
mark_x (SCM x
);
43 static int print_x (SCM x
, SCM port
, scm_print_state
* pstate
);
44 static size_t free_x (SCM x
);
45 static void init_smob_type (void);
46 static void test_scm_smob_mark (void);
56 c_x
= (x_t
*) scm_gc_malloc (sizeof (x_t
), "x");
57 c_x
->scm_value
= scm_from_int (i
);
59 SCM_NEWSMOB (s_x
, x_tag
, c_x
);
67 c_x
= (x_t
*) SCM_SMOB_DATA (x
);
68 scm_gc_mark (c_x
->scm_value
);
77 c_x
= (x_t
*) SCM_SMOB_DATA (x
);
78 scm_gc_free (c_x
, sizeof (x_t
), "x");
84 print_x (SCM x
, SCM port
, scm_print_state
* pstate SCM_UNUSED
)
86 x_t
*c_x
= (x_t
*) SCM_SMOB_DATA (x
);
87 scm_puts ("#<x ", port
);
88 if (c_x
== (x_t
*) NULL
)
89 scm_puts ("(freed)", port
);
91 scm_write (c_x
->scm_value
, port
);
102 for (i
= 0; i
< SMOBS_COUNT
; i
++)
105 if (mark_call_count
< SMOBS_COUNT
)
107 fprintf (stderr
, "FAIL: SMOB mark function called for each SMOB\n");
115 x_tag
= scm_make_smob_type ("x", sizeof (x_t
));
116 scm_set_smob_free (x_tag
, free_x
);
117 scm_set_smob_print (x_tag
, print_x
);
118 scm_set_smob_mark (x_tag
, mark_x
);
122 tests (void *data
, int argc
, char **argv
)
125 test_scm_smob_mark ();
129 main (int argc
, char *argv
[])
131 scm_boot_guile (argc
, argv
, tests
, NULL
);