1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
################################################################################
#
# $Project: /Convert-Binary-C $
# $Author: mhx $
# $Date: 2009/03/15 04:10:43 +0100 $
# $Revision: 13 $
# $Source: /xsubs/offsetof.xs $
#
################################################################################
#
# Copyright (c) 2002-2009 Marcus Holland-Moritz. All rights reserved.
# This program is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself.
#
################################################################################
################################################################################
#
# METHOD: offsetof
#
# WRITTEN BY: Marcus Holland-Moritz ON: Mar 2002
# CHANGED BY: ON:
#
################################################################################
SV *
CBC::offsetof(type, member)
const char *type
const char *member
PREINIT:
CBC_METHOD(offsetof);
MemberInfo mi, mi2;
const char *m = member;
CODE:
CT_DEBUG_METHOD2("'%s', '%s'", type, member);
CHECK_PARSE_DATA;
CHECK_VOID_CONTEXT;
while (isSPACE(*m))
m++;
if (*m == '\0')
WARN((aTHX_ "Empty string passed as member expression"));
NEED_PARSE_DATA;
if (!get_member_info(aTHX_ THIS, type, &mi, 0))
Perl_croak(aTHX_ "Cannot find '%s'", type);
(void) get_member(aTHX_ &mi, member, &mi2, CBC_GM_ACCEPT_DOTLESS_MEMBER);
if (mi2.pDecl && mi2.pDecl->bitfield_flag)
Perl_croak(aTHX_ "Cannot use %s on bitfields", method);
if (mi.flags)
WARN_FLAGS(type, mi.flags);
RETVAL = newSViv(mi2.offset);
OUTPUT:
RETVAL
|