1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-03 08:10:31 +02:00
guile/libguile/smob-internal.h
Andy Wingo 62b23a8dc4 Add smob-internal.h
* libguile/smob-internal.h: New file.
* libguile/Makefile.am (noinst_HEADERS): Add new file.
* libguile/smob.c (scm_new_smob, scm_new_double_smob): Adapt.
2025-06-30 14:58:44 +02:00

98 lines
2.2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SCM_SMOB_INTERNAL_H
#define SCM_SMOB_INTERNAL_H
/* Copyright 1995-1996,1998-2001,2004,2006,2009-2012,2015,2018,2025
Free Software Foundation, Inc.
This file is part of Guile.
Guile is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Guile is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Guile. If not, see
<https://www.gnu.org/licenses/>. */
#include "libguile/smob.h"
struct scm_smob
{
scm_t_bits tag_and_flags;
};
struct scm_single_smob
{
struct scm_smob header;
scm_t_bits data_1;
};
struct scm_double_smob
{
struct scm_smob header;
scm_t_bits data_1;
scm_t_bits data_2;
scm_t_bits data_3;
};
static inline int
scm_is_smob (SCM x)
{
return SCM_HAS_TYP7 (x, scm_tc7_smob);
}
static inline struct scm_smob *
scm_to_smob (SCM x)
{
if (!scm_is_smob (x))
abort ();
return (struct scm_smob *) SCM_UNPACK_POINTER (x);
}
static inline SCM
scm_from_smob (struct scm_smob * x)
{
return SCM_PACK_POINTER (x);
}
static inline struct scm_smob_descriptor *
scm_i_smob_descriptor (struct scm_smob *x)
{
return &scm_smobs[((x->tag_and_flags) & 0xff00) >> 8];
}
static inline int
scm_smob_field_is_managed (const struct scm_smob_descriptor *desc, size_t i)
{
if (i >= 32)
abort();
return ((1 << i) & desc->unmanaged_fields) == 0;
}
static inline int
scm_smob_field_is_unmanaged (const struct scm_smob_descriptor *desc, size_t i)
{
return !scm_smob_field_is_managed (desc, i);
}
static inline void*
scm_smob_field_loc (struct scm_smob *smob, size_t i)
{
uintptr_t addr = (uintptr_t) smob;
return (void *) (addr + sizeof (*smob) + i * sizeof (scm_t_bits));
}
SCM_INTERNAL void scm_i_finalize_smob (struct scm_thread *thread, SCM obj);
#endif /* SCM_SMOB_INTERNAL_H */