mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-03 08:10:31 +02:00
* 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.
98 lines
2.2 KiB
C
98 lines
2.2 KiB
C
#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 */
|