Skip to content

Commit

Permalink
Fixing double initialization of critical section
Browse files Browse the repository at this point in the history
  • Loading branch information
ktakashi committed Dec 16, 2024
1 parent d0b5d41 commit 41b475c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/clos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2319,9 +2319,14 @@ static void init_class(SgClass *klass, const SgChar *name,
klass->gettersNSetters = (SgSlotAccessor**)Sg_ListToArray(acc, TRUE);
klass->slots = slots;
klass->nfields = (int)Sg_Length(slots);

/* do we need this? */
Sg_InitMutex(&klass->mutex, FALSE);
Sg_InitCond(&klass->cv);
if ((flags & SG_NO_INIT_MUTEX) == 0) {
Sg_InitMutex(&klass->mutex, FALSE);
}
if ((flags & SG_NO_INIT_CV) == 0) {
Sg_InitCond(&klass->cv);
}
}

void Sg_InitStaticClass(SgClass *klass, const SgChar *name,
Expand Down Expand Up @@ -3139,8 +3144,6 @@ void Sg__InitClos()
BINIT(SG_CLASS_DICTIONARY, "<dictionary>", NULL);
BINIT(SG_CLASS_ORDERED_DICTIONARY, "<ordered-dictionary>", NULL);

/* hashtable */
CINIT(SG_CLASS_HASHTABLE, "<hashtable>");
/* treemap */
CINIT(SG_CLASS_TREE_MAP, "<tree-map>");

Expand Down
2 changes: 1 addition & 1 deletion src/dl_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ static SgDynLoadInitFn dl_sym(void *handle, const char *name)

static void dl_close(void *handle)
{
(void)FreeLibrary((HMODULE)handle);
/* (void)FreeLibrary((HMODULE)handle); */
}

2 changes: 1 addition & 1 deletion src/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SgObject Sg_AllocateRecordTypeMeta(SgClass *klass, SgObject initargs)
SG_SET_CLASS(m, klass);
/* ok we need to initialise the metaclass by hand */
SG_CLASS(m)->cpa = Sg_RTMCPL;
Sg_InitStaticClass(SG_CLASS(m), NULL, NULL, rtm_slots, 0);
Sg_InitStaticClass(SG_CLASS(m), NULL, NULL, rtm_slots, SG_NO_INIT_CV);
SG_RECORD_TYPE_META(m)->rtd = SG_FALSE;
SG_RECORD_TYPE_META(m)->rcd = SG_FALSE;
return m;
Expand Down
6 changes: 6 additions & 0 deletions src/sagittarius/private/clos.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ enum {
SG_CLASS_APPLICABLE = 0x04,
};

/* A bit ugly work around for double initialization... */
typedef enum {
SG_NO_INIT_CV = 0x00000001,
SG_NO_INIT_MUTEX = 0x00000002,
} SgClassInitFlags;

/* built-in classes */
SG_CLASS_DECL(Sg_TopClass);
SG_CLASS_DECL(Sg_BoolClass);
Expand Down

0 comments on commit 41b475c

Please sign in to comment.