using System;
using System.Runtime.InteropServices;

using ALLEGRO_SYSTEM = System.IntPtr;
using ALLEGRO_CONFIG = System.IntPtr;
using ALLEGRO_PATH = System.IntPtr;

namespace sharpallegro5
{
    /* memory.h */
    public partial class AllegroApi
    {
        public static string __FILE__ { get { return new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); } }
        public static int __LINE__ { get { return new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(); } }
        public static string __func__ { get { return new System.Diagnostics.StackTrace(true).GetFrame(0).GetMethod().Name; } }
        /* Type: ALLEGRO_MEMORY_INTERFACE
         */
        //typedef struct ALLEGRO_MEMORY_INTERFACE ALLEGRO_MEMORY_INTERFACE;

        //struct ALLEGRO_MEMORY_INTERFACE {
        //   void *(*mi_malloc)(size_t n, int line, const char *file, const char *func);
        //   void (*mi_free)(void *ptr, int line, const char *file, const char *func);
        //   void *(*mi_realloc)(void *ptr, size_t n, int line, const char *file, const char *func);
        //   void *(*mi_calloc)(size_t count, size_t n, int line, const char *file, const char *func);
        //};

        //AL_FUNC(void, al_set_memory_interface, (ALLEGRO_MEMORY_INTERFACE *iface));


        ///* Function: al_malloc
        // */
        //#define al_malloc(n) \
        //   (al_malloc_with_context((n), __LINE__, __FILE__, __func__))

        ///* Function: al_free
        // */
        //#define al_free(p) \
        //   (al_free_with_context((p), __LINE__, __FILE__, __func__))
        public static void al_free(IntPtr p)
        {
            al_free_with_context(p, __LINE__, __FILE__, __func__);
        }

        ///* Function: al_realloc
        // */
        //#define al_realloc(p, n) \
        //   (al_realloc_with_context((p), (n), __LINE__, __FILE__, __func__))

        ///* Function: al_calloc
        // */
        //#define al_calloc(c, n) \
        //   (al_calloc_with_context((c), (n), __LINE__, __FILE__, __func__))


        //AL_FUNC(void *, al_malloc_with_context, (size_t n,
        //   int line, const char *file, const char *func));
        //void al_free_with_context(void *ptr, int line, const char *file, const char *func)
        [DllImport(allegroDllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void al_free_with_context(IntPtr ptr, int line, string file, string func);
        //AL_FUNC(void *, al_realloc_with_context, (void *ptr, size_t n,
        //   int line, const char *file, const char *func));
        //AL_FUNC(void *, al_calloc_with_context, (size_t count, size_t n,
        //   int line, const char *file, const char *func));
    }
}
