Skip to content

Commit

Permalink
Move some private SPL Directory elements out of the header
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Jun 23, 2022
1 parent 365537f commit 4d43241
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
29 changes: 29 additions & 0 deletions ext/spl/spl_directory.c
Expand Up @@ -52,6 +52,35 @@ PHPAPI zend_class_entry *spl_ce_GlobIterator;
PHPAPI zend_class_entry *spl_ce_SplFileObject;
PHPAPI zend_class_entry *spl_ce_SplTempFileObject;

/* Object helper */
static inline spl_filesystem_object *spl_filesystem_from_obj(zend_object *obj) /* {{{ */ {
return (spl_filesystem_object*)((char*)(obj) - XtOffsetOf(spl_filesystem_object, std));
}
/* }}} */
#define Z_SPLFILESYSTEM_P(zv) spl_filesystem_from_obj(Z_OBJ_P((zv)))

/* define an overloaded iterator structure */
typedef struct {
zend_object_iterator intern;
zval current;
void *object;
} spl_filesystem_iterator;

static inline spl_filesystem_iterator* spl_filesystem_object_to_iterator(spl_filesystem_object *obj)
{
spl_filesystem_iterator *it;

it = ecalloc(1, sizeof(spl_filesystem_iterator));
it->object = (void *)obj;
zend_iterator_init(&it->intern);
return it;
}

static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_filesystem_iterator *it)
{
return (spl_filesystem_object*)it->object;
}

#define CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(spl_filesystem_object_pointer) \
if (!(spl_filesystem_object_pointer)->u.file.stream) { \
zend_throw_error(NULL, "Object not initialized"); \
Expand Down
40 changes: 6 additions & 34 deletions ext/spl/spl_directory.h
Expand Up @@ -30,12 +30,7 @@ extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject;

PHP_MINIT_FUNCTION(spl_directory);

typedef enum {
SPL_FS_INFO, /* must be 0 */
SPL_FS_DIR,
SPL_FS_FILE
} SPL_FS_OBJ_TYPE;

/* Internal objecte structure and helpers for Directory and File SPL objects */
typedef struct _spl_filesystem_object spl_filesystem_object;

typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object);
Expand All @@ -48,12 +43,11 @@ typedef struct _spl_other_handler {
spl_foreign_clone_t clone;
} spl_other_handler;

/* define an overloaded iterator structure */
typedef struct {
zend_object_iterator intern;
zval current;
void *object;
} spl_filesystem_iterator;
typedef enum {
SPL_FS_INFO, /* must be 0 */
SPL_FS_DIR,
SPL_FS_FILE
} SPL_FS_OBJ_TYPE;

struct _spl_filesystem_object {
void *oth;
Expand Down Expand Up @@ -96,28 +90,6 @@ struct _spl_filesystem_object {
zend_object std;
};

static inline spl_filesystem_object *spl_filesystem_from_obj(zend_object *obj) /* {{{ */ {
return (spl_filesystem_object*)((char*)(obj) - XtOffsetOf(spl_filesystem_object, std));
}
/* }}} */

#define Z_SPLFILESYSTEM_P(zv) spl_filesystem_from_obj(Z_OBJ_P((zv)))

static inline spl_filesystem_iterator* spl_filesystem_object_to_iterator(spl_filesystem_object *obj)
{
spl_filesystem_iterator *it;

it = ecalloc(1, sizeof(spl_filesystem_iterator));
it->object = (void *)obj;
zend_iterator_init(&it->intern);
return it;
}

static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_filesystem_iterator *it)
{
return (spl_filesystem_object*)it->object;
}

#define SPL_FILE_OBJECT_DROP_NEW_LINE 0x00000001 /* drop new lines */
#define SPL_FILE_OBJECT_READ_AHEAD 0x00000002 /* read on rewind/next */
#define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000004 /* skip empty lines */
Expand Down

0 comments on commit 4d43241

Please sign in to comment.