Skip to content

Add new file IO callback API.#142

Closed
Clownacy wants to merge 3 commits intortissera:masterfrom
Clownacy:new-callback-api
Closed

Add new file IO callback API.#142
Clownacy wants to merge 3 commits intortissera:masterfrom
Clownacy:new-callback-api

Conversation

@Clownacy
Copy link
Contributor

@Clownacy Clownacy commented Feb 3, 2026

This new one avoids the need for memory allocation, streamlines some library internals, and provides a simpler interface for the user:

Old API:

core_file* const file_callbacks = (core_file*)malloc(sizeof(core_file));

if (file_callbacks == NULL)
{
	return NULL;
}
else
{
	chd_file *file;

	file_callbacks->argp = &disc->file;
	file_callbacks->fsize = ClownCD_Disc_CHDFileSize;
	file_callbacks->fread = ClownCD_Disc_CHDFileRead;
	file_callbacks->fclose = ClownCD_Disc_CHDFileClose;
	file_callbacks->fseek = ClownCD_Disc_CHDFileSeek;

	chd_open_core_file(file_callbacks, CHD_OPEN_READ, NULL, &file);
	return file;
}

New API:

static const core_file_callbacks file_callbacks = {
	ClownCD_Disc_CHDFileSize,
	ClownCD_Disc_CHDFileRead,
	ClownCD_Disc_CHDFileClose,
	ClownCD_Disc_CHDFileSeek,
};

chd_file *file;

chd_open_core_file_callbacks(&file_callbacks, &disc->file, CHD_OPEN_READ, NULL, &file);
return file;

The old API has been preserved for backwards-compatibility; since libchdr is packaged by Debian, I figured that API-breaking changes would be undesirable.

I also threw-in some miscellaneous changes that I had lying around; they can be removed if you want them submitting separately.

For some reason, the libretro fork has this, but upstream does not!
This new one avoids the need for memory allocation, streamlines some
library internals, and provides a simpler interface for the user:

Old API:

```c
core_file* const file_callbacks = (core_file*)malloc(sizeof(core_file));

if (file_callbacks == NULL)
{
	return NULL;
}
else
{
	chd_file *file;

	file_callbacks->argp = &disc->file;
	file_callbacks->fsize = ClownCD_Disc_CHDFileSize;
	file_callbacks->fread = ClownCD_Disc_CHDFileRead;
	file_callbacks->fclose = ClownCD_Disc_CHDFileClose;
	file_callbacks->fseek = ClownCD_Disc_CHDFileSeek;

	chd_open_core_file(file_callbacks, CHD_OPEN_READ, NULL, &file);
	return file;
}
```

New API:

```c
static const core_file_callbacks file_callbacks = {
	ClownCD_Disc_CHDFileSize,
	ClownCD_Disc_CHDFileRead,
	ClownCD_Disc_CHDFileClose,
	ClownCD_Disc_CHDFileSeek,
};

chd_file *file;

chd_open_core_file_callbacks(&file_callbacks, &disc->file, CHD_OPEN_READ, NULL, &file);
return file;
```

The old API has been preserved for backwards-compatibility; since
libchdr is packaged by Debian, I figured that API-breaking changes
would be undesirable.
@Clownacy
Copy link
Contributor Author

Clownacy commented Feb 6, 2026

Closing since #143 makes this redundant.

@Clownacy Clownacy closed this Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant